Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Quincy379
jadx
提交
b52f3525
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,发现更多精彩内容 >>
提交
b52f3525
编写于
1月 28, 2018
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
core: support 'not-int' and 'not-long' instructions
上级
20bf85b1
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
118 addition
and
61 deletion
+118
-61
jadx-core/build.gradle
jadx-core/build.gradle
+2
-1
jadx-core/src/main/java/jadx/core/codegen/InsnGen.java
jadx-core/src/main/java/jadx/core/codegen/InsnGen.java
+18
-11
jadx-core/src/main/java/jadx/core/dex/instructions/InsnDecoder.java
...src/main/java/jadx/core/dex/instructions/InsnDecoder.java
+12
-0
jadx-core/src/main/java/jadx/core/dex/instructions/InsnType.java
...re/src/main/java/jadx/core/dex/instructions/InsnType.java
+1
-0
jadx-core/src/main/java/jadx/core/utils/ErrorsCounter.java
jadx-core/src/main/java/jadx/core/utils/ErrorsCounter.java
+2
-18
jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java
jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java
+5
-12
jadx-core/src/test/java/jadx/tests/api/SmaliTest.java
jadx-core/src/test/java/jadx/tests/api/SmaliTest.java
+20
-16
jadx-core/src/test/java/jadx/tests/api/compiler/StaticCompiler.java
...src/test/java/jadx/tests/api/compiler/StaticCompiler.java
+1
-1
jadx-core/src/test/java/jadx/tests/integration/arith/TestArithConst.java
...est/java/jadx/tests/integration/arith/TestArithConst.java
+2
-2
jadx-core/src/test/java/jadx/tests/integration/arith/TestArithNot.java
.../test/java/jadx/tests/integration/arith/TestArithNot.java
+35
-0
jadx-core/src/test/smali/arith/TestArithConst.smali
jadx-core/src/test/smali/arith/TestArithConst.smali
+0
-0
jadx-core/src/test/smali/arith/TestArithNot.smali
jadx-core/src/test/smali/arith/TestArithNot.smali
+20
-0
未找到文件。
jadx-core/build.gradle
浏览文件 @
b52f3525
...
...
@@ -9,6 +9,7 @@ dependencies {
compile
'com.intellij:annotations:12.0'
compile
'uk.com.robust-it:cloning:1.9.2'
testCompile
'org.smali:smali:2.0.3'
testCompile
'org.smali:smali:2.2.2'
testCompile
'org.smali:baksmali:2.2.2'
}
jadx-core/src/main/java/jadx/core/codegen/InsnGen.java
浏览文件 @
b52f3525
...
...
@@ -270,18 +270,13 @@ public class InsnGen {
makeArith
((
ArithNode
)
insn
,
code
,
state
);
break
;
case
NEG:
{
boolean
wrap
=
state
.
contains
(
Flags
.
BODY_ONLY
);
if
(
wrap
)
{
code
.
add
(
'('
);
}
code
.
add
(
'-'
);
addArg
(
code
,
insn
.
getArg
(
0
));
if
(
wrap
)
{
code
.
add
(
')'
);
}
case
NEG:
oneArgInsn
(
code
,
insn
,
state
,
'-'
);
break
;
case
NOT:
oneArgInsn
(
code
,
insn
,
state
,
'~'
);
break
;
}
case
RETURN:
if
(
insn
.
getArgsCount
()
!=
0
)
{
...
...
@@ -525,6 +520,18 @@ public class InsnGen {
}
}
private
void
oneArgInsn
(
CodeWriter
code
,
InsnNode
insn
,
Set
<
Flags
>
state
,
char
op
)
throws
CodegenException
{
boolean
wrap
=
state
.
contains
(
Flags
.
BODY_ONLY
);
if
(
wrap
)
{
code
.
add
(
'('
);
}
code
.
add
(
op
);
addArg
(
code
,
insn
.
getArg
(
0
));
if
(
wrap
)
{
code
.
add
(
')'
);
}
}
private
void
fallbackOnlyInsn
(
InsnNode
insn
)
throws
CodegenException
{
if
(!
fallback
)
{
throw
new
CodegenException
(
insn
.
getType
()
+
" can be used only in fallback mode"
);
...
...
jadx-core/src/main/java/jadx/core/dex/instructions/InsnDecoder.java
浏览文件 @
b52f3525
...
...
@@ -324,6 +324,11 @@ public class InsnDecoder {
case
Opcodes
.
NEG_DOUBLE
:
return
neg
(
insn
,
ArgType
.
DOUBLE
);
case
Opcodes
.
NOT_INT
:
return
not
(
insn
,
ArgType
.
INT
);
case
Opcodes
.
NOT_LONG
:
return
not
(
insn
,
ArgType
.
LONG
);
case
Opcodes
.
INT_TO_BYTE
:
return
cast
(
insn
,
ArgType
.
INT
,
ArgType
.
BYTE
);
case
Opcodes
.
INT_TO_CHAR
:
...
...
@@ -699,6 +704,13 @@ public class InsnDecoder {
return
inode
;
}
private
InsnNode
not
(
DecodedInstruction
insn
,
ArgType
type
)
{
InsnNode
inode
=
new
InsnNode
(
InsnType
.
NOT
,
1
);
inode
.
setResult
(
InsnArg
.
reg
(
insn
,
0
,
type
));
inode
.
addArg
(
InsnArg
.
reg
(
insn
,
1
,
type
));
return
inode
;
}
private
InsnNode
insn
(
InsnType
type
,
RegisterArg
res
)
{
InsnNode
node
=
new
InsnNode
(
type
,
0
);
node
.
setResult
(
res
);
...
...
jadx-core/src/main/java/jadx/core/dex/instructions/InsnType.java
浏览文件 @
b52f3525
...
...
@@ -8,6 +8,7 @@ public enum InsnType {
ARITH
,
NEG
,
NOT
,
MOVE
,
CAST
,
...
...
jadx-core/src/main/java/jadx/core/utils/ErrorsCounter.java
浏览文件 @
b52f3525
...
...
@@ -81,26 +81,10 @@ public class ErrorsCounter {
}
public
static
String
formatErrorMsg
(
ClassNode
cls
,
String
msg
)
{
return
msg
+
" in class: "
+
cls
;
return
msg
+
" in class: "
+
cls
+
", dex: "
+
cls
.
dex
().
getDexFile
().
getName
()
;
}
public
static
String
formatErrorMsg
(
MethodNode
mth
,
String
msg
)
{
return
msg
+
" in method: "
+
mth
;
}
private
String
formatException
(
Throwable
e
)
{
if
(
e
==
null
||
e
.
getMessage
()
==
null
)
{
return
""
;
}
else
{
return
"\n error: "
+
e
.
getMessage
();
}
}
public
String
formatErrorMsg
(
ClassNode
cls
,
String
msg
,
Throwable
e
)
{
return
formatErrorMsg
(
cls
,
msg
)
+
formatException
(
e
);
}
public
String
formatErrorMsg
(
MethodNode
mth
,
String
msg
,
Throwable
e
)
{
return
formatErrorMsg
(
mth
,
msg
)
+
formatException
(
e
);
return
msg
+
" in method: "
+
mth
+
", dex: "
+
mth
.
dex
().
getDexFile
().
getName
();
}
}
jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java
浏览文件 @
b52f3525
...
...
@@ -35,7 +35,6 @@ import jadx.tests.api.compiler.StaticCompiler;
import
jadx.tests.api.utils.TestUtils
;
import
static
jadx
.
core
.
utils
.
files
.
FileUtils
.
addFileToJar
;
import
static
jadx
.
core
.
utils
.
files
.
FileUtils
.
close
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
hamcrest
.
Matchers
.
empty
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
...
...
@@ -261,11 +260,11 @@ public abstract class IntegrationTest extends TestUtils {
assertThat
(
"File list is empty"
,
list
,
not
(
empty
()));
File
temp
=
createTempFile
(
".jar"
);
JarOutputStream
jo
=
new
JarOutputStream
(
new
FileOutputStream
(
temp
));
for
(
File
file
:
list
)
{
addFileToJar
(
jo
,
file
,
path
+
"/"
+
file
.
getName
());
try
(
JarOutputStream
jo
=
new
JarOutputStream
(
new
FileOutputStream
(
temp
)))
{
for
(
File
file
:
list
)
{
addFileToJar
(
jo
,
file
,
path
+
"/"
+
file
.
getName
());
}
}
close
(
jo
);
return
temp
;
}
...
...
@@ -336,13 +335,7 @@ public abstract class IntegrationTest extends TestUtils {
outTmp
.
deleteOnExit
();
List
<
File
>
files
=
StaticCompiler
.
compile
(
compileFileList
,
outTmp
,
withDebugInfo
);
// remove classes which are parents for test class
Iterator
<
File
>
iterator
=
files
.
iterator
();
while
(
iterator
.
hasNext
())
{
File
next
=
iterator
.
next
();
if
(!
next
.
getName
().
contains
(
cls
.
getSimpleName
()))
{
iterator
.
remove
();
}
}
files
.
removeIf
(
next
->
!
next
.
getName
().
contains
(
cls
.
getSimpleName
()));
for
(
File
clsFile
:
files
)
{
clsFile
.
deleteOnExit
();
}
...
...
jadx-core/src/test/java/jadx/tests/api/SmaliTest.java
浏览文件 @
b52f3525
package
jadx.tests.api
;
import
java.io.File
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.jf.smali.main
;
import
org.jf.smali.Smali
;
import
org.jf.smali.SmaliOptions
;
import
jadx.core.dex.nodes.ClassNode
;
import
static
org
.
junit
.
Assert
.
fail
;
public
abstract
class
SmaliTest
extends
IntegrationTest
{
private
static
final
String
SMALI_TESTS_PROJECT
=
"jadx-core"
;
private
static
final
String
SMALI_TESTS_DIR
=
"src/test/smali"
;
private
static
final
String
SMALI_TESTS_EXT
=
".smali"
;
protected
ClassNode
getClassNodeFromSmali
(
String
clsName
)
{
File
smaliFile
=
getSmaliFile
(
clsNam
e
);
protected
ClassNode
getClassNodeFromSmali
(
String
file
,
String
clsName
)
{
File
smaliFile
=
getSmaliFile
(
fil
e
);
File
outDex
=
createTempFile
(
".dex"
);
compileSmali
(
smaliFile
,
outDex
);
return
getClassNodeFromFile
(
outDex
,
clsName
);
}
protected
ClassNode
getClassNodeFromSmaliWithPath
(
String
path
,
String
clsName
)
{
return
getClassNodeFromSmali
(
path
+
File
.
separatorChar
+
clsName
,
clsName
);
}
protected
ClassNode
getClassNodeFromSmali
(
String
clsName
)
{
return
getClassNodeFromSmali
(
clsName
,
clsName
);
}
private
static
File
getSmaliFile
(
String
clsName
)
{
File
smaliFile
=
new
File
(
SMALI_TESTS_DIR
,
clsName
+
SMALI_TESTS_EXT
);
if
(
smaliFile
.
exists
())
{
...
...
@@ -32,18 +37,17 @@ public abstract class SmaliTest extends IntegrationTest {
if
(
smaliFile
.
exists
())
{
return
smaliFile
;
}
fail
(
"Smali file not found: "
+
SMALI_TESTS_DIR
+
"/"
+
clsName
+
SMALI_TESTS_EXT
);
return
null
;
throw
new
AssertionError
(
"Smali file not found: "
+
SMALI_TESTS_DIR
+
"/"
+
clsName
+
SMALI_TESTS_EXT
);
}
private
static
boolean
compileSmali
(
File
input
,
File
output
)
{
List
<
String
>
args
=
new
ArrayList
<>();
args
.
add
(
input
.
getAbsolutePath
()
);
args
.
add
(
"-o"
);
args
.
add
(
output
.
getAbsolutePath
());
main
.
main
(
args
.
toArray
(
new
String
[
args
.
size
()]));
try
{
SmaliOptions
params
=
new
SmaliOptions
(
);
params
.
outputDexFile
=
output
.
getAbsolutePath
();
Smali
.
assemble
(
params
,
input
.
getAbsolutePath
()
);
}
catch
(
Exception
e
)
{
throw
new
AssertionError
(
"Smali assemble error"
,
e
);
}
return
true
;
}
}
jadx-core/src/test/java/jadx/tests/api/compiler/StaticCompiler.java
浏览文件 @
b52f3525
...
...
@@ -22,7 +22,7 @@ import static javax.tools.JavaCompiler.CompilationTask;
public
class
StaticCompiler
{
private
static
final
List
<
String
>
COMMON_ARGS
=
Arrays
.
asList
(
"-source 1.
7 -target 1.7
"
.
split
(
" "
));
private
static
final
List
<
String
>
COMMON_ARGS
=
Arrays
.
asList
(
"-source 1.
8 -target 1.8
"
.
split
(
" "
));
public
static
List
<
File
>
compile
(
List
<
File
>
files
,
File
outDir
,
boolean
includeDebugInfo
)
throws
IOException
{
...
...
jadx-core/src/test/java/jadx/tests/
smali
/TestArithConst.java
→
jadx-core/src/test/java/jadx/tests/
integration/arith
/TestArithConst.java
浏览文件 @
b52f3525
package
jadx.tests.
smali
;
package
jadx.tests.
integration.arith
;
import
org.junit.Test
;
...
...
@@ -13,7 +13,7 @@ public class TestArithConst extends SmaliTest {
@Test
public
void
test
()
{
noDebugInfo
();
ClassNode
cls
=
getClassNodeFromSmali
(
"TestArithConst"
);
ClassNode
cls
=
getClassNodeFromSmali
WithPath
(
"arith"
,
"TestArithConst"
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsOne
(
"return i + CONST_INT;"
));
...
...
jadx-core/src/test/java/jadx/tests/integration/arith/TestArithNot.java
0 → 100644
浏览文件 @
b52f3525
package
jadx.tests.integration.arith
;
import
org.junit.Test
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.tests.api.SmaliTest
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
import
static
org
.
hamcrest
.
Matchers
.
not
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TestArithNot
extends
SmaliTest
{
/*
Smali Code equivalent:
public static class TestCls {
public int test1(int a) {
return ~a;
}
public long test2(long b) {
return ~b;
}
}
*/
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNodeFromSmaliWithPath
(
"arith"
,
"TestArithNot"
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsString
(
"return ~a;"
));
assertThat
(
code
,
containsString
(
"return ~b;"
));
assertThat
(
code
,
not
(
containsString
(
"^"
)));
}
}
jadx-core/src/test/smali/TestArithConst.smali
→
jadx-core/src/test/smali/
arith/
TestArithConst.smali
浏览文件 @
b52f3525
文件已移动
jadx-core/src/test/smali/arith/TestArithNot.smali
0 → 100644
浏览文件 @
b52f3525
.class public LTestArithNot;
.super Ljava/lang/Object;
.method private test1(I)I
.registers 2
.param p1, "a"
not-int v0, p1
return v0
.end method
.method private test2(J)J
.registers 4
.param p1, "b"
not-long v0, p1
return v0
.end method
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录