Changeset 5053 for trunk/tools/common/kFilePE.cpp
- Timestamp:
- Feb 2, 2001, 9:45:42 AM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/common/kFilePE.cpp
r4358 r5053 41 41 /** 42 42 * Constructs a kFilePE object for a file. 43 * @param p hFileFile to create object from.43 * @param pFile File to create object from. 44 44 * @remark throws errorcode (TODO: errorhandling.) 45 45 */ 46 kFilePE::kFilePE( FILE *phFile) throw(int) : pvBase(NULL),46 kFilePE::kFilePE(kFile *pFile) throw(int) : pvBase(NULL), 47 47 pDosHdr(NULL), pFileHdr(NULL), pOptHdr(NULL), paDataDir(NULL), paSectionHdr(NULL), 48 48 pExportDir(NULL), … … 62 62 63 63 /* read dos-header - assumes there is one */ 64 if (!fseek(phFile, 0, SEEK_SET) 65 && fread(&doshdr, sizeof(doshdr), 1, phFile) == 1 64 if ( pFile->readAt(&doshdr, sizeof(doshdr), 0) 66 65 && doshdr.e_magic == IMAGE_DOS_SIGNATURE 67 66 && doshdr.e_lfanew > sizeof(doshdr) … … 71 70 72 71 /* read pe headers */ 73 if (!fseek(phFile, doshdr.e_lfanew, SEEK_SET) 74 && fread(&pehdr, sizeof(pehdr), 1, phFile) == 1 72 if ( pFile->readAt(&pehdr, sizeof(pehdr), doshdr.e_lfanew) 75 73 && pehdr.Signature == IMAGE_NT_SIGNATURE 76 74 && pehdr.FileHeader.SizeOfOptionalHeader == sizeof(IMAGE_OPTIONAL_HEADER) … … 78 76 { 79 77 /* create mapping */ 80 pvBase = malloc((size_t)pehdr.OptionalHeader.SizeOfImage);78 pvBase = calloc((size_t)pehdr.OptionalHeader.SizeOfImage, 1); 81 79 if (pvBase != NULL) 82 80 { 83 memset(pvBase, 0, (size_t)pehdr.OptionalHeader.SizeOfImage);84 81 /* 85 82 printf("%ld\n", pehdr.OptionalHeader.SizeOfHeaders); … … 88 85 sizeof(IMAGE_NT_HEADERS) + sizeof(IMAGE_SECTION_HEADER) * pehdr.FileHeader.NumberOfSections); 89 86 */ 90 if (!fseek(phFile, 0, SEEK_SET) 91 && fread(pvBase, (size_t)pehdr.OptionalHeader.SizeOfHeaders, 1, phFile) == 1 92 ) 87 if (pFile->readAt(pvBase, pehdr.OptionalHeader.SizeOfHeaders, 0)) 93 88 { 94 89 /* read sections */ … … 105 100 106 101 cbSection = min(pSectionHdr->Misc.VirtualSize, pSectionHdr->SizeOfRawData); 107 if (cbSection 108 && 109 (fseek(phFile, pSectionHdr->PointerToRawData, SEEK_SET) 110 || 111 fread((void*)((ULONG)pvBase + pSectionHdr->VirtualAddress), (size_t)cbSection, 1, phFile) != 1 112 ) 102 if ( cbSection 103 && !pFile->readAt((char*)pvBase + pSectionHdr->VirtualAddress, 104 cbSection, 105 pSectionHdr->PointerToRawData) 113 106 ) 114 107 { … … 286 279 paSectionHdr[i].Characteristics 287 280 ); 288 289 }281 } 282 pOut->printf("\n"); 290 283 291 284 … … 328 321 329 322 /* 323 * Dump Import Directory if present. 324 */ 325 if (pImportDir) 326 { 327 pOut->printf("Import Directory\n" 328 "----------------\n"); 329 330 PIMAGE_IMPORT_DESCRIPTOR pCur = pImportDir; 331 while (pCur->u.Characteristics != 0) 332 { 333 pOut->printf("%s\n", (char*)pvBase + pCur->Name); 334 pCur++; 335 } 336 } 337 338 339 /* 330 340 * Dump TLS directory if present 331 341 */
Note:
See TracChangeset
for help on using the changeset viewer.