Fix linter issues on cpu (#144)
* quick linter stuff * Fix cpu init in tests * update cpu name
This commit is contained in:
parent
e32701f978
commit
3e81cba8fb
@ -31,7 +31,7 @@ class Operand(object):
|
|||||||
scale = property( lambda self: self.parent.op.mem.scale )
|
scale = property( lambda self: self.parent.op.mem.scale )
|
||||||
disp = property( lambda self: self.parent.op.mem.disp )
|
disp = property( lambda self: self.parent.op.mem.disp )
|
||||||
|
|
||||||
def __init__(self, cpu, op, **kwargs):
|
def __init__(self, cpu, op):
|
||||||
'''
|
'''
|
||||||
This encapsulates the arch-independent way to access instruction
|
This encapsulates the arch-independent way to access instruction
|
||||||
operands and immediates based on a capstone operand descriptor. This
|
operands and immediates based on a capstone operand descriptor. This
|
||||||
@ -82,8 +82,7 @@ class Operand(object):
|
|||||||
''' It writes the value of specific type to the registers or memory '''
|
''' It writes the value of specific type to the registers or memory '''
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
# Basic register file structure not actully need to abstract as it's used only'
|
# Basic register file structure not actually need to abstract as it's used only from the cpu implementation
|
||||||
# from the cpu implementation
|
|
||||||
class RegisterFile(object):
|
class RegisterFile(object):
|
||||||
|
|
||||||
def __init__(self, aliases=None):
|
def __init__(self, aliases=None):
|
||||||
@ -360,7 +359,7 @@ class Cpu(object):
|
|||||||
break
|
break
|
||||||
assert isinstance(c, str)
|
assert isinstance(c, str)
|
||||||
text += c
|
text += c
|
||||||
except MemoryException as e:
|
except MemoryException:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
code = text.ljust(self.max_instr_width, '\x00')
|
code = text.ljust(self.max_instr_width, '\x00')
|
||||||
@ -462,7 +461,6 @@ class Cpu(object):
|
|||||||
result += "%3s: 0x%016x"%(reg_name, value)
|
result += "%3s: 0x%016x"%(reg_name, value)
|
||||||
else:
|
else:
|
||||||
result += "%3s: %r"%(reg_name, value)
|
result += "%3s: %r"%(reg_name, value)
|
||||||
pos = 0
|
|
||||||
result += '\n'
|
result += '\n'
|
||||||
|
|
||||||
return result
|
return result
|
||||||
@ -496,7 +494,7 @@ class DivideError(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
class CpuInterrupt(Exception):
|
class CpuInterrupt(Exception):
|
||||||
''' Any interruption triggred by the CPU '''
|
''' Any interruption triggered by the CPU '''
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class Interruption(CpuInterrupt):
|
class Interruption(CpuInterrupt):
|
||||||
|
|||||||
@ -115,7 +115,6 @@ class Armv7Operand(Operand):
|
|||||||
|
|
||||||
def address(self):
|
def address(self):
|
||||||
assert self.op.type == ARM_OP_MEM
|
assert self.op.type == ARM_OP_MEM
|
||||||
mem = self.op.mem
|
|
||||||
addr = self.get_mem_base_addr() + self.get_mem_offset()
|
addr = self.get_mem_base_addr() + self.get_mem_offset()
|
||||||
return addr & Mask(self.cpu.address_bit_size)
|
return addr & Mask(self.cpu.address_bit_size)
|
||||||
|
|
||||||
@ -265,7 +264,7 @@ class Armv7Cpu(Cpu):
|
|||||||
mode = CS_MODE_ARM
|
mode = CS_MODE_ARM
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, memory, *args, **kwargs):
|
def __init__(self, memory):
|
||||||
super(Armv7Cpu, self).__init__(Armv7RegisterFile(), memory)
|
super(Armv7Cpu, self).__init__(Armv7RegisterFile(), memory)
|
||||||
self._last_flags = {'C': 0, 'V': 0, 'N': 0, 'Z': 0}
|
self._last_flags = {'C': 0, 'V': 0, 'N': 0, 'Z': 0}
|
||||||
self._force_next = False
|
self._force_next = False
|
||||||
@ -736,7 +735,7 @@ class Armv7Cpu(Cpu):
|
|||||||
|
|
||||||
@instruction
|
@instruction
|
||||||
def SVC(cpu, op):
|
def SVC(cpu, op):
|
||||||
if (op.read() != 0):
|
if op.read() != 0:
|
||||||
logger.warning("Bad SVC number: {:08}".format(op.read()))
|
logger.warning("Bad SVC number: {:08}".format(op.read()))
|
||||||
raise Interruption(0)
|
raise Interruption(0)
|
||||||
|
|
||||||
|
|||||||
@ -24,7 +24,7 @@ def assemble(asm):
|
|||||||
|
|
||||||
class Armv7CpuTest(unittest.TestCase):
|
class Armv7CpuTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.c = Cpu(Memory32(), 'armv7')
|
self.c = Cpu(Memory32())
|
||||||
self.rf = self.c.regfile
|
self.rf = self.c.regfile
|
||||||
self._setupStack()
|
self._setupStack()
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ def itest_custom(asm):
|
|||||||
|
|
||||||
class Armv7CpuInstructions(unittest.TestCase):
|
class Armv7CpuInstructions(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.cpu = Cpu(Memory32(), 'armv7')
|
self.cpu = Cpu(Memory32())
|
||||||
self.mem = self.cpu.memory
|
self.mem = self.cpu.memory
|
||||||
self.rf = self.cpu.regfile
|
self.rf = self.cpu.regfile
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import struct
|
||||||
import unittest
|
import unittest
|
||||||
from manticore.core.cpu.x86 import *
|
from manticore.core.cpu.x86 import *
|
||||||
from manticore.core.smtlib import Operators
|
from manticore.core.smtlib import Operators
|
||||||
|
|||||||
@ -90,7 +90,7 @@ class Armv7UnicornInstructions(unittest.TestCase):
|
|||||||
all semantics match.
|
all semantics match.
|
||||||
'''
|
'''
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.cpu = Cpu(Memory32(), 'armv7')
|
self.cpu = Cpu(Memory32())
|
||||||
self.mem = self.cpu.memory
|
self.mem = self.cpu.memory
|
||||||
self.rf = self.cpu.regfile
|
self.rf = self.cpu.regfile
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user