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
KittyArm64 Namespace Reference

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

Enumerations

enum class  EZeroRegOrStackPointer { ZeroRegister , StackPointer }
 What register index 31 means in a given instruction field. More...

Functions

int64_t signExtend (uint32_t val, int bits)
 Sign-extends a 32-bit unsigned integer to a 64-bit signed integer.
std::string xRegName (unsigned reg, EZeroRegOrStackPointer at31)
 Returns the name of an ARM64 general-purpose X-register.
std::string wRegName (unsigned reg, EZeroRegOrStackPointer at31)
 Returns the name of an ARM64 general-purpose W-register.
int resolveRegIndex (unsigned reg, EZeroRegOrStackPointer at31)
 Resolves a raw 5-bit encoded register field into a trackable index, without naming it.
int regIndex (const std::string &name)
 Inverse of xRegName()/wRegName(): 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 (EKittyInsnTypeArm64 t)
 Converts an EKittyInsnTypeArm64 to a string representation.
uint8_t loadStoreWidth (EKittyInsnTypeArm64 t)
 Load/Store access width in bytes for an AArch64 instruction type.
bool isLoad (EKittyInsnTypeArm64 t)
 True when t is one of the load instruction types.
bool isStore (EKittyInsnTypeArm64 t)
 True when t is one of the store instruction types.
EKittyInsnTypeArm64 decodeInsnType (uint32_t instr)
 Decodes type of an ARM64 instruction.
KittyInsnArm64 decodeInsn (uint32_t instr, uint64_t address=0)
 Decodes an ARM64 instruction.

Variables

constexpr uint32_t kInstructionStride = 4
constexpr int kNumGPRegisters = 32

Detailed Description

Namespace containing utility functions for ARM64 instructions.

This namespace provides utility functions for decoding ARM64 instructions,

Enumeration Type Documentation

◆ EZeroRegOrStackPointer

What register index 31 means in a given instruction field.

AArch64 overloads register 31: in most contexts it is the zero register (XZR/WZR, reads as 0 and discards writes), but in the "add/subtract (immediate)" instruction class it is SP in both the Rd and Rn fields - there is no "ADD XZR, ..." immediate form. Which one applies is a property of the specific instruction and field being decoded, not of whether the field happens to be the "first" or "second" operand, so it must be passed explicitly by each call site rather than guessed from position.

Enumerator
ZeroRegister 

register 31 denotes XZR/WZR

StackPointer 

register 31 denotes SP

Function Documentation

◆ branchCondName()

std::string KittyArm64::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()

KittyInsnArm64 KittyArm64::decodeInsn ( uint32_t instr,
uint64_t address = 0 )

Decodes an ARM64 instruction.

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

◆ decodeInsnType()

EKittyInsnTypeArm64 KittyArm64::decodeInsnType ( uint32_t instr)

Decodes type of an ARM64 instruction.

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

◆ isLoad()

bool KittyArm64::isLoad ( EKittyInsnTypeArm64 t)

True when t is one of the load instruction types.

Includes the pre-indexed, post-indexed and literal forms. A load missing from here is not merely unrecorded: a consumer that models only what it recognises leaves the destination register holding a stale tracked value.

Parameters
tThe instruction type to query.

◆ isStore()

bool KittyArm64::isStore ( EKittyInsnTypeArm64 t)

True when t is one of the store instruction types.

Parameters
tThe instruction type to query.

◆ loadStoreWidth()

uint8_t KittyArm64::loadStoreWidth ( EKittyInsnTypeArm64 t)

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

Covers the pre-indexed, post-indexed, unscaled and literal forms as well as the plain ones: the type is the only thing that carries the width, so a form missing from here reports the wrong size rather than no size.

Reports 0 for anything that is not a load or store, matching the ARM32 twin: width is non-zero exactly for the types isLoad/isStore accept, so a caller never has to check those first to get a trustworthy answer.

Parameters
tThe instruction type to query.
Returns
1/2/4/8 for the byte/halfword/word/doubleword forms; 0 for a type that is not a load or store at all.

◆ regIndex()

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

Inverse of xRegName()/wRegName(): maps a decoded register name back to its index.

Parameters
nameRegister name as produced by xRegName()/wRegName() - "X0".."X30"/ "W0".."W30", "SP", or "XZR"/"WZR".
Returns
The register index (0-31), or -1 for a name that does not denote a trackable base - notably XZR/WZR, since the zero register never holds one.

◆ resolveRegIndex()

int KittyArm64::resolveRegIndex ( unsigned reg,
EZeroRegOrStackPointer at31 )
inline

Resolves a raw 5-bit encoded register field into a trackable index, without naming it.

Not a parse - unlike regIndex(), which recovers an index from a rendered name, this takes the hardware field straight from the instruction word and applies the same register-31 business rule xRegName()/wRegName() use to name it, so regIndex(xRegName(reg, at31)) == resolveRegIndex(reg, at31) by construction. That is what the analyzer calls: formatting a 5-bit field as "X3" only to parse it back is most of what a decode used to cost.

Returns
0-31, or -1 for the zero register, which never holds a base.

◆ signExtend()

int64_t KittyArm64::signExtend ( uint32_t val,
int bits )
inline

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

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

◆ typeToString()

std::string KittyArm64::typeToString ( EKittyInsnTypeArm64 t)

Converts an EKittyInsnTypeArm64 to a string representation.

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

Variable Documentation

◆ kInstructionStride

uint32_t KittyArm64::kInstructionStride = 4
constexpr

AArch64 instruction size. Fixed at 4 bytes for every A64 encoding, which is what lets a linear sweep step without decoding. The one source of truth for anything stepping through A64 code.

◆ kNumGPRegisters

int KittyArm64::kNumGPRegisters = 32
constexpr

AArch64 general-purpose register count: X0-X30 plus SP/XZR at index 31. The one source of truth for register-array sizing and regIndex's bound check, so the two cannot drift apart.