Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_41695661
jadx
提交
63a57130
J
jadx
项目概览
weixin_41695661
/
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,体验更适合开发者的 AI 搜索 >>
未验证
提交
63a57130
编写于
8月 19, 2022
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: load resource table nodes in one change (#1648)
上级
bc4db61e
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
171 addition
and
102 deletion
+171
-102
jadx-gui/src/main/java/jadx/gui/search/providers/ResourceSearchProvider.java
...ava/jadx/gui/search/providers/ResourceSearchProvider.java
+37
-40
jadx-gui/src/main/java/jadx/gui/treemodel/JResource.java
jadx-gui/src/main/java/jadx/gui/treemodel/JResource.java
+32
-59
jadx-gui/src/main/java/jadx/gui/treemodel/JRoot.java
jadx-gui/src/main/java/jadx/gui/treemodel/JRoot.java
+3
-2
jadx-gui/src/main/java/jadx/gui/utils/UiUtils.java
jadx-gui/src/main/java/jadx/gui/utils/UiUtils.java
+1
-1
jadx-gui/src/main/java/jadx/gui/utils/res/ResTableHelper.java
...-gui/src/main/java/jadx/gui/utils/res/ResTableHelper.java
+98
-0
未找到文件。
jadx-gui/src/main/java/jadx/gui/search/providers/ResourceSearchProvider.java
浏览文件 @
63a57130
...
...
@@ -52,7 +52,7 @@ public class ResourceSearchProvider implements ISearchProvider {
if
(
cancelable
.
isCanceled
())
{
return
null
;
}
JResource
resNode
=
getNext
Node
(
);
JResource
resNode
=
getNext
ResFile
(
cancelable
);
if
(
resNode
==
null
)
{
return
null
;
}
...
...
@@ -62,7 +62,7 @@ public class ResourceSearchProvider implements ISearchProvider {
}
pos
=
0
;
resQueue
.
removeLast
();
addChildren
(
res
Queue
,
res
Node
);
addChildren
(
resNode
);
if
(
resQueue
.
isEmpty
())
{
return
null
;
}
...
...
@@ -90,39 +90,37 @@ public class ResourceSearchProvider implements ISearchProvider {
return
new
JResSearchNode
(
resNode
,
line
.
trim
(),
newPos
);
}
private
@Nullable
JResource
getNextNode
()
{
JResource
node
=
resQueue
.
peekLast
();
if
(
node
==
null
)
{
return
null
;
}
try
{
node
.
loadNode
();
}
catch
(
Exception
e
)
{
LOG
.
error
(
"Error load resource node: {}"
,
node
,
e
);
resQueue
.
removeLast
();
return
getNextNode
();
}
if
(
node
.
getType
()
==
JResource
.
JResType
.
FILE
)
{
if
(
shouldProcess
(
node
))
{
return
node
;
private
@Nullable
JResource
getNextResFile
(
Cancelable
cancelable
)
{
while
(
true
)
{
JResource
node
=
resQueue
.
peekLast
();
if
(
node
==
null
)
{
return
null
;
}
try
{
node
.
loadNode
();
}
catch
(
Exception
e
)
{
LOG
.
error
(
"Error load resource node: {}"
,
node
,
e
);
resQueue
.
removeLast
();
continue
;
}
if
(
cancelable
.
isCanceled
())
{
return
null
;
}
if
(
node
.
getType
()
==
JResource
.
JResType
.
FILE
)
{
if
(
shouldProcess
(
node
))
{
return
node
;
}
resQueue
.
removeLast
();
}
else
{
// dir
resQueue
.
removeLast
();
addChildren
(
node
);
}
resQueue
.
removeLast
();
return
getNextNode
();
}
// dit or root
resQueue
.
removeLast
();
addChildren
(
resQueue
,
node
);
return
getNextNode
();
}
private
void
addChildren
(
Deque
<
JResource
>
deque
,
JResource
resNode
)
{
Enumeration
<
TreeNode
>
children
=
resNode
.
children
();
while
(
children
.
hasMoreElements
())
{
TreeNode
node
=
children
.
nextElement
();
if
(
node
instanceof
JResource
)
{
deque
.
add
((
JResource
)
node
);
}
}
private
void
addChildren
(
JResource
resNode
)
{
resQueue
.
addAll
(
resNode
.
getSubNodes
());
}
private
static
Deque
<
JResource
>
initResQueue
(
MainWindow
mw
)
{
...
...
@@ -155,16 +153,15 @@ public class ResourceSearchProvider implements ISearchProvider {
}
private
boolean
shouldProcess
(
JResource
resNode
)
{
ResourceFile
resFile
=
resNode
.
getResFile
();
if
(
resFile
.
getType
()
==
ResourceType
.
ARSC
)
{
// don't check size of generated resource table, it will also skip all sub files
return
anyExt
||
extSet
.
contains
(
"xml"
);
}
if
(!
anyExt
)
{
String
fileExt
;
ResourceFile
resFile
=
resNode
.
getResFile
();
if
(
resFile
.
getType
()
==
ResourceType
.
ARSC
)
{
fileExt
=
"xml"
;
}
else
{
fileExt
=
CommonFileUtils
.
getFileExtension
(
resFile
.
getOriginalName
());
if
(
fileExt
==
null
)
{
return
false
;
}
String
fileExt
=
CommonFileUtils
.
getFileExtension
(
resFile
.
getOriginalName
());
if
(
fileExt
==
null
)
{
return
false
;
}
if
(!
extSet
.
contains
(
fileExt
))
{
return
false
;
...
...
jadx-gui/src/main/java/jadx/gui/treemodel/JResource.java
浏览文件 @
63a57130
package
jadx.gui.treemodel
;
import
java.util.
ArrayList
;
import
java.util.
Collections
;
import
java.util.Comparator
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -14,10 +14,10 @@ import org.jetbrains.annotations.Nullable;
import
jadx.api.ICodeInfo
;
import
jadx.api.ICodeWriter
;
import
jadx.api.ResourceFile
;
import
jadx.api.ResourceFileContent
;
import
jadx.api.ResourceType
;
import
jadx.api.ResourcesLoader
;
import
jadx.api.impl.SimpleCodeInfo
;
import
jadx.core.utils.ListUtils
;
import
jadx.core.utils.Utils
;
import
jadx.core.xmlgen.ResContainer
;
import
jadx.gui.ui.TabbedPane
;
...
...
@@ -26,6 +26,7 @@ import jadx.gui.ui.panel.ContentPanel;
import
jadx.gui.ui.panel.ImagePanel
;
import
jadx.gui.utils.NLS
;
import
jadx.gui.utils.UiUtils
;
import
jadx.gui.utils.res.ResTableHelper
;
public
class
JResource
extends
JLoadableNode
{
private
static
final
long
serialVersionUID
=
-
201018424302612434L
;
...
...
@@ -41,6 +42,10 @@ public class JResource extends JLoadableNode {
private
static
final
ImageIcon
JAVA_ICON
=
UiUtils
.
openSvgIcon
(
"nodes/java"
);
private
static
final
ImageIcon
UNKNOWN_ICON
=
UiUtils
.
openSvgIcon
(
"nodes/unknown"
);
public
static
final
Comparator
<
JResource
>
RESOURCES_COMPARATOR
=
Comparator
.<
JResource
>
comparingInt
(
r
->
r
.
type
.
ordinal
())
.
thenComparing
(
JResource:
:
getName
,
String
.
CASE_INSENSITIVE_ORDER
);
public
enum
JResType
{
ROOT
,
DIR
,
...
...
@@ -49,11 +54,11 @@ public class JResource extends JLoadableNode {
private
final
transient
String
name
;
private
final
transient
String
shortName
;
private
final
transient
List
<
JResource
>
files
=
new
ArrayList
<>(
1
);
private
final
transient
JResType
type
;
private
final
transient
ResourceFile
resFile
;
private
transient
boolean
loaded
;
private
transient
volatile
boolean
loaded
;
private
transient
List
<
JResource
>
subNodes
=
Collections
.
emptyList
();
private
transient
ICodeInfo
content
;
public
JResource
(
ResourceFile
resFile
,
String
name
,
JResType
type
)
{
...
...
@@ -69,7 +74,8 @@ public class JResource extends JLoadableNode {
}
public
final
void
update
()
{
if
(
files
.
isEmpty
())
{
removeAllChildren
();
if
(
Utils
.
isEmpty
(
subNodes
))
{
if
(
type
==
JResType
.
DIR
||
type
==
JResType
.
ROOT
||
resFile
.
getType
()
==
ResourceType
.
ARSC
)
{
// fake leaf to force show expand button
...
...
@@ -77,14 +83,7 @@ public class JResource extends JLoadableNode {
add
(
new
TextNode
(
NLS
.
str
(
"tree.loading"
)));
}
}
else
{
removeAllChildren
();
Comparator
<
JResource
>
typeComparator
=
Comparator
.
comparingInt
(
r
->
r
.
type
.
ordinal
());
Comparator
<
JResource
>
nameComparator
=
Comparator
.
comparing
(
JResource:
:
getName
,
String
.
CASE_INSENSITIVE_ORDER
);
files
.
sort
(
typeComparator
.
thenComparing
(
nameComparator
));
for
(
JResource
res
:
files
)
{
for
(
JResource
res
:
subNodes
)
{
res
.
update
();
add
(
res
);
}
...
...
@@ -106,8 +105,23 @@ public class JResource extends JLoadableNode {
return
type
;
}
public
List
<
JResource
>
getFiles
()
{
return
files
;
public
List
<
JResource
>
getSubNodes
()
{
return
subNodes
;
}
public
void
addSubNode
(
JResource
node
)
{
subNodes
=
ListUtils
.
safeAdd
(
subNodes
,
node
);
}
public
void
sortSubNodes
()
{
sortResNodes
(
subNodes
);
}
private
static
void
sortResNodes
(
List
<
JResource
>
nodes
)
{
if
(
Utils
.
notEmpty
(
nodes
))
{
nodes
.
forEach
(
JResource:
:
sortSubNodes
);
nodes
.
sort
(
RESOURCES_COMPARATOR
);
}
}
@Override
...
...
@@ -145,9 +159,9 @@ public class JResource extends JLoadableNode {
}
if
(
rc
.
getDataType
()
==
ResContainer
.
DataType
.
RES_TABLE
)
{
ICodeInfo
codeInfo
=
loadCurrentSingleRes
(
rc
);
for
(
ResContainer
subFile
:
rc
.
getSubFiles
())
{
loadSubNodes
(
this
,
subFile
,
1
);
}
List
<
JResource
>
nodes
=
ResTableHelper
.
buildTree
(
rc
);
sortResNodes
(
nodes
);
subNodes
=
nodes
;
return
codeInfo
;
}
// single node
...
...
@@ -178,47 +192,6 @@ public class JResource extends JLoadableNode {
}
}
private
void
loadSubNodes
(
JResource
root
,
ResContainer
rc
,
int
depth
)
{
String
resName
=
rc
.
getName
();
String
[]
path
=
resName
.
split
(
"/"
);
String
resShortName
=
path
.
length
==
0
?
resName
:
path
[
path
.
length
-
1
];
ICodeInfo
code
=
rc
.
getText
();
ResourceFileContent
fileContent
=
new
ResourceFileContent
(
resShortName
,
ResourceType
.
XML
,
code
);
addPath
(
path
,
root
,
new
JResource
(
fileContent
,
resName
,
resShortName
,
JResType
.
FILE
));
for
(
ResContainer
subFile
:
rc
.
getSubFiles
())
{
loadSubNodes
(
root
,
subFile
,
depth
+
1
);
}
}
private
static
void
addPath
(
String
[]
path
,
JResource
root
,
JResource
jResource
)
{
if
(
path
.
length
==
1
)
{
root
.
getFiles
().
add
(
jResource
);
return
;
}
JResource
currentRoot
=
root
;
int
last
=
path
.
length
-
1
;
for
(
int
i
=
0
;
i
<=
last
;
i
++)
{
String
f
=
path
[
i
];
if
(
i
==
last
)
{
currentRoot
.
getFiles
().
add
(
jResource
);
}
else
{
currentRoot
=
getResDir
(
currentRoot
,
f
);
}
}
}
private
static
JResource
getResDir
(
JResource
root
,
String
dirName
)
{
for
(
JResource
file
:
root
.
getFiles
())
{
if
(
file
.
getName
().
equals
(
dirName
))
{
return
file
;
}
}
JResource
resDir
=
new
JResource
(
null
,
dirName
,
JResType
.
DIR
);
root
.
getFiles
().
add
(
resDir
);
return
resDir
;
}
@Override
public
String
getSyntaxName
()
{
if
(
resFile
==
null
)
{
...
...
jadx-gui/src/main/java/jadx/gui/treemodel/JRoot.java
浏览文件 @
63a57130
...
...
@@ -68,17 +68,18 @@ public class JRoot extends JNode {
}
else
{
subRF
=
new
JResource
(
rf
,
rf
.
getDeobfName
(),
name
,
JResType
.
FILE
);
}
curRf
.
getFiles
().
add
(
subRF
);
curRf
.
addSubNode
(
subRF
);
}
curRf
=
subRF
;
}
}
root
.
sortSubNodes
();
root
.
update
();
return
root
;
}
private
JResource
getResourceByName
(
JResource
rf
,
String
name
)
{
for
(
JResource
sub
:
rf
.
get
Fil
es
())
{
for
(
JResource
sub
:
rf
.
get
SubNod
es
())
{
if
(
sub
.
getName
().
equals
(
name
))
{
return
sub
;
}
...
...
jadx-gui/src/main/java/jadx/gui/utils/UiUtils.java
浏览文件 @
63a57130
...
...
@@ -375,7 +375,7 @@ public class UiUtils {
try
{
SwingUtilities
.
invokeAndWait
(
runnable
);
}
catch
(
InterruptedException
e
)
{
LOG
.
warn
(
"UI thread interrupted
"
,
e
);
LOG
.
warn
(
"UI thread interrupted
, runnable: {}"
,
runnable
,
e
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
...
...
jadx-gui/src/main/java/jadx/gui/utils/res/ResTableHelper.java
0 → 100644
浏览文件 @
63a57130
package
jadx.gui.utils.res
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.jetbrains.annotations.Nullable
;
import
jadx.api.ICodeInfo
;
import
jadx.api.ResourceFileContent
;
import
jadx.api.ResourceType
;
import
jadx.core.xmlgen.ResContainer
;
import
jadx.gui.treemodel.JResource
;
public
class
ResTableHelper
{
/**
* Build UI tree for resource table container.
*
* @return root nodes
*/
public
static
List
<
JResource
>
buildTree
(
ResContainer
resTable
)
{
ResTableHelper
resTableHelper
=
new
ResTableHelper
();
resTableHelper
.
process
(
resTable
);
return
resTableHelper
.
roots
;
}
private
final
List
<
JResource
>
roots
=
new
ArrayList
<>();
private
final
Map
<
String
,
JResource
>
dirs
=
new
HashMap
<>();
private
ResTableHelper
()
{
}
private
void
process
(
ResContainer
resTable
)
{
for
(
ResContainer
subFile
:
resTable
.
getSubFiles
())
{
loadSubNodes
(
subFile
);
}
}
private
void
loadSubNodes
(
ResContainer
rc
)
{
String
resName
=
rc
.
getName
();
int
split
=
resName
.
lastIndexOf
(
'/'
);
String
dir
;
String
name
;
if
(
split
==
-
1
)
{
dir
=
null
;
name
=
resName
;
}
else
{
dir
=
resName
.
substring
(
0
,
split
);
name
=
resName
.
substring
(
split
+
1
);
}
ICodeInfo
code
=
rc
.
getText
();
ResourceFileContent
fileContent
=
new
ResourceFileContent
(
name
,
ResourceType
.
XML
,
code
);
JResource
resFile
=
new
JResource
(
fileContent
,
resName
,
name
,
JResource
.
JResType
.
FILE
);
addResFile
(
dir
,
resFile
);
for
(
ResContainer
subFile
:
rc
.
getSubFiles
())
{
loadSubNodes
(
subFile
);
}
}
private
void
addResFile
(
@Nullable
String
dir
,
JResource
resFile
)
{
if
(
dir
==
null
)
{
roots
.
add
(
resFile
);
return
;
}
JResource
dirRes
=
dirs
.
get
(
dir
);
if
(
dirRes
!=
null
)
{
dirRes
.
addSubNode
(
resFile
);
return
;
}
JResource
parentDir
=
null
;
int
splitPos
=
-
1
;
while
(
true
)
{
int
prevStart
=
splitPos
+
1
;
splitPos
=
dir
.
indexOf
(
'/'
,
prevStart
);
boolean
last
=
splitPos
==
-
1
;
String
path
=
last
?
dir
:
dir
.
substring
(
0
,
splitPos
);
JResource
curDir
=
dirs
.
get
(
path
);
if
(
curDir
==
null
)
{
String
dirName
=
last
?
dir
.
substring
(
prevStart
)
:
dir
.
substring
(
prevStart
,
splitPos
);
curDir
=
new
JResource
(
null
,
dirName
,
JResource
.
JResType
.
DIR
);
dirs
.
put
(
path
,
curDir
);
if
(
parentDir
==
null
)
{
roots
.
add
(
curDir
);
}
else
{
parentDir
.
addSubNode
(
curDir
);
}
}
if
(
last
)
{
curDir
.
addSubNode
(
resFile
);
return
;
}
parentDir
=
curDir
;
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录