Changeset 5053 for trunk/tools/common
- Timestamp:
- Feb 2, 2001, 9:45:42 AM (25 years ago)
- Location:
- trunk/tools/common
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/common/kDump.cpp
r4360 r5053 1 /* $Id: kDump.cpp,v 1. 1 2000-10-02 04:07:44bird Exp $1 /* $Id: kDump.cpp,v 1.2 2001-02-02 08:45:41 bird Exp $ 2 2 * 3 3 * Generic dumper... … … 39 39 for (argi = 1; argi < argc; argi++) 40 40 { 41 FILE *phFile = fopen(argv[argi], "rb"); 42 if (phFile) 41 try 43 42 { 44 kFileFormatBase *pFile = NULL; 45 try {pFile = new kFilePE(phFile);} 43 kFile file(argv[argi]); 44 kFileFormatBase * pFile = NULL; 45 try {pFile = new kFilePE(&file);} 46 46 catch (int err) 47 47 { 48 //try {pFile = new kFileLX(phFile);}49 //catch (int err)48 try {pFile = new kFileLX(&file);} 49 catch (int err) 50 50 { 51 try {pFile = new kFileDef( phFile);}51 try {pFile = new kFileDef(&file);} 52 52 catch (int err) 53 53 { … … 66 66 delete pFile; 67 67 } 68 fclose(phFile);69 68 } 70 else69 catch (int err) 71 70 { 72 fprintf(stderr, "Fatal: Failed to open file %s .\n", argv[argi]);71 fprintf(stderr, "Fatal: Failed to open file %s err=%d.\n", argv[argi], err); 73 72 return -1; 74 73 } -
trunk/tools/common/kDump.mak
r4712 r5053 1 # $Id: kDump.mak,v 1. 2 2000-12-02 23:26:58bird Exp $1 # $Id: kDump.mak,v 1.3 2001-02-02 08:45:41 bird Exp $ 2 2 3 3 # … … 39 39 # 40 40 OBJS = \ 41 $(OBJDIR)\kDump.obj 41 $(OBJDIR)\kDump.obj \ 42 $(COMMONLIB) 42 43 43 44 … … 46 47 # 47 48 LIBS = \ 48 $(COMMONLIB) \49 49 $(RTLLIB) \ 50 50 os2386.lib -
trunk/tools/common/kFileFormatBase.cpp
r4358 r5053 1 /* $Id: kFileFormatBase.cpp,v 1. 2 2000-10-02 04:01:39bird Exp $1 /* $Id: kFileFormatBase.cpp,v 1.3 2001-02-02 08:45:41 bird Exp $ 2 2 * 3 3 * kFileFormatBase - Base class for kFile<format> classes. … … 20 20 #include <stdio.h> 21 21 22 #include "kFile.h" 22 23 #include "kFileFormatBase.h" 23 24 … … 79 80 BOOL kFileFormatBase::dump(kFile *pOut) 80 81 { 81 pOut = pOut;82 pOut->printf("Sorry, dump() is not implemented for this file format.\n"); 82 83 return FALSE; 83 84 } -
trunk/tools/common/kFileLX.cpp
r4750 r5053 1 /* $Id: kFileLX.cpp,v 1. 3 2000-12-04 08:48:08bird Exp $1 /* $Id: kFileLX.cpp,v 1.4 2001-02-02 08:45:41 bird Exp $ 2 2 * 3 3 * … … 46 46 #include <assert.h> 47 47 48 #include "kFile.h" 48 49 #include "kFileFormatBase.h" 49 50 #include "kInterfaces.h" … … 112 113 * @param pszFilename LX executable image name. 113 114 */ 114 kFileLX::kFileLX(const char *pszFilename) 115 kFileLX::kFileLX(const char *pszFilename) throw (int) 115 116 : pvBase(NULL) 116 117 { … … 119 120 /* create filemapping */ 120 121 pvBase = kFileFormatBase::readfile(pszFilename); 122 if (pvBase == NULL) 123 throw(1); 124 125 pehdr = (struct exe_hdr*)pvBase; 126 if (pehdr->e_magic == EMAGIC) 127 offLXHdr = pehdr->e_lfanew; 128 else 129 offLXHdr = 0; 130 131 pe32 = (struct e32_exe*)((char*)pvBase + offLXHdr); 132 if (*(PUSHORT)pe32 != E32MAGIC) 133 { 134 free(pvBase); 135 pvBase = NULL; 136 throw(2); 137 } 138 139 paObject = pe32->e32_objtab && pe32->e32_objcnt 140 ? (struct o32_obj*)((char*)pvBase + pe32->e32_objtab + offLXHdr) : NULL; 141 paMap = pe32->e32_objmap 142 ? (struct o32_map*)((char*)pvBase + pe32->e32_objmap + offLXHdr) : NULL; 143 } 144 145 146 /** 147 * Create an LX file object from an LX executable image. 148 * @param pFile Pointer to opened LX file. 149 */ 150 kFileLX::kFileLX(kFile *pFile) throw (int) 151 : pvBase(NULL) 152 { 153 struct exe_hdr * pehdr; 154 155 /* create filemapping */ 156 pvBase = pFile->readFile(); 121 157 if (pvBase == NULL) 122 158 throw(1); -
trunk/tools/common/kFileLX.h
r4750 r5053 1 /* $Id: kFileLX.h,v 1. 3 2000-12-04 08:48:09bird Exp $1 /* $Id: kFileLX.h,v 1.4 2001-02-02 08:45:41 bird Exp $ 2 2 * 3 3 * kFileLX - Linear Executable file reader. … … 28 28 29 29 public: 30 kFileLX(const char *pszFilename); 30 kFileLX(const char *pszFilename) throw (int); 31 kFileLX(kFile *pFile) throw (int); 31 32 ~kFileLX(); 32 33 -
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 */ -
trunk/tools/common/kFilePE.h
r4358 r5053 80 80 81 81 public: 82 kFilePE( FILE *phFile) throw(int);82 kFilePE(kFile *pFile) throw(int); 83 83 virtual ~kFilePE(); 84 84 -
trunk/tools/common/makefile
r4804 r5053 1 # $Id: makefile,v 1.1 1 2000-12-16 20:10:07bird Exp $1 # $Id: makefile,v 1.12 2001-02-02 08:45:42 bird Exp $ 2 2 3 3 # … … 32 32 $(OBJDIR)\common.a \ 33 33 !endif 34 $(ODIN32_TOOLS)\kDef2Wat.exe 35 #$(ODIN32_TOOLS)\kDump.exe34 $(ODIN32_TOOLS)\kDef2Wat.exe \ 35 $(ODIN32_TOOLS)\kDump.exe 36 36 37 37
Note:
See TracChangeset
for help on using the changeset viewer.