Changeset 6234 for trunk/src/win32k/pe2lx/pe2lx.cpp
- Timestamp:
- Jul 8, 2001, 5:23:44 AM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/win32k/pe2lx/pe2lx.cpp
r5985 r6234 1 /* $Id: pe2lx.cpp,v 1.2 7 2001-06-13 04:49:11bird Exp $1 /* $Id: pe2lx.cpp,v 1.28 2001-07-08 03:23:44 bird Exp $ 2 2 * 3 3 * Pe2Lx class implementation. Ring 0 and Ring 3 … … 18 18 #define INCL_DOSERRORS /* DOS Error codes. */ 19 19 #define INCL_OS2KRNL_LDR /* Loader definitions. */ 20 #define INCL_OS2KRNL_PTDA /* PTDA definitions. */ 20 21 #ifdef RING0 21 22 #define INCL_NOAPI /* RING0: No apis. */ … … 101 102 #include "ldr.h" /* ldr helpers. (ldrGetExePath) */ 102 103 #include "env.h" /* Environment helpers. */ 104 #include "dev32hlp.h" /* 32-bit devhlpers. Needs LOCKHANDLE. */ 105 #include "PerTaskW32kData.h" /* Per Task Win32k Data. */ 103 106 #endif 104 107 #include "modulebase.h" /* ModuleBase class definitions, ++. */ … … 587 590 } 588 591 } 592 ulImageBase = pNtHdrs->OptionalHeader.ImageBase; 589 593 LXHdr.e32_mflags = pNtHdrs->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI 590 594 ? E32PMAPI : E32PMW; … … 592 596 LXHdr.e32_mflags |= E32LIBINIT | E32LIBTERM | E32MODDLL; 593 597 else 598 { 594 599 LXHdr.e32_mflags |= E32MODEXE; 595 if (pNtHdrs->FileHeader.Characteristics & IMAGE_FILE_RELOCS_STRIPPED) 596 LXHdr.e32_mflags |= E32NOINTFIX; 597 ulImageBase = pNtHdrs->OptionalHeader.ImageBase; 600 if ( pNtHdrs->FileHeader.Characteristics & IMAGE_FILE_RELOCS_STRIPPED /* Force location if possible. */ 601 || ulImageBase < 0x04000000 && ulImageBase + pNtHdrs->OptionalHeader.SizeOfImage < 0x04000000) 602 LXHdr.e32_mflags |= E32NOINTFIX; 603 } 598 604 599 605 /* 13.Convert exports. */ … … 1091 1097 #ifdef DEBUG 1092 1098 if (cObjects != pSMTE->smte_objcnt) 1093 printErr(("cObject (%d) != smte_objcnt(%d)\n", cObjects, pSMTE->smte_objcnt));1099 printErr(("cObjects(%d) != smte_objcnt(%d)\n", cObjects, pSMTE->smte_objcnt)); 1094 1100 #endif 1095 1101 fApplyFixups = FALSE; … … 1108 1114 } 1109 1115 1116 if (fDeltaOnly) 1117 return applyFixupsDelta(pvPage, ulDelta, ulRVAPage); 1118 1119 /* 1120 * Iterate thru the fixup chunks until we find one or two with fixups valid for 1121 * this page. I say one or two since we might have cross page fixups from the previous page 1122 * So, we'll have to start working at the previous page. 1123 * ASSUME: -fixups are sorted ascendingly on page RVA. only one chunk per page. 1124 * -only one cross page fixup at each end which doesn't overlapp with other fixups. 1125 */ 1110 1126 PIMAGE_BASE_RELOCATION pbr = pBaseRelocs; 1111 ULONG ulBefore;1112 ULONG ulAfter;1113 ULONG flRead = 0; /* bitmask: 0 = no read, 1 = ulBefore is read, 2 = ulAfter is read */1114 1127 1115 1128 while ((unsigned)pbr - (unsigned)pBaseRelocs + 8 < cbBaseRelocs /* 8= VirtualAddress and SizeOfBlock members */ … … 1117 1130 && pbr->VirtualAddress < ulRVAPage + PAGESIZE) 1118 1131 { 1132 1119 1133 if (pbr->VirtualAddress + PAGESIZE >= ulRVAPage) 1120 1134 { … … 1129 1143 } 1130 1144 1145 1146 /* 1147 * skip to near end of previous page to save time 1148 * I just don't dare to skip to the second last offset, 1149 * 7 offsets from the end sounds nice and secure. 1150 */ 1151 if (pbr->VirtualAddress < ulRVAPage && cRelocations > 7) 1152 { 1153 pwoffFixup += cRelocations - 7; /* */ 1154 cRelocations = 7; 1155 } 1156 1157 1158 /* 1159 * Loop thru the fixups in this chunk. 1160 */ 1131 1161 while (cRelocations != 0) 1132 1162 { 1133 static char acbFixupTypes[16] = {0x00, 0x02, 0x02, 0x04, 1163 /* 1164 * Fixup size table. 0xFF for fixups which aren't supported 1165 * or is just non-sense. 1166 */ 1167 #define CBFIXUPMAX 4 1168 static char acbFixupTypes[16] = {0xFF, 0x02, 0x02, 0x04, 1134 1169 0xFF, 0xFF, 0xFF, 0xFF, 1135 1170 0xFF, 0xFF, 0xFF, 0xFF, 1136 1171 0xFF, 0xFF, 0xFF, 0xFF}; 1137 int offFixup = *pwoffFixup & ( PAGESIZE-1);1172 int offFixup = *pwoffFixup & (int)(PAGESIZE-1); 1138 1173 int fType = *pwoffFixup >> 12; 1139 1174 int cbFixup = acbFixupTypes[fType]; 1140 1175 1141 if (cbFixup != 0 && cbFixup <= 41176 if (cbFixup <= CBFIXUPMAX 1142 1177 && offFixup + pbr->VirtualAddress + (cbFixup-1) >= ulRVAPage 1143 1178 && offFixup + pbr->VirtualAddress < ulRVAPage + PAGESIZE … … 1146 1181 ULONG iObj; 1147 1182 ULONG ulTarget; 1148 PULONG pul; /* Pointer to fixup target */ 1149 ULONG ul; /* Crosspage fixups: Conent of fixup target */ 1150 unsigned uShift1; /* Crosspage fixups: Shift */ 1151 unsigned uShift2; /* Crosspage fixups: Inverse of Shift1 */ 1183 ULONG ul; /* Crosspage fixups: Content of fixup target */ 1152 1184 1153 1185 if (offFixup + pbr->VirtualAddress < ulRVAPage) 1154 1186 { /* 1155 1187 * Crosspagefixup - from the page before 1188 * Start by reading the bytes on the previous page. We have to in case 1189 * of carray. 1156 1190 */ 1157 uShift1 = (unsigned)((offFixup + pbr->VirtualAddress) % cbFixup) * 8; 1158 uShift2 = cbFixup * 8 - uShift1; 1159 pul = (PULONG)pvPage; 1160 ul = *pul; 1191 //printInf(("Crosspagefixup at offset=%d type=%d\n", offFixup - PAGESIZE, fType)); 1192 printf("Crosspagefixup at offset=%d type=%d\n", offFixup - PAGESIZE, fType); 1193 rc = readAtRVA(ulRVAPage + offFixup - PAGESIZE, SSToDS(&ul), sizeof(ul)); 1194 if (rc != NO_ERROR) 1195 { 1196 printErr(("readAtRVA(0x%08x, ul(Before)..) failed with rc=%d\n", ulRVAPage + offFixup - PAGESIZE, rc)); 1197 return rc; 1198 } 1199 1200 /* 1201 * If none-delta and highlow fixup try resolve target address. 1202 * Falls back on delta fixup. We have to do this because of 1203 * object alignment problems. 1204 */ 1205 iObj = ~0UL; 1161 1206 if (!fDeltaOnly && fType == IMAGE_REL_BASED_HIGHLOW) 1162 1207 { 1163 /* Read? */1164 if ((flRead & 1) == 0)1165 {1166 rc = readAtRVA(ulRVAPage - 4, SSToDS(&ulBefore), sizeof(ulBefore));1167 if (rc != NO_ERROR)1168 {1169 printErr(("readAtRVA(0x%08x, ulBefore..) failed with rc=%d\n", ulRVAPage-4, rc));1170 return rc;1171 }1172 flRead |= 1;1173 }1174 1208 /* Get target pointer, find it's object and apply the fixup */ 1175 ulTarget = (ulBefore >> uShift1) | (ul << uShift2); 1176 ulTarget -= ulImageBase; /* ulTarget is now an RVA */ 1209 ulTarget = ul - ulImageBase; /* ulTarget is now an RVA */ 1177 1210 iObj = 0UL; 1178 1211 while (iObj < cObjects … … 1182 1215 iObj++; 1183 1216 if (iObj < cObjects) 1184 *pul = ((pSMTE->smte_objtab[iObj].ote_base + ulTarget - paObjects[iObj].ulRVA) >> uShift2) 1185 | (ul & ((~0UL) << uShift1)); 1186 else 1187 *pul = (((ulDelta >> uShift2) + ul) & ((~0UL) >> uShift2)) | (ul & ((~0UL) << uShift1)); 1217 ul = pSMTE->smte_objtab[iObj].ote_base + ulTarget - paObjects[iObj].ulRVA; 1188 1218 } 1189 else 1190 { /* apply delta fixup */ 1219 1220 /* 1221 * Apply delta fixup. 1222 */ 1223 if (iObj >= cObjects) 1224 { 1191 1225 switch (fType) 1192 1226 { 1227 case IMAGE_REL_BASED_LOW: 1193 1228 case IMAGE_REL_BASED_HIGHLOW: 1194 *pul = (((ulDelta >> uShift2) + ul) & ((~0UL) >> uShift2)) | (ul & ((~0UL) << uShift1));1229 ul += ulDelta; 1195 1230 break; 1196 1231 case IMAGE_REL_BASED_HIGH: 1197 1232 case IMAGE_REL_BASED_HIGHADJ: /* According to M$ docs these seems to be the same fixups. */ 1198 1233 case IMAGE_REL_BASED_HIGH3ADJ: 1199 *pul = (((ulDelta >> 24) + ul) & 0xFF) | (ul & 0xFFFFFF00UL);1234 ul += ulDelta >> 16; 1200 1235 break; 1201 case IMAGE_REL_BASED_LOW: 1202 *pul = (((ulDelta >> 8) + ul) & 0xFF) | (ul & 0xFFFFFF00UL); 1236 case IMAGE_REL_BASED_ABSOLUTE: 1203 1237 break; 1238 default: 1239 printErr(("Unknown fixup type %d offset=%0x%08x\n", fType, offFixup)); 1204 1240 } 1205 1241 } 1242 1243 /* 1244 * Copy the needed fixup data from ul to the page. 1245 */ 1246 if (cbFixup <= CBFIXUPMAX) 1247 memcpy(pvPage, (char*)SSToDS(&ul) + PAGESIZE - offFixup, (size_t)(cbFixup - PAGESIZE + offFixup)); 1206 1248 } 1207 1249 else if (offFixup + pbr->VirtualAddress + cbFixup > ulRVAPage + PAGESIZE) … … 1209 1251 * Crosspagefixup - into the page afterwards 1210 1252 */ 1211 uShift1 = (unsigned)((offFixup + pbr->VirtualAddress) % cbFixup) * 8; 1212 uShift2 = cbFixup * 8 - uShift1; 1213 pul = (PULONG)((unsigned)pvPage + PAGESIZE - sizeof(ULONG)); 1214 ul = *pul; 1253 printInf(("Crosspagefixup at offset=%d type=%d\n", PAGESIZE-offFixup, fType)); 1254 1255 /* 1256 * If none-delta and highlow fixup then read the full 4 bytes so we can 1257 * resolve the target address and fix it. 1258 * If we fail to fix it we'll fall back on delta fixup. 1259 */ 1260 iObj = ~0UL; 1215 1261 if (!fDeltaOnly && fType == IMAGE_REL_BASED_HIGHLOW) 1216 1262 { 1217 /* Read? */1218 if ( (flRead & 2) == 0)1263 rc = readAtRVA(ulRVAPage + offFixup, SSToDS(&ul), sizeof(ul)); 1264 if (rc != NO_ERROR) 1219 1265 { 1220 rc = readAtRVA(ulRVAPage+PAGESIZE, SSToDS(&ulAfter), sizeof(ulAfter)); 1221 if (rc != NO_ERROR) 1222 { 1223 printErr(("readAtRVA(0x%08x, ulAfter..) failed with rc=%d\n", ulRVAPage+PAGESIZE, rc)); 1224 return rc; 1225 } 1226 flRead |= 2; 1266 printErr(("readAtRVA(0x%08x, ul(After)..) failed with rc=%d\n", ulRVAPage+offFixup, rc)); 1267 return rc; 1227 1268 } 1269 1228 1270 /* Get target pointer, find it's object and apply the fixup */ 1229 ulTarget = (ulAfter << uShift2) | (ul >> uShift1); 1230 ulTarget -= ulImageBase; /* ulTarget is now an RVA */ 1271 ulTarget = ul - ulImageBase; /* ulTarget is now an RVA */ 1231 1272 iObj = 0UL; 1232 1273 while (iObj < cObjects … … 1236 1277 iObj++; 1237 1278 if (iObj < cObjects) 1238 *pul = ((pSMTE->smte_objtab[iObj].ote_base + ulTarget - paObjects[iObj].ulRVA) << uShift1) 1239 | (ul & ((~0UL) >> uShift2)); 1240 else 1241 *pul += ulDelta << uShift1; 1279 ul = pSMTE->smte_objtab[iObj].ote_base + ulTarget - paObjects[iObj].ulRVA; 1242 1280 } 1243 else 1244 { /* apply delta fixup */ 1281 1282 /* 1283 * Apply delta fixup. 1284 */ 1285 if (iObj >= cObjects) 1286 { 1287 ul = 0; 1288 memcpy(SSToDS(&ul), (char*)pvPage + offFixup, (size_t)(PAGESIZE - offFixup)); 1245 1289 switch (fType) 1246 1290 { 1291 case IMAGE_REL_BASED_LOW: 1247 1292 case IMAGE_REL_BASED_HIGHLOW: 1248 *pul += ulDelta << uShift1;1293 ul += ulDelta; 1249 1294 break; 1250 1295 case IMAGE_REL_BASED_HIGH: 1251 1296 case IMAGE_REL_BASED_HIGHADJ: /* According to M$ docs these seems to be the same fixups. */ 1252 1297 case IMAGE_REL_BASED_HIGH3ADJ: 1253 *pul += ulDelta <<8;1298 ul += ulDelta >> 8; 1254 1299 break; 1255 case IMAGE_REL_BASED_LOW: 1256 *pul += ulDelta << 24; 1300 case IMAGE_REL_BASED_ABSOLUTE: 1257 1301 break; 1302 default: 1303 printErr(("Unknown fixup type %d offset=%0x%08x\n", fType, offFixup)); 1258 1304 } 1259 1305 } 1306 1307 /* 1308 * Copy the needed fixup data from ul to the page. 1309 */ 1310 if (cbFixup <= CBFIXUPMAX) 1311 memcpy((char*)pvPage + offFixup, (char*)SSToDS(&ul), (size_t)(PAGESIZE - offFixup)); 1260 1312 } 1261 1313 else … … 1263 1315 * Common fixup 1264 1316 */ 1317 PULONG pul; /* Pointer to fixup target */ 1265 1318 pul = (PULONG)((unsigned)pvPage + offFixup + pbr->VirtualAddress - ulRVAPage); 1266 1319 switch (fType) … … 1272 1325 else 1273 1326 { 1274 ulTarget = *pul; 1275 ulTarget -= ulImageBase; /* ulTarget is now an RVA */ 1327 ulTarget = *pul - ulImageBase; /* ulTarget is now an RVA */ 1276 1328 iObj = 0UL; 1277 1329 while (iObj < cObjects … … 1286 1338 } 1287 1339 break; 1340 1341 /* Placeholder. */ 1342 case IMAGE_REL_BASED_ABSOLUTE: 1343 break; 1344 1288 1345 /* Will probably not work very well until the 64KB object alignment is gone! */ 1289 1346 case IMAGE_REL_BASED_HIGH: … … 1298 1355 *(PUSHORT)pul += (USHORT)ulDelta; 1299 1356 break; 1357 default: 1358 printErr(("Unknown fixup type %d offset=%0x%08x\n", fType, offFixup)); 1300 1359 } 1301 1360 } 1302 1361 } 1303 1362 1304 /* Next offset/type */ 1363 /* 1364 * Next offset/type 1365 */ 1305 1366 pwoffFixup++; 1306 1367 cRelocations--; 1307 } 1308 } 1309 1310 /* next */ 1368 } /* while loop */ 1369 1370 } /* else: not touching this page */ 1371 1372 /* 1373 * Next Fixup chunk. (i.e. next page) 1374 */ 1311 1375 pbr = (PIMAGE_BASE_RELOCATION)((unsigned)pbr + pbr->SizeOfBlock); 1312 } 1313 } 1376 } /* while loop */ 1377 } /* else: don't need to apply fixups */ 1314 1378 NOREF(iPageTable); 1315 1379 NOREF(pvPTDA); … … 1319 1383 1320 1384 1385 /** 1386 * applyFixups worker used when only deltas are to be applied. 1387 */ 1388 ULONG Pe2Lx::applyFixupsDelta(PVOID pvPage, ULONG ulDelta, ULONG ulRVAPage) 1389 { 1390 /* 1391 * Iterate thru the fixup chunks until we find one or two with fixups valid for 1392 * this page. I say one or two since we might have cross page fixups from the previous page 1393 * So, we'll have to start working at the previous page. 1394 * ASSUME: -fixups are sorted ascendingly on page RVA. only one chunk per page. 1395 * -only one cross page fixup at each end which doesn't overlapp with other fixups. 1396 */ 1397 PIMAGE_BASE_RELOCATION pbr = pBaseRelocs; 1398 1399 while ((unsigned)pbr - (unsigned)pBaseRelocs + 8 < cbBaseRelocs /* 8= VirtualAddress and SizeOfBlock members */ 1400 && pbr->SizeOfBlock >= 8 1401 && pbr->VirtualAddress < ulRVAPage + PAGESIZE) 1402 { 1403 1404 if (pbr->VirtualAddress + PAGESIZE >= ulRVAPage) 1405 { 1406 PWORD pwoffFixup = &pbr->TypeOffset[0]; 1407 ULONG cRelocations = (pbr->SizeOfBlock - offsetof(IMAGE_BASE_RELOCATION, TypeOffset)) / sizeof(WORD); /* note that sizeof(BaseReloc) is 12 bytes! */ 1408 1409 /* Some bound checking just to be sure it works... */ 1410 if ((unsigned)pbr - (unsigned)pBaseRelocs + pbr->SizeOfBlock > cbBaseRelocs) 1411 { 1412 printWar(("Block ends after BaseRelocation datadirectory.\n")); 1413 cRelocations = (((unsigned)pBaseRelocs + cbBaseRelocs) - (unsigned)pbr - offsetof(IMAGE_BASE_RELOCATION, TypeOffset)) / sizeof(WORD); 1414 } 1415 1416 1417 /* 1418 * skip to near end of previous page to save time 1419 * I just don't dare to skip to the second last offset, 1420 * 7 offsets from the end sounds nice and secure. 1421 */ 1422 if (pbr->VirtualAddress < ulRVAPage && cRelocations > 7) 1423 { 1424 pwoffFixup += cRelocations - 7; /* */ 1425 cRelocations = 7; 1426 } 1427 1428 1429 /* 1430 * Loop thru the fixups in this chunk. 1431 */ 1432 while (cRelocations != 0) 1433 { 1434 /* 1435 * Fixup size table. 0xFF for fixups which aren't supported 1436 * or is just non-sense. 1437 */ 1438 #define CBFIXUPMAX 4 1439 static char acbFixupTypes[16] = {0xFF, 0x02, 0x02, 0x04, 1440 0xFF, 0xFF, 0xFF, 0xFF, 1441 0xFF, 0xFF, 0xFF, 0xFF, 1442 0xFF, 0xFF, 0xFF, 0xFF}; 1443 int offFixup = *pwoffFixup & (int)(PAGESIZE-1); 1444 int fType = *pwoffFixup >> 12; 1445 int cbFixup = acbFixupTypes[fType]; 1446 1447 if (cbFixup <= CBFIXUPMAX 1448 && offFixup + pbr->VirtualAddress + (cbFixup-1) >= ulRVAPage 1449 && offFixup + pbr->VirtualAddress < ulRVAPage + PAGESIZE 1450 ) 1451 { 1452 ULONG ul; /* Crosspage fixups: Content of fixup target */ 1453 1454 if (offFixup + pbr->VirtualAddress < ulRVAPage) 1455 { /* 1456 * Crosspagefixup - from the page before 1457 * Start by reading the bytes on the previous page. We have to in case 1458 * of carray. 1459 */ 1460 printInf(("Crosspagefixup at offset=%d type=%d\n", offFixup - PAGESIZE, fType)); 1461 APIRET rc = readAtRVA(ulRVAPage + offFixup - PAGESIZE, SSToDS(&ul), sizeof(ul)); 1462 if (rc != NO_ERROR) 1463 { 1464 printErr(("readAtRVA(0x%08x, ul(Before)..) failed with rc=%d\n", ulRVAPage + offFixup - PAGESIZE, rc)); 1465 return rc; 1466 } 1467 1468 /* 1469 * Apply delta fixup. 1470 */ 1471 switch (fType) 1472 { 1473 case IMAGE_REL_BASED_LOW: 1474 case IMAGE_REL_BASED_HIGHLOW: 1475 ul += ulDelta; 1476 break; 1477 case IMAGE_REL_BASED_HIGH: 1478 case IMAGE_REL_BASED_HIGHADJ: /* According to M$ docs these seems to be the same fixups. */ 1479 case IMAGE_REL_BASED_HIGH3ADJ: 1480 ul += ulDelta >> 16; 1481 break; 1482 case IMAGE_REL_BASED_ABSOLUTE: 1483 break; 1484 default: 1485 printErr(("Unknown fixup type %d offset=%0x%08x\n", fType, offFixup)); 1486 } 1487 1488 /* 1489 * Copy the needed fixup data from ul to the page. 1490 */ 1491 if (cbFixup <= CBFIXUPMAX) 1492 memcpy(pvPage, (char*)SSToDS(&ul) + PAGESIZE - offFixup, (size_t)(cbFixup - PAGESIZE + offFixup)); 1493 } 1494 else if (offFixup + pbr->VirtualAddress + cbFixup > ulRVAPage + PAGESIZE) 1495 { /* 1496 * Crosspagefixup - into the page afterwards 1497 */ 1498 printInf(("Crosspagefixup at offset=%d type=%d\n", PAGESIZE-offFixup, fType)); 1499 1500 /* 1501 * Apply delta fixup. 1502 */ 1503 ul = 0; 1504 memcpy(SSToDS(&ul), (char*)pvPage + offFixup, (size_t)(PAGESIZE - offFixup)); 1505 switch (fType) 1506 { 1507 case IMAGE_REL_BASED_LOW: 1508 case IMAGE_REL_BASED_HIGHLOW: 1509 ul += ulDelta; 1510 break; 1511 case IMAGE_REL_BASED_HIGH: 1512 case IMAGE_REL_BASED_HIGHADJ: /* According to M$ docs these seems to be the same fixups. */ 1513 case IMAGE_REL_BASED_HIGH3ADJ: 1514 ul += ulDelta >> 8; 1515 break; 1516 case IMAGE_REL_BASED_ABSOLUTE: 1517 break; 1518 default: 1519 printErr(("Unknown fixup type %d offset=%0x%08x\n", fType, offFixup)); 1520 } 1521 1522 /* 1523 * Copy the needed fixup data from ul to the page. 1524 */ 1525 if (cbFixup <= CBFIXUPMAX) 1526 memcpy((char*)pvPage + offFixup, (char*)SSToDS(&ul), (size_t)(PAGESIZE - offFixup)); 1527 } 1528 else 1529 { /* 1530 * Common fixup 1531 */ 1532 PULONG pul; /* Pointer to fixup target */ 1533 pul = (PULONG)((unsigned)pvPage + offFixup + pbr->VirtualAddress - ulRVAPage); 1534 switch (fType) 1535 { 1536 case IMAGE_REL_BASED_HIGHLOW: 1537 printInfA(("IMAGE_REL_BASED_HIGHLOW offset=0x%08x\n", offFixup)); 1538 *pul += ulDelta; 1539 break; 1540 /* Placeholder. */ 1541 case IMAGE_REL_BASED_ABSOLUTE: 1542 break; 1543 /* Will probably not work very well until the 64KB object alignment is gone! */ 1544 case IMAGE_REL_BASED_HIGH: 1545 case IMAGE_REL_BASED_HIGHADJ: /* According to M$ docs these seems to be the same fixups. */ 1546 case IMAGE_REL_BASED_HIGH3ADJ: 1547 printInfA(("IMAGE_REL_BASED_HIGH offset=0x%08x\n", offFixup)); 1548 *(PUSHORT)pul += (USHORT)(ulDelta >> 16); 1549 break; 1550 /* Will probably not work very well until the 64KB object alignment is gone! */ 1551 case IMAGE_REL_BASED_LOW: 1552 printInfA(("IMAGE_REL_BASED_LOW offset=0x%08x\n", offFixup)); 1553 *(PUSHORT)pul += (USHORT)ulDelta; 1554 break; 1555 default: 1556 printErr(("Unknown fixup type %d offset=%0x%08x\n", fType, offFixup)); 1557 } 1558 } 1559 } 1560 1561 /* 1562 * Next offset/type 1563 */ 1564 pwoffFixup++; 1565 cRelocations--; 1566 } /* while loop */ 1567 1568 } /* else: not touching this page */ 1569 1570 /* 1571 * Next Fixup chunk. (i.e. next page) 1572 */ 1573 pbr = (PIMAGE_BASE_RELOCATION)((unsigned)pbr + pbr->SizeOfBlock); 1574 } /* while loop */ 1575 1576 return NO_ERROR; 1577 } 1321 1578 1322 1579 /** … … 1351 1608 * Initiate the Odin32 Path static variable and call worker. 1352 1609 */ 1610 #ifdef DEBUG 1611 APIRET rc; 1612 //kprintf(("pe2lx::openPath(%.*s, %d, %x, %x, %x)\n", 1613 // cchFilename, pachFilename, cchFilename, pLdrLv, pful, lLibPath)); 1614 rc = openPath2(pachFilename, cchFilename, pLdrLv, pful, lLibPath, initOdin32Path()); 1615 //kprintf(("pe2lx::openPath rc=%d\n", rc)); 1616 return rc; 1617 #else 1353 1618 return openPath2(pachFilename, cchFilename, pLdrLv, pful, lLibPath, initOdin32Path()); 1619 #endif 1354 1620 1355 1621 #else … … 1388 1654 * (cchFilename should have been USHORT. But, then the compiler would 1389 1655 * treat it as an ULONG.) 1656 * TODO: Support quotes. 1390 1657 */ 1391 1658 ULONG Pe2Lx::openPath2(PCHAR pachFilename, ULONG cchFilename, ldrlv_t *pLdrLv, PULONG pful, ULONG lLibPath, BOOL fOdin32PathValid) … … 1407 1674 #define FINDDLL_ENDLIBPATH 9 /* uses ldrOpenPath */ 1408 1675 #define FINDDLL_FIRST FINDDLL_EXECUTABLEDIR 1409 #define FINDDLL_LAST FINDDLL_ PATH1676 #define FINDDLL_LAST FINDDLL_ENDLIBPATH 1410 1677 1411 1678 struct _LocalVars … … 1424 1691 pVars = (struct _LocalVars*)rmalloc(sizeof(struct _LocalVars)); 1425 1692 if (pVars == NULL) 1693 { 1694 printErr(("openPath2: rmalloc failed\n")); 1426 1695 return ERROR_NOT_ENOUGH_MEMORY; 1696 } 1427 1697 1428 1698 cchExt = cchFilename - 1; … … 1446 1716 case FINDDLL_EXECUTABLEDIR: 1447 1717 if ((pszPath = ldrGetExePath(pVars->szPath, TRUE)) == NULL) 1718 { 1719 //kprintf(("openPath2: failed to find exe path.\n")); //DEBUG 1448 1720 continue; 1721 } 1449 1722 break; 1450 1723 … … 1455 1728 case FINDDLL_SYSTEM32DIR: 1456 1729 if (!fOdin32PathValid) 1730 { 1731 //kprintf(("openPath2: invalid odin32 paths.\n")); 1457 1732 continue; 1733 } 1458 1734 pszPath = pVars->szPath; 1459 1735 strcpy(pszPath, pszOdin32Path); … … 1463 1739 case FINDDLL_SYSTEM16DIR: 1464 1740 if (!fOdin32PathValid) 1741 { 1742 //kprintf(("openPath2: invalid odin32 paths.\n")); 1465 1743 continue; 1744 } 1466 1745 pszPath = pVars->szPath; 1467 1746 strcpy(pszPath, pszOdin32Path); … … 1471 1750 case FINDDLL_WINDIR: 1472 1751 if (!fOdin32PathValid) 1752 { 1753 //kprintf(("openPath2: invalid odin32 paths.\n")); 1473 1754 continue; 1755 } 1474 1756 pszPath = pVars->szPath; 1475 1757 strcpy(pszPath, pszOdin32Path); … … 1478 1760 1479 1761 case FINDDLL_PATH: 1480 pszPath = (char*)GetEnv(TRUE); 1762 { 1763 PPTD pptd = GetTaskData(0); 1764 pszPath = NULL; 1765 if (pptd) 1766 pszPath = pptd->pszzOdin32Env; 1767 if (!pszPath) 1768 pszPath = (char*)GetEnv(TRUE); 1481 1769 if (pszPath == NULL) 1770 { 1771 //kprintf(("openPath2: failed to GetEnv.\n")); 1482 1772 continue; 1773 } 1483 1774 pszPath = (char*)ScanEnv(pszPath, "PATH"); 1484 1775 break; 1485 1486 #if 0 1776 } 1777 1778 #if 1 1487 1779 case FINDDLL_BEGINLIBPATH: 1488 pszPath = ptda_GetBeginLibpath()... ; 1780 pszPath = NULL; 1781 if (ptdaGetCur()) 1782 pszPath = ptdaGet_ptda_pBeginLIBPATH(ptdaGetCur()); 1489 1783 if (pszPath == NULL) 1490 1784 continue; … … 1496 1790 1497 1791 case FINDDLL_ENDLIBPATH: 1498 pszPath = ptda_GetEndLibpath()... ; 1792 pszPath = NULL; 1793 if (ptdaGetCur()) 1794 pszPath = ptdaGet_ptda_pEndLIBPATH(ptdaGetCur()); 1499 1795 if (pszPath == NULL) 1500 1796 continue; 1501 1797 break; 1502 1798 #endif 1799 1503 1800 default: /* !internalerror! */ 1504 1801 printIPE(("Pe2Lx::openPath(%.*s,..): iPath is %d which is invalid.\n", cchFilename, pachFilename, iPath)); … … 1507 1804 } 1508 1805 1806 //kprintf(("openPath2: level:%d path=%s\n", iPath, pszPath)); 1509 1807 1510 1808 /** @sketch … … 1597 1895 */ 1598 1896 rfree(pVars); 1599 return ldrOpenPath(pachFilename, (USHORT)cchFilename, pLdrLv, pful, lLibPath);1897 return ERROR_FILE_NOT_FOUND;//ldrOpenPath(pachFilename, (USHORT)cchFilename, pLdrLv, pful, lLibPath); 1600 1898 1601 1899 #else … … 1632 1930 makeObjectTable(); 1633 1931 memcpy(smte.smte_objtab, paObjTab, sizeof(OTE) * cObjects); 1634 smte.smte_objtab[0].ote_base = 0x1 25D0000;1932 smte.smte_objtab[0].ote_base = 0x132d0000; 1635 1933 for (i = 1; i < cObjects; i++) 1636 1934 smte.smte_objtab[i].ote_base = ALIGN(smte.smte_objtab[i-1].ote_size + smte.smte_objtab[i-1].ote_base, 0x10000); … … 1660 1958 return rc; 1661 1959 } 1662 rc = applyFixups(&mte, 1, 1, &achPage[0], ulAddress, NULL);1960 rc = applyFixups(&mte, i, ulRVA >> PAGESHIFT, &achPage[0], ulAddress, NULL); 1663 1961 if (rc != NO_ERROR) 1664 1962 {
Note:
See TracChangeset
for help on using the changeset viewer.