00200 {
00201 PUCHAR FixupVA;
00202
USHORT Offset;
00203 LONG Temp;
00204 LONG TempOrig;
00205 ULONG Temp32;
00206 ULONGLONG Value64;
00207 LONGLONG Temp64;
00208 LONG_PTR ActualDiff;
00209
00210
RTL_PAGED_CODE();
00211
00212
while (SizeOfBlock--) {
00213
00214
Offset = *NextOffset & (
USHORT)0xfff;
00215 FixupVA = (PUCHAR)(VA +
Offset);
00216
00217
00218
00219
00220
00221
switch ((*NextOffset) >> 12) {
00222
00223
case IMAGE_REL_BASED_HIGHLOW :
00224
00225
00226
00227
00228 *(LONG UNALIGNED *)FixupVA += (ULONG) Diff;
00229
break;
00230
00231
case IMAGE_REL_BASED_HIGH :
00232
00233
00234
00235 Temp = *(
PUSHORT)FixupVA << 16;
00236 Temp += (ULONG) Diff;
00237 *(
PUSHORT)FixupVA = (
USHORT)(Temp >> 16);
00238
break;
00239
00240
case IMAGE_REL_BASED_HIGHADJ :
00241
00242
00243
00244
00245
00246
#if defined(NTOS_KERNEL_RUNTIME)
00247
00248
00249
00250
00251
if (
Offset &
LDRP_RELOCATION_FINAL) {
00252 ++NextOffset;
00253 --SizeOfBlock;
00254
break;
00255 }
00256
#endif
00257
00258 Temp = *(
PUSHORT)FixupVA << 16;
00259
#if defined(BLDR_KERNEL_RUNTIME)
00260
TempOrig = Temp;
00261
#endif
00262
++NextOffset;
00263 --SizeOfBlock;
00264 Temp += (LONG)(*(
PSHORT)NextOffset);
00265 Temp += (ULONG) Diff;
00266 Temp += 0x8000;
00267 *(
PUSHORT)FixupVA = (
USHORT)(Temp >> 16);
00268
00269
#if defined(BLDR_KERNEL_RUNTIME)
00270
ActualDiff = ((((ULONG_PTR)(Temp - TempOrig)) >> 16) -
00271 (((ULONG_PTR)Diff) >> 16 ));
00272
00273
if (ActualDiff == 1) {
00274
00275
00276
00277
00278 *(NextOffset - 1) |=
LDRP_RELOCATION_INCREMENT;
00279 }
00280
else if (ActualDiff != 0) {
00281
00282
00283
00284 *(NextOffset - 1) |=
LDRP_RELOCATION_FINAL;
00285 }
00286
#endif
00287
00288
break;
00289
00290
case IMAGE_REL_BASED_LOW :
00291
00292
00293
00294 Temp = *(
PSHORT)FixupVA;
00295 Temp += (ULONG) Diff;
00296 *(
PUSHORT)FixupVA = (
USHORT)Temp;
00297
break;
00298
00299
case IMAGE_REL_BASED_IA64_IMM64:
00300
00301
00302
00303
00304
00305
00306 FixupVA = (PUCHAR)((ULONG_PTR)FixupVA & ~(15));
00307 Value64 = (ULONGLONG)0;
00308
00309
00310
00311
00312
00313
00314 EXT_IMM64(Value64,
00315 (PULONG)FixupVA + EMARCH_ENC_I17_IMM7B_INST_WORD_X,
00316 EMARCH_ENC_I17_IMM7B_SIZE_X,
00317 EMARCH_ENC_I17_IMM7B_INST_WORD_POS_X,
00318 EMARCH_ENC_I17_IMM7B_VAL_POS_X);
00319 EXT_IMM64(Value64,
00320 (PULONG)FixupVA + EMARCH_ENC_I17_IMM9D_INST_WORD_X,
00321 EMARCH_ENC_I17_IMM9D_SIZE_X,
00322 EMARCH_ENC_I17_IMM9D_INST_WORD_POS_X,
00323 EMARCH_ENC_I17_IMM9D_VAL_POS_X);
00324 EXT_IMM64(Value64,
00325 (PULONG)FixupVA + EMARCH_ENC_I17_IMM5C_INST_WORD_X,
00326 EMARCH_ENC_I17_IMM5C_SIZE_X,
00327 EMARCH_ENC_I17_IMM5C_INST_WORD_POS_X,
00328 EMARCH_ENC_I17_IMM5C_VAL_POS_X);
00329 EXT_IMM64(Value64,
00330 (PULONG)FixupVA + EMARCH_ENC_I17_IC_INST_WORD_X,
00331 EMARCH_ENC_I17_IC_SIZE_X,
00332 EMARCH_ENC_I17_IC_INST_WORD_POS_X,
00333 EMARCH_ENC_I17_IC_VAL_POS_X);
00334 EXT_IMM64(Value64,
00335 (PULONG)FixupVA + EMARCH_ENC_I17_IMM41a_INST_WORD_X,
00336 EMARCH_ENC_I17_IMM41a_SIZE_X,
00337 EMARCH_ENC_I17_IMM41a_INST_WORD_POS_X,
00338 EMARCH_ENC_I17_IMM41a_VAL_POS_X);
00339
00340
00341
00342
00343
00344 Value64+=Diff;
00345
00346
00347
00348
00349
00350 INS_IMM64(Value64,
00351 ((PULONG)FixupVA + EMARCH_ENC_I17_IMM7B_INST_WORD_X),
00352 EMARCH_ENC_I17_IMM7B_SIZE_X,
00353 EMARCH_ENC_I17_IMM7B_INST_WORD_POS_X,
00354 EMARCH_ENC_I17_IMM7B_VAL_POS_X);
00355 INS_IMM64(Value64,
00356 ((PULONG)FixupVA + EMARCH_ENC_I17_IMM9D_INST_WORD_X),
00357 EMARCH_ENC_I17_IMM9D_SIZE_X,
00358 EMARCH_ENC_I17_IMM9D_INST_WORD_POS_X,
00359 EMARCH_ENC_I17_IMM9D_VAL_POS_X);
00360 INS_IMM64(Value64,
00361 ((PULONG)FixupVA + EMARCH_ENC_I17_IMM5C_INST_WORD_X),
00362 EMARCH_ENC_I17_IMM5C_SIZE_X,
00363 EMARCH_ENC_I17_IMM5C_INST_WORD_POS_X,
00364 EMARCH_ENC_I17_IMM5C_VAL_POS_X);
00365 INS_IMM64(Value64,
00366 ((PULONG)FixupVA + EMARCH_ENC_I17_IC_INST_WORD_X),
00367 EMARCH_ENC_I17_IC_SIZE_X,
00368 EMARCH_ENC_I17_IC_INST_WORD_POS_X,
00369 EMARCH_ENC_I17_IC_VAL_POS_X);
00370 INS_IMM64(Value64,
00371 ((PULONG)FixupVA + EMARCH_ENC_I17_IMM41a_INST_WORD_X),
00372 EMARCH_ENC_I17_IMM41a_SIZE_X,
00373 EMARCH_ENC_I17_IMM41a_INST_WORD_POS_X,
00374 EMARCH_ENC_I17_IMM41a_VAL_POS_X);
00375 INS_IMM64(Value64,
00376 ((PULONG)FixupVA + EMARCH_ENC_I17_IMM41b_INST_WORD_X),
00377 EMARCH_ENC_I17_IMM41b_SIZE_X,
00378 EMARCH_ENC_I17_IMM41b_INST_WORD_POS_X,
00379 EMARCH_ENC_I17_IMM41b_VAL_POS_X);
00380 INS_IMM64(Value64,
00381 ((PULONG)FixupVA + EMARCH_ENC_I17_IMM41c_INST_WORD_X),
00382 EMARCH_ENC_I17_IMM41c_SIZE_X,
00383 EMARCH_ENC_I17_IMM41c_INST_WORD_POS_X,
00384 EMARCH_ENC_I17_IMM41c_VAL_POS_X);
00385 INS_IMM64(Value64,
00386 ((PULONG)FixupVA + EMARCH_ENC_I17_SIGN_INST_WORD_X),
00387 EMARCH_ENC_I17_SIGN_SIZE_X,
00388 EMARCH_ENC_I17_SIGN_INST_WORD_POS_X,
00389 EMARCH_ENC_I17_SIGN_VAL_POS_X);
00390
break;
00391
00392
case IMAGE_REL_BASED_DIR64:
00393
00394 *(ULONG_PTR UNALIGNED *)FixupVA += Diff;
00395
00396
break;
00397
00398
case IMAGE_REL_BASED_MIPS_JMPADDR :
00399
00400
00401
00402 Temp = (*(PULONG)FixupVA & 0x3ffffff) << 2;
00403 Temp += (ULONG) Diff;
00404 *(PULONG)FixupVA = (*(PULONG)FixupVA & ~0x3ffffff) |
00405 ((Temp >> 2) & 0x3ffffff);
00406
00407
break;
00408
00409
case IMAGE_REL_BASED_ABSOLUTE :
00410
00411
00412
00413
break;
00414
00415
case IMAGE_REL_BASED_SECTION :
00416
00417
00418
00419
break;
00420
00421
case IMAGE_REL_BASED_REL32 :
00422
00423
00424
00425
break;
00426
00427
case IMAGE_REL_BASED_HIGH3ADJ :
00428
00429
00430
00431
00432
00433
00434 Temp64 = *(
PUSHORT)FixupVA << 16;
00435 ++NextOffset;
00436 --SizeOfBlock;
00437 Temp64 += (LONG)((
SHORT)NextOffset[1]);
00438 Temp64 <<= 16;
00439 Temp64 += (LONG)((
USHORT)NextOffset[0]);
00440 Temp64 += Diff;
00441 Temp64 += 0x8000;
00442 Temp64 >>=16;
00443 Temp64 += 0x8000;
00444 *(
PUSHORT)FixupVA = (
USHORT)(Temp64 >> 16);
00445 ++NextOffset;
00446 --SizeOfBlock;
00447
break;
00448
00449
default :
00450
00451
00452
00453
00454
return (PIMAGE_BASE_RELOCATION)
NULL;
00455 }
00456 ++NextOffset;
00457 }
00458
return (PIMAGE_BASE_RELOCATION)NextOffset;
00459 }