Changeset 257 for trunk/src/helpers/exeh.c
- Timestamp:
- Jan 8, 2004, 5:43:29 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/exeh.c
r242 r257 266 266 267 267 // 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/out273 (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 275 275 { 276 276 // now check if we really have a DOS header 277 if (pExec-> pDosExeHeader->usDosExeID != 0x5a4d)277 if (pExec->DosExeHeader.usDosExeID != 0x5a4d) 278 278 { 279 279 // arc = ERROR_INVALID_EXE_SIGNATURE; … … 289 289 // remove the DOS header info, since we have none 290 290 // V0.9.12 (2001-05-03) [umoeller] 291 FREE(pExec->pDosExeHeader);291 // FREE(pExec->pDosExeHeader); 292 292 pExec->cbDosExeHeader = 0; 293 293 } … … 295 295 { 296 296 // we have a DOS header: 297 if (pExec-> pDosExeHeader->usRelocTableOfs < 0x40)297 if (pExec->DosExeHeader.usRelocTableOfs < 0x40) 298 298 { 299 299 // neither LX nor PE nor NE: … … 305 305 // we have a new header offset: 306 306 fLoadNewHeader = TRUE; 307 ulNewHeaderOfs = pExec-> pDosExeHeader->ulNewHeaderOfs;307 ulNewHeaderOfs = pExec->DosExeHeader.ulNewHeaderOfs; 308 308 } 309 309 } … … 1199 1199 ULONG ulNewHeaderOfs = 0; // V0.9.12 (2001-05-03) [umoeller] 1200 1200 1201 if (pExec-> pDosExeHeader)1201 if (pExec->cbDosExeHeader) 1202 1202 // executable has DOS stub: V0.9.12 (2001-05-03) [umoeller] 1203 ulNewHeaderOfs = pExec-> pDosExeHeader->ulNewHeaderOfs;1203 ulNewHeaderOfs = pExec->DosExeHeader.ulNewHeaderOfs; 1204 1204 1205 1205 if (pExec->ulExeFormat == EXEFORMAT_LX) … … 1353 1353 HFILE hfExe = pExec->pFile->hf; 1354 1354 1355 if (pExec-> pDosExeHeader)1355 if (pExec->cbDosExeHeader) 1356 1356 // executable has DOS stub: V0.9.12 (2001-05-03) [umoeller] 1357 ulNewHeaderOfs = pExec-> pDosExeHeader->ulNewHeaderOfs;1357 ulNewHeaderOfs = pExec->DosExeHeader.ulNewHeaderOfs; 1358 1358 1359 1359 ENSURE(DosSetFilePtr(hfExe, … … 1594 1594 HFILE hfExe = pExec->pFile->hf; 1595 1595 1596 if (pExec-> pDosExeHeader)1596 if (pExec->cbDosExeHeader) 1597 1597 // executable has DOS stub: V0.9.12 (2001-05-03) [umoeller] 1598 ulNewHeaderOfs = pExec-> pDosExeHeader->ulNewHeaderOfs;1598 ulNewHeaderOfs = pExec->DosExeHeader.ulNewHeaderOfs; 1599 1599 1600 1600 ENSURE(DosSetFilePtr(hfExe, … … 1801 1801 ULONG ulNewHeaderOfs = 0; // V0.9.12 (2001-05-03) [umoeller] 1802 1802 1803 if (pExec-> pDosExeHeader)1803 if (pExec->cbDosExeHeader) 1804 1804 // executable has DOS stub: V0.9.12 (2001-05-03) [umoeller] 1805 ulNewHeaderOfs = pExec-> pDosExeHeader->ulNewHeaderOfs;1805 ulNewHeaderOfs = pExec->DosExeHeader.ulNewHeaderOfs; 1806 1806 1807 1807 if (pExec->ulExeFormat == EXEFORMAT_LX) … … 1976 1976 ULONG ulNewHeaderOfs = 0; // V0.9.12 (2001-05-03) [umoeller] 1977 1977 1978 if (pExec-> pDosExeHeader)1978 if (pExec->cbDosExeHeader) 1979 1979 // executable has DOS stub: V0.9.12 (2001-05-03) [umoeller] 1980 ulNewHeaderOfs = pExec-> pDosExeHeader->ulNewHeaderOfs;1980 ulNewHeaderOfs = pExec->DosExeHeader.ulNewHeaderOfs; 1981 1981 1982 1982 if (pExec->ulExeFormat == EXEFORMAT_LX) … … 2371 2371 ULONG cb; 2372 2372 2373 if (pExec-> pDosExeHeader)2373 if (pExec->cbDosExeHeader) 2374 2374 // executable has DOS stub: V0.9.12 (2001-05-03) [umoeller] 2375 ulNewHeaderOfs = pExec-> pDosExeHeader->ulNewHeaderOfs;2375 ulNewHeaderOfs = pExec->DosExeHeader.ulNewHeaderOfs; 2376 2376 2377 2377 // resource table … … 2883 2883 ULONG ulPageSize = pExec->pLXHeader->ulPageSize; 2884 2884 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 2885 2891 ulOffset += ulExeOffset; 2886 2892 … … 2898 2904 ulOffset, 2899 2905 &ulSize, 2900 p abCompressed,2906 pbTarget, // pabCompressed, V1.0.2 (2003-11-13) [umoeller] 2901 2907 0))) 2902 2908 { … … 2924 2930 break; 2925 2931 2932 /* V1.0.2 (2003-11-13) [umoeller] 2926 2933 case VALID: 2927 2934 // uncompressed … … 2930 2937 ulPageSize); 2931 2938 break; 2939 */ 2932 2940 } 2933 2941 } … … 2948 2956 * type _and_ ID. 2949 2957 * 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. 2954 2976 * 2955 2977 * This code will properly unpack compressed … … 2977 2999 ULONG idResource, // in: resource ID or 0 for first 2978 3000 PBYTE *ppbResData, // out: resource data (to be free()'d) 3001 PULONG pulOffset, // out: offset of actual data in buffer 2979 3002 PULONG pcbResData) // out: size of resource data (ptr can be NULL) 2980 3003 { … … 2995 3018 return ERROR_INVALID_EXE_SIGNATURE; 2996 3019 2997 if (pExec-> pDosExeHeader)3020 if (pExec->cbDosExeHeader) 2998 3021 // executable has DOS stub: V0.9.12 (2001-05-03) [umoeller] 2999 ulNewHeaderOfs = pExec-> pDosExeHeader->ulNewHeaderOfs;3022 ulNewHeaderOfs = pExec->DosExeHeader.ulNewHeaderOfs; 3000 3023 3001 3024 if (!(cResources = pLXHeader->ulResTblCnt)) … … 3136 3159 if (!arc) 3137 3160 { 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; 3153 3183 3154 3184 fPtrFound = TRUE; 3155 3185 } 3156 3157 FREE(pabUncompressed); 3186 else 3187 FREE(pabUncompressed); 3188 3158 3189 FREE(pabCompressed); 3159 3190 } … … 3239 3270 ULONG cb; 3240 3271 3241 if (pExec-> pDosExeHeader)3272 if (pExec->cbDosExeHeader) 3242 3273 // executable has DOS stub: V0.9.12 (2001-05-03) [umoeller] 3243 ulNewHeaderOfs = pExec-> pDosExeHeader->ulNewHeaderOfs;3274 ulNewHeaderOfs = pExec->DosExeHeader.ulNewHeaderOfs; 3244 3275 3245 3276 // resource table … … 3351 3382 return ERROR_INVALID_EXE_SIGNATURE; 3352 3383 3353 if (pExec-> pDosExeHeader)3384 if (pExec->cbDosExeHeader) 3354 3385 // executable has DOS stub: V0.9.12 (2001-05-03) [umoeller] 3355 ulNewHeaderOfs = pExec-> pDosExeHeader->ulNewHeaderOfs;3386 ulNewHeaderOfs = pExec->DosExeHeader.ulNewHeaderOfs; 3356 3387 3357 3388 // _Pmpf((__FUNCTION__ ": entering, checking %d resources", pNEHeader->usResSegmCount)); … … 3454 3485 char **papsz[] = 3455 3486 { 3456 (char**)&pExec->pDosExeHeader,3487 // (char**)&pExec->pDosExeHeader, 3457 3488 (char**)&pExec->pNEHeader, 3458 3489 (char**)&pExec->pLXHeader,
Note:
See TracChangeset
for help on using the changeset viewer.