Fix bugs in scanner.last_instr()...

And ave instruction stream self.insts like we do in Python 3 so we
can start simplifying code.
This commit is contained in:
rocky
2017-12-15 20:34:34 -05:00
parent 9cb99e3290
commit 15057bed1d
3 changed files with 17 additions and 7 deletions

View File

@@ -174,8 +174,9 @@ class Scanner(object):
instr = [instr] instr = [instr]
result_offset = None result_offset = None
current_distance = len(code) current_distance = self.insts[-1].offset - self.insts[0].offset
extended_arg = 0 extended_arg = 0
# FIXME: use self.insts rather than code[]
for offset in self.op_range(start, end): for offset in self.op_range(start, end):
op = code[offset] op = code[offset]
@@ -197,6 +198,12 @@ class Scanner(object):
if new_distance <= current_distance: if new_distance <= current_distance:
current_distance = new_distance current_distance = new_distance
result_offset = offset result_offset = offset
pass
pass
pass
pass
extended_arg = 0
pass
return result_offset return result_offset
def all_instr(self, start, end, instr, target=None, include_beyond_target=False): def all_instr(self, start, end, instr, target=None, include_beyond_target=False):

View File

@@ -26,7 +26,7 @@ from collections import namedtuple
from array import array from array import array
from xdis.code import iscode from xdis.code import iscode
from xdis.bytecode import op_has_argument, op_size, instruction_size from xdis.bytecode import Bytecode, op_has_argument, op_size, instruction_size
from xdis.util import code2num from xdis.util import code2num
from uncompyle6.scanner import Scanner from uncompyle6.scanner import Scanner
@@ -88,10 +88,9 @@ class Scanner2(Scanner):
if not show_asm: if not show_asm:
show_asm = self.show_asm show_asm = self.show_asm
bytecode = Bytecode(co, self.opc)
# show_asm = 'after' # show_asm = 'after'
if show_asm in ('both', 'before'): if show_asm in ('both', 'before'):
from xdis.bytecode import Bytecode
bytecode = Bytecode(co, self.opc)
for instr in bytecode.get_instructions(co): for instr in bytecode.get_instructions(co):
print(instr.disassemble()) print(instr.disassemble())
@@ -110,6 +109,7 @@ class Scanner2(Scanner):
self.build_lines_data(co, codelen) self.build_lines_data(co, codelen)
self.build_prev_op(codelen) self.build_prev_op(codelen)
self.insts = list(bytecode)
free, names, varnames = self.unmangle_code_names(co, classname) free, names, varnames = self.unmangle_code_names(co, classname)
self.names = names self.names = names

View File

@@ -19,6 +19,7 @@ from uncompyle6.scanner import L65536
# bytecode verification, verify(), uses JUMP_OPs from here # bytecode verification, verify(), uses JUMP_OPs from here
from xdis.opcodes import opcode_26 from xdis.opcodes import opcode_26
from xdis.bytecode import Bytecode
JUMP_OPS = opcode_26.JUMP_OPS JUMP_OPS = opcode_26.JUMP_OPS
class Scanner26(scan.Scanner2): class Scanner26(scan.Scanner2):
@@ -87,11 +88,12 @@ class Scanner26(scan.Scanner2):
cause specific rules for the specific number of arguments they take. cause specific rules for the specific number of arguments they take.
""" """
show_asm = self.show_asm if not show_asm else show_asm if not show_asm:
show_asm = self.show_asm
bytecode = Bytecode(co, self.opc)
# show_asm = 'after' # show_asm = 'after'
if show_asm in ('both', 'before'): if show_asm in ('both', 'before'):
from xdis.bytecode import Bytecode
bytecode = Bytecode(co, self.opc)
for instr in bytecode.get_instructions(co): for instr in bytecode.get_instructions(co):
print(instr.disassemble()) print(instr.disassemble())
@@ -108,6 +110,7 @@ class Scanner26(scan.Scanner2):
self.build_lines_data(co, codelen) self.build_lines_data(co, codelen)
self.build_prev_op(codelen) self.build_prev_op(codelen)
self.insts = list(bytecode)
free, names, varnames = self.unmangle_code_names(co, classname) free, names, varnames = self.unmangle_code_names(co, classname)
self.names = names self.names = names