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
a9290f31
Commit
a9290f31
authored
Dec 13, 2013
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: remove synthetic constructors
parent
e46dfc55
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
1 deletion
+60
-1
ClassModifier.java
...e/src/main/java/jadx/core/dex/visitors/ClassModifier.java
+19
-1
TestInnerClass2.java
...re/src/test/java/jadx/tests/internal/TestInnerClass2.java
+41
-0
No files found.
jadx-core/src/main/java/jadx/core/dex/visitors/ClassModifier.java
View file @
a9290f31
...
...
@@ -9,6 +9,7 @@ import jadx.core.dex.instructions.IndexInsnNode;
import
jadx.core.dex.instructions.InsnType
;
import
jadx.core.dex.instructions.args.InsnArg
;
import
jadx.core.dex.instructions.args.RegisterArg
;
import
jadx.core.dex.instructions.mods.ConstructorInsn
;
import
jadx.core.dex.nodes.BlockNode
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.core.dex.nodes.FieldNode
;
...
...
@@ -26,7 +27,12 @@ public class ClassModifier extends AbstractVisitor {
for
(
ClassNode
inner
:
cls
.
getInnerClasses
())
{
visit
(
inner
);
}
if
(
cls
.
getAccessFlags
().
isSynthetic
()
&&
cls
.
getFields
().
isEmpty
()
&&
cls
.
getMethods
().
isEmpty
())
{
cls
.
getAttributes
().
add
(
AttributeFlag
.
DONT_GENERATE
);
return
false
;
}
removeSyntheticFields
(
cls
);
removeSyntheticMethods
(
cls
);
removeEmptyMethods
(
cls
);
...
...
@@ -110,6 +116,18 @@ public class ClassModifier extends AbstractVisitor {
it
.
remove
();
}
}
// remove synthetic constructor for inner non-static classes
if
(
af
.
isSynthetic
()
&&
af
.
isConstructor
()
&&
mth
.
getBasicBlocks
().
size
()
==
2
)
{
List
<
InsnNode
>
insns
=
mth
.
getBasicBlocks
().
get
(
0
).
getInstructions
();
if
(
insns
.
size
()
==
1
&&
insns
.
get
(
0
).
getType
()
==
InsnType
.
CONSTRUCTOR
)
{
ConstructorInsn
constr
=
(
ConstructorInsn
)
insns
.
get
(
0
);
if
(
constr
.
isThis
()
&&
mth
.
getArguments
(
false
).
size
()
>=
1
)
{
mth
.
removeFirstArgument
();
mth
.
getAttributes
().
add
(
AttributeFlag
.
DONT_GENERATE
);
}
}
}
}
}
...
...
jadx-core/src/test/java/jadx/tests/internal/TestInnerClass2.java
0 → 100644
View file @
a9290f31
package
jadx
.
tests
.
internal
;
import
jadx.api.InternalJadxTest
;
import
jadx.core.dex.nodes.ClassNode
;
import
java.util.Timer
;
import
java.util.TimerTask
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
import
static
org
.
hamcrest
.
CoreMatchers
.
not
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TestInnerClass2
extends
InternalJadxTest
{
public
static
class
TestCls
{
private
static
class
TerminateTask
extends
TimerTask
{
@Override
public
void
run
()
{
System
.
err
.
println
(
"Test timed out"
);
}
}
public
void
test
()
{
new
Timer
().
schedule
(
new
TerminateTask
(),
1000
);
}
}
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
assertThat
(
code
,
containsString
(
"new Timer().schedule(new TerminateTask(), 1000);"
));
assertThat
(
code
,
not
(
containsString
(
"synthetic"
)));
assertThat
(
code
,
not
(
containsString
(
"this"
)));
assertThat
(
code
,
not
(
containsString
(
"null"
)));
assertThat
(
code
,
not
(
containsString
(
"AnonymousClass"
)));
}
}
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