summaryrefslogtreecommitdiff
path: root/crenshaw
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2018-08-18 13:12:16 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2018-08-18 13:12:16 +0200
commita3b01d933dc061fd9c24dd2caf121fe92c497d76 (patch)
tree5c67232700e68309aca033a266dfcc4020c243e0 /crenshaw
parent8fe76f1f67c5122d1789b6e3c4c3eba302f749f2 (diff)
downloadcompilertests-a3b01d933dc061fd9c24dd2caf121fe92c497d76.tar.gz
compilertests-a3b01d933dc061fd9c24dd2caf121fe92c497d76.tar.bz2
crenshaw/emul: added printing of stack
Diffstat (limited to 'crenshaw')
-rw-r--r--crenshaw/emul.c50
1 files changed, 38 insertions, 12 deletions
diff --git a/crenshaw/emul.c b/crenshaw/emul.c
index 104cac6..f1dcad9 100644
--- a/crenshaw/emul.c
+++ b/crenshaw/emul.c
@@ -2,6 +2,7 @@
#include <capstone/capstone.h>
#include <sys/types.h>
+#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -21,32 +22,56 @@
static void dump_regs( uc_engine *uc )
{
- int eip;
- int esp;
- int eax;
- int ebx;
- int ecx;
+ uint32_t eip;
+ uint32_t esp;
+ uint32_t ebp;
+ uint32_t eax;
+ uint32_t ebx;
+ uint32_t ecx;
+ uint32_t edx;
+ uint32_t esi;
+ uint32_t edi;
uc_reg_read( uc, UC_X86_REG_EIP, &eip );
uc_reg_read( uc, UC_X86_REG_ESP, &esp );
+ uc_reg_read( uc, UC_X86_REG_EBP, &ebp );
uc_reg_read( uc, UC_X86_REG_EAX, &eax );
uc_reg_read( uc, UC_X86_REG_EBX, &ebx );
uc_reg_read( uc, UC_X86_REG_ECX, &ecx );
+ uc_reg_read( uc, UC_X86_REG_EDX, &edx );
+ uc_reg_read( uc, UC_X86_REG_ESI, &esi );
+ uc_reg_read( uc, UC_X86_REG_EDI, &edi );
- printf( "EIP: %08x\n", eip );
- printf( "ESP: %08x\n", esp );
- printf( "EAX: %08x\n", eax );
- printf( "EBX: %08x\n", ebx );
- printf( "ECX: %08x\n", ecx );
+ printf( "EIP: %08X\n", eip );
+ printf( "ESP: %08X\n", esp );
+ printf( "EBP: %08X\n", ebp );
+ printf( "EAX: %08X\n", eax );
+ printf( "EBX: %08X\n", ebx );
+ printf( "ECX: %08X\n", ecx );
+ printf( "EDX: %08X\n", edx );
+ printf( "ESI: %08X\n", esi );
+ printf( "EDI: %08X\n", edi );
}
-uint32_t mul_hash( uint64_t x, int p )
+static void dump_stack( uc_engine *uc )
+{
+ uint32_t esp;
+ uint8_t mem[4];
+ uc_reg_read( uc, UC_X86_REG_ESP, &esp );
+
+ for( int i = esp; i < STACK_START; i += 4 ) {
+ uc_mem_read( uc, i, &mem, 4 );
+ printf( "%08X: %02X%02X%02X%02X\n", i, mem[3], mem[2], mem[1], mem[0] );
+ }
+}
+
+static uint32_t mul_hash( uint64_t x, int p )
{
uint32_t v = x * INT32_C( 2654435761 );
return v >> ( 32 - p );
}
-int compute_p( int size )
+static int compute_p( int size )
{
int p = 0;
while( size > 0 ) {
@@ -252,6 +277,7 @@ int main( int argc, char *argv[] )
address = eip;
dump_regs( uc );
+ dump_stack( uc );
if( strcmp( instrs[n].mnemonic, "hlt" ) == 0 ) {
terminate = true;