about summary refs log tree commit diff stats
path: root/miasm2
diff options
context:
space:
mode:
Diffstat (limited to 'miasm2')
-rw-r--r--miasm2/arch/arm/arch.py36
-rw-r--r--miasm2/arch/mips32/arch.py17
-rw-r--r--miasm2/arch/msp430/arch.py11
-rw-r--r--miasm2/arch/x86/arch.py16
4 files changed, 38 insertions, 42 deletions
diff --git a/miasm2/arch/arm/arch.py b/miasm2/arch/arm/arch.py
index f6b2e1cf..f40279a7 100644
--- a/miasm2/arch/arm/arch.py
+++ b/miasm2/arch/arm/arch.py
@@ -75,6 +75,10 @@ pregs_expr = [ExprId(x) for x in pregs_str]
 
 p_regs = reg_info(pregs_str, pregs_expr)
 
+conditional_branch = ["BEQ", "BNE", "BCS", "BCC", "BMI", "BPL", "BVS",
+                      "BVC", "BHI", "BLS", "BGE", "BLT", "BGT", "BLE"]
+
+unconditional_branch = ["B", "BX", "BL", "BLX"]
 
 # parser helper ###########
 
@@ -352,9 +356,7 @@ class instruction_arm(instruction):
 
 
     def dstflow(self):
-        if self.name.startswith('BIC'):
-            return False
-        return self.name.startswith('B')
+        return self.name in conditional_branch + unconditional_branch
 
     def dstflow2label(self, symbol_pool):
         e = self.args[0]
@@ -369,11 +371,10 @@ class instruction_arm(instruction):
         self.args[0] = s
 
     def breakflow(self):
-        if self.name.startswith('B') and not self.name.startswith('BIC'):
+        if self.name in conditional_branch + unconditional_branch:
             return True
         if self.name.startswith("LDM") and PC in self.args[1].args:
             return True
-
         if self.args and PC in self.args[0].get_r():
             return True
         return False
@@ -384,8 +385,6 @@ class instruction_arm(instruction):
         return self.additional_info.lnk
 
     def getdstflow(self, symbol_pool):
-        if self.name in ['CBZ', 'CBNZ']:
-            return [self.args[1]]
         return [self.args[0]]
 
     def splitflow(self):
@@ -427,11 +426,9 @@ class instruction_armt(instruction_arm):
         super(instruction_armt, self).__init__(*args, **kargs)
 
     def dstflow(self):
-        if self.name.startswith('BIC'):
-            return False
         if self.name in ["CBZ", "CBNZ"]:
             return True
-        return self.name.startswith('B')
+        return self.name in conditional_branch + unconditional_branch
 
     def dstflow2label(self, symbol_pool):
         if self.name in ["CBZ", "CBNZ"]:
@@ -452,10 +449,7 @@ class instruction_armt(instruction_arm):
             self.args[0] = s
 
     def breakflow(self):
-        if self.name in ['B', 'BX', 'BL', 'BLX',
-                         'BEQ', 'BNE', 'BCS', 'BCC', 'BMI', 'BPL', 'BVS',
-                         'BVC', 'BHI', 'BLS', 'BGE', 'BLT', 'BGT', 'BLE',
-                         'CBZ', 'CBNZ']:
+        if self.name in conditional_branch + unconditional_branch +["CBZ", "CBNZ"]:
             return True
         if self.name.startswith("LDM") and PC in self.args[1].args:
             return True
@@ -463,18 +457,18 @@ class instruction_armt(instruction_arm):
             return True
         return False
 
+    def getdstflow(self, symbol_pool):
+        if self.name in ['CBZ', 'CBNZ']:
+            return [self.args[1]]
+        return [self.args[0]]
+
     def splitflow(self):
-        if self.name in ['BL', 'BLX',
-                         'BEQ', 'BNE', 'BCS', 'BCC', 'BMI', 'BPL', 'BVS',
-                         'BVC', 'BHI', 'BLS', 'BGE', 'BLT', 'BGT', 'BLE',
-                         'CBZ', 'CBNZ']:
+        if self.name in conditional_branch + ['BL', 'BLX', 'CBZ', 'CBNZ']:
             return True
         return False
 
     def is_subcall(self):
-        if self.name in ['BL', 'BLX']:
-            return True
-        return False
+        return self.name in ['BL', 'BLX']
 
     def fixDstOffset(self):
         e = self.args[0]
diff --git a/miasm2/arch/mips32/arch.py b/miasm2/arch/mips32/arch.py
index b3bbc3ff..ac22f7c9 100644
--- a/miasm2/arch/mips32/arch.py
+++ b/miasm2/arch/mips32/arch.py
@@ -50,10 +50,9 @@ deref = deref_off | deref_nooff
 class additional_info:
     def __init__(self):
         self.except_on_instr = False
-br_flt = ['BC1F']
 
-br_0 = ['B', 'JR', 'BAL', 'JAL', 'JALR']
-br_1 = ['BGEZ', 'BLTZ', 'BGTZ', 'BLEZ', 'BC1T', 'BC1F'] + br_flt
+br_0 = ['B', 'J', 'JR', 'BAL', 'JAL', 'JALR']
+br_1 = ['BGEZ', 'BLTZ', 'BGTZ', 'BLEZ', 'BC1T', 'BC1F']
 br_2 = ['BEQ', 'BEQL', 'BNE']
 
 
@@ -78,9 +77,7 @@ class instruction_mips32(instruction):
     def dstflow(self):
         if self.name == 'BREAK':
             return False
-        if self.name.startswith('B'):
-            return True
-        if self.name in ['JAL', 'JALR', 'JR', 'J']:
+        if self.name in br_0 + br_1 + br_2:
             return True
         return False
 
@@ -116,19 +113,15 @@ class instruction_mips32(instruction):
     def breakflow(self):
         if self.name == 'BREAK':
             return False
-        if self.name.startswith('B') or self.name in ['JR', 'J', 'JAL', 'JALR']:
+        if self.name in br_0 + br_1 + br_2:
             return True
         return False
 
     def is_subcall(self):
-        if self.name in ['JAL', 'JALR']:
+        if self.name in ['JAL', 'JALR', 'BAL']:
             return True
         return False
 
-        if self.name == 'BLX':
-            return True
-        return self.additional_info.lnk
-
     def getdstflow(self, symbol_pool):
         if self.name in br_0:
             return [self.args[0]]
diff --git a/miasm2/arch/msp430/arch.py b/miasm2/arch/msp430/arch.py
index 34993ebc..dff91e7b 100644
--- a/miasm2/arch/msp430/arch.py
+++ b/miasm2/arch/msp430/arch.py
@@ -16,6 +16,9 @@ console_handler.setFormatter(logging.Formatter("%(levelname)-5s: %(message)s"))
 log.addHandler(console_handler)
 log.setLevel(logging.DEBUG)
 
+conditional_branch = ['jnz', 'jz', 'jnc', 'jc',
+                      'jn', 'jge', 'jl']
+unconditional_branch = ['jmp']
 
 def deref2expr_nooff(s, l, t):
     t = t[0]
@@ -152,7 +155,7 @@ class instruction_msp430(instruction):
         self.args[0] = s
 
     def breakflow(self):
-        if self.name.startswith('j'):
+        if self.name in conditional_branch + unconditional_branch:
             return True
         if self.name.startswith('ret'):
             return True
@@ -163,10 +166,10 @@ class instruction_msp430(instruction):
         return self.name in ['call']
 
     def splitflow(self):
-        if self.name.startswith('jmp'):
-            return False
-        if self.name.startswith('j'):
+        if self.name in conditional_branch:
             return True
+        if self.name in unconditional_branch:
+            return False
         return self.name in ['call']
 
     def setdstflow(self, a):
diff --git a/miasm2/arch/x86/arch.py b/miasm2/arch/x86/arch.py
index 186cbd8b..85356468 100644
--- a/miasm2/arch/x86/arch.py
+++ b/miasm2/arch/x86/arch.py
@@ -16,6 +16,12 @@ console_handler.setFormatter(logging.Formatter("%(levelname)-5s: %(message)s"))
 log.addHandler(console_handler)
 log.setLevel(logging.WARN)
 
+conditional_branch = ["JO", "JNO", "JB", "JAE",
+                      "JZ", "JNZ", "JBE", "JA",
+                      "JS", "JNS", "JPE", "JNP",
+                      #"L", "NL", "NG", "G"]
+                      "JL", "JGE", "JLE", "JG"]
+unconditional_branch = ['JMP']
 
 f_isad = "AD"
 f_s08 = "S08"
@@ -465,7 +471,7 @@ class instruction_x86(instruction):
         return self.additional_info.v_admode
 
     def dstflow(self):
-        if self.name.startswith('J'):
+        if self.name in conditional_branch + unconditional_branch:
             return True
         if self.name.startswith('LOOP'):
             return True
@@ -491,7 +497,7 @@ class instruction_x86(instruction):
             return
 
     def breakflow(self):
-        if self.name.startswith('J'):
+        if self.name in conditional_branch + unconditional_branch:
             return True
         if self.name.startswith('LOOP'):
             return True
@@ -507,10 +513,10 @@ class instruction_x86(instruction):
         return self.name in ['CALL', 'HLT', 'IRET', 'ICEBP']
 
     def splitflow(self):
-        if self.name.startswith('JMP'):
-            return False
-        if self.name.startswith('J'):
+        if self.name in conditional_branch:
             return True
+        if self.name in unconditional_branch:
+            return False
         if self.name.startswith('LOOP'):
             return True
         if self.name.startswith('INT'):