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
2b7f8931
Commit
2b7f8931
authored
Feb 21, 2015
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: fix source line for some return instructions
parent
ec3b71e5
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
104 additions
and
20 deletions
+104
-20
CodeShrinker.java
...re/src/main/java/jadx/core/dex/visitors/CodeShrinker.java
+21
-12
ConstInlinerVisitor.java
...main/java/jadx/core/dex/visitors/ConstInlinerVisitor.java
+6
-5
TestTernary3.java
.../java/jadx/tests/integration/conditions/TestTernary3.java
+2
-3
TestReturnSourceLine.java
...adx/tests/integration/debuginfo/TestReturnSourceLine.java
+75
-0
No files found.
jadx-core/src/main/java/jadx/core/dex/visitors/CodeShrinker.java
View file @
2b7f8931
...
...
@@ -249,19 +249,28 @@ public class CodeShrinker extends AbstractVisitor {
private
static
boolean
inline
(
RegisterArg
arg
,
InsnNode
insn
,
@Nullable
BlockNode
block
,
MethodNode
mth
)
{
InsnNode
parentInsn
=
arg
.
getParentInsn
();
// replace move instruction if needed
if
(
parentInsn
!=
null
&&
parentInsn
.
getType
()
==
InsnType
.
MOVE
)
{
if
(
block
==
null
)
{
block
=
BlockUtils
.
getBlockByInsn
(
mth
,
parentInsn
);
}
if
(
block
!=
null
)
{
int
index
=
InsnList
.
getIndex
(
block
.
getInstructions
(),
parentInsn
);
if
(
index
!=
-
1
)
{
insn
.
setResult
(
parentInsn
.
getResult
());
insn
.
copyAttributesFrom
(
parentInsn
);
insn
.
setOffset
(
parentInsn
.
getOffset
());
if
(
parentInsn
!=
null
)
{
switch
(
parentInsn
.
getType
())
{
case
MOVE:
{
if
(
block
==
null
)
{
block
=
BlockUtils
.
getBlockByInsn
(
mth
,
parentInsn
);
}
if
(
block
!=
null
)
{
int
index
=
InsnList
.
getIndex
(
block
.
getInstructions
(),
parentInsn
);
if
(
index
!=
-
1
)
{
insn
.
setResult
(
parentInsn
.
getResult
());
insn
.
copyAttributesFrom
(
parentInsn
);
insn
.
setOffset
(
parentInsn
.
getOffset
());
block
.
getInstructions
().
set
(
index
,
insn
);
return
true
;
block
.
getInstructions
().
set
(
index
,
insn
);
return
true
;
}
}
break
;
}
case
RETURN:
{
parentInsn
.
setSourceLine
(
insn
.
getSourceLine
());
break
;
}
}
}
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/ConstInlinerVisitor.java
View file @
2b7f8931
...
...
@@ -69,7 +69,7 @@ public class ConstInlinerVisitor extends AbstractVisitor {
if
(!
arg
.
getType
().
isTypeKnown
())
{
arg
.
merge
(
resType
);
}
return
replaceConst
(
mth
,
sVar
,
lit
);
return
replaceConst
(
mth
,
insn
,
lit
);
}
/**
...
...
@@ -98,13 +98,11 @@ public class ConstInlinerVisitor extends AbstractVisitor {
return
false
;
}
private
static
boolean
replaceConst
(
MethodNode
mth
,
SSAVar
sVar
,
long
literal
)
{
private
static
boolean
replaceConst
(
MethodNode
mth
,
InsnNode
constInsn
,
long
literal
)
{
SSAVar
sVar
=
constInsn
.
getResult
().
getSVar
();
List
<
RegisterArg
>
use
=
new
ArrayList
<
RegisterArg
>(
sVar
.
getUseList
());
int
replaceCount
=
0
;
for
(
RegisterArg
arg
:
use
)
{
// if (arg.getSVar().isUsedInPhi()) {
// continue;
// }
InsnNode
useInsn
=
arg
.
getParentInsn
();
if
(
useInsn
==
null
||
useInsn
.
getType
()
==
InsnType
.
PHI
)
{
continue
;
...
...
@@ -125,6 +123,9 @@ public class ConstInlinerVisitor extends AbstractVisitor {
if
(
useInsn
.
replaceArg
(
arg
,
litArg
))
{
fixTypes
(
mth
,
useInsn
,
litArg
);
replaceCount
++;
if
(
useInsn
.
getType
()
==
InsnType
.
RETURN
)
{
useInsn
.
setSourceLine
(
constInsn
.
getSourceLine
());
}
FieldNode
f
=
null
;
ArgType
litArgType
=
litArg
.
getType
();
...
...
jadx-core/src/test/java/jadx/tests/integration/conditions/TestTernary3.java
View file @
2b7f8931
...
...
@@ -41,9 +41,8 @@ public class TestTernary3 extends IntegrationTest {
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
// TODO:
assertThat
(
code
,
containsOne
(
"return (n == null || !(arg instanceof Named)) "
+
"? false : n.equals(((Named) arg).getName());"
));
assertThat
(
code
,
containsOne
(
"if (n == null || !(arg instanceof Named)) {"
));
assertThat
(
code
,
containsOne
(
"return n.equals(((Named) arg).getName());"
));
assertThat
(
code
,
not
(
containsString
(
"if ((arg instanceof RegisterArg)) {"
)));
}
...
...
jadx-core/src/test/java/jadx/tests/integration/debuginfo/TestReturnSourceLine.java
0 → 100644
View file @
2b7f8931
package
jadx
.
tests
.
integration
.
debuginfo
;
import
jadx.core.codegen.CodeWriter
;
import
jadx.core.dex.attributes.nodes.LineAttrNode
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.core.dex.nodes.MethodNode
;
import
jadx.tests.api.IntegrationTest
;
import
org.junit.Test
;
import
static
jadx
.
tests
.
api
.
utils
.
JadxMatchers
.
containsOne
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TestReturnSourceLine
extends
IntegrationTest
{
public
static
class
TestCls
{
public
int
test1
(
boolean
v
)
{
if
(
v
)
{
f
();
return
1
;
}
f
();
return
0
;
}
public
int
test2
(
int
v
)
{
if
(
v
==
0
)
{
f
();
return
v
-
1
;
}
f
();
return
v
+
1
;
}
public
int
test3
(
int
v
)
{
if
(
v
==
0
)
{
f
();
return
v
;
}
f
();
return
v
+
1
;
}
private
void
f
()
{
}
}
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
CodeWriter
codeWriter
=
cls
.
getCode
();
String
code
=
codeWriter
.
toString
();
String
[]
lines
=
code
.
split
(
CodeWriter
.
NL
);
MethodNode
test1
=
cls
.
searchMethodByName
(
"test1(Z)I"
);
checkLine
(
lines
,
codeWriter
,
test1
,
3
,
"return 1;"
);
MethodNode
test2
=
cls
.
searchMethodByName
(
"test2(I)I"
);
checkLine
(
lines
,
codeWriter
,
test2
,
3
,
"return v - 1;"
);
// TODO:
// MethodNode test3 = cls.searchMethodByName("test3(I)I");
// checkLine(lines, codeWriter, test3, 3, "return v;");
}
private
static
void
checkLine
(
String
[]
lines
,
CodeWriter
cw
,
LineAttrNode
node
,
int
offset
,
String
str
)
{
int
decompiledLine
=
node
.
getDecompiledLine
()
+
offset
;
assertThat
(
lines
[
decompiledLine
-
1
],
containsOne
(
str
));
Integer
sourceLine
=
cw
.
getLineMapping
().
get
(
decompiledLine
);
assertNotNull
(
sourceLine
);
assertEquals
(
node
.
getSourceLine
()
+
offset
,
(
int
)
sourceLine
);
}
}
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