summaryrefslogtreecommitdiff
path: root/lib/interception
diff options
context:
space:
mode:
authorTimur Iskhodzhanov <timurrrr@google.com>2014-01-29 02:00:58 +0000
committerTimur Iskhodzhanov <timurrrr@google.com>2014-01-29 02:00:58 +0000
commitba1bd562fb62508bb428c74fc892a47e2577d45d (patch)
tree8a10df9096c26f3d3b3a03ef4fcf8772f5b6ea69 /lib/interception
parent5d8f9f481e9446742f785cb0a61f73965a7b308b (diff)
Add support for more instruction prefixes so we can intercept functions in the VS2013 RTL
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@200366 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/interception')
-rw-r--r--lib/interception/interception_win.cc22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/interception/interception_win.cc b/lib/interception/interception_win.cc
index abbab2497..2331da55c 100644
--- a/lib/interception/interception_win.cc
+++ b/lib/interception/interception_win.cc
@@ -89,11 +89,22 @@ bool OverrideFunction(uptr old_func, uptr new_func, uptr *orig_old_func) {
size_t head = 0;
while (head < 5) {
switch (old_bytes[head]) {
+ case '\x51': // push ecx
+ case '\x52': // push edx
+ case '\x53': // push ebx
+ case '\x54': // push esp
case '\x55': // push ebp
case '\x56': // push esi
case '\x57': // push edi
+ case '\x5D': // pop ebp
head++;
continue;
+ case '\x6A': // 6A XX = push XX
+ head += 2;
+ continue;
+ case '\xE9': // E9 XX YY ZZ WW = jmp WWZZYYXX
+ head += 5;
+ continue;
}
switch (*(unsigned short*)(old_bytes + head)) { // NOLINT
case 0xFF8B: // 8B FF = mov edi, edi
@@ -101,23 +112,34 @@ bool OverrideFunction(uptr old_func, uptr new_func, uptr *orig_old_func) {
case 0xC033: // 33 C0 = xor eax, eax
head += 2;
continue;
+ case 0x458B: // 8B 45 XX = mov eax, dword ptr [ebp+XXh]
+ case 0x5D8B: // 8B 5D XX = mov ebx, dword ptr [ebp+XXh]
case 0xEC83: // 83 EC XX = sub esp, XX
head += 3;
continue;
case 0xC1F7: // F7 C1 XX YY ZZ WW = test ecx, WWZZYYXX
head += 6;
continue;
+ case 0x3D83: // 83 3D XX YY ZZ WW TT = cmp TT, WWZZYYXX
+ head += 7;
+ continue;
}
switch (0x00FFFFFF & *(unsigned int*)(old_bytes + head)) {
case 0x24448A: // 8A 44 24 XX = mov eal, dword ptr [esp+XXh]
case 0x244C8B: // 8B 4C 24 XX = mov ecx, dword ptr [esp+XXh]
case 0x24548B: // 8B 54 24 XX = mov edx, dword ptr [esp+XXh]
+ case 0x24748B: // 8B 74 24 XX = mov esi, dword ptr [esp+XXh]
case 0x247C8B: // 8B 7C 24 XX = mov edi, dword ptr [esp+XXh]
head += 4;
continue;
}
// Unknown instruction!
+ // FIXME: Unknown instruction failures might happen when we add a new
+ // interceptor or a new compiler version. In either case, they should result
+ // in visible and readable error messages. However, merely calling abort()
+ // or __debugbreak() leads to an infinite recursion in CheckFailed.
+ // Do we have a good way to abort with an error message here?
return false;
}