Changeset 5531 for trunk/tools


Ignore:
Timestamp:
Apr 17, 2001, 2:26:28 AM (24 years ago)
Author:
bird
Message:

Second iteration of the kFile* classes and interfaces.

Location:
trunk/tools
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/common/kDef2Wat.cpp

    r4402 r5531  
    1 /* $Id: kDef2Wat.cpp,v 1.1 2000-10-03 05:42:37 bird Exp $
     1/* $Id: kDef2Wat.cpp,v 1.2 2001-04-17 00:26:10 bird Exp $
    22 *
    33 * Converter for IBM/MS linker definition files (.DEF) to Watcom linker directives and options.
     
    1818#include "kFile.h"
    1919#include "kFileFormatBase.h"
     20#include "kInterfaces.h"
    2021#include "kFileDef.h"
    2122
  • trunk/tools/common/kDump.cpp

    r5053 r5531  
    1 /* $Id: kDump.cpp,v 1.2 2001-02-02 08:45:41 bird Exp $
     1/* $Id: kDump.cpp,v 1.3 2001-04-17 00:26:10 bird Exp $
    22 *
    33 * Generic dumper...
     
    2525#include "kFile.h"
    2626#include "kFileFormatBase.h"
     27#include "kInterfaces.h"
    2728#include "kFileDef.h"
    2829#include "kFileLX.h"
  • trunk/tools/common/kFile.cpp

    r4426 r5531  
    1 /* $Id: kFile.cpp,v 1.7 2000-10-05 07:27:56 bird Exp $
     1/* $Id: kFile.cpp,v 1.8 2001-04-17 00:26:10 bird Exp $
    22 *
    33 * kFile - Simple (for the time being) file class.
     
    945945}
    946946
     947
     948
     949/**
     950 * Reads the specified file in to a memory block and returns it.
     951 * @returns Pointer to memory mapping on success.
     952 *          NULL on error.
     953 * @param   pszFilename     Name of the file.
     954 * @author  knut st. osmundsen (knut.stange.osmundsen@mynd.no)
     955 * @remark  May throw errors.
     956 */
     957void *kFile::readFile(const char *pszFilename)
     958{
     959    kFile file(pszFilename);
     960    return file.readFile();
     961}
     962
  • trunk/tools/common/kFile.h

    r4426 r5531  
    1 /* $Id: kFile.h,v 1.7 2000-10-05 07:27:57 bird Exp $
     1/* $Id: kFile.h,v 1.8 2001-04-17 00:26:10 bird Exp $
    22 *
    33 * kFile - Simple (for the time being) file class.
     
    6363    BOOL            readAt(void *pvBuffer, long cbBuffer, long off) throw(int);
    6464    void *          readFile() throw(int);
     65    static void *   readFile(const char *pszFilename) throw(int);
    6566    BOOL            readln(char *pszBuffer, long cchBuffer);
    6667
  • trunk/tools/common/kFileDef.cpp

    r4804 r5531  
    2929#include "kFile.h"
    3030#include "kFileFormatBase.h"
     31#include "kInterfaces.h"
    3132#include "kFileDef.h"
     33
     34/*******************************************************************************
     35*   Global Variables                                                           *
     36*******************************************************************************/
     37#if 0
     38static kFileDef tst((kFile*)NULL);
     39#endif
    3240
    3341
     
    522530/**
    523531 * Query for the module name.
    524  * @returns   Success indicator. TRUE / FALSE.
    525  * @param     pszBuffer  Pointer to buffer which to put the name into.
    526  */
    527 BOOL  kFileDef::queryModuleName(char *pszBuffer)
    528 {
     532 * @returns Success indicator. TRUE / FALSE.
     533 * @param   pszBuffer   Pointer to buffer which to put the name into.
     534 * @param   cchBuffer   Size of the buffer (defaults to 260 chars).
     535 */
     536BOOL  kFileDef::moduleGetName(char *pszBuffer, int cchSize/* = 260*/)
     537{
     538    int cch;
    529539    if (pszModName == NULL)
    530540        return FALSE;
    531541
    532     strcpy(pszBuffer, pszModName);
     542    cch = strlen(pszModName) + 1;
     543    if (cch > cchSize)
     544        return FALSE;
     545    memcpy(pszBuffer, pszModName, cch);
    533546
    534547    return TRUE;
     
    540553 * @returns   Success indicator. TRUE / FALSE.
    541554 * @param     pExport  Pointer to export structure.
    542  * @remark
    543  */
    544 BOOL  kFileDef::findFirstExport(PEXPORTENTRY pExport)
     555 */
     556BOOL  kFileDef::exportFindFirst(kExportEntry *pExport)
    545557{
    546558    if (pExports != NULL && pExport != NULL)
    547559    {
    548560        pExport->ulOrdinal = pExports->ulOrdinal;
     561        pExport->achName[0] = '\0';
    549562        if (pExports->pszName != NULL)
    550563            strcpy(&pExport->achName[0], pExports->pszName);
    551         else
    552             pExport->achName[0] = '\0';
     564
     565        pExport->achIntName[0] = '\0';
    553566        if (pExports->pszIntName)
    554567            strcpy(&pExport->achIntName[0], pExports->pszIntName);
    555         else
    556             pExport->achIntName[0] = '\0';
     568
     569        pExport->ulAddress = pExport->iObject = pExport->ulOffset = ~0UL;
    557570        pExport->pv = (void*)pExports->pNext;
    558571    }
     
    567580 * @returns   Success indicator. TRUE / FALSE.
    568581 * @param     pExport  Pointer to export structure.
    569  * @remark
    570  */
    571 BOOL  kFileDef::findNextExport(PEXPORTENTRY pExport)
     582 */
     583BOOL  kFileDef::exportFindNext(kExportEntry *pExport)
    572584{
    573585    if (pExport != NULL && pExport->pv != NULL)
     
    576588
    577589        pExport->ulOrdinal = pExp->ulOrdinal;
     590        pExport->achName[0] = '\0';
    578591        if (pExp->pszName != NULL)
    579592            strcpy(&pExport->achName[0], pExp->pszName);
    580         else
    581             pExport->achName[0] = '\0';
     593        pExport->achIntName[0] = '\0';
    582594        if (pExp->pszIntName)
    583595            strcpy(&pExport->achIntName[0], pExp->pszIntName);
    584         else
    585             pExport->achIntName[0] = '\0';
     596        pExport->ulAddress = pExport->iObject = pExport->ulOffset = ~0UL;
    586597        pExport->pv = (void*)pExp->pNext;
    587598    }
     
    589600        return FALSE;
    590601    return TRUE;
     602}
     603
     604
     605/**
     606 * Frees resources associated with the communicatin area.
     607 * It's not necessary to call this when exportFindNext has return FALSE.
     608 * (We don't allocate anything so it's not a problem ;-)
     609 * @param   pExport     Communication area which has been successfully
     610 *                      processed by findFirstExport.
     611 */
     612void kFileDef::exportFindClose(kExportEntry *pExport)
     613{
     614    pExport = pExport;
     615    return;
     616}
     617
     618
     619/**
     620 * Lookup information on a spesific export given by ordinal number.
     621 * @returns Success indicator.
     622 * @param   pExport     Communication area containing export information
     623 *                      on successful return.
     624 * @remark  stub
     625 */
     626BOOL kFileDef::exportLookup(unsigned long ulOrdinal, kExportEntry *pExport)
     627{
     628    assert(!"not implemented.");
     629    ulOrdinal = ulOrdinal;
     630    pExport = pExport;
     631    return FALSE;
     632}
     633
     634/**
     635 * Lookup information on a spesific export given by name.
     636 * @returns Success indicator.
     637 * @param   pExport     Communication area containing export information
     638 *                      on successful return.
     639 * @remark  stub
     640 */
     641BOOL kFileDef::exportLookup(const char *  pszName, kExportEntry *pExport)
     642{
     643    assert(!"not implemented.");
     644    pszName = pszName;
     645    pExport = pExport;
     646    return FALSE;
    591647}
    592648
  • trunk/tools/common/kFileDef.h

    r4402 r5531  
    6161 * @author      knut st. osmundsen
    6262 */
    63 class kFileDef : public kFileFormatBase
     63class kFileDef : public kExportI, public kFileFormatBase, public kModuleI
    6464{
    6565    private:
     
    104104        virtual ~kFileDef();
    105105
     106        /** @cat Module information methods. */
     107        BOOL        moduleGetName(char *pszBuffer, int cchSize = 260);
     108
     109        /** @cat Export enumeration methods. */
     110        BOOL        exportFindFirst(kExportEntry *pExport);
     111        BOOL        exportFindNext(kExportEntry *pExport);
     112        void        exportFindClose(kExportEntry *pExport);
     113
     114        /** @cat Export Lookup methods */
     115        BOOL        exportLookup(unsigned long ulOrdinal, kExportEntry *pExport);
     116        BOOL        exportLookup(const char *  pszName, kExportEntry *pExport);
     117
    106118        /**@cat queries... */
    107         BOOL        queryModuleName(char *pszBuffer);
    108         BOOL        findFirstExport(PEXPORTENTRY pExport);
    109         BOOL        findNextExport(PEXPORTENTRY pExport);
    110119        BOOL        isDef() const                { return TRUE;}
    111120        char const *queryModuleName(void) const  { return pszModName;     }
     
    128137};
    129138
    130 
    131139#endif
  • trunk/tools/common/kFileFormatBase.cpp

    r5053 r5531  
    1 /* $Id: kFileFormatBase.cpp,v 1.3 2001-02-02 08:45:41 bird Exp $
     1/* $Id: kFileFormatBase.cpp,v 1.4 2001-04-17 00:26:11 bird Exp $
    22 *
    33 * kFileFormatBase - Base class for kFile<format> classes.
     
    2121
    2222#include "kFile.h"
     23#include "kInterfaces.h"
    2324#include "kFileFormatBase.h"
    2425
    25 
    26 
    27 
    28 /**
    29  * Creates a memory buffer for a binary file.
    30  * @returns   Pointer to file memoryblock. NULL on error.
    31  * @param     pszFilename  Pointer to filename string.
    32  * @remark    This function is the one using most of the execution
    33  *            time (DosRead + DosOpen) - about 70% of the execution time!
    34  */
    35 void *kFileFormatBase::readfile(const char *pszFilename)
    36 {
    37     void *pvFile = NULL;
    38     FILE *phFile;
    39 
    40     phFile = fopen(pszFilename, "rb");
    41     if (phFile != NULL)
    42     {
    43         long int cbFile;
    44 
    45         if (ftell(phFile) < 0
    46             ||
    47             fseek(phFile, 0, SEEK_END) != 0
    48             ||
    49             (cbFile = ftell(phFile)) < 0
    50             ||
    51             fseek(phFile, 0, SEEK_SET) != 0
    52             )
    53             cbFile = -1;
    54 
    55         if (cbFile > 0)
    56         {
    57             pvFile = malloc((size_t)cbFile + 1);
    58             if (pvFile != NULL)
    59             {
    60                 memset(pvFile, 0, (size_t)cbFile + 1);
    61                 if (fread(pvFile, 1, (size_t)cbFile, phFile) == 0)
    62                 {   /* failed! */
    63                     free(pvFile);
    64                     pvFile = NULL;
    65                 }
    66             }
    67             else
    68                 fprintf(stderr, "warning/error: failed to open file %s\n", pszFilename);
    69         }
    70         fclose(phFile);
    71     }
    72     return pvFile;
    73 }
    7426
    7527/**
  • trunk/tools/common/kFileFormatBase.h

    r4358 r5531  
    1 /* $Id: kFileFormatBase.h,v 1.4 2000-10-02 04:01:39 bird Exp $
     1/* $Id: kFileFormatBase.h,v 1.5 2001-04-17 00:26:11 bird Exp $
    22 *
    33 * kFileFormatBase - Base class for kFile<format> classes.
     
    1515*   Defined Constants                                                         *
    1616******************************************************************************/
    17 #define MAXEXPORTNAME 256
    1817#define ORD_START_INTERNAL_FUNCTIONS 1200
    1918
     
    2625class kFile;
    2726
    28 /**
    29  * ExportEntry used by the findFirstExport/findNextExport functions
    30  */
    31 typedef struct _ExportEntry
    32 {
    33     unsigned long   ulOrdinal;
    34     char            achName[MAXEXPORTNAME];
    35     char            achIntName[MAXEXPORTNAME]; /* not used by PEFile */
    36 
    37     /* these don't apply for .DEF files. (should have a flag for that...) */
    38     unsigned long   offset;
    39     unsigned long   iObject;
    40 
    41     /* internal - do not use! */
    42     void          *pv;
    43 } EXPORTENTRY, *PEXPORTENTRY;
    44 
    4527
    4628/**
     
    5133{
    5234public:
    53     virtual BOOL  queryModuleName(char *pszBuffer) = 0;
    54     virtual BOOL  findFirstExport(PEXPORTENTRY pExport) = 0;
    55     virtual BOOL  findNextExport(PEXPORTENTRY pExport)  = 0;
    5635    virtual BOOL  isDef() const { return FALSE;}
    5736    virtual BOOL  isPe() const  { return FALSE;}
    5837    virtual BOOL  isLx() const  { return FALSE;}
    59 
    60     static void * readfile(const char *pszFilename);
    6138    virtual BOOL  dump(kFile *pOut);
    6239};
  • trunk/tools/common/kFileLX.cpp

    r5053 r5531  
    1 /* $Id: kFileLX.cpp,v 1.4 2001-02-02 08:45:41 bird Exp $
     1/* $Id: kFileLX.cpp,v 1.5 2001-04-17 00:26:11 bird Exp $
    22 *
    33 *
     
    6464
    6565
    66 
     66/*******************************************************************************
     67*   Global Variables                                                           *
     68*******************************************************************************/
     69#if 0
     70static kFileLX tst((kFile*)NULL);
     71#endif
     72
     73
     74/**
     75 * Internal worker which lookup the name corresponding to an ordinal.
     76 * @returns Success indicator.
     77 * @param   iOrdinal ( >= 0).
     78 * @param   pszBuffer.
     79 */
    6780BOOL kFileLX::queryExportName(int iOrdinal, char *pszBuffer)
    6881{
     
    119132
    120133    /* create filemapping */
    121     pvBase = kFileFormatBase::readfile(pszFilename);
     134    pvBase = kFile::readFile(pszFilename);
    122135    if (pvBase == NULL)
    123136        throw(1);
     
    192205
    193206
    194 BOOL kFileLX::queryModuleName(char *pszBuffer)
     207/**
     208 * Query for the module name.
     209 * @returns Success indicator. TRUE / FALSE.
     210 * @param   pszBuffer   Pointer to buffer which to put the name into.
     211 * @param   cchBuffer   Size of the buffer (defaults to 260 chars).
     212 */
     213BOOL kFileLX::moduleGetName(char *pszBuffer, int cchBuffer/*= 260*/)
    195214{
    196215    /* The module name is the 0 ordinal entry in resident name table */
     216    assert(cchBuffer >= 255);
    197217    return queryExportName(0, pszBuffer);
    198218}
    199219
    200220
    201 
    202 BOOL kFileLX::findFirstExport(PEXPORTENTRY pExport)
     221/**
     222 * Finds the first exports.
     223 * @returns   Success indicator. TRUE / FALSE.
     224 * @param     pExport  Pointer to export structure.
     225 */
     226BOOL kFileLX::exportFindFirst(kExportEntry *pExport)
    203227{
    204228    struct b32_bundle * pBundle = (struct b32_bundle*)((char*)pvBase + pe32->e32_enttab + offLXHdr);
     
    239263                {
    240264                    case ENTRY16:
    241                         pExport->offset = pEntry->e32_variant.e32_offset.offset16;
     265                        pExport->ulOffset = pEntry->e32_variant.e32_offset.offset16;
    242266                        break;
    243267
    244268                    case ENTRY32:
    245                         pExport->offset = pEntry->e32_variant.e32_offset.offset32;
     269                        pExport->ulOffset = pEntry->e32_variant.e32_offset.offset32;
    246270                        break;
    247271
    248272                    case GATE16:
    249                         pExport->offset = pEntry->e32_variant.e32_callgate.offset;
     273                        pExport->ulOffset = pEntry->e32_variant.e32_callgate.offset;
    250274                        break;
    251275                    default:
     
    260284                pExpState->pe32     = pEntry;
    261285                pExpState->iOrdinal = iOrdinal;
     286                pExport->ulAddress = ~0UL; /* TODO */
    262287                return TRUE;
    263288            }
     
    270295
    271296
    272 
    273 BOOL kFileLX::findNextExport(PEXPORTENTRY pExport)
     297/**
     298 * Finds the next export.
     299 * @returns   Success indicator. TRUE / FALSE.
     300 * @param     pExport  Pointer to export structure.
     301 */
     302BOOL kFileLX::exportFindNext(kExportEntry *pExport)
    274303{
    275304    static int      acbEntry[] =
     
    283312
    284313    PEXPSTATE pExpState = (PEXPSTATE)pExport->pv;
     314    pExport->ulAddress = ~0UL; /* TODO */
    285315
    286316    /*
     
    303333            pExport->achName[0] = '\0';
    304334
    305         /* offset */
     335        /* ulOffset */
    306336        switch (pExpState->pb32->b32_type & ~TYPEINFO)
    307337        {
    308338            case ENTRY16:
    309                 pExport->offset = pExpState->pe32->e32_variant.e32_offset.offset16;
     339                pExport->ulOffset = pExpState->pe32->e32_variant.e32_offset.offset16;
    310340                break;
    311341
    312342            case ENTRY32:
    313                 pExport->offset = pExpState->pe32->e32_variant.e32_offset.offset32;
     343                pExport->ulOffset = pExpState->pe32->e32_variant.e32_offset.offset32;
    314344                break;
    315345
    316346            case GATE16:
    317                 pExport->offset = pExpState->pe32->e32_variant.e32_callgate.offset;
     347                pExport->ulOffset = pExpState->pe32->e32_variant.e32_callgate.offset;
    318348                break;
    319349        }
     
    360390            {
    361391                case ENTRY16:
    362                     pExport->offset = pExpState->pe32->e32_variant.e32_offset.offset16;
     392                    pExport->ulOffset = pExpState->pe32->e32_variant.e32_offset.offset16;
    363393                    break;
    364394
    365395                case ENTRY32:
    366                     pExport->offset = pExpState->pe32->e32_variant.e32_offset.offset32;
     396                    pExport->ulOffset = pExpState->pe32->e32_variant.e32_offset.offset32;
    367397                    break;
    368398
    369399                case GATE16:
    370                     pExport->offset = pExpState->pe32->e32_variant.e32_callgate.offset;
     400                    pExport->ulOffset = pExpState->pe32->e32_variant.e32_callgate.offset;
    371401                    break;
    372402                default:
     
    384414    free(pExport->pv);
    385415    pExport->pv = NULL;
     416    return FALSE;
     417}
     418
     419
     420/**
     421 * Frees resources associated with the communicatin area.
     422 * It's not necessary to call this when exportFindNext has return FALSE.
     423 * @param   pExport     Communication area which has been successfully
     424 *                      processed by findFirstExport.
     425 */
     426void kFileLX::exportFindClose(kExportEntry *pExport)
     427{
     428    free(pExport->pv);
     429    pExport->pv = NULL;
     430    return;
     431}
     432
     433
     434/**
     435 * Lookup information on a spesific export given by ordinal number.
     436 * @returns Success indicator.
     437 * @param   pExport     Communication area containing export information
     438 *                      on successful return.
     439 * @remark  stub
     440 */
     441BOOL kFileLX::exportLookup(unsigned long ulOrdinal, kExportEntry *pExport)
     442{
     443    assert(!"not implemented.");
     444    ulOrdinal = ulOrdinal;
     445    pExport = pExport;
     446    return FALSE;
     447}
     448
     449/**
     450 * Lookup information on a spesific export given by name.
     451 * @returns Success indicator.
     452 * @param   pExport     Communication area containing export information
     453 *                      on successful return.
     454 * @remark  stub
     455 */
     456BOOL kFileLX::exportLookup(const char *  pszName, kExportEntry *pExport)
     457{
     458    assert(!"not implemented.");
     459    pszName = pszName;
     460    pExport = pExport;
    386461    return FALSE;
    387462}
  • trunk/tools/common/kFileLX.h

    r5053 r5531  
    1 /* $Id: kFileLX.h,v 1.4 2001-02-02 08:45:41 bird Exp $
     1/* $Id: kFileLX.h,v 1.5 2001-04-17 00:26:11 bird Exp $
    22 *
    33 * kFileLX - Linear Executable file reader.
     
    1515
    1616
    17 class kFileLX : public kFileFormatBase/*, public kPageI*/
     17class kFileLX : public kFileFormatBase, public kExecutableI /*, public kPageI*/
    1818{
    1919protected:
     
    3232    ~kFileLX();
    3333
    34     virtual BOOL        queryModuleName(char *pszBuffer);
    35     virtual BOOL        findFirstExport(PEXPORTENTRY pExport);
    36     virtual BOOL        findNextExport(PEXPORTENTRY pExport);
     34    /** @cat Module information methods. */
     35    BOOL        moduleGetName(char *pszBuffer, int cchSize = 260);
     36
     37    /** @cat Export enumeration methods. */
     38    BOOL        exportFindFirst(kExportEntry *pExport);
     39    BOOL        exportFindNext(kExportEntry *pExport);
     40    void        exportFindClose(kExportEntry *pExport);
     41
     42    /** @cat Export Lookup methods */
     43    BOOL        exportLookup(unsigned long ulOrdinal, kExportEntry *pExport);
     44    BOOL        exportLookup(const char *  pszName, kExportEntry *pExport);
     45
    3746    virtual BOOL        isLx() const {return TRUE;};
    3847
  • trunk/tools/common/kFilePE.cpp

    r5053 r5531  
    3636#include "kFile.h"
    3737#include "kFileFormatBase.h"
     38#include "kInterfaces.h"
    3839#include "kFilePe.h"
    3940
     41/*******************************************************************************
     42*   Global Variables                                                           *
     43*******************************************************************************/
     44#if 0
     45kFilePE kFilePE((kFile*)NULL);
     46#endif
    4047
    4148/**
     
    6269
    6370    /* read dos-header - assumes there is one */
    64     if (   pFile->readAt(&doshdr, sizeof(doshdr), 0) 
     71    if (   pFile->readAt(&doshdr, sizeof(doshdr), 0)
    6572        && doshdr.e_magic == IMAGE_DOS_SIGNATURE
    6673        && doshdr.e_lfanew > sizeof(doshdr)
     
    101108                        cbSection = min(pSectionHdr->Misc.VirtualSize, pSectionHdr->SizeOfRawData);
    102109                        if (    cbSection
    103                             &&  !pFile->readAt((char*)pvBase + pSectionHdr->VirtualAddress, 
    104                                                cbSection, 
     110                            &&  !pFile->readAt((char*)pvBase + pSectionHdr->VirtualAddress,
     111                                               cbSection,
    105112                                               pSectionHdr->PointerToRawData)
    106113                            )
     
    169176/**
    170177 * Query for the module name.
    171  * @returns   Success indicator. TRUE / FALSE.
    172  * @param     pszBuffer  Pointer to buffer which to put the name into.
    173  */
    174 BOOL  kFilePE::queryModuleName(char *pszBuffer)
     178 * @returns Success indicator. TRUE / FALSE.
     179 * @param   pszBuffer   Pointer to buffer which to put the name into.
     180 * @param   cchBuffer   Size of the buffer (defaults to 260 chars).
     181 */
     182BOOL  kFilePE::moduleGetName(char *pszBuffer, int cchSize/* = 260*/)
    175183{
    176184    if (pExportDir && pExportDir->Name)
    177         strcpy(pszBuffer, (char*)((int)pExportDir->Name + (int)pvBase));
     185    {
     186        char *psz = (char*)((int)pExportDir->Name + (int)pvBase);
     187        int cch = strlen(psz) + 1;
     188        if (cch > cchSize)
     189            return FALSE;
     190        memcpy(pszBuffer, psz, cch);
     191    }
    178192    else
    179193        return FALSE;
     
    189203 * @remark
    190204 */
    191 BOOL  kFilePE::findFirstExport(PEXPORTENTRY pExport)
     205BOOL  kFilePE::exportFindFirst(kExportEntry *pExport)
    192206{
    193207    if (pExportDir && pExportDir->NumberOfFunctions)
    194208    {
    195         memset(pExport, 0, sizeof(EXPORTENTRY));
     209        memset(pExport, 0, sizeof(kExportEntry));
    196210        pExport->ulOrdinal = pExportDir->Base - 1;
    197         return findNextExport(pExport);
     211        return exportFindNext(pExport);
    198212    }
    199213
     
    208222 * @remark
    209223 */
    210 BOOL  kFilePE::findNextExport(PEXPORTENTRY pExport)
     224BOOL  kFilePE::exportFindNext(kExportEntry *pExport)
    211225{
    212226    if (pExportDir && pExportDir->NumberOfFunctions)
     
    241255        return FALSE;
    242256
     257    pExport->ulAddress = pExport->iObject = pExport->ulOffset = ~0UL; /* FIXME/TODO */
    243258    pExport->achIntName[0] = '\0';
    244259    pExport->pv = NULL;
    245260    return TRUE;
     261}
     262
     263
     264/**
     265 * Frees resources associated with the communicatin area.
     266 * It's not necessary to call this when exportFindNext has return FALSE.
     267 * (We don't allocate anything so it's not a problem ;-)
     268 * @param   pExport     Communication area which has been successfully
     269 *                      processed by findFirstExport.
     270 */
     271void kFilePE::exportFindClose(kExportEntry *pExport)
     272{
     273    pExport = pExport;
     274    return;
     275}
     276
     277
     278/**
     279 * Lookup information on a spesific export given by ordinal number.
     280 * @returns Success indicator.
     281 * @param   pExport     Communication area containing export information
     282 *                      on successful return.
     283 * @remark  stub
     284 */
     285BOOL kFilePE::exportLookup(unsigned long ulOrdinal, kExportEntry *pExport)
     286{
     287    assert(!"not implemented.");
     288    ulOrdinal = ulOrdinal;
     289    pExport = pExport;
     290    return FALSE;
     291}
     292
     293/**
     294 * Lookup information on a spesific export given by name.
     295 * @returns Success indicator.
     296 * @param   pExport     Communication area containing export information
     297 *                      on successful return.
     298 * @remark  stub
     299 */
     300BOOL kFilePE::exportLookup(const char *  pszName, kExportEntry *pExport)
     301{
     302    assert(!"not implemented.");
     303    pszName = pszName;
     304    pExport = pExport;
     305    return FALSE;
    246306}
    247307
     
    327387        pOut->printf("Import Directory\n"
    328388                     "----------------\n");
    329        
     389
    330390        PIMAGE_IMPORT_DESCRIPTOR pCur = pImportDir;
    331391        while (pCur->u.Characteristics != 0)
     
    334394            pCur++;
    335395        }
    336     }   
     396    }
    337397
    338398
  • trunk/tools/common/kFilePE.h

    r5053 r5531  
    1 /*
     1/* $Id: kFilePE.h,v 1.4 2001-04-17 00:26:11 bird Exp $
    22 * kFilePE - PE files.
    33 *
    4  * Copyright (c) 1999 knut st. osmundsen
     4 * Copyright (c) 1999-2001 knut st. osmundsen
    55 *
    66 */
     
    1414
    1515#if !defined(__WINE_PEEXE_H) && !defined(_WINNT_)
    16 #if 0
     16#if 1
    1717    #define PIMAGE_DOS_HEADER           void*
    1818    #define PIMAGE_FILE_HEADER          void*
     
    4747 * @author      knut st. osmundsen
    4848 */
    49 class kFilePE : public kFileFormatBase
     49class kFilePE : public kFileFormatBase, public kExecutableI
    5050{
    5151    private:
     
    8383        virtual ~kFilePE();
    8484
    85         /* operations */
    86         BOOL  queryModuleName(char *pszBuffer);
    87         BOOL  findFirstExport(PEXPORTENTRY pExport);
    88         BOOL  findNextExport(PEXPORTENTRY pExport);
     85        /** @cat Module information methods. */
     86        BOOL        moduleGetName(char *pszBuffer, int cchSize = 260);
     87
     88        /** @cat Export enumeration methods. */
     89        BOOL        exportFindFirst(kExportEntry *pExport);
     90        BOOL        exportFindNext(kExportEntry *pExport);
     91        void        exportFindClose(kExportEntry *pExport);
     92
     93        /** @cat Export Lookup methods */
     94        BOOL        exportLookup(unsigned long ulOrdinal, kExportEntry *pExport);
     95        BOOL        exportLookup(const char *  pszName, kExportEntry *pExport);
     96
    8997        BOOL  isPe() const   { return TRUE;}
    9098
  • trunk/tools/common/kInterfaces.h

    r4751 r5531  
    1 /* $Id: kInterfaces.h,v 1.1 2000-12-04 08:49:00 bird Exp $
     1/* $Id: kInterfaces.h,v 1.2 2001-04-17 00:26:12 bird Exp $
    22 *
    33 * This headerfile contains interfaces for the common tools classes.
     
    1212#ifndef _kInterfaces_h_
    1313#define _kInterfaces_h_
     14
     15
     16class kPageI;
     17class kExportI;
     18class kExportEntry;
     19class kModuleI;
     20
    1421
    1522/**
     
    3138     * @param   ulAddress   Page address. This will be page aligned.
    3239     */
    33     virtual BOOL    getPage(char *pachPage, ULONG ulAddress) = 0;
     40    virtual BOOL    pageGet(char *pachPage, ULONG ulAddress) = 0;
    3441
    3542    /**
     
    4249     * @remark  Object = Section.
    4350     */
    44     virtual BOOL    getPage(char *pachPage, int iObject, int offObject) = 0;
     51    virtual BOOL    pageGet(char *pachPage, int iObject, int offObject) = 0;
    4552
    4653    /**
     
    5158     * @param   ulAddress   Page address. This will be page aligned.
    5259     */
    53     virtual BOOL    putPage(const char *pachPage, ULONG ulAddress) = 0;
     60    virtual BOOL    pagePut(const char *pachPage, ULONG ulAddress) = 0;
    5461
    5562    /**
     
    6168     * @param   offObject   Offset into the object.
    6269     */
    63     virtual BOOL    putPage(const char *pachPage, int iObject, int offObject) = 0;
     70    virtual BOOL    pagePut(const char *pachPage, int iObject, int offObject) = 0;
    6471
    6572    /**
     
    6774     * @returns Pagesize in bytes.
    6875     */
    69     virtual int     getPageSize() = 0;
     76    virtual int     pageGetPageSize() = 0;
     77};
     78
     79
     80/**
     81 * ExportEntry used by the findFirstExport/findNextExport functions
     82 */
     83class kExportEntry
     84{
     85#define MAXEXPORTNAME 256
     86public:
     87    unsigned long   ulOrdinal;                  /* Ordinal of export. 0 if invalid. */
     88    char            achName[MAXEXPORTNAME];     /* Public or exported name. */
     89    char            achIntName[MAXEXPORTNAME];  /* Optional. not used by PEFile */
     90
     91    unsigned long   ulOffset;                   /* Offset. -1 if invalid. */
     92    unsigned long   iObject;                    /* Object number. -1 if invalid. */
     93    unsigned long   ulAddress;                  /* Address of symbol. -1 if invalid. */
     94
     95public:
     96    /** @cat Internal use - don't mess! */
     97    void *          pv;                          /* Internal pointer. */
     98};
     99
     100/**
     101 * Interface class (ie. virtual) which defines the interface for executables
     102 * (objects and libraries to perhaps) files used to enumerate exports and
     103 * public exported names.
     104 * @author      knut st. osmundsen (knut.stange.osmundsen@mynd.no)
     105 */
     106class kExportI
     107{
     108public:
     109    /** @cat Export enumeration methods. */
     110
     111    /**
     112     * Find the first export/public name.
     113     * @returns Success indicator.
     114     * @param   pExport     Communication area.
     115     */
     116    virtual BOOL    exportFindFirst(kExportEntry * pExport) = 0;
     117
     118    /**
     119     * Find the next export/public name.
     120     * @returns Success indicator.
     121     *          FALSE when no more exports (exportFindClose has been processed then).
     122     * @param   pExport     Communication area which has been successfully
     123     *                      processed by findFirstExport.
     124     */
     125    virtual BOOL    exportFindNext(kExportEntry * pExport) = 0;
     126
     127    /**
     128     * Frees resources associated with the communicatin area.
     129     * It's not necessary to call this when exportFindNext has return FALSE.
     130     * @param   pExport     Communication area which has been successfully
     131     *                      processed by findFirstExport.
     132     */
     133    virtual void    exportFindClose(kExportEntry * pExport) = 0;
     134
     135
     136    /** @cat Export Search methods */
     137
     138    /**
     139     * Lookup information on a spesific export given by ordinal number.
     140     * @returns Success indicator.
     141     * @param   pExport     Communication area containing export information
     142     *                      on successful return.
     143     */
     144    virtual BOOL    exportLookup(unsigned long ulOrdinal, kExportEntry *pExport) = 0;
     145
     146    /**
     147     * Lookup information on a spesific export given by name.
     148     * @returns Success indicator.
     149     * @param   pExport     Communication area containing export information
     150     *                      on successful return.
     151     */
     152    virtual BOOL    exportLookup(const char *  pszName, kExportEntry *pExport) = 0;
     153};
     154
     155
     156/**
     157 * Interface class (ie. virtual) which defines the interface for executables
     158 * (objects and libraries to perhaps) files used to enumerate exports and
     159 * @author      knut st. osmundsen (knut.stange.osmundsen@mynd.no)
     160 */
     161class kModuleI
     162{
     163public:
     164    /** @cat Module information methods. */
     165    virtual BOOL    moduleGetName(char *pszBuffer, int cbBuffer = 260) = 0;
     166};
     167
     168
     169/**
     170 * Interface class (ie. virtual) which defines the interface for
     171 * executables files.
     172 * @author      knut st. osmundsen (knut.stange.osmundsen@mynd.no)
     173 */
     174class kExecutableI : public kModuleI, public kExportI
     175{
     176public:
     177    /** @cat Executable information methods. */
     178    #if 0
     179    virtual BOOL execIsDLL(void) = 0;
     180    virtual BOOL execIsProgram(void) = 0;
     181    virtual BOOL execIsDriver(void) = 0;
     182    #endif
    70183};
    71184
  • trunk/tools/database/APIImport.cpp

    r5053 r5531  
    1 /* $Id: APIImport.cpp,v 1.8 2001-02-02 08:45:42 bird Exp $ */
     1/* $Id: APIImport.cpp,v 1.9 2001-04-17 00:24:46 bird Exp $ */
    22/*
    33 *
     
    1818#include "APIImport.h"
    1919#include "kFile.h"
     20#include "kInterfaces.h"
    2021#include "kFileFormatBase.h"
    2122#include "kFilePE.h"
     
    242243static long processFile(const char *pszFilename, const POPTIONS pOptions, long &cFunctions)
    243244{
    244     kFileFormatBase  *pFile;
    245245    long              lRc = 1;
    246246
     
    252252        try
    253253        {
     254            kFileFormatBase *   pFileBase = NULL;
     255            kExportI *          pExportFile;
     256            kModuleI *          pModuleFile;
    254257            char    achDataBuffer[0x200];
    255258            char   *pszModuleName = &achDataBuffer[0];
     
    259262            try
    260263            {
    261                 pFile = new kFilePE(&InFile);
     264                kFilePE *pFile = new kFilePE(&InFile);
     265                pExportFile = pFile;
     266                pModuleFile = pFile;
     267                pFileBase = pFile;
    262268            }
    263269            catch (int i)
    264270            {
    265271                i = i;
    266                 pFile = new kFileDef(&InFile);
    267             }
    268 
    269             if (pFile->queryModuleName(pszModuleName))
     272                kFileDef *pFile = new kFileDef(&InFile);
     273                pExportFile = pFile;
     274                pModuleFile = pFile;
     275                pFileBase = pFile;
     276            }
     277
     278            if (pModuleFile->moduleGetName(pszModuleName))
    270279            {
    271280                int cch = strlen(pszModuleName);
     
    281290                    BOOL    fClearUpdateOk = FALSE;
    282291                    BOOL    fOk;
    283                     EXPORTENTRY export;
     292                    kExportEntry export;
    284293
    285294                    /* Clear the update flag for all functions in this DLL. */
     
    288297
    289298                    lRc = 0;
    290                     fOk = pFile->findFirstExport(&export);
     299                    fOk = pExportFile->exportFindFirst(&export);
    291300                    while (fOk)
    292301                    {
    293302                        /* check if name or not */
    294                         if (!pFile->isDef() || export.ulOrdinal < ORD_START_INTERNAL_FUNCTIONS)
     303                        if (!pFileBase->isDef() || export.ulOrdinal < ORD_START_INTERNAL_FUNCTIONS)
    295304                        {
    296305                            char szIntName[256];
     
    344353
    345354                        /* next */
    346                         fOk = pFile->findNextExport(&export);
     355                        fOk = pExportFile->exportFindNext(&export);
    347356                    }
    348357
     
    362371                fprintf(phLog, "%s: error - could not get module name.\n", pszFilename);
    363372
    364             delete(pFile);
     373            delete(pFileBase);
    365374        }
    366375        catch (int err)
  • trunk/tools/impdef/ImpDef.cpp

    r4823 r5531  
    1 /* $Id: ImpDef.cpp,v 1.6 2000-12-17 03:26:41 bird Exp $ */
     1/* $Id: ImpDef.cpp,v 1.7 2001-04-17 00:26:28 bird Exp $ */
    22/*
    33 * ImpDef - Create export file which use internal names and ordinals.
     
    1616#include "ImpDef.h"
    1717#include "kFile.h"
     18#include "kInterFaces.h"
    1819#include "kFileFormatBase.h"
    1920#include "kFileDef.h"
     
    2526static void   syntax(void);
    2627static long   processFile(const char *pszInput, const char *pszOutput, const POPTIONS pOptions);
    27 static char  *generateExportName(const PEXPORTENTRY pExport, char *pszBuffer, const POPTIONS pOptions);
     28static char  *generateExportName(const kExportEntry * pExport, char *pszBuffer, const POPTIONS pOptions);
    2829
    2930
     
    191192            try
    192193            {
    193                 EXPORTENTRY export;
     194                kExportEntry export;
    194195                kFile Output(pszOutput, FALSE);
    195196
     
    205206
    206207                /* Exports */
    207                 if (DefFile.findFirstExport(&export))
     208                if (DefFile.exportFindFirst(&export))
    208209                {
    209210                    Output.printf("EXPORTS\n");
     
    235236
    236237                        Output.printf("    %-*s  @%ld\n", 40, pszName, export.ulOrdinal);
    237                     } while (DefFile.findNextExport(&export));
     238                    } while (DefFile.exportFindNext(&export));
    238239                Output.setSize();
    239240                }
     
    275276 * @remark
    276277 */
    277 static char *generateExportName(const PEXPORTENTRY pExport, char *pszBuffer, const POPTIONS pOptions)
     278static char *generateExportName(const kExportEntry * pExport, char *pszBuffer, const POPTIONS pOptions)
    278279{
    279280    if (pExport->ulOrdinal < pOptions->ulOrdStartInternalFunctions)
Note: See TracChangeset for help on using the changeset viewer.