Error when dumping PE file
-
Hi In my program i want to use
BOOL MapAndLoad( PSTR ImageName, PSTR DllPath, PLOADED_IMAGE LoadedImage, BOOL DotDll, BOOL ReadOnly );
function in Imagehlp.h .CPE::CPE(CString fileName, CString filePath):fileName(fileName),filePath(filePath) { LOADED_IMAGE loi; ::MapAndLoad((LPSTR)(LPCTSTR)fileName, (LPSTR)(LPCTSTR)filePath, &loi,FALSE, TRUE); int i = loi.NumberOfSections; char q[50]; sprintf(q,"%d",i); MessageBox(NULL, q,NULL,0); }
When i compiled and execute it. It gives error Messagebox with value -858993460 . I changed my projects setting use multibyte character set. wchar_t to char. But can not find solution. What is wrong with this code? How can i fix it? Thanks. -
Hi In my program i want to use
BOOL MapAndLoad( PSTR ImageName, PSTR DllPath, PLOADED_IMAGE LoadedImage, BOOL DotDll, BOOL ReadOnly );
function in Imagehlp.h .CPE::CPE(CString fileName, CString filePath):fileName(fileName),filePath(filePath) { LOADED_IMAGE loi; ::MapAndLoad((LPSTR)(LPCTSTR)fileName, (LPSTR)(LPCTSTR)filePath, &loi,FALSE, TRUE); int i = loi.NumberOfSections; char q[50]; sprintf(q,"%d",i); MessageBox(NULL, q,NULL,0); }
When i compiled and execute it. It gives error Messagebox with value -858993460 . I changed my projects setting use multibyte character set. wchar_t to char. But can not find solution. What is wrong with this code? How can i fix it? Thanks.sawerr wrote:
What is wrong with this code?
You did not check the return value from
MapAndLoad()
, nor did you callGetLastError()
.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
sawerr wrote:
What is wrong with this code?
You did not check the return value from
MapAndLoad()
, nor did you callGetLastError()
.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
I checked the return value, it is not TRUE MapAndLoad() is not working. I changed code because of pstr parameters.
CPE::CPE(CString fileName, CString filePath):fileName(fileName),filePath(filePath) { char *ch1 = strdup(fileName); char *ch2 = strdup(filePath); MessageBox(NULL, ch1, ch2, 0); PLOADED_IMAGE loi = ::ImageLoad((PSTR)ch1, (PSTR)ch2); BOOL b = ::MapAndLoad(ch1, ch2, loi,TRUE, TRUE); if(b == TRUE) { MessageBox(NULL, "DONE", NULL, 0); } ULONG i = loi->NumberOfSections; char q[50]; sprintf(q,"%d",i); MessageBox(NULL, q,NULL,0); }
fileName and filePath parameters correct (they are coming from CFileDialog) but it gives run-time error in line ULONG i = loi->NumberOfSections; Unhandled exception at 0x76c977f2 in PEInside.exe: 0xC0000005: Access violation writing location 0x00000004. Do you have any suggestions? -
I checked the return value, it is not TRUE MapAndLoad() is not working. I changed code because of pstr parameters.
CPE::CPE(CString fileName, CString filePath):fileName(fileName),filePath(filePath) { char *ch1 = strdup(fileName); char *ch2 = strdup(filePath); MessageBox(NULL, ch1, ch2, 0); PLOADED_IMAGE loi = ::ImageLoad((PSTR)ch1, (PSTR)ch2); BOOL b = ::MapAndLoad(ch1, ch2, loi,TRUE, TRUE); if(b == TRUE) { MessageBox(NULL, "DONE", NULL, 0); } ULONG i = loi->NumberOfSections; char q[50]; sprintf(q,"%d",i); MessageBox(NULL, q,NULL,0); }
fileName and filePath parameters correct (they are coming from CFileDialog) but it gives run-time error in line ULONG i = loi->NumberOfSections; Unhandled exception at 0x76c977f2 in PEInside.exe: 0xC0000005: Access violation writing location 0x00000004. Do you have any suggestions?If
MapAndLoad()
is returning0
, why are you then proceeding to dereferenceloi
?sawerr wrote:
Do you have any suggestions?
Yes.
BOOL b = ::MapAndLoad(ch1, ch2, loi, TRUE, TRUE);
if (b)
{
CString q;q.Format("%lu", loi->NumberOfSections); AfxMessageBox(q);
}
else
{
CString q;q.Format("%lu", GetLastError()); AfxMessageBox(q);
}
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
If
MapAndLoad()
is returning0
, why are you then proceeding to dereferenceloi
?sawerr wrote:
Do you have any suggestions?
Yes.
BOOL b = ::MapAndLoad(ch1, ch2, loi, TRUE, TRUE);
if (b)
{
CString q;q.Format("%lu", loi->NumberOfSections); AfxMessageBox(q);
}
else
{
CString q;q.Format("%lu", GetLastError()); AfxMessageBox(q);
}
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne