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
a135eb44
Commit
a135eb44
authored
Nov 13, 2014
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: check registers numbers, fix fallback mode
parent
252ed0e1
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
80 additions
and
20 deletions
+80
-20
ClassGen.java
jadx-core/src/main/java/jadx/core/codegen/ClassGen.java
+7
-3
NameGen.java
jadx-core/src/main/java/jadx/core/codegen/NameGen.java
+2
-5
MethodNode.java
jadx-core/src/main/java/jadx/core/dex/nodes/MethodNode.java
+20
-0
BlockMakerVisitor.java
...c/main/java/jadx/core/dex/visitors/BlockMakerVisitor.java
+2
-0
DepthTraversal.java
.../src/main/java/jadx/core/dex/visitors/DepthTraversal.java
+4
-0
IntegrationTest.java
jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java
+6
-10
SmaliTest.java
jadx-core/src/test/java/jadx/tests/api/SmaliTest.java
+2
-2
TestFallbackMode.java
...ava/jadx/tests/integration/fallback/TestFallbackMode.java
+37
-0
No files found.
jadx-core/src/main/java/jadx/core/codegen/ClassGen.java
View file @
a135eb44
...
...
@@ -302,7 +302,7 @@ public class ClassGen {
}
}
MethodGen
mthGen
;
if
(
badCode
||
mth
.
contains
(
AType
.
JADX_ERROR
))
{
if
(
badCode
||
mth
.
contains
(
AType
.
JADX_ERROR
)
||
fallback
)
{
mthGen
=
MethodGen
.
getFallbackMethodGen
(
mth
);
}
else
{
mthGen
=
new
MethodGen
(
this
,
mth
);
...
...
@@ -313,7 +313,11 @@ public class ClassGen {
code
.
add
(
'{'
);
code
.
incIndent
();
insertSourceFileInfo
(
code
,
mth
);
mthGen
.
addInstructions
(
code
);
if
(
fallback
)
{
mthGen
.
addFallbackMethodCode
(
code
);
}
else
{
mthGen
.
addInstructions
(
code
);
}
code
.
decIndent
();
code
.
startLine
(
'}'
);
}
...
...
@@ -535,7 +539,7 @@ public class ClassGen {
private
void
insertSourceFileInfo
(
CodeWriter
code
,
AttrNode
node
)
{
SourceFileAttr
sourceFileAttr
=
node
.
get
(
AType
.
SOURCE_FILE
);
if
(
sourceFileAttr
!=
null
)
{
code
.
startLine
(
"/
/ compiled from: "
).
add
(
sourceFileAttr
.
getFileName
()
);
code
.
startLine
(
"/
* compiled from: "
).
add
(
sourceFileAttr
.
getFileName
()).
add
(
" */"
);
}
}
...
...
jadx-core/src/main/java/jadx/core/codegen/NameGen.java
View file @
a135eb44
...
...
@@ -70,7 +70,7 @@ public class NameGen {
public
String
useArg
(
RegisterArg
arg
)
{
String
name
=
arg
.
getName
();
if
(
name
==
null
)
{
if
(
name
==
null
||
fallback
)
{
return
getFallbackName
(
arg
);
}
return
name
;
...
...
@@ -117,10 +117,7 @@ public class NameGen {
private
String
getFallbackName
(
RegisterArg
arg
)
{
String
name
=
arg
.
getName
();
String
base
=
"r"
+
arg
.
getRegNum
();
if
(
name
!=
null
&&
!
name
.
equals
(
"this"
))
{
return
base
+
"_"
+
name
;
}
return
base
;
return
name
!=
null
?
base
+
"_"
+
name
:
base
;
}
private
static
String
makeNameForType
(
ArgType
type
)
{
...
...
jadx-core/src/main/java/jadx/core/dex/nodes/MethodNode.java
View file @
a135eb44
...
...
@@ -114,6 +114,26 @@ public class MethodNode extends LineAttrNode implements ILoadable {
}
}
public
void
checkInstructions
()
{
List
<
RegisterArg
>
list
=
new
ArrayList
<
RegisterArg
>();
for
(
InsnNode
insnNode
:
instructions
)
{
if
(
insnNode
==
null
)
{
continue
;
}
list
.
clear
();
RegisterArg
resultArg
=
insnNode
.
getResult
();
if
(
resultArg
!=
null
)
{
list
.
add
(
resultArg
);
}
insnNode
.
getRegisterArgs
(
list
);
for
(
int
i
=
0
,
listSize
=
list
.
size
();
i
<
listSize
;
i
++)
{
if
(
list
.
get
(
i
).
getRegNum
()
>=
regsCount
)
{
throw
new
JadxRuntimeException
(
"Incorrect register number in instruction: "
+
insnNode
);
}
}
}
}
private
void
initMethodTypes
()
{
if
(!
parseSignature
())
{
retType
=
mthInfo
.
getReturnType
();
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/BlockMakerVisitor.java
View file @
a135eb44
...
...
@@ -45,6 +45,8 @@ public class BlockMakerVisitor extends AbstractVisitor {
if
(
mth
.
isNoCode
())
{
return
;
}
mth
.
checkInstructions
();
mth
.
initBasicBlocks
();
splitBasicBlocks
(
mth
);
processBlocksTree
(
mth
);
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/DepthTraversal.java
View file @
a135eb44
package
jadx
.
core
.
dex
.
visitors
;
import
jadx.core.dex.attributes.AType
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.core.dex.nodes.MethodNode
;
import
jadx.core.utils.ErrorsCounter
;
...
...
@@ -23,6 +24,9 @@ public class DepthTraversal {
}
public
static
void
visit
(
IDexTreeVisitor
visitor
,
MethodNode
mth
)
{
if
(
mth
.
contains
(
AType
.
JADX_ERROR
))
{
return
;
}
try
{
visitor
.
visit
(
mth
);
}
catch
(
Throwable
e
)
{
...
...
jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java
View file @
a135eb44
...
...
@@ -335,13 +335,15 @@ public abstract class IntegrationTest extends TestUtils {
return
files
;
}
p
ublic
void
noDebugInfo
()
{
p
rotected
void
noDebugInfo
()
{
this
.
withDebugInfo
=
false
;
}
// Try to make test class compilable
@Deprecated
public
void
disableCompilation
()
{
protected
void
setFallback
()
{
this
.
isFallback
=
true
;
}
protected
void
disableCompilation
()
{
this
.
compile
=
false
;
}
...
...
@@ -353,12 +355,6 @@ public abstract class IntegrationTest extends TestUtils {
// Use only for debug purpose
@Deprecated
protected
void
setFallback
()
{
this
.
isFallback
=
true
;
}
// Use only for debug purpose
@Deprecated
protected
void
notDeleteTmpJar
()
{
this
.
deleteTmpFiles
=
false
;
}
...
...
jadx-core/src/test/java/jadx/tests/api/SmaliTest.java
View file @
a135eb44
...
...
@@ -25,7 +25,7 @@ public class SmaliTest extends IntegrationTest {
return
getClassNodeFromFile
(
outDex
,
fullClsName
);
}
private
File
getSmaliFile
(
String
clsName
)
{
private
static
File
getSmaliFile
(
String
clsName
)
{
File
smaliFile
=
new
File
(
SMALI_TESTS_DIR
,
clsName
+
SMALI_TESTS_EXT
);
if
(
smaliFile
.
exists
())
{
return
smaliFile
;
...
...
@@ -38,7 +38,7 @@ public class SmaliTest extends IntegrationTest {
return
null
;
}
p
ubl
ic
boolean
compileSmali
(
File
input
,
File
output
)
{
p
rivate
stat
ic
boolean
compileSmali
(
File
input
,
File
output
)
{
List
<
String
>
args
=
new
ArrayList
<
String
>();
args
.
add
(
input
.
getAbsolutePath
());
...
...
jadx-core/src/test/java/jadx/tests/integration/fallback/TestFallbackMode.java
0 → 100644
View file @
a135eb44
package
jadx
.
tests
.
integration
.
fallback
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.tests.api.IntegrationTest
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
import
static
org
.
hamcrest
.
CoreMatchers
.
not
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TestFallbackMode
extends
IntegrationTest
{
public
static
class
TestCls
{
public
int
test
(
int
a
)
{
while
(
a
<
10
)
{
a
++;
}
return
a
;
}
}
@Test
public
void
test
()
{
setFallback
();
disableCompilation
();
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsString
(
"public int test(int r2) {"
));
assertThat
(
code
,
containsString
(
"r1_this = this;"
));
assertThat
(
code
,
containsString
(
"L_0x0004:"
));
assertThat
(
code
,
not
(
containsString
(
"throw new UnsupportedOperationException"
)));
}
}
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