Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
keyescgm
jadx
提交
cd153c76
J
jadx
项目概览
keyescgm
/
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,发现更多精彩内容 >>
未验证
提交
cd153c76
编写于
10月 12, 2021
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: add raung input plugin, use raung in tests
上级
f30c14b2
变更
11
显示空白变更内容
内联
并排
Showing
11 changed file
with
248 addition
and
68 deletion
+248
-68
jadx-core/build.gradle
jadx-core/build.gradle
+1
-3
jadx-core/src/test/java/jadx/tests/api/RaungTest.java
jadx-core/src/test/java/jadx/tests/api/RaungTest.java
+85
-0
jadx-core/src/test/java/jadx/tests/integration/others/TestJavaSwap.java
...test/java/jadx/tests/integration/others/TestJavaSwap.java
+4
-62
jadx-core/src/test/raung/others/TestJavaSwap.raung
jadx-core/src/test/raung/others/TestJavaSwap.raung
+29
-0
jadx-plugins/jadx-java-input/src/main/java/jadx/plugins/input/java/JavaInputPlugin.java
...rc/main/java/jadx/plugins/input/java/JavaInputPlugin.java
+8
-1
jadx-plugins/jadx-java-input/src/main/java/jadx/plugins/input/java/JavaLoadResult.java
...src/main/java/jadx/plugins/input/java/JavaLoadResult.java
+11
-2
jadx-plugins/jadx-raung-input/build.gradle
jadx-plugins/jadx-raung-input/build.gradle
+11
-0
jadx-plugins/jadx-raung-input/src/main/java/jadx/plugins/input/raung/RaungConvert.java
.../src/main/java/jadx/plugins/input/raung/RaungConvert.java
+67
-0
jadx-plugins/jadx-raung-input/src/main/java/jadx/plugins/input/raung/RaungInputPlugin.java
.../main/java/jadx/plugins/input/raung/RaungInputPlugin.java
+30
-0
jadx-plugins/jadx-raung-input/src/main/resources/META-INF/services/jadx.api.plugins.JadxPlugin
...n/resources/META-INF/services/jadx.api.plugins.JadxPlugin
+1
-0
settings.gradle
settings.gradle
+1
-0
未找到文件。
jadx-core/build.gradle
浏览文件 @
cd153c76
...
...
@@ -14,13 +14,11 @@ dependencies {
testImplementation
'org.apache.commons:commons-lang3:3.12.0'
testImplementation
'org.ow2.asm:asm:9.2'
testImplementation
'org.ow2.asm:asm-util:9.2'
testRuntimeOnly
(
project
(
':jadx-plugins:jadx-dex-input'
))
testRuntimeOnly
(
project
(
':jadx-plugins:jadx-smali-input'
))
testRuntimeOnly
(
project
(
':jadx-plugins:jadx-java-convert'
))
testRuntimeOnly
(
project
(
':jadx-plugins:jadx-java-input'
))
testRuntimeOnly
(
project
(
':jadx-plugins:jadx-raung-input'
))
}
test
{
...
...
jadx-core/src/test/java/jadx/tests/api/RaungTest.java
0 → 100644
浏览文件 @
cd153c76
package
jadx.tests.api
;
import
java.io.File
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
import
org.junit.jupiter.api.BeforeEach
;
import
jadx.api.JadxInternalAccess
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.core.dex.nodes.RootNode
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
import
static
org
.
hamcrest
.
Matchers
.
notNullValue
;
public
abstract
class
RaungTest
extends
IntegrationTest
{
private
static
final
String
RAUNG_TESTS_PROJECT
=
"jadx-core"
;
private
static
final
String
RAUNG_TESTS_DIR
=
"src/test/raung"
;
private
static
final
String
RAUNG_TESTS_EXT
=
".raung"
;
@BeforeEach
public
void
init
()
{
super
.
init
();
this
.
useJavaInput
();
}
/**
* Preferred method for one file raung test
*/
protected
ClassNode
getClassNodeFromRaung
()
{
String
pkg
=
getTestPkg
();
String
clsName
=
getTestName
();
return
getClassNodeFromRaung
(
pkg
+
File
.
separatorChar
+
clsName
,
pkg
+
'.'
+
clsName
);
}
protected
ClassNode
getClassNodeFromRaung
(
String
file
,
String
clsName
)
{
File
raungFile
=
getRaungFile
(
file
);
return
getClassNodeFromFiles
(
Collections
.
singletonList
(
raungFile
),
clsName
);
}
protected
List
<
ClassNode
>
loadFromRaungFiles
()
{
jadxDecompiler
=
loadFiles
(
collectRaungFiles
(
getTestPkg
(),
getTestName
()));
RootNode
root
=
JadxInternalAccess
.
getRoot
(
jadxDecompiler
);
List
<
ClassNode
>
classes
=
root
.
getClasses
(
false
);
decompileAndCheck
(
classes
);
return
classes
;
}
private
List
<
File
>
collectRaungFiles
(
String
pkg
,
String
testDir
)
{
String
raungFilesDir
=
pkg
+
File
.
separatorChar
+
testDir
+
File
.
separatorChar
;
File
raungDir
=
getRaungDir
(
raungFilesDir
);
String
[]
raungFileNames
=
raungDir
.
list
((
dir
,
name
)
->
name
.
endsWith
(
".raung"
));
assertThat
(
"Raung files not found in "
+
raungDir
,
raungFileNames
,
notNullValue
());
return
Stream
.
of
(
raungFileNames
)
.
map
(
file
->
new
File
(
raungDir
,
file
))
.
collect
(
Collectors
.
toList
());
}
private
static
File
getRaungFile
(
String
baseName
)
{
File
raungFile
=
new
File
(
RAUNG_TESTS_DIR
,
baseName
+
RAUNG_TESTS_EXT
);
if
(
raungFile
.
exists
())
{
return
raungFile
;
}
File
pathFromRoot
=
new
File
(
RAUNG_TESTS_PROJECT
,
raungFile
.
getPath
());
if
(
pathFromRoot
.
exists
())
{
return
pathFromRoot
;
}
throw
new
AssertionError
(
"Raung file not found: "
+
raungFile
.
getPath
());
}
private
static
File
getRaungDir
(
String
baseName
)
{
File
raungDir
=
new
File
(
RAUNG_TESTS_DIR
,
baseName
);
if
(
raungDir
.
exists
())
{
return
raungDir
;
}
File
pathFromRoot
=
new
File
(
RAUNG_TESTS_PROJECT
,
raungDir
.
getPath
());
if
(
pathFromRoot
.
exists
())
{
return
pathFromRoot
;
}
throw
new
AssertionError
(
"Raung dir not found: "
+
raungDir
.
getPath
());
}
}
jadx-core/src/test/java/jadx/tests/integration/others/TestJavaSwap.java
浏览文件 @
cd153c76
package
jadx.tests.integration.others
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.io.StringWriter
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.util.Collections
;
import
java.util.List
;
import
org.junit.jupiter.api.Test
;
import
org.objectweb.asm.ClassReader
;
import
org.objectweb.asm.ClassWriter
;
import
org.objectweb.asm.MethodVisitor
;
import
org.objectweb.asm.Opcodes
;
import
org.objectweb.asm.util.CheckClassAdapter
;
import
jadx.core.utils.files.FileUtils
;
import
jadx.tests.api.IntegrationTest
;
import
jadx.tests.api.RaungTest
;
import
static
jadx
.
tests
.
api
.
utils
.
assertj
.
JadxAssertions
.
assertThat
;
public
class
TestJavaSwap
extends
Integration
Test
{
public
class
TestJavaSwap
extends
Raung
Test
{
@SuppressWarnings
(
"StringBufferReplaceableByString"
)
public
static
class
TestCls
{
...
...
@@ -44,52 +29,9 @@ public class TestJavaSwap extends IntegrationTest {
}
@Test
public
void
test
()
throws
IOException
{
// TODO: find up-to-date assembler/disassembler in java
ClassWriter
cw
=
new
ClassWriter
(
ClassWriter
.
COMPUTE_FRAMES
);
cw
.
visit
(
Opcodes
.
V1_8
,
0
,
"TestCls"
,
null
,
"java/lang/Object"
,
new
String
[]
{});
cw
.
visitField
(
Opcodes
.
ACC_PRIVATE
,
"field"
,
"Ljava/lang/Iterable;"
,
null
,
null
).
visitEnd
();
MethodVisitor
mv
=
cw
.
visitMethod
(
Opcodes
.
ACC_PUBLIC
,
"toString"
,
"()Ljava/lang/String;"
,
null
,
new
String
[]
{});
mv
.
visitCode
();
mv
.
visitVarInsn
(
Opcodes
.
ALOAD
,
0
);
mv
.
visitFieldInsn
(
Opcodes
.
GETFIELD
,
"TestCls"
,
"field"
,
"Ljava/lang/Iterable;"
);
mv
.
visitMethodInsn
(
Opcodes
.
INVOKESTATIC
,
"java/lang/String"
,
"valueOf"
,
"(Ljava/lang/Object;)Ljava/lang/String;"
,
false
);
mv
.
visitVarInsn
(
Opcodes
.
ASTORE
,
1
);
mv
.
visitIntInsn
(
Opcodes
.
BIPUSH
,
8
);
mv
.
visitVarInsn
(
Opcodes
.
ALOAD
,
1
);
mv
.
visitMethodInsn
(
Opcodes
.
INVOKESTATIC
,
"java/lang/String"
,
"valueOf"
,
"(Ljava/lang/Object;)Ljava/lang/String;"
,
false
);
mv
.
visitMethodInsn
(
Opcodes
.
INVOKEVIRTUAL
,
"java/lang/String"
,
"length"
,
"()I"
,
false
);
mv
.
visitInsn
(
Opcodes
.
IADD
);
mv
.
visitTypeInsn
(
Opcodes
.
NEW
,
"java/lang/StringBuilder"
);
mv
.
visitInsn
(
Opcodes
.
DUP_X1
);
mv
.
visitInsn
(
Opcodes
.
SWAP
);
mv
.
visitMethodInsn
(
Opcodes
.
INVOKESPECIAL
,
"java/lang/StringBuilder"
,
"<init>"
,
"(I)V"
,
false
);
mv
.
visitLdcInsn
(
"concat("
);
mv
.
visitMethodInsn
(
Opcodes
.
INVOKEVIRTUAL
,
"java/lang/StringBuilder"
,
"append"
,
"(Ljava/lang/String;)Ljava/lang/StringBuilder;"
,
false
);
mv
.
visitVarInsn
(
Opcodes
.
ALOAD
,
1
);
mv
.
visitMethodInsn
(
Opcodes
.
INVOKEVIRTUAL
,
"java/lang/StringBuilder"
,
"append"
,
"(Ljava/lang/String;)Ljava/lang/StringBuilder;"
,
false
);
mv
.
visitLdcInsn
(
")"
);
mv
.
visitMethodInsn
(
Opcodes
.
INVOKEVIRTUAL
,
"java/lang/StringBuilder"
,
"append"
,
"(Ljava/lang/String;)Ljava/lang/StringBuilder;"
,
false
);
mv
.
visitMethodInsn
(
Opcodes
.
INVOKEVIRTUAL
,
"java/lang/StringBuilder"
,
"toString"
,
"()Ljava/lang/String;"
,
false
);
mv
.
visitInsn
(
Opcodes
.
ARETURN
);
mv
.
visitMaxs
(
0
,
0
);
// auto calculated
mv
.
visitEnd
();
cw
.
visitEnd
();
byte
[]
clsBytes
=
cw
.
toByteArray
();
StringWriter
results
=
new
StringWriter
();
CheckClassAdapter
.
verify
(
new
ClassReader
(
clsBytes
),
false
,
new
PrintWriter
(
results
));
assertThat
(
results
.
toString
()).
isEmpty
();
Path
clsFile
=
FileUtils
.
createTempFile
(
".class"
);
Files
.
write
(
clsFile
,
clsBytes
);
List
<
File
>
files
=
Collections
.
singletonList
(
clsFile
.
toFile
());
public
void
test
()
{
useJavaInput
();
assertThat
(
getClassNodeFrom
Files
(
files
,
"TestCls"
))
assertThat
(
getClassNodeFrom
Raung
(
))
.
code
();
}
}
jadx-core/src/test/raung/others/TestJavaSwap.raung
0 → 100644
浏览文件 @
cd153c76
.version 52
.class others/TestJavaSwap
.auto frames
.field private field Ljava/lang/Iterable;
.method public toString()Ljava/lang/String;
aload 0
getfield others/TestJavaSwap field Ljava/lang/Iterable;
invokestatic java/lang/String valueOf (Ljava/lang/Object;)Ljava/lang/String;
astore 1
bipush 8
aload 1
invokestatic java/lang/String valueOf (Ljava/lang/Object;)Ljava/lang/String;
invokevirtual java/lang/String length ()I
iadd
new java/lang/StringBuilder
dup_x1
swap
invokespecial java/lang/StringBuilder <init> (I)V
ldc "concat("
invokevirtual java/lang/StringBuilder append (Ljava/lang/String;)Ljava/lang/StringBuilder;
aload 1
invokevirtual java/lang/StringBuilder append (Ljava/lang/String;)Ljava/lang/StringBuilder;
ldc ")"
invokevirtual java/lang/StringBuilder append (Ljava/lang/String;)Ljava/lang/StringBuilder;
invokevirtual java/lang/StringBuilder toString ()Ljava/lang/String;
areturn
.end method
jadx-plugins/jadx-java-input/src/main/java/jadx/plugins/input/java/JavaInputPlugin.java
浏览文件 @
cd153c76
package
jadx.plugins.input.java
;
import
java.io.Closeable
;
import
java.nio.file.Path
;
import
java.util.List
;
import
org.jetbrains.annotations.Nullable
;
import
jadx.api.plugins.JadxPluginInfo
;
import
jadx.api.plugins.input.JadxInputPlugin
;
import
jadx.api.plugins.input.data.ILoadResult
;
...
...
@@ -22,10 +25,14 @@ public class JavaInputPlugin implements JadxInputPlugin {
@Override
public
ILoadResult
loadFiles
(
List
<
Path
>
inputFiles
)
{
return
loadClassFiles
(
inputFiles
,
null
);
}
public
static
ILoadResult
loadClassFiles
(
List
<
Path
>
inputFiles
,
@Nullable
Closeable
closeable
)
{
List
<
JavaClassReader
>
readers
=
new
JavaFileLoader
().
collectFiles
(
inputFiles
);
if
(
readers
.
isEmpty
())
{
return
EmptyLoadResult
.
INSTANCE
;
}
return
new
JavaLoadResult
(
readers
);
return
new
JavaLoadResult
(
readers
,
closeable
);
}
}
jadx-plugins/jadx-java-input/src/main/java/jadx/plugins/input/java/JavaLoadResult.java
浏览文件 @
cd153c76
package
jadx.plugins.input.java
;
import
java.io.Closeable
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.function.Consumer
;
import
org.jetbrains.annotations.Nullable
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -14,9 +17,12 @@ public class JavaLoadResult implements ILoadResult {
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
JavaLoadResult
.
class
);
private
final
List
<
JavaClassReader
>
readers
;
@Nullable
private
final
Closeable
closeable
;
public
JavaLoadResult
(
List
<
JavaClassReader
>
readers
)
{
public
JavaLoadResult
(
List
<
JavaClassReader
>
readers
,
@Nullable
Closeable
closeable
)
{
this
.
readers
=
readers
;
this
.
closeable
=
closeable
;
}
@Override
...
...
@@ -40,7 +46,10 @@ public class JavaLoadResult implements ILoadResult {
}
@Override
public
void
close
()
{
public
void
close
()
throws
IOException
{
readers
.
clear
();
if
(
closeable
!=
null
)
{
closeable
.
close
();
}
}
}
jadx-plugins/jadx-raung-input/build.gradle
0 → 100644
浏览文件 @
cd153c76
plugins
{
id
'java-library'
}
dependencies
{
api
(
project
(
":jadx-plugins:jadx-plugins-api"
))
implementation
(
project
(
":jadx-plugins:jadx-java-input"
))
implementation
(
'io.github.skylot:raung-asm:0.0.1'
)
}
jadx-plugins/jadx-raung-input/src/main/java/jadx/plugins/input/raung/RaungConvert.java
0 → 100644
浏览文件 @
cd153c76
package
jadx.plugins.input.raung
;
import
java.io.Closeable
;
import
java.nio.file.FileSystems
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.PathMatcher
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
org.jetbrains.annotations.Nullable
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
io.github.skylot.raung.asm.RaungAsm
;
public
class
RaungConvert
implements
Closeable
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
RaungConvert
.
class
);
@Nullable
private
Path
tmpJar
;
public
boolean
execute
(
List
<
Path
>
input
)
{
List
<
Path
>
raungInputs
=
filterRaungFiles
(
input
);
if
(
raungInputs
.
isEmpty
())
{
return
false
;
}
try
{
this
.
tmpJar
=
Files
.
createTempFile
(
"jadx-raung-"
,
".jar"
);
RaungAsm
.
create
()
.
output
(
tmpJar
)
.
inputs
(
input
)
.
execute
();
return
true
;
}
catch
(
Exception
e
)
{
LOG
.
error
(
"Raung process error"
,
e
);
}
close
();
return
false
;
}
private
List
<
Path
>
filterRaungFiles
(
List
<
Path
>
input
)
{
PathMatcher
matcher
=
FileSystems
.
getDefault
().
getPathMatcher
(
"glob:**.raung"
);
return
input
.
stream
()
.
filter
(
matcher:
:
matches
)
.
collect
(
Collectors
.
toList
());
}
public
List
<
Path
>
getFiles
()
{
if
(
tmpJar
==
null
)
{
return
Collections
.
emptyList
();
}
return
Collections
.
singletonList
(
tmpJar
);
}
@Override
public
void
close
()
{
try
{
if
(
tmpJar
!=
null
)
{
Files
.
deleteIfExists
(
tmpJar
);
}
}
catch
(
Exception
e
)
{
LOG
.
error
(
"Failed to remove tmp jar file: {}"
,
tmpJar
,
e
);
}
}
}
jadx-plugins/jadx-raung-input/src/main/java/jadx/plugins/input/raung/RaungInputPlugin.java
0 → 100644
浏览文件 @
cd153c76
package
jadx.plugins.input.raung
;
import
java.nio.file.Path
;
import
java.util.List
;
import
jadx.api.plugins.JadxPluginInfo
;
import
jadx.api.plugins.input.JadxInputPlugin
;
import
jadx.api.plugins.input.data.ILoadResult
;
import
jadx.api.plugins.input.data.impl.EmptyLoadResult
;
import
jadx.plugins.input.java.JavaInputPlugin
;
public
class
RaungInputPlugin
implements
JadxInputPlugin
{
@Override
public
JadxPluginInfo
getPluginInfo
()
{
return
new
JadxPluginInfo
(
"raung-input"
,
"RaungInput"
,
"Load .raung files"
);
}
@Override
public
ILoadResult
loadFiles
(
List
<
Path
>
input
)
{
RaungConvert
convert
=
new
RaungConvert
();
if
(!
convert
.
execute
(
input
))
{
return
EmptyLoadResult
.
INSTANCE
;
}
return
JavaInputPlugin
.
loadClassFiles
(
convert
.
getFiles
(),
convert
);
}
}
jadx-plugins/jadx-raung-input/src/main/resources/META-INF/services/jadx.api.plugins.JadxPlugin
0 → 100644
浏览文件 @
cd153c76
jadx.plugins.input.raung.RaungInputPlugin
settings.gradle
浏览文件 @
cd153c76
...
...
@@ -7,5 +7,6 @@ include 'jadx-plugins'
include
'jadx-plugins:jadx-plugins-api'
include
'jadx-plugins:jadx-dex-input'
include
'jadx-plugins:jadx-java-input'
include
'jadx-plugins:jadx-raung-input'
include
'jadx-plugins:jadx-smali-input'
include
'jadx-plugins:jadx-java-convert'
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录