コード例 #1
0
ファイル: basicblock.py プロジェクト: NoamSheffer/WazeWP7
	def __init__(self, controller, instructions, labels, trace):
		CodeBlock.__init__(self, controller, instructions, labels, trace)

		for insn in self.instructions:
			insn.setBasicBlock(self)
		# If the last instruction is a return, then this is a return
		# block
		self.isReturnBlock = instructions[-1].isReturnInstruction
コード例 #2
0
ファイル: basicblock.py プロジェクト: glennneiger/WazeWP7
    def __init__(self, controller, instructions, labels, trace):
        CodeBlock.__init__(self, controller, instructions, labels, trace)

        for insn in self.instructions:
            insn.setBasicBlock(self)
        # If the last instruction is a return, then this is a return
        # block
        self.isReturnBlock = instructions[-1].isReturnInstruction
コード例 #3
0
ファイル: javamethod.py プロジェクト: glennneiger/WazeWP7
    def __init__(self, controller, functions):
        self.controller = controller
        self.name = "call"
        self.bc = bytecode.ByteCodeGenerator(self.controller)
        self.rh = register.RegisterHandler(self.controller, self.bc)

        CodeBlock.__init__(self, self.controller, [], [], False)
        self.functions = functions
        self.address = 0
        self.size = 0
コード例 #4
0
ファイル: javamethod.py プロジェクト: NoamSheffer/WazeWP7
	def __init__(self, controller, functions):
		self.controller = controller
		self.name = "call"
		self.bc = bytecode.ByteCodeGenerator(self.controller)
		self.rh = register.RegisterHandler(self.controller, self.bc)

		CodeBlock.__init__(self, self.controller, [], [], False)
		self.functions = functions
		self.address = 0
		self.size = 0
コード例 #5
0
ファイル: function.py プロジェクト: glennneiger/WazeWP7
	def __init__(self, controller, name, instructions, labels, trace=False):
		CodeBlock.__init__(self, controller, instructions, labels, trace, setupRegisters = True)
		self.name = name
		sym = self.controller.elf.getSymbolByAddress(self.address)
		if self.address == self.controller.elf.getEntryPoint():
			self.name = "start"
		elif sym.localLinkage():
			self.name = self.name +  "_%x" % (self.address)
		self.basicBlocks = []

		# Assume this is a leaf function, but non-recursive
		self.isLeafFunction = True
		self.isRecursive = False

		# Create basic blocks and check leafness
		first = 0
		last = 0
		for insn in self.instructions:
			last = last + 1
			if insn.isBranch or insn.isBranchDestination and not insn.address == self.address:
				# Remove the last instruction if this is a branch -
				# but not for the function entry point. The reason is
				# that some functions might start with a branch
				if insn.isBranchDestination and not insn.address == self.address:
					last = last - 1
				if last != first:
					# Do not append empty basic blocks
					bb = BasicBlock(self.controller, self.instructions[first:last], self.labels, trace)
					self.basicBlocks.append(bb)
				first = last
				if insn.isBranchDestination and not insn.address == self.address:
					last = last + 1

			if insn.isFunctionCall:
				self.isLeafFunction = False

			# Is this a recursive function call (only Jal is important)
			if isinstance(insn, instruction.Jal) and insn.dstAddress == self.address:
				self.isRecursive = True
			insn.setFunction(self)
		else:
			# Last one
			if last != first:
				self.basicBlocks.append(BasicBlock(self.controller, self.instructions[first:last], self.labels, trace))
コード例 #6
0
ファイル: javamethod.py プロジェクト: glennneiger/WazeWP7
    def __init__(self, controller, functions):
        self.functions = functions
        self.controller = controller
        self.labels = {}
        self.instructions = []
        self.exceptionHandlers = []
        self.returnAddresses = {}

        for fn in self.functions:
            fn.setJavaMethod(self)
            for key, item in fn.labels.iteritems():
                assert (not self.labels.has_key(key))
                self.labels[key] = item
            self.instructions = self.instructions + fn.instructions

            self.name = fn.name
            self.methodAccess = "public"
        self.bc = bytecode.ByteCodeGenerator(self.controller)
        self.rh = register.RegisterHandler(self.controller, self.bc)

        useTracing = False
        for fn in self.functions:
            if fn.useTracing:
                useTracing = True
                break

        CodeBlock.__init__(self,
                           self.controller,
                           self.instructions,
                           self.labels,
                           useTracing,
                           setupRegisters=True)

        # Each label and instruction belongs to one java method
        for lab in self.labels.values():
            if lab.address >= self.address and lab.address <= self.address + self.size:
                lab.setJavaMethod(self)

        self.cleanupRegs = set()

        # For non-leafs, we always pass all registers
        i = 0
        for fn in self.functions:
            if not fn.isLeaf(
            ) or fn.address == self.controller.elf.getEntryPoint():
                self.addSourceRegister(mips.R_SP)
                self.addSourceRegister(mips.R_A0)
                self.addSourceRegister(mips.R_A1)
                self.addSourceRegister(mips.R_A2)
                self.addSourceRegister(mips.R_A3)
                self.addDestinationRegister(mips.R_V0)
                self.addDestinationRegister(mips.R_V1)
            self.addSourceRegister(mips.R_MEM)
            self.addDestinationRegister(mips.R_MEM)
            fn.setIndex(i)
            i = i + 1

        self.argumentRegisters = [
            mips.R_SP, mips.R_A0, mips.R_A1, mips.R_A2, mips.R_A3
        ]
        if not config.debug:
            self.argumentRegisters = list(
                self.usedRegisters.intersection(
                    [mips.R_SP, mips.R_A0, mips.R_A1, mips.R_A2, mips.R_A3]))
        self.argumentRegisters.sort()
        # Always place sp first
        if mips.R_SP in self.argumentRegisters:
            self.argumentRegisters.remove(mips.R_SP)
            self.argumentRegisters = [mips.R_SP] + self.argumentRegisters
        # And add the function address argument last if we have multiple functions / method
        if self.hasMultipleFunctions():
            self.argumentRegisters = self.argumentRegisters + [mips.R_FNA]
        self.usesMemoryInstructions = False
コード例 #7
0
ファイル: function.py プロジェクト: glennneiger/WazeWP7
	def __str__(self):
		out = "%s:\n" % (self.name)
		return out + CodeBlock.__str__(self)
コード例 #8
0
ファイル: javamethod.py プロジェクト: NoamSheffer/WazeWP7
	def __init__(self, controller, functions):
		self.functions = functions
		self.controller = controller
		self.labels = {}
		self.instructions = []
		self.exceptionHandlers = []
		self.returnAddresses = {}

		for fn in self.functions:
			fn.setJavaMethod(self)
			for key, item in fn.labels.iteritems():
				assert(not self.labels.has_key(key))
				self.labels[key] = item
			self.instructions = self.instructions + fn.instructions

			self.name = fn.name
			self.methodAccess = "public"
		self.bc = bytecode.ByteCodeGenerator(self.controller)
		self.rh = register.RegisterHandler(self.controller, self.bc)

		useTracing = False
		for fn in self.functions:
			if fn.useTracing:
				useTracing = True
				break

		CodeBlock.__init__(self, self.controller, self.instructions, self.labels, useTracing, setupRegisters=True)

		# Each label and instruction belongs to one java method
		for lab in self.labels.values():
			if lab.address >= self.address and lab.address <= self.address + self.size:
				lab.setJavaMethod(self)

		self.cleanupRegs = set()

		# For non-leafs, we always pass all registers
		i = 0
		for fn in self.functions:
			if not fn.isLeaf() or fn.address == self.controller.elf.getEntryPoint():
				self.addSourceRegister(mips.R_SP)
				self.addSourceRegister(mips.R_A0)
				self.addSourceRegister(mips.R_A1)
				self.addSourceRegister(mips.R_A2)
				self.addSourceRegister(mips.R_A3)
				self.addDestinationRegister(mips.R_V0)
				self.addDestinationRegister(mips.R_V1)
			self.addSourceRegister(mips.R_MEM)
			self.addDestinationRegister(mips.R_MEM)
			fn.setIndex(i)
			i = i + 1

		self.argumentRegisters = [mips.R_SP, mips.R_A0, mips.R_A1, mips.R_A2, mips.R_A3]
		if not config.debug:
			self.argumentRegisters = list(self.usedRegisters.intersection( [mips.R_SP, mips.R_A0, mips.R_A1, mips.R_A2, mips.R_A3] ))
		self.argumentRegisters.sort()
		# Always place sp first
		if mips.R_SP in self.argumentRegisters:
			self.argumentRegisters.remove(mips.R_SP)
			self.argumentRegisters = [mips.R_SP] + self.argumentRegisters
		# And add the function address argument last if we have multiple functions / method
		if self.hasMultipleFunctions():
			self.argumentRegisters = self.argumentRegisters + [mips.R_FNA]
		self.usesMemoryInstructions = False