FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
jeb-samplecode/plugins/scripts/DOptStringSimplifier.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
/
DOptStringSimplifier.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
76 lines (69 loc) · 3.02 KB
Breadcrumbs
jeb-samplecode
/
plugins
/
scripts
/
DOptStringSimplifier.java
Copy path
File metadata and controls
76 lines (69 loc) · 3.02 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//?type=dexdec-ir
import
com
.
pnfsoftware
.
jeb
.
core
.
units
.
code
.
android
.
controlflow
.
BasicBlock
;
import
com
.
pnfsoftware
.
jeb
.
core
.
units
.
code
.
android
.
ir
.
IDVisitor
;
import
com
.
pnfsoftware
.
jeb
.
core
.
units
.
code
.
android
.
ir
.
AbstractDOptimizer
;
import
com
.
pnfsoftware
.
jeb
.
core
.
units
.
code
.
android
.
ir
.
IDCallInfo
;
import
com
.
pnfsoftware
.
jeb
.
core
.
units
.
code
.
android
.
ir
.
IDExpression
;
import
com
.
pnfsoftware
.
jeb
.
core
.
units
.
code
.
android
.
ir
.
IDImm
;
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
;
import
com
.
pnfsoftware
.
jeb
.
core
.
units
.
code
.
java
.
JavaOperatorType
;
/**
* (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 useless calls to {@code String.valueOf}.
*
* <pre>
* String.valueOf(some_string)
*
* => (simplified to)
*
* some_string
* </pre>
*
* @author Nicolas Falliere
*
*/
public
class
DOptStringSimplifier
extends
AbstractDOptimizer
{
private
static
final
String
msig0
=
"Ljava/lang/String;->valueOf(Ljava/lang/Object;)Ljava/lang/String;"
;
private
int
totalcnt
;
@
Override
public
int
perform
() {
totalcnt
=
0
;
for
(
int
iblk
=
0
;
iblk
<
cfg
.
size
();
iblk
++) {
BasicBlock
<
IDInstruction
>
b
=
cfg
.
get
(
iblk
);
for
(
int
i
=
0
;
i
<
b
.
size
();
i
++) {
IDInstruction
insn
=
b
.
get
(
i
);
insn
.
visitDepthPost
(
new
IDVisitor
() {
@
Override
public
void
process
(
IDExpression
e
,
IDExpression
parent
,
IVisitResults
<
IDExpression
>
results
) {
if
(
e
instanceof
IDCallInfo
&&
msig0
.
equals
(((
IDCallInfo
)
e
).
getMethodSignature
())) {
IDExpression
arg0
= ((
IDCallInfo
)
e
).
getArgument
(
0
);
boolean
proceed
=
false
;
if
(
arg0
instanceof
IDImm
&& ((
IDImm
)
arg0
).
isString
()) {
proceed
=
true
;
}
else
if
(
arg0
instanceof
IDOperation
&& ((
IDOperation
)
arg0
).
getOperator
().
is
(
JavaOperatorType
.
CONCAT
)) {
proceed
=
true
;
}
if
(
arg0
instanceof
IDCallInfo
&& ((
IDCallInfo
)
arg0
).
getMethodSignature
().
endsWith
(
")Ljava/lang/String;"
)) {
proceed
=
true
;
}
if
(
proceed
) {
if
(
parent
.
replaceSubExpression
(
e
,
arg0
)) {
totalcnt
++;
}
}
}
}
});
}
}
return
totalcnt
;
}
}
Back
|
FazBrowse Home
|
New Git URL