aboutsummaryrefslogtreecommitdiff
path: root/frida_mode/src/ctx
diff options
context:
space:
mode:
authorWorksButNotTested <62701594+WorksButNotTested@users.noreply.github.com>2021-05-17 19:02:45 +0100
committerGitHub <noreply@github.com>2021-05-17 20:02:45 +0200
commite40c0c2da16f14dfddb5641f6f825903879534a9 (patch)
tree363135f288fd63253471a0455ebadd24a512a1ce /frida_mode/src/ctx
parent9d50ae7468970412177c9e08edf7f32ff9fdf1ce (diff)
downloadafl++-e40c0c2da16f14dfddb5641f6f825903879534a9.tar.gz
FASAN Support (#918)
* FASAN Support * Fix handling of Address Sanitizer DSO * Changes to identification of Address Sanitizer DSO Co-authored-by: Your Name <you@example.com>
Diffstat (limited to 'frida_mode/src/ctx')
-rw-r--r--frida_mode/src/ctx/ctx_x64.c114
1 files changed, 114 insertions, 0 deletions
diff --git a/frida_mode/src/ctx/ctx_x64.c b/frida_mode/src/ctx/ctx_x64.c
new file mode 100644
index 00000000..dec759f4
--- /dev/null
+++ b/frida_mode/src/ctx/ctx_x64.c
@@ -0,0 +1,114 @@
+#include "frida-gum.h"
+
+#include "debug.h"
+
+#include "ctx.h"
+
+#if defined(__x86_64__)
+
+ #define X86_REG_8L(LABEL, REG) \
+ case LABEL: { \
+ \
+ return REG & GUM_INT8_MASK; \
+ \
+ }
+
+ #define X86_REG_8H(LABEL, REG) \
+ case LABEL: { \
+ \
+ return (REG & GUM_INT16_MASK) >> 8; \
+ \
+ }
+
+ #define X86_REG_16(LABEL, REG) \
+ case LABEL: { \
+ \
+ return (REG & GUM_INT16_MASK); \
+ \
+ }
+
+ #define X86_REG_32(LABEL, REG) \
+ case LABEL: { \
+ \
+ return (REG & GUM_INT32_MASK); \
+ \
+ }
+
+ #define X86_REG_64(LABEL, REG) \
+ case LABEL: { \
+ \
+ return (REG); \
+ \
+ }
+
+guint64 ctx_read_reg(GumX64CpuContext *ctx, x86_reg reg) {
+
+ switch (reg) {
+
+ X86_REG_8L(X86_REG_AL, ctx->rax)
+ X86_REG_8L(X86_REG_BL, ctx->rbx)
+ X86_REG_8L(X86_REG_CL, ctx->rcx)
+ X86_REG_8L(X86_REG_DL, ctx->rdx)
+ X86_REG_8L(X86_REG_BPL, ctx->rbp)
+ X86_REG_8L(X86_REG_SIL, ctx->rsi)
+ X86_REG_8L(X86_REG_DIL, ctx->rdi)
+
+ X86_REG_8H(X86_REG_AH, ctx->rax)
+ X86_REG_8H(X86_REG_BH, ctx->rbx)
+ X86_REG_8H(X86_REG_CH, ctx->rcx)
+ X86_REG_8H(X86_REG_DH, ctx->rdx)
+
+ X86_REG_16(X86_REG_AX, ctx->rax)
+ X86_REG_16(X86_REG_BX, ctx->rbx)
+ X86_REG_16(X86_REG_CX, ctx->rcx)
+ X86_REG_16(X86_REG_DX, ctx->rdx)
+ X86_REG_16(X86_REG_DI, ctx->rdi)
+ X86_REG_16(X86_REG_SI, ctx->rsi)
+ X86_REG_16(X86_REG_BP, ctx->rbp)
+
+ X86_REG_32(X86_REG_EAX, ctx->rax)
+ X86_REG_32(X86_REG_ECX, ctx->rcx)
+ X86_REG_32(X86_REG_EDX, ctx->rdx)
+ X86_REG_32(X86_REG_EBX, ctx->rbx)
+ X86_REG_32(X86_REG_ESP, ctx->rsp)
+ X86_REG_32(X86_REG_EBP, ctx->rbp)
+ X86_REG_32(X86_REG_ESI, ctx->rsi)
+ X86_REG_32(X86_REG_EDI, ctx->rdi)
+ X86_REG_32(X86_REG_R8D, ctx->r8)
+ X86_REG_32(X86_REG_R9D, ctx->r9)
+ X86_REG_32(X86_REG_R10D, ctx->r10)
+ X86_REG_32(X86_REG_R11D, ctx->r11)
+ X86_REG_32(X86_REG_R12D, ctx->r12)
+ X86_REG_32(X86_REG_R13D, ctx->r13)
+ X86_REG_32(X86_REG_R14D, ctx->r14)
+ X86_REG_32(X86_REG_R15D, ctx->r15)
+ X86_REG_32(X86_REG_EIP, ctx->rip)
+
+ X86_REG_64(X86_REG_RAX, ctx->rax)
+ X86_REG_64(X86_REG_RCX, ctx->rcx)
+ X86_REG_64(X86_REG_RDX, ctx->rdx)
+ X86_REG_64(X86_REG_RBX, ctx->rbx)
+ X86_REG_64(X86_REG_RSP, ctx->rsp)
+ X86_REG_64(X86_REG_RBP, ctx->rbp)
+ X86_REG_64(X86_REG_RSI, ctx->rsi)
+ X86_REG_64(X86_REG_RDI, ctx->rdi)
+ X86_REG_64(X86_REG_R8, ctx->r8)
+ X86_REG_64(X86_REG_R9, ctx->r9)
+ X86_REG_64(X86_REG_R10, ctx->r10)
+ X86_REG_64(X86_REG_R11, ctx->r11)
+ X86_REG_64(X86_REG_R12, ctx->r12)
+ X86_REG_64(X86_REG_R13, ctx->r13)
+ X86_REG_64(X86_REG_R14, ctx->r14)
+ X86_REG_64(X86_REG_R15, ctx->r15)
+ X86_REG_64(X86_REG_RIP, ctx->rip)
+
+ default:
+ FATAL("Failed to read register: %d", reg);
+ return 0;
+
+ }
+
+}
+
+#endif
+