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
0ae7c1ef
Commit
0ae7c1ef
authored
Aug 19, 2018
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: rename wrapped synthetic method (#336)
parent
cb135997
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
205 additions
and
34 deletions
+205
-34
ClassModifier.java
...e/src/main/java/jadx/core/dex/visitors/ClassModifier.java
+65
-34
BlockUtils.java
jadx-core/src/main/java/jadx/core/utils/BlockUtils.java
+6
-0
TestInnerClassSyntheticRename.java
...ests/integration/inner/TestInnerClassSyntheticRename.java
+41
-0
TestInnerClassSyntheticRename.smali
.../src/test/smali/inner/TestInnerClassSyntheticRename.smali
+93
-0
No files found.
jadx-core/src/main/java/jadx/core/dex/visitors/ClassModifier.java
View file @
0ae7c1ef
...
...
@@ -11,8 +11,10 @@ import jadx.core.dex.info.FieldInfo;
import
jadx.core.dex.info.MethodInfo
;
import
jadx.core.dex.instructions.IndexInsnNode
;
import
jadx.core.dex.instructions.InsnType
;
import
jadx.core.dex.instructions.InvokeNode
;
import
jadx.core.dex.instructions.args.ArgType
;
import
jadx.core.dex.instructions.args.InsnArg
;
import
jadx.core.dex.instructions.args.InsnWrapArg
;
import
jadx.core.dex.instructions.args.RegisterArg
;
import
jadx.core.dex.instructions.args.SSAVar
;
import
jadx.core.dex.instructions.mods.ConstructorInsn
;
...
...
@@ -44,8 +46,8 @@ public class ClassModifier extends AbstractVisitor {
return
false
;
}
removeSyntheticFields
(
cls
);
removeSyntheticMethods
(
cls
);
removeEmptyMethods
(
cl
s
);
cls
.
getMethods
().
forEach
(
mth
->
removeSyntheticMethods
(
cls
,
mth
)
);
cls
.
getMethods
().
forEach
(
ClassModifier:
:
removeEmptyMethod
s
);
markAnonymousClass
(
cls
);
return
false
;
...
...
@@ -122,27 +124,26 @@ public class ClassModifier extends AbstractVisitor {
return
true
;
}
private
static
void
removeSyntheticMethods
(
ClassNode
cls
)
{
for
(
MethodNode
mth
:
cls
.
getMethods
())
{
private
static
void
removeSyntheticMethods
(
ClassNode
cls
,
MethodNode
mth
)
{
if
(
mth
.
isNoCode
())
{
continue
;
return
;
}
AccessInfo
af
=
mth
.
getAccessFlags
();
// remove bridge methods
if
(
af
.
isBridge
()
&&
af
.
isSynthetic
()
&&
!
isMethodUniq
(
cls
,
mth
))
{
// TODO add more checks before method deletion
if
(!
af
.
isSynthetic
())
{
return
;
}
if
(
removeBridgeMethod
(
cls
,
mth
))
{
mth
.
add
(
AFlag
.
DONT_GENERATE
);
}
else
{
return
;
}
// remove synthetic constructor for inner classes
if
(
af
.
isSynthetic
()
&&
af
.
isConstructor
()
&&
mth
.
getBasicBlocks
().
size
()
==
2
)
{
if
(
af
.
isConstructor
()
&&
mth
.
getBasicBlocks
().
size
()
==
2
)
{
List
<
RegisterArg
>
args
=
mth
.
getArguments
(
false
);
if
(
isRemovedClassInArgs
(
cls
,
args
))
{
modifySyntheticMethod
(
cls
,
mth
,
args
);
}
}
}
}
}
private
static
boolean
isRemovedClassInArgs
(
ClassNode
cls
,
List
<
RegisterArg
>
mthArgs
)
{
for
(
RegisterArg
arg
:
mthArgs
)
{
...
...
@@ -192,7 +193,40 @@ public class ClassModifier extends AbstractVisitor {
}
}
private
static
boolean
isMethodUniq
(
ClassNode
cls
,
MethodNode
mth
)
{
private
static
boolean
removeBridgeMethod
(
ClassNode
cls
,
MethodNode
mth
)
{
List
<
InsnNode
>
allInsns
=
BlockUtils
.
collectAllInsns
(
mth
.
getBasicBlocks
());
if
(
allInsns
.
size
()
==
1
)
{
InsnNode
wrappedInsn
=
allInsns
.
get
(
0
);
if
(
wrappedInsn
.
getType
()
==
InsnType
.
RETURN
)
{
InsnArg
arg
=
wrappedInsn
.
getArg
(
0
);
if
(
arg
.
isInsnWrap
())
{
wrappedInsn
=
((
InsnWrapArg
)
arg
).
getWrapInsn
();
}
}
if
(
checkSyntheticWrapper
(
mth
,
wrappedInsn
))
{
return
true
;
}
}
return
!
isMethodUnique
(
cls
,
mth
);
}
private
static
boolean
checkSyntheticWrapper
(
MethodNode
mth
,
InsnNode
insn
)
{
InsnType
insnType
=
insn
.
getType
();
if
(
insnType
==
InsnType
.
INVOKE
)
{
MethodInfo
callMth
=
((
InvokeNode
)
insn
).
getCallMth
();
MethodNode
wrappedMth
=
mth
.
root
().
deepResolveMethod
(
callMth
);
if
(
wrappedMth
!=
null
)
{
String
alias
=
mth
.
getAlias
();
if
(!
wrappedMth
.
getAlias
().
equals
(
alias
)
&&
wrappedMth
.
isVirtual
())
{
wrappedMth
.
getMethodInfo
().
setAlias
(
alias
);
}
return
true
;
}
}
return
false
;
}
private
static
boolean
isMethodUnique
(
ClassNode
cls
,
MethodNode
mth
)
{
MethodInfo
mi
=
mth
.
getMethodInfo
();
for
(
MethodNode
otherMth
:
cls
.
getMethods
())
{
if
(
otherMth
!=
mth
)
{
...
...
@@ -207,10 +241,8 @@ public class ClassModifier extends AbstractVisitor {
return
true
;
}
private
static
void
removeEmptyMethods
(
ClassNode
cls
)
{
for
(
MethodNode
mth
:
cls
.
getMethods
())
{
private
static
void
removeEmptyMethods
(
MethodNode
mth
)
{
AccessInfo
af
=
mth
.
getAccessFlags
();
// remove public empty constructors
if
(
af
.
isConstructor
()
&&
(
af
.
isPublic
()
||
af
.
isStatic
())
...
...
@@ -222,5 +254,4 @@ public class ClassModifier extends AbstractVisitor {
}
}
}
}
}
jadx-core/src/main/java/jadx/core/utils/BlockUtils.java
View file @
0ae7c1ef
...
...
@@ -550,4 +550,10 @@ public class BlockUtils {
}
return
true
;
}
public
static
List
<
InsnNode
>
collectAllInsns
(
List
<
BlockNode
>
blocks
)
{
List
<
InsnNode
>
insns
=
new
ArrayList
<>();
blocks
.
forEach
(
block
->
insns
.
addAll
(
block
.
getInstructions
()));
return
insns
;
}
}
jadx-core/src/test/java/jadx/tests/integration/inner/TestInnerClassSyntheticRename.java
0 → 100644
View file @
0ae7c1ef
package
jadx
.
tests
.
integration
.
inner
;
import
org.junit.Test
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.tests.api.SmaliTest
;
import
static
jadx
.
tests
.
api
.
utils
.
JadxMatchers
.
containsOne
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
hamcrest
.
Matchers
.
not
;
import
static
org
.
junit
.
Assert
.
assertThat
;
/**
* Issue: https://github.com/skylot/jadx/issues/336
*/
public
class
TestInnerClassSyntheticRename
extends
SmaliTest
{
// private class MyAsync extends AsyncTask<Uri, Uri, List<Uri>> {
// @Override
// protected List<Uri> doInBackground(Uri... uris) {
// Log.i("MyAsync", "doInBackground");
// return null;
// }
//
// @Override
// protected void onPostExecute(List<Uri> uris) {
// Log.i("MyAsync", "onPostExecute");
// }
// }
@Test
public
void
test
()
{
disableCompilation
();
ClassNode
cls
=
getClassNodeFromSmali
(
"inner/TestInnerClassSyntheticRename"
,
"com.github.skylot.testasync.MyAsync"
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsOne
(
"protected List<Uri> doInBackground(Uri... uriArr) {"
));
assertThat
(
code
,
containsOne
(
"protected void onPostExecute(List<Uri> list) {"
));
assertThat
(
code
,
not
(
containsString
(
"synthetic"
)));
}
}
jadx-core/src/test/smali/inner/TestInnerClassSyntheticRename.smali
0 → 100644
View file @
0ae7c1ef
.class Lcom/github/skylot/testasync/MyAsync;
.super Landroid/os/AsyncTask;
# annotations
.annotation system Ldalvik/annotation/Signature;
value = {
"Landroid/os/AsyncTask<",
"Landroid/net/Uri;",
"Landroid/net/Uri;",
"Ljava/util/List<",
"Landroid/net/Uri;",
">;>;"
}
.end annotation
# direct methods
.method private constructor <init>(Lcom/github/skylot/testasync/MainActivity;)V
.locals 0
invoke-direct {p0}, Landroid/os/AsyncTask;-><init>()V
return-void
.end method
# virtual methods
.method protected varargs a([Landroid/net/Uri;)Ljava/util/List;
.locals 1
.annotation system Ldalvik/annotation/Signature;
value = {
"([",
"Landroid/net/Uri;",
")",
"Ljava/util/List<",
"Landroid/net/Uri;",
">;"
}
.end annotation
const-string p1, "MyAsync"
const-string v0, "doInBackground"
invoke-static {p1, v0}, Landroid/util/Log;->i(Ljava/lang/String;Ljava/lang/String;)I
const/4 p1, 0x0
return-object p1
.end method
.method protected a(Ljava/util/List;)V
.locals 1
.annotation system Ldalvik/annotation/Signature;
value = {
"(",
"Ljava/util/List<",
"Landroid/net/Uri;",
">;)V"
}
.end annotation
const-string p1, "MyAsync"
const-string v0, "onPostExecute"
invoke-static {p1, v0}, Landroid/util/Log;->i(Ljava/lang/String;Ljava/lang/String;)I
return-void
.end method
.method protected synthetic doInBackground([Ljava/lang/Object;)Ljava/lang/Object;
.locals 0
check-cast p1, [Landroid/net/Uri;
invoke-virtual {p0, p1}, Lcom/github/skylot/testasync/MyAsync;->a([Landroid/net/Uri;)Ljava/util/List;
move-result-object p1
return-object p1
.end method
.method protected synthetic onPostExecute(Ljava/lang/Object;)V
.locals 0
check-cast p1, Ljava/util/List;
invoke-virtual {p0, p1}, Lcom/github/skylot/testasync/MyAsync;->a(Ljava/util/List;)V
return-void
.end method
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