Skip to content

Commit

Permalink
Enabled support of export index as argument of get_proc_address opcode
Browse files Browse the repository at this point in the history
  • Loading branch information
MiranDMC committed Apr 13, 2024
1 parent 95dea91 commit d15c006
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions cleo_plugins/MemoryOperations/MemoryOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d15c006

Please sign in to comment.