Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_39073359
jadx
提交
6448f0e3
J
jadx
项目概览
qq_39073359
/
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,发现更多精彩内容 >>
未验证
提交
6448f0e3
编写于
5月 22, 2022
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: use variable length encoding instead short for offsets (can overflow) (#1489)
上级
e07332d4
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
130 addition
and
49 deletion
+130
-49
jadx-core/src/main/java/jadx/api/JavaClass.java
jadx-core/src/main/java/jadx/api/JavaClass.java
+0
-1
jadx-gui/src/main/java/jadx/gui/utils/codecache/disk/CodeMetadataAdapter.java
...va/jadx/gui/utils/codecache/disk/CodeMetadataAdapter.java
+8
-6
jadx-gui/src/main/java/jadx/gui/utils/codecache/disk/DiskCodeCache.java
...ain/java/jadx/gui/utils/codecache/disk/DiskCodeCache.java
+1
-1
jadx-gui/src/main/java/jadx/gui/utils/codecache/disk/adapters/BaseDataAdapter.java
...dx/gui/utils/codecache/disk/adapters/BaseDataAdapter.java
+0
-26
jadx-gui/src/main/java/jadx/gui/utils/codecache/disk/adapters/DataAdapterHelper.java
.../gui/utils/codecache/disk/adapters/DataAdapterHelper.java
+63
-0
jadx-gui/src/main/java/jadx/gui/utils/codecache/disk/adapters/InsnCodeOffsetAdapter.java
.../utils/codecache/disk/adapters/InsnCodeOffsetAdapter.java
+2
-2
jadx-gui/src/main/java/jadx/gui/utils/codecache/disk/adapters/NodeDeclareRefAdapter.java
.../utils/codecache/disk/adapters/NodeDeclareRefAdapter.java
+2
-2
jadx-gui/src/main/java/jadx/gui/utils/codecache/disk/adapters/VarNodeAdapter.java
...adx/gui/utils/codecache/disk/adapters/VarNodeAdapter.java
+10
-5
jadx-gui/src/main/java/jadx/gui/utils/codecache/disk/adapters/VarRefAdapter.java
...jadx/gui/utils/codecache/disk/adapters/VarRefAdapter.java
+4
-6
jadx-gui/src/test/java/jadx/gui/utils/codecache/disk/adapters/DataAdapterHelperTest.java
.../utils/codecache/disk/adapters/DataAdapterHelperTest.java
+40
-0
未找到文件。
jadx-core/src/main/java/jadx/api/JavaClass.java
浏览文件 @
6448f0e3
...
...
@@ -206,7 +206,6 @@ public final class JavaClass implements JavaNode {
// ignore declarations and offset annotations
continue
;
}
// ignore declarations
JavaNode
annNode
=
rootDec
.
getJavaNodeByCodeAnnotation
(
codeInfo
,
ann
);
if
(
annNode
==
null
&&
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Failed to resolve code annotation, cls: {}, pos: {}, ann: {}"
,
this
,
entry
.
getKey
(),
ann
);
...
...
jadx-gui/src/main/java/jadx/gui/utils/codecache/disk/CodeMetadataAdapter.java
浏览文件 @
6448f0e3
...
...
@@ -25,6 +25,8 @@ import jadx.core.dex.nodes.RootNode;
import
jadx.core.utils.files.FileUtils
;
import
jadx.gui.utils.codecache.disk.adapters.CodeAnnotationAdapter
;
import
static
jadx
.
gui
.
utils
.
codecache
.
disk
.
adapters
.
DataAdapterHelper
.
readUVInt
;
import
static
jadx
.
gui
.
utils
.
codecache
.
disk
.
adapters
.
DataAdapterHelper
.
writeUVInt
;
import
static
java
.
nio
.
file
.
StandardOpenOption
.
CREATE
;
import
static
java
.
nio
.
file
.
StandardOpenOption
.
TRUNCATE_EXISTING
;
import
static
java
.
nio
.
file
.
StandardOpenOption
.
WRITE
;
...
...
@@ -68,8 +70,8 @@ public class CodeMetadataAdapter {
private
void
writeLines
(
DataOutput
out
,
Map
<
Integer
,
Integer
>
lines
)
throws
IOException
{
out
.
writeInt
(
lines
.
size
());
for
(
Map
.
Entry
<
Integer
,
Integer
>
entry
:
lines
.
entrySet
())
{
out
.
writeShort
(
entry
.
getKey
());
out
.
writeShort
(
entry
.
getValue
());
writeUVInt
(
out
,
entry
.
getKey
());
writeUVInt
(
out
,
entry
.
getValue
());
}
}
...
...
@@ -80,8 +82,8 @@ public class CodeMetadataAdapter {
}
Map
<
Integer
,
Integer
>
lines
=
new
HashMap
<>(
size
);
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
int
key
=
in
.
readShort
(
);
int
value
=
in
.
readShort
(
);
int
key
=
readUVInt
(
in
);
int
value
=
readUVInt
(
in
);
lines
.
put
(
key
,
value
);
}
return
lines
;
...
...
@@ -90,7 +92,7 @@ public class CodeMetadataAdapter {
private
void
writeAnnotations
(
DataOutputStream
out
,
Map
<
Integer
,
ICodeAnnotation
>
annotations
)
throws
IOException
{
out
.
writeInt
(
annotations
.
size
());
for
(
Map
.
Entry
<
Integer
,
ICodeAnnotation
>
entry
:
annotations
.
entrySet
())
{
out
.
writeInt
(
entry
.
getKey
());
writeUVInt
(
out
,
entry
.
getKey
());
codeAnnotationAdapter
.
write
(
out
,
entry
.
getValue
());
}
}
...
...
@@ -102,7 +104,7 @@ public class CodeMetadataAdapter {
}
Map
<
Integer
,
ICodeAnnotation
>
map
=
new
HashMap
<>(
size
);
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
int
pos
=
in
.
readInt
(
);
int
pos
=
readUVInt
(
in
);
ICodeAnnotation
ann
=
codeAnnotationAdapter
.
read
(
in
);
if
(
ann
!=
null
)
{
map
.
put
(
pos
,
ann
);
...
...
jadx-gui/src/main/java/jadx/gui/utils/codecache/disk/DiskCodeCache.java
浏览文件 @
6448f0e3
...
...
@@ -37,7 +37,7 @@ import jadx.core.utils.files.FileUtils;
public
class
DiskCodeCache
implements
ICodeCache
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
DiskCodeCache
.
class
);
private
static
final
int
DATA_FORMAT_VERSION
=
8
;
private
static
final
int
DATA_FORMAT_VERSION
=
9
;
private
final
Path
srcDir
;
private
final
Path
metaDir
;
...
...
jadx-gui/src/main/java/jadx/gui/utils/codecache/disk/adapters/BaseDataAdapter.java
已删除
100644 → 0
浏览文件 @
e07332d4
package
jadx.gui.utils.codecache.disk.adapters
;
import
java.io.DataInput
;
import
java.io.DataOutput
;
import
java.io.IOException
;
import
org.jetbrains.annotations.Nullable
;
public
abstract
class
BaseDataAdapter
<
T
>
implements
DataAdapter
<
T
>
{
public
void
writeNullableUTF
(
DataOutput
out
,
@Nullable
String
str
)
throws
IOException
{
if
(
str
==
null
)
{
out
.
writeByte
(
0
);
}
else
{
out
.
writeByte
(
1
);
out
.
writeUTF
(
str
);
}
}
public
@Nullable
String
readNullableUTF
(
DataInput
in
)
throws
IOException
{
if
(
in
.
readByte
()
==
0
)
{
return
null
;
}
return
in
.
readUTF
();
}
}
jadx-gui/src/main/java/jadx/gui/utils/codecache/disk/adapters/DataAdapterHelper.java
0 → 100644
浏览文件 @
6448f0e3
package
jadx.gui.utils.codecache.disk.adapters
;
import
java.io.DataInput
;
import
java.io.DataOutput
;
import
java.io.IOException
;
import
org.jetbrains.annotations.Nullable
;
public
class
DataAdapterHelper
{
public
static
void
writeNullableUTF
(
DataOutput
out
,
@Nullable
String
str
)
throws
IOException
{
if
(
str
==
null
)
{
out
.
writeByte
(
0
);
}
else
{
out
.
writeByte
(
1
);
out
.
writeUTF
(
str
);
}
}
public
static
@Nullable
String
readNullableUTF
(
DataInput
in
)
throws
IOException
{
if
(
in
.
readByte
()
==
0
)
{
return
null
;
}
return
in
.
readUTF
();
}
/**
* Write unsigned variable length integer (ULEB128 encoding)
*/
public
static
void
writeUVInt
(
DataOutput
out
,
int
val
)
throws
IOException
{
if
(
val
<
0
)
{
throw
new
IllegalArgumentException
(
"Expect value >= 0, got: "
+
val
);
}
int
current
=
val
;
int
next
=
val
;
while
(
true
)
{
next
>>>=
7
;
if
(
next
==
0
)
{
// last byte
out
.
writeByte
(
current
&
0x7f
);
return
;
}
out
.
writeByte
((
current
&
0x7f
)
|
0x80
);
current
=
next
;
}
}
/**
* Read unsigned variable length integer (ULEB128 encoding)
*/
public
static
int
readUVInt
(
DataInput
in
)
throws
IOException
{
int
result
=
0
;
int
shift
=
0
;
while
(
true
)
{
byte
v
=
in
.
readByte
();
result
|=
(
v
&
(
byte
)
0x7f
)
<<
shift
;
shift
+=
7
;
if
((
v
&
0x80
)
!=
0x80
)
{
return
result
;
}
}
}
}
jadx-gui/src/main/java/jadx/gui/utils/codecache/disk/adapters/InsnCodeOffsetAdapter.java
浏览文件 @
6448f0e3
...
...
@@ -12,11 +12,11 @@ public class InsnCodeOffsetAdapter implements DataAdapter<InsnCodeOffset> {
@Override
public
void
write
(
DataOutput
out
,
InsnCodeOffset
value
)
throws
IOException
{
out
.
writeShort
(
value
.
getOffset
());
DataAdapterHelper
.
writeUVInt
(
out
,
value
.
getOffset
());
}
@Override
public
InsnCodeOffset
read
(
DataInput
in
)
throws
IOException
{
return
new
InsnCodeOffset
(
in
.
readShort
(
));
return
new
InsnCodeOffset
(
DataAdapterHelper
.
readUVInt
(
in
));
}
}
jadx-gui/src/main/java/jadx/gui/utils/codecache/disk/adapters/NodeDeclareRefAdapter.java
浏览文件 @
6448f0e3
...
...
@@ -21,13 +21,13 @@ public class NodeDeclareRefAdapter implements DataAdapter<NodeDeclareRef> {
throw
new
RuntimeException
(
"Null node in NodeDeclareRef"
);
}
refAdapter
.
write
(
out
,
node
);
out
.
writeShort
(
value
.
getDefPos
());
DataAdapterHelper
.
writeUVInt
(
out
,
value
.
getDefPos
());
}
@Override
public
NodeDeclareRef
read
(
DataInput
in
)
throws
IOException
{
ICodeNodeRef
ref
=
(
ICodeNodeRef
)
refAdapter
.
read
(
in
);
int
defPos
=
in
.
readShort
(
);
int
defPos
=
DataAdapterHelper
.
readUVInt
(
in
);
NodeDeclareRef
nodeDeclareRef
=
new
NodeDeclareRef
(
ref
);
nodeDeclareRef
.
setDefPos
(
defPos
);
// restore def position if loading metadata without actual decompilation
...
...
jadx-gui/src/main/java/jadx/gui/utils/codecache/disk/adapters/VarNodeAdapter.java
浏览文件 @
6448f0e3
...
...
@@ -8,7 +8,12 @@ import jadx.api.metadata.annotations.VarNode;
import
jadx.core.dex.instructions.args.ArgType
;
import
jadx.core.dex.nodes.MethodNode
;
public
class
VarNodeAdapter
extends
BaseDataAdapter
<
VarNode
>
{
import
static
jadx
.
gui
.
utils
.
codecache
.
disk
.
adapters
.
DataAdapterHelper
.
readNullableUTF
;
import
static
jadx
.
gui
.
utils
.
codecache
.
disk
.
adapters
.
DataAdapterHelper
.
readUVInt
;
import
static
jadx
.
gui
.
utils
.
codecache
.
disk
.
adapters
.
DataAdapterHelper
.
writeNullableUTF
;
import
static
jadx
.
gui
.
utils
.
codecache
.
disk
.
adapters
.
DataAdapterHelper
.
writeUVInt
;
public
class
VarNodeAdapter
implements
DataAdapter
<
VarNode
>
{
private
final
MethodNodeAdapter
mthAdapter
;
public
VarNodeAdapter
(
MethodNodeAdapter
mthAdapter
)
{
...
...
@@ -18,8 +23,8 @@ public class VarNodeAdapter extends BaseDataAdapter<VarNode> {
@Override
public
void
write
(
DataOutput
out
,
VarNode
value
)
throws
IOException
{
mthAdapter
.
write
(
out
,
value
.
getMth
());
out
.
writeShort
(
value
.
getReg
());
out
.
writeShort
(
value
.
getSsa
());
writeUVInt
(
out
,
value
.
getReg
());
writeUVInt
(
out
,
value
.
getSsa
());
ArgTypeAdapter
.
INSTANCE
.
write
(
out
,
value
.
getType
());
writeNullableUTF
(
out
,
value
.
getName
());
}
...
...
@@ -27,8 +32,8 @@ public class VarNodeAdapter extends BaseDataAdapter<VarNode> {
@Override
public
VarNode
read
(
DataInput
in
)
throws
IOException
{
MethodNode
mth
=
mthAdapter
.
read
(
in
);
int
reg
=
in
.
readShort
(
);
int
ssa
=
in
.
readShort
(
);
int
reg
=
readUVInt
(
in
);
int
ssa
=
readUVInt
(
in
);
ArgType
type
=
ArgTypeAdapter
.
INSTANCE
.
read
(
in
);
String
name
=
readNullableUTF
(
in
);
return
new
VarNode
(
mth
,
reg
,
ssa
,
type
,
name
);
...
...
jadx-gui/src/main/java/jadx/gui/utils/codecache/disk/adapters/VarRefAdapter.java
浏览文件 @
6448f0e3
...
...
@@ -6,21 +6,19 @@ import java.io.IOException;
import
jadx.api.metadata.annotations.VarRef
;
public
class
VarRefAdapter
extends
Base
DataAdapter
<
VarRef
>
{
public
class
VarRefAdapter
implements
DataAdapter
<
VarRef
>
{
public
static
final
VarRefAdapter
INSTANCE
=
new
VarRefAdapter
();
@Override
public
void
write
(
DataOutput
out
,
VarRef
value
)
throws
IOException
{
int
refPos
=
value
.
getRefPos
();
if
(
refPos
<=
0
)
{
throw
new
RuntimeException
(
"Variable refPos is invalid: "
+
value
);
}
out
.
writeInt
(
refPos
);
DataAdapterHelper
.
writeUVInt
(
out
,
refPos
);
}
@Override
public
VarRef
read
(
DataInput
in
)
throws
IOException
{
return
VarRef
.
fromPos
(
in
.
readInt
());
int
refPos
=
DataAdapterHelper
.
readUVInt
(
in
);
return
VarRef
.
fromPos
(
refPos
);
}
}
jadx-gui/src/test/java/jadx/gui/utils/codecache/disk/adapters/DataAdapterHelperTest.java
0 → 100644
浏览文件 @
6448f0e3
package
jadx.gui.utils.codecache.disk.adapters
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.DataInput
;
import
java.io.DataInputStream
;
import
java.io.DataOutputStream
;
import
java.io.IOException
;
import
org.junit.jupiter.api.Test
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
class
DataAdapterHelperTest
{
@Test
void
uvInt
()
throws
IOException
{
checkUVIntFor
(
0
);
checkUVIntFor
(
7
);
checkUVIntFor
(
0x7f
);
checkUVIntFor
(
0x80
);
checkUVIntFor
(
0x256
);
checkUVIntFor
(
Byte
.
MAX_VALUE
);
checkUVIntFor
(
Short
.
MAX_VALUE
);
checkUVIntFor
(
Integer
.
MAX_VALUE
);
}
private
void
checkUVIntFor
(
int
val
)
throws
IOException
{
assertThat
(
writeReadUVInt
(
val
)).
isEqualTo
(
val
);
}
private
int
writeReadUVInt
(
int
val
)
throws
IOException
{
ByteArrayOutputStream
byteOut
=
new
ByteArrayOutputStream
();
DataOutputStream
out
=
new
DataOutputStream
(
byteOut
);
DataAdapterHelper
.
writeUVInt
(
out
,
val
);
DataInput
in
=
new
DataInputStream
(
new
ByteArrayInputStream
(
byteOut
.
toByteArray
()));
return
DataAdapterHelper
.
readUVInt
(
in
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录