decompiler
1.0.0
|
Classes for specifying addresses and other low-level constants. More...
#include "space.hh"
Classes | |
class | ghidra::Address |
A low-level machine address for labelling bytes and data. More... | |
class | ghidra::SeqNum |
A class for uniquely labelling and comparing PcodeOps. More... | |
class | ghidra::Range |
A contiguous range of bytes in some address space. More... | |
class | ghidra::RangeProperties |
A partially parsed description of a Range. More... | |
class | ghidra::RangeList |
A disjoint set of Ranges, possibly across multiple address spaces. More... | |
Functions | |
uintb | ghidra::calc_mask (int4 size) |
Calculate a mask for a given byte size. More... | |
uintb | ghidra::pcode_right (uintb val, int4 sa) |
uintb | ghidra::pcode_left (uintb val, int4 sa) |
uintb | ghidra::minimalmask (uintb val) |
Calculate smallest mask that covers the given value. More... | |
intb | ghidra::sign_extend (intb val, int4 bit) |
Sign extend above given bit. More... | |
intb | ghidra::zero_extend (intb val, int4 bit) |
Clear all bits above given bit. More... | |
bool | ghidra::signbit_negative (uintb val, int4 size) |
Return true if the sign-bit is set. More... | |
uintb | ghidra::uintb_negate (uintb in, int4 size) |
Negate the sized value. More... | |
uintb | ghidra::sign_extend (uintb in, int4 sizein, int4 sizeout) |
Sign-extend a value between two byte sizes. More... | |
void | ghidra::byte_swap (intb &val, int4 size) |
Swap bytes in the given value. More... | |
uintb | ghidra::byte_swap (uintb val, int4 size) |
Return the given value with bytes swapped. More... | |
int4 | ghidra::leastsigbit_set (uintb val) |
Return index of least significant bit set in given value. More... | |
int4 | ghidra::mostsigbit_set (uintb val) |
Return index of most significant bit set in given value. More... | |
int4 | ghidra::popcount (uintb val) |
Return the number of one bits in the given value. More... | |
int4 | ghidra::count_leading_zeros (uintb val) |
Return the number of leading zero bits in the given value. More... | |
uintb | ghidra::coveringmask (uintb val) |
Return a mask that covers the given value. More... | |
int4 | ghidra::bit_transitions (uintb val, int4 sz) |
Calculate the number of bit transitions in the sized value. More... | |
void | ghidra::mult64to128 (uint8 *res, uint8 x, uint8 y) |
Multiply 2 unsigned 64-bit values, producing a 128-bit value. More... | |
void | ghidra::unsignedSubtract128 (uint8 *a, uint8 *b) |
Subtract (in-place) a 128-bit value from a base 128-value. More... | |
int4 | ghidra::unsignedCompare128 (uint8 *a, uint8 *b) |
Compare two unsigned 128-bit values. More... | |
int4 | ghidra::power2Divide (int4 n, uint8 divisor, uint8 &q, uint8 &r) |
Unsigned division of a power of 2 (upto 2^127) by a 64-bit divisor. More... | |
Classes for specifying addresses and other low-level constants.
All addresses are absolute and there are are no registers in CPUI. However, all addresses are prefixed with an "immutable" pointer, which can specify a separate RAM space, a register space, an i/o space etc. Thus a translation from a real machine language will typically simulate registers by placing them in their own space, separate from RAM. Indirection (i.e. pointers) must be simulated through the LOAD and STORE ops.
int4 ghidra::bit_transitions | ( | uintb | val, |
int4 | sz | ||
) |
Calculate the number of bit transitions in the sized value.
Treat val as a constant of size sz. Scanning across the bits of val return the number of transitions (from 0->1 or 1->0) If there are 2 or less transitions, this is an indication of a bit flag or a mask
val | is the given value |
sz | is the size to treat the value as |
void ghidra::byte_swap | ( | intb & | val, |
int4 | size | ||
) |
Swap bytes in the given value.
Swap the least significant size bytes in val
val | is a reference to the value to swap |
size | is the number of bytes to swap |
uintb ghidra::byte_swap | ( | uintb | val, |
int4 | size | ||
) |
Return the given value with bytes swapped.
Swap the least significant size bytes in val
val | is the value to swap |
size | is the number of bytes to swap |
|
inline |
Calculate a mask for a given byte size.
size | is the desired size in bytes |
References ghidra::calc_mask().
Referenced by ghidra::AddTreeState::AddTreeState(), ghidra::ActionStackPtrFlow::analyzeExtraPop(), ghidra::RuleCollectTerms::applyOp(), ghidra::RuleOrMask::applyOp(), ghidra::RuleNegateIdentity::applyOp(), ghidra::RuleShiftBitops::applyOp(), ghidra::RuleRightShiftAnd::applyOp(), ghidra::RulePullsubMulti::applyOp(), ghidra::RulePullsubIndirect::applyOp(), ghidra::RuleHighOrderAnd::applyOp(), ghidra::RuleAndDistribute::applyOp(), ghidra::RuleAndCommute::applyOp(), ghidra::RuleAndPiece::applyOp(), ghidra::RuleAndZext::applyOp(), ghidra::RuleAndCompare::applyOp(), ghidra::RuleDoubleShift::applyOp(), ghidra::RuleShiftCompare::applyOp(), ghidra::RuleBoolZext::applyOp(), ghidra::RuleSborrow::applyOp(), ghidra::RuleSignShift::applyOp(), ghidra::RuleTestSign::applyOp(), ghidra::RuleTransformCpool::applyOp(), ghidra::Rule2Comp2Mult::applyOp(), ghidra::RuleCarryElim::applyOp(), ghidra::RuleSub2Add::applyOp(), ghidra::RuleSubCommute::applyOp(), ghidra::RuleConcatCommute::applyOp(), ghidra::RuleShiftAnd::applyOp(), ghidra::RuleSubZext::applyOp(), ghidra::RuleSubCancel::applyOp(), ghidra::RuleHumptyOr::applyOp(), ghidra::RuleLess2Zero::applyOp(), ghidra::RuleLessEqual2Zero::applyOp(), ghidra::RuleSLess2Zero::applyOp(), ghidra::RuleEqual2Zero::applyOp(), ghidra::RuleEqual2Constant::applyOp(), ghidra::RuleMultNegOne::applyOp(), ghidra::RuleAddUnsigned::applyOp(), ghidra::RuleDivTermAdd2::applyOp(), ghidra::RuleSignDiv2::applyOp(), ghidra::RuleDivChain::applyOp(), ghidra::RuleSignForm2::applyOp(), ghidra::RuleSignNearMult::applyOp(), ghidra::RuleModOpt::applyOp(), ghidra::RuleSignMod2nOpt::applyOp(), ghidra::RuleSignMod2Opt::applyOp(), ghidra::RuleSignMod2nOpt2::applyOp(), ghidra::RuleSubvarAnd::applyOp(), ghidra::RuleSubvarSubpiece::applyOp(), ghidra::RuleSubvarCompZero::applyOp(), ghidra::RuleSubvarZext::applyOp(), ghidra::RuleSubvarSext::applyOp(), ghidra::RuleFuncPtrEncoding::applyOp(), ghidra::RuleThreeWayCompare::applyOp(), ghidra::SplitDatatype::buildInConstants(), ghidra::calc_mask(), ghidra::Funcdata::calcNZMask(), ghidra::AddrSpace::calcScaleMask(), ghidra::ActionStackPtrFlow::checkClog(), ghidra::ValueSetSolver::checkRelativeConstant(), ghidra::RuleSignMod2nOpt2::checkSignExtForm(), ghidra::CircleRange::CircleRange(), ghidra::Funcdata::collapseIntMultMult(), ghidra::RangeList::decode(), ghidra::TypeEnum::decode(), ghidra::RuleThreeWayCompare::detectThreeWay(), ghidra::Funcdata::distributeIntMultAdd(), ghidra::TypePointerRel::downChain(), ghidra::OpBehaviorIntAdd::evaluateBinary(), ghidra::OpBehaviorIntSub::evaluateBinary(), ghidra::OpBehaviorIntCarry::evaluateBinary(), ghidra::OpBehaviorIntLeft::evaluateBinary(), ghidra::OpBehaviorIntRight::evaluateBinary(), ghidra::OpBehaviorIntSright::evaluateBinary(), ghidra::OpBehaviorIntMult::evaluateBinary(), ghidra::OpBehaviorSubpiece::evaluateBinary(), ghidra::TypePointerRel::evaluateThruParent(), ghidra::Varnode::findSubpieceShadow(), ghidra::JumpTable::foldInNormalization(), ghidra::ActionDeadCode::gatherConsumedReturn(), ghidra::AliasChecker::gatherOffset(), ghidra::SplitDatatype::generateConstants(), ghidra::SleighBuilder::generateLocation(), ghidra::SleighBuilder::generatePointer(), ghidra::RuleSLess2Zero::getHiBit(), ghidra::EmulatePcodeOp::getLoadImageValue(), ghidra::EmulateSnippet::getLoadImageValue(), ghidra::TypeEnum::getMatches(), ghidra::JumpBasic::getMaxValue(), ghidra::PcodeOp::getNZMaskLocal(), ghidra::ContextDatabase::getTrackedValue(), ghidra::MemoryBank::getValue(), ghidra::EquateSymbol::isValueClose(), ghidra::ActionDeadCode::markConsumedParameters(), ghidra::TransformManager::newConstant(), ghidra::TransformManager::newSplit(), ghidra::PrintC::opPtrsub(), ghidra::FloatFormat::opTrunc(), ghidra::Funcdata::opUndoPtradd(), ghidra::TypeOpIntAdd::propagateAddPointer(), ghidra::ActionDeadCode::propagateConsumed(), ghidra::CircleRange::pullBack(), ghidra::CircleRange::pullBackBinary(), ghidra::CircleRange::pullBackUnary(), ghidra::PrintC::push_integer(), ghidra::ActionDeadCode::pushConsumed(), ghidra::PrintC::pushEquate(), ghidra::CircleRange::pushForwardBinary(), ghidra::CircleRange::pushForwardUnary(), ghidra::OpBehaviorIntAdd::recoverInputBinary(), ghidra::OpBehaviorIntSub::recoverInputBinary(), ghidra::OpBehaviorIntLeft::recoverInputBinary(), ghidra::OpBehaviorIntZext::recoverInputUnary(), ghidra::OpBehaviorIntSext::recoverInputUnary(), ghidra::Funcdata::replaceLessequal(), ghidra::SegmentedResolver::resolve(), ghidra::PcodeCacher::resolveRelatives(), ghidra::TypeFactory::setEnumValues(), ghidra::CircleRange::setFull(), ghidra::CircleRange::setNZMask(), ghidra::CircleRange::setRange(), ghidra::SubvariableFlow::setReplacement(), ghidra::MemoryBank::setValue(), ghidra::SubvariableFlow::traceBackward(), ghidra::SubvariableFlow::traceBackwardSext(), ghidra::SubvariableFlow::traceForward(), ghidra::SubvariableFlow::traceForwardSext(), ghidra::ActionLikelyTrash::traceTrash(), ghidra::Funcdata::transferVarnodeProperties(), and ghidra::zero_extend().
int4 ghidra::count_leading_zeros | ( | uintb | val | ) |
Return the number of leading zero bits in the given value.
Count the number of more significant zero bits before the most significant one bit in the representation of the given value;
val | is the given value |
uintb ghidra::coveringmask | ( | uintb | val | ) |
Return a mask that covers the given value.
Return smallest number of form 2^n-1, bigger or equal to the given value
val | is the given value |
int4 ghidra::leastsigbit_set | ( | uintb | val | ) |
Return index of least significant bit set in given value.
The least significant bit is index 0.
val | is the given value |
|
inline |
Calculate smallest mask that covers the given value.
Calculcate a mask that covers either the least significant byte, uint2, uint4, or uint8, whatever is smallest.
val | is the given value |
References ghidra::minimalmask().
Referenced by ghidra::JumpTable::foldInNormalization(), ghidra::ActionDeadCode::gatherConsumedReturn(), ghidra::ActionDeadCode::markConsumedParameters(), and ghidra::minimalmask().
int4 ghidra::mostsigbit_set | ( | uintb | val | ) |
Return index of most significant bit set in given value.
The least significant bit is index 0.
val | is the given value |
void ghidra::mult64to128 | ( | uint8 * | res, |
uint8 | x, | ||
uint8 | y | ||
) |
Multiply 2 unsigned 64-bit values, producing a 128-bit value.
TODO: Remove once we import a full multiprecision library.
res | points to the result array (2 uint8 pieces) |
x | is the first 64-bit value |
y | is the second 64-bit value |
|
inline |
Perform a CPUI_INT_LEFT on the given val
val | is the value to shift |
sa | is the number of bits to shift |
References ghidra::pcode_left().
Referenced by ghidra::RuleShiftBitops::applyOp(), ghidra::PcodeOp::getNZMaskLocal(), and ghidra::pcode_left().
|
inline |
Perform a CPUI_INT_RIGHT on the given val
val | is the value to shift |
sa | is the number of bits to shift |
References ghidra::pcode_right().
Referenced by ghidra::RuleShiftBitops::applyOp(), ghidra::PcodeOp::getNZMaskLocal(), and ghidra::pcode_right().
int4 ghidra::popcount | ( | uintb | val | ) |
Return the number of one bits in the given value.
Count the number (population) bits set.
val | is the given value |
int4 ghidra::power2Divide | ( | int4 | n, |
uint8 | divisor, | ||
uint8 & | q, | ||
uint8 & | r | ||
) |
Unsigned division of a power of 2 (upto 2^127) by a 64-bit divisor.
The result must be less than 2^64. The remainder is calculated.
n | is the power of 2 for the numerand |
divisor | is the 64-bit divisor |
q | is the passed back 64-bit quotient |
r | is the passed back 64-bit remainder |
|
inline |
Sign extend above given bit.
Sign extend val starting at bit
val | is the value to be sign-extended |
bit | is the index of the bit to extend from (0=least significant bit) |
uintb ghidra::sign_extend | ( | uintb | in, |
int4 | sizein, | ||
int4 | sizeout | ||
) |
Sign-extend a value between two byte sizes.
Take the first sizein bytes of the given in and sign-extend this to sizeout bytes, keeping any more significant bytes zero
in | is the given value |
sizein | is the size to treat that value as an input |
sizeout | is the size to sign-extend the value to |
bool ghidra::signbit_negative | ( | uintb | val, |
int4 | size | ||
) |
Return true if the sign-bit is set.
Treat the given val as a constant of size bytes
val | is the given value |
size | is the size in bytes |
uintb ghidra::uintb_negate | ( | uintb | in, |
int4 | size | ||
) |
Negate the sized value.
Treat the given in as a constant of size bytes. Negate this constant keeping the upper bytes zero.
in | is the given value |
size | is the size in bytes |
int4 ghidra::unsignedCompare128 | ( | uint8 * | a, |
uint8 * | b | ||
) |
Compare two unsigned 128-bit values.
TODO: Remove once we import a full multiprecision library. Given a first and second value, return -1, 0, or 1 depending on whether the first value is less, equal, or greater than the second value.
a | is the first 128-bit value (as an array of 2 uint8 elements) |
b | is the second 128-bit value |
void ghidra::unsignedSubtract128 | ( | uint8 * | a, |
uint8 * | b | ||
) |
Subtract (in-place) a 128-bit value from a base 128-value.
The base value is altered in place. TODO: Remove once we import a full multiprecision library.
a | is the base 128-bit value being subtracted from in-place |
b | is the other 128-bit value being subtracted |
|
inline |
Clear all bits above given bit.
Zero extend val starting at bit
val | is the value to be zero extended |
bit | is the index of the bit to extend from (0=least significant bit) |
References ghidra::calc_mask(), and ghidra::zero_extend().
Referenced by ghidra::OpBehaviorIntSdiv::evaluateBinary(), ghidra::OpBehaviorIntSrem::evaluateBinary(), and ghidra::zero_extend().