FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
jeb-samplecode/plugins/scripts/DOptCleanCondExpr.java at master · pnfsoftware/jeb-samplecode · GitHub
pnfsoftware
jeb-samplecode
Repository navigation
Code
Pull requests
3
(3)
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
jeb-samplecode
/
plugins
/
scripts
/
DOptCleanCondExpr.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
61 lines (57 loc) · 2.11 KB
Breadcrumbs
jeb-samplecode
/
plugins
/
scripts
/
DOptCleanCondExpr.java
Copy path
File metadata and controls
61 lines (57 loc) · 2.11 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//?type=dexdec-ir
import
com
.
pnfsoftware
.
jeb
.
core
.
units
.
code
.
android
.
ir
.
AbstractDOptimizer
;
import
com
.
pnfsoftware
.
jeb
.
core
.
units
.
code
.
android
.
ir
.
IDVisitor
;
import
com
.
pnfsoftware
.
jeb
.
core
.
units
.
code
.
android
.
ir
.
IDExpression
;
import
com
.
pnfsoftware
.
jeb
.
core
.
units
.
code
.
android
.
ir
.
IDInstruction
;
import
com
.
pnfsoftware
.
jeb
.
core
.
units
.
code
.
android
.
ir
.
IDOperation
;
import
com
.
pnfsoftware
.
jeb
.
core
.
units
.
code
.
asm
.
decompiler
.
IVisitResults
;
/**
* (NOTE: Sample IR optimizer plugin for JEB's dexdec. A variant of this plugin is shipping as a dexdec built-in.
* As such, there is no need to enable this sample as it is. Its goal is to showcase parts of dexdec IR API for
* learning and experimental purposes.)
* <p>
* Simplify conditional expressions where both alternatives are the same.
* <p>
* Example:
*
* <pre>
* COND ? X: X // COND has no side-effect
*
* =>
*
* X
* </pre>
*
* NOTE: gendec: see EOptUselessCondRem
*
* @author Nicolas Falliere
*
*/
public
class
DOptCleanCondExpr
extends
AbstractDOptimizer
{
private
int
totalcnt
;
@
Override
public
int
perform
() {
totalcnt
=
0
;
for
(
IDInstruction
insn
:
cfg
.
instructions
()) {
insn
.
visitInstructionPostOrder
(
new
IDVisitor
() {
@
Override
public
void
process
(
IDExpression
e
,
IDExpression
parent
,
IVisitResults
<
IDExpression
>
results
) {
if
(
e
instanceof
IDOperation
&& ((
IDOperation
)
e
).
isConditional
()) {
IDExpression
eP
= ((
IDOperation
)
e
).
getCondPredicate
();
IDExpression
eT
= ((
IDOperation
)
e
).
getCondTrueExpression
();
IDExpression
eR
= ((
IDOperation
)
e
).
getCondFalseExpression
();
if
(
eT
.
equalsEx
(
eR
,
false
) && !
eP
.
hasSideEffects
(
ctx
,
true
)) {
if
(
parent
.
replaceSubExpression
(
e
,
eT
)) {
totalcnt
++;
}
}
}
}
},
true
);
}
if
(
totalcnt
>
0
) {
cfg
.
invalidateDataFlowAnalysis
();
}
return
totalcnt
;
}
}
Back
|
FazBrowse Home
|
New Git URL