Changeset 5053 for trunk/tools/common


Ignore:
Timestamp:
Feb 2, 2001, 9:45:42 AM (25 years ago)
Author:
bird
Message:

Corrected kFileLX and kFilePE constructors.
Made kDump.exe work again.
Added import module dump to kFilePE.

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:44 bird Exp $
     1/* $Id: kDump.cpp,v 1.2 2001-02-02 08:45:41 bird Exp $
    22 *
    33 * Generic dumper...
     
    3939    for (argi = 1; argi < argc; argi++)
    4040    {
    41         FILE *phFile = fopen(argv[argi], "rb");
    42         if (phFile)
     41        try
    4342        {
    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);}
    4646            catch (int err)
    4747            {
    48                 //try {pFile = new kFileLX(phFile);}
    49                 //catch (int err)
     48                try {pFile = new kFileLX(&file);}
     49                catch (int err)
    5050                {
    51                     try {pFile = new kFileDef(phFile);}
     51                    try {pFile = new kFileDef(&file);}
    5252                    catch (int err)
    5353                    {
     
    6666                delete pFile;
    6767            }
    68             fclose(phFile);
    6968        }
    70         else
     69        catch (int err)
    7170        {
    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);
    7372            return -1;
    7473        }
  • trunk/tools/common/kDump.mak

    r4712 r5053  
    1 # $Id: kDump.mak,v 1.2 2000-12-02 23:26:58 bird Exp $
     1# $Id: kDump.mak,v 1.3 2001-02-02 08:45:41 bird Exp $
    22
    33#
     
    3939#
    4040OBJS = \
    41 $(OBJDIR)\kDump.obj
     41$(OBJDIR)\kDump.obj \
     42$(COMMONLIB)
    4243
    4344
     
    4647#
    4748LIBS = \
    48 $(COMMONLIB) \
    4949$(RTLLIB) \
    5050os2386.lib
  • trunk/tools/common/kFileFormatBase.cpp

    r4358 r5053  
    1 /* $Id: kFileFormatBase.cpp,v 1.2 2000-10-02 04:01:39 bird Exp $
     1/* $Id: kFileFormatBase.cpp,v 1.3 2001-02-02 08:45:41 bird Exp $
    22 *
    33 * kFileFormatBase - Base class for kFile<format> classes.
     
    2020#include <stdio.h>
    2121
     22#include "kFile.h"
    2223#include "kFileFormatBase.h"
    2324
     
    7980BOOL   kFileFormatBase::dump(kFile *pOut)
    8081{
    81     pOut = pOut;
     82    pOut->printf("Sorry, dump() is not implemented for this file format.\n");
    8283    return FALSE;
    8384}
  • trunk/tools/common/kFileLX.cpp

    r4750 r5053  
    1 /* $Id: kFileLX.cpp,v 1.3 2000-12-04 08:48:08 bird Exp $
     1/* $Id: kFileLX.cpp,v 1.4 2001-02-02 08:45:41 bird Exp $
    22 *
    33 *
     
    4646#include <assert.h>
    4747
     48#include "kFile.h"
    4849#include "kFileFormatBase.h"
    4950#include "kInterfaces.h"
     
    112113 * @param     pszFilename   LX executable image name.
    113114 */
    114 kFileLX::kFileLX(const char *pszFilename)
     115kFileLX::kFileLX(const char *pszFilename)  throw (int)
    115116: pvBase(NULL)
    116117{
     
    119120    /* create filemapping */
    120121    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 */
     150kFileLX::kFileLX(kFile *pFile) throw (int)
     151: pvBase(NULL)
     152{
     153    struct exe_hdr * pehdr;
     154
     155    /* create filemapping */
     156    pvBase = pFile->readFile();
    121157    if (pvBase == NULL)
    122158        throw(1);
  • trunk/tools/common/kFileLX.h

    r4750 r5053  
    1 /* $Id: kFileLX.h,v 1.3 2000-12-04 08:48:09 bird Exp $
     1/* $Id: kFileLX.h,v 1.4 2001-02-02 08:45:41 bird Exp $
    22 *
    33 * kFileLX - Linear Executable file reader.
     
    2828
    2929public:
    30     kFileLX(const char *pszFilename);
     30    kFileLX(const char *pszFilename) throw (int);
     31    kFileLX(kFile *pFile) throw (int);
    3132    ~kFileLX();
    3233
  • trunk/tools/common/kFilePE.cpp

    r4358 r5053  
    4141/**
    4242 * Constructs a kFilePE object for a file.
    43  * @param     phFile  File to create object from.
     43 * @param     pFile     File to create object from.
    4444 * @remark    throws errorcode (TODO: errorhandling.)
    4545 */
    46 kFilePE::kFilePE(FILE *phFile) throw(int) : pvBase(NULL),
     46kFilePE::kFilePE(kFile *pFile) throw(int) : pvBase(NULL),
    4747    pDosHdr(NULL), pFileHdr(NULL), pOptHdr(NULL), paDataDir(NULL), paSectionHdr(NULL),
    4848    pExportDir(NULL),
     
    6262
    6363    /* 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)
    6665        && doshdr.e_magic == IMAGE_DOS_SIGNATURE
    6766        && doshdr.e_lfanew > sizeof(doshdr)
     
    7170
    7271        /* 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)
    7573            && pehdr.Signature == IMAGE_NT_SIGNATURE
    7674            && pehdr.FileHeader.SizeOfOptionalHeader == sizeof(IMAGE_OPTIONAL_HEADER)
     
    7876        {
    7977            /* create mapping */
    80             pvBase = malloc((size_t)pehdr.OptionalHeader.SizeOfImage);
     78            pvBase = calloc((size_t)pehdr.OptionalHeader.SizeOfImage, 1);
    8179            if (pvBase != NULL)
    8280            {
    83                 memset(pvBase, 0, (size_t)pehdr.OptionalHeader.SizeOfImage);
    8481                /*
    8582                printf("%ld\n", pehdr.OptionalHeader.SizeOfHeaders);
     
    8885                       sizeof(IMAGE_NT_HEADERS) + sizeof(IMAGE_SECTION_HEADER) * pehdr.FileHeader.NumberOfSections);
    8986                */
    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))
    9388                {
    9489                    /* read sections */
     
    105100
    106101                        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)
    113106                            )
    114107                        {
     
    286279                     paSectionHdr[i].Characteristics
    287280                     );
    288 
    289     }
     281    }
     282    pOut->printf("\n");
    290283
    291284
     
    328321
    329322    /*
     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    /*
    330340     * Dump TLS directory if present
    331341     */
  • trunk/tools/common/kFilePE.h

    r4358 r5053  
    8080
    8181    public:
    82         kFilePE(FILE *phFile) throw(int);
     82        kFilePE(kFile *pFile) throw(int);
    8383        virtual ~kFilePE();
    8484
  • trunk/tools/common/makefile

    r4804 r5053  
    1 # $Id: makefile,v 1.11 2000-12-16 20:10:07 bird Exp $
     1# $Id: makefile,v 1.12 2001-02-02 08:45:42 bird Exp $
    22
    33#
     
    3232        $(OBJDIR)\common.a \
    3333!endif
    34         $(ODIN32_TOOLS)\kDef2Wat.exe
    35 #        $(ODIN32_TOOLS)\kDump.exe
     34        $(ODIN32_TOOLS)\kDef2Wat.exe \
     35        $(ODIN32_TOOLS)\kDump.exe
    3636
    3737
Note: See TracChangeset for help on using the changeset viewer.