Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
ql04210214
jadx
提交
3bdda551
J
jadx
项目概览
ql04210214
/
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,发现更多精彩内容 >>
提交
3bdda551
编写于
8月 14, 2014
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
core: inline filled array creation
上级
b657b0fb
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
159 addition
and
10 deletion
+159
-10
jadx-core/src/main/java/jadx/core/Jadx.java
jadx-core/src/main/java/jadx/core/Jadx.java
+2
-0
jadx-core/src/main/java/jadx/core/codegen/InsnGen.java
jadx-core/src/main/java/jadx/core/codegen/InsnGen.java
+1
-1
jadx-core/src/main/java/jadx/core/dex/visitors/ReSugarCode.java
...ore/src/main/java/jadx/core/dex/visitors/ReSugarCode.java
+78
-0
jadx-core/src/main/java/jadx/core/utils/InstructionRemover.java
...ore/src/main/java/jadx/core/utils/InstructionRemover.java
+13
-7
jadx-core/src/test/java/jadx/tests/internal/TestFloatValue.java
...ore/src/test/java/jadx/tests/internal/TestFloatValue.java
+1
-1
jadx-core/src/test/java/jadx/tests/internal/annotations/TestVarArgAnnotation.java
...jadx/tests/internal/annotations/TestVarArgAnnotation.java
+1
-1
jadx-core/src/test/java/jadx/tests/internal/arrays/TestArrayFill.java
...c/test/java/jadx/tests/internal/arrays/TestArrayFill.java
+28
-0
jadx-core/src/test/java/jadx/tests/internal/arrays/TestArrayFill2.java
.../test/java/jadx/tests/internal/arrays/TestArrayFill2.java
+35
-0
未找到文件。
jadx-core/src/main/java/jadx/core/Jadx.java
浏览文件 @
3bdda551
...
...
@@ -14,6 +14,7 @@ import jadx.core.dex.visitors.IDexTreeVisitor;
import
jadx.core.dex.visitors.MethodInlineVisitor
;
import
jadx.core.dex.visitors.ModVisitor
;
import
jadx.core.dex.visitors.PrepareForCodeGen
;
import
jadx.core.dex.visitors.ReSugarCode
;
import
jadx.core.dex.visitors.SimplifyVisitor
;
import
jadx.core.dex.visitors.regions.CheckRegions
;
import
jadx.core.dex.visitors.regions.IfRegionVisitor
;
...
...
@@ -69,6 +70,7 @@ public class Jadx {
passes
.
add
(
new
EnumVisitor
());
passes
.
add
(
new
CodeShrinker
());
passes
.
add
(
new
ReSugarCode
());
if
(
args
.
isCFGOutput
())
{
passes
.
add
(
new
DotGraphVisitor
(
outDir
,
false
));
}
...
...
jadx-core/src/main/java/jadx/core/codegen/InsnGen.java
浏览文件 @
3bdda551
...
...
@@ -496,7 +496,7 @@ public class InsnGen {
useType
(
code
,
insn
.
getResult
().
getType
());
code
.
add
(
'{'
);
for
(
int
i
=
0
;
i
<
c
;
i
++)
{
addArg
(
code
,
insn
.
getArg
(
i
));
addArg
(
code
,
insn
.
getArg
(
i
)
,
false
);
if
(
i
+
1
<
c
)
{
code
.
add
(
", "
);
}
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/ReSugarCode.java
0 → 100644
浏览文件 @
3bdda551
package
jadx.core.dex.visitors
;
import
jadx.core.dex.instructions.InsnType
;
import
jadx.core.dex.instructions.args.InsnArg
;
import
jadx.core.dex.instructions.args.LiteralArg
;
import
jadx.core.dex.nodes.BlockNode
;
import
jadx.core.dex.nodes.InsnNode
;
import
jadx.core.dex.nodes.MethodNode
;
import
jadx.core.utils.InstructionRemover
;
import
jadx.core.utils.exceptions.JadxException
;
import
java.util.List
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
public
class
ReSugarCode
extends
AbstractVisitor
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
ReSugarCode
.
class
);
@Override
public
void
visit
(
MethodNode
mth
)
throws
JadxException
{
if
(
mth
.
isNoCode
())
{
return
;
}
InstructionRemover
remover
=
new
InstructionRemover
(
mth
);
for
(
BlockNode
block
:
mth
.
getBasicBlocks
())
{
remover
.
setBlock
(
block
);
List
<
InsnNode
>
instructions
=
block
.
getInstructions
();
int
size
=
instructions
.
size
();
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
InsnNode
replacedInsn
=
process
(
mth
,
instructions
,
i
,
remover
);
if
(
replacedInsn
!=
null
)
{
instructions
.
set
(
i
,
replacedInsn
);
}
}
remover
.
perform
();
}
}
private
static
InsnNode
process
(
MethodNode
mth
,
List
<
InsnNode
>
instructions
,
int
i
,
InstructionRemover
remover
)
{
InsnNode
insn
=
instructions
.
get
(
i
);
switch
(
insn
.
getType
())
{
case
NEW_ARRAY:
return
processNewArray
(
mth
,
instructions
,
i
,
remover
);
default
:
return
null
;
}
}
/**
* Replace new array and sequence of array-put to new filled-array instruction.
*/
private
static
InsnNode
processNewArray
(
MethodNode
mth
,
List
<
InsnNode
>
instructions
,
int
i
,
InstructionRemover
remover
)
{
InsnNode
insn
=
instructions
.
get
(
i
);
InsnArg
arg
=
insn
.
getArg
(
0
);
if
(!
arg
.
isLiteral
())
{
return
null
;
}
int
len
=
(
int
)
((
LiteralArg
)
arg
).
getLiteral
();
int
size
=
instructions
.
size
();
if
(
len
<=
0
||
i
+
len
>=
size
||
instructions
.
get
(
i
+
len
).
getType
()
!=
InsnType
.
APUT
)
{
return
null
;
}
InsnNode
filledArr
=
new
InsnNode
(
InsnType
.
FILLED_NEW_ARRAY
,
len
);
filledArr
.
setResult
(
insn
.
getResult
());
for
(
int
j
=
0
;
j
<
len
;
j
++)
{
InsnNode
put
=
instructions
.
get
(
i
+
1
+
j
);
if
(
put
.
getType
()
!=
InsnType
.
APUT
)
{
LOG
.
debug
(
"Not a APUT in expected new filled array: {}, method: {}"
,
put
,
mth
);
return
null
;
}
filledArr
.
addArg
(
put
.
getArg
(
2
));
remover
.
add
(
put
);
}
return
filledArr
;
}
}
jadx-core/src/main/java/jadx/core/utils/InstructionRemover.java
浏览文件 @
3bdda551
...
...
@@ -26,17 +26,23 @@ public class InstructionRemover {
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
InstructionRemover
.
class
);
private
final
MethodNode
mth
;
private
final
List
<
InsnNode
>
insns
;
private
final
List
<
InsnNode
>
toRemove
;
private
List
<
InsnNode
>
instrList
;
public
InstructionRemover
(
MethodNode
mth
,
BlockNode
block
)
{
this
(
mth
,
block
.
getInstructions
()
);
public
InstructionRemover
(
MethodNode
mth
)
{
this
(
mth
,
null
);
}
public
InstructionRemover
(
MethodNode
mth
,
List
<
InsnNode
>
instructions
)
{
public
InstructionRemover
(
MethodNode
mth
,
BlockNode
block
)
{
this
.
mth
=
mth
;
this
.
insns
=
instructions
;
this
.
toRemove
=
new
ArrayList
<
InsnNode
>();
if
(
block
!=
null
)
{
this
.
instrList
=
block
.
getInstructions
();
}
}
public
void
setBlock
(
BlockNode
block
)
{
this
.
instrList
=
block
.
getInstructions
();
}
public
void
add
(
InsnNode
insn
)
{
...
...
@@ -47,7 +53,7 @@ public class InstructionRemover {
if
(
toRemove
.
isEmpty
())
{
return
;
}
removeAll
(
mth
,
ins
ns
,
toRemove
);
removeAll
(
mth
,
ins
trList
,
toRemove
);
toRemove
.
clear
();
}
...
...
@@ -84,7 +90,7 @@ public class InstructionRemover {
}
}
// Don't use 'ins
ns
.removeAll(toRemove)' because it will remove instructions by content
// Don't use 'ins
trList
.removeAll(toRemove)' because it will remove instructions by content
// and here can be several instructions with same content
private
static
void
removeAll
(
MethodNode
mth
,
List
<
InsnNode
>
insns
,
List
<
InsnNode
>
toRemove
)
{
for
(
InsnNode
rem
:
toRemove
)
{
...
...
jadx-core/src/test/java/jadx/tests/internal/TestFloatValue.java
浏览文件 @
3bdda551
...
...
@@ -25,7 +25,7 @@ public class TestFloatValue extends InternalJadxTest {
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
not
(
containsString
(
"1073741824"
)));
assertThat
(
code
,
containsString
(
"0.55f
;
"
));
assertThat
(
code
,
containsString
(
"0.55f"
));
assertThat
(
code
,
containsString
(
"fa[0] = fa[0] / 2.0f;"
));
}
}
jadx-core/src/test/java/jadx/tests/internal/annotations/TestVarArgAnnotation.java
浏览文件 @
3bdda551
...
...
@@ -39,7 +39,7 @@ public class TestVarArgAnnotation extends InternalJadxTest {
// TODO:
assertThat
(
code
,
containsString
(
"test1(new int[]{1, 2});"
));
assertThat
(
code
,
containsString
(
"test2(3,
objArr
);"
));
assertThat
(
code
,
containsString
(
"test2(3,
new Object[]{\"1\", Integer.valueOf(7)}
);"
));
// negative case
assertThat
(
code
,
containsString
(
"void test3(int[] a) {"
));
...
...
jadx-core/src/test/java/jadx/tests/internal/arrays/TestArrayFill.java
0 → 100644
浏览文件 @
3bdda551
package
jadx.tests.internal.arrays
;
import
jadx.api.InternalJadxTest
;
import
jadx.core.dex.nodes.ClassNode
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TestArrayFill
extends
InternalJadxTest
{
public
static
class
TestCls
{
public
String
[]
method
()
{
return
new
String
[]{
"1"
,
"2"
,
"3"
};
}
}
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
System
.
out
.
println
(
code
);
assertThat
(
code
,
containsString
(
"return new String[]{\"1\", \"2\", \"3\"};"
));
}
}
jadx-core/src/test/java/jadx/tests/internal/arrays/TestArrayFill2.java
0 → 100644
浏览文件 @
3bdda551
package
jadx.tests.internal.arrays
;
import
jadx.api.InternalJadxTest
;
import
jadx.core.dex.nodes.ClassNode
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TestArrayFill2
extends
InternalJadxTest
{
public
static
class
TestCls
{
public
int
[]
test
(
int
a
)
{
return
new
int
[]{
1
,
a
+
1
,
2
};
}
public
int
[]
test2
(
int
a
)
{
return
new
int
[]{
1
,
a
++,
a
*
2
};
}
}
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
System
.
out
.
println
(
code
);
assertThat
(
code
,
containsString
(
"return new int[]{1, a + 1, 2};"
));
// TODO
// assertThat(code, containsString("return new int[]{1, a++, a * 2};"));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录