instruction ¤
Classes:
-
InstructionCondition
– -
SplitType
– -
PwndbgInstruction
– -
PwndbgInstructionImpl
– -
EnhancedOperand
– -
ManualPwndbgInstruction
–
Functions:
Attributes:
-
UNCONDITIONAL_JUMP_INSTRUCTIONS
(dict[int, set[int]]
) – -
BRANCH_AND_LINK_INSTRUCTIONS
(dict[int, set[int]]
) – -
GENERIC_UNCONDITIONAL_JUMP_GROUPS
– -
GENERIC_JUMP_GROUPS
– -
ALL_JUMP_GROUPS
– -
FORWARD_JUMP_GROUP
– -
CAPSTONE_ARCH_MAPPING_STRING
–
UNCONDITIONAL_JUMP_INSTRUCTIONS module-attribute
¤
UNCONDITIONAL_JUMP_INSTRUCTIONS: dict[int, set[int]] = {
CS_ARCH_X86: {X86_INS_JMP},
CS_ARCH_MIPS: {
MIPS_INS_J,
MIPS_INS_JR,
MIPS_INS_JAL,
MIPS_INS_JALR,
MIPS_INS_JALR_HB,
MIPS_INS_BAL,
MIPS_INS_ALIAS_BAL,
MIPS_INS_B,
MIPS_INS_ALIAS_B,
},
CS_ARCH_SPARC: {SPARC_INS_JMP, SPARC_INS_JMPL},
CS_ARCH_ARM: {ARM_INS_TBB, ARM_INS_TBH},
CS_ARCH_AARCH64: {AARCH64_INS_BL, AARCH64_INS_BLR, AARCH64_INS_BR},
CS_ARCH_RISCV: {
RISCV_INS_JAL,
RISCV_INS_JALR,
RISCV_INS_C_JAL,
RISCV_INS_C_JALR,
RISCV_INS_C_J,
RISCV_INS_C_JR,
},
CS_ARCH_PPC: {PPC_INS_B, PPC_INS_BA, PPC_INS_BL, PPC_INS_BLA},
CS_ARCH_SYSTEMZ: {SYSTEMZ_INS_B, SYSTEMZ_INS_BAL, SYSTEMZ_INS_BALR},
CS_ARCH_LOONGARCH: {
LOONGARCH_INS_B,
LOONGARCH_INS_BL,
LOONGARCH_INS_JIRL,
LOONGARCH_INS_ALIAS_JR,
},
}
BRANCH_AND_LINK_INSTRUCTIONS module-attribute
¤
GENERIC_UNCONDITIONAL_JUMP_GROUPS module-attribute
¤
ALL_JUMP_GROUPS module-attribute
¤
ALL_JUMP_GROUPS = GENERIC_JUMP_GROUPS | GENERIC_UNCONDITIONAL_JUMP_GROUPS
CAPSTONE_ARCH_MAPPING_STRING module-attribute
¤
CAPSTONE_ARCH_MAPPING_STRING = {
CS_ARCH_ARM: "arm",
CS_ARCH_AARCH64: "aarch64",
CS_ARCH_X86: "x86",
CS_ARCH_PPC: "powerpc",
CS_ARCH_MIPS: "mips",
CS_ARCH_SPARC: "sparc",
CS_ARCH_RISCV: "RISCV",
CS_ARCH_SYSTEMZ: "s390x",
CS_ARCH_LOONGARCH: "loongarch",
}
InstructionCondition ¤
SplitType ¤
Bases: Enum
Attributes:
PwndbgInstruction ¤
Bases: Protocol
Methods:
Attributes:
-
cs_insn
(CsInsn
) – -
address
(int
) – -
size
(int
) – -
mnemonic
(str
) – -
op_str
(str
) – -
groups
(set[int]
) – -
id
(int
) – -
operands
(list[EnhancedOperand]
) – -
asm_string
(str
) – -
next
(int
) – -
target
(int
) – -
target_string
(str | None
) – -
target_const
(bool | None
) – -
condition
(InstructionCondition
) – -
declare_conditional
(bool | None
) – -
declare_is_unconditional_jump
(bool
) – -
force_unconditional_jump_target
(bool
) – -
annotation
(str | None
) – -
annotation_padding
(int | None
) – -
syscall
(int | None
) – -
syscall_name
(str | None
) – -
causes_branch_delay
(bool
) – -
split
(SplitType
) – -
emulated
(bool
) – -
call_like
(bool
) – -
jump_like
(bool
) – -
has_jump_target
(bool
) – -
is_conditional_jump
(bool
) – -
is_unconditional_jump
(bool
) – -
is_conditional_jump_taken
(bool
) – -
bytes
(bytearray
) –
PwndbgInstructionImpl ¤
Bases: PwndbgInstruction
Methods:
-
op_find
– -
op_count
–Return number of operands having same operand Capstone type 'op_type'
-
__repr__
–
Attributes:
-
cs_insn
(CsInsn
) –The underlying Capstone instruction object.
-
address
(int
) – -
size
(int
) –Length of the instruction
-
mnemonic
(str
) –Ex: 'MOV'
-
op_str
(str
) –Ex: 'RAX, RDX'
-
groups
(set[int]
) –Capstone instruction groups that we belong to.
-
id
(int
) –The underlying Capstone ID for the instruction
-
operands
(list[EnhancedOperand]
) – -
asm_string
(str
) –The full string representing the instruction -
mov rdi, rsp
with appropriate padding. -
next
(int
) –This is the address that the instruction pointer will be set to after using the "nexti" GDB command.
-
target
(int
) –This is target of instructions that change the PC, regardless of if it's conditional or not,
-
target_string
(str | None
) –String representation of the target address.
-
target_const
(bool | None
) –Whether the target is a constant expression
-
condition
(InstructionCondition
) –Does the condition that the instruction checks for pass?
-
declare_conditional
(bool | None
) –This field is used to declare if the instruction is a conditional instruction.
-
declare_is_unconditional_jump
(bool
) –This field is used to declare that this instruction is an unconditional jump.
-
force_unconditional_jump_target
(bool
) –This asserts that the .target attribute is the real target of the instruction.
-
annotation
(str | None
) –The string is set in the "DisassemblyAssistant.enhance" function.
-
annotation_padding
(int | None
) –The left adjustment padding that was used to previously print this.
-
syscall
(int | None
) –The syscall number for this instruction, if it is a syscall. Otherwise None.
-
syscall_name
(str | None
) –The syscall name as a string
-
causes_branch_delay
(bool
) –Whether or not this instruction has a single branch delay slot
-
split
(SplitType
) –The type of split in the disasm display this instruction causes:
-
emulated
(bool
) –If the enhancement successfully used emulation for this instruction
-
call_like
(bool
) –True if this is a call-like instruction, meaning either it's a CALL or a branch and link.
-
jump_like
(bool
) –True if this instruction is "jump-like", such as a JUMP, CALL, or RET.
-
has_jump_target
(bool
) –True if we have determined that this instruction can explicitly change the program counter, and
-
is_conditional_jump
(bool
) –True if this instruction can change the program counter conditionally.
-
is_unconditional_jump
(bool
) –True if we know the instruction can change the program counter, and does so unconditionally.
-
is_conditional_jump_taken
(bool
) –True if this is a conditional jump, and we predicted that we will take the jump
-
bytes
(bytearray
) –Raw machine instruction bytes
cs_insn instance-attribute
¤
The underlying Capstone instruction object. Only the enhancement code should access the 'cs_insn' property
groups instance-attribute
¤
Capstone instruction groups that we belong to. Groups that apply to all architectures: CS_GRP_INVALID | CS_GRP_JUMP | CS_GRP_CALL | CS_GRP_RET | CS_GRP_INT | CS_GRP_IRET | CS_GRP_PRIVILEGE | CS_GRP_BRANCH_RELATIVE
id instance-attribute
¤
The underlying Capstone ID for the instruction If it's an alias, use the id of the alias
Examples: X86_INS_JMP, X86_INS_CALL, RISCV_INS_C_JAL
operands instance-attribute
¤
operands: list[EnhancedOperand] = [EnhancedOperand(op) for op in operands]
asm_string instance-attribute
¤
The full string representing the instruction - mov rdi, rsp
with appropriate padding.
This is syntax highlighted during enhancement.
This is additionally modified during enhancement for the purposes of replacing immediate values with their corresponding symbols
next instance-attribute
¤
This is the address that the instruction pointer will be set to after using the "nexti" GDB command. This means it is the address of the next instruction to be executed in all cases except "call" instructions.
Typically, it is self.address + self.size
(the next instruction in memory)
If it is a jump and we know it is taken, then it is the value of the jump target.
Not set to "call" instruction targets, to indicate we will eventually (probably) return to this address
target instance-attribute
¤
This is target of instructions that change the PC, regardless of if it's conditional or not, and whether or not we take the jump. This includes "call" and all other instructions that set the PC
If the instruction is not one that changes the PC, target is set to "next"
target_string instance-attribute
¤
String representation of the target address.
Colorized symbol if a symbol exists at address, else colorized address
target_const instance-attribute
¤
Whether the target is a constant expression
condition instance-attribute
¤
condition: InstructionCondition = UNDETERMINED
Does the condition that the instruction checks for pass?
For example, "JNE" jumps if Zero Flag is 0, else it does nothing. "CMOVA" conditionally performs a move depending on a flag. See 'condition' function in pwndbg.aglib.disasm.x86 for example on setting this.
UNDETERMINED if we cannot reason about the condition, or if the instruction always executes unconditionally (most instructions).
TRUE if the instruction has a conditional action, and we determine it is taken.
FALSE if the instruction has a conditional action, and we know it is not taken.
declare_conditional instance-attribute
¤
This field is used to declare if the instruction is a conditional instruction. In most cases, we can determine this purely based on the instruction ID, and this field is irrelevent. However, in some arches, like Arm, the same instruction can be made conditional by certain instruction attributes. Ex: Arm, bls
instruction. This is encoded as a b
under the code, with an additional condition code field. In this case, sometimes a b
instruction is unconditional (always branches), in other cases it is conditional. We use this field to disambiguate these cases.
True if we manually determine this instruction is a conditional instruction False if it's not a conditional instruction None if we don't have a determination (most cases)
declare_is_unconditional_jump instance-attribute
¤
This field is used to declare that this instruction is an unconditional jump. Most of the time, we depend on Capstone groups to check for jump instructions. However, some instructions become branches depending on the operands, such as Arm add
, sub
, ldr
, pop
, where PC is the destination register
In these cases, we want to forcefully state that this instruction mutates the PC, so we set this attribute to True.
This helps in two cases: 1. Disassembly splits 2. Instructions like stepuntilasm
work better, as they detect these as branches to stop at.
force_unconditional_jump_target instance-attribute
¤
This asserts that the .target attribute is the real target of the instruction. This is only relevent in the edge case that the target is the next instruction in memory (address + size). The normal check for "target" checks that the target is NOT the next address in memory, and here we can assert that even if that is the case, we know that the jump really does just go to where self.target is.
annotation instance-attribute
¤
The string is set in the "DisassemblyAssistant.enhance" function. It is used in the disasm print view to add context to the instruction, mostly operand value. This string is not used for all cases - if the instruction is a call or a jump, the 'target'. variables is used instead. See 'pwndbg.color.disasm.instruction()' for specific usage.
annotation_padding instance-attribute
¤
The left adjustment padding that was used to previously print this. We retain it so the output is consistent between prints
syscall instance-attribute
¤
The syscall number for this instruction, if it is a syscall. Otherwise None.
syscall_name instance-attribute
¤
The syscall name as a string
Ex: "openat", "read"
causes_branch_delay instance-attribute
¤
Whether or not this instruction has a single branch delay slot
split instance-attribute
¤
The type of split in the disasm display this instruction causes:
NO_SPLIT - no extra spacing between this and the next instruction
BRANCH_TAKEN - a newline with an arrow pointing down
BRANCH_NOT_TAKEN - an empty newline
emulated instance-attribute
¤
If the enhancement successfully used emulation for this instruction
call_like property
¤
True if this is a call-like instruction, meaning either it's a CALL or a branch and link.
Checking for the CS_GRP_CALL is insufficient, as there are many "branch and link" instructions that are not labeled as a call
jump_like property
¤
True if this instruction is "jump-like", such as a JUMP, CALL, or RET. Basically, the PC is set to some target by means of this instruction.
It may still be a conditional jump - this property does not indicate whether the jump is taken or not.
has_jump_target property
¤
True if we have determined that this instruction can explicitly change the program counter, and we have determined the jump target.
Edge case - the jump target MAY be the next address in memory - so we check force_unconditional_jump_target
is_conditional_jump property
¤
True if this instruction can change the program counter conditionally.
This is used, in part, to determine if the instruction deserves a "checkmark" in the disasm view.
This does not imply that we have resolved the .target
is_unconditional_jump property
¤
True if we know the instruction can change the program counter, and does so unconditionally.
This includes things like RET, CALL, and JMP (in x86).
This property is used in enhancement to determine certain codepaths when resolving .next for this instruction.
This does not imply that we have resolved the .target
is_conditional_jump_taken property
¤
True if this is a conditional jump, and we predicted that we will take the jump
op_find ¤
op_find(op_type: int, position: int) -> EnhancedOperand
op_count ¤
Return number of operands having same operand Capstone type 'op_type'
EnhancedOperand ¤
Methods:
-
__repr__
–
Attributes:
-
cs_op
(Any
) –Underlying Capstone operand. Takes on a different value depending on the architecture.
-
before_value
(int | None
) –The value of the operand before the instruction executes.
-
after_value
(int | None
) –The value of the operand after the instruction executes.
-
before_value_resolved
(int | None
) –The 'resolved' value of the operand that is actually used in the instruction logic, before the instruction executes.
-
before_value_no_modifiers
(int | None
) –This is a special field used in some architectures that allow operand modifiers, such as shifts and extends in Arm.
-
after_value_resolved
(int | None
) –The 'resolved' value of the operand after the instruction executes.
-
str
(str | None
) –String representing the operand
-
symbol
(str | None
) –Colorized symbol name for this operand, if .before_value is set and symbol exists, else None.
-
type
(int
) –CS_OP_REG | CS_OP_MEM | CS_OP_IMM | CS_OP_INVALID | CS_OP_FP
-
reg
(int
) –The underlying Capstone ID for the register
-
imm
(int
) –The immediate value of the operand (if applicable)
-
mem
(Any
) –Return the underlying Capstone mem object (if applicable)
cs_op instance-attribute
¤
Underlying Capstone operand. Takes on a different value depending on the architecture.
x86 = capstone.x86.X86Op, arm = capstone.arm.ArmOp, mips = capstone.mips.MipsOp
before_value instance-attribute
¤
The value of the operand before the instruction executes. This is set only if the operand value can be reasoned about.
after_value instance-attribute
¤
The value of the operand after the instruction executes. Only set when using emulation.
before_value_resolved instance-attribute
¤
The 'resolved' value of the operand that is actually used in the instruction logic, before the instruction executes. This is the same as before_value if it's not a memory operand, in which cases it's the dereferenced value.
Helpful for cases like cmp byte ptr [rip + 0x166669], 0
, where first operand could be a register or a memory value to dereference, and we want the actual value used.
before_value_no_modifiers instance-attribute
¤
This is a special field used in some architectures that allow operand modifiers, such as shifts and extends in Arm. Capstone bundles the modifier with the operand, and when we are resolving concrete operand values, we apply the modifier. However, in some annotations we need to un-modified raw register value, which is what this field is for.
after_value_resolved instance-attribute
¤
The 'resolved' value of the operand after the instruction executes.
str instance-attribute
¤
String representing the operand
Ex: "RAX", or "[0x7fffffffd9e8]". None if value cannot be determined.
symbol instance-attribute
¤
Colorized symbol name for this operand, if .before_value is set and symbol exists, else None.
ManualPwndbgInstruction ¤
Bases: PwndbgInstruction
GDB/LLDB's built-in disassemblers.
Instances of this class do not go through the 'enhancement' process due to lacking important information provided by Capstone. As a result of this, some of the methods raise NotImplementedError, because if they are called it indicates a bug elsewhere in the codebase.
Methods:
Attributes:
-
cs_insn
(CsInsn
) – -
address
– -
size
– -
mnemonic
– -
op_str
– -
groups
– -
id
– -
operands
– -
asm_string
– -
next
– -
target
– -
target_string
– -
target_const
– -
condition
– -
declare_conditional
– -
declare_is_unconditional_jump
– -
force_unconditional_jump_target
– -
annotation
– -
annotation_padding
– -
syscall
– -
syscall_name
– -
causes_branch_delay
– -
split
– -
emulated
– -
bytes
(bytearray
) – -
call_like
(bool
) – -
jump_like
(bool
) – -
has_jump_target
(bool
) – -
is_conditional_jump
(bool
) – -
is_unconditional_jump
(bool
) – -
is_conditional_jump_taken
(bool
) –
boolean_to_instruction_condition ¤
boolean_to_instruction_condition(condition: bool) -> InstructionCondition