about summary refs log tree commit diff stats
path: root/src/tools
diff options
context:
space:
mode:
authorYang Liu <liuyang22@iscas.ac.cn>2025-04-01 18:36:12 +0800
committerGitHub <noreply@github.com>2025-04-01 12:36:12 +0200
commit670876112e3ab4a36205223a6f0c4290a527c4a9 (patch)
tree7d13933149ff9b438ae1002621ec7db31676c4ee /src/tools
parent495d3cc4c0ec521e932677ac3d2fcad2c3d80eca (diff)
downloadbox64-670876112e3ab4a36205223a6f0c4290a527c4a9.tar.gz
box64-670876112e3ab4a36205223a6f0c4290a527c4a9.zip
Some cosmetic changes to C header files (#2487)
* [DYNAREC] Move cosim functions to a new header

* Moved isNativeCall to elfloader
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/bridge.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/tools/bridge.c b/src/tools/bridge.c
index 7c697b22..3bc46713 100644
--- a/src/tools/bridge.c
+++ b/src/tools/bridge.c
@@ -300,3 +300,31 @@ void fini_bridge_helper()
 {
     cleanAlternate();
 }
+
+int isNativeCall(uintptr_t addr, int is32bits, uintptr_t* calladdress, uint16_t* retn)
+{
+    if (is32bits)
+        addr &= 0xFFFFFFFFLL;
+
+#define PK(a)   *(uint8_t*)(addr + a)
+#define PK32(a) *(int32_t*)(addr + a)
+
+    if (!addr || !getProtection(addr))
+        return 0;
+    if (PK(0) == 0xff && PK(1) == 0x25) {    // "absolute" jump, maybe the GOT (well, RIP relative in fact)
+        uintptr_t a1 = addr + 6 + (PK32(2)); // need to add a check to see if the address is from the GOT !
+        addr = (uintptr_t)getAlternate(*(void**)a1);
+    }
+    if (!addr || !getProtection(addr))
+        return 0;
+    onebridge_t* b = (onebridge_t*)(addr);
+    if (b->CC == 0xCC && b->S == 'S' && b->C == 'C' && b->w != (wrapper_t)0 && b->f != (uintptr_t)PltResolver64) {
+        // found !
+        if (retn) *retn = (b->C3 == 0xC2) ? b->N : 0;
+        if (calladdress) *calladdress = addr + 1;
+        return 1;
+    }
+    return 0;
+#undef PK32
+#undef PK
+}