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
39093130
Commit
39093130
authored
May 01, 2018
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: fix processing overriden methods in deobfuscator (#207)
parent
9e9270a8
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
70 deletions
+55
-70
Deobfuscator.java
jadx-core/src/main/java/jadx/core/deobf/Deobfuscator.java
+52
-67
OverridedMethodsNode.java
...e/src/main/java/jadx/core/deobf/OverridedMethodsNode.java
+1
-1
TestMthRename.java
...test/java/jadx/tests/integration/deobf/TestMthRename.java
+2
-2
No files found.
jadx-core/src/main/java/jadx/core/deobf/Deobfuscator.java
View file @
39093130
...
...
@@ -3,7 +3,7 @@ package jadx.core.deobf;
import
java.io.File
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.
Linked
HashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
...
...
@@ -142,87 +142,72 @@ public class Deobfuscator {
ovrdMap
.
clear
();
}
@Nullable
private
static
ClassNode
resolveOverridingInternal
(
DexNode
dex
,
ClassNode
cls
,
String
signature
,
Set
<
MethodInfo
>
overrideSet
,
ClassNode
rootClass
)
{
ClassNode
result
=
null
;
private
void
resolveOverriding
(
MethodNode
mth
)
{
Set
<
ClassNode
>
clsParents
=
new
LinkedHashSet
<>();
collectClassHierarchy
(
mth
.
getParentClass
(),
clsParents
);
for
(
MethodNode
m
:
cls
.
getMethods
())
{
if
(
m
.
getMethodInfo
().
getShortId
().
startsWith
(
signature
))
{
result
=
cls
;
overrideSet
.
add
(
m
.
getMethodInfo
());
break
;
String
mthSignature
=
mth
.
getMethodInfo
().
makeSignature
(
false
);
Set
<
MethodInfo
>
overrideSet
=
new
LinkedHashSet
<>();
for
(
ClassNode
classNode
:
clsParents
)
{
MethodInfo
methodInfo
=
getMthOverride
(
classNode
.
getMethods
(),
mthSignature
);
if
(
methodInfo
!=
null
)
{
overrideSet
.
add
(
methodInfo
);
}
}
ArgType
superClass
=
cls
.
getSuperClass
();
if
(
superClass
!=
null
)
{
ClassNode
superNode
=
dex
.
resolveClass
(
superClass
);
if
(
superNode
!=
null
)
{
ClassNode
clsWithMth
=
resolveOverridingInternal
(
dex
,
superNode
,
signature
,
overrideSet
,
rootClass
);
if
(
clsWithMth
!=
null
)
{
if
((
result
!=
null
)
&&
(
result
!=
cls
))
{
if
(
clsWithMth
!=
result
)
{
LOG
.
warn
(
String
.
format
(
"Multiple overriding '%s' from '%s' and '%s' in '%s'"
,
signature
,
result
.
getFullName
(),
clsWithMth
.
getFullName
(),
rootClass
.
getFullName
()));
if
(
overrideSet
.
isEmpty
())
{
return
;
}
}
else
{
result
=
clsWithMth
;
OverridedMethodsNode
overrideNode
=
getOverrideMethodsNode
(
overrideSet
);
if
(
overrideNode
==
null
)
{
overrideNode
=
new
OverridedMethodsNode
(
overrideSet
);
ovrd
.
add
(
overrideNode
);
}
for
(
MethodInfo
overrideMth
:
overrideSet
)
{
if
(!
ovrdMap
.
containsKey
(
overrideMth
))
{
ovrdMap
.
put
(
overrideMth
,
overrideNode
);
overrideNode
.
add
(
overrideMth
);
}
}
}
for
(
ArgType
iFaceType
:
cls
.
getInterfaces
())
{
ClassNode
iFaceNode
=
dex
.
resolveClass
(
iFaceType
);
if
(
iFaceNode
!=
null
)
{
ClassNode
clsWithMth
=
resolveOverridingInternal
(
dex
,
iFaceNode
,
signature
,
overrideSet
,
rootClass
);
if
(
clsWithMth
!=
null
)
{
if
((
result
!=
null
)
&&
(
result
!=
cls
))
{
if
(
clsWithMth
!=
result
)
{
LOG
.
warn
(
String
.
format
(
"Multiple overriding '%s' from '%s' and '%s' in '%s'"
,
signature
,
result
.
getFullName
(),
clsWithMth
.
getFullName
(),
rootClass
.
getFullName
()));
private
OverridedMethodsNode
getOverrideMethodsNode
(
Set
<
MethodInfo
>
overrideSet
)
{
for
(
MethodInfo
overrideMth
:
overrideSet
)
{
OverridedMethodsNode
node
=
ovrdMap
.
get
(
overrideMth
);
if
(
node
!=
null
)
{
return
node
;
}
}
else
{
result
=
clsWithMth
;
}
return
null
;
}
private
MethodInfo
getMthOverride
(
List
<
MethodNode
>
methods
,
String
mthSignature
)
{
for
(
MethodNode
m
:
methods
)
{
MethodInfo
mthInfo
=
m
.
getMethodInfo
();
if
(
mthInfo
.
getShortId
().
startsWith
(
mthSignature
))
{
return
mthInfo
;
}
}
return
result
;
return
null
;
}
private
void
resolveOverriding
(
MethodNode
mth
)
{
Set
<
MethodInfo
>
overrideSet
=
new
HashSet
<>();
String
mthSignature
=
mth
.
getMethodInfo
().
makeSignature
(
false
);
ClassNode
cls
=
mth
.
getParentClass
();
resolveOverridingInternal
(
mth
.
dex
(),
cls
,
mthSignature
,
overrideSet
,
cls
);
if
(
overrideSet
.
size
()
>
1
)
{
OverridedMethodsNode
overrideNode
=
null
;
for
(
MethodInfo
_mth
:
overrideSet
)
{
if
(
ovrdMap
.
containsKey
(
_mth
))
{
overrideNode
=
ovrdMap
.
get
(
_mth
);
break
;
}
}
if
(
overrideNode
==
null
)
{
overrideNode
=
new
OverridedMethodsNode
(
overrideSet
);
ovrd
.
add
(
overrideNode
);
private
void
collectClassHierarchy
(
ClassNode
cls
,
Set
<
ClassNode
>
collected
)
{
boolean
added
=
collected
.
add
(
cls
);
if
(
added
)
{
ArgType
superClass
=
cls
.
getSuperClass
();
if
(
superClass
!=
null
)
{
ClassNode
superNode
=
cls
.
dex
().
resolveClass
(
superClass
);
if
(
superNode
!=
null
)
{
collectClassHierarchy
(
superNode
,
collected
);
}
for
(
MethodInfo
_mth
:
overrideSet
)
{
if
(!
ovrdMap
.
containsKey
(
_mth
))
{
ovrdMap
.
put
(
_mth
,
overrideNode
);
if
(!
overrideNode
.
contains
(
_mth
))
{
overrideNode
.
add
(
_mth
);
}
for
(
ArgType
argType
:
cls
.
getInterfaces
())
{
ClassNode
interfaceNode
=
cls
.
dex
().
resolveClass
(
argType
);
if
(
interfaceNode
!=
null
)
{
collectClassHierarchy
(
interfaceNode
,
collected
);
}
}
}
overrideSet
.
clear
();
}
private
void
processClass
(
ClassNode
cls
)
{
...
...
jadx-core/src/main/java/jadx/core/deobf/OverridedMethodsNode.java
View file @
39093130
...
...
@@ -4,7 +4,7 @@ import java.util.Set;
import
jadx.core.dex.info.MethodInfo
;
/* package */
class
OverridedMethodsNode
{
class
OverridedMethodsNode
{
private
Set
<
MethodInfo
>
methods
;
...
...
jadx-core/src/test/java/jadx/tests/integration/deobf/TestMthRename.java
View file @
39093130
...
...
@@ -30,10 +30,10 @@ public class TestMthRename extends IntegrationTest {
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsString
(
"public abstract void m
0
a();"
));
assertThat
(
code
,
containsString
(
"public abstract void m
o1
a();"
));
assertThat
(
code
,
not
(
containsString
(
"public abstract void a();"
)));
assertThat
(
code
,
containsString
(
".m
0
a();"
));
assertThat
(
code
,
containsString
(
".m
o1
a();"
));
assertThat
(
code
,
not
(
containsString
(
".a();"
)));
}
}
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