Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing contents of char** on a windows x64 cause exception
    primarykey
    data
    text
    <p>The following piece of code is causing an exception on a windows vista x64 and i can't figure why. </p> <pre><code>size_t pBaseAddr; char *lpszFuncName; IMAGE_EXPORT_DIRECTORY *pExportDir; const char **lpszNames; unsigned int dwIndex; lpszNames = ((const char **)(pBaseAddr + pExportDir-&gt;AddressOfNames)); if(lpszNames == NULL) return NULL; for(dwIndex = 0; dwIndex &lt; pExportDir-&gt;NumberOfFunctions; dwIndex++) { if(strcmp((char *)(pBaseAddr + lpszNames[dwIndex]), lpszFuncName) == 0) return Something; } </code></pre> <p>The problem, i think, is on the strcmp() line, specifically on lpszNames[dwIndex]. It works on 32 bits but on 64 it crashes with a access violation. if you want to see the whole code <a href="https://stackoverflow.com/questions/1766031/differences-in-code-between-windows-32-bits-and-64-bits">check my previous question</a></p> <p>EDIT: since people didn't look at the link i posted on the question I will post the entire code from the original question.</p> <pre><code>// Retrieve NT header from base address. IMAGE_NT_HEADERS *GetNtHeaderFromBase( void *pBaseAddr ) { IMAGE_DOS_HEADER *pDosHeader; IMAGE_NT_HEADERS *pNtHeaders; pDosHeader = ((IMAGE_DOS_HEADER *)pBaseAddr); if(pDosHeader-&gt;e_magic != IMAGE_DOS_SIGNATURE) return NULL; pNtHeaders = ((IMAGE_NT_HEADERS *)((DWORD)pBaseAddr + pDosHeader-&gt;e_lfanew)); if(pNtHeaders-&gt;Signature != IMAGE_NT_SIGNATURE) return NULL; return ((pNtHeaders == NULL) ? NULL : pNtHeaders); } // This emulates GetProcAddress. void *GetFuncAddr( size_t pBaseAddr, char *lpszFuncName ) { IMAGE_NT_HEADERS *pNtHeaders; IMAGE_DATA_DIRECTORY *pDataDir; IMAGE_EXPORT_DIRECTORY *pExportDir; const char **lpszNames; size_t *lpdwFuncs, dwIndex; pNtHeaders = GetNtHeaderFromBase((void *)pBaseAddr); if(pNtHeaders == NULL) return NULL; pDataDir = ((IMAGE_DATA_DIRECTORY *)(pNtHeaders-&gt;OptionalHeader.DataDirectory + IMAGE_DIRECTORY_ENTRY_EXPORT)); if(pDataDir == NULL) return NULL; pExportDir = ((IMAGE_EXPORT_DIRECTORY *)(pBaseAddr + pDataDir-&gt;VirtualAddress)); if(pExportDir == NULL) return NULL; lpdwFuncs = ((size_t *)(pBaseAddr + pExportDir-&gt;AddressOfFunctions)); lpszNames = ((const char **)(pBaseAddr + pExportDir-&gt;AddressOfNames)); if(lpdwFuncs == NULL || lpszNames == NULL) return NULL; for(dwIndex = 0; dwIndex &lt; pExportDir-&gt;NumberOfFunctions; dwIndex++) { // decrypt funcname and get the address if(strcmp((char *)(pBaseAddr + lpszNames[dwIndex]), lpszFuncName) == 0) return (void*)(pBaseAddr + lpdwFuncs[dwIndex]); } return NULL; } </code></pre> <p>EDIT2: NO, i am NOT using DWORD.</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