Changeset 4358 for trunk/tools
- Timestamp:
- Oct 2, 2000, 6:01:40 AM (25 years ago)
- Location:
- trunk/tools/common
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/common/kFile.cpp
r4129 r4358 1 /* $Id: kFile.cpp,v 1. 4 2000-08-31 03:00:12bird Exp $1 /* $Id: kFile.cpp,v 1.5 2000-10-02 04:01:39 bird Exp $ 2 2 * 3 3 * kFile - Simple (for the time being) file class. 4 4 * 5 * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@ pmsc.no)5 * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no) 6 6 * 7 7 * Project Odin Software License can be found in LICENSE.TXT … … 26 26 #include <stdio.h> 27 27 28 #include <kFile.h> 28 #include "kFile.h" 29 30 /******************************************************************************* 31 * Global Variables * 32 *******************************************************************************/ 33 kFile kFile::StdIn((HFILE)0, TRUE); 34 kFile kFile::StdOut((HFILE)1, FALSE); 35 kFile kFile::StdErr((HFILE)2, FALSE); 29 36 30 37 … … 37 44 BOOL kFile::refreshFileStatus() 38 45 { 46 if (fStdDev) 47 return fStatusClean = TRUE; 48 39 49 if (!fStatusClean) 40 50 { … … 77 87 } 78 88 89 /** 90 * Creates a kFile object for a file that is opened allready. 91 * Intended use for the three standard handles only. 92 * 93 * @returns <object> with state updated. 94 * @param pszFilename Filename. 95 * @param fReadOnly TRUE: Open the file readonly. 96 * FALSE: Open the file readwrite appending 97 * existing files. 98 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 99 */ 100 kFile::kFile(HFILE hFile, BOOL fReadOnly) 101 : fReadOnly(fReadOnly), 102 fStatusClean(FALSE), 103 fThrowErrors(FALSE), 104 offVirtual(0), 105 offReal(0), 106 pszFilename(NULL), 107 hFile(hFile), 108 fStdDev(TRUE) 109 { 110 if (!refreshFileStatus()) 111 throw ((int)rc); 112 this->pszFilename = strdup(""); 113 } 114 79 115 80 116 /** … … 86 122 * FALSE: Open the file readwrite appending 87 123 * existing files. 88 * @author knut st. osmundsen (knut.stange.osmundsen@ pmsc.no)124 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 89 125 */ 90 126 kFile::kFile(const char *pszFilename, BOOL fReadOnly/*=TRUE*/) … … 94 130 offVirtual(0), 95 131 offReal(0), 96 pszFilename(NULL) 132 pszFilename(NULL), 133 fStdDev(FALSE) 97 134 { 98 135 ULONG fulOpenFlags; -
trunk/tools/common/kFile.h
r4129 r4358 1 /* $Id: kFile.h,v 1. 4 2000-08-31 03:00:13bird Exp $1 /* $Id: kFile.h,v 1.5 2000-10-02 04:01:39 bird Exp $ 2 2 * 3 3 * kFile - Simple (for the time being) file class. … … 26 26 HFILE hFile; /* Pointer to stdio filehandle */ 27 27 BOOL fReadOnly; /* True if readonly access, False is readwrite. */ 28 BOOL fStdDev; /* True if stdio, stderr or stdin. Filestatus is invalid with this is set.*/ 28 29 APIRET rc; /* Last error (return code). */ 29 30 FILESTATUS4 filestatus; /* Filestatus data. */ … … 42 43 BOOL position() throw(int); 43 44 45 /** @cat constructors */ 46 private: 47 kFile(HFILE hFile, BOOL fReadOnly); 44 48 public: 45 /** @cat constructor */46 49 kFile(const char *pszFilename, BOOL fReadOnly = TRUE) throw(int); 47 50 ~kFile(); … … 75 78 BOOL setFailOnErrors(); 76 79 int getLastError() const; 80 81 /** standard files */ 82 static kFile StdOut; 83 static kFile StdIn; 84 static kFile StdErr; 77 85 }; 78 86 -
trunk/tools/common/kFileFormatBase.cpp
r3246 r4358 1 /* $Id: kFileFormatBase.cpp,v 1. 1 2000-03-27 10:18:40bird Exp $1 /* $Id: kFileFormatBase.cpp,v 1.2 2000-10-02 04:01:39 bird Exp $ 2 2 * 3 3 * kFileFormatBase - Base class for kFile<format> classes. … … 71 71 return pvFile; 72 72 } 73 74 /** 75 * Dump function. 76 * @returns Successindicator. 77 * @param pOut Output file. 78 */ 79 BOOL kFileFormatBase::dump(kFile *pOut) 80 { 81 pOut = pOut; 82 return FALSE; 83 } 84 -
trunk/tools/common/kFileFormatBase.h
r4129 r4358 1 /* $Id: kFileFormatBase.h,v 1. 3 2000-08-31 03:00:13bird Exp $1 /* $Id: kFileFormatBase.h,v 1.4 2000-10-02 04:01:39 bird Exp $ 2 2 * 3 3 * kFileFormatBase - Base class for kFile<format> classes. … … 23 23 ******************************************************************************/ 24 24 #pragma pack(4) 25 26 class kFile; 25 27 26 28 /** … … 57 59 58 60 static void * readfile(const char *pszFilename); 61 virtual BOOL dump(kFile *pOut); 59 62 }; 60 63 -
trunk/tools/common/kFilePE.cpp
r824 r4358 34 34 #include <assert.h> 35 35 #include <peexe.h> 36 #include "kFile.h" 36 37 #include "kFileFormatBase.h" 37 38 #include "kFilePe.h" … … 45 46 kFilePE::kFilePE(FILE *phFile) throw(int) : pvBase(NULL), 46 47 pDosHdr(NULL), pFileHdr(NULL), pOptHdr(NULL), paDataDir(NULL), paSectionHdr(NULL), 47 pExportDir(NULL) 48 pExportDir(NULL), 49 pImportDir(NULL), 50 pRsrcDir(NULL), 51 pBRelocDir(NULL), 52 pDebugDir(NULL), 53 pCopyright(NULL), 54 pulGlobalPtr(NULL), 55 pTLSDir(NULL), 56 pLoadConfigDir(NULL), 57 pBoundImportDir(NULL), 58 pIATDir(NULL), 59 pDelayImportDir(NULL) 48 60 { 49 61 IMAGE_DOS_HEADER doshdr; … … 93 105 94 106 cbSection = min(pSectionHdr->Misc.VirtualSize, pSectionHdr->SizeOfRawData); 95 if (fseek(phFile, pSectionHdr->PointerToRawData, SEEK_SET) 96 || 97 fread((void*)((ULONG)pvBase + pSectionHdr->VirtualAddress), (size_t)cbSection, 1, phFile) != 1 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 ) 98 113 ) 99 114 { … … 120 135 pOptHdr->NumberOfRvaAndSizes*sizeof(*paDataDir)); 121 136 122 if (paDataDir[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress) 123 pExportDir = (PIMAGE_EXPORT_DIRECTORY)((int)pvBase + paDataDir[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress); 137 //if (paDataDir[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress) 138 // pExportDir = (PIMAGE_EXPORT_DIRECTORY)((int)pvBase + paDataDir[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress); 139 for (i = 0; i < pOptHdr->NumberOfRvaAndSizes && i < 16; i++) 140 { 141 if (paDataDir[i].VirtualAddress != 0) 142 { 143 if (paDataDir[i].VirtualAddress < pOptHdr->SizeOfImage) 144 ((PULONG)&this->pExportDir)[i] = (int)pvBase + paDataDir[i].VirtualAddress; 145 #ifdef DEBUG 146 else 147 fprintf(stderr, "bad directory pointer %d\n", i); 148 #endif 149 } 150 } 124 151 } 125 152 else … … 227 254 228 255 256 /** 257 * Mini dump function. 258 */ 259 BOOL kFilePE::dump(kFile *pOut) 260 { 261 int i,j,k; 262 int c; 263 264 /* 265 * Dump sections. 266 */ 267 pOut->printf("Sections\n" 268 "--------\n"); 269 for (i = 0; i < pFileHdr->NumberOfSections; i++) 270 { 271 pOut->printf("%2d %-8.8s VirtSize: 0x%08x RVA: 0x%08x\n" 272 " RawSize: 0x%08x FileOffset: 0x%08x\n" 273 " #Relocs: 0x%08x FileOffset: 0x%08x\n" 274 " #LineNbr: 0x%08x FileOffset: 0x%08x\n" 275 " Characteristics: 0x%08x\n", 276 i, 277 paSectionHdr[i].Name, 278 paSectionHdr[i].Misc.VirtualSize, 279 paSectionHdr[i].VirtualAddress, 280 paSectionHdr[i].PointerToRawData, 281 paSectionHdr[i].PointerToRawData, 282 paSectionHdr[i].NumberOfRelocations, 283 paSectionHdr[i].PointerToRelocations, 284 paSectionHdr[i].NumberOfLinenumbers, 285 paSectionHdr[i].PointerToLinenumbers, 286 paSectionHdr[i].Characteristics 287 ); 288 289 } 290 291 292 /* 293 * Dump the directories. 294 */ 295 pOut->printf("Data Directory\n" 296 "--------------\n"); 297 for (i = 0; i < pOptHdr->NumberOfRvaAndSizes; i++) 298 { 299 static const char * apszDirectoryNames[] = 300 { 301 "Export", 302 "Import", 303 "Resource", 304 "Exception", 305 "Security", 306 "Base Reloc", 307 "Debug", 308 "Copyright", 309 "Global Ptr", 310 "TLS", 311 "Load Config", 312 "Bound Import", 313 "IAT", 314 "Delay Import", 315 "COM Descriptor", 316 "unknown", 317 "unknown" 318 }; 319 320 pOut->printf("%2d %-16s Size: 0x%08x RVA: 0x%08x\n", 321 i, 322 apszDirectoryNames[i], 323 pOptHdr->DataDirectory[i].Size, 324 pOptHdr->DataDirectory[i].VirtualAddress); 325 } 326 pOut->printf("\n"); 327 328 329 /* 330 * Dump TLS directory if present 331 */ 332 if (pTLSDir) 333 { 334 pOut->printf("TLS Directory\n" 335 "-------------\n"); 336 if (pOptHdr->DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS].Size % sizeof(IMAGE_TLS_DIRECTORY)) 337 pOut->printf(" Warning! The size directory isn't a multiple of the directory struct!"); 338 339 c = (int)(pOptHdr->DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS].Size / sizeof(IMAGE_TLS_DIRECTORY)); 340 for (i = 0; i < c; i++) 341 { 342 343 pOut->printf("%2d StartAddressOfRawData %p\n" 344 " EndAddressOfRawData %p\n" 345 " AddressOfIndex %p\n" 346 " AddressOfCallBacks %p\n" 347 " SizeOfZeroFill %p\n" 348 " Characteristics %p\n", 349 i, 350 pTLSDir[i].StartAddressOfRawData, 351 pTLSDir[i].EndAddressOfRawData, 352 pTLSDir[i].AddressOfIndex, 353 pTLSDir[i].AddressOfCallBacks, 354 pTLSDir[i].SizeOfZeroFill, 355 pTLSDir[i].Characteristics); 356 357 /* Print Callbacks */ 358 if (pTLSDir[i].AddressOfCallBacks) 359 { 360 PULONG paulIndex; 361 PULONG paulCallback; 362 ULONG ulBorlandRVAFix = 0UL; 363 364 /* Check if the addresses in the TLSDir is RVAs or real addresses */ 365 if (pTLSDir[i].StartAddressOfRawData > pOptHdr->ImageBase) 366 ulBorlandRVAFix = pOptHdr->ImageBase; 367 368 j = 0; 369 paulIndex = (PULONG)((ULONG)pTLSDir[i].AddressOfIndex - ulBorlandRVAFix + (ULONG)this->pvBase); 370 paulCallback = (PULONG)((ULONG)pTLSDir[i].AddressOfCallBacks - ulBorlandRVAFix + (ULONG)this->pvBase); 371 if (*paulCallback) 372 { 373 pOut->printf(" Callbacks:\n"); 374 for (j = 0; paulCallback[j] != 0; j++) 375 { 376 pOut->printf(" %02d Address: 0x%08x Index: 0x%08x\n", 377 paulIndex[j], 378 paulCallback[j]); 379 } 380 } 381 else 382 pOut->printf(" (Empty callback array!)\n"); 383 } 384 385 } 386 387 pOut->printf("\n"); 388 } 389 390 391 return TRUE; 392 } 393 -
trunk/tools/common/kFilePE.h
r824 r4358 7 7 8 8 #ifndef _kFilePE_h_ 9 #define 9 #define _kFilePE_h_ 10 10 11 11 /******************************************************************************* 12 12 * Defined Constants * 13 13 *******************************************************************************/ 14 14 15 #if !defined(__WINE_PEEXE_H) && !defined(_WINNT_) 16 #if 0 15 17 #define PIMAGE_DOS_HEADER void* 16 18 #define PIMAGE_FILE_HEADER void* … … 18 20 #define PIMAGE_DATA_DIRECTORY void* 19 21 #define PIMAGE_SECTION_HEADER void* 20 #define PIMAGE_EXPORT_DIRECTORY void* 22 #define PIMAGE_EXPORT_DIRECTORY void* 23 #define PIMAGE_IMPORT_DESCRIPTOR void* 24 #define PIMAGE_RESOURCE_DIRECTORY void* 25 #define PIMAGE_BASE_RELOCATION void* 26 #define PIMAGE_DEBUG_DIRECTORY void* 27 #define PSZ void* 28 #define PULONG void* 29 #define PIMAGE_TLS_DIRECTORY void* 30 #define PIMAGE_LOAD_CONFIG_DIRECTORY void* 31 #define PIMAGE_IMPORT_DESCRIPTOR void* 32 #define PIMAGE_THUNK_DATA void* 33 #define PIMAGE_IMPORT_DESCRIPTOR void* 34 #else 35 #include <peexe.h> 36 #endif 21 37 #endif 22 38 … … 43 59 PIMAGE_SECTION_HEADER paSectionHdr; 44 60 45 /* directories */ 46 PIMAGE_EXPORT_DIRECTORY pExportDir; 61 /** @cat 62 * Directory pointers. 63 */ 64 PIMAGE_EXPORT_DIRECTORY pExportDir; /* 0 */ 65 PIMAGE_IMPORT_DESCRIPTOR pImportDir; /* 1 */ 66 PIMAGE_RESOURCE_DIRECTORY pRsrcDir; /* 2 */ 67 PVOID pExcpDir; /* 3 */ 68 PVOID pSecDir; /* 4 */ 69 PIMAGE_BASE_RELOCATION pBRelocDir; /* 5 */ 70 PIMAGE_DEBUG_DIRECTORY pDebugDir; /* 6 */ 71 PSZ pCopyright; /* 7 */ 72 PULONG pulGlobalPtr; /* 8 */ //is this the correct pointer type? 73 PIMAGE_TLS_DIRECTORY pTLSDir; /* 9 */ 74 PIMAGE_LOAD_CONFIG_DIRECTORY pLoadConfigDir; /* 10 */ 75 PIMAGE_IMPORT_DESCRIPTOR pBoundImportDir;/* 11 */ //is this the correct pointer type? 76 PIMAGE_THUNK_DATA pIATDir; /* 12 */ //is this the correct pointer type? 77 PIMAGE_IMPORT_DESCRIPTOR pDelayImportDir;/* 13 */ 78 PVOID pComDir; /* 14 */ 79 PVOID pv15; /* 15 */ 47 80 48 81 public: … … 55 88 BOOL findNextExport(PEXPORTENTRY pExport); 56 89 BOOL isPe() const { return TRUE;} 90 91 BOOL dump(kFile *pOut); 57 92 }; 58 93 -
trunk/tools/common/makefile
r3534 r4358 1 # $Id: makefile,v 1. 5 2000-05-13 16:04:43bird Exp $1 # $Id: makefile,v 1.6 2000-10-02 04:01:40 bird Exp $ 2 2 3 3 # … … 18 18 # 19 19 20 PDWIN32_INCLUDE = ..\..\include 21 PDWIN32_TOOLS = ..\bin 22 !include $(PDWIN32_INCLUDE)\pdwin32.mk 23 24 25 !ifdef DEBUG 26 MAKE_CMD = $(MAKE) -nologo DEBUG=1 27 !else 28 MAKE_CMD = $(MAKE) -nologo 29 !endif 20 !include ..\..\include\pdwin32.mk 30 21 31 22 … … 48 39 @$(MAKE_CMD) OMF=1 -f makefile.gcc 49 40 41 kDump.exe: dummy 42 -@echo $@ 43 @$(MAKE_CMD) -f makefile.icc kDump.exe 44 50 45 51 46 #a simple hack to make nmake process the target. -
trunk/tools/common/makefile.icc
r3592 r4358 1 # $Id: makefile.icc,v 1.1 0 2000-05-23 18:23:04bird Exp $1 # $Id: makefile.icc,v 1.11 2000-10-02 04:01:40 bird Exp $ 2 2 3 3 # … … 52 52 53 53 54 # CommonICC 54 55 commonicc.lib: $(OBJDIR)\commonicc.lib 55 56 $(CP) $** $@ … … 58 59 $(RM) $@ 59 60 $(ILIB) /nobackup $@ $(OBJS: = +), NUL; 61 62 # kDump 63 kDump.exe: $(OBJDIR)\kDump.exe 64 $(CP) $** $@ 65 66 $(OBJDIR)\kDump.exe: commonicc.lib $(OBJDIR)\kDump.obj 67 $(LD) $(LDFLAGS) -Fe$@ $** $(RTLLIB) OS2386.LIB 60 68 61 69
Note:
See TracChangeset
for help on using the changeset viewer.