Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Quincy379
jadx
提交
9856b6d3
J
jadx
项目概览
Quincy379
/
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,发现更多精彩内容 >>
提交
9856b6d3
编写于
2月 21, 2019
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: remove invalid chars from class names (#453)
上级
e1ca2904
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
104 addition
and
23 deletion
+104
-23
jadx-core/src/main/java/jadx/core/deobf/Deobfuscator.java
jadx-core/src/main/java/jadx/core/deobf/Deobfuscator.java
+1
-15
jadx-core/src/main/java/jadx/core/deobf/NameMapper.java
jadx-core/src/main/java/jadx/core/deobf/NameMapper.java
+51
-0
jadx-core/src/main/java/jadx/core/dex/visitors/RenameVisitor.java
...e/src/main/java/jadx/core/dex/visitors/RenameVisitor.java
+14
-8
jadx-core/src/test/java/jadx/core/deobf/NameMapperTest.java
jadx-core/src/test/java/jadx/core/deobf/NameMapperTest.java
+38
-0
未找到文件。
jadx-core/src/main/java/jadx/core/deobf/Deobfuscator.java
浏览文件 @
9856b6d3
...
...
@@ -483,21 +483,7 @@ public class Deobfuscator {
if
(
name
.
length
()
>
maxLength
)
{
return
"x"
+
Integer
.
toHexString
(
name
.
hashCode
());
}
if
(!
NameMapper
.
isAllCharsPrintable
(
name
))
{
return
removeInvalidChars
(
name
);
}
return
name
;
}
private
String
removeInvalidChars
(
String
name
)
{
StringBuilder
sb
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
name
.
length
();
i
++)
{
int
ch
=
name
.
charAt
(
i
);
if
(
NameMapper
.
isPrintableChar
(
ch
))
{
sb
.
append
((
char
)
ch
);
}
}
return
sb
.
toString
();
return
NameMapper
.
removeInvalidCharsMiddle
(
name
);
}
private
void
dumpClassAlias
(
ClassNode
cls
)
{
...
...
jadx-core/src/main/java/jadx/core/deobf/NameMapper.java
浏览文件 @
9856b6d3
...
...
@@ -91,6 +91,14 @@ public class NameMapper {
&&
isAllCharsPrintable
(
str
);
}
public
static
boolean
isValidIdentifierStart
(
int
codePoint
)
{
return
Character
.
isJavaIdentifierStart
(
codePoint
);
}
public
static
boolean
isValidIdentifierPart
(
int
codePoint
)
{
return
Character
.
isJavaIdentifierPart
(
codePoint
);
}
public
static
boolean
isPrintableChar
(
int
c
)
{
return
32
<=
c
&&
c
<=
126
;
}
...
...
@@ -105,6 +113,49 @@ public class NameMapper {
return
true
;
}
/**
* Return modified string with removed:
* <p><ul>
* <li> not printable chars (including unicode)
* <li> chars not valid for java identifier part
* </ul><p>
* Note: this 'middle' method must be used with prefixed string:
* <p><ul>
* <li> can leave invalid chars for java identifier start (i.e numbers)
* <li> result not checked for reserved words
* </ul><p>
*/
public
static
String
removeInvalidCharsMiddle
(
String
name
)
{
if
(
isValidIdentifier
(
name
)
&&
isAllCharsPrintable
(
name
))
{
return
name
;
}
int
len
=
name
.
length
();
StringBuilder
sb
=
new
StringBuilder
(
len
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
int
codePoint
=
name
.
codePointAt
(
i
);
if
(
isPrintableChar
(
codePoint
)
&&
isValidIdentifierPart
(
codePoint
))
{
sb
.
append
((
char
)
codePoint
);
}
}
return
sb
.
toString
();
}
/**
* Return string with removed invalid chars, see {@link #removeInvalidCharsMiddle}
* <p>
* Prepend prefix if first char is not valid as java identifier start char.
*/
public
static
String
removeInvalidChars
(
String
name
,
String
prefix
)
{
String
result
=
removeInvalidCharsMiddle
(
name
);
if
(!
result
.
isEmpty
())
{
int
codePoint
=
result
.
codePointAt
(
0
);
if
(!
isValidIdentifierStart
(
codePoint
))
{
return
prefix
+
result
;
}
}
return
result
;
}
private
NameMapper
()
{
}
}
jadx-core/src/main/java/jadx/core/dex/visitors/RenameVisitor.java
浏览文件 @
9856b6d3
...
...
@@ -72,14 +72,9 @@ public class RenameVisitor extends AbstractVisitor {
ClassInfo
classInfo
=
cls
.
getClassInfo
();
ClassInfo
alias
=
classInfo
.
getAlias
();
String
clsName
=
alias
.
getShortName
();
String
newShortName
=
null
;
char
firstChar
=
clsName
.
charAt
(
0
);
if
(
Character
.
isDigit
(
firstChar
))
{
newShortName
=
Consts
.
ANONYMOUS_CLASS_PREFIX
+
clsName
;
}
else
if
(
firstChar
==
'$'
)
{
newShortName
=
"C"
+
clsName
;
}
if
(
newShortName
!=
null
)
{
String
newShortName
=
fixClsShortName
(
clsName
);
if
(!
newShortName
.
equals
(
clsName
))
{
classInfo
.
rename
(
cls
.
root
(),
alias
.
makeFullClsName
(
newShortName
,
true
));
}
if
(
alias
.
getPackage
().
isEmpty
())
{
...
...
@@ -89,6 +84,17 @@ public class RenameVisitor extends AbstractVisitor {
}
}
private
String
fixClsShortName
(
String
clsName
)
{
char
firstChar
=
clsName
.
charAt
(
0
);
if
(
Character
.
isDigit
(
firstChar
))
{
return
Consts
.
ANONYMOUS_CLASS_PREFIX
+
NameMapper
.
removeInvalidCharsMiddle
(
clsName
);
}
if
(
firstChar
==
'$'
)
{
return
'C'
+
NameMapper
.
removeInvalidCharsMiddle
(
clsName
);
}
return
NameMapper
.
removeInvalidChars
(
clsName
,
"C"
);
}
private
void
checkFields
(
ClassNode
cls
)
{
Set
<
String
>
names
=
new
HashSet
<>();
for
(
FieldNode
field
:
cls
.
getFields
())
{
...
...
jadx-core/src/test/java/jadx/core/deobf/NameMapperTest.java
0 → 100644
浏览文件 @
9856b6d3
package
jadx.core.deobf
;
import
org.junit.Test
;
import
static
jadx
.
core
.
deobf
.
NameMapper
.
isValidIdentifier
;
import
static
jadx
.
core
.
deobf
.
NameMapper
.
removeInvalidChars
;
import
static
jadx
.
core
.
deobf
.
NameMapper
.
removeInvalidCharsMiddle
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
NameMapperTest
{
@Test
public
void
validIdentifiers
()
{
assertThat
(
isValidIdentifier
(
"ACls"
),
is
(
true
));
}
@Test
public
void
notValidIdentifiers
()
{
assertThat
(
isValidIdentifier
(
"1cls"
),
is
(
false
));
assertThat
(
isValidIdentifier
(
"-cls"
),
is
(
false
));
assertThat
(
isValidIdentifier
(
"A-cls"
),
is
(
false
));
}
@Test
public
void
testRemoveInvalidCharsMiddle
()
{
assertThat
(
removeInvalidCharsMiddle
(
"1cls"
),
is
(
"1cls"
));
assertThat
(
removeInvalidCharsMiddle
(
"-cls"
),
is
(
"cls"
));
assertThat
(
removeInvalidCharsMiddle
(
"A-cls"
),
is
(
"Acls"
));
}
@Test
public
void
testRemoveInvalidChars
()
{
assertThat
(
removeInvalidChars
(
"1cls"
,
"C"
),
is
(
"C1cls"
));
assertThat
(
removeInvalidChars
(
"-cls"
,
"C"
),
is
(
"cls"
));
assertThat
(
removeInvalidChars
(
"A-cls"
,
"C"
),
is
(
"Acls"
));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录