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

Second iteration of the kFile* classes and interfaces.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.