Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
J
jadx
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
jadx
Commits
bae7f1b0
Commit
bae7f1b0
authored
Apr 02, 2019
by
Ahmed Ashour
Committed by
skylot
Apr 02, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: field increment (PR #550)
parent
e6e8f636
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
10 deletions
+24
-10
SimplifyVisitor.java
...src/main/java/jadx/core/dex/visitors/SimplifyVisitor.java
+24
-0
TestFieldIncrement2.java
...ava/jadx/tests/integration/arith/TestFieldIncrement2.java
+0
-10
No files found.
jadx-core/src/main/java/jadx/core/dex/visitors/SimplifyVisitor.java
View file @
bae7f1b0
...
@@ -49,12 +49,36 @@ public class SimplifyVisitor extends AbstractVisitor {
...
@@ -49,12 +49,36 @@ public class SimplifyVisitor extends AbstractVisitor {
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
InsnNode
modInsn
=
simplifyInsn
(
mth
,
list
.
get
(
i
));
InsnNode
modInsn
=
simplifyInsn
(
mth
,
list
.
get
(
i
));
if
(
modInsn
!=
null
)
{
if
(
modInsn
!=
null
)
{
if
(
i
!=
0
&&
modInsn
.
contains
(
AFlag
.
ARITH_ONEARG
))
{
InsnNode
mergedNode
=
simplifyOneArgConsecutive
(
list
.
get
(
i
-
1
),
list
.
get
(
i
),
(
ArithNode
)
modInsn
);
if
(
mergedNode
!=
null
)
{
list
.
remove
(
i
-
1
);
modInsn
=
mergedNode
;
i
--;
}
}
list
.
set
(
i
,
modInsn
);
list
.
set
(
i
,
modInsn
);
}
}
}
}
}
}
}
}
private
static
InsnNode
simplifyOneArgConsecutive
(
InsnNode
insn1
,
InsnNode
insn2
,
ArithNode
modInsn
)
{
if
(
insn1
.
getType
()
==
InsnType
.
IGET
&&
insn2
.
getType
()
==
InsnType
.
IPUT
&&
insn1
.
getResult
().
getSVar
().
getUseCount
()
==
2
&&
insn2
.
getArg
(
1
).
equals
(
insn1
.
getResult
()))
{
FieldInfo
field
=
(
FieldInfo
)
((
IndexInsnNode
)
insn2
).
getIndex
();
FieldArg
fArg
=
new
FieldArg
(
field
,
new
InsnWrapArg
(
insn1
));
return
new
ArithNode
(
modInsn
.
getOp
(),
fArg
,
modInsn
.
getArg
(
1
));
}
return
null
;
}
private
static
InsnNode
simplifyInsn
(
MethodNode
mth
,
InsnNode
insn
)
{
private
static
InsnNode
simplifyInsn
(
MethodNode
mth
,
InsnNode
insn
)
{
if
(
insn
.
contains
(
AFlag
.
DONT_GENERATE
))
{
if
(
insn
.
contains
(
AFlag
.
DONT_GENERATE
))
{
return
null
;
return
null
;
...
...
jadx-core/src/test/java/jadx/tests/integration/arith/TestFieldIncrement2.java
View file @
bae7f1b0
...
@@ -2,7 +2,6 @@ package jadx.tests.integration.arith;
...
@@ -2,7 +2,6 @@ package jadx.tests.integration.arith;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
jadx.NotYetImplemented
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.tests.api.IntegrationTest
;
import
jadx.tests.api.IntegrationTest
;
...
@@ -33,15 +32,6 @@ public class TestFieldIncrement2 extends IntegrationTest {
...
@@ -33,15 +32,6 @@ public class TestFieldIncrement2 extends IntegrationTest {
String
code
=
cls
.
getCode
().
toString
();
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsString
(
"this.a.f += n;"
));
assertThat
(
code
,
containsString
(
"this.a.f += n;"
));
assertThat
(
code
,
containsString
(
"a2.f *= n;"
));
}
@Test
@NotYetImplemented
public
void
test2
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsString
(
"this.a.f *= n;"
));
assertThat
(
code
,
containsString
(
"this.a.f *= n;"
));
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment