Changeset 4750


Ignore:
Timestamp:
Dec 4, 2000, 9:48:09 AM (24 years ago)
Author:
bird
Message:

Not completed implementation of kPageI.

Location:
trunk/tools/common
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/tools/common/kFileLX.cpp

    r4129 r4750  
    1 /* $Id: kFileLX.cpp,v 1.2 2000-08-31 03:00:13 bird Exp $
     1/* $Id: kFileLX.cpp,v 1.3 2000-12-04 08:48:08 bird Exp $
    22 *
    33 *
     
    4747
    4848#include "kFileFormatBase.h"
     49#include "kInterfaces.h"
    4950#include "kFileLX.h"
     51
    5052
    5153/*******************************************************************************
     
    127129
    128130    pe32 = (struct e32_exe*)((char*)pvBase + offLXHdr);
    129     if (*(PUSHORT)pe32 == E32MAGIC)
    130     {
    131         paObject = (struct o32_obj*)((char*)pvBase + pe32->e32_objtab + offLXHdr);
    132     }
    133     else
     131    if (*(PUSHORT)pe32 != E32MAGIC)
    134132    {
    135133        free(pvBase);
     
    137135        throw(2);
    138136    }
     137
     138    paObject = pe32->e32_objtab && pe32->e32_objcnt
     139        ? (struct o32_obj*)((char*)pvBase + pe32->e32_objtab + offLXHdr) : NULL;
     140    paMap = pe32->e32_objmap
     141        ? (struct o32_map*)((char*)pvBase + pe32->e32_objmap + offLXHdr) : NULL;
    139142}
    140143
     
    372375}
    373376
     377#if 0
     378
     379/** @cat Get and put page methods. (the first ones are generic) */
     380BOOL kFileLX::getPage(char *pachPage, ULONG ulAddress)
     381{
     382    int iObj;
     383
     384    for (iObj = 0; iObj < pe32->e32_objcnt; iObj++)
     385        if (    paObject[iObj].o32_base > ulAddress
     386            &&  paObject[iObj].o32_base + paObject[iObj].o32_size > ulAddress
     387            )
     388            return getPage(pachPage, iObj, ulAddress - paObject[iObj].o32_base);
     389
     390    return FALSE;
     391}
     392
     393BOOL kFileLX::getPage(char *pachPage, int iObject, int offObject)
     394{
     395    offObject &= ~(PAGESIZE - 1);
     396    if (    iObject >= pe32->e32_objcnt
     397        &&  offObject >= paObject[iObject].o32_size
     398        )
     399        return FALSE;
     400
     401    /*
     402     * Is there a pagemap entry for the requested page?
     403     */
     404    if ((offObject >> PAGESHIFT) < paObject[iObject].o32_mapsize)
     405    {   /* yes */
     406        int     iPage = (offObject >> PAGESIZE) + paObject[iObject].o32_pagemap - 1;
     407        char *  pchPageData = (char*)((paMap[iPage].o32_pagedataoffset << pe32->e32_pageshift) + pe32->e32_datapage + (char*)pvBase);
     408
     409        if (pchPageData )
     410        {
     411        }
     412
     413    }
     414    else
     415    {   /* no, so it's a zero page */
     416        memset(pachPage, 0, PAGESIZE);
     417    }
     418
     419    return FALSE;
     420}
     421
     422BOOL kFileLX::putPage(const char *pachPage, ULONG ulAddress)
     423{
     424    return FALSE;
     425}
     426
     427BOOL kFileLX::putPage(const char *pachPage, int iObject, int offObject)
     428{
     429    return FALSE;
     430}
     431
     432BOOL kFileLX::getPageLX(char *pachPage, int iObject, int iPage)
     433{
     434    return FALSE;
     435}
     436
     437BOOL kFileLX::getPageLX(char *pachPage, int iPage)
     438{
     439    return FALSE;
     440}
     441
     442BOOL kFileLX::putPageLX(const char *pachPage, int iObject, int iPage)
     443{
     444    return FALSE;
     445}
     446
     447BOOL kFileLX::putPageLX(const char *pachPage, int iPage)
     448{
     449    return FALSE;
     450}
     451
     452
     453/**
     454 * Expands a page compressed with the old exepack method introduced with OS/2 2.0.
     455 * (/EXEPACK or just /EXEPACK)
     456 * @returns Successindicator.
     457 * @param   pachPage        Pointer to output page. size: PAGESIZE
     458 *                          Upon successful return this will contain the expanded page data.
     459 * @param   pachSrcPage     Pointer to source data. size: cchSrcPage.
     460 *                          This data should be compressed with EXEPACK:2!
     461 * @sketch  Have no good idea right now.
     462 * @status  Completely implemented.
     463 * @author  knut st. osmundsen (knut.stange.osmundsen@mynd.no)
     464 * @remark
     465 */
     466BOOL kFileLX::expandPage1(char *pachPage, const char * pachSrcPage, int cchSrcPage)
     467{
     468    struct LX_Iter *pIter = (struct LX_Iter *)pachSrcPage;
     469    char *          pachDestPage = pachPage; /* Store the pointer for boundrary checking. */
     470
     471    /* Validate size of data. */
     472    if (cchSrcPage >= PAGESIZE - 2)
     473        return FALSE;
     474
     475    /*
     476     * Expand the page.
     477     */
     478    while (pIter->LX_nIter)
     479    {
     480        /* Check if we're out of bound. */
     481        if (    pachPage - pachDesPage + pIter->LX_nIter * pIter->LX_nBytes > PAGESIZE
     482            ||  cchSrcPage <= 0)
     483            return FALSE;
     484
     485        if (pIter->LX_nBytes == 1)
     486        {   /* one databyte */
     487            memset(pachPage, &pIter->LX_Iterdata, pIter->LX_nIter);
     488            pchPage += pIter->LX_nIter;
     489            cchSrcPage -= pIter->LX_nIter + 4;
     490            pIter++;
     491        }
     492        else
     493        {
     494            for (int i = 0; i < pIter->LX_nIter; i++, pachPage += pIter->LX_nBytes)
     495                memcpy(pachPage, &pIter->LX_Iterdata, pIter->LX_nBytes);
     496            cchSrcPage -= 4 + pIter->LX_nBytes;
     497            pIter   = (pIter)((char*)pIter 4 + pIter->LX_nBytes);
     498        }
     499    }
     500    return TRUE;
     501#if 0
     502/* example code */
     503    int             off;
     504    struct LX_Iter *pIter;
     505    char *          pch = pvPage; /* Current position on page */
     506
     507    off = pe32->e32_datapage + (pObjMap->o32_pagedataoffset << pe32->e32_pageshift);
     508    if (pObjMap->o32_pagesize && (off + pObjMap->o32_pagesize - 1) >= cbFile)
     509    {
     510        fprintf(stderr, "Error: Page resides outside of the file.\n");
     511        return 1;
     512    }
     513    pIter = (struct LX_Iter *)((char*)pvFile + off);
     514
     515    /* expand page */
     516    while (pIter->LX_nIter > 0)
     517    {
     518        if (pch + (pIter->LX_nBytes * pIter->LX_nIter) > (char*)pvPage + OBJPAGELEN)
     519        {
     520            fprintf(stderr, "Error: Iterated page expands to more than a page!\n");
     521            return 1;
     522        }
     523
     524        if (pIter->LX_nBytes == 1)
     525        {
     526            memset(pch, pIter->LX_Iterdata, pIter->LX_nIter);
     527            pch += pIter->LX_nIter;
     528            pIter++;
     529        }
     530        else
     531        {
     532            int i;
     533            for (i = 0; i < pIter->LX_nIter; i++, pch += pIter->LX_nBytes)
     534                memcpy(pch, &pIter->LX_Iterdata, pIter->LX_nBytes);
     535            #if 1 /* curious */
     536            if (pIter->LX_nBytes > 2) fprintf(stdout, "pIter->LX_nBytes = %\n", pIter->LX_nBytes);
     537            #endif
     538
     539            pIter = (struct LX_Iter*)((char*)pIter + 4 + pIter->LX_nBytes);
     540        }
     541    }
     542
     543    return FALSE;
     544#endif
     545}
     546
     547
     548/**
     549 * Expands a page compressed with the exepack method introduced with OS/2 Warp 3.0.
     550 * (/EXEPACK:2)
     551 * @returns Successindicator.
     552 * @param   pachPage        Pointer to output page. size: PAGESIZE
     553 *                          Upon successful return this will contain the expanded page data.
     554 * @param   pachSrcPage     Pointer to source data. size: cchSrcPage.
     555 *                          This data should be compressed with EXEPACK:2!
     556 * @sketch  Have no good idea right now.
     557 * @status  Stub.
     558 * @author  knut st. osmundsen (knut.stange.osmundsen@mynd.no)
     559 * @remark
     560 */
     561BOOL kFileLX::expandPage2(char *pachPage, const char * pachSrcPage, int cchSrcPage)
     562{
     563    NOREF(pachPage);
     564    NOREF(pachSrcPage);
     565    NOREF(cchSrcPage);
     566    return FALSE;
     567}
     568
     569
     570/**
     571 * Compresses a page using the old exepack method introduced with OS/2 2.0.
     572 * (/EXEPACK:1 or just /EXEPACK)
     573 * @returns Size of the compressed page in the pachPage buffer.
     574 *          PAGESIZE if failed to compress the page.
     575 *          -1 on error.
     576 * @param   pachPage        Pointer to output buffer. size: PAGESIZE.
     577 *                          This will hold the compressed page data upon return.
     578 * @param   pachSrcPage     Pointer to page to compress. size: PAGESIZE.
     579 * @sketch
     580 * @status  stub.
     581 * @author  knut st. osmundsen (knut.stange.osmundsen@mynd.no)
     582 * @remark  Not implemented.
     583 */
     584int kFileLX::compressPage1(char *pachPage, const char * pachSrcPage)
     585{
     586    NOREF(pachPage);
     587    NOREF(pachSrcPage);
     588    return -1;
     589}
     590
     591
     592/**
     593 * Compresses a page using the exepack method introduced with OS/2 Warp 3.0.
     594 * (/EXEPACK:2)
     595 * @returns Size of the compressed page in the pachPage buffer.
     596 *          PAGESIZE if failed to compress the page.
     597 *          -1 on error.
     598 * @param   pachPage        Pointer to output buffer. size: PAGESIZE.
     599 *                          This will hold the compressed page data upon return.
     600 * @param   pachSrcPage     Pointer to page to compress. size: PAGESIZE.
     601 * @sketch  Have no idea!
     602 * @status  stub.
     603 * @author  knut st. osmundsen (knut.stange.osmundsen@mynd.no)
     604 * @remark  Not implemented.
     605 */
     606int kFileLX::compressPage2(char *pachPage, const char * pachSrcPage)
     607{
     608    NOREF(pachPage);
     609    NOREF(pachSrcPage);
     610    return -1;
     611}
     612
     613#endif
  • TabularUnified trunk/tools/common/kFileLX.h

    r4129 r4750  
    1 /* $Id: kFileLX.h,v 1.2 2000-08-31 03:00:13 bird Exp $
     1/* $Id: kFileLX.h,v 1.3 2000-12-04 08:48:09 bird Exp $
    22 *
    33 * kFileLX - Linear Executable file reader.
     
    1515
    1616
    17 class kFileLX : public kFileFormatBase
     17class kFileLX : public kFileFormatBase/*, public kPageI*/
    1818{
    1919protected:
    20     PVOID               pvBase;
    21     ULONG               offLXHdr;
    22     struct e32_exe *    pe32;
    23     struct o32_obj *    paObject;
     20    PVOID               pvBase;         /* Pointer to filemapping. */
     21    ULONG               cbFile;         /* Size of filemapping. */
     22    ULONG               offLXHdr;       /* Offset of the LX header. */
     23    struct e32_exe *    pe32;           /* Pointer to the exe header within the filemapping. */
     24    struct o32_obj *    paObject;       /* Pointer to the objecttable. */
     25    struct o32_map *    paMap;          /* Pointer to page map table. */
    2426
    2527    BOOL                queryExportName(int iOrdinal, char *pszBuffer);
     
    3739    int                 getObjectCount();
    3840
     41#if 0
     42    /** @cat Get and put page methods. (the first ones are generic) */
     43    BOOL                getPage(char *pachPage, ULONG ulAddress);
     44    BOOL                getPage(char *pachPage, int iObject, int offObject);
     45    BOOL                putPage(const char *pachPage, ULONG ulAddress);
     46    BOOL                putPage(const char *pachPage, int iObject, int offObject);
    3947
     48    BOOL                getPageLX(char *pachPage, int iObject, int iPage);
     49    BOOL                getPageLX(char *pachPage, int iPage);
     50    BOOL                putPageLX(const char *pachPage, int iObject, int iPage);
     51    BOOL                putPageLX(const char *pachPage, int iPage);
     52
     53    /** @cat Compression and expansion methods compatible with exepack:1 and exepack:2. */
     54    static BOOL         expandPage1(char *pachPage, const char * pachSrcPage, int cchSrcPage);
     55    static BOOL         expandPage2(char *pachPage, const char * pachSrcPage, int cchSrcPage);
     56    static int          compressPage1(char *pachPage, const char * pachSrcPage);
     57    static int          compressPage2(char *pachPage, const char * pachSrcPage);
     58#endif
    4059};
    4160#endif
Note: See TracChangeset for help on using the changeset viewer.