Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Quincy379
jadx
提交
ec66476a
J
jadx
项目概览
Quincy379
/
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,发现更多精彩内容 >>
提交
ec66476a
编写于
3月 31, 2019
作者:
A
Ahmed Ashour
提交者:
skylot
3月 31, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: better String constructor from byte and char arrays (#530) (PR #533)
上级
008216d5
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
149 addition
and
1 deletion
+149
-1
jadx-core/src/main/java/jadx/core/dex/info/MethodInfo.java
jadx-core/src/main/java/jadx/core/dex/info/MethodInfo.java
+15
-0
jadx-core/src/main/java/jadx/core/dex/instructions/InvokeNode.java
.../src/main/java/jadx/core/dex/instructions/InvokeNode.java
+1
-1
jadx-core/src/main/java/jadx/core/dex/visitors/SimplifyVisitor.java
...src/main/java/jadx/core/dex/visitors/SimplifyVisitor.java
+47
-0
jadx-core/src/test/java/jadx/tests/integration/others/TestStringConstructor.java
.../jadx/tests/integration/others/TestStringConstructor.java
+86
-0
未找到文件。
jadx-core/src/main/java/jadx/core/dex/info/MethodInfo.java
浏览文件 @
ec66476a
...
@@ -33,6 +33,21 @@ public final class MethodInfo {
...
@@ -33,6 +33,21 @@ public final class MethodInfo {
shortId
=
makeSignature
(
true
);
shortId
=
makeSignature
(
true
);
}
}
private
MethodInfo
(
ClassInfo
declClass
,
String
name
,
List
<
ArgType
>
args
,
ArgType
retType
)
{
this
.
name
=
name
;
alias
=
name
;
aliasFromPreset
=
false
;
this
.
declClass
=
declClass
;
this
.
args
=
args
;
this
.
retType
=
retType
;
shortId
=
makeSignature
(
true
);
}
public
static
MethodInfo
externalMth
(
ClassInfo
declClass
,
String
name
,
List
<
ArgType
>
args
,
ArgType
retType
)
{
return
new
MethodInfo
(
declClass
,
name
,
args
,
retType
);
}
public
static
MethodInfo
fromDex
(
DexNode
dex
,
int
mthIndex
)
{
public
static
MethodInfo
fromDex
(
DexNode
dex
,
int
mthIndex
)
{
MethodInfo
mth
=
dex
.
root
().
getInfoStorage
().
getMethod
(
dex
,
mthIndex
);
MethodInfo
mth
=
dex
.
root
().
getInfoStorage
().
getMethod
(
dex
,
mthIndex
);
if
(
mth
!=
null
)
{
if
(
mth
!=
null
)
{
...
...
jadx-core/src/main/java/jadx/core/dex/instructions/InvokeNode.java
浏览文件 @
ec66476a
...
@@ -36,7 +36,7 @@ public class InvokeNode extends InsnNode implements CallMthInterface {
...
@@ -36,7 +36,7 @@ public class InvokeNode extends InsnNode implements CallMthInterface {
}
}
}
}
p
rivate
InvokeNode
(
MethodInfo
mth
,
InvokeType
invokeType
,
int
argsCount
)
{
p
ublic
InvokeNode
(
MethodInfo
mth
,
InvokeType
invokeType
,
int
argsCount
)
{
super
(
InsnType
.
INVOKE
,
argsCount
);
super
(
InsnType
.
INVOKE
,
argsCount
);
this
.
mth
=
mth
;
this
.
mth
=
mth
;
this
.
type
=
invokeType
;
this
.
type
=
invokeType
;
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/SimplifyVisitor.java
浏览文件 @
ec66476a
...
@@ -8,7 +8,9 @@ import org.slf4j.Logger;
...
@@ -8,7 +8,9 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
jadx.core.Consts
;
import
jadx.core.Consts
;
import
jadx.core.deobf.NameMapper
;
import
jadx.core.dex.attributes.AFlag
;
import
jadx.core.dex.attributes.AFlag
;
import
jadx.core.dex.info.ClassInfo
;
import
jadx.core.dex.info.FieldInfo
;
import
jadx.core.dex.info.FieldInfo
;
import
jadx.core.dex.info.MethodInfo
;
import
jadx.core.dex.info.MethodInfo
;
import
jadx.core.dex.instructions.ArithNode
;
import
jadx.core.dex.instructions.ArithNode
;
...
@@ -19,6 +21,7 @@ import jadx.core.dex.instructions.IfNode;
...
@@ -19,6 +21,7 @@ import jadx.core.dex.instructions.IfNode;
import
jadx.core.dex.instructions.IndexInsnNode
;
import
jadx.core.dex.instructions.IndexInsnNode
;
import
jadx.core.dex.instructions.InsnType
;
import
jadx.core.dex.instructions.InsnType
;
import
jadx.core.dex.instructions.InvokeNode
;
import
jadx.core.dex.instructions.InvokeNode
;
import
jadx.core.dex.instructions.InvokeType
;
import
jadx.core.dex.instructions.args.ArgType
;
import
jadx.core.dex.instructions.args.ArgType
;
import
jadx.core.dex.instructions.args.FieldArg
;
import
jadx.core.dex.instructions.args.FieldArg
;
import
jadx.core.dex.instructions.args.InsnArg
;
import
jadx.core.dex.instructions.args.InsnArg
;
...
@@ -29,6 +32,7 @@ import jadx.core.dex.instructions.mods.TernaryInsn;
...
@@ -29,6 +32,7 @@ import jadx.core.dex.instructions.mods.TernaryInsn;
import
jadx.core.dex.nodes.BlockNode
;
import
jadx.core.dex.nodes.BlockNode
;
import
jadx.core.dex.nodes.InsnNode
;
import
jadx.core.dex.nodes.InsnNode
;
import
jadx.core.dex.nodes.MethodNode
;
import
jadx.core.dex.nodes.MethodNode
;
import
jadx.core.dex.nodes.RootNode
;
import
jadx.core.dex.regions.conditions.IfCondition
;
import
jadx.core.dex.regions.conditions.IfCondition
;
public
class
SimplifyVisitor
extends
AbstractVisitor
{
public
class
SimplifyVisitor
extends
AbstractVisitor
{
...
@@ -95,12 +99,55 @@ public class SimplifyVisitor extends AbstractVisitor {
...
@@ -95,12 +99,55 @@ public class SimplifyVisitor extends AbstractVisitor {
}
}
break
;
break
;
case
CONSTRUCTOR:
simplfyConstructor
(
mth
.
root
(),
(
ConstructorInsn
)
insn
);
break
;
default
:
default
:
break
;
break
;
}
}
return
null
;
return
null
;
}
}
private
static
void
simplfyConstructor
(
RootNode
root
,
ConstructorInsn
insn
)
{
if
(
insn
.
getArgsCount
()
!=
0
&&
insn
.
getCallMth
().
getDeclClass
().
getType
().
equals
(
ArgType
.
STRING
))
{
InsnArg
arg
=
insn
.
getArg
(
0
);
InsnNode
node
=
arg
.
isInsnWrap
()
?
((
InsnWrapArg
)
arg
).
getWrapInsn
()
:
insn
;
if
(
node
.
getArgsCount
()
!=
0
)
{
ArgType
argType
=
node
.
getArg
(
0
).
getType
();
if
(
node
.
getType
()
==
InsnType
.
FILLED_NEW_ARRAY
&&
(
argType
==
ArgType
.
BYTE
||
argType
==
ArgType
.
CHAR
))
{
int
printable
=
0
;
byte
[]
arr
=
new
byte
[
node
.
getArgsCount
()];
for
(
int
i
=
0
;
i
<
arr
.
length
;
i
++)
{
arr
[
i
]
=
(
byte
)
((
LiteralArg
)
node
.
getArg
(
i
)).
getLiteral
();
if
(
NameMapper
.
isPrintableChar
(
arr
[
i
]))
{
printable
++;
}
}
if
(
printable
>=
arr
.
length
-
printable
)
{
InsnWrapArg
wa
=
new
InsnWrapArg
(
new
ConstStringNode
(
new
String
(
arr
)));
if
(
insn
.
getArgsCount
()
==
1
)
{
insn
.
setArg
(
0
,
wa
);
}
else
{
MethodInfo
mi
=
MethodInfo
.
externalMth
(
ClassInfo
.
fromType
(
root
,
ArgType
.
STRING
),
"getBytes"
,
Collections
.
emptyList
(),
ArgType
.
array
(
ArgType
.
BYTE
));
InvokeNode
in
=
new
InvokeNode
(
mi
,
InvokeType
.
VIRTUAL
,
1
);
in
.
addArg
(
wa
);
insn
.
setArg
(
0
,
new
InsnWrapArg
(
in
));
}
}
}
}
}
}
private
static
InsnNode
processCast
(
MethodNode
mth
,
InsnNode
insn
)
{
private
static
InsnNode
processCast
(
MethodNode
mth
,
InsnNode
insn
)
{
InsnArg
castArg
=
insn
.
getArg
(
0
);
InsnArg
castArg
=
insn
.
getArg
(
0
);
ArgType
argType
=
castArg
.
getType
();
ArgType
argType
=
castArg
.
getType
();
...
...
jadx-core/src/test/java/jadx/tests/integration/others/TestStringConstructor.java
0 → 100644
浏览文件 @
ec66476a
package
jadx.tests.integration.others
;
import
static
jadx
.
tests
.
api
.
utils
.
JadxMatchers
.
containsOne
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
import
java.nio.charset.StandardCharsets
;
import
org.junit.jupiter.api.Test
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.tests.api.IntegrationTest
;
public
class
TestStringConstructor
extends
IntegrationTest
{
public
static
class
TestCls
{
public
String
tag
=
new
String
(
new
byte
[]
{
'a'
,
'b'
,
'c'
});
}
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsOne
(
"abc"
));
}
public
static
class
TestCls2
{
public
String
tag
=
new
String
(
new
byte
[]
{
'a'
,
'b'
,
'c'
},
StandardCharsets
.
UTF_8
);
}
@Test
public
void
test2
()
{
ClassNode
cls
=
getClassNode
(
TestCls2
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsOne
(
"new String(\"abc\".getBytes(), StandardCharsets.UTF_8)"
));
}
public
static
class
TestCls3
{
public
String
tag
=
new
String
(
new
byte
[]
{
1
,
2
,
3
,
'a'
,
'b'
,
'c'
});
}
@Test
public
void
test3
()
{
ClassNode
cls
=
getClassNode
(
TestCls3
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsOne
(
"\\u0001\\u0002\\u0003abc"
));
}
public
static
class
TestCls4
{
public
String
tag
=
new
String
(
new
char
[]
{
1
,
2
,
3
,
'a'
,
'b'
,
'c'
});
}
@Test
public
void
test4
()
{
ClassNode
cls
=
getClassNode
(
TestCls4
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsOne
(
"\\u0001\\u0002\\u0003abc"
));
}
public
static
class
TestCls5
{
public
String
tag
=
new
String
(
new
char
[]
{
1
,
2
,
3
,
'a'
,
'b'
});
}
@Test
public
void
test5
()
{
ClassNode
cls
=
getClassNode
(
TestCls5
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsOne
(
"{1, 2, 3, 'a', 'b'}"
));
}
public
static
class
TestClsNegative
{
public
String
tag
=
new
String
();
}
@Test
public
void
testNegative
()
{
ClassNode
cls
=
getClassNode
(
TestClsNegative
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsOne
(
"tag = new String();"
));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录