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
9cea0163
Commit
9cea0163
authored
Nov 29, 2014
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: fix BlockNode hashCode function
parent
577176dd
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
127 additions
and
55 deletions
+127
-55
IgnoreEdgeAttr.java
...n/java/jadx/core/dex/attributes/nodes/IgnoreEdgeAttr.java
+1
-1
BlockNode.java
jadx-core/src/main/java/jadx/core/dex/nodes/BlockNode.java
+2
-14
SimplifyVisitor.java
...src/main/java/jadx/core/dex/visitors/SimplifyVisitor.java
+11
-0
BlockFinallyExtract.java
...dx/core/dex/visitors/blocksmaker/BlockFinallyExtract.java
+1
-13
BlockProcessor.java
...va/jadx/core/dex/visitors/blocksmaker/BlockProcessor.java
+32
-26
BlockUtils.java
jadx-core/src/main/java/jadx/core/utils/BlockUtils.java
+20
-0
TestFinallyExtract.java
...a/jadx/tests/integration/trycatch/TestFinallyExtract.java
+0
-1
TestTryCatchFinally2.java
...jadx/tests/integration/trycatch/TestTryCatchFinally2.java
+60
-0
No files found.
jadx-core/src/main/java/jadx/core/dex/attributes/nodes/IgnoreEdgeAttr.java
View file @
9cea0163
...
...
@@ -10,7 +10,7 @@ import java.util.Set;
public
class
IgnoreEdgeAttr
implements
IAttribute
{
private
final
Set
<
BlockNode
>
blocks
=
new
HashSet
<
BlockNode
>();
private
final
Set
<
BlockNode
>
blocks
=
new
HashSet
<
BlockNode
>(
3
);
public
Set
<
BlockNode
>
getBlocks
()
{
return
blocks
;
...
...
jadx-core/src/main/java/jadx/core/dex/nodes/BlockNode.java
View file @
9cea0163
...
...
@@ -179,7 +179,7 @@ public class BlockNode extends AttrNode implements IBlock {
@Override
public
int
hashCode
()
{
return
id
;
// TODO id can change during reindex
return
startOffset
;
}
@Override
...
...
@@ -187,23 +187,11 @@ public class BlockNode extends AttrNode implements IBlock {
if
(
this
==
obj
)
{
return
true
;
}
if
(
obj
==
null
)
{
return
false
;
}
if
(
hashCode
()
!=
obj
.
hashCode
())
{
return
false
;
}
if
(!(
obj
instanceof
BlockNode
))
{
return
false
;
}
BlockNode
other
=
(
BlockNode
)
obj
;
if
(
id
!=
other
.
id
)
{
return
false
;
}
if
(
startOffset
!=
other
.
startOffset
)
{
return
false
;
}
return
true
;
return
id
==
other
.
id
&&
startOffset
==
other
.
startOffset
;
}
@Override
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/SimplifyVisitor.java
View file @
9cea0163
...
...
@@ -86,6 +86,17 @@ public class SimplifyVisitor extends AbstractVisitor {
}
break
;
case
MOVE:
InsnArg
firstArg
=
insn
.
getArg
(
0
);
if
(
firstArg
.
isLiteral
())
{
InsnNode
constInsn
=
new
InsnNode
(
InsnType
.
CONST
,
1
);
constInsn
.
setResult
(
insn
.
getResult
());
constInsn
.
addArg
(
firstArg
);
constInsn
.
copyAttributesFrom
(
insn
);
return
constInsn
;
}
break
;
default
:
break
;
}
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/blocksmaker/BlockFinallyExtract.java
View file @
9cea0163
...
...
@@ -359,7 +359,7 @@ public class BlockFinallyExtract extends AbstractVisitor {
BlockNode
sOut
=
out
.
getSecond
();
// redirect out edges
List
<
BlockNode
>
filtPreds
=
filterPredecessors
(
sOut
);
List
<
BlockNode
>
filtPreds
=
BlockUtils
.
filterPredecessors
(
sOut
);
if
(
filtPreds
.
size
()
>
1
)
{
BlockNode
pred
=
sOut
.
getPredecessors
().
get
(
0
);
BlockNode
newPred
=
BlockSplitter
.
insertBlockBetween
(
mth
,
pred
,
sOut
);
...
...
@@ -446,18 +446,6 @@ public class BlockFinallyExtract extends AbstractVisitor {
edgeAttr
.
getBlocks
().
add
(
toBlock
);
}
private
static
List
<
BlockNode
>
filterPredecessors
(
BlockNode
block
)
{
List
<
BlockNode
>
predecessors
=
block
.
getPredecessors
();
List
<
BlockNode
>
list
=
new
ArrayList
<
BlockNode
>(
predecessors
.
size
());
for
(
BlockNode
pred
:
predecessors
)
{
IgnoreEdgeAttr
edgeAttr
=
pred
.
get
(
AType
.
IGNORE_EDGE
);
if
(
edgeAttr
==
null
||
!
edgeAttr
.
contains
(
block
))
{
list
.
add
(
pred
);
}
}
return
list
;
}
private
static
int
countInstructions
(
ExceptionHandler
excHandler
)
{
int
totalSize
=
0
;
for
(
BlockNode
excBlock
:
excHandler
.
getBlocks
())
{
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/blocksmaker/BlockProcessor.java
View file @
9cea0163
...
...
@@ -315,34 +315,40 @@ public class BlockProcessor extends AbstractVisitor {
return
false
;
}
BlockNode
exitBlock
=
mth
.
getExitBlocks
().
get
(
0
);
if
(
exitBlock
.
getPredecessors
().
size
()
>
1
&&
exitBlock
.
getInstructions
().
size
()
==
1
&&
!
exitBlock
.
contains
(
AFlag
.
SYNTHETIC
))
{
InsnNode
returnInsn
=
exitBlock
.
getInstructions
().
get
(
0
);
List
<
BlockNode
>
preds
=
new
ArrayList
<
BlockNode
>(
exitBlock
.
getPredecessors
());
if
(
returnInsn
.
getArgsCount
()
!=
0
&&
!
isReturnArgAssignInPred
(
preds
,
returnInsn
))
{
return
false
;
}
boolean
first
=
true
;
for
(
BlockNode
pred
:
preds
)
{
BlockNode
newRetBlock
=
BlockSplitter
.
startNewBlock
(
mth
,
exitBlock
.
getStartOffset
());
newRetBlock
.
add
(
AFlag
.
SYNTHETIC
);
InsnNode
newRetInsn
;
if
(
first
)
{
newRetInsn
=
returnInsn
;
newRetBlock
.
add
(
AFlag
.
ORIG_RETURN
);
first
=
false
;
}
else
{
newRetInsn
=
duplicateReturnInsn
(
returnInsn
);
}
newRetBlock
.
getInstructions
().
add
(
newRetInsn
);
removeConnection
(
pred
,
exitBlock
);
connect
(
pred
,
newRetBlock
);
if
(
exitBlock
.
getInstructions
().
size
()
!=
1
||
exitBlock
.
contains
(
AFlag
.
SYNTHETIC
))
{
return
false
;
}
List
<
BlockNode
>
preds
=
exitBlock
.
getPredecessors
();
if
(
preds
.
size
()
<
2
)
{
return
false
;
}
preds
=
BlockUtils
.
filterPredecessors
(
exitBlock
);
if
(
preds
.
size
()
<
2
)
{
return
false
;
}
InsnNode
returnInsn
=
exitBlock
.
getInstructions
().
get
(
0
);
if
(
returnInsn
.
getArgsCount
()
!=
0
&&
!
isReturnArgAssignInPred
(
preds
,
returnInsn
))
{
return
false
;
}
boolean
first
=
true
;
for
(
BlockNode
pred
:
preds
)
{
BlockNode
newRetBlock
=
BlockSplitter
.
startNewBlock
(
mth
,
exitBlock
.
getStartOffset
());
newRetBlock
.
add
(
AFlag
.
SYNTHETIC
);
InsnNode
newRetInsn
;
if
(
first
)
{
newRetInsn
=
returnInsn
;
newRetBlock
.
add
(
AFlag
.
ORIG_RETURN
);
first
=
false
;
}
else
{
newRetInsn
=
duplicateReturnInsn
(
returnInsn
);
}
cleanExitNodes
(
mth
);
return
true
;
newRetBlock
.
getInstructions
().
add
(
newRetInsn
);
removeConnection
(
pred
,
exitBlock
);
connect
(
pred
,
newRetBlock
);
}
return
false
;
cleanExitNodes
(
mth
);
return
true
;
}
private
static
boolean
isReturnArgAssignInPred
(
List
<
BlockNode
>
preds
,
InsnNode
returnInsn
)
{
...
...
jadx-core/src/main/java/jadx/core/utils/BlockUtils.java
View file @
9cea0163
...
...
@@ -2,6 +2,7 @@ package jadx.core.utils;
import
jadx.core.dex.attributes.AFlag
;
import
jadx.core.dex.attributes.AType
;
import
jadx.core.dex.attributes.nodes.IgnoreEdgeAttr
;
import
jadx.core.dex.attributes.nodes.PhiListAttr
;
import
jadx.core.dex.instructions.IfNode
;
import
jadx.core.dex.instructions.InsnType
;
...
...
@@ -79,6 +80,25 @@ public class BlockUtils {
return
ret
;
}
/**
* Return predecessors list without blocks contains 'IGNORE_EDGE' attribute.
*
* @return new list of filtered predecessors
*/
public
static
List
<
BlockNode
>
filterPredecessors
(
BlockNode
block
)
{
List
<
BlockNode
>
predecessors
=
block
.
getPredecessors
();
List
<
BlockNode
>
list
=
new
ArrayList
<
BlockNode
>(
predecessors
.
size
());
for
(
BlockNode
pred
:
predecessors
)
{
IgnoreEdgeAttr
edgeAttr
=
pred
.
get
(
AType
.
IGNORE_EDGE
);
if
(
edgeAttr
==
null
)
{
list
.
add
(
pred
);
}
else
if
(!
edgeAttr
.
contains
(
block
))
{
list
.
add
(
pred
);
}
}
return
list
;
}
public
static
boolean
isBackEdge
(
BlockNode
from
,
BlockNode
to
)
{
if
(
to
==
null
)
{
return
false
;
...
...
jadx-core/src/test/java/jadx/tests/integration/trycatch/TestFinallyExtract.java
View file @
9cea0163
...
...
@@ -30,7 +30,6 @@ public class TestFinallyExtract extends IntegrationTest {
@Test
public
void
test
()
{
setOutputCFG
();
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
...
...
jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally2.java
0 → 100644
View file @
9cea0163
package
jadx
.
tests
.
integration
.
trycatch
;
import
jadx.core.clsp.NClass
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.tests.api.IntegrationTest
;
import
java.io.DataOutputStream
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
org.junit.Test
;
import
static
jadx
.
tests
.
api
.
utils
.
JadxMatchers
.
containsOne
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TestTryCatchFinally2
extends
IntegrationTest
{
public
static
class
TestCls
{
private
NClass
[]
classes
;
public
void
test
(
OutputStream
output
)
throws
IOException
{
DataOutputStream
out
=
new
DataOutputStream
(
output
);
try
{
out
.
writeByte
(
1
);
out
.
writeInt
(
classes
.
length
);
for
(
NClass
cls
:
classes
)
{
writeString
(
out
,
cls
.
getName
());
}
for
(
NClass
cls
:
classes
)
{
NClass
[]
parents
=
cls
.
getParents
();
out
.
writeByte
(
parents
.
length
);
for
(
NClass
parent
:
parents
)
{
out
.
writeInt
(
parent
.
getId
());
}
}
}
finally
{
out
.
close
();
}
}
private
void
writeString
(
DataOutputStream
out
,
String
name
)
{
}
}
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsOne
(
"} finally {"
));
assertThat
(
code
,
containsOne
(
"out.close();"
));
assertThat
(
code
,
containsOne
(
"for (NClass parent : parents) {"
));
// TODO
// assertThat(code, countString(2, "for (NClass cls : classes) {"));
assertThat
(
code
,
containsOne
(
"for (NClass cls : this.classes) {"
));
assertThat
(
code
,
containsOne
(
"for (NClass cls2 : this.classes) {"
));
}
}
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