Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
ql04210214
jadx
提交
15c9d333
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,发现更多精彩内容 >>
未验证
提交
15c9d333
编写于
8月 13, 2022
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(gui): handle possible classes overlap in disk cache (#1633)
上级
7e0fafba
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
31 addition
and
3 deletion
+31
-3
jadx-core/src/main/java/jadx/core/utils/files/FileUtils.java
jadx-core/src/main/java/jadx/core/utils/files/FileUtils.java
+3
-1
jadx-gui/src/main/java/jadx/gui/utils/codecache/disk/DiskCodeCache.java
...ain/java/jadx/gui/utils/codecache/disk/DiskCodeCache.java
+28
-2
未找到文件。
jadx-core/src/main/java/jadx/core/utils/files/FileUtils.java
浏览文件 @
15c9d333
...
...
@@ -13,6 +13,7 @@ import java.nio.file.FileVisitOption;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.nio.file.StandardOpenOption
;
import
java.security.MessageDigest
;
import
java.util.ArrayList
;
import
java.util.Comparator
;
...
...
@@ -228,7 +229,8 @@ public class FileUtils {
public
static
void
writeFile
(
Path
file
,
String
data
)
throws
IOException
{
FileUtils
.
makeDirsForFile
(
file
);
Files
.
write
(
file
,
data
.
getBytes
(
StandardCharsets
.
UTF_8
));
Files
.
write
(
file
,
data
.
getBytes
(
StandardCharsets
.
UTF_8
),
StandardOpenOption
.
WRITE
,
StandardOpenOption
.
CREATE
,
StandardOpenOption
.
TRUNCATE_EXISTING
);
}
public
static
String
readFile
(
Path
textFile
)
throws
IOException
{
...
...
jadx-gui/src/main/java/jadx/gui/utils/codecache/disk/DiskCodeCache.java
浏览文件 @
15c9d333
...
...
@@ -15,6 +15,7 @@ import java.nio.file.Path;
import
java.nio.file.Paths
;
import
java.nio.file.attribute.FileTime
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
...
...
@@ -30,6 +31,7 @@ import jadx.api.ICodeCache;
import
jadx.api.ICodeInfo
;
import
jadx.api.JadxArgs
;
import
jadx.core.Jadx
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.core.dex.nodes.RootNode
;
import
jadx.core.utils.Utils
;
import
jadx.core.utils.exceptions.JadxRuntimeException
;
...
...
@@ -42,7 +44,7 @@ import static java.nio.file.StandardOpenOption.WRITE;
public
class
DiskCodeCache
implements
ICodeCache
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
DiskCodeCache
.
class
);
private
static
final
int
DATA_FORMAT_VERSION
=
1
2
;
private
static
final
int
DATA_FORMAT_VERSION
=
1
3
;
private
static
final
byte
[]
JADX_NAMES_MAP_HEADER
=
"jadxnm"
.
getBytes
(
StandardCharsets
.
US_ASCII
);
...
...
@@ -55,6 +57,7 @@ public class DiskCodeCache implements ICodeCache {
private
final
ExecutorService
writePool
;
private
final
Map
<
String
,
ICodeInfo
>
writeOps
=
new
ConcurrentHashMap
<>();
private
final
Map
<
String
,
Integer
>
namesMap
=
new
ConcurrentHashMap
<>();
private
final
Map
<
String
,
Integer
>
allClsIds
;
public
DiskCodeCache
(
RootNode
root
,
Path
baseDir
)
{
srcDir
=
baseDir
.
resolve
(
"sources"
);
...
...
@@ -65,6 +68,7 @@ public class DiskCodeCache implements ICodeCache {
codeVersion
=
buildCodeVersion
(
args
);
writePool
=
Executors
.
newFixedThreadPool
(
args
.
getThreadsCount
());
codeMetadataAdapter
=
new
CodeMetadataAdapter
(
root
);
allClsIds
=
buildClassIdsMap
(
root
.
getClasses
());
if
(
checkCodeVersion
())
{
loadNamesMap
();
}
else
{
...
...
@@ -112,6 +116,7 @@ public class DiskCodeCache implements ICodeCache {
public
void
add
(
String
clsFullName
,
ICodeInfo
codeInfo
)
{
writeOps
.
put
(
clsFullName
,
codeInfo
);
int
clsId
=
getClsId
(
clsFullName
);
namesMap
.
put
(
clsFullName
,
clsId
);
writePool
.
execute
(()
->
{
try
{
FileUtils
.
writeFile
(
getJavaFile
(
clsId
),
codeInfo
.
getCodeStr
());
...
...
@@ -218,7 +223,11 @@ public class DiskCodeCache implements ICodeCache {
}
private
int
getClsId
(
String
clsFullName
)
{
return
namesMap
.
computeIfAbsent
(
clsFullName
,
n
->
namesMap
.
size
());
Integer
id
=
allClsIds
.
get
(
clsFullName
);
if
(
id
==
null
)
{
throw
new
JadxRuntimeException
(
"Unknown class name: "
+
clsFullName
);
}
return
id
;
}
private
void
saveNamesMap
()
{
...
...
@@ -250,6 +259,13 @@ public class DiskCodeCache implements ICodeCache {
String
clsName
=
in
.
readUTF
();
int
clsId
=
in
.
readInt
();
namesMap
.
put
(
clsName
,
clsId
);
Integer
prevId
=
allClsIds
.
get
(
clsName
);
if
(
prevId
==
null
||
prevId
!=
clsId
)
{
LOG
.
debug
(
"Unexpected class id, got: {}, expect: {}"
,
clsId
,
prevId
);
LOG
.
warn
(
"Inconsistent disk cache, resetting..."
);
reset
();
return
;
}
}
LOG
.
info
(
"Found {} classes in disk cache, dir: {}"
,
count
,
metaDir
.
getParent
());
}
catch
(
Exception
e
)
{
...
...
@@ -271,6 +287,16 @@ public class DiskCodeCache implements ICodeCache {
return
Paths
.
get
(
firstByte
,
FileUtils
.
intToHex
(
clsId
)
+
ext
);
}
private
Map
<
String
,
Integer
>
buildClassIdsMap
(
List
<
ClassNode
>
classes
)
{
int
clsCount
=
classes
.
size
();
Map
<
String
,
Integer
>
map
=
new
HashMap
<>(
clsCount
);
for
(
int
i
=
0
;
i
<
clsCount
;
i
++)
{
ClassNode
cls
=
classes
.
get
(
i
);
map
.
put
(
cls
.
getRawName
(),
i
);
}
return
map
;
}
@SuppressWarnings
(
"ResultOfMethodCallIgnored"
)
@Override
public
void
close
()
throws
IOException
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录