From b495563e636c223be39d5ed516572f6a8406b2b3 Mon Sep 17 00:00:00 2001 From: Camille Mougey Date: Tue, 6 Jan 2015 18:03:10 +0100 Subject: Examples: Move used samples to a common place: /samples --- example/samples/box.exe | Bin 0 -> 21827 bytes example/samples/box_upx.exe | Bin 0 -> 14659 bytes example/samples/md5_arm | Bin 0 -> 15381 bytes example/samples/x86_32_mod.S | 35 +++++++++++++++++++++++++++++ example/samples/x86_32_mod_self.S | 20 +++++++++++++++++ example/samples/x86_32_repmod.S | 46 ++++++++++++++++++++++++++++++++++++++ example/samples/x86_32_sc.bin | 1 + example/samples/x86_32_simple.S | 12 ++++++++++ 8 files changed, 114 insertions(+) create mode 100755 example/samples/box.exe create mode 100755 example/samples/box_upx.exe create mode 100755 example/samples/md5_arm create mode 100644 example/samples/x86_32_mod.S create mode 100644 example/samples/x86_32_mod_self.S create mode 100644 example/samples/x86_32_repmod.S create mode 100644 example/samples/x86_32_sc.bin create mode 100644 example/samples/x86_32_simple.S (limited to 'example/samples') diff --git a/example/samples/box.exe b/example/samples/box.exe new file mode 100755 index 00000000..1c11bcda Binary files /dev/null and b/example/samples/box.exe differ diff --git a/example/samples/box_upx.exe b/example/samples/box_upx.exe new file mode 100755 index 00000000..d0776ec2 Binary files /dev/null and b/example/samples/box_upx.exe differ diff --git a/example/samples/md5_arm b/example/samples/md5_arm new file mode 100755 index 00000000..148e0611 Binary files /dev/null and b/example/samples/md5_arm differ diff --git a/example/samples/x86_32_mod.S b/example/samples/x86_32_mod.S new file mode 100644 index 00000000..df7792af --- /dev/null +++ b/example/samples/x86_32_mod.S @@ -0,0 +1,35 @@ +main: + CALL test_automod + CALL test_automod + RET + +test_automod: + PUSH EBP + MOV EBP, ESP + +loop: + MOV EAX, 0 + CMP EAX, 0 + JMP mod_addr +mod_addr: + JNZ end + + PUSH 0 + PUSH title + PUSH msg + PUSH 0 + CALL DWORD PTR [ MessageBoxA ] + + ; automodif code + MOV BYTE PTR [mod_addr], 0xEB + JMP loop +end: + MOV BYTE PTR [mod_addr], 0x75 + MOV ESP, EBP + POP EBP + RET + +title: +.string "Hello!" +msg: +.string "World!" diff --git a/example/samples/x86_32_mod_self.S b/example/samples/x86_32_mod_self.S new file mode 100644 index 00000000..398438ec --- /dev/null +++ b/example/samples/x86_32_mod_self.S @@ -0,0 +1,20 @@ +main: + PUSH EBP + MOV EBP, ESP + MOV BYTE PTR [myint], 0x90 +myint: + INT 0x3 + + PUSH 0 + PUSH title + PUSH msg + PUSH 0 + CALL DWORD PTR [ MessageBoxA ] + MOV ESP, EBP + POP EBP + RET + +title: +.string "Hello!" +msg: +.string "World!" diff --git a/example/samples/x86_32_repmod.S b/example/samples/x86_32_repmod.S new file mode 100644 index 00000000..332a876c --- /dev/null +++ b/example/samples/x86_32_repmod.S @@ -0,0 +1,46 @@ +main: + CALL test_automod + RET + +lbl_good: + NOP + NOP + NOP + NOP + NOP + NOP + NOP + NOP + NOP + +test_automod: + PUSH EBP + MOV EBP, ESP + + LEA EDI, DWORD PTR [lbl_mod] + LEA ESI, DWORD PTR [lbl_good] + + MOV ECX, 0x8 + REPE MOVSB +lbl_mod: + XOR EAX, EAX + MOV DWORD PTR [EAX], 0xDEADC0DE + + NOP + NOP + NOP + + PUSH 0 + PUSH title + PUSH msg + PUSH 0 + CALL DWORD PTR [ MessageBoxA ] + + MOV ESP, EBP + POP EBP + RET + +title: +.string "Hello!" +msg: +.string "World!" diff --git a/example/samples/x86_32_sc.bin b/example/samples/x86_32_sc.bin new file mode 100644 index 00000000..c1931ce0 --- /dev/null +++ b/example/samples/x86_32_sc.bin @@ -0,0 +1 @@ +I[t[[ \ No newline at end of file diff --git a/example/samples/x86_32_simple.S b/example/samples/x86_32_simple.S new file mode 100644 index 00000000..f38c232f --- /dev/null +++ b/example/samples/x86_32_simple.S @@ -0,0 +1,12 @@ +main: + PUSH 0 + PUSH title + PUSH msg + PUSH 0 + CALL DWORD PTR [ MessageBoxA ] + RET + +title: +.string "Hello!" +msg: +.string "World!" -- cgit 1.4.1 From 4a3880c62638ca5e3f1ea74bd2f29b186fb109a6 Mon Sep 17 00:00:00 2001 From: Camille Mougey Date: Wed, 7 Jan 2015 17:13:58 +0100 Subject: Example/Sample: Remove unused file box.exe --- example/samples/box.exe | Bin 21827 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100755 example/samples/box.exe (limited to 'example/samples') diff --git a/example/samples/box.exe b/example/samples/box.exe deleted file mode 100755 index 1c11bcda..00000000 Binary files a/example/samples/box.exe and /dev/null differ -- cgit 1.4.1 From 42d91afa7441f62c77febc7d3dbc3e43d4a31218 Mon Sep 17 00:00:00 2001 From: Camille Mougey Date: Fri, 9 Jan 2015 18:05:07 +0100 Subject: Example: Move expression samples to sample directory --- example/expression/sc_connect_back.bin | Bin 290 -> 0 bytes example/expression/simple_test.bin | Bin 141 -> 0 bytes example/expression/simple_test.c | 26 -------------------------- example/samples/sc_connect_back.bin | Bin 0 -> 290 bytes example/samples/simple_test.bin | Bin 0 -> 141 bytes example/samples/simple_test.c | 26 ++++++++++++++++++++++++++ test/test_all.py | 7 ++++--- 7 files changed, 30 insertions(+), 29 deletions(-) delete mode 100644 example/expression/sc_connect_back.bin delete mode 100644 example/expression/simple_test.bin delete mode 100644 example/expression/simple_test.c create mode 100644 example/samples/sc_connect_back.bin create mode 100644 example/samples/simple_test.bin create mode 100644 example/samples/simple_test.c (limited to 'example/samples') diff --git a/example/expression/sc_connect_back.bin b/example/expression/sc_connect_back.bin deleted file mode 100644 index 9e9c80a5..00000000 Binary files a/example/expression/sc_connect_back.bin and /dev/null differ diff --git a/example/expression/simple_test.bin b/example/expression/simple_test.bin deleted file mode 100644 index 60f4e768..00000000 Binary files a/example/expression/simple_test.bin and /dev/null differ diff --git a/example/expression/simple_test.c b/example/expression/simple_test.c deleted file mode 100644 index 8e344f18..00000000 --- a/example/expression/simple_test.c +++ /dev/null @@ -1,26 +0,0 @@ -int test(unsigned int argc, char** argv) -{ - unsigned int ret; - if (argc == 0) - ret = 0x1001; - else if (argc < 2) - ret = 0x1002; - else if (argc <= 5) - ret = 0x1003; - else if (argc != 7 && argc*2 == 14) - ret = 0x1004; - else if (argc*2 == 14) - ret = 0x1005; - else if (argc & 0x30) - ret = 0x1006; - else if (argc + 3 == 0x45) - ret = 0x1007; - else - ret = 0x1008; - return ret; -} - -int main(int argc, char** argv) -{ - return test(argc, argv); -} diff --git a/example/samples/sc_connect_back.bin b/example/samples/sc_connect_back.bin new file mode 100644 index 00000000..9e9c80a5 Binary files /dev/null and b/example/samples/sc_connect_back.bin differ diff --git a/example/samples/simple_test.bin b/example/samples/simple_test.bin new file mode 100644 index 00000000..60f4e768 Binary files /dev/null and b/example/samples/simple_test.bin differ diff --git a/example/samples/simple_test.c b/example/samples/simple_test.c new file mode 100644 index 00000000..8e344f18 --- /dev/null +++ b/example/samples/simple_test.c @@ -0,0 +1,26 @@ +int test(unsigned int argc, char** argv) +{ + unsigned int ret; + if (argc == 0) + ret = 0x1001; + else if (argc < 2) + ret = 0x1002; + else if (argc <= 5) + ret = 0x1003; + else if (argc != 7 && argc*2 == 14) + ret = 0x1004; + else if (argc*2 == 14) + ret = 0x1005; + else if (argc & 0x30) + ret = 0x1006; + else if (argc + 3 == 0x45) + ret = 0x1007; + else + ret = 0x1008; + return ret; +} + +int main(int argc, char** argv) +{ + return test(argc, argv); +} diff --git a/test/test_all.py b/test/test_all.py index f4df9967..61ad701a 100644 --- a/test/test_all.py +++ b/test/test_all.py @@ -119,7 +119,7 @@ for script in [["disasm_single_instr.py"], "0x410f90"], ]: testset += Example(script) -## Expression + class ExampleDisasmFull(Example): """TestDis specificities: - script: disasm_full.py @@ -151,15 +151,16 @@ testset += ExampleDisasmFull(["mips32l", "mips32_sc_l.bin", "0"], testset += ExampleDisasmFull(["mips32b", "mips32_sc_b.bin", "0"], depends=[test_mips32]) +## Expression testset += Example(["expression/graph_dataflow.py", - "expression/sc_connect_back.bin", "0x2e"], + Example.get_sample("sc_connect_back.bin"), "0x2e"], products=["data.txt"]) testset += Example(["expression/asm_to_ir.py"], products=["graph.txt", "graph2.txt"]) testset += Example(["expression/get_read_write.py"], products=["graph_instr.txt"]) testset += Example(["expression/solve_condition_stp.py", - "expression/simple_test.bin"], + Example.get_sample("simple_test.bin")], products=["graph_instr.txt"]) for script in [["expression/basic_op.py"], -- cgit 1.4.1 From 7ce340c2e62d985e92c42add8ffc385d54360a91 Mon Sep 17 00:00:00 2001 From: Camille Mougey Date: Wed, 21 Jan 2015 17:46:26 +0100 Subject: Example/ASM: Extract asm sources to sample dir --- example/samples/arm_sc.S | 17 +++++++++++++ example/samples/arm_simple.S | 24 ++++++++++++++++++ example/samples/armt.S | 27 ++++++++++++++++++++ example/samples/mips32.S | 12 +++++++++ example/samples/msp430.S | 8 ++++++ example/samples/x86_32_enc.S | 38 +++++++++++++++++++++++++++++ example/samples/x86_32_manip_ptr.S | 50 ++++++++++++++++++++++++++++++++++++++ example/samples/x86_64.S | 13 ++++++++++ 8 files changed, 189 insertions(+) create mode 100644 example/samples/arm_sc.S create mode 100644 example/samples/arm_simple.S create mode 100644 example/samples/armt.S create mode 100644 example/samples/mips32.S create mode 100644 example/samples/msp430.S create mode 100644 example/samples/x86_32_enc.S create mode 100644 example/samples/x86_32_manip_ptr.S create mode 100644 example/samples/x86_64.S (limited to 'example/samples') diff --git a/example/samples/arm_sc.S b/example/samples/arm_sc.S new file mode 100644 index 00000000..e9a0787f --- /dev/null +++ b/example/samples/arm_sc.S @@ -0,0 +1,17 @@ +main: + MOV R1, R0 + MOV R2, 0x100 + LDR R3, [PC, mykey1-$] +loop: + ADD R2, R1, R2 + ADD R1, R1, 1 + LDR R3, [PC, mykey2-$] + CMP R1, R3 + BEQ loop + + ADD R0, R1, R2 + BX LR +mykey1: +.long 0x1 +mykey2: +.long 0x2 diff --git a/example/samples/arm_simple.S b/example/samples/arm_simple.S new file mode 100644 index 00000000..f6dcf81e --- /dev/null +++ b/example/samples/arm_simple.S @@ -0,0 +1,24 @@ +main: + STMFD SP!, {R4, R5, LR} + MOV R0, mystr & 0xffff + ORR R0, R0, mystr & 0xffff0000 + MOV R4, R0 + MOV R1, mystrend & 0xffff + ORR R1, R1, mystrend & 0xffff0000 +xxx: + LDRB R2, [PC, key-$] +loop: + LDRB R3, [R0] + EOR R3, R3, R2 + STRB R3, [R0], 1 + CMP R0, R1 + BNE loop +end: + MOV R0, R4 + LDMFD SP!, {R4, R5, PC} +key: +.byte 0x11 +mystr: +.string "test string" +mystrend: +.long 0 diff --git a/example/samples/armt.S b/example/samples/armt.S new file mode 100644 index 00000000..c50075a6 --- /dev/null +++ b/example/samples/armt.S @@ -0,0 +1,27 @@ +memcpy: + PUSH {R0-R3, LR} + B test_end +loop: + LDRB R3, [R1] + STRB R3, [R0] + ADDS R0, R0, 1 + ADDS R1, R1, 1 + SUBS R2, R2, 1 +test_end: + CMP R2, 0 + BNE loop + POP {R0-R3, PC} +main: + PUSH {LR} + SUB SP, 0x100 + MOV R0, SP + ADD R1, PC, mystr-$+6 + MOV R0, R0 + EORS R2, R2 + ADDS R2, R2, 0x4 + BL memcpy + ADD SP, 0x100 + POP {PC} + +mystr: +.string "toto" diff --git a/example/samples/mips32.S b/example/samples/mips32.S new file mode 100644 index 00000000..ae44d52f --- /dev/null +++ b/example/samples/mips32.S @@ -0,0 +1,12 @@ +main: + ADDIU A0, ZERO, 0x10 + ADDIU A1, ZERO, 0 +loop: + ADDIU A1, A1, 0x1 + BNE A0, ZERO, loop + ADDIU A0, A0, 0xFFFFFFFF + + ADDIU A2, A2, 0x1 + MOVN A1, ZERO, ZERO + JR RA + ADDIU A2, A2, 0x1 diff --git a/example/samples/msp430.S b/example/samples/msp430.S new file mode 100644 index 00000000..77f4b448 --- /dev/null +++ b/example/samples/msp430.S @@ -0,0 +1,8 @@ +main: + mov.w 0x10, R10 + mov.w 0x0, R11 +loop: + add.w 1, R11 + sub.w 1, R10 + jnz loop + mov.w @SP+, PC diff --git a/example/samples/x86_32_enc.S b/example/samples/x86_32_enc.S new file mode 100644 index 00000000..92379838 --- /dev/null +++ b/example/samples/x86_32_enc.S @@ -0,0 +1,38 @@ +main: + CALL cipher_code + CALL msgbox_encrypted_start + CALL cipher_code + RET + +cipher_code: + PUSH EBP + MOV EBP, ESP + + LEA ESI, DWORD PTR [msgbox_encrypted_start] + LEA EDI, DWORD PTR [msgbox_encrypted_stop] + +loop: + XOR BYTE PTR [ESI], 0x42 + INC ESI + CMP ESI, EDI + JBE loop + + MOV ESP, EBP + POP EBP + RET + +msgbox_encrypted_start: + PUSH 0 + PUSH title + PUSH msg + PUSH 0 + CALL DWORD PTR [ MessageBoxA ] + RET +.dontsplit +msgbox_encrypted_stop: +.long 0 + +title: +.string "Hello!" +msg: +.string "World!" diff --git a/example/samples/x86_32_manip_ptr.S b/example/samples/x86_32_manip_ptr.S new file mode 100644 index 00000000..43e4ed73 --- /dev/null +++ b/example/samples/x86_32_manip_ptr.S @@ -0,0 +1,50 @@ +main: + PUSH EBP + MOV EBP, ESP + SUB ESP, 0x100 + MOV EAX, 0x1337 + ; test ptr manip + LEA ESI, DWORD PTR [mystr^toto] + CALL toto +mystr: +.string "test string" + toto: + POP EDI + + PUSH EDI + ; test scasb + XOR EAX, EAX + XOR ECX, ECX + DEC ECX + REPNE SCASB + NOT ECX + DEC ECX + + ; test movsb + POP ESI + LEA EDI, DWORD PTR [EBP-0x100] + REPE MOVSB + + ; test float + PUSH 0 + FLD1 + FLD1 + FADD ST, ST(1) + FIST DWORD PTR [ESP] + POP EAX + + ; test cond mnemo + NOP + NOP + CMOVZ EAX, EBX + ; test shr + NOP + SHR EAX, 1 + NOP + NOP + SHR EAX, CL + NOP + + MOV ESP, EBP + POP EBP + RET diff --git a/example/samples/x86_64.S b/example/samples/x86_64.S new file mode 100644 index 00000000..d090a01b --- /dev/null +++ b/example/samples/x86_64.S @@ -0,0 +1,13 @@ +main: + MOV R9, 0x0 + MOV R8, title + MOV RDX, msg + MOV RCX, 0x0 + MOV RAX, QWORD PTR [ MessageBoxA ] + CALL RAX + RET + +title: +.string "Hello!" +msg: +.string "World!" -- cgit 1.4.1