Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

work-in-progress branch to make ddx2dot work on baksmali

  • Loading branch information...
commit efd02b1f3a9561d17617e21547371a495e7a4bdc 1 parent f190ed0
Nelson Elhage authored

Showing 1 changed file with 31 additions and 17 deletions. Show diff stats Hide diff stats

  1. +31 17 ddx2dot
48 ddx2dot
@@ -91,7 +91,8 @@ def findExit(lines):
91 91 code = []
92 92
93 93 for line in lines:
94   - m = re.search(r'^(\w+):', line)
  94 + if not line.strip(): continue
  95 + m = re.search(r'^\s*(:\w+)', line)
95 96 if m:
96 97 if candidate:
97 98 return_blocks[this_label] = code
@@ -101,7 +102,7 @@ def findExit(lines):
101 102 continue
102 103
103 104 code.append(line)
104   -
  105 +
105 106 if line.strip().startswith('return'):
106 107 candidate = True
107 108 else:
@@ -143,26 +144,33 @@ switchBlock('entry')
143 144
144 145 (NONE, SPARSE, PACKED) = range(3)
145 146
  147 +switch_table = {}
  148 +switch_idx = None
  149 +
146 150 for line in lines:
  151 + if not line.strip(): continue
147 152 code.append(line)
148 153
149 154 if in_switch:
150 155 l = line.strip()
151   - if l.startswith('default:'):
152   - addEdgeTo(l.split()[-1], 'default')
  156 + if l.startswith('.end'):
  157 + was_goto = True
153 158 in_switch = False
  159 + code = []
154 160 continue
155 161 else:
156 162 if in_switch == PACKED:
157   - lbl = l.split()[0]
158   - case = l.split()[-1]
  163 + lbl = l
  164 + case = hex(switch_idx)
  165 + switch_idx += 1
159 166 else: # SPARSE
160   - lbl = l.split()[-1]
161   - case = l.split()[0]
  167 + m = re.search(r'(0x[a-fA-F0-9]+)\s*->\s*(:\w+)', l)
  168 + lbl = m.group(2)
  169 + case = m.group(1)
162 170 addEdgeTo(lbl, case)
163 171 continue
164   -
165   - m = re.search(r'^(\w+):', line)
  172 +
  173 + m = re.search(r'^\s*(:\w+)', line)
166 174 if m:
167 175 del code[-1]
168 176 switchBlock(m.group(1))
@@ -172,7 +180,7 @@ for line in lines:
172 180 insn = line.strip()
173 181
174 182 if insn.startswith('if-'):
175   - to = insn.split(",")[-1]
  183 + to = insn.split()[-1]
176 184 addEdgeTo(to, 'true')
177 185 switchBlock(gensym())
178 186
@@ -181,15 +189,21 @@ for line in lines:
181 189 was_goto = True
182 190 if insn.startswith('throw'):
183 191 was_goto = True
184   - elif insn.startswith('packed-switch'):
185   - in_switch = PACKED
186   - was_goto = True
187   - elif insn.startswith('sparse-switch'):
188   - in_switch = SPARSE
189   - was_goto = True
  192 + elif insn.startswith('packed-switch') or \
  193 + insn.startswith('sparse-switch'):
  194 + label = insn.split()[-1]
  195 + switch_table[label] = block
  196 + switchBlock(gensym())
190 197 elif insn.startswith('goto'):
191 198 addEdgeTo(insn.split()[-1], 'goto')
192 199 was_goto = True
  200 + elif insn.startswith('.sparse-switch'):
  201 + in_switch = SPARSE
  202 + block = switch_table[block]
  203 + elif insn.startswith('.packed-switch'):
  204 + in_switch = PACKED
  205 + switch_idx = int(insn.split()[-1], 16)
  206 + block = switch_table[block]
193 207
194 208 if code:
195 209 exitBlock()

0 comments on commit efd02b1

Please sign in to comment.
Something went wrong with that request. Please try again.