@@ -85,7 +85,16 @@ const u8 kIdentityCodeWithJump[] = {
85
85
0xC3 , // ret
86
86
};
87
87
88
- #else
88
+ const u8 kIdentityCodeWithJumpBackwards [] = {
89
+ 0x89 , 0xC8 , // mov eax, ecx
90
+ 0xC3 , // ret
91
+ 0xE9 , 0xF8 , 0xFF , 0xFF ,
92
+ 0xFF , // jmp - 8
93
+ 0xCC , 0xCC , 0xCC , 0xCC ,
94
+ };
95
+ const u8 kIdentityCodeWithJumpBackwardsOffset = 3 ;
96
+
97
+ # else
89
98
90
99
const u8 kIdentityCodeWithPrologue [] = {
91
100
0x55 , // push ebp
@@ -134,7 +143,16 @@ const u8 kIdentityCodeWithJump[] = {
134
143
0xC3 , // ret
135
144
};
136
145
137
- #endif
146
+ const u8 kIdentityCodeWithJumpBackwards [] = {
147
+ 0x8B , 0x44 , 0x24 , 0x04 , // mov eax,dword ptr [esp + 4]
148
+ 0xC3 , // ret
149
+ 0xE9 , 0xF6 , 0xFF , 0xFF ,
150
+ 0xFF , // jmp - 10
151
+ 0xCC , 0xCC , 0xCC , 0xCC ,
152
+ };
153
+ const u8 kIdentityCodeWithJumpBackwardsOffset = 5 ;
154
+
155
+ # endif
138
156
139
157
const u8 kPatchableCode1 [] = {
140
158
0xB8 , 0x4B , 0x00 , 0x00 , 0x00 , // mov eax,4B
@@ -366,13 +384,14 @@ TEST(Interception, InternalGetProcAddress) {
366
384
EXPECT_NE (DbgPrint_adddress, isdigit_address);
367
385
}
368
386
369
- template <class T >
387
+ template <class T >
370
388
static void TestIdentityFunctionPatching (
371
- const T &code,
372
- TestOverrideFunction override ,
373
- FunctionPrefixKind prefix_kind = FunctionPrefixNone ) {
389
+ const T &code, TestOverrideFunction override ,
390
+ FunctionPrefixKind prefix_kind = FunctionPrefixNone ,
391
+ int function_start_offset = 0 ) {
374
392
uptr identity_address;
375
393
LoadActiveCode (code, &identity_address, prefix_kind);
394
+ identity_address += function_start_offset;
376
395
IdentityFunction identity = (IdentityFunction)identity_address;
377
396
378
397
// Validate behavior before dynamic patching.
@@ -410,7 +429,7 @@ static void TestIdentityFunctionPatching(
410
429
TestOnlyReleaseTrampolineRegions ();
411
430
}
412
431
413
- #if !SANITIZER_WINDOWS64
432
+ # if !SANITIZER_WINDOWS64
414
433
TEST (Interception, OverrideFunctionWithDetour) {
415
434
TestOverrideFunction override = OverrideFunctionWithDetour;
416
435
FunctionPrefixKind prefix = FunctionPrefixDetour;
@@ -424,6 +443,9 @@ TEST(Interception, OverrideFunctionWithDetour) {
424
443
TEST (Interception, OverrideFunctionWithRedirectJump) {
425
444
TestOverrideFunction override = OverrideFunctionWithRedirectJump;
426
445
TestIdentityFunctionPatching (kIdentityCodeWithJump , override );
446
+ TestIdentityFunctionPatching (kIdentityCodeWithJumpBackwards , override ,
447
+ FunctionPrefixNone,
448
+ kIdentityCodeWithJumpBackwardsOffset );
427
449
}
428
450
429
451
TEST (Interception, OverrideFunctionWithHotPatch) {
0 commit comments