X Tutup
Skip to content

Commit ec06693

Browse files
committed
Towards better 3.0 decompilation
Sync scanner2 and scanner3 better
1 parent 3f40c16 commit ec06693

File tree

3 files changed

+382
-11
lines changed

3 files changed

+382
-11
lines changed

uncompyle6/scanners/scanner2.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -484,20 +484,21 @@ def detect_control_flow(self, offset, op):
484484
in python2.3+
485485
"""
486486

487-
# TODO: check the struct boundaries more precisely -Dan
488-
489487
code = self.code
490488

491489
# Detect parent structure
492490
parent = self.structs[0]
493491
start = parent['start']
494492
end = parent['end']
493+
494+
# Pick inner-most parent for our offset
495495
for struct in self.structs:
496-
_start = struct['start']
497-
_end = struct['end']
498-
if (_start <= offset < _end) and (_start >= start and _end <= end):
499-
start = _start
500-
end = _end
496+
current_start = struct['start']
497+
current_end = struct['end']
498+
if ((current_start <= offset < current_end)
499+
and (current_start >= start and current_end <= end)):
500+
start = current_start
501+
end = current_end
501502
parent = struct
502503

503504
if op == self.opc.SETUP_LOOP:

uncompyle6/scanners/scanner3.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ def ingest(self, co, classname=None, code_objects={}, show_asm=None):
322322
if target <= inst.offset:
323323
next_opname = self.opname[self.code[inst.offset+3]]
324324
if (inst.offset in self.stmts and
325+
#if (hasattr(inst, 'linestart') and
325326
(next_opname not in ('END_FINALLY', 'POP_BLOCK',
326327
# Python 3.0 only uses POP_TOP
327328
'POP_TOP'))):
@@ -499,7 +500,7 @@ def build_statement_indices(self):
499500
prelim = self.all_instr(start, end, self.statement_opcodes)
500501

501502
# Initialize final container with statements with
502-
# preliminnary data
503+
# preliminary data
503504
stmts = self.stmts = set(prelim)
504505

505506
# Same for opcode sequences
@@ -578,11 +579,11 @@ def get_target(self, offset):
578579
op = self.code[offset]
579580
if self.version >= 3.6:
580581
target = self.code[offset+1]
581-
if op in op3.hasjrel:
582+
if op in self.opc.hasjrel:
582583
target += offset + 2
583584
else:
584585
target = self.code[offset+1] + self.code[offset+2] * 256
585-
if op in op3.hasjrel:
586+
if op in self.opc.hasjrel:
586587
target += offset + 3
587588

588589
return target

0 commit comments

Comments
 (0)
X Tutup