java.lang.Object | |
↳ | com.pnfsoftware.jeb.core.units.code.asm.decompiler.ir.EUtil |
Utility methods to manipulate the IR expression
.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
EUtil() |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
static IEOperation | add(IEGeneric a, IEGeneric b, IEGeneric c) | ||||||||||
static IEOperation | add(IEGeneric a, IEGeneric b) | ||||||||||
static void | addIfVar(List<IEVar> list, IEGeneric e) | ||||||||||
static IEOperation | andB(IEGeneric a, IEGeneric b) | ||||||||||
static IEOperation | andL(IEGeneric a, IEGeneric b) | ||||||||||
static boolean | areAlmostImmediates(Collection<IEGeneric> c) | ||||||||||
static IEGeneric |
buildCarryFlag(IEGeneric a, IEGeneric b, IEGeneric result, boolean addition, boolean nativeOp)
Retrieve the Carry flag Bit of the operation result = a {+/-} b {+ CarryIn}
| ||||||||||
static IEOperation |
buildLogicalOperation(IEOperation e)
Transform the operands of an operation into logical operands (LOG_NEQ with 0).
| ||||||||||
static IEGeneric |
buildOverflowFlag(IEGeneric a, IEGeneric b, IEGeneric result, boolean addition)
Retrieve the oVerflow flag Bit of the operation result = a {+/-} b {+ CarryIn}
| ||||||||||
static IECond |
buildStrictLogicalECond(IECond e)
Check if the ECond predicate is a ""boolean"", i.e.
| ||||||||||
static IEOperation |
buildStrictLogicalOperation(IEOperation e)
Check if the operands of logical OR, AND and NOT are ""booleans"", i.e.
| ||||||||||
static IEGeneric | checkFalse(IEGeneric e) | ||||||||||
static IEGeneric | checkTrue(IEGeneric e) | ||||||||||
static Set<IEVar> | collectVars(IEGeneric e) | ||||||||||
static void | collectVars(IEGeneric e, Set<IEVar> r) | ||||||||||
static IEGeneric |
compose(IEGeneric... elts)
Create a composition if the provided list of elements contains at least two entries, else
return the single element.
| ||||||||||
static IEGeneric |
compose(Collection<IEGeneric> elts)
Create a composition if the provided list of elements contains at list two entries, else
return the single element.
| ||||||||||
static boolean | containsUndeterminedInvocations(IEGeneric e) | ||||||||||
static void | countExpressionsPresence(IEGeneric e, List<IEGeneric> targets, int[] count) | ||||||||||
static int | countSubExpressions(IEGeneric e) | ||||||||||
static int | countVariablePresence(IEGeneric e, IEVar target) | ||||||||||
static int | countVariableUse(IEGeneric e) | ||||||||||
static IEImm |
createImm(long val, int bitsize)
Create an immediate, limited to 64 bits.
| ||||||||||
static IEImm |
createImm(byte[] bytes, int bitsize)
Create an arbitrary-long immediate.
| ||||||||||
static IEOperation |
div(IEGeneric a, IEGeneric b, boolean signed)
Alias for
divS(IEGeneric, IEGeneric) / divU(IEGeneric, IEGeneric)
| ||||||||||
static IEOperation | divS(IEGeneric a, IEGeneric b) | ||||||||||
static IEOperation | divU(IEGeneric a, IEGeneric b) | ||||||||||
static IEOperation | eq(IEGeneric a, IEGeneric b) | ||||||||||
static IEGeneric |
eqFloat(IEGeneric op1, IEGeneric op2)
Not(NaN) and eq (with 0 == -0)
| ||||||||||
static long | evaluateAddress_preVerified(IEGeneric e, IEState state) | ||||||||||
static long | evaluateAddress_preVerified(IEGeneric e) | ||||||||||
static long | evaluateUnsignedLong_preVerified(IEGeneric e) | ||||||||||
static long | evaluateUnsignedLong_preVerified(IEGeneric e, IEState state) | ||||||||||
static IEImm | evaluate_preVerified(IEGeneric e, IEState state) | ||||||||||
static IEImm | evaluate_preVerified(IEGeneric e) | ||||||||||
static IEGeneric |
extend(IEGeneric a, int bitsize, boolean signExtend)
Extend an
IEGeneric . | ||||||||||
static String |
formatIRCFGWithContext(int mode, CFG<IEStatement> cfg, IERoutineContext ectx)
Format an IR-CFG.
| ||||||||||
static IEOperation | geS(IEGeneric a, IEGeneric b) | ||||||||||
static IEOperation | geU(IEGeneric a, IEGeneric b) | ||||||||||
static IEMem | getAssigningFromMemory(IEStatement stm) | ||||||||||
static IEMem | getAssigningToMemory(IEStatement stm) | ||||||||||
static OperationType | getMirrorOperation(OperationType optype) | ||||||||||
static OperationType | getOperation(IEGeneric e, OperationType... optypes) | ||||||||||
static OperationType | getOperation(IEOperation e, OperationType... optypes) | ||||||||||
static OperationType | getReverseOperation(OperationType optype) | ||||||||||
static IEGeneric |
getSignExtensionBase(IECompose e)
Check if the composition is a sign-extension of a base expression, and if so, provide the
base expression.
| ||||||||||
static IEGeneric |
getSignExtensionBase(IEGeneric e)
Check if an IR expression looks like a sign-extension operation, and if so, provide the base
expression.
| ||||||||||
static IEGeneric |
getSignExtensionBase(IEGeneric base, IEGeneric extend)
Check if the composition of both expressions make up a sign-extension, and if so, provide the
base expression.
| ||||||||||
static List<IEGeneric> | getSubExpressions(IEGeneric e) | ||||||||||
static Set<Integer> | getUsedVarIds(IEGeneric e) | ||||||||||
static IEGeneric |
gtFloat(IEGeneric op1, IEGeneric op2)
Not(NaN) and gt
| ||||||||||
static IEOperation | gtS(IEGeneric a, IEGeneric b) | ||||||||||
static IEOperation | gtU(IEGeneric a, IEGeneric b) | ||||||||||
static boolean | hasExplicitlyUsedVar(IEGeneric e, IEVar target) | ||||||||||
static boolean | isAlmostImmediate(IEGeneric a) | ||||||||||
static boolean |
isAssignedIn(BasicBlock<IEStatement> bb, IEGeneric possibleDispatch)
Check that an IRE is assigned in a basic block.
| ||||||||||
static boolean | isComparableOperation(IEOperation e) | ||||||||||
static boolean | isComparableOperation(IEOperation e, boolean allowUnsigned) | ||||||||||
static boolean |
isComparableOperation(IEGeneric e)
""Boolean"" comparable operation (eq/neq and all greater/lesser comparisons)
| ||||||||||
static boolean | isComparableSignedOperation(IEOperation e) | ||||||||||
static boolean | isCondEAssign(IEGeneric e) | ||||||||||
static boolean | isCondEJump(IEGeneric e) | ||||||||||
static boolean | isExpressionModified(IEStatement insn, IEGeneric target, boolean defuse) | ||||||||||
static boolean | isFirstBit(IESlice s2) | ||||||||||
static boolean | isImmSize(IEGeneric e, int bitsize) | ||||||||||
static boolean | isImmValue(IEGeneric e, long value) | ||||||||||
static boolean | isImmValue(IEGeneric e, BigInteger value) | ||||||||||
static boolean | isImmZero(IEGeneric e) | ||||||||||
static boolean | isJump(IEGeneric e) | ||||||||||
static boolean | isLastBit(IESlice s2) | ||||||||||
static boolean |
isLogicalOperation(IEGeneric e)
""Boolean"" operation (and, or, not, eq/neq and all greater/lesser comparisons)
| ||||||||||
static boolean | isMatchDuaryOperation(IEGeneric e, OperationType wantedOperationType, IEGeneric wantedOperand1, IEGeneric wantedOperand2) | ||||||||||
static boolean | isNBit(IESlice s2, int n) | ||||||||||
static IEGeneric |
isNaN(IEGeneric op)
As per IEEE 754-1985 floating-point standard, is NaN a number which exponent is filled with
ones and a non-zero number in the mantissa
| ||||||||||
static boolean |
isNotPredicate(IEGeneric p, IEGeneric p2)
Indicate if p == !p2.
| ||||||||||
static boolean |
isOne(IEGeneric e)
Verify that an IRE is an immediate holding 1.
| ||||||||||
static boolean | isOperation(IEGeneric e, OperationType optype) | ||||||||||
static boolean | isOperation(IEGeneric e, OperationType... optypes) | ||||||||||
static boolean | isOperationSize(IEGeneric e, int bitsize) | ||||||||||
static boolean |
isPCAssign(IEStatement stm)
Determine if the provided statement is a PC-assign:
Var_PC = ... | ||||||||||
static boolean | isRegister(IEGeneric op, int reg) | ||||||||||
static boolean | isStrictLogicalOperation(IEOperation e) | ||||||||||
static boolean |
isStrictLogicalOperation(IEGeneric e)
Logical operations that should have logical operands (and, or, not)
| ||||||||||
static boolean | isTrampoline(BasicBlock<IEStatement> bb) | ||||||||||
static boolean | isUnconditionalJump(IEGeneric e) | ||||||||||
static boolean |
isZero(IEGeneric e)
Verify that an IRE is a Zero representation (EImm(0) or ESlice(0, x, x))
| ||||||||||
static boolean | isZeroExtend(IECompose e) | ||||||||||
static IEOperation | leS(IEGeneric a, IEGeneric b) | ||||||||||
static IEOperation | leU(IEGeneric a, IEGeneric b) | ||||||||||
static void | loglist(List<? extends IEStatement> irlist) | ||||||||||
static boolean |
looksLikeSignExtension(IECompose e)
Determine if a composition looks like a sign-extension operation.
| ||||||||||
static IEGeneric |
ltFloat(IEGeneric op1, IEGeneric op2)
Not(NaN) and lt
| ||||||||||
static IEOperation | ltS(IEGeneric a, IEGeneric b) | ||||||||||
static IEOperation | ltU(IEGeneric a, IEGeneric b) | ||||||||||
static IEOperation |
makeCast(IEGeneric src, int dstSize, boolean signed)
Create an integer cast operation.
| ||||||||||
static void |
makeUncond(IEJump j)
throws if failure
| ||||||||||
static IEOperation |
mul(IEGeneric a, IEGeneric b, boolean signed)
Alias for
mulS(IEGeneric, IEGeneric) / mulU(IEGeneric, IEGeneric)
| ||||||||||
static IEOperation | mulS(IEGeneric a, IEGeneric b) | ||||||||||
static IEOperation | mulU(IEGeneric a, IEGeneric b) | ||||||||||
static IEOperation | ne(IEGeneric a, IEGeneric b) | ||||||||||
static IEGeneric | notB(IEGeneric a) | ||||||||||
static IEGeneric | notL(IEGeneric a) | ||||||||||
static IEImm |
one(int bitsize)
Generates the value 1L with defined bitsize.
| ||||||||||
static IEImm |
ones(int bitsize)
Generates an EImm filled with ones.
| ||||||||||
static IEOperation | orB(IEGeneric a, IEGeneric b) | ||||||||||
static IEOperation | orL(IEGeneric a, IEGeneric b) | ||||||||||
static IEOperation | pow(IEGeneric a, IEGeneric b) | ||||||||||
static IEOperation | remS(IEGeneric a, IEGeneric b) | ||||||||||
static IEOperation | remU(IEGeneric a, IEGeneric b) | ||||||||||
static IEGeneric | replaceSubExpressionRecursive(IEGeneric stm, IEGeneric src, IEGeneric dst, EVisitResults results) | ||||||||||
static IEGeneric | replaceSubExpressionRecursive(IEGeneric stm, IEGeneric src, IEGeneric dst) | ||||||||||
static boolean |
resolveExpressionsBackward(Object name, IEConverter<?> conv, List<IEStatement> r, IEGeneric... targets)
Apply a list of IEStatements to user targets, resolving expression starting from last
IEStatement to first. | ||||||||||
static IEGeneric | reversePredicate(IEGeneric predicate) | ||||||||||
static IEGeneric |
safeExtend(IEGeneric a, int bitsize, boolean signExtend)
Safely extend an
IEGeneric . | ||||||||||
static int |
sameBitsize(IEGeneric... elts)
If all the provided expressions have the same bitsize, return it.
| ||||||||||
static int |
sameBitsizeAllowNulls(IEGeneric... elts)
If all the provided expressions have the same bitsize, return it.
| ||||||||||
static IEOperation | sar(IEGeneric a, IEGeneric b) | ||||||||||
static IEOperation | shl(IEGeneric a, IEGeneric b) | ||||||||||
static IEOperation | shr(IEGeneric a, IEGeneric b) | ||||||||||
static IEOperation | sub(IEGeneric a, IEGeneric b) | ||||||||||
static IEOperation | xorB(IEGeneric a, IEGeneric b) | ||||||||||
static IEImm |
zero(int bitsize)
Generates the value 0 with defined bitsize.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Retrieve the Carry flag Bit of the operation result = a {+/-} b {+ CarryIn}
a | operand a |
---|---|
b | operand b |
result | result (may have an additional carry flag added before) |
addition | true if a + b, false if a - b |
nativeOp | indicate it CARRY / LT_U can be
used over complex xor expression |
Transform the operands of an operation into logical operands (LOG_NEQ with 0).
Retrieve the oVerflow flag Bit of the operation result = a {+/-} b {+ CarryIn}
a | operand a |
---|---|
b | operand b |
result | result (may have an additional carry flag added before) |
addition | true if a + b, false if a - b |
Check if the ECond predicate is a ""boolean"", i.e. a logical operation.
In case it is not, a new ECond with a boolean predicate is built (based on LOG_NEQ 0).
Check if the operands of logical OR, AND and NOT are ""booleans"", i.e. logical operations.
In case they are not, a new operation with boolean operands is built (based on LOG_NEQ 0).
Create a composition if the provided list of elements contains at least two entries, else return the single element.
Create a composition if the provided list of elements contains at list two entries, else return the single element.
Alias for divS(IEGeneric, IEGeneric)
/ divU(IEGeneric, IEGeneric)
Format an IR-CFG.
mode | 0=no chains 1=with simple chains 2=with full chains 3=with simple chains and IR types 4=with full chains and IR types |
---|---|
cfg | IR-CFG |
ectx | optional routine context; one must be provided to get EVar id name resolution |
Check if the composition is a sign-extension of a base expression, and if so, provide the base expression.
e | expression to test that should be a signExtend |
---|
Check if an IR expression looks like a sign-extension operation, and if so, provide the base expression.
Check if the composition of both expressions make up a sign-extension, and if so, provide the base expression.
Check that an IRE is assigned in a basic block.
This method does not rely on data flow analysis; it simply searches for an assignment to the given IRE.
""Boolean"" comparable operation (eq/neq and all greater/lesser comparisons)
""Boolean"" operation (and, or, not, eq/neq and all greater/lesser comparisons)
As per IEEE 754-1985 floating-point standard, is NaN a number which exponent is filled with ones and a non-zero number in the mantissa
Indicate if p == !p2. Search for reversed operator as well as mirrored predicate. Do not consider NOT operations.
p | reference predicate |
---|---|
p2 | predicate to test |
Determine if the provided statement is a PC-assign: Var_PC = ...
Logical operations that should have logical operands (and, or, not)
Verify that an IRE is a Zero representation (EImm(0) or ESlice(0, x, x))
Determine if a composition looks like a sign-extension operation.
Create an integer cast operation. Those special operations are introduced in late IR processing phases (stage 700+), it is recommended to avoid then in early stages.
src | the source to be casted |
---|---|
dstSize | the destination size; should be different the the source's size |
signed | signed or unsigned cast; note that signed cast make sense only when casting upward |
Alias for mulS(IEGeneric, IEGeneric)
/ mulU(IEGeneric, IEGeneric)
Generates the value 1L with defined bitsize. Do not mistake #one(ERoutineContext, int) for #ones(ERoutineContext, int)
bitsize | Bitsize of the EImm |
---|
Generates an EImm filled with ones. Do not mistake #ones(ERoutineContext, int) for #one(ERoutineContext, int)
ones(2) ==> 0x3 ones(16) ==> 0xFFFF ...
bitsize | Bitsize of the EImm |
---|
Apply a list of IEStatements to user targets, resolving expression starting from last
IEStatement
to first. If any error occur (something can not be translated for
example), this method returns false.
As an example:
r = {R0 = 7; R0 = R0 + 4; R1 = 8} targets = [R0, R1] i = 2 => targets = [R0, 8] i = 1 => targets = [R0+4, 8] i = 0 => targets = [11, 8] return true
If all the provided expressions have the same bitsize, return it. Null elements are considered invalid and will result in a failure (the method will return 0).
elts | a list of IRE |
---|
If all the provided expressions have the same bitsize, return it. Null elements are ignored.
elts | a list of IRE |
---|
Generates the value 0 with defined bitsize.
bitsize | Bitsize of the EImm |
---|