Changeset 21302 for trunk/src/kernel32/hmfile.cpp
- Timestamp:
- Jun 18, 2009, 11:53:26 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/hmfile.cpp
r10564 r21302 35 35 #include "mmap.h" 36 36 #include "oslibdos.h" 37 #include <customloader.h> 37 38 38 39 #define DBG_LOCALLOG DBG_hmfile … … 97 98 if (hFile != INVALID_HANDLE_ERROR) 98 99 { 99 pHMHandleData->dwUserData = (DWORD) new HMFileInfo( (LPSTR)lpFileName, lpSecurityAttributes);100 pHMHandleData->dwUserData = (DWORD) new HMFileInfo(hFile, (LPSTR)lpFileName, lpSecurityAttributes); 100 101 pHMHandleData->hHMHandle = hFile; 101 102 return (NO_ERROR); … … 261 262 262 263 if(hFile != HFILE_ERROR) { 263 pHMHandleData->dwUserData = (DWORD) new HMFileInfo( (LPSTR)lpFileName, NULL);264 pHMHandleData->dwUserData = (DWORD) new HMFileInfo(hFile, (LPSTR)lpFileName, NULL); 264 265 } 265 266 return (NO_ERROR); … … 302 303 PHMHANDLEDATA pHMSrcHandle, 303 304 HANDLE destprocess, 304 PHANDLE desthandle,305 305 DWORD fdwAccess, 306 306 BOOL fInherit, … … 311 311 DWORD rc; 312 312 313 dprintf(("KERNEL32:HMDeviceFileClass::DuplicateHandle (%08x,%08x,%08x,%08x ,%08x)",313 dprintf(("KERNEL32:HMDeviceFileClass::DuplicateHandle (%08x,%08x,%08x,%08x)", 314 314 pHMHandleData, 315 315 srcprocess, 316 316 pHMSrcHandle->hHMHandle, 317 destprocess, 318 desthandle)); 317 destprocess)); 319 318 320 319 //TODO: Inheritance of file handles won't work! … … 345 344 memcpy(pHMHandleData, &duphdata, sizeof(duphdata)); 346 345 347 if(fInherit) SetHandleInformation(pHMHandleData, ~HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);346 SetHandleInformation(pHMHandleData, HANDLE_FLAG_INHERIT, (fInherit) ? HANDLE_FLAG_INHERIT : 0); 348 347 349 348 SetLastError(ERROR_SUCCESS); … … 360 359 } 361 360 362 rc = OSLibDosDupHandle(pHMSrcHandle->hHMHandle,363 desthandle);361 pHMHandleData->hHMHandle = 0; 362 rc = OSLibDosDupHandle(pHMSrcHandle->hHMHandle, &pHMHandleData->hHMHandle); 364 363 if (rc) 365 364 { … … 370 369 } 371 370 else { 372 if(fInherit) SetHandleInformation(pHMHandleData, ~HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);371 SetHandleInformation(pHMHandleData, HANDLE_FLAG_INHERIT, (fInherit) ? HANDLE_FLAG_INHERIT : 0); 373 372 374 373 SetLastError(ERROR_SUCCESS); 375 pHMHandleData->hHMHandle = *desthandle;376 374 return TRUE; // OK 377 375 } … … 620 618 nrpages++; 621 619 622 map->commitRange((ULONG)lpBuffer, offset & ~0xfff, TRUE, nrpages);620 map->commitRange((ULONG)lpBuffer, offset & ~0xfff, FALSE, nrpages); 623 621 map->Release(); 624 622 } … … 844 842 { 845 843 DWORD ret; 844 HMFileInfo *fileInfo = (HMFileInfo *)pHMHandleData->dwUserData; 846 845 847 846 dprintfl(("KERNEL32: HMDeviceFileClass::SetFilePointer %s(%08xh,%08xh,%08xh,%08xh)\n", … … 852 851 dwMoveMethod)); 853 852 853 if(fileInfo && fileInfo->dwLXOffset) 854 { 855 switch(dwMoveMethod) 856 { 857 case FILE_BEGIN: 858 dprintf(("SetFilePointer FILE_BEGIN (LX) -> change offset from %x to %x", lDistanceToMove, lDistanceToMove+fileInfo->dwLXOffset)); 859 lDistanceToMove += fileInfo->dwLXOffset; 860 break; 861 862 case FILE_END: 863 //Could overshoot the virtual beginning of the PE file 864 lDistanceToMove -= MAGIC_STUBEXE_SIZE; 865 dprintf(("SetFilePointer FILE_END -> might be dangerous!!")); 866 break; 867 868 } 869 } 854 870 ret = OSLibDosSetFilePointer(pHMHandleData->hHMHandle, 855 871 lDistanceToMove, … … 1169 1185 } 1170 1186 1171 pHMHandleData->dwUserData = (DWORD) new HMFileInfo( (LPSTR)lpFileName, lpSecurityAttributes);1187 pHMHandleData->dwUserData = (DWORD) new HMFileInfo(0, (LPSTR)lpFileName, lpSecurityAttributes); 1172 1188 pHMHandleData->hHMHandle = 0x8000000; 1173 1189 return (NO_ERROR); … … 1282 1298 } 1283 1299 FindClose(hFind); 1300 1301 if(fileInfo->dwLXOffset) 1302 { 1303 //subtract the LX header and magic qword from the file size 1304 dprintf(("GetFileSize (LX) -> change size from %x to %x", finddata.nFileSizeLow, finddata.nFileSizeLow-fileInfo->dwLXOffset-MAGIC_STUBEXE_SIZE)); 1305 finddata.nFileSizeLow -= (fileInfo->dwLXOffset+MAGIC_STUBEXE_SIZE); 1306 } 1284 1307 return finddata.nFileSizeLow; 1285 1308 } … … 1329 1352 //****************************************************************************** 1330 1353 //****************************************************************************** 1331 HMFileInfo::HMFileInfo( LPSTR lpszFileName, PVOID lpSecurityAttributes)1354 HMFileInfo::HMFileInfo(HANDLE hFile, LPSTR lpszFileName, PVOID lpSecurityAttributes) 1332 1355 { 1333 1356 this->lpszFileName = (LPSTR)malloc(strlen(lpszFileName)+1); … … 1337 1360 strcpy(this->lpszFileName, lpszFileName); 1338 1361 this->lpSecurityAttributes = lpSecurityAttributes; 1362 dwLXOffset = 0; 1363 1364 //Only check files that end with .exe for now; they might be prepended with 1365 //an LX header. We need to skip that to present the original file to the 1366 //caller 1367 if(hFile && !stricmp(lpszFileName + strlen(lpszFileName) - 4, ".EXE")) 1368 { 1369 ULONG action, ulRead, signature, ulFileSize; 1370 ULONG magic[2]; 1371 IMAGE_DOS_HEADER doshdr; 1372 1373 //read dos header 1374 if(!OSLibDosRead(hFile, (LPVOID)&doshdr, sizeof(doshdr), &ulRead)) { 1375 goto failure; 1376 } 1377 if(OSLibDosSetFilePointer(hFile, doshdr.e_lfanew, NULL, FILE_BEGIN) != doshdr.e_lfanew) { 1378 goto failure; 1379 } 1380 //read signature dword 1381 if(!OSLibDosRead(hFile, (LPVOID)&signature, sizeof(signature), &ulRead)) { 1382 goto failure; 1383 } 1384 1385 //Make sure it's an LX executable before continueing 1386 if(doshdr.e_magic != IMAGE_DOS_SIGNATURE || (WORD)signature != IMAGE_OS2_SIGNATURE_LX) 1387 { 1388 goto failure; 1389 } 1390 1391 //magic signature located at 8 bytes from file end 1392 if(OSLibDosSetFilePointer(hFile, -8, NULL, FILE_END) == -1) { 1393 goto failure; 1394 } 1395 //read magic signature + pe offset 1396 if(!OSLibDosRead(hFile, (LPVOID)&magic[0], sizeof(magic), &ulRead)) { 1397 goto failure; 1398 } 1399 if(magic[0] != MAGIC_STUBEXE_SIGNATURE || magic[1] > ulFileSize) { 1400 goto failure; 1401 } 1402 //this is the offset of the PE image inside our LX executable 1403 dwLXOffset = magic[1]; 1404 1405 dprintf(("LX wrapper: PE file %s starts at %x", lpszFileName, dwLXOffset)); 1406 //reset file pointer to PE image start 1407 if(OSLibDosSetFilePointer(hFile, dwLXOffset, NULL, FILE_BEGIN) != dwLXOffset) { 1408 DebugInt3(); 1409 } 1410 goto end; 1411 1412 failure: 1413 //reset file pointer to file start 1414 if(OSLibDosSetFilePointer(hFile, 0, NULL, FILE_BEGIN) != 0) { 1415 DebugInt3(); 1416 } 1417 } 1418 end: 1419 return; 1339 1420 } 1340 1421 //******************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.