Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
colcode
jadx
提交
7b1c7b96
J
jadx
项目概览
colcode
/
jadx
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
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 搜索 >>
未验证
提交
7b1c7b96
编写于
5月 20, 2022
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: use alias for variable names (#1487)
上级
e4b19ab5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
44 addition
and
24 deletion
+44
-24
jadx-core/src/main/java/jadx/core/codegen/NameGen.java
jadx-core/src/main/java/jadx/core/codegen/NameGen.java
+35
-24
jadx-core/src/main/java/jadx/core/dex/nodes/utils/MethodUtils.java
.../src/main/java/jadx/core/dex/nodes/utils/MethodUtils.java
+9
-0
未找到文件。
jadx-core/src/main/java/jadx/core/codegen/NameGen.java
浏览文件 @
7b1c7b96
...
...
@@ -7,6 +7,7 @@ import java.util.Set;
import
jadx.core.Consts
;
import
jadx.core.deobf.NameMapper
;
import
jadx.core.dex.attributes.AFlag
;
import
jadx.core.dex.attributes.nodes.LoopLabelAttr
;
import
jadx.core.dex.info.ClassInfo
;
import
jadx.core.dex.info.MethodInfo
;
...
...
@@ -173,7 +174,7 @@ public class NameGen {
private
String
makeNameForType
(
ArgType
type
)
{
if
(
type
.
isPrimitive
())
{
return
makeNameForPrimitive
(
type
);
return
type
.
getPrimitiveType
().
getShortName
().
toLowerCase
(
);
}
if
(
type
.
isArray
())
{
return
makeNameForType
(
type
.
getArrayRootElement
())
+
"Arr"
;
...
...
@@ -181,10 +182,6 @@ public class NameGen {
return
makeNameForObject
(
type
);
}
private
static
String
makeNameForPrimitive
(
ArgType
type
)
{
return
type
.
getPrimitiveType
().
getShortName
().
toLowerCase
();
}
private
String
makeNameForObject
(
ArgType
type
)
{
if
(
type
.
isGenericType
())
{
return
StringUtils
.
escape
(
type
.
getObject
().
toLowerCase
());
...
...
@@ -194,23 +191,32 @@ public class NameGen {
if
(
alias
!=
null
)
{
return
alias
;
}
ClassInfo
extClsInfo
=
ClassInfo
.
fromType
(
mth
.
root
(),
type
);
String
shortName
=
extClsInfo
.
getShortName
();
String
vName
=
fromName
(
shortName
);
if
(
vName
!=
null
)
{
return
vName
;
}
if
(
shortName
!=
null
)
{
String
lower
=
StringUtils
.
escape
(
shortName
.
toLowerCase
());
if
(
shortName
.
equals
(
lower
))
{
return
lower
+
"Var"
;
}
return
lower
;
}
return
makeNameForCheckedClass
(
ClassInfo
.
fromType
(
mth
.
root
(),
type
));
}
return
StringUtils
.
escape
(
type
.
toString
());
}
private
String
makeNameForCheckedClass
(
ClassInfo
classInfo
)
{
String
shortName
=
classInfo
.
getAliasShortName
();
String
vName
=
fromName
(
shortName
);
if
(
vName
!=
null
)
{
return
vName
;
}
String
lower
=
StringUtils
.
escape
(
shortName
.
toLowerCase
());
if
(
shortName
.
equals
(
lower
))
{
return
lower
+
"Var"
;
}
return
lower
;
}
private
String
makeNameForClass
(
ClassInfo
classInfo
)
{
String
alias
=
getAliasForObject
(
classInfo
.
getFullName
());
if
(
alias
!=
null
)
{
return
alias
;
}
return
makeNameForCheckedClass
(
classInfo
);
}
private
static
String
fromName
(
String
name
)
{
if
(
name
==
null
||
name
.
isEmpty
())
{
return
null
;
...
...
@@ -241,7 +247,12 @@ public class NameGen {
case
CONSTRUCTOR:
ConstructorInsn
co
=
(
ConstructorInsn
)
insn
;
return
makeNameForObject
(
co
.
getClassType
().
getType
());
MethodNode
callMth
=
mth
.
root
().
getMethodUtils
().
resolveMethod
(
co
);
if
(
callMth
!=
null
&&
callMth
.
contains
(
AFlag
.
ANONYMOUS_CONSTRUCTOR
))
{
// don't use name of anonymous class
return
null
;
}
return
makeNameForClass
(
co
.
getClassType
());
case
ARRAY_LENGTH:
return
"length"
;
...
...
@@ -267,11 +278,11 @@ public class NameGen {
}
private
String
makeNameFromInvoke
(
MethodInfo
callMth
)
{
String
name
=
callMth
.
get
Name
();
ArgType
declType
=
callMth
.
getDeclClass
().
getType
();
String
name
=
callMth
.
get
Alias
();
ClassInfo
declClass
=
callMth
.
getDeclClass
();
if
(
"getInstance"
.
equals
(
name
))
{
// e.g. Cipher.getInstance
return
makeNameFor
Type
(
declType
);
return
makeNameFor
Class
(
declClass
);
}
if
(
name
.
startsWith
(
"get"
)
||
name
.
startsWith
(
"set"
))
{
return
fromName
(
name
.
substring
(
3
));
...
...
@@ -280,9 +291,9 @@ public class NameGen {
return
"it"
;
}
if
(
"toString"
.
equals
(
name
))
{
return
makeNameFor
Type
(
declType
);
return
makeNameFor
Class
(
declClass
);
}
if
(
"forName"
.
equals
(
name
)
&&
decl
Type
.
equals
(
ArgType
.
CLASS
))
{
if
(
"forName"
.
equals
(
name
)
&&
decl
Class
.
getType
()
.
equals
(
ArgType
.
CLASS
))
{
return
OBJ_ALIAS
.
get
(
Consts
.
CLASS_CLASS
);
}
if
(
name
.
startsWith
(
"to"
))
{
...
...
jadx-core/src/main/java/jadx/core/dex/nodes/utils/MethodUtils.java
浏览文件 @
7b1c7b96
...
...
@@ -45,6 +45,15 @@ public class MethodUtils {
return
root
.
getClsp
().
getMethodDetails
(
callMth
);
}
@Nullable
public
MethodNode
resolveMethod
(
BaseInvokeNode
invokeNode
)
{
IMethodDetails
methodDetails
=
getMethodDetails
(
invokeNode
);
if
(
methodDetails
instanceof
MethodNode
)
{
return
((
MethodNode
)
methodDetails
);
}
return
null
;
}
/**
* Search methods with same name and args count in class hierarchy starting from {@code startCls}
* Beware {@code startCls} can be different from {@code mthInfo.getDeclClass()}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录