Note that there are some explanatory texts on larger screens.

plurals
  1. POdynamic load on Windows 7 fails
    primarykey
    data
    text
    <p>As I mentioned on one my previous questions I am playing with simulating GetProcAddress() in my code. The following code is successful in doing this, however it causes the application to crash on windows 7</p> <pre><code>void *GetFuncAddr(HMODULE hModule, char *fname) { unsigned int count = 1; IMAGE_DOS_HEADER *DosHeader; IMAGE_NT_HEADERS *NtHeaders; IMAGE_OPTIONAL_HEADER *OptionalHeader; IMAGE_DATA_DIRECTORY *DataDirectory; IMAGE_EXPORT_DIRECTORY *Exp; ULONG *addrof; char *fullfname; ULONG *faddr; DosHeader = (IMAGE_DOS_HEADER *)hModule; if (DosHeader-&gt;e_magic != IMAGE_DOS_SIGNATURE) { return NULL; } NtHeaders = (IMAGE_NT_HEADERS *)(((BYTE *)DosHeader) + DosHeader-&gt;e_lfanew); if (NtHeaders-&gt;Signature != IMAGE_NT_SIGNATURE) { return NULL; } OptionalHeader = &amp;NtHeaders-&gt;OptionalHeader; DataDirectory = &amp;OptionalHeader-&gt;DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT]; Exp = (IMAGE_EXPORT_DIRECTORY *)((size_t)DosHeader + DataDirectory-&gt;VirtualAddress); addrof = (ULONG *)((BYTE*) hModule + Exp-&gt;addrof); faddr = (ULONG*) ((BYTE*) hModule + Exp-&gt;AddressOfFunctions); for(count = 0; count &lt; Exp-&gt;NumberOfNames; count++) { fullfname = (char*)((BYTE*) hModule + addrof[count]); if(strcmp(fullfname, fname) == 0) { return (void*)((BYTE*) hModule + faddr[count]); } } return NULL; } </code></pre> <p>It doesn't matter what function I tried loading using this the application crashes. The crashes occurs when calling the imported function so my guess is that the pointer returned might be the offending thing here. This occurs on both x86 and x64. Is there any visible reason for this in this code?</p> <p>I tried setting the function to return FARPROC but I'm getting all confused about how to cast the return on ((BYTE*) hModule + faddr[count]);</p> <p>Anyway, any ideas? solutions? Any help is appreciated.</p> <p>Thanks. jess.</p> <p><strong>EDIT</strong> The error returned by some of the API's i am importing is error 18, the parameter is incorrect.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload