Пример #1
0
 def __init__(self, emulator):
     # we need the emulator instance in order to call its 'fatal' method.
     self.emu = emulator
     # holds the java->python objects and methods mapping
     self.mapping = ObjectMapping()
     # map of jump labels to opcodes offsets
     self.labels = {}
     # variables container
     self.variables = {}
     # try/catch blocks container with opcodes offsets
     self.catch_blocks = []
     # packed switches containers
     self.packed_switches = {}
     # array data blocks
     self.array_data = {}
     # list of thrown exceptions
     self.exceptions = []
     # holds the result of the last method invocation
     self.result = None
     # holds the return value of the method ( used by return-* opcodes )
     self.return_v = None
     # set to true when a return-* opcode is executed
     self.stop = False
     # current opcode index
     self.pc = 0
Пример #2
0
class VM(object):
    def __init__(self, emulator):
        # we need the emulator instance in order to call its 'fatal' method.
        self.emu = emulator
        # holds the java->python objects and methods mapping
        self.mapping = ObjectMapping()
        # map of jump labels to opcodes offsets
        self.labels = {}
        # variables container
        self.variables = {}
        # try/catch blocks container with opcodes offsets
        self.catch_blocks = []
        # packed switches containers
        self.packed_switches = {}
        # array data blocks
        self.array_data = {}
        # list of thrown exceptions
        self.exceptions = []
        # holds the result of the last method invocation
        self.result = None
        # holds the return value of the method ( used by return-* opcodes )
        self.return_v = None
        # set to true when a return-* opcode is executed
        self.stop = False
        # current opcode index
        self.pc = 0

    def __getitem__(self, name):
        return self.variables[name]

    def __setitem__(self, name, value):
        self.variables[name] = value

    def fatal(self, message):
        self.emu.fatal(message)

    def goto(self, label):
        self.pc = self.labels[label]

    def exception(self, e):
        self.exceptions.append(e)

        # check if this operation is surrounded by a try/catch block
        for block in self.catch_blocks:
            start, end, label = block
            if start <= self.pc <= end:
                self.goto(label)
                return

        # nope, report unhandled exception
        self.emu.fatal("Unhandled exception '%s'." % str(e) )

    def new_instance(self, klass):
        return self.mapping.new_instance(self, klass)

    def invoke(self, this, class_name, method_name, args):
        self.mapping.invoke( self, this, class_name, method_name, args )
Пример #3
0
class VM(object):
    def __init__(self, emulator):
        # we need the emulator instance in order to call its 'fatal' method.
        self.emu = emulator
        # holds the java->python objects and methods mapping
        self.mapping = ObjectMapping()
        # map of jump labels to opcodes offsets
        self.labels = {}
        # variables container
        self.variables = {}
        # try/catch blocks container with opcodes offsets
        self.catch_blocks = []
        # packed switches containers
        self.packed_switches = {}
        # array data blocks
        self.array_data = {}
        # list of thrown exceptions
        self.exceptions = []
        # holds the result of the last method invocation
        self.result = None
        # holds the return value of the method ( used by return-* opcodes )
        self.return_v = None
        # set to true when a return-* opcode is executed
        self.stop = False
        # current opcode index
        self.pc = 0

    def __getitem__(self, name):
        return self.variables[name]

    def __setitem__(self, name, value):
        self.variables[name] = value

    def fatal(self, message):
        self.emu.fatal(message)

    def goto(self, label):
        self.pc = self.labels[label]

    def exception(self, e):
        self.exceptions.append(e)

        # check if this operation is surrounded by a try/catch block
        for block in self.catch_blocks:
            start, end, label = block
            if start <= self.pc <= end:
                self.goto(label)
                return

        # nope, report unhandled exception
        self.emu.fatal("Unhandled exception '%s'." % str(e))

    def new_instance(self, klass):
        return self.mapping.new_instance(self, klass)

    def invoke(self, this, class_name, method_name, args):
        self.mapping.invoke(self, this, class_name, method_name, args)
Пример #4
0
 def __init__(self, emulator):
     # we need the emulator instance in order to call its 'fatal' method.
     self.emu = emulator
     # holds the java->python objects and methods mapping
     self.mapping = ObjectMapping()
     # map of jump labels to opcodes offsets
     self.labels = {}
     # variables container
     self.variables = {}
     # try/catch blocks container with opcodes offsets
     self.catch_blocks = []
     # packed switches containers
     self.packed_switches = {}
     # array data blocks
     self.array_data = {}
     # list of thrown exceptions
     self.exceptions = []
     # holds the result of the last method invocation
     self.result = None
     # holds the return value of the method ( used by return-* opcodes )
     self.return_v = None
     # set to true when a return-* opcode is executed
     self.stop = False
     # current opcode index
     self.pc = 0