Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2301_76393173
jadx
提交
bd4c61d3
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,发现更多精彩内容 >>
提交
bd4c61d3
编写于
9月 28, 2013
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
core: fix incorrect float values processing
上级
00a6b6ef
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
172 addition
and
20 deletion
+172
-20
jadx-core/src/main/java/jadx/core/codegen/TypeGen.java
jadx-core/src/main/java/jadx/core/codegen/TypeGen.java
+2
-1
jadx-core/src/main/java/jadx/core/dex/instructions/args/ArgType.java
...rc/main/java/jadx/core/dex/instructions/args/ArgType.java
+11
-1
jadx-core/src/main/java/jadx/core/dex/instructions/args/LiteralArg.java
...main/java/jadx/core/dex/instructions/args/LiteralArg.java
+12
-2
jadx-core/src/main/java/jadx/core/dex/visitors/ConstInlinerVisitor.java
...main/java/jadx/core/dex/visitors/ConstInlinerVisitor.java
+44
-16
jadx-core/src/test/java/jadx/tests/internal/TestArgInline.java
...core/src/test/java/jadx/tests/internal/TestArgInline.java
+30
-0
jadx-core/src/test/java/jadx/tests/internal/TestFloatValue.java
...ore/src/test/java/jadx/tests/internal/TestFloatValue.java
+31
-0
jadx-core/src/test/java/jadx/tests/internal/TestVariablesDefinitions.java
...st/java/jadx/tests/internal/TestVariablesDefinitions.java
+42
-0
未找到文件。
jadx-core/src/main/java/jadx/core/codegen/TypeGen.java
浏览文件 @
bd4c61d3
...
@@ -41,10 +41,11 @@ public class TypeGen {
...
@@ -41,10 +41,11 @@ public class TypeGen {
public
static
String
literalToString
(
long
lit
,
ArgType
type
)
{
public
static
String
literalToString
(
long
lit
,
ArgType
type
)
{
if
(
type
==
null
||
!
type
.
isTypeKnown
())
{
if
(
type
==
null
||
!
type
.
isTypeKnown
())
{
String
n
=
Long
.
toString
(
lit
);
String
n
=
Long
.
toString
(
lit
);
if
(
Math
.
abs
(
lit
)
>
100
)
if
(
Math
.
abs
(
lit
)
>
100
)
{
n
+=
"; // 0x"
+
Long
.
toHexString
(
lit
)
n
+=
"; // 0x"
+
Long
.
toHexString
(
lit
)
+
" float:"
+
Float
.
intBitsToFloat
((
int
)
lit
)
+
" float:"
+
Float
.
intBitsToFloat
((
int
)
lit
)
+
" double:"
+
Double
.
longBitsToDouble
(
lit
);
+
" double:"
+
Double
.
longBitsToDouble
(
lit
);
}
return
n
;
return
n
;
}
}
...
...
jadx-core/src/main/java/jadx/core/dex/instructions/args/ArgType.java
浏览文件 @
bd4c61d3
...
@@ -40,6 +40,10 @@ public abstract class ArgType {
...
@@ -40,6 +40,10 @@ public abstract class ArgType {
PrimitiveType
.
BOOLEAN
,
PrimitiveType
.
SHORT
,
PrimitiveType
.
BYTE
,
PrimitiveType
.
CHAR
,
PrimitiveType
.
BOOLEAN
,
PrimitiveType
.
SHORT
,
PrimitiveType
.
BYTE
,
PrimitiveType
.
CHAR
,
PrimitiveType
.
OBJECT
,
PrimitiveType
.
ARRAY
);
PrimitiveType
.
OBJECT
,
PrimitiveType
.
ARRAY
);
public
static
final
ArgType
NARROW_NUMBERS
=
unknown
(
PrimitiveType
.
INT
,
PrimitiveType
.
FLOAT
,
PrimitiveType
.
BOOLEAN
,
PrimitiveType
.
SHORT
,
PrimitiveType
.
BYTE
,
PrimitiveType
.
CHAR
);
public
static
final
ArgType
WIDE
=
unknown
(
PrimitiveType
.
LONG
,
PrimitiveType
.
DOUBLE
);
public
static
final
ArgType
WIDE
=
unknown
(
PrimitiveType
.
LONG
,
PrimitiveType
.
DOUBLE
);
protected
int
hash
;
protected
int
hash
;
...
@@ -597,8 +601,14 @@ public abstract class ArgType {
...
@@ -597,8 +601,14 @@ public abstract class ArgType {
public
int
getRegCount
()
{
public
int
getRegCount
()
{
if
(
isPrimitive
())
{
if
(
isPrimitive
())
{
PrimitiveType
type
=
getPrimitiveType
();
PrimitiveType
type
=
getPrimitiveType
();
if
(
type
==
PrimitiveType
.
LONG
||
type
==
PrimitiveType
.
DOUBLE
)
if
(
type
==
PrimitiveType
.
LONG
||
type
==
PrimitiveType
.
DOUBLE
)
{
return
2
;
return
2
;
}
else
{
return
1
;
}
}
if
(!
isTypeKnown
())
{
return
0
;
}
}
return
1
;
return
1
;
}
}
...
...
jadx-core/src/main/java/jadx/core/dex/instructions/args/LiteralArg.java
浏览文件 @
bd4c61d3
...
@@ -8,10 +8,20 @@ public final class LiteralArg extends InsnArg {
...
@@ -8,10 +8,20 @@ public final class LiteralArg extends InsnArg {
private
final
long
literal
;
private
final
long
literal
;
public
LiteralArg
(
long
value
,
ArgType
type
)
{
public
LiteralArg
(
long
value
,
ArgType
type
)
{
if
(
value
!=
0
)
{
if
(
type
.
isObject
())
{
throw
new
JadxRuntimeException
(
"Wrong literal type: "
+
type
+
" for value: "
+
value
);
}
else
if
(!
type
.
isTypeKnown
()
&&
!
type
.
contains
(
PrimitiveType
.
LONG
)
&&
!
type
.
contains
(
PrimitiveType
.
DOUBLE
))
{
ArgType
m
=
ArgType
.
merge
(
type
,
ArgType
.
NARROW_NUMBERS
);
if
(
m
!=
null
)
{
type
=
m
;
}
}
}
this
.
literal
=
value
;
this
.
literal
=
value
;
this
.
typedVar
=
new
TypedVar
(
type
);
this
.
typedVar
=
new
TypedVar
(
type
);
if
(
literal
!=
0
&&
type
.
isObject
())
throw
new
RuntimeException
(
"wrong literal type"
);
}
}
public
long
getLiteral
()
{
public
long
getLiteral
()
{
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/ConstInlinerVisitor.java
浏览文件 @
bd4c61d3
...
@@ -37,8 +37,12 @@ public class ConstInlinerVisitor extends AbstractVisitor {
...
@@ -37,8 +37,12 @@ public class ConstInlinerVisitor extends AbstractVisitor {
private
static
boolean
checkInsn
(
MethodNode
mth
,
BlockNode
block
,
InsnNode
insn
)
{
private
static
boolean
checkInsn
(
MethodNode
mth
,
BlockNode
block
,
InsnNode
insn
)
{
if
(
insn
.
getType
()
==
InsnType
.
CONST
)
{
if
(
insn
.
getType
()
==
InsnType
.
CONST
)
{
InsnArg
arg
=
insn
.
getArg
(
0
);
InsnArg
arg
=
insn
.
getArg
(
0
);
if
(
arg
.
isLiteral
()
if
(
arg
.
isLiteral
())
{
&&
insn
.
getResult
().
getType
().
getRegCount
()
==
1
/* process only narrow types */
)
{
ArgType
resType
=
insn
.
getResult
().
getType
();
// make sure arg has correct type
if
(!
arg
.
getType
().
isTypeKnown
())
{
arg
.
merge
(
resType
);
}
long
lit
=
((
LiteralArg
)
arg
).
getLiteral
();
long
lit
=
((
LiteralArg
)
arg
).
getLiteral
();
return
replaceConst
(
mth
,
block
,
insn
,
lit
);
return
replaceConst
(
mth
,
block
,
insn
,
lit
);
}
}
...
@@ -61,17 +65,9 @@ public class ConstInlinerVisitor extends AbstractVisitor {
...
@@ -61,17 +65,9 @@ public class ConstInlinerVisitor extends AbstractVisitor {
if
(
arg
!=
insn
.
getResult
()
&&
!
registerReassignOnPath
(
block
,
useBlock
,
insn
))
{
if
(
arg
!=
insn
.
getResult
()
&&
!
registerReassignOnPath
(
block
,
useBlock
,
insn
))
{
// in most cases type not equal arg.getType()
// in most cases type not equal arg.getType()
// just set unknown type and run type fixer
// just set unknown type and run type fixer
LiteralArg
litArg
=
InsnArg
.
lit
(
literal
,
ArgType
.
NARROW
);
LiteralArg
litArg
=
InsnArg
.
lit
(
literal
,
ArgType
.
UNKNOWN
);
if
(
useInsn
.
replaceArg
(
arg
,
litArg
))
{
if
(
useInsn
.
replaceArg
(
arg
,
litArg
))
{
// if (useInsn.getType() == InsnType.MOVE) {
fixTypes
(
mth
,
useInsn
,
litArg
);
// // 'move' became 'const'
// InsnNode constInsn = new InsnNode(mth, InsnType.CONST, 1);
// constInsn.setResult(useInsn.getResult());
// constInsn.addArg(litArg);
// ModVisitor.replaceInsn(useBlock, useInsn, constInsn);
// fixTypes(mth, constInsn);
// }
fixTypes
(
mth
,
useInsn
);
replace
++;
replace
++;
}
}
}
}
...
@@ -102,7 +98,7 @@ public class ConstInlinerVisitor extends AbstractVisitor {
...
@@ -102,7 +98,7 @@ public class ConstInlinerVisitor extends AbstractVisitor {
* This is method similar to PostTypeResolver.visit method,
* This is method similar to PostTypeResolver.visit method,
* but contains some expensive operations needed only after constant inline
* but contains some expensive operations needed only after constant inline
*/
*/
private
static
void
fixTypes
(
MethodNode
mth
,
InsnNode
insn
)
{
private
static
void
fixTypes
(
MethodNode
mth
,
InsnNode
insn
,
LiteralArg
litArg
)
{
switch
(
insn
.
getType
())
{
switch
(
insn
.
getType
())
{
case
CONST:
case
CONST:
insn
.
getArg
(
0
).
merge
(
insn
.
getResult
());
insn
.
getArg
(
0
).
merge
(
insn
.
getResult
());
...
@@ -120,13 +116,30 @@ public class ConstInlinerVisitor extends AbstractVisitor {
...
@@ -120,13 +116,30 @@ public class ConstInlinerVisitor extends AbstractVisitor {
break
;
break
;
}
}
case
IF:
case
IF:
{
IfNode
ifnode
=
(
IfNode
)
insn
;
IfNode
ifnode
=
(
IfNode
)
insn
;
if
(!
ifnode
.
isZeroCmp
())
{
if
(!
ifnode
.
isZeroCmp
())
{
insn
.
getArg
(
1
).
merge
(
insn
.
getArg
(
0
));
InsnArg
arg0
=
insn
.
getArg
(
0
);
insn
.
getArg
(
0
).
merge
(
insn
.
getArg
(
1
));
InsnArg
arg1
=
insn
.
getArg
(
1
);
if
(
arg0
==
litArg
)
{
arg0
.
merge
(
arg1
);
}
else
{
arg1
.
merge
(
arg0
);
}
}
}
break
;
break
;
}
case
CMP_G:
case
CMP_L:
{
InsnArg
arg0
=
insn
.
getArg
(
0
);
InsnArg
arg1
=
insn
.
getArg
(
1
);
if
(
arg0
==
litArg
)
{
arg0
.
merge
(
arg1
);
}
else
{
arg1
.
merge
(
arg0
);
}
break
;
}
case
RETURN:
case
RETURN:
if
(
insn
.
getArgsCount
()
!=
0
)
{
if
(
insn
.
getArgsCount
()
!=
0
)
{
...
@@ -153,6 +166,21 @@ public class ConstInlinerVisitor extends AbstractVisitor {
...
@@ -153,6 +166,21 @@ public class ConstInlinerVisitor extends AbstractVisitor {
}
}
break
;
break
;
case
ARITH:
litArg
.
merge
(
insn
.
getResult
());
break
;
case
APUT:
case
AGET:
if
(
litArg
==
insn
.
getArg
(
1
))
{
litArg
.
merge
(
ArgType
.
INT
);
}
break
;
case
NEW_ARRAY:
litArg
.
merge
(
ArgType
.
INT
);
break
;
default
:
default
:
break
;
break
;
}
}
...
...
jadx-core/src/test/java/jadx/tests/internal/TestArgInline.java
0 → 100644
浏览文件 @
bd4c61d3
package
jadx.tests.internal
;
import
jadx.api.InternalJadxTest
;
import
jadx.core.dex.nodes.ClassNode
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
import
static
org
.
hamcrest
.
CoreMatchers
.
not
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TestArgInline
extends
InternalJadxTest
{
public
static
class
TestCls
{
public
void
method
(
int
a
)
{
while
(
a
<
10
)
{
int
b
=
a
+
1
;
a
=
b
;
}
}
}
//@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
System
.
out
.
println
(
code
);
assertThat
(
code
,
not
(
containsString
(
"a = a + 1;"
)));
assertThat
(
code
,
containsString
(
"a++;"
));
}
}
jadx-core/src/test/java/jadx/tests/internal/TestFloatValue.java
0 → 100644
浏览文件 @
bd4c61d3
package
jadx.tests.internal
;
import
jadx.api.InternalJadxTest
;
import
jadx.core.dex.nodes.ClassNode
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
import
static
org
.
hamcrest
.
CoreMatchers
.
not
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TestFloatValue
extends
InternalJadxTest
{
public
static
class
TestCls
{
public
float
[]
method
()
{
float
[]
fa
=
{
0.55f
};
fa
[
0
]
/=
2
;
return
fa
;
}
}
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
not
(
containsString
(
"1073741824"
)));
assertThat
(
code
,
containsString
(
"0.55f;"
));
assertThat
(
code
,
containsString
(
"fa[0] = fa[0] / 2.0f;"
));
}
}
jadx-core/src/test/java/jadx/tests/internal/TestVariablesDefinitions.java
0 → 100644
浏览文件 @
bd4c61d3
package
jadx.tests.internal
;
import
jadx.api.InternalJadxTest
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.core.dex.visitors.DepthTraverser
;
import
jadx.core.dex.visitors.IDexTreeVisitor
;
import
jadx.core.utils.exceptions.DecodeException
;
import
java.util.List
;
import
org.slf4j.Logger
;
public
class
TestVariablesDefinitions
extends
InternalJadxTest
{
public
static
class
TestCls
{
private
static
Logger
LOG
;
private
ClassNode
cls
;
private
List
<
IDexTreeVisitor
>
passes
;
public
void
run
()
{
try
{
cls
.
load
();
for
(
IDexTreeVisitor
visitor
:
passes
)
{
DepthTraverser
.
visit
(
visitor
,
cls
);
}
}
catch
(
DecodeException
e
)
{
LOG
.
error
(
"Decode exception: "
+
cls
,
e
);
}
finally
{
cls
.
unload
();
}
}
}
//@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
System
.
out
.
println
(
code
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录