Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
ql04210214
jadx
提交
d2acaa03
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,发现更多精彩内容 >>
提交
d2acaa03
编写于
6月 05, 2014
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
core: guess variable name from assign instruction
上级
f2aa4cd1
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
135 addition
and
24 deletion
+135
-24
jadx-core/src/main/java/jadx/core/codegen/NameGen.java
jadx-core/src/main/java/jadx/core/codegen/NameGen.java
+108
-24
jadx-core/src/main/java/jadx/core/dex/instructions/args/MthParameterArg.java
...java/jadx/core/dex/instructions/args/MthParameterArg.java
+20
-0
jadx-core/src/main/java/jadx/core/dex/visitors/regions/ProcessVariables.java
...java/jadx/core/dex/visitors/regions/ProcessVariables.java
+7
-0
未找到文件。
jadx-core/src/main/java/jadx/core/codegen/NameGen.java
浏览文件 @
d2acaa03
...
...
@@ -3,20 +3,46 @@ package jadx.core.codegen;
import
jadx.core.Consts
;
import
jadx.core.deobf.NameMapper
;
import
jadx.core.dex.info.ClassInfo
;
import
jadx.core.dex.instructions.InvokeNode
;
import
jadx.core.dex.instructions.args.ArgType
;
import
jadx.core.dex.instructions.args.InsnArg
;
import
jadx.core.dex.instructions.args.InsnWrapArg
;
import
jadx.core.dex.instructions.args.NamedArg
;
import
jadx.core.dex.instructions.args.RegisterArg
;
import
jadx.core.dex.instructions.args.SSAVar
;
import
jadx.core.dex.instructions.mods.ConstructorInsn
;
import
jadx.core.dex.nodes.InsnNode
;
import
jadx.core.utils.Utils
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Map
;
import
java.util.Set
;
public
class
NameGen
{
private
static
final
Map
<
String
,
String
>
OBJ_ALIAS
;
private
final
Set
<
String
>
varNames
=
new
HashSet
<
String
>();
private
final
boolean
fallback
;
static
{
OBJ_ALIAS
=
new
HashMap
<
String
,
String
>();
OBJ_ALIAS
.
put
(
Consts
.
CLASS_STRING
,
"str"
);
OBJ_ALIAS
.
put
(
Consts
.
CLASS_CLASS
,
"cls"
);
OBJ_ALIAS
.
put
(
Consts
.
CLASS_THROWABLE
,
"th"
);
OBJ_ALIAS
.
put
(
Consts
.
CLASS_OBJECT
,
"obj"
);
OBJ_ALIAS
.
put
(
"java.util.Iterator"
,
"it"
);
OBJ_ALIAS
.
put
(
"java.lang.Boolean"
,
"bool"
);
OBJ_ALIAS
.
put
(
"java.lang.Short"
,
"sh"
);
OBJ_ALIAS
.
put
(
"java.lang.Integer"
,
"num"
);
OBJ_ALIAS
.
put
(
"java.lang.Character"
,
"ch"
);
OBJ_ALIAS
.
put
(
"java.lang.Byte"
,
"b"
);
OBJ_ALIAS
.
put
(
"java.lang.Float"
,
"f"
);
OBJ_ALIAS
.
put
(
"java.lang.Long"
,
"l"
);
OBJ_ALIAS
.
put
(
"java.lang.Double"
,
"d"
);
}
public
NameGen
(
boolean
fallback
)
{
this
.
fallback
=
fallback
;
}
...
...
@@ -72,7 +98,7 @@ public class NameGen {
}
String
varName
;
if
(
name
!=
null
)
{
if
(
name
.
equals
(
"this"
))
{
if
(
"this"
.
equals
(
name
))
{
return
name
;
}
varName
=
name
;
...
...
@@ -101,34 +127,92 @@ public class NameGen {
private
static
String
makeNameForObject
(
ArgType
type
)
{
if
(
type
.
isObject
())
{
String
obj
=
type
.
getObject
();
if
(
obj
.
startsWith
(
"java.lang."
))
{
if
(
obj
.
equals
(
Consts
.
CLASS_STRING
))
{
return
"str"
;
String
alias
=
getAliasForObject
(
type
.
getObject
());
if
(
alias
!=
null
)
{
return
alias
;
}
if
(
obj
.
equals
(
Consts
.
CLASS_OBJECT
))
{
return
"obj"
;
ClassInfo
clsInfo
=
ClassInfo
.
fromType
(
type
);
String
shortName
=
clsInfo
.
getShortName
();
String
vName
=
fromName
(
shortName
);
if
(
vName
!=
null
)
{
return
vName
;
}
if
(
obj
.
equals
(
Consts
.
CLASS_CLASS
))
{
return
"cls"
;
}
if
(
obj
.
equals
(
Consts
.
CLASS_THROWABLE
))
{
return
"th"
;
return
Utils
.
escape
(
type
.
toString
());
}
private
static
String
fromName
(
String
name
)
{
if
(
name
==
null
||
name
.
isEmpty
())
{
return
null
;
}
ClassInfo
clsInfo
=
ClassInfo
.
fromType
(
type
);
String
shortName
=
clsInfo
.
getShortName
();
if
(
shortName
.
toUpperCase
().
equals
(
shortName
))
{
if
(
name
.
toUpperCase
().
equals
(
name
))
{
// all characters are upper case
return
shortN
ame
.
toLowerCase
();
return
n
ame
.
toLowerCase
();
}
if
(!
shortName
.
isEmpty
())
{
String
v1
=
Character
.
toLowerCase
(
shortName
.
charAt
(
0
))
+
shortName
.
substring
(
1
);
if
(!
v1
.
equals
(
shortName
))
{
String
v1
=
Character
.
toLowerCase
(
name
.
charAt
(
0
))
+
name
.
substring
(
1
);
if
(!
v1
.
equals
(
name
))
{
return
v1
;
}
if
(
name
.
length
()
<
3
)
{
return
name
+
"Var"
;
}
return
null
;
}
return
Utils
.
escape
(
type
.
toString
());
public
static
void
guessName
(
RegisterArg
arg
)
{
SSAVar
sVar
=
arg
.
getSVar
();
if
(
sVar
==
null
||
sVar
.
getName
()
!=
null
)
{
return
;
}
RegisterArg
assignArg
=
sVar
.
getAssign
();
InsnNode
assignInsn
=
assignArg
.
getParentInsn
();
String
name
=
makeNameFromInsn
(
assignInsn
);
if
(
name
!=
null
&&
!
NameMapper
.
isReserved
(
name
))
{
assignArg
.
setName
(
name
);
}
}
public
static
String
getAliasForObject
(
String
name
)
{
return
OBJ_ALIAS
.
get
(
name
);
}
private
static
String
makeNameFromInsn
(
InsnNode
insn
)
{
switch
(
insn
.
getType
())
{
case
INVOKE:
InvokeNode
inv
=
(
InvokeNode
)
insn
;
String
name
=
inv
.
getCallMth
().
getName
();
if
(
name
.
startsWith
(
"get"
)
||
name
.
startsWith
(
"set"
))
{
return
fromName
(
name
.
substring
(
3
));
}
if
(
"iterator"
.
equals
(
name
))
{
return
"it"
;
}
return
name
;
case
CONSTRUCTOR:
ConstructorInsn
co
=
(
ConstructorInsn
)
insn
;
return
makeNameForObject
(
co
.
getClassType
().
getType
());
case
ARRAY_LENGTH:
return
"length"
;
case
ARITH:
case
TERNARY:
case
CAST:
for
(
InsnArg
arg
:
insn
.
getArguments
())
{
if
(
arg
.
isInsnWrap
())
{
InsnNode
wrapInsn
=
((
InsnWrapArg
)
arg
).
getWrapInsn
();
String
wName
=
makeNameFromInsn
(
wrapInsn
);
if
(
wName
!=
null
)
{
return
wName
;
}
}
}
break
;
default
:
break
;
}
return
null
;
}
}
jadx-core/src/main/java/jadx/core/dex/instructions/args/MthParameterArg.java
浏览文件 @
d2acaa03
...
...
@@ -41,4 +41,24 @@ public class MthParameterArg extends RegisterArg {
}
super
.
setSVar
(
sVar
);
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
{
return
true
;
}
if
(!(
obj
instanceof
MthParameterArg
))
{
return
false
;
}
if
(!
super
.
equals
(
obj
))
{
return
false
;
}
MthParameterArg
that
=
(
MthParameterArg
)
obj
;
return
isThis
==
that
.
isThis
;
}
@Override
public
int
hashCode
()
{
return
31
*
super
.
hashCode
()
+
(
isThis
?
1
:
0
);
}
}
jadx-core/src/main/java/jadx/core/dex/visitors/regions/ProcessVariables.java
浏览文件 @
d2acaa03
package
jadx.core.dex.visitors.regions
;
import
jadx.core.codegen.NameGen
;
import
jadx.core.dex.attributes.AFlag
;
import
jadx.core.dex.attributes.AType
;
import
jadx.core.dex.attributes.nodes.DeclareVariablesAttr
;
...
...
@@ -179,6 +180,7 @@ public class ProcessVariables extends AbstractVisitor {
if
(
u
.
getArgRegion
()
==
assignRegion
&&
canDeclareInRegion
(
u
,
assignRegion
,
regionsOrder
))
{
u
.
getArg
().
getParentInsn
().
add
(
AFlag
.
DECLARE_VAR
);
processVar
(
u
.
getArg
());
it
.
remove
();
break
;
}
...
...
@@ -248,6 +250,11 @@ public class ProcessVariables extends AbstractVisitor {
region
.
addAttr
(
dv
);
}
dv
.
addVar
(
arg
);
processVar
(
arg
);
}
private
static
void
processVar
(
RegisterArg
arg
)
{
NameGen
.
guessName
(
arg
);
}
private
static
int
calculateOrder
(
IContainer
container
,
Map
<
IContainer
,
Integer
>
regionsOrder
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录