Ignore:
Timestamp:
Jan 8, 2004, 5:43:29 PM (22 years ago)
Author:
umoeller
Message:

Fixes that have piled up in the last three months.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/helpers/exeh.c

    r242 r257  
    266266
    267267        // read old DOS EXE header
    268         if (!(pExec->pDosExeHeader = (PDOSEXEHEADER)malloc(sizeof(DOSEXEHEADER))))
    269             arc = ERROR_NOT_ENOUGH_MEMORY;
    270         else if (!(arc = doshReadAt(pFile,
    271                                     0,
    272                                     &pExec->cbDosExeHeader,      // in/out
    273                                     (PBYTE)pExec->pDosExeHeader,
    274                                     DRFL_FAILIFLESS)))
     268        if ((arc = doshReadAt(pFile,
     269                              0,
     270                              &pExec->cbDosExeHeader,      // in/out
     271                              (PBYTE)&pExec->DosExeHeader,
     272                              DRFL_FAILIFLESS)))
     273            pExec->cbDosExeHeader = 0;
     274        else
    275275        {
    276276            // now check if we really have a DOS header
    277             if (pExec->pDosExeHeader->usDosExeID != 0x5a4d)
     277            if (pExec->DosExeHeader.usDosExeID != 0x5a4d)
    278278            {
    279279                // arc = ERROR_INVALID_EXE_SIGNATURE;
     
    289289                // remove the DOS header info, since we have none
    290290                // V0.9.12 (2001-05-03) [umoeller]
    291                 FREE(pExec->pDosExeHeader);
     291                // FREE(pExec->pDosExeHeader);
    292292                pExec->cbDosExeHeader = 0;
    293293            }
     
    295295            {
    296296                // we have a DOS header:
    297                 if (pExec->pDosExeHeader->usRelocTableOfs < 0x40)
     297                if (pExec->DosExeHeader.usRelocTableOfs < 0x40)
    298298                {
    299299                    // neither LX nor PE nor NE:
     
    305305                    // we have a new header offset:
    306306                    fLoadNewHeader = TRUE;
    307                     ulNewHeaderOfs = pExec->pDosExeHeader->ulNewHeaderOfs;
     307                    ulNewHeaderOfs = pExec->DosExeHeader.ulNewHeaderOfs;
    308308                }
    309309            }
     
    11991199        ULONG ulNewHeaderOfs = 0;       // V0.9.12 (2001-05-03) [umoeller]
    12001200
    1201         if (pExec->pDosExeHeader)
     1201        if (pExec->cbDosExeHeader)
    12021202            // executable has DOS stub: V0.9.12 (2001-05-03) [umoeller]
    1203             ulNewHeaderOfs = pExec->pDosExeHeader->ulNewHeaderOfs;
     1203            ulNewHeaderOfs = pExec->DosExeHeader.ulNewHeaderOfs;
    12041204
    12051205        if (pExec->ulExeFormat == EXEFORMAT_LX)
     
    13531353    HFILE hfExe = pExec->pFile->hf;
    13541354
    1355     if (pExec->pDosExeHeader)
     1355    if (pExec->cbDosExeHeader)
    13561356        // executable has DOS stub: V0.9.12 (2001-05-03) [umoeller]
    1357         ulNewHeaderOfs = pExec->pDosExeHeader->ulNewHeaderOfs;
     1357        ulNewHeaderOfs = pExec->DosExeHeader.ulNewHeaderOfs;
    13581358
    13591359    ENSURE(DosSetFilePtr(hfExe,
     
    15941594    HFILE hfExe = pExec->pFile->hf;
    15951595
    1596     if (pExec->pDosExeHeader)
     1596    if (pExec->cbDosExeHeader)
    15971597        // executable has DOS stub: V0.9.12 (2001-05-03) [umoeller]
    1598         ulNewHeaderOfs = pExec->pDosExeHeader->ulNewHeaderOfs;
     1598        ulNewHeaderOfs = pExec->DosExeHeader.ulNewHeaderOfs;
    15991599
    16001600    ENSURE(DosSetFilePtr(hfExe,
     
    18011801        ULONG ulNewHeaderOfs = 0; // V0.9.12 (2001-05-03) [umoeller]
    18021802
    1803         if (pExec->pDosExeHeader)
     1803        if (pExec->cbDosExeHeader)
    18041804            // executable has DOS stub: V0.9.12 (2001-05-03) [umoeller]
    1805             ulNewHeaderOfs = pExec->pDosExeHeader->ulNewHeaderOfs;
     1805            ulNewHeaderOfs = pExec->DosExeHeader.ulNewHeaderOfs;
    18061806
    18071807        if (pExec->ulExeFormat == EXEFORMAT_LX)
     
    19761976        ULONG           ulNewHeaderOfs = 0; // V0.9.12 (2001-05-03) [umoeller]
    19771977
    1978         if (pExec->pDosExeHeader)
     1978        if (pExec->cbDosExeHeader)
    19791979            // executable has DOS stub: V0.9.12 (2001-05-03) [umoeller]
    1980             ulNewHeaderOfs = pExec->pDosExeHeader->ulNewHeaderOfs;
     1980            ulNewHeaderOfs = pExec->DosExeHeader.ulNewHeaderOfs;
    19811981
    19821982        if (pExec->ulExeFormat == EXEFORMAT_LX)
     
    23712371        ULONG cb;
    23722372
    2373         if (pExec->pDosExeHeader)
     2373        if (pExec->cbDosExeHeader)
    23742374            // executable has DOS stub: V0.9.12 (2001-05-03) [umoeller]
    2375             ulNewHeaderOfs = pExec->pDosExeHeader->ulNewHeaderOfs;
     2375            ulNewHeaderOfs = pExec->DosExeHeader.ulNewHeaderOfs;
    23762376
    23772377        // resource table
     
    28832883        ULONG ulPageSize = pExec->pLXHeader->ulPageSize;
    28842884
     2885        // if the data is not compressed, we read it directly
     2886        // into caller's pbData buffer (avoid one memcpy)
     2887        // V1.0.2 (2003-11-13) [umoeller]
     2888        PBYTE pbTarget =
     2889            (ulFlags == VALID) ? pbData : pabCompressed;
     2890
    28852891        ulOffset += ulExeOffset;
    28862892
     
    28982904                                    ulOffset,
    28992905                                    &ulSize,
    2900                                     pabCompressed,
     2906                                    pbTarget, // pabCompressed, V1.0.2 (2003-11-13) [umoeller]
    29012907                                    0)))
    29022908        {
     
    29242930                break;
    29252931
     2932                /* V1.0.2 (2003-11-13) [umoeller]
    29262933                case VALID:
    29272934                    // uncompressed
     
    29302937                           ulPageSize);
    29312938                break;
     2939                */
    29322940            }
    29332941        }
     
    29482956 *      type _and_ ID.
    29492957 *
    2950  *      If NO_ERROR is returned, *ppbResData receives
    2951  *      a new buffer with the raw resource data, and
    2952  *      *pcbResData receives the size of that buffer.
    2953  *      The caller must then free() that buffer.
     2958 *      If NO_ERROR is returned,
     2959 *
     2960 *      --  *ppbResData receives a new buffer with
     2961 *          the raw resource data, which the caller
     2962 *          must free();
     2963 *
     2964 *      --  *pulOffset receives an offset into that
     2965 *          buffer, where the actual resource data
     2966 *          starts;
     2967 *
     2968 *      --  *pcbResData receives the size of the
     2969 *          following resource data (what follows
     2970 *          after *pulOffset).
     2971 *
     2972 *      The reason for this slightly complicated
     2973 *      format is to avoid another memcpy since
     2974 *      resource data need not necessarily be on
     2975 *      an LX page boundary.
    29542976 *
    29552977 *      This code will properly unpack compressed
     
    29772999                          ULONG idResource,      // in: resource ID or 0 for first
    29783000                          PBYTE *ppbResData,     // out: resource data (to be free()'d)
     3001                          PULONG pulOffset,      // out: offset of actual data in buffer
    29793002                          PULONG pcbResData)     // out: size of resource data (ptr can be NULL)
    29803003{
     
    29953018        return ERROR_INVALID_EXE_SIGNATURE;
    29963019
    2997     if (pExec->pDosExeHeader)
     3020    if (pExec->cbDosExeHeader)
    29983021        // executable has DOS stub: V0.9.12 (2001-05-03) [umoeller]
    2999         ulNewHeaderOfs = pExec->pDosExeHeader->ulNewHeaderOfs;
     3022        ulNewHeaderOfs = pExec->DosExeHeader.ulNewHeaderOfs;
    30003023
    30013024    if (!(cResources = pLXHeader->ulResTblCnt))
     
    31363159                        if (!arc)
    31373160                        {
    3138                             // allocate a new buffer for caller
    3139                             if (!(*ppbResData = (PBYTE)malloc(pRsEntry->cb)))
    3140                                 arc = ERROR_NOT_ENOUGH_MEMORY;
    3141                             else
    3142                             {
    3143                                 // copy into that buffer from the offset
    3144                                 // into the first page and the data from
    3145                                 // the subsequent pages too
    3146                                 memcpy(*ppbResData,
    3147                                        pabUncompressed + ulResOffsetInFirstPage,
    3148                                        pRsEntry->cb);
    3149 
    3150                                 if (pcbResData)
    3151                                     *pcbResData = pRsEntry->cb;
    3152                             }
     3161                            // new code without malloc/memcpy V1.0.2 (2003-11-13) [umoeller]
     3162                            *ppbResData = pabUncompressed;
     3163                            *pulOffset = ulResOffsetInFirstPage;
     3164
     3165
     3166                            /*
     3167                                // allocate a new buffer for caller
     3168                                if (!(*ppbResData = (PBYTE)malloc(pRsEntry->cb)))
     3169                                    arc = ERROR_NOT_ENOUGH_MEMORY;
     3170                                else
     3171                                {
     3172                                    // copy into that buffer from the offset
     3173                                    // into the first page and the data from
     3174                                    // the subsequent pages too
     3175                                    memcpy(*ppbResData,
     3176                                           pabUncompressed + ulResOffsetInFirstPage,
     3177                                           pRsEntry->cb);
     3178                                }
     3179                            */
     3180
     3181                            if (pcbResData)
     3182                                *pcbResData = pRsEntry->cb;
    31533183
    31543184                            fPtrFound = TRUE;
    31553185                        }
    3156 
    3157                         FREE(pabUncompressed);
     3186                        else
     3187                            FREE(pabUncompressed);
     3188
    31583189                        FREE(pabCompressed);
    31593190                    }
     
    32393270        ULONG cb;
    32403271
    3241         if (pExec->pDosExeHeader)
     3272        if (pExec->cbDosExeHeader)
    32423273            // executable has DOS stub: V0.9.12 (2001-05-03) [umoeller]
    3243             ulNewHeaderOfs = pExec->pDosExeHeader->ulNewHeaderOfs;
     3274            ulNewHeaderOfs = pExec->DosExeHeader.ulNewHeaderOfs;
    32443275
    32453276        // resource table
     
    33513382        return ERROR_INVALID_EXE_SIGNATURE;
    33523383
    3353     if (pExec->pDosExeHeader)
     3384    if (pExec->cbDosExeHeader)
    33543385        // executable has DOS stub: V0.9.12 (2001-05-03) [umoeller]
    3355         ulNewHeaderOfs = pExec->pDosExeHeader->ulNewHeaderOfs;
     3386        ulNewHeaderOfs = pExec->DosExeHeader.ulNewHeaderOfs;
    33563387
    33573388    // _Pmpf((__FUNCTION__ ": entering, checking %d resources", pNEHeader->usResSegmCount));
     
    34543485        char **papsz[] =
    34553486            {
    3456                 (char**)&pExec->pDosExeHeader,
     3487                // (char**)&pExec->pDosExeHeader,
    34573488                (char**)&pExec->pNEHeader,
    34583489                (char**)&pExec->pLXHeader,
Note: See TracChangeset for help on using the changeset viewer.