-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
130 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from typing import Dict, List, Tuple | ||
|
||
from .enums import default_vex_archinfo, vex_endness_from_string | ||
from .types import Register | ||
from .vex_ffi import guest_offsets | ||
|
||
|
||
class PyvexArch: | ||
def __init__(self, name: str, bits: int, memory_endness: str): | ||
self.name = name | ||
self.bits = bits | ||
self.memory_endness = memory_endness | ||
self.instruction_endness = "Iend_BE" | ||
self.byte_width = 8 | ||
self.register_list: List[Register] = [] | ||
self.registers: Dict[str, Tuple[int, int]] = {} | ||
self.vex_arch = { | ||
"X86": "VexArchX86", | ||
"AMD64": "VexArchAMD64", | ||
"ARM": "VexArchARM", | ||
"AArch64": "VexArchARM64", | ||
"PPC32": "VexArchPPC32", | ||
"PPC64": "VexArchPPC64", | ||
"S390X": "VexArchS390X", | ||
"MIPS32": "VexArchMIPS32", | ||
"MIPS64": "VexArchMIPS64", | ||
}[name] | ||
self.ip_offset = guest_offsets[ | ||
( | ||
self.vex_name_small, | ||
{ | ||
"X86": "eip", | ||
"AMD64": "rip", | ||
"ARM": "r15t", | ||
"AArch64": "pc", | ||
"PPC32": "cia", | ||
"PPC64": "cia", | ||
"S390X": "ia", | ||
"MIPS32": "pc", | ||
"MIPS64": "pc", | ||
}[name], | ||
) | ||
] | ||
self.vex_archinfo = default_vex_archinfo() | ||
if memory_endness == "Iend_BE": | ||
self.vex_archinfo["endness"] = vex_endness_from_string("VexEndnessBE") | ||
|
||
def __repr__(self): | ||
return f"<PyvexArch {self.name}" | ||
|
||
@property | ||
def vex_name_small(self): | ||
return self.vex_arch[7:].lower() | ||
|
||
def translate_register_name(self, offset, size=None): | ||
for (arch, reg), offset2 in guest_offsets.items(): | ||
if arch == self.vex_name_small and offset2 == offset: | ||
return reg | ||
return None | ||
|
||
def get_register_offset(self, name: str) -> int: | ||
return guest_offsets[(self.vex_name_small, name)] | ||
|
||
|
||
ARCH_X86 = PyvexArch("X86", 32, "Iend_LE") | ||
ARCH_AMD64 = PyvexArch("AMD64", 64, "Iend_LE") | ||
ARCH_ARM_LE = PyvexArch("ARM", 32, "Iend_LE") | ||
ARCH_ARM_BE = PyvexArch("ARM", 32, "Iend_LE") | ||
ARCH_ARM64_LE = PyvexArch("AArch64", 64, "Iend_LE") | ||
ARCH_ARM64_BE = PyvexArch("AArch64", 64, "Iend_BE") | ||
ARCH_PPC32 = PyvexArch("PPC32", 32, "Iend_BE") | ||
ARCH_PPC64_BE = PyvexArch("PPC64", 64, "Iend_BE") | ||
ARCH_PPC64_LE = PyvexArch("PPC64", 64, "Iend_LE") | ||
ARCH_S390X = PyvexArch("S390X", 64, "Iend_BE") | ||
ARCH_MIPS32_BE = PyvexArch("MIPS32", 32, "Iend_BE") | ||
ARCH_MIPS32_LE = PyvexArch("MIPS32", 32, "Iend_LE") | ||
ARCH_MIPS64_BE = PyvexArch("MIPS64", 64, "Iend_BE") | ||
ARCH_MIPS64_LE = PyvexArch("MIPS64", 64, "Iend_LE") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters