Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
J
jadx
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
jadx
Commits
c555cd08
Commit
c555cd08
authored
Jul 14, 2019
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: rename packages with reserved names (#711)
parent
92e28326
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
119 additions
and
24 deletions
+119
-24
Deobfuscator.java
jadx-core/src/main/java/jadx/core/deobf/Deobfuscator.java
+29
-7
RenameVisitor.java
...e/src/main/java/jadx/core/dex/visitors/RenameVisitor.java
+28
-16
CodeGenUtils.java
jadx-core/src/main/java/jadx/core/utils/CodeGenUtils.java
+1
-1
TestReservedPackageNames.java
...adx/tests/integration/names/TestReservedPackageNames.java
+59
-0
a.smali
...ore/src/test/smali/names/TestReservedPackageNames/a.smali
+2
-0
No files found.
jadx-core/src/main/java/jadx/core/deobf/Deobfuscator.java
View file @
c555cd08
...
...
@@ -346,7 +346,7 @@ public class Deobfuscator {
ClassInfo
classInfo
=
cls
.
getClassInfo
();
String
pkgFullName
=
classInfo
.
getPackage
();
PackageNode
pkg
=
getPackageNode
(
pkgFullName
,
true
);
doPkg
(
pkg
,
pkgFullName
);
processPackageFull
(
pkg
,
pkgFullName
);
String
alias
=
deobfPresets
.
getForCls
(
classInfo
);
if
(
alias
!=
null
)
{
...
...
@@ -372,6 +372,24 @@ public class Deobfuscator {
return
makeClsAlias
(
cls
);
}
public
String
getPkgAlias
(
ClassNode
cls
)
{
ClassInfo
classInfo
=
cls
.
getClassInfo
();
PackageNode
pkg
=
null
;
DeobfClsInfo
deobfClsInfo
=
clsMap
.
get
(
classInfo
);
if
(
deobfClsInfo
!=
null
)
{
pkg
=
deobfClsInfo
.
getPkg
();
}
else
{
String
fullPkgName
=
classInfo
.
getPackage
();
pkg
=
getPackageNode
(
fullPkgName
,
true
);
processPackageFull
(
pkg
,
fullPkgName
);
}
if
(
pkg
.
hasAnyAlias
())
{
return
pkg
.
getFullAlias
();
}
else
{
return
pkg
.
getFullName
();
}
}
private
String
makeClsAlias
(
ClassNode
cls
)
{
ClassInfo
classInfo
=
cls
.
getClassInfo
();
String
alias
=
null
;
...
...
@@ -472,7 +490,7 @@ public class Deobfuscator {
return
alias
;
}
private
void
doPkg
(
PackageNode
pkg
,
String
fullName
)
{
private
void
processPackageFull
(
PackageNode
pkg
,
String
fullName
)
{
if
(
pkgSet
.
contains
(
fullName
))
{
return
;
}
...
...
@@ -482,15 +500,19 @@ public class Deobfuscator {
PackageNode
parentPkg
=
pkg
.
getParentPackage
();
while
(!
parentPkg
.
getName
().
isEmpty
())
{
if
(!
parentPkg
.
hasAlias
())
{
doPkg
(
parentPkg
,
parentPkg
.
getFullName
());
processPackageFull
(
parentPkg
,
parentPkg
.
getFullName
());
}
parentPkg
=
parentPkg
.
getParentPackage
();
}
String
pkgName
=
pkg
.
getName
();
if
(!
pkg
.
hasAlias
()
&&
shouldRename
(
pkgName
))
{
String
pkgAlias
=
String
.
format
(
"p%03d%s"
,
pkgIndex
++,
prepareNamePart
(
pkgName
));
pkg
.
setAlias
(
pkgAlias
);
if
(!
pkg
.
hasAlias
())
{
String
pkgName
=
pkg
.
getName
();
if
((
args
.
isDeobfuscationOn
()
&&
shouldRename
(
pkgName
))
||
(
args
.
isRenameValid
()
&&
!
NameMapper
.
isValidIdentifier
(
pkgName
))
||
(
args
.
isRenamePrintable
()
&&
!
NameMapper
.
isAllCharsPrintable
(
pkgName
)))
{
String
pkgAlias
=
String
.
format
(
"p%03d%s"
,
pkgIndex
++,
prepareNamePart
(
pkg
.
getName
()));
pkg
.
setAlias
(
pkgAlias
);
}
}
}
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/RenameVisitor.java
View file @
c555cd08
...
...
@@ -95,25 +95,37 @@ public class RenameVisitor extends AbstractVisitor {
classInfo
.
changeShortName
(
newShortName
);
cls
.
addAttr
(
new
RenameReasonAttr
(
cls
).
append
(
"invalid class name"
));
}
if
(
args
.
isRenameValid
())
{
if
(
classInfo
.
isInner
())
{
ClassInfo
parentClass
=
classInfo
.
getParentClass
();
while
(
parentClass
!=
null
)
{
if
(
parentClass
.
getAliasShortName
().
equals
(
clsName
))
{
String
clsAlias
=
deobfuscator
.
getClsAlias
(
cls
);
classInfo
.
changeShortName
(
clsAlias
);
cls
.
addAttr
(
new
RenameReasonAttr
(
cls
).
append
(
"collision with other inner class name"
));
break
;
}
parentClass
=
parentClass
.
getParentClass
();
}
}
else
{
if
(
classInfo
.
getAliasPkg
().
isEmpty
())
{
classInfo
.
changePkg
(
Consts
.
DEFAULT_PACKAGE_NAME
);
cls
.
addAttr
(
new
RenameReasonAttr
(
cls
).
append
(
"default package"
));
if
(
classInfo
.
isInner
()
&&
args
.
isRenameValid
())
{
// check inner classes names
ClassInfo
parentClass
=
classInfo
.
getParentClass
();
while
(
parentClass
!=
null
)
{
if
(
parentClass
.
getAliasShortName
().
equals
(
clsName
))
{
String
clsAlias
=
deobfuscator
.
getClsAlias
(
cls
);
classInfo
.
changeShortName
(
clsAlias
);
cls
.
addAttr
(
new
RenameReasonAttr
(
cls
).
append
(
"collision with other inner class name"
));
break
;
}
parentClass
=
parentClass
.
getParentClass
();
}
}
checkPackage
(
deobfuscator
,
cls
,
classInfo
,
args
);
}
private
static
void
checkPackage
(
Deobfuscator
deobfuscator
,
ClassNode
cls
,
ClassInfo
classInfo
,
JadxArgs
args
)
{
if
(
classInfo
.
isInner
())
{
return
;
}
String
aliasPkg
=
classInfo
.
getAliasPkg
();
if
(
args
.
isRenameValid
()
&&
aliasPkg
.
isEmpty
())
{
classInfo
.
changePkg
(
Consts
.
DEFAULT_PACKAGE_NAME
);
cls
.
addAttr
(
new
RenameReasonAttr
(
cls
).
append
(
"default package"
));
return
;
}
String
fullPkgAlias
=
deobfuscator
.
getPkgAlias
(
cls
);
if
(!
fullPkgAlias
.
equals
(
aliasPkg
))
{
classInfo
.
changePkg
(
fullPkgAlias
);
cls
.
addAttr
(
new
RenameReasonAttr
(
cls
).
append
(
"invalid package"
));
}
}
@Nullable
...
...
jadx-core/src/main/java/jadx/core/utils/CodeGenUtils.java
View file @
c555cd08
...
...
@@ -22,7 +22,7 @@ public class CodeGenUtils {
code
.
startLine
(
"/* renamed from: "
).
add
(
origName
);
RenameReasonAttr
renameReasonAttr
=
node
.
get
(
AType
.
RENAME_REASON
);
if
(
renameReasonAttr
!=
null
)
{
code
.
add
(
" reason: "
);
code
.
add
(
"
reason: "
);
code
.
add
(
renameReasonAttr
.
getDescription
());
}
code
.
add
(
" */"
);
...
...
jadx-core/src/test/java/jadx/tests/integration/names/TestReservedPackageNames.java
0 → 100644
View file @
c555cd08
package
jadx
.
tests
.
integration
.
names
;
import
java.util.List
;
import
org.junit.jupiter.api.Test
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.tests.api.SmaliTest
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
hamcrest
.
Matchers
.
not
;
public
class
TestReservedPackageNames
extends
SmaliTest
{
// @formatter:off
/*
package do.if;
public class A {}
*/
// @formatter:on
@Test
public
void
test
()
{
List
<
ClassNode
>
clsList
=
loadFromSmaliFiles
();
for
(
ClassNode
cls
:
clsList
)
{
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
not
(
containsString
(
"package do.if;"
)));
}
}
@Test
public
void
testDeobf
()
{
enableDeobfuscation
();
List
<
ClassNode
>
clsList
=
loadFromSmaliFiles
();
for
(
ClassNode
cls
:
clsList
)
{
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
not
(
containsString
(
"package do.if;"
)));
}
}
@Test
public
void
testRenameDisabled
()
{
args
.
setRenameCaseSensitive
(
false
);
args
.
setRenameValid
(
false
);
args
.
setRenamePrintable
(
false
);
disableCompilation
();
List
<
ClassNode
>
clsList
=
loadFromSmaliFiles
();
for
(
ClassNode
cls
:
clsList
)
{
String
code
=
cls
.
getCode
().
toString
();
if
(
cls
.
getShortName
().
equals
(
"A"
))
{
assertThat
(
code
,
containsString
(
"package do.if;"
));
}
}
}
}
jadx-core/src/test/smali/names/TestReservedPackageNames/a.smali
0 → 100644
View file @
c555cd08
.class public Ldo/if/A;
.super Ljava/lang/Object;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment