about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--example/samples/aarch64_simple.S17
-rw-r--r--test/arch/aarch64/unit/asm_test.py64
-rw-r--r--test/arch/aarch64/unit/mn_ubfm.py30
-rw-r--r--test/test_all.py11
4 files changed, 122 insertions, 0 deletions
diff --git a/example/samples/aarch64_simple.S b/example/samples/aarch64_simple.S
new file mode 100644
index 00000000..f786f168
--- /dev/null
+++ b/example/samples/aarch64_simple.S
@@ -0,0 +1,17 @@
+main:
+  SUB             SP, SP, 0x10
+  STRB            W0, [SP,0xF]
+  LDRB            W0, [SP,0xF]
+  CMP             W0, 0x1F
+  B.LS            is_print
+  LDRB            W0, [SP,0xF]
+  CMP             W0, 0x7E
+  B.HI            is_print
+  MOVZ            W0, 1
+  B               ret_
+is_print:
+  MOVZ            W0, 0
+
+ret_:
+  ADD             SP, SP, 0x10
+  RET             LR
\ No newline at end of file
diff --git a/test/arch/aarch64/unit/asm_test.py b/test/arch/aarch64/unit/asm_test.py
new file mode 100644
index 00000000..60ed418e
--- /dev/null
+++ b/test/arch/aarch64/unit/asm_test.py
@@ -0,0 +1,64 @@
+#! /usr/bin/env python
+import sys
+import os
+
+from miasm2.core.cpu import parse_ast
+from miasm2.arch.aarch64.arch import mn_aarch64, base_expr, variable
+from miasm2.core import parse_asm
+from miasm2.expression.expression import *
+from miasm2.core import asmbloc
+from elfesteem.strpatchwork import StrPatchwork
+from miasm2.analysis.machine import Machine
+from miasm2.jitter.csts import *
+from pdb import pm
+
+
+filename = os.environ.get('PYTHONSTARTUP')
+if filename and os.path.isfile(filename):
+    execfile(filename)
+
+
+reg_and_id = dict(mn_aarch64.regs.all_regs_ids_byname)
+
+class Asm_Test(object):
+    def __init__(self):
+        self.myjit = Machine("aarch64l").jitter()
+        self.myjit.init_stack()
+
+        self.myjit.jit.log_regs = False
+        self.myjit.jit.log_mn = False
+
+
+    def __call__(self):
+        self.asm()
+        self.run()
+        self.check()
+
+
+    def asm(self):
+        blocs, symbol_pool = parse_asm.parse_txt(mn_aarch64, 'l', self.TXT,
+                                                 symbol_pool = self.myjit.ir_arch.symbol_pool)
+        # fix shellcode addr
+        symbol_pool.set_offset(symbol_pool.getby_name("main"), 0x0)
+        s = StrPatchwork()
+        patches = asmbloc.asm_resolve_final(mn_aarch64, blocs[0], symbol_pool)
+        for offset, raw in patches.items():
+            s[offset] = raw
+
+        self.assembly = str(s)
+
+    def run(self):
+        run_addr = 0
+        self.myjit.vm.add_memory_page(run_addr, PAGE_READ | PAGE_WRITE, self.assembly)
+
+        self.myjit.cpu.LR = 0x1337beef
+
+        self.myjit.add_breakpoint(0x1337beef, lambda x:False)
+
+        self.myjit.init_run(run_addr)
+        self.myjit.continue_run()
+
+        assert(self.myjit.pc == 0x1337beef)
+
+    def check(self):
+        raise NotImplementedError('abstract method')
diff --git a/test/arch/aarch64/unit/mn_ubfm.py b/test/arch/aarch64/unit/mn_ubfm.py
new file mode 100644
index 00000000..938f13cf
--- /dev/null
+++ b/test/arch/aarch64/unit/mn_ubfm.py
@@ -0,0 +1,30 @@
+#! /usr/bin/env python
+from asm_test import Asm_Test
+from pdb import pm
+
+
+class Test_UBFM1(Asm_Test):
+    TXT = '''
+main:
+       MOVZ    X0, 0x5600
+       UBFM    X0, X0, 8, 15
+       RET     LR
+    '''
+    def check(self):
+        assert(self.myjit.cpu.X0 == 0x56)
+        pass
+
+class Test_UBFM2(Asm_Test):
+    TXT = '''
+main:
+       MOVZ    X0, 0x56
+       UBFM    X0, X0, 4, 55
+       RET     LR
+    '''
+    def check(self):
+        assert(self.myjit.cpu.X0 == 0x5)
+        pass
+
+
+if __name__ == "__main__":
+    [test()() for test in [Test_UBFM1, Test_UBFM2 ]]
diff --git a/test/test_all.py b/test/test_all.py
index 5f8f6ea7..7270af3d 100644
--- a/test/test_all.py
+++ b/test/test_all.py
@@ -40,6 +40,7 @@ for script in ["x86/sem.py",
                "x86/unit/mn_das.py",
                "arm/arch.py",
                "arm/sem.py",
+               "aarch64/unit/mn_ubfm.py",
                "msp430/arch.py",
                "msp430/sem.py",
                "sh4/arch.py",
@@ -214,6 +215,8 @@ for source in test_box_names:
 
 test_armb = ExampleShellcode(["armb", "arm_simple.S", "demo_arm_b.bin"])
 test_arml = ExampleShellcode(["arml", "arm_simple.S", "demo_arm_l.bin"])
+test_aarch64b = ExampleShellcode(["aarch64b", "aarch64_simple.S", "demo_aarch64_b.bin"])
+test_aarch64l = ExampleShellcode(["aarch64l", "aarch64_simple.S", "demo_aarch64_l.bin"])
 test_armb_sc = ExampleShellcode(["armb", "arm_sc.S", "demo_arm2_b.bin"])
 test_arml_sc = ExampleShellcode(["arml", "arm_sc.S", "demo_arm2_l.bin"])
 test_armtb = ExampleShellcode(["armtb", "armt.S", "demo_armt_b.bin"])
@@ -226,6 +229,8 @@ test_x86_64 = ExampleShellcode(["x86_64", "x86_64.S", "demo_x86_64.bin",
 
 testset += test_armb
 testset += test_arml
+testset += test_aarch64b
+testset += test_aarch64l
 testset += test_armb_sc
 testset += test_arml_sc
 testset += test_armtb
@@ -277,6 +282,10 @@ testset += ExampleDisasmFull(["armtl", Example.get_sample("demo_armt_l.bin"),
                               "0"], depends=[test_armtl])
 testset += ExampleDisasmFull(["armtb", Example.get_sample("demo_armt_b.bin"),
                               "0"], depends=[test_armtb])
+testset += ExampleDisasmFull(["aarch64l", Example.get_sample("demo_aarch64_l.bin"),
+                              "0"], depends=[test_aarch64l])
+testset += ExampleDisasmFull(["aarch64b", Example.get_sample("demo_aarch64_b.bin"),
+                              "0"], depends=[test_aarch64b])
 testset += ExampleDisasmFull(["x86_32", Example.get_sample("x86_32_simple.bin"),
                               "0x401000"], depends=[test_box["simple"]])
 testset += ExampleDisasmFull(["msp430", Example.get_sample("msp430_sc.bin"),
@@ -287,6 +296,8 @@ testset += ExampleDisasmFull(["mips32b", Example.get_sample("mips32_sc_b.bin"),
                               "0"], depends=[test_mips32b])
 testset += ExampleDisasmFull(["x86_64", Example.get_sample("demo_x86_64.bin"),
                               "0x401000"], depends=[test_x86_64])
+testset += ExampleDisasmFull(["aarch64l", Example.get_sample("md5_aarch64l"),
+                              "0x400A00"], depends=[test_aarch64l])
 
 
 ## Expression