Class EUtil
IR expressions
.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic IECond
abs
(IERoutineContext ctx, IEGeneric a) OperationMath#abs(int, int)
applied toIEGeneric
static IEOperation
static IEOperation
static int
adjustBranchToIRInstruction
(IEStatement stm, int currentTargetIROffset, int newTargetIROffset) static IEOperation
static IEOperation
static IEGeneric
buildCarryFlag
(IEGeneric a, IEGeneric b, IEGeneric result, boolean addition, boolean nativeOp) Generate an IR expression computing the carry flag bit of an integer addition or subtraction operation.static IEOperation
Transform the operands of an operation into logical operands (LOG_NEQ with 0).static IEGeneric
buildOverflowFlag
(IEGeneric a, IEGeneric b, IEGeneric result, boolean addition) Generate an IR expression computing the overflow flag bit of an integer addition or subtraction operation.static IECond
Check if the ECond predicate is a ""boolean"", i.e.static IEOperation
Check if the operands of logical OR, AND and NOT are ""booleans"", i.e.static int
Calculate the trivial complexity metric for the provided IR expression.static Boolean
checkCallReturnAddress
(IERoutineContext ctx, CFG<IEStatement> cfg, BasicBlock<IEStatement> b, int insnIndex) static IEGeneric
static IEGeneric
static IEGeneric
cmpFloat
(OperationType op, IEGeneric op1, IEGeneric op2) static void
collectVars
(IEGeneric e, Collection<IEVar> sink) Collect all EVars of an expression.static IEGeneric
compose
(IERoutineContext ctx, IEGeneric... elts) Create a composition if the provided list of elements contains at least two entries, else return the single element.static IEGeneric
compose
(IERoutineContext ctx, Collection<IEGeneric> elts) Create a composition if the provided list of elements contains at list two entries, else return the single element.static boolean
Indicates if the target expression contains any token expressionstatic boolean
Indicates if the generic expression contains any memory access (meaningIEMem
)static boolean
Indicates if the generic expression invokes any undetermined kind of call (meaningIECall
,IEJumpFar
orIEUntranslatedInstruction
)static int
countExpressionPresence
(IEGeneric e, IEGeneric target) Recursively count (using deep equality) how many times the provided target is seen in the input expression.static void
countExpressionsPresence
(IEGeneric e, List<IEGeneric> targets, int[] acounts) Recursively count (using deep equality) how many times each of the provided targets is seen in the input expression.static int
Collect sub-expressions of the input expression and return the cardinal of that collection.static int
countVariablePresence
(IEGeneric e, IEVar target) Count the number of times anIEVar
is present in an expression.static int
static IEOperation
createConversionOperation
(OperationType convOperator, IEGeneric src, int dstSize) Create a conversion operation: an integer truncation, integer extension (zero or signed), float truncation or extension, float-to-int and int-to-float conversion.static IEOperation
createResizeOperation
(IEGeneric src, int dstSize, boolean signed) Create a resize operation operation: truncation, zero-extension, or sign-extension.static int
determineArgumentStackSlotCount
(IWildcardPrototype prototype, Collection<IWildcardType> varArgTypes) Determine the number of stacks slots used by invoking a method having the provided prototype and an optional list of additional arguments.static int
determineReturnValuesStackSlotCount
(IWildcardPrototype prototype, int inputStackSlotCount) Determine the number of stack slots filled out when a routine with the provided prototype returns.static IEOperation
Alias fordivS(IEGeneric, IEGeneric)
/divU(IEGeneric, IEGeneric)
static IEOperation
static IEOperation
static void
dump
(CFG<IEStatement> cfg, String filename) Dump an IR-CFG to a Graphvizdot
file in the user's temporary folder.static void
dump
(CFG<IEStatement> cfg, String filename, String title) Dump an IR-CFG to a Graphvizdot
file in the user's temporary folder.static IEOperation
static int
evalAsPositiveInt
(IEImm imm) Evaluate an immediate to a 32-bit positive int.static int
Evaluate and convert a positive immediate to a 32-bit int.static IEImm
static IEImm
evaluate_preVerified
(IEGeneric e, EState state) static long
static long
evaluateAddress_preVerified
(IEGeneric e, EState state) static long
static long
evaluateUnsignedLong_preVerified
(IEGeneric e, EState state) static boolean
expandCalls
(IERoutineContext ctx, boolean alsoExpandPCAssign) Call/PC-assign expansion: augment the size to at least 2, to accommodate splitting:
- if an EReturn is to be inserted (tail-calls) in lieu of a ECall
- if a raw PC-assign cannot be converted to a single EJumpFarstatic CFG<IEStatement>
expandStatementSize
(IERoutineContext ectx, IEStatement stm0, int minSize) Expand thesize
of a statement.static CFG<IEStatement>
expandStatementSizes
(IERoutineContext ectx, Collection<IEStatement> stmcoll, int minSize) Expand thesizes
of a collection of statements.static IEGeneric
Extend anIEGeneric
.static IECond
fabs
(IERoutineContext ctx, IEGeneric a) OperationMath#abs(float, float)
applied toIEGeneric
static IECond
fmax
(IERoutineContext ctx, IEGeneric a, IEGeneric b) OperationMath.max(float, float)
applied toIEGeneric
static IECond
fmin
(IERoutineContext ctx, IEGeneric a, IEGeneric b) OperationMath.min(float, float)
applied toIEGeneric
static String
formatIR
(IERoutineContext ectx) Format an IR-CFG.static String
formatIR
(IERoutineContext ectx, boolean displayOffsets, boolean displayDataChains, boolean displayTypes) Format an IR-CFG.static String
formatStatements
(List<? extends IEStatement> irlist) static String
formatVars
(IERoutineContext ctx, int... varids) static String
formatVars
(IERoutineContext ctx, Collection<Integer> varids) static List<IWildcardType>
gatherArgumentTypes
(IWildcardPrototype prototype, Collection<IWildcardType> varArgTypes) Retrieve the list of input types, by examining the provided prototype and optional list of additional arguments.static IEOperation
static IEMem
static IEMem
static IEGeneric
Retrieve the destination of anIEAssign
(or null if is not an assignment).static IEGeneric
Retrieve the source of anIEAssign
(or null if is not an assignment).static IWildcardType
static OperationType
getMirrorOperation
(OperationType optype) static OperationType
getOperation
(IEGeneric e, OperationType... optypes) static OperationType
getOperation
(IEOperation e, OperationType... optypes) getParents
(IEGeneric expression, IEGeneric value) Retrieve all the parents of a value.static OperationType
getReverseOperation
(OperationType optype) static IEGeneric
Check if the composition is a sign-extension of a base expression, and if so, provide the base expression.static IEGeneric
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.Collect the sub-expressions of an IRE.getVars
(IERoutineContext ctx, Collection<Integer> varids) static IEVar
static Integer
static List<IWildcardType>
getWildcardTypes
(IWildcardTypeManager etypeman, Collection<IEGeneric> elts) static IEOperation
static IEOperation
static IEOperation
static boolean
hasExplicitlyUsedVar
(IEGeneric e, IEVar target) static boolean
Checks if an IR routine contains only basic blocks with one parent and one child (no merge or disjunction of control-flow).static boolean
Determine if an IR expression is side-effect free.static boolean
Determine if the provided IR expression embeds no amount at all of type information.static boolean
hasSameType
(IEGeneric e1, IEGeneric e2) static boolean
The opposite ofhasNoSideEffect(IEGeneric)
.static boolean
Determine if the provided IR expression embeds some type information.static IEGeneric
static IEImm
imm
(byte[] val, int bitsize) Create an arbitrary-long immediate.static IEImm
imm
(long val, int bitsize) Create an immediate, limited to 64 bits.static IEImm
Create an arbitrary-long immediate.static IEImm
imm
(BigInteger val, int bitsize) Create an arbitrary-long immediate.static boolean
isAssignedIn
(BasicBlock<IEStatement> bb, IEGeneric checkedDst) Check that an IRE is assigned in a basic block.static boolean
Verify that an IRE is a single-bit immediate set to 1 (technically, -1).static boolean
Verify that an IRE is a single-bit immediate set to 0.static boolean
static boolean
""Boolean"" comparable operation (eq/neq and all greater/lesser comparisons)static boolean
static boolean
isComparableOperation
(IEOperation e, boolean allowUnsigned, boolean allowFloat) static boolean
static boolean
static boolean
static boolean
isExpressionModified
(IEStatement insn, IEGeneric target, boolean defuse) static boolean
isFirstBit
(IESlice s2) static boolean
static boolean
static boolean
static boolean
isImmValue
(IEGeneric e, long value) static boolean
isImmValue
(IEGeneric e, BigInteger value) static boolean
static boolean
static boolean
static boolean
isLegalSignedImmediate
(IEImm v, int checkedBitsize) Verify that the provided immediate is a legal signed value if it were to be treated as a signed integer of `checkedBitsize`.static boolean
isLegalUnsignedImmediate
(IEImm v, int checkedBitsize) Verify that the provided immediate is a legal unsigned value if it were to be treated as an unsigned integer of `checkedBitsize`.static boolean
Determine if the IRE is an EImm or a slice or composition of immediates.static boolean
Determine if the expression is equivalent to an EImm that can be read as along
primitive.static boolean
isLikeLongImmediate
(IEGeneric e, boolean unsigned) Determine if the expression is equivalent to an EImm that can be read as along
primitive.static boolean
""Boolean"" operation (and, or, not, eq/neq and all greater/lesser comparisons)static boolean
Determine if the expression is an EImm that can be read as along
primitive.static boolean
isLongImmediate
(IEGeneric e, boolean unsigned) Determine if the expression is an EImm that can be read as along
primitive.static boolean
isMatchDuaryOperation
(IEGeneric e, OperationType wantedOperationType, IEGeneric wantedOperand1, IEGeneric wantedOperand2) static boolean
Verify that an IRE is an immediate holding the value -1.static IEGeneric
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 mantissastatic boolean
static boolean
isNotPredicate
(IEGeneric p, IEGeneric p2) Indicate if p == !p2.static boolean
Verify that an IRE is an immediate holding 1.static boolean
isOperation
(IEGeneric e, OperationType optype) Determine if theIEGeneric
is anIEOperation
.static boolean
isOperation
(IEGeneric e, OperationType... optypes) Determine if theIEGeneric
is anIEOperation
.static boolean
isOperationSize
(IEGeneric e, int bitsize) static boolean
isPCAssign
(IEStatement stm) Determine if the provided statement is a PC-assign:PC = ...
static boolean
static boolean
isSPAssign
(IEStatement stm) Determine if the provided statement is a SP-assign:SP = ...
orSP[slice] = ...
.static boolean
Determine if the provided statement is assigning the stack pointer or the program counter.static boolean
Logical operations that should have logical operands (and, or, not)static boolean
static boolean
static boolean
static boolean
static boolean
isVariableAssigned
(IEStatement stm, IEVar var) static boolean
static boolean
Verify that an IRE is a Zero representation (EImm(0) or ESlice(0, x, x))static boolean
static boolean
static IEOperation
static IEOperation
static boolean
Determine if a composition looks like a sign-extension operation.static IEOperation
static IEOperation
static void
throws if failurestatic IEImm
mask
(int bitsize, int maskbits) Create a bit mask, eg mask(16, 4) will create the mask:b0000000000001111
static IEImm
mask
(int bitsize, int maskbegin, int maskend) Create a bit mask, eg mask(16, 1, 5) will create the mask:b0000000000011110
static IECond
max
(IERoutineContext ctx, IEGeneric a, IEGeneric b, boolean signed) OperationMath.max(int, int)
applied toIEGeneric
static IECond
min
(IERoutineContext ctx, IEGeneric a, IEGeneric b, boolean signed) OperationMath.min(int, int)
applied toIEGeneric
static IEImm
minusOne
(int bitsize) Generates the value -1, ie anEImm
filled with ones.static IEOperation
static IEOperation
static IEGeneric
static IEGeneric
static IEGeneric
static IEImm
one
(int bitsize) Generates the value 1L with defined bitsize.static IEOperation
op
(OperationType operator, IEGeneric a) static IEOperation
op
(OperationType operator, IEGeneric a, IEGeneric b) static IEOperation
static IEOperation
static IEOperation
static IEOperation
static IEOperation
static IEGeneric
replaceSubExpressionRecursive
(IEGeneric stm, IEGeneric src, IEGeneric dst) static IEGeneric
replaceSubExpressionRecursive
(IEGeneric stm, IEGeneric src, IEGeneric dst, EVisitResults results) static boolean
Determine if type `b` can be implicitly converted to type `a`, without a cast.static boolean
resolveExpressionsBackward
(Object name, IEConverter<?> conv, List<IEStatement> r, IEGeneric... targets) Apply a list of IEStatements to user targets, resolving expression starting from lastIEStatement
to first.static IEGeneric
reversePredicate
(IEGeneric predicate) static IEGeneric
safeExtend
(IEGeneric a, int bitsize, boolean signExtend) Safely extend anIEGeneric
.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
static void
setLowerLevelAddress
(long addr, List<IEStatement> list) static void
setLowerLevelAddress
(long addr, List<IEStatement> list, int fromIndex, int toIndex) static void
setLowerLevelAddressIfNone
(long addr, List<IEStatement> list) static void
setLowerLevelAddressIfNone
(long addr, List<IEStatement> list, int fromIndex, int toIndex) static IEOperation
static IEOperation
static IEGeneric
Sign-extend operation IRE.static IEOperation
static IEGeneric
Truncate operation IRE.static void
verify
(CFG<IEStatement> cfg) Verify an IR-CFG.static void
verify
(IERoutineContext ctx) Verify an IR-CFG.static IEOperation
static IEImm
zero
(int bitsize) Generates the value 0 with defined bitsize.static IEGeneric
Zero-extend operation IRE.
-
Constructor Details
-
EUtil
public EUtil()
-
-
Method Details
-
formatStatements
-
formatIR
Format an IR-CFG.- Parameters:
ectx
- routine context- Returns:
- the formatted CFG
-
formatIR
public static String formatIR(IERoutineContext ectx, boolean displayOffsets, boolean displayDataChains, boolean displayTypes) Format an IR-CFG.- Parameters:
ectx
- routine contextdisplayOffsets
-displayDataChains
-displayTypes
-- Returns:
- the formatted CFG
-
dump
Dump an IR-CFG to a Graphvizdot
file in the user's temporary folder.- Parameters:
cfg
- CFGfilename
- filename (the ".dot" extension will be appended if necessary)
-
dump
Dump an IR-CFG to a Graphvizdot
file in the user's temporary folder.- Parameters:
cfg
- CFGfilename
- filename (the ".dot" extension will be appended if necessary)title
- optional title or header string
-
verify
Verify an IR-CFG. This method relies on theECFGVerifier
and throws on error.- Parameters:
ctx
- IR context
-
verify
Verify an IR-CFG. This method relies on theECFGVerifier
and throws on error.- Parameters:
cfg
- IR graph
-
isPCAssign
Determine if the provided statement is a PC-assign:PC = ...
- Parameters:
stm
- a statement- Returns:
-
isSPAssign
Determine if the provided statement is a SP-assign:SP = ...
orSP[slice] = ...
.- Parameters:
stm
- a statement- Returns:
-
isSPAssignOrPCAssign
Determine if the provided statement is assigning the stack pointer or the program counter. CombinesisSPAssign(IEStatement)
isPCAssign(IEStatement)
in a single efficient call.- Parameters:
stm
- a statement- Returns:
-
imm
Create an immediate, limited to 64 bits.- Parameters:
val
-bitsize
-- Returns:
-
imm
Create an arbitrary-long immediate.- Parameters:
val
- big-endian bytes of the valuebitsize
-- Returns:
-
imm
Create an arbitrary-long immediate.- Parameters:
val
- valuebitsize
-- Returns:
-
imm
Create an arbitrary-long immediate.- Parameters:
val
- string representation of the integer immediatebitsize
-- Returns:
-
one
Generates the value 1L with defined bitsize. Do not mistake#one(ERoutineContext, int)
for#ones(ERoutineContext, int)
- Parameters:
bitsize
- Bitsize of theEImm
-
zero
Generates the value 0 with defined bitsize.- Parameters:
bitsize
- Bitsize of theEImm
-
minusOne
Generates the value -1, ie anEImm
filled with ones.- Parameters:
bitsize
- Bitsize of theEImm
-
mask
Create a bit mask, eg mask(16, 4) will create the mask:b0000000000001111
- Parameters:
bitsize
-maskbits
- must be less than or equal to `bitsize`- Returns:
-
mask
Create a bit mask, eg mask(16, 1, 5) will create the mask:b0000000000011110
- Parameters:
bitsize
-maskbegin
- start bit of the mask, inclusivemaskend
- end bit of the mask, exclusive- Returns:
-
compose
Create a composition if the provided list of elements contains at least two entries, else return the single element.- Parameters:
elts
-- Returns:
-
compose
Create a composition if the provided list of elements contains at list two entries, else return the single element.- Parameters:
elts
-- Returns:
-
checkTrue
-
checkFalse
-
isOperation
Determine if theIEGeneric
is anIEOperation
. Use when e can be null, otherwise prefer nativeIEGeneric.isOperation(OperationType)
- Parameters:
e
- IR expression- Returns:
e != null && e.IsOperation(optype)
-
isOperation
Determine if theIEGeneric
is anIEOperation
. Use when e can be null, otherwise prefer nativeIEGeneric.isOperation(OperationType...)
- Parameters:
e
- IR expression- Returns:
e != null && e.IsOperation(optypes)
-
isLogicalOperation
""Boolean"" operation (and, or, not, eq/neq and all greater/lesser comparisons)- Parameters:
e
- IR expression- Returns:
- true if this is a logical operation
-
isComparableOperation
""Boolean"" comparable operation (eq/neq and all greater/lesser comparisons)- Parameters:
e
- IR expression- Returns:
- true if this is a comparable operation
-
isComparableOperation
-
isComparableIntegerOperation
-
isComparableSignedOperation
-
isComparableOperation
public static boolean isComparableOperation(IEOperation e, boolean allowUnsigned, boolean allowFloat) -
isStrictLogicalOperation
Logical operations that should have logical operands (and, or, not) -
isStrictLogicalOperation
-
getOperation
-
getOperation
-
isOperationSize
-
getReverseOperation
-
getMirrorOperation
-
isVar
-
isVarOrVarSlice
-
getVarSlice
-
getVarSliceId
-
isZero
Verify that an IRE is a Zero representation (EImm(0) or ESlice(0, x, x)) -
isOne
Verify that an IRE is an immediate holding 1.IMPORTANT: i1:1 will fail the test since it is equal to -1. Consider using
isBitOne(IEGeneric)
orisMinusOne(IEGeneric)
instead. -
isMinusOne
Verify that an IRE is an immediate holding the value -1. -
isBitOne
Verify that an IRE is a single-bit immediate set to 1 (technically, -1). -
isBitZero
Verify that an IRE is a single-bit immediate set to 0. -
isImmSize
-
isImmValue
-
isImmValue
-
isImmZero
-
isImmNonZero
-
isCondEAssign
-
isJump
-
isUnconditionalJump
-
isConditionalJump
-
makeUncond
throws if failure -
isAssignedIn
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.
- Parameters:
checkedDst
-- Returns:
-
getSubExpressions
Collect the sub-expressions of an IRE. Simply callsIEGeneric#getSubExpressions(List)
. Not recursive!- Parameters:
e
-- Returns:
-
countSubExpressions
Collect sub-expressions of the input expression and return the cardinal of that collection. Simply callsIEGeneric#getSubExpressions(List)
. Not recursive!- Parameters:
e
-- Returns:
-
sameBitsize
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).- Parameters:
elts
- a list of IRE- Returns:
- the common bitsize of all provided elements; 0 if the elements do not have the same bitsize
-
sameBitsizeAllowNulls
If all the provided expressions have the same bitsize, return it. Null elements are ignored.- Parameters:
elts
- a list of IRE- Returns:
- the common bitsize of all provided elements; 0 if the elements do not have the same bitsize
-
countVariableUse
-
calculateComplexity
Calculate the trivial complexity metric for the provided IR expression. Every IR element has a weight of 1.- Parameters:
e
-- Returns:
-
countVariablePresence
Count the number of times anIEVar
is present in an expression. (Defined vars are counted as well.)- Parameters:
e
-target
-IEVar
to be counter- Returns:
-
countExpressionPresence
Recursively count (using deep equality) how many times the provided target is seen in the input expression.- Parameters:
e
- expression to be examinedtarget
- target- Returns:
- presence count
-
countExpressionsPresence
Recursively count (using deep equality) how many times each of the provided targets is seen in the input expression.- Parameters:
e
- expression to be examinedtargets
- targetsacounts
- output counts, the array size must match target's, and counts must be initially set to 0
-
getUsedVarIds
-
collectVars
-
collectVars
Collect all EVars of an expression. If the expression is an EVar, it will be collected.- Parameters:
e
- IR expressionsink
- a recipient for collected EVars. Note that a set may be used to collect unique EVars, or a list may be used to collect all encountered EVars
-
hasExplicitlyUsedVar
-
isTrampoline
-
reversePredicate
-
containsUndeterminedInvocations
Indicates if the generic expression invokes any undetermined kind of call (meaningIECall
,IEJumpFar
orIEUntranslatedInstruction
)- Parameters:
e
-IEGeneric
- Returns:
- true if the expression contains undetermined invocation.
-
containsMemoryAccess
Indicates if the generic expression contains any memory access (meaningIEMem
)- Parameters:
e
-IEGeneric
- Returns:
- true if the expression contains memory access.
-
contains
Indicates if the target expression contains any token expression- Parameters:
target
- expression to search intotoken
- token to search- Returns:
- true if target contains token
-
buildStrictLogicalOperation
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).
- Returns:
- transformed IRE
-
buildLogicalOperation
Transform the operands of an operation into logical operands (LOG_NEQ with 0). -
buildStrictLogicalECond
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).
- Returns:
- transformed IRE
-
op
-
op
-
ltS
-
leS
-
gtS
-
geS
-
ltU
-
leU
-
gtU
-
geU
-
eq
-
ne
-
andL
-
orL
-
notL
-
notL
-
identL
-
andB
-
orB
-
xorB
-
notB
-
add
-
add
-
sub
-
mul
-
div
Alias fordivS(IEGeneric, IEGeneric)
/divU(IEGeneric, IEGeneric)
-
divS
-
divU
-
remS
-
remU
-
shl
-
shr
-
sar
-
pow
-
min
OperationMath.min(int, int)
applied toIEGeneric
-
max
OperationMath.max(int, int)
applied toIEGeneric
-
abs
OperationMath#abs(int, int)
applied toIEGeneric
-
fmin
OperationMath.min(float, float)
applied toIEGeneric
-
fmax
OperationMath.max(float, float)
applied toIEGeneric
-
fabs
OperationMath#abs(float, float)
applied toIEGeneric
-
extend
-
safeExtend
-
isNotPredicate
Indicate if p == !p2. Search for reversed operator as well as mirrored predicate. Do not consider NOT operations.- Parameters:
p
- reference predicatep2
- predicate to test- Returns:
-
isFirstBit
-
isLastBit
-
isNBit
-
isNaN
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 -
cmpFloat
-
createResizeOperation
Create a resize operation operation: truncation, zero-extension, or sign-extension.- Parameters:
src
- the source to be extended (dstSize > srcSize) or truncated (dstSize < srcSize)dstSize
- the destination size; should be different than the source'ssigned
- for extensions, else N/A- Returns:
- the operation IRE
-
createConversionOperation
public static IEOperation createConversionOperation(OperationType convOperator, IEGeneric src, int dstSize) Create a conversion operation: an integer truncation, integer extension (zero or signed), float truncation or extension, float-to-int and int-to-float conversion.- Parameters:
convOperator
- one of for whichOperationType.isConversion()
returns true (eg,OperationType.CAST
,OperationType.CAST_S
,OperationType.FP2FP
,OperationType.FP2INT
,OperationType.INT2FP
)src
- operand to be extended, truncated, or converteddstSize
- resulting bitsize- Returns:
- the operation IRE
-
truncate
Truncate operation IRE.- Parameters:
src
-dstSize
- must be less or equal than src's size- Returns:
-
zeroExt
Zero-extend operation IRE.- Parameters:
src
-dstSize
- must be greater or equal than src's size- Returns:
-
signExt
Sign-extend operation IRE.- Parameters:
src
-dstSize
- must be greater or equal than src's size- Returns:
-
looksLikeSignExtension
Determine if a composition looks like a sign-extension operation.- Parameters:
e
-- Returns:
-
getSignExtensionBase
Check if an IR expression looks like a sign-extension operation, and if so, provide the base expression.- Parameters:
e
-- Returns:
-
getSignExtensionBase
Check if the composition is a sign-extension of a base expression, and if so, provide the base expression.- Parameters:
e
- expression to test that should be a signExtend- Returns:
- the base expression
-
getSignExtensionBase
Check if the composition of both expressions make up a sign-extension, and if so, provide the base expression.if the input expression is as such:
COMPOSE(base, MSB(base) ? -1: 0)
, then return:base
- Parameters:
base
- candidate base (i.e., base we expect to retrieve)extend
- candidate sign-extension expression, extendingbase
- Returns:
- base on success, else null
-
isZeroExtend
-
isZeroExtend
-
buildCarryFlag
public static IEGeneric buildCarryFlag(IEGeneric a, IEGeneric b, IEGeneric result, boolean addition, boolean nativeOp) Generate an IR expression computing the carry flag bit of an integer addition or subtraction operation.The carry flag is used to indicate wrap-around for unsigned operations.
- Parameters:
a
- operand ab
- operand bresult
- result c (may have an additional carry flag added before)addition
- true if the carry is to be computed for "a + b", false for "a - b"nativeOp
- indicate itOperationType.CARRY
/OperationType.LT_U
can be used over complex xor expression- Returns:
- a one-bit overflow flag IR expression
-
buildOverflowFlag
public static IEGeneric buildOverflowFlag(IEGeneric a, IEGeneric b, IEGeneric result, boolean addition) Generate an IR expression computing the overflow flag bit of an integer addition or subtraction operation.The Overflow flag is used to indicate wrap-around for signed operations.
Note: The generated IR is equivalent to:
MSB((a ^ c) & ~(a ^ b))
for an addition, orMSB((a ^ c) & (a ^ b))
for a subtraction.- Parameters:
a
- operand ab
- operand bresult
- result c, comprising an optional carry flag added beforehandaddition
- true if the overflow is to be computed for "a + b", false for "a - b"- Returns:
- a one-bit overflow flag IR expression
-
isLongImmediate
Determine if the expression is an EImm that can be read as along
primitive.- Parameters:
e
- expression- Returns:
-
isLongImmediate
Determine if the expression is an EImm that can be read as along
primitive.- Parameters:
e
- expressionunsigned
-- Returns:
-
isLikeLongImmediate
Determine if the expression is equivalent to an EImm that can be read as along
primitive.- Parameters:
e
- expression- Returns:
-
isLikeLongImmediate
Determine if the expression is equivalent to an EImm that can be read as along
primitive.- Parameters:
e
- expressionunsigned
-- Returns:
-
isImmediate
Determine if theIEGeneric
is anIEImm
. Use when e can be null, otherwise prefer nativeIEGeneric.isImm()
- Parameters:
e
- IR expression- Returns:
e != null && e.IsImm()
-
isLikeImmediate
Determine if the IRE is an EImm or a slice or composition of immediates.- Parameters:
a
-- Returns:
-
getParents
Retrieve all the parents of a value. The search is done by reference.- Parameters:
expression
- expression to search into.value
- value to be searched.- Returns:
- the list of direct parents.
-
evalAsSaturatedPositiveInt
Evaluate and convert a positive immediate to a 32-bit int. If the immediate is greater thanLong.MAX_VALUE
, the method will throw. It the evaluated value is greater thanInteger.MAX_VALUE
, Integer#MAX_VALUE will be returned.- Parameters:
imm
- immediate to be evaluated- Returns:
- a 32-bit positive or zero int
- See Also:
-
evalAsPositiveInt
Evaluate an immediate to a 32-bit positive int. Apply Integer positive mask is greater thanInteger.MAX_VALUE
.- Parameters:
imm
-- Returns:
-
evaluate_preVerified
-
evaluate_preVerified
-
evaluateUnsignedLong_preVerified
-
evaluateUnsignedLong_preVerified
-
evaluateAddress_preVerified
-
evaluateAddress_preVerified
-
replaceSubExpressionRecursive
-
replaceSubExpressionRecursive
public static IEGeneric replaceSubExpressionRecursive(IEGeneric stm, IEGeneric src, IEGeneric dst, EVisitResults results) -
resolveExpressionsBackward
public static boolean resolveExpressionsBackward(Object name, IEConverter<?> conv, List<IEStatement> r, IEGeneric... targets) Apply a list of IEStatements to user targets, resolving expression starting from lastIEStatement
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
- Parameters:
name
-conv
-r
-targets
-- Returns:
-
isExpressionModified
-
isMatchDuaryOperation
public static boolean isMatchDuaryOperation(IEGeneric e, OperationType wantedOperationType, IEGeneric wantedOperand1, IEGeneric wantedOperand2) -
getAssigningToMemory
Determine if the statement is anIEAssign
to anIEMem
. If so, return the memory target.DST = mXX[???]
- Parameters:
stm
-- Returns:
- a memory IRE or null
-
getAssigningFromMemory
- Parameters:
stm
-- Returns:
- a memory IRE or null
-
hasLinearControlFlow
Checks if an IR routine contains only basic blocks with one parent and one child (no merge or disjunction of control-flow).- Returns:
-
getVars
-
formatVars
-
formatVars
-
isVariableAssigned
- Parameters:
stm
-var
-- Returns:
-
hasTypeInfo
Determine if the provided IR expression embeds some type information. Note that the sub-expressions are not examined.- Parameters:
e
-- Returns:
-
hasNoTypeInfo
Determine if the provided IR expression embeds no amount at all of type information.- Parameters:
e
-- Returns:
-
hasSameType
- Parameters:
e1
-e2
-- Returns:
-
isSameType
- Parameters:
a
-b
-- Returns:
-
getBestType
- Parameters:
a
-b
-- Returns:
-
requiresExplicitCast
Determine if type `b` can be implicitly converted to type `a`, without a cast.- Parameters:
a
-b
-- Returns:
-
getWildcardTypes
public static List<IWildcardType> getWildcardTypes(IWildcardTypeManager etypeman, Collection<IEGeneric> elts) -
gatherArgumentTypes
public static List<IWildcardType> gatherArgumentTypes(IWildcardPrototype prototype, Collection<IWildcardType> varArgTypes) Retrieve the list of input types, by examining the provided prototype and optional list of additional arguments.- Parameters:
prototype
-varArgTypes
- optional; the prototype MUST be marked VarArg for this to not be disregarded- Returns:
-
determineArgumentStackSlotCount
public static int determineArgumentStackSlotCount(IWildcardPrototype prototype, Collection<IWildcardType> varArgTypes) Determine the number of stacks slots used by invoking a method having the provided prototype and an optional list of additional arguments.- Parameters:
prototype
-varArgTypes
- optional; the prototype MUST be marked VarArg for this to not be disregarded- Returns:
-
determineReturnValuesStackSlotCount
public static int determineReturnValuesStackSlotCount(IWildcardPrototype prototype, int inputStackSlotCount) Determine the number of stack slots filled out when a routine with the provided prototype returns.- Parameters:
prototype
-inputStackSlotCount
- the number of stack slots used for input (arguments); depending on the calling convention specified in the prototype, this value may be needed in order to calculate the count correctly- Returns:
-
getAssignmentSource
Retrieve the source of anIEAssign
(or null if is not an assignment).- Parameters:
stm
-- Returns:
-
getAssignmentDestination
Retrieve the destination of anIEAssign
(or null if is not an assignment).- Parameters:
stm
-- Returns:
-
hasNoSideEffect
Determine if an IR expression is side-effect free.This method is taking a liberal approach to side-effects: Side effects include invocations to other routines determined to be non side-effect-free, voluntarily throwing an exception, or performing a memory-access that will trigger an exception.
The opposite of
hasSideEffect(IEGeneric)
.- Parameters:
e
-- Returns:
-
hasSideEffect
The opposite ofhasNoSideEffect(IEGeneric)
.- Parameters:
e
-- Returns:
-
checkCallReturnAddress
public static Boolean checkCallReturnAddress(IERoutineContext ctx, CFG<IEStatement> cfg, BasicBlock<IEStatement> b, int insnIndex) - Parameters:
ctx
-cfg
-b
-insnIndex
-- Returns:
- null if the return address is not set; true if it is an immediate value matching the call expected return address (i.e., following the call instruction itself); false otherwise
-
expandStatementSize
public static CFG<IEStatement> expandStatementSize(IERoutineContext ectx, IEStatement stm0, int minSize) Expand thesize
of a statement.CAREFUL! This method can modify the structure of the CFG (block order, block count, etc.).
- Parameters:
ectx
-stm0
-minSize
-- Returns:
- the resulting CFG (it may be the original CFG)
-
expandStatementSizes
public static CFG<IEStatement> expandStatementSizes(IERoutineContext ectx, Collection<IEStatement> stmcoll, int minSize) Expand thesizes
of a collection of statements.CAREFUL! This method can modify the structure of the CFG (block order, block count, etc.).
- Parameters:
ectx
-stmcoll
-minSize
-- Returns:
- the resulting CFG (it may be the original CFG)
-
adjustBranchToIRInstruction
public static int adjustBranchToIRInstruction(IEStatement stm, int currentTargetIROffset, int newTargetIROffset) -
expandCalls
Call/PC-assign expansion: augment the size to at least 2, to accommodate splitting:
- if an EReturn is to be inserted (tail-calls) in lieu of a ECall
- if a raw PC-assign cannot be converted to a single EJumpFar- Parameters:
ctx
- routine contextalsoExpandPCAssign
- if true, PC-assigns will also be expanded; else, only ECalls are expanded- Returns:
- success indicator
-
setLowerLevelAddress
-
setLowerLevelAddress
public static void setLowerLevelAddress(long addr, List<IEStatement> list, int fromIndex, int toIndex) -
setLowerLevelAddressIfNone
-
setLowerLevelAddressIfNone
public static void setLowerLevelAddressIfNone(long addr, List<IEStatement> list, int fromIndex, int toIndex) -
isLegalSignedImmediate
Verify that the provided immediate is a legal signed value if it were to be treated as a signed integer of `checkedBitsize`.Examples:
the 64-bit value 0x00000000_07FFFFFFF is legal if treated as a 32-bit signed immediate the 64-bit value 0xFFFFFFFF_FFFFE0000 is legal if treated as a 32-bit signed immediate the 64-bit value 0x00000000_87FFFFFFF is ILLEGAL if treated as a 32-bit signed immediate the 64-bit value 0x00100000_000000012 is ILLEGAL if treated as a 32-bit signed immediate the 64-bit value 0xFFFF00FF_FFFFE0000 is ILLEGAL if treated as a 32-bit signed immediate
- Parameters:
v
-checkedBitsize
-- Returns:
-
isLegalUnsignedImmediate
Verify that the provided immediate is a legal unsigned value if it were to be treated as an unsigned integer of `checkedBitsize`.- Parameters:
v
-checkedBitsize
-- Returns:
-