Skip to content

How can load references dll still using MemoryLoadLibrary #119

Description

@jeffjiang0613

I have a library named a.dll, a.dll has a reference b.dll.
When I want to use MemoryLoadLibrary to load a.dll, the default references loader is LoadLibraryA, when I changed the loader to my own loader like the code below, it crashed. How to change the return value of MemoryLoadLibraryEx to a value like the return value of LoadLibraryA?

HCUSTOMMODULE LoadLibrary_R(LPCSTR filename, void* userdata)
{
      bool isFound = false;
      for(auto it: names)
      {
          if (strcmp(it, filename) == 0) {
              isFound = true;
              break;
          }
      }

    if (isFound) {
        size_t size;
        auto buffer = readFileToBuffer(filename, &size);
        auto t = (HMODULE)((PMEMORYMODULE)MemoryLoadLibraryEx(buffer, LoadLibrary_R, _GetProcAddress, _FreeLibrary, NULL))->codeBase;
        //still wrong
        //auto t = (HMODULE)MemoryLoadLibraryEx(buffer, LoadLibrary_R, _GetProcAddress, _FreeLibrary, NULL));
        return t;
    }
    else {
        HMODULE result = LoadLibraryA(filename);
        if (result == NULL) {
            return NULL;
        }
        return (HCUSTOMMODULE)result;
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions