emulator ¤
Emulation assistance from Unicorn.
Classes:
Functions:
-
parse_consts
–Unicorn "consts" is a python module consisting of a variable definition
-
create_reg_to_const_map
– -
debug
–
Attributes:
-
arch_to_UC
– -
arch_to_UC_consts
– -
arch_to_reg_const_map
– -
enable_virtual_tlb
– -
DEBUG
– -
arch_to_SYSCALL
– -
ARM_BANNED_INSTRUCTIONS
– -
BANNED_INSTRUCTIONS
– -
blacklisted_regs
–e = pwndbg.emu.emulator.Emulator()
arch_to_UC module-attribute
¤
arch_to_UC = {
"i386": UC_ARCH_X86,
"x86-64": UC_ARCH_X86,
"mips": UC_ARCH_MIPS,
"sparc": UC_ARCH_SPARC,
"arm": UC_ARCH_ARM,
"armcm": UC_ARCH_ARM,
"aarch64": UC_ARCH_ARM64,
"rv32": UC_ARCH_RISCV,
"rv64": UC_ARCH_RISCV,
"s390x": UC_ARCH_S390X,
}
arch_to_UC_consts module-attribute
¤
arch_to_UC_consts = {
"i386": parse_consts(x86_const),
"x86-64": parse_consts(x86_const),
"mips": parse_consts(mips_const),
"sparc": parse_consts(sparc_const),
"arm": parse_consts(arm_const),
"armcm": parse_consts(arm_const),
"aarch64": parse_consts(arm64_const),
"rv32": parse_consts(riscv_const),
"rv64": parse_consts(riscv_const),
"s390x": parse_consts(s390x_const),
}
arch_to_reg_const_map module-attribute
¤
arch_to_reg_const_map = {
"i386": create_reg_to_const_map(arch_to_UC_consts["i386"]),
"x86-64": create_reg_to_const_map(
arch_to_UC_consts["x86-64"],
{"FSBASE": UC_X86_REG_FS_BASE, "GSBASE": UC_X86_REG_GS_BASE},
),
"mips": create_reg_to_const_map(arch_to_UC_consts["mips"]),
"sparc": create_reg_to_const_map(arch_to_UC_consts["sparc"]),
"arm": create_reg_to_const_map(arch_to_UC_consts["arm"]),
"armcm": create_reg_to_const_map(arch_to_UC_consts["armcm"]),
"aarch64": create_reg_to_const_map(
arch_to_UC_consts["aarch64"], {"CPSR": UC_ARM64_REG_NZCV}
),
"rv32": create_reg_to_const_map(arch_to_UC_consts["rv32"]),
"rv64": create_reg_to_const_map(arch_to_UC_consts["rv64"]),
"s390x": create_reg_to_const_map(arch_to_UC_consts["s390x"]),
}
arch_to_SYSCALL module-attribute
¤
arch_to_SYSCALL = {
UC_ARCH_X86: [
X86_INS_SYSCALL,
X86_INS_SYSENTER,
X86_INS_SYSEXIT,
X86_INS_SYSRET,
X86_INS_IRET,
X86_INS_IRETD,
X86_INS_IRETQ,
X86_INS_INT,
X86_INS_INT1,
X86_INS_INT3,
],
UC_ARCH_MIPS: [MIPS_INS_SYSCALL],
UC_ARCH_SPARC: [SPARC_INS_T],
UC_ARCH_ARM: [ARM_INS_SVC],
UC_ARCH_ARM64: [AARCH64_INS_SVC],
UC_ARCH_PPC: [PPC_INS_SC],
UC_ARCH_RISCV: [RISCV_INS_ECALL],
}
ARM_BANNED_INSTRUCTIONS module-attribute
¤
BANNED_INSTRUCTIONS module-attribute
¤
BANNED_INSTRUCTIONS = {
"mips": {MIPS_INS_RDHWR},
"arm": ARM_BANNED_INSTRUCTIONS,
"armcm": ARM_BANNED_INSTRUCTIONS,
"aarch64": {AARCH64_INS_MRS},
}
blacklisted_regs module-attribute
¤
e = pwndbg.emu.emulator.Emulator() e.until_jump()
InstructionExecutedResult ¤
Emulator ¤
Methods:
-
read_register
– -
read_memory
– -
telescope
– -
format_telescope
– -
format_telescope_list
– -
telescope_enhance
– -
memory_read_string
– -
__getattr__
– -
update_pc
– -
read_thumb_bit
–Return 0 or 1, representing the status of the Thumb bit in the current Arm architecture
-
get_uc_mode
–Retrieve the mode used by Unicorn for the current architecture.
-
map_page
– -
hook_mem_invalid
– -
hook_intr
–We never want to emulate through an interrupt. Just stop.
-
get_reg_enum
–Returns the Unicorn Emulator enum code for the named register.
-
hook_add
– -
hook_del
– -
emu_start
– -
emu_stop
– -
emulate_with_hook
– -
mem_read
– -
until_jump
–Emulates instructions starting at the specified address until the
-
until_jump_hook_code
– -
until_call
– -
until_syscall
–Emulates instructions starting at the specified address until the program
-
until_syscall_hook_code
– -
single_step
–Steps one instruction.
-
single_step_iter
– -
single_step_hook_code
– -
dumpregs
– -
trace_hook
– -
__repr__
–
Attributes:
-
arch
– -
const_regs
– -
uc_mode
– -
uc
– -
regs
(RegisterSet
) – -
valid
– -
last_pc
– -
last_single_step_result
– -
last_step_succeeded
(bool
) –
last_single_step_result instance-attribute
¤
last_single_step_result = InstructionExecutedResult(None, None)
format_telescope_list ¤
telescope_enhance ¤
memory_read_string ¤
read_thumb_bit ¤
Return 0 or 1, representing the status of the Thumb bit in the current Arm architecture
This reads from the emulator itself, meaning this can be read to determine a state transitions between non-Thumb and Thumb mode
Return None if the Thumb bit is not relevent to the current architecture
Mimics the read_thumb_bit
function defined in aglib/arch.py
hook_intr ¤
We never want to emulate through an interrupt. Just stop.
get_reg_enum ¤
Returns the Unicorn Emulator enum code for the named register.
Also supports general registers like 'sp' and 'pc'.
until_jump ¤
Emulates instructions starting at the specified address until the program counter is set to an address which does not linearly follow the previously-emulated instruction.
Parameters:
-
pc
(int
, default:None
) –Address to start at. If
None
, uses the current instruction.
Return
Returns a tuple containing the address of the jump instruction, and its target in the format (address, target).
If emulation is forced to stop (e.g., because of a syscall or invalid memory access) then address is the instruction which could not be emulated through, and target will be None.
Notes
This routine does not consider 'call $+5'
until_jump_hook_code ¤
until_syscall ¤
Emulates instructions starting at the specified address until the program counter points at a syscall instruction (int 0x80, svc, etc.).
single_step ¤
Steps one instruction.
Yields:
-
int
–Each iteration, yields a tuple of (address_just_executed, instruction_size).
-
int
–Returns (None, None) upon failure to execute the instruction
single_step_hook_code ¤
parse_consts ¤
Unicorn "consts" is a python module consisting of a variable definition for each known entity. We repack it here as a dict for performance.
Maps "UC_*" -> integer value of the constant
create_reg_to_const_map ¤
create_reg_to_const_map(
base_consts: dict[str, int], additional_mapping: dict[str, int] = None
) -> dict[str, int]