Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
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
3d0c6e49
Commit
3d0c6e49
authored
Mar 10, 2014
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: fix inline in 'move' instruction
parent
03da35b2
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
9 deletions
+39
-9
InsnNode.java
jadx-core/src/main/java/jadx/core/dex/nodes/InsnNode.java
+3
-5
PrepareForCodeGen.java
...c/main/java/jadx/core/dex/visitors/PrepareForCodeGen.java
+31
-2
TestArgInline.java
...core/src/test/java/jadx/tests/internal/TestArgInline.java
+5
-2
No files found.
jadx-core/src/main/java/jadx/core/dex/nodes/InsnNode.java
View file @
3d0c6e49
...
@@ -24,10 +24,6 @@ public class InsnNode extends LineAttrNode {
...
@@ -24,10 +24,6 @@ public class InsnNode extends LineAttrNode {
protected
int
offset
;
protected
int
offset
;
protected
int
insnHashCode
=
super
.
hashCode
();
protected
int
insnHashCode
=
super
.
hashCode
();
protected
InsnNode
(
InsnType
type
)
{
this
(
type
,
1
);
}
public
InsnNode
(
InsnType
type
,
int
argsCount
)
{
public
InsnNode
(
InsnType
type
,
int
argsCount
)
{
this
.
insnType
=
type
;
this
.
insnType
=
type
;
this
.
offset
=
-
1
;
this
.
offset
=
-
1
;
...
@@ -155,9 +151,11 @@ public class InsnNode extends LineAttrNode {
...
@@ -155,9 +151,11 @@ public class InsnNode extends LineAttrNode {
case
STR_CONCAT:
case
STR_CONCAT:
case
MOVE_EXCEPTION:
case
MOVE_EXCEPTION:
return
true
;
return
true
;
}
default
:
return
false
;
return
false
;
}
}
}
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/PrepareForCodeGen.java
View file @
3d0c6e49
...
@@ -16,6 +16,11 @@ import jadx.core.utils.exceptions.JadxException;
...
@@ -16,6 +16,11 @@ import jadx.core.utils.exceptions.JadxException;
import
java.util.Iterator
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.List
;
/**
* Prepare instructions for code generation pass,
* most of this modification breaks register dependencies,
* so this pass must be just before CodeGen.
*/
public
class
PrepareForCodeGen
extends
AbstractVisitor
{
public
class
PrepareForCodeGen
extends
AbstractVisitor
{
@Override
@Override
...
@@ -26,7 +31,8 @@ public class PrepareForCodeGen extends AbstractVisitor {
...
@@ -26,7 +31,8 @@ public class PrepareForCodeGen extends AbstractVisitor {
}
}
for
(
BlockNode
block
:
blocks
)
{
for
(
BlockNode
block
:
blocks
)
{
removeInstructions
(
block
);
removeInstructions
(
block
);
removeBrackets
(
block
);
checkInline
(
block
);
removeParenthesis
(
block
);
modifyArith
(
block
);
modifyArith
(
block
);
}
}
}
}
...
@@ -52,12 +58,31 @@ public class PrepareForCodeGen extends AbstractVisitor {
...
@@ -52,12 +58,31 @@ public class PrepareForCodeGen extends AbstractVisitor {
}
}
}
}
private
static
void
removeBrackets
(
BlockNode
block
)
{
private
static
void
checkInline
(
BlockNode
block
)
{
List
<
InsnNode
>
list
=
block
.
getInstructions
();
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
InsnNode
insn
=
list
.
get
(
i
);
// replace 'move' with inner wrapped instruction
if
(
insn
.
getType
()
==
InsnType
.
MOVE
&&
insn
.
getArg
(
0
).
isInsnWrap
()
&&
!
insn
.
getAttributes
().
contains
(
AttributeFlag
.
DECLARE_VAR
))
{
InsnNode
wrapInsn
=
((
InsnWrapArg
)
insn
.
getArg
(
0
)).
getWrapInsn
();
wrapInsn
.
setResult
(
insn
.
getResult
());
list
.
set
(
i
,
wrapInsn
);
}
}
}
private
static
void
removeParenthesis
(
BlockNode
block
)
{
for
(
InsnNode
insn
:
block
.
getInstructions
())
{
for
(
InsnNode
insn
:
block
.
getInstructions
())
{
checkInsn
(
insn
);
checkInsn
(
insn
);
}
}
}
}
/**
* Remove parenthesis for wrapped insn in arith '+' or '-'
* ('(a + b) +c' => 'a + b + c')
*/
private
static
void
checkInsn
(
InsnNode
insn
)
{
private
static
void
checkInsn
(
InsnNode
insn
)
{
if
(
insn
.
getType
()
==
InsnType
.
ARITH
)
{
if
(
insn
.
getType
()
==
InsnType
.
ARITH
)
{
ArithNode
arith
=
(
ArithNode
)
insn
;
ArithNode
arith
=
(
ArithNode
)
insn
;
...
@@ -82,6 +107,10 @@ public class PrepareForCodeGen extends AbstractVisitor {
...
@@ -82,6 +107,10 @@ public class PrepareForCodeGen extends AbstractVisitor {
}
}
}
}
/**
* Replace arithmetic operation with short form
* ('a = a + 2' => 'a += 2')
*/
private
static
void
modifyArith
(
BlockNode
block
)
{
private
static
void
modifyArith
(
BlockNode
block
)
{
List
<
InsnNode
>
list
=
block
.
getInstructions
();
List
<
InsnNode
>
list
=
block
.
getInstructions
();
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
...
...
jadx-core/src/test/java/jadx/tests/internal/TestArgInline.java
View file @
3d0c6e49
...
@@ -3,6 +3,8 @@ package jadx.tests.internal;
...
@@ -3,6 +3,8 @@ package jadx.tests.internal;
import
jadx.api.InternalJadxTest
;
import
jadx.api.InternalJadxTest
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.core.dex.nodes.ClassNode
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
import
static
org
.
hamcrest
.
CoreMatchers
.
not
;
import
static
org
.
hamcrest
.
CoreMatchers
.
not
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertThat
;
...
@@ -19,12 +21,13 @@ public class TestArgInline extends InternalJadxTest {
...
@@ -19,12 +21,13 @@ public class TestArgInline extends InternalJadxTest {
}
}
}
}
//
@Test
@Test
public
void
test
()
{
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
String
code
=
cls
.
getCode
().
toString
();
System
.
out
.
println
(
code
);
System
.
out
.
println
(
code
);
assertThat
(
code
,
not
(
containsString
(
"a = a + 1;"
)));
assertThat
(
code
,
containsString
(
"a++;"
));
assertThat
(
code
,
containsString
(
"a++;"
));
assertThat
(
code
,
not
(
containsString
(
"a = a + 1;"
)));
}
}
}
}
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