Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2301_76393173
jadx
提交
98ef7c39
J
jadx
项目概览
2301_76393173
/
jadx
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jadx
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
98ef7c39
编写于
5月 02, 2018
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
core: fix synthetic constructor remove (#265)
上级
e039a5a9
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
156 addition
and
22 deletion
+156
-22
jadx-core/src/main/java/jadx/core/dex/nodes/DexNode.java
jadx-core/src/main/java/jadx/core/dex/nodes/DexNode.java
+1
-1
jadx-core/src/main/java/jadx/core/dex/visitors/ClassModifier.java
...e/src/main/java/jadx/core/dex/visitors/ClassModifier.java
+53
-20
jadx-core/src/test/java/jadx/tests/api/SmaliTest.java
jadx-core/src/test/java/jadx/tests/api/SmaliTest.java
+1
-1
jadx-core/src/test/java/jadx/tests/integration/inner/TestInnerClassFakeSyntheticConstructor.java
...gration/inner/TestInnerClassFakeSyntheticConstructor.java
+35
-0
jadx-core/src/test/java/jadx/tests/integration/inner/TestInnerClassSyntheticConstructor.java
...integration/inner/TestInnerClassSyntheticConstructor.java
+28
-0
jadx-core/src/test/smali/inner/TestInnerClassFakeSyntheticConstructor.smali
.../smali/inner/TestInnerClassFakeSyntheticConstructor.smali
+38
-0
未找到文件。
jadx-core/src/main/java/jadx/core/dex/nodes/DexNode.java
浏览文件 @
98ef7c39
...
...
@@ -210,7 +210,7 @@ public class DexNode implements IDexNode {
@Override
public
String
toString
()
{
return
"DEX
"
;
return
"DEX
: "
+
file
;
}
}
jadx-core/src/main/java/jadx/core/dex/visitors/ClassModifier.java
浏览文件 @
98ef7c39
...
...
@@ -11,6 +11,7 @@ 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.args.ArgType
;
import
jadx.core.dex.instructions.args.InsnArg
;
import
jadx.core.dex.instructions.args.RegisterArg
;
import
jadx.core.dex.instructions.args.SSAVar
;
...
...
@@ -133,29 +134,62 @@ public class ClassModifier extends AbstractVisitor {
if
(
af
.
isBridge
()
&&
af
.
isSynthetic
()
&&
!
isMethodUniq
(
cls
,
mth
))
{
// TODO add more checks before method deletion
mth
.
add
(
AFlag
.
DONT_GENERATE
);
}
else
{
// remove synthetic constructor for inner classes
if
(
af
.
isSynthetic
()
&&
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
)
{
ArgType
argType
=
arg
.
getType
();
if
(!
argType
.
isObject
())
{
continue
;
}
// remove synthetic constructor for inner classes
if
(
af
.
isSynthetic
()
&&
af
.
isConstructor
()
&&
mth
.
getBasicBlocks
().
size
()
==
2
)
{
List
<
InsnNode
>
insns
=
mth
.
getBasicBlocks
().
get
(
0
).
getInstructions
();
if
(
insns
.
size
()
==
1
&&
insns
.
get
(
0
).
getType
()
==
InsnType
.
CONSTRUCTOR
)
{
ConstructorInsn
constr
=
(
ConstructorInsn
)
insns
.
get
(
0
);
List
<
RegisterArg
>
args
=
mth
.
getArguments
(
false
);
if
(
constr
.
isThis
()
&&
!
args
.
isEmpty
())
{
// remove first arg for non-static class (references to outer class)
if
(
args
.
get
(
0
).
getType
().
equals
(
cls
.
getParentClass
().
getClassInfo
().
getType
()))
{
args
.
get
(
0
).
add
(
AFlag
.
SKIP_ARG
);
}
// remove unused args
for
(
RegisterArg
arg
:
args
)
{
SSAVar
sVar
=
arg
.
getSVar
();
if
(
sVar
!=
null
&&
sVar
.
getUseCount
()
==
0
)
{
arg
.
add
(
AFlag
.
SKIP_ARG
);
}
}
mth
.
add
(
AFlag
.
DONT_GENERATE
);
ClassNode
argCls
=
cls
.
dex
().
resolveClass
(
argType
);
if
(
argCls
==
null
)
{
// check if missing class from current top class
ClassInfo
argClsInfo
=
ClassInfo
.
fromType
(
cls
.
root
(),
argType
);
if
(
argClsInfo
.
isInner
()
&&
cls
.
getFullName
().
startsWith
(
argClsInfo
.
getParentClass
().
getFullName
()))
{
return
true
;
}
}
else
{
if
(
argCls
.
contains
(
AFlag
.
DONT_GENERATE
))
{
return
true
;
}
}
}
return
false
;
}
/**
* Remove synthetic constructor and redirect calls to existing constructor
*/
private
static
void
modifySyntheticMethod
(
ClassNode
cls
,
MethodNode
mth
,
List
<
RegisterArg
>
args
)
{
List
<
InsnNode
>
insns
=
mth
.
getBasicBlocks
().
get
(
0
).
getInstructions
();
if
(
insns
.
size
()
==
1
&&
insns
.
get
(
0
).
getType
()
==
InsnType
.
CONSTRUCTOR
)
{
ConstructorInsn
constr
=
(
ConstructorInsn
)
insns
.
get
(
0
);
if
(
constr
.
isThis
()
&&
!
args
.
isEmpty
())
{
// remove first arg for non-static class (references to outer class)
RegisterArg
firstArg
=
args
.
get
(
0
);
if
(
firstArg
.
getType
().
equals
(
cls
.
getParentClass
().
getClassInfo
().
getType
()))
{
firstArg
.
add
(
AFlag
.
SKIP_ARG
);
}
// remove unused args
for
(
RegisterArg
arg
:
args
)
{
SSAVar
sVar
=
arg
.
getSVar
();
if
(
sVar
!=
null
&&
sVar
.
getUseCount
()
==
0
)
{
arg
.
add
(
AFlag
.
SKIP_ARG
);
}
}
mth
.
add
(
AFlag
.
DONT_GENERATE
);
}
}
}
...
...
@@ -191,5 +225,4 @@ public class ClassModifier extends AbstractVisitor {
}
}
}
}
jadx-core/src/test/java/jadx/tests/api/SmaliTest.java
浏览文件 @
98ef7c39
...
...
@@ -37,7 +37,7 @@ public abstract class SmaliTest extends IntegrationTest {
if
(
smaliFile
.
exists
())
{
return
smaliFile
;
}
throw
new
AssertionError
(
"Smali file not found: "
+
SMALI_TESTS_DIR
+
"/"
+
clsName
+
SMALI_TESTS_EXT
);
throw
new
AssertionError
(
"Smali file not found: "
+
smaliFile
.
getAbsolutePath
()
);
}
private
static
boolean
compileSmali
(
File
input
,
File
output
)
{
...
...
jadx-core/src/test/java/jadx/tests/integration/inner/TestInnerClassFakeSyntheticConstructor.java
0 → 100644
浏览文件 @
98ef7c39
package
jadx.tests.integration.inner
;
import
org.junit.Test
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.tests.api.IntegrationTest
;
import
jadx.tests.api.SmaliTest
;
import
static
jadx
.
tests
.
api
.
utils
.
JadxMatchers
.
containsOne
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TestInnerClassFakeSyntheticConstructor
extends
SmaliTest
{
// public class TestCls {
// public /* synthetic */ TestCls(String a) {
// this(a, true);
// }
//
// public TestCls(String a, boolean b) {
// }
//
// public static TestCls build(String str) {
// return new TestCls(str);
// }
// }
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNodeFromSmali
(
"inner/TestInnerClassFakeSyntheticConstructor"
,
"jadx.tests.inner.TestCls"
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsOne
(
"TestCls(String a) {"
));
// and must compile
}
}
jadx-core/src/test/java/jadx/tests/integration/inner/TestInnerClassSyntheticConstructor.java
0 → 100644
浏览文件 @
98ef7c39
package
jadx.tests.integration.inner
;
import
org.junit.Test
;
import
jadx.tests.api.IntegrationTest
;
import
jadx.tests.api.SmaliTest
;
import
static
org
.
hamcrest
.
Matchers
.
not
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TestInnerClassSyntheticConstructor
extends
IntegrationTest
{
private
class
TestCls
{
private
int
mth
()
{
return
1
;
}
}
public
int
call
()
{
return
new
TestCls
().
mth
();
}
@Test
public
void
test
()
{
getClassNode
(
TestInnerClassSyntheticConstructor
.
class
);
// must compile, no usage of removed synthetic empty class
}
}
jadx-core/src/test/smali/inner/TestInnerClassFakeSyntheticConstructor.smali
0 → 100644
浏览文件 @
98ef7c39
.class public Ljadx/tests/inner/TestCls;
.super Ljava/lang/Object;
# direct methods
.method public synthetic constructor <init>(Ljava/lang/String;)V
.registers 3
.param p1, "a" # Ljava/lang/String;
.prologue
const/4 v0, 0x1
invoke-direct {p0, p1, v0}, Ljadx/tests/inner/TestCls;-><init>(Ljava/lang/String;Z)V
return-void
.end method
.method public constructor <init>(Ljava/lang/String;Z)V
.registers 3
.param p1, "a" # Ljava/lang/String;
.param p2, "b" # Z
.prologue
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
return-void
.end method
.method public static build(Ljava/lang/String;)Ljadx/tests/inner/TestCls;
.registers 2
.param p0, "str" # Ljava/lang/String;
.prologue
new-instance v0, Ljadx/tests/inner/TestCls;
invoke-direct {v0, p0}, Ljadx/tests/inner/TestCls;-><init>(Ljava/lang/String;)V
return-object v0
.end method
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录