From 8acb334302bb663925772db83e395906d810f7b3 Mon Sep 17 00:00:00 2001 From: MiranDMC Date: Sun, 14 Apr 2024 01:48:31 +0200 Subject: [PATCH] Enabled support of export index as argument in get_proc_address opcode (#124) Enabled support of export index as argument in get_proc_address opcode --- .../MemoryOperations/MemoryOperations.cpp | 19 +++++++++++++++---- tests/cleo_tests/MemoryOperations/0AA4.txt | 15 +++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/cleo_plugins/MemoryOperations/MemoryOperations.cpp b/cleo_plugins/MemoryOperations/MemoryOperations.cpp index 03335792..1e0f5d74 100644 --- a/cleo_plugins/MemoryOperations/MemoryOperations.cpp +++ b/cleo_plugins/MemoryOperations/MemoryOperations.cpp @@ -396,12 +396,23 @@ class MemoryOperations //0AA4=3, get_proc_address %1d% library %2d% result %3d% // IF and SET static OpcodeResult __stdcall opcode_0AA4(CLEO::CRunningScript* thread) { - OPCODE_READ_PARAM_STRING(name); - auto ptr = (HMODULE)OPCODE_READ_PARAM_PTR(); + void* funcPtr = nullptr; - // allow any pointer, not just from 0AA2 + auto paramType = thread->PeekDataType(); + if (IsImmInteger(paramType) || IsVariable(paramType)) + { + auto procedure = OPCODE_READ_PARAM_UINT(); // text pointer or export index - see GetProcAddress docs + auto module = (HMODULE)OPCODE_READ_PARAM_PTR(); - auto funcPtr = (void*)GetProcAddress(ptr, name); + funcPtr = (void*)GetProcAddress(module, (LPCSTR)procedure); + } + else + { + OPCODE_READ_PARAM_STRING(name); + auto module = (HMODULE)OPCODE_READ_PARAM_PTR(); + + funcPtr = (void*)GetProcAddress(module, name); + } OPCODE_WRITE_PARAM_PTR(funcPtr); OPCODE_CONDITION_RESULT(funcPtr != nullptr); diff --git a/tests/cleo_tests/MemoryOperations/0AA4.txt b/tests/cleo_tests/MemoryOperations/0AA4.txt index e746a223..9d3ca25e 100644 --- a/tests/cleo_tests/MemoryOperations/0AA4.txt +++ b/tests/cleo_tests/MemoryOperations/0AA4.txt @@ -8,6 +8,7 @@ terminate_this_custom_script function tests it("should return address of Sleep function from kernel32.dll", test1) + it("should get export by index", test2) return function test1 @@ -24,4 +25,18 @@ function tests assert(false) end end + + function test2 + int load_library_addr = read_memory 0x858070 4 false + + int kernel_dll_addr = call_function_return {address} load_library_addr {numParams} 1 {pop} 0 {funcParams} "kernel32.dll" // tested opcode + if + // lib address can be any valid pointer, not necessarily one loaded with 0AA2 opcode + int sleep_addr = get_dynamic_library_procedure {procName} 1 {DynamicLibrary} kernel_dll_addr + then + assert(true) + else + assert(false) + end + end end