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
eadf046b
Commit
eadf046b
authored
Dec 25, 2018
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: show try/catch processing problems in code comments
parent
e9591efd
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
61 additions
and
44 deletions
+61
-44
SplitterBlockAttr.java
...c/main/java/jadx/core/dex/trycatch/SplitterBlockAttr.java
+1
-1
BlockFinish.java
.../java/jadx/core/dex/visitors/blocksmaker/BlockFinish.java
+3
-3
CheckRegions.java
...ain/java/jadx/core/dex/visitors/regions/CheckRegions.java
+1
-1
ProcessTryCatchRegions.java
...adx/core/dex/visitors/regions/ProcessTryCatchRegions.java
+29
-25
RegionMaker.java
...main/java/jadx/core/dex/visitors/regions/RegionMaker.java
+7
-7
BaseExternalTest.java
...e/src/test/java/jadx/tests/external/BaseExternalTest.java
+20
-7
No files found.
jadx-core/src/main/java/jadx/core/dex/trycatch/SplitterBlockAttr.java
View file @
eadf046b
...
...
@@ -23,6 +23,6 @@ public class SplitterBlockAttr implements IAttribute {
@Override
public
String
toString
()
{
return
"Splitter:
"
+
block
;
return
"Splitter:"
+
block
;
}
}
jadx-core/src/main/java/jadx/core/dex/visitors/blocksmaker/BlockFinish.java
View file @
eadf046b
...
...
@@ -26,7 +26,7 @@ public class BlockFinish extends AbstractVisitor {
for
(
BlockNode
block
:
mth
.
getBasicBlocks
())
{
block
.
updateCleanSuccessors
();
fixSplitterBlock
(
block
);
fixSplitterBlock
(
mth
,
block
);
}
mth
.
finishBasicBlocks
();
...
...
@@ -36,7 +36,7 @@ public class BlockFinish extends AbstractVisitor {
* For evey exception handler must be only one splitter block,
* select correct one and remove others if necessary.
*/
private
static
void
fixSplitterBlock
(
BlockNode
block
)
{
private
static
void
fixSplitterBlock
(
MethodNode
mth
,
BlockNode
block
)
{
ExcHandlerAttr
excHandlerAttr
=
block
.
get
(
AType
.
EXC_HANDLER
);
if
(
excHandlerAttr
==
null
)
{
return
;
...
...
@@ -58,7 +58,7 @@ public class BlockFinish extends AbstractVisitor {
}
BlockNode
topSplitter
=
BlockUtils
.
getTopBlock
(
splitters
.
keySet
());
if
(
topSplitter
==
null
)
{
LOG
.
warn
(
"Unknown top splitter block from list: {}"
,
splitters
);
mth
.
addWarn
(
"Unknown top exception splitter block from list: "
+
splitters
);
return
;
}
for
(
Map
.
Entry
<
BlockNode
,
SplitterBlockAttr
>
entry
:
splitters
.
entrySet
())
{
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/regions/CheckRegions.java
View file @
eadf046b
...
...
@@ -60,7 +60,7 @@ public class CheckRegions extends AbstractVisitor {
&&
!
block
.
getInstructions
().
isEmpty
()
&&
!
block
.
contains
(
AFlag
.
SKIP
))
{
String
blockCode
=
getBlockInsnStr
(
mth
,
block
);
mth
.
addWarn
(
"Missing block: "
+
block
+
", code:"
+
CodeWriter
.
NL
+
blockCode
);
mth
.
addWarn
(
"Missing block: "
+
block
+
", code
skipped
:"
+
CodeWriter
.
NL
+
blockCode
);
}
}
}
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/regions/ProcessTryCatchRegions.java
View file @
eadf046b
...
...
@@ -27,7 +27,6 @@ import jadx.core.dex.trycatch.TryCatchBlock;
import
jadx.core.utils.BlockUtils
;
import
jadx.core.utils.ErrorsCounter
;
import
jadx.core.utils.RegionUtils
;
import
jadx.core.utils.exceptions.JadxRuntimeException
;
/**
* Extract blocks to separate try/catch region
...
...
@@ -67,34 +66,39 @@ public class ProcessTryCatchRegions extends AbstractRegionVisitor {
// for each try block search nearest dominator block
for
(
TryCatchBlock
tb
:
tryBlocks
)
{
if
(
tb
.
getHandlersCount
()
==
0
)
{
LOG
.
warn
(
"No exception handlers in catch block, method: {}"
,
mth
);
mth
.
addWarn
(
"No exception handlers in catch block: "
+
tb
);
continue
;
}
BitSet
bs
=
new
BitSet
(
mth
.
getBasicBlocks
().
size
());
for
(
ExceptionHandler
excHandler
:
tb
.
getHandlers
())
{
BlockNode
handlerBlock
=
excHandler
.
getHandlerBlock
();
if
(
handlerBlock
!=
null
)
{
SplitterBlockAttr
splitter
=
handlerBlock
.
get
(
AType
.
SPLITTER_BLOCK
);
if
(
splitter
!=
null
)
{
BlockNode
block
=
splitter
.
getBlock
();
bs
.
set
(
block
.
getId
());
}
}
}
List
<
BlockNode
>
domBlocks
=
BlockUtils
.
bitSetToBlocks
(
mth
,
bs
);
BlockNode
domBlock
;
if
(
domBlocks
.
size
()
!=
1
)
{
domBlock
=
BlockUtils
.
getTopBlock
(
domBlocks
);
if
(
domBlock
==
null
)
{
throw
new
JadxRuntimeException
(
"Exception block dominator not found, method:"
+
mth
+
", dom blocks: "
+
domBlocks
);
processTryCatchBlock
(
mth
,
tb
,
tryBlocksMap
);
}
}
private
static
void
processTryCatchBlock
(
MethodNode
mth
,
TryCatchBlock
tb
,
Map
<
BlockNode
,
TryCatchBlock
>
tryBlocksMap
)
{
BitSet
bs
=
new
BitSet
(
mth
.
getBasicBlocks
().
size
());
for
(
ExceptionHandler
excHandler
:
tb
.
getHandlers
())
{
BlockNode
handlerBlock
=
excHandler
.
getHandlerBlock
();
if
(
handlerBlock
!=
null
)
{
SplitterBlockAttr
splitter
=
handlerBlock
.
get
(
AType
.
SPLITTER_BLOCK
);
if
(
splitter
!=
null
)
{
BlockNode
block
=
splitter
.
getBlock
();
bs
.
set
(
block
.
getId
());
}
}
else
{
domBlock
=
domBlocks
.
get
(
0
);
}
TryCatchBlock
prevTB
=
tryBlocksMap
.
put
(
domBlock
,
tb
);
if
(
prevTB
!=
null
)
{
ErrorsCounter
.
methodWarn
(
mth
,
"Failed to process nested try/catch"
);
}
List
<
BlockNode
>
domBlocks
=
BlockUtils
.
bitSetToBlocks
(
mth
,
bs
);
BlockNode
domBlock
;
if
(
domBlocks
.
size
()
!=
1
)
{
domBlock
=
BlockUtils
.
getTopBlock
(
domBlocks
);
if
(
domBlock
==
null
)
{
mth
.
addWarn
(
"Exception block dominator not found, dom blocks: "
+
domBlocks
);
return
;
}
}
else
{
domBlock
=
domBlocks
.
get
(
0
);
}
TryCatchBlock
prevTB
=
tryBlocksMap
.
put
(
domBlock
,
tb
);
if
(
prevTB
!=
null
)
{
mth
.
addWarn
(
"Failed to process nested try/catch"
);
}
}
...
...
@@ -105,7 +109,7 @@ public class ProcessTryCatchRegions extends AbstractRegionVisitor {
if
(
region
.
getSubBlocks
().
contains
(
dominator
))
{
TryCatchBlock
tb
=
tryBlocksMap
.
get
(
dominator
);
if
(!
wrapBlocks
(
region
,
tb
,
dominator
))
{
ErrorsCounter
.
methodWarn
(
mth
,
"Can't wrap try/catch for "
+
region
);
ErrorsCounter
.
methodWarn
(
mth
,
"Can't wrap try/catch for
region:
"
+
region
);
}
tryBlocksMap
.
remove
(
dominator
);
return
true
;
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionMaker.java
View file @
eadf046b
...
...
@@ -929,7 +929,7 @@ public class RegionMaker {
}
}
for
(
ExceptionHandler
handler
:
tc
.
getHandlers
())
{
processExcHandler
(
handler
,
exits
);
processExcHandler
(
mth
,
handler
,
exits
);
}
}
return
processHandlersOutBlocks
(
mth
,
tcs
);
...
...
@@ -968,12 +968,12 @@ public class RegionMaker {
return
excOutRegion
;
}
private
void
processExcHandler
(
ExceptionHandler
handler
,
Set
<
BlockNode
>
exits
)
{
private
void
processExcHandler
(
MethodNode
mth
,
ExceptionHandler
handler
,
Set
<
BlockNode
>
exits
)
{
BlockNode
start
=
handler
.
getHandlerBlock
();
if
(
start
==
null
)
{
return
;
}
RegionStack
stack
=
new
RegionStack
(
mth
);
RegionStack
stack
=
new
RegionStack
(
this
.
mth
);
BlockNode
dom
;
if
(
handler
.
isFinally
())
{
SplitterBlockAttr
splitterAttr
=
start
.
get
(
AType
.
SPLITTER_BLOCK
);
...
...
@@ -986,11 +986,11 @@ public class RegionMaker {
stack
.
addExits
(
exits
);
}
BitSet
domFrontier
=
dom
.
getDomFrontier
();
List
<
BlockNode
>
handlerExits
=
BlockUtils
.
bitSetToBlocks
(
mth
,
domFrontier
);
boolean
inLoop
=
mth
.
getLoopForBlock
(
start
)
!=
null
;
List
<
BlockNode
>
handlerExits
=
BlockUtils
.
bitSetToBlocks
(
this
.
mth
,
domFrontier
);
boolean
inLoop
=
this
.
mth
.
getLoopForBlock
(
start
)
!=
null
;
for
(
BlockNode
exit
:
handlerExits
)
{
if
((!
inLoop
||
BlockUtils
.
isPathExists
(
start
,
exit
))
&&
RegionUtils
.
isRegionContainsBlock
(
mth
.
getRegion
(),
exit
))
{
&&
RegionUtils
.
isRegionContainsBlock
(
this
.
mth
.
getRegion
(),
exit
))
{
stack
.
addExit
(
exit
);
}
}
...
...
@@ -998,7 +998,7 @@ public class RegionMaker {
ExcHandlerAttr
excHandlerAttr
=
start
.
get
(
AType
.
EXC_HANDLER
);
if
(
excHandlerAttr
==
null
)
{
LOG
.
warn
(
"Missing exception handler attribute for start block"
);
mth
.
addWarn
(
"Missing exception handler attribute for start block: "
+
start
);
}
else
{
handler
.
getHandlerRegion
().
addAttr
(
excHandlerAttr
);
}
...
...
jadx-core/src/test/java/jadx/tests/external/BaseExternalTest.java
View file @
eadf046b
...
...
@@ -127,23 +127,36 @@ public abstract class BaseExternalTest extends IntegrationTest {
String
[]
lines
=
code
.
split
(
CodeWriter
.
NL
);
for
(
MethodNode
mth
:
classNode
.
getMethods
())
{
if
(
mthPattern
.
matcher
(
mth
.
getName
()).
matches
())
{
int
decompiledLine
=
mth
.
getDecompiledLine
();
int
decompiledLine
=
mth
.
getDecompiledLine
()
-
1
;
StringBuilder
mthCode
=
new
StringBuilder
();
int
startLine
=
getCommentLinesCount
(
lines
,
decompiledLine
);
int
brackets
=
0
;
for
(
int
i
=
decompiledLine
-
1
;
i
>
0
&&
i
<
lines
.
length
;
i
++)
{
for
(
int
i
=
startLine
;
i
>
0
&&
i
<
lines
.
length
;
i
++)
{
String
line
=
lines
[
i
];
mthCode
.
append
(
line
).
append
(
CodeWriter
.
NL
);
brackets
+=
StringUtils
.
countMatches
(
line
,
'{'
);
brackets
-=
StringUtils
.
countMatches
(
line
,
'}'
);
if
(
brackets
<=
0
)
{
break
;
if
(
i
>=
decompiledLine
)
{
brackets
+=
StringUtils
.
countMatches
(
line
,
'{'
);
brackets
-=
StringUtils
.
countMatches
(
line
,
'}'
);
if
(
brackets
<=
0
)
{
break
;
}
}
}
LOG
.
info
(
"
\n{}"
,
mthCode
);
LOG
.
info
(
"
Print method: {}\n{}"
,
mth
.
getMethodInfo
().
getShortId
()
,
mthCode
);
}
}
}
protected
int
getCommentLinesCount
(
String
[]
lines
,
int
line
)
{
for
(
int
i
=
line
-
1
;
i
>
0
&&
i
<
lines
.
length
;
i
--)
{
String
str
=
lines
[
i
];
if
(
str
.
isEmpty
()
||
str
.
equals
(
CodeWriter
.
NL
))
{
return
i
+
1
;
}
}
return
0
;
}
private
void
printErrorReport
(
JadxDecompiler
jadx
)
{
jadx
.
printErrorsReport
();
assertThat
(
jadx
.
getErrorsCount
(),
is
(
0
));
...
...
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