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
0e04dc72
Commit
0e04dc72
authored
Apr 27, 2013
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid variable names clash
parent
484e07df
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
27 deletions
+44
-27
InsnGen.java
src/main/java/jadx/codegen/InsnGen.java
+1
-1
MethodGen.java
src/main/java/jadx/codegen/MethodGen.java
+22
-21
ProcessVariables.java
...main/java/jadx/dex/visitors/regions/ProcessVariables.java
+8
-5
TestCF2.java
src/samples/java/jadx/samples/TestCF2.java
+13
-0
No files found.
src/main/java/jadx/codegen/InsnGen.java
View file @
0e04dc72
...
@@ -101,7 +101,7 @@ public class InsnGen {
...
@@ -101,7 +101,7 @@ public class InsnGen {
}
}
public
String
declareVar
(
RegisterArg
arg
)
throws
CodegenException
{
public
String
declareVar
(
RegisterArg
arg
)
throws
CodegenException
{
return
useType
(
arg
.
getType
())
+
" "
+
a
rg
(
arg
);
return
useType
(
arg
.
getType
())
+
" "
+
mgen
.
assignA
rg
(
arg
);
}
}
private
String
lit
(
LiteralArg
arg
)
{
private
String
lit
(
LiteralArg
arg
)
{
...
...
src/main/java/jadx/codegen/MethodGen.java
View file @
0e04dc72
...
@@ -20,12 +20,9 @@ import jadx.utils.Utils;
...
@@ -20,12 +20,9 @@ import jadx.utils.Utils;
import
jadx.utils.exceptions.CodegenException
;
import
jadx.utils.exceptions.CodegenException
;
import
jadx.utils.exceptions.DecodeException
;
import
jadx.utils.exceptions.DecodeException
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.Iterator
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.Set
;
import
java.util.Set
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
...
@@ -37,12 +34,12 @@ public class MethodGen {
...
@@ -37,12 +34,12 @@ public class MethodGen {
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
MethodGen
.
class
);
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
MethodGen
.
class
);
private
final
MethodNode
mth
;
private
final
MethodNode
mth
;
private
final
Set
<
String
>
mthArgsDecls
;
private
final
Map
<
String
,
ArgType
>
varDecls
=
new
HashMap
<
String
,
ArgType
>();
private
final
ClassGen
classGen
;
private
final
ClassGen
classGen
;
private
final
boolean
fallback
;
private
final
boolean
fallback
;
private
final
AnnotationGen
annotationGen
;
private
final
AnnotationGen
annotationGen
;
private
final
Set
<
String
>
varNames
=
new
HashSet
<
String
>();
public
MethodGen
(
ClassGen
classGen
,
MethodNode
mth
)
{
public
MethodGen
(
ClassGen
classGen
,
MethodNode
mth
)
{
this
.
mth
=
mth
;
this
.
mth
=
mth
;
this
.
classGen
=
classGen
;
this
.
classGen
=
classGen
;
...
@@ -50,9 +47,8 @@ public class MethodGen {
...
@@ -50,9 +47,8 @@ public class MethodGen {
this
.
annotationGen
=
classGen
.
getAnnotationGen
();
this
.
annotationGen
=
classGen
.
getAnnotationGen
();
List
<
RegisterArg
>
args
=
mth
.
getArguments
(
true
);
List
<
RegisterArg
>
args
=
mth
.
getArguments
(
true
);
mthArgsDecls
=
new
HashSet
<
String
>(
args
.
size
());
for
(
RegisterArg
arg
:
args
)
{
for
(
RegisterArg
arg
:
args
)
{
mthArgsDecl
s
.
add
(
makeArgName
(
arg
));
varName
s
.
add
(
makeArgName
(
arg
));
}
}
}
}
...
@@ -183,11 +179,28 @@ public class MethodGen {
...
@@ -183,11 +179,28 @@ public class MethodGen {
*/
*/
public
String
assignArg
(
RegisterArg
arg
)
{
public
String
assignArg
(
RegisterArg
arg
)
{
String
name
=
makeArgName
(
arg
);
String
name
=
makeArgName
(
arg
);
if
(!
mthArgsDecls
.
contains
(
name
))
if
(
varNames
.
add
(
name
))
varDecls
.
put
(
name
,
arg
.
getType
());
return
name
;
if
(
fallback
)
return
name
;
name
=
getUniqVarName
(
name
);
arg
.
getTypedVar
().
setName
(
name
);
return
name
;
return
name
;
}
}
private
String
getUniqVarName
(
String
name
)
{
String
r
;
int
i
=
2
;
do
{
r
=
name
+
i
;
i
++;
}
while
(
varNames
.
contains
(
r
));
varNames
.
add
(
r
);
return
r
;
}
private
void
makeInitCode
(
CodeWriter
code
)
throws
CodegenException
{
private
void
makeInitCode
(
CodeWriter
code
)
throws
CodegenException
{
InsnGen
igen
=
new
InsnGen
(
this
,
mth
,
fallback
);
InsnGen
igen
=
new
InsnGen
(
this
,
mth
,
fallback
);
// generate super call
// generate super call
...
@@ -195,17 +208,6 @@ public class MethodGen {
...
@@ -195,17 +208,6 @@ public class MethodGen {
igen
.
makeInsn
(
mth
.
getSuperCall
(),
code
);
igen
.
makeInsn
(
mth
.
getSuperCall
(),
code
);
}
}
public
void
makeVariablesDeclaration
(
CodeWriter
code
)
{
for
(
Entry
<
String
,
ArgType
>
var
:
varDecls
.
entrySet
())
{
code
.
startLine
(
TypeGen
.
translate
(
classGen
,
var
.
getValue
()));
code
.
add
(
" "
);
code
.
add
(
var
.
getKey
());
code
.
add
(
";"
);
}
if
(!
varDecls
.
isEmpty
())
code
.
endl
();
}
public
CodeWriter
makeInstructions
(
int
mthIndent
)
throws
CodegenException
{
public
CodeWriter
makeInstructions
(
int
mthIndent
)
throws
CodegenException
{
CodeWriter
code
=
new
CodeWriter
(
mthIndent
+
1
);
CodeWriter
code
=
new
CodeWriter
(
mthIndent
+
1
);
...
@@ -242,7 +244,6 @@ public class MethodGen {
...
@@ -242,7 +244,6 @@ public class MethodGen {
(
new
RegionGen
(
this
,
mth
)).
makeRegion
(
insns
,
mth
.
getRegion
());
(
new
RegionGen
(
this
,
mth
)).
makeRegion
(
insns
,
mth
.
getRegion
());
makeInitCode
(
code
);
makeInitCode
(
code
);
makeVariablesDeclaration
(
code
);
code
.
add
(
insns
);
code
.
add
(
insns
);
}
else
{
}
else
{
makeFallbackMethod
(
code
,
mth
);
makeFallbackMethod
(
code
,
mth
);
...
...
src/main/java/jadx/dex/visitors/regions/ProcessVariables.java
View file @
0e04dc72
...
@@ -107,13 +107,16 @@ public class ProcessVariables extends AbstractVisitor {
...
@@ -107,13 +107,16 @@ public class ProcessVariables extends AbstractVisitor {
// reduce assigns map
// reduce assigns map
List
<
RegisterArg
>
mthArgs
=
mth
.
getArguments
(
true
);
List
<
RegisterArg
>
mthArgs
=
mth
.
getArguments
(
true
);
for
(
RegisterArg
arg
:
mthArgs
)
{
usageMap
.
remove
(
arg
);
}
for
(
Iterator
<
Entry
<
RegisterArg
,
Usage
>>
it
=
usageMap
.
entrySet
().
iterator
();
it
.
hasNext
();)
{
for
(
Iterator
<
Entry
<
RegisterArg
,
Usage
>>
it
=
usageMap
.
entrySet
().
iterator
();
it
.
hasNext
();)
{
Entry
<
RegisterArg
,
Usage
>
entry
=
it
.
next
();
Entry
<
RegisterArg
,
Usage
>
entry
=
it
.
next
();
Usage
u
=
entry
.
getValue
();
Usage
u
=
entry
.
getValue
();
RegisterArg
r
=
u
.
getArg
();
// if no assigns
or method argument
=> remove
// if no assigns => remove
if
(
u
.
getAssigns
().
isEmpty
()
||
mthArgs
.
indexOf
(
r
)
!=
-
1
)
{
if
(
u
.
getAssigns
().
isEmpty
())
{
it
.
remove
();
it
.
remove
();
continue
;
continue
;
}
}
...
@@ -122,7 +125,7 @@ public class ProcessVariables extends AbstractVisitor {
...
@@ -122,7 +125,7 @@ public class ProcessVariables extends AbstractVisitor {
for
(
IRegion
assignRegion
:
u
.
getAssigns
())
{
for
(
IRegion
assignRegion
:
u
.
getAssigns
())
{
if
(
u
.
getArgRegion
()
==
assignRegion
if
(
u
.
getArgRegion
()
==
assignRegion
&&
canDeclareInRegion
(
u
,
assignRegion
))
{
&&
canDeclareInRegion
(
u
,
assignRegion
))
{
r
.
getParentInsn
().
getAttributes
().
add
(
new
DeclareVariableAttr
());
u
.
getArg
()
.
getParentInsn
().
getAttributes
().
add
(
new
DeclareVariableAttr
());
it
.
remove
();
it
.
remove
();
break
;
break
;
}
}
...
@@ -132,8 +135,8 @@ public class ProcessVariables extends AbstractVisitor {
...
@@ -132,8 +135,8 @@ public class ProcessVariables extends AbstractVisitor {
// apply
// apply
for
(
Entry
<
RegisterArg
,
Usage
>
entry
:
usageMap
.
entrySet
())
{
for
(
Entry
<
RegisterArg
,
Usage
>
entry
:
usageMap
.
entrySet
())
{
Usage
u
=
entry
.
getValue
();
Usage
u
=
entry
.
getValue
();
// find common region which contains all usage regions
// find region which contain all usage regions
Set
<
IRegion
>
set
=
u
.
getUseRegions
();
Set
<
IRegion
>
set
=
u
.
getUseRegions
();
for
(
Iterator
<
IRegion
>
it
=
set
.
iterator
();
it
.
hasNext
();)
{
for
(
Iterator
<
IRegion
>
it
=
set
.
iterator
();
it
.
hasNext
();)
{
IRegion
r
=
it
.
next
();
IRegion
r
=
it
.
next
();
...
...
src/samples/java/jadx/samples/TestCF2.java
View file @
0e04dc72
...
@@ -4,6 +4,18 @@ public class TestCF2 extends AbstractTest {
...
@@ -4,6 +4,18 @@ public class TestCF2 extends AbstractTest {
private
final
Object
ready_mutex
=
new
Object
();
private
final
Object
ready_mutex
=
new
Object
();
private
boolean
ready
=
false
;
private
boolean
ready
=
false
;
public
int
simple_loops
()
throws
InterruptedException
{
int
[]
a
=
new
int
[]
{
1
,
2
,
4
,
6
,
8
};
int
b
=
0
;
for
(
int
i
=
0
;
i
<
a
.
length
;
i
++)
{
b
+=
a
[
i
];
}
for
(
long
i
=
b
;
i
>
0
;
i
--)
{
b
+=
i
;
}
return
b
;
}
/**
/**
* Test infinite loop
* Test infinite loop
*/
*/
...
@@ -92,6 +104,7 @@ public class TestCF2 extends AbstractTest {
...
@@ -92,6 +104,7 @@ public class TestCF2 extends AbstractTest {
@Override
@Override
public
boolean
testRun
()
throws
Exception
{
public
boolean
testRun
()
throws
Exception
{
assertEquals
(
simple_loops
(),
252
);
// TODO add checks
// TODO add checks
return
true
;
return
true
;
}
}
...
...
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