KittyMemoryEx 1.0.0
Dedicated library for runtime code patching, memory scanning, tracing, injection and some more useful memory utilities. works for both Android and Linux
Loading...
Searching...
No Matches
KittyArm32 Namespace Reference

Namespace containing utility functions for ARM32 instructions. More...

Functions

int32_t signExtend (uint32_t val, int bits)
 Sign-extends a 32-bit unsigned integer to a 32-bit signed integer.
std::string regName (unsigned r)
 Returns the name of an ARM32 general-purpose register.
int regIndex (const std::string &name)
 Inverse of regName(): maps a decoded register name back to its index.
std::string branchCondName (uint32_t cond)
 Returns the name of a conditional execution flag.
std::string typeToString (EKittyInsnTypeArm32 t)
 Converts an EKittyInsnTypeArm32 to a string representation.
uint8_t loadStoreWidth (EKittyInsnTypeArm32 t)
 Load/Store access width in bytes for an ARM32 instruction type.
bool isLoad (EKittyInsnTypeArm32 t)
 True when t is one of the load instruction types.
bool isStore (EKittyInsnTypeArm32 t)
 True when t is one of the store instruction types.
EKittyInsnTypeArm32 decodeInsnType (uint32_t instr)
 Decodes type of an ARM32 instruction.
KittyInsnArm32 decodeInsn (uint32_t instr, uint32_t address=0)
 Decodes an ARM32 instruction.

Variables

constexpr uint32_t kInstructionStride = 4
constexpr uint32_t kPcBias = 8
constexpr int kLinkRegister = 14
constexpr int kNumGPRegisters = 15

Detailed Description

Namespace containing utility functions for ARM32 instructions.

This namespace provides utility functions for decoding ARM32 instructions,

Function Documentation

◆ branchCondName()

std::string KittyArm32::branchCondName ( uint32_t cond)
inline

Returns the name of a conditional execution flag.

Parameters
condThe conditional execution flag value (0-15).
Returns
The name of the conditional execution flag as a string.

◆ decodeInsn()

KittyInsnArm32 KittyArm32::decodeInsn ( uint32_t instr,
uint32_t address = 0 )

Decodes an ARM32 instruction.

Parameters
instrThe 32-bit instruction value.
addressThe address of the instruction (optional).
Returns
The details of the decoded instruction.

◆ decodeInsnType()

EKittyInsnTypeArm32 KittyArm32::decodeInsnType ( uint32_t instr)

Decodes type of an ARM32 instruction.

Parameters
instrThe 32-bit instruction value.
Returns
The type of the instruction.

◆ isLoad()

bool KittyArm32::isLoad ( EKittyInsnTypeArm32 t)

True when t is one of the load instruction types.

Parameters
tThe instruction type to query.

◆ isStore()

bool KittyArm32::isStore ( EKittyInsnTypeArm32 t)

True when t is one of the store instruction types.

Parameters
tThe instruction type to query.

◆ loadStoreWidth()

uint8_t KittyArm32::loadStoreWidth ( EKittyInsnTypeArm32 t)

Load/Store access width in bytes for an ARM32 instruction type.

Parameters
tThe instruction type to query.
Returns
1 for the byte forms, 2 for the halfword forms, 4 for everything else (word loads/stores, and LDR_LITERAL); 0 for a type that is not a load or store at all.

◆ regIndex()

int KittyArm32::regIndex ( const std::string & name)

Inverse of regName(): maps a decoded register name back to its index.

Parameters
nameRegister name as produced by regName() - "sp"/"lr"/"pc" for 13/14/15, "r0".."r15" otherwise.
Returns
The register index (0-15), or -1 for anything unrecognised. Note that 15 (PC) is a valid answer here while being one past kNumGPRegisters: PC is nameable but not trackable, so a caller sizing an array by kNumGPRegisters must bound-check the result rather than index with it directly.

◆ regName()

std::string KittyArm32::regName ( unsigned r)
inline

Returns the name of an ARM32 general-purpose register.

Parameters
rThe register number (0-15).
Returns
The name of the register as a string.

◆ signExtend()

int32_t KittyArm32::signExtend ( uint32_t val,
int bits )
inline

Sign-extends a 32-bit unsigned integer to a 32-bit signed integer.

Parameters
valThe input 32-bit unsigned integer.
bitsThe number of bits to sign-extend.
Returns
The sign-extended 32-bit signed integer.

◆ typeToString()

std::string KittyArm32::typeToString ( EKittyInsnTypeArm32 t)

Converts an EKittyInsnTypeArm32 to a string representation.

Parameters
tThe instruction type to convert.
Returns
The string representation of the instruction type.

Variable Documentation

◆ kInstructionStride

uint32_t KittyArm32::kInstructionStride = 4
constexpr

A32 instruction size. Fixed at 4 bytes, which is what makes a linear sweep possible at all - and is exactly the assumption that does not hold for Thumb/Thumb-2, whose mixed 16/32-bit encoding this decoder does not handle. The one source of truth for anything stepping through A32 code.

◆ kLinkRegister

int KittyArm32::kLinkRegister = 14
constexpr

R14, the link register: BX LR is how an A32 function returns, so a consumer looking for returns has to name this register.

◆ kNumGPRegisters

int KittyArm32::kNumGPRegisters = 15
constexpr

ARM32 general-purpose register count: R0-R14. R15 (PC) is deliberately excluded - every consumer of this constant tracks live register state, and PC's value changes every instruction rather than being something register-tracking can hold, so it is never a valid array index here. The one source of truth for register-array sizing and regIndex's bound check.

◆ kPcBias

uint32_t KittyArm32::kPcBias = 8
constexpr

What A32 reads the PC as: the instruction's own address plus 8, an artefact of the original three-stage pipeline that the architecture keeps for compatibility. Every PC-relative form here is biased by it, so the number lives in one place rather than as a literal 8 at each use.