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
95795620
Commit
95795620
authored
Mar 11, 2014
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: fix indent for 'break' in 'case' block, refactor tests
parent
890c0a99
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
100 additions
and
40 deletions
+100
-40
CodeWriter.java
jadx-core/src/main/java/jadx/core/codegen/CodeWriter.java
+13
-22
RegionGen.java
jadx-core/src/main/java/jadx/core/codegen/RegionGen.java
+8
-4
InternalJadxTest.java
jadx-core/src/test/java/jadx/api/InternalJadxTest.java
+1
-10
TestUtils.java
jadx-core/src/test/java/jadx/api/TestUtils.java
+25
-0
TestSwitch.java
jadx-core/src/test/java/jadx/tests/internal/TestSwitch.java
+49
-0
TestSynchronized.java
...e/src/test/java/jadx/tests/internal/TestSynchronized.java
+1
-1
TestVariablesDefinitions.java
...st/java/jadx/tests/internal/TestVariablesDefinitions.java
+1
-1
TestAnonymousClass3.java
...t/java/jadx/tests/internal/inner/TestAnonymousClass3.java
+2
-2
No files found.
jadx-core/src/main/java/jadx/core/codegen/CodeWriter.java
View file @
95795620
...
...
@@ -50,30 +50,20 @@ public class CodeWriter {
public
CodeWriter
startLine
()
{
addLine
();
addIndent
();
add
Line
Indent
();
return
this
;
}
public
CodeWriter
startLine
(
char
c
)
{
addLine
();
addIndent
();
add
Line
Indent
();
add
(
c
);
return
this
;
}
public
CodeWriter
startLine
(
String
str
)
{
addLine
();
addIndent
();
add
(
str
);
return
this
;
}
public
CodeWriter
startLine
(
int
ind
,
String
str
)
{
addLine
();
addIndent
();
for
(
int
i
=
0
;
i
<
ind
;
i
++)
{
addIndent
();
}
addLineIndent
();
add
(
str
);
return
this
;
}
...
...
@@ -118,12 +108,17 @@ public class CodeWriter {
offset
=
0
;
}
p
ublic
CodeWriter
add
Indent
()
{
p
rivate
CodeWriter
addLine
Indent
()
{
buf
.
append
(
indentStr
);
offset
+=
indentStr
.
length
();
return
this
;
}
public
CodeWriter
addIndent
()
{
add
(
INDENT
);
return
this
;
}
private
void
updateIndent
()
{
int
curIndent
=
indent
;
if
(
curIndent
<
INDENT_CACHE
.
length
)
{
...
...
@@ -137,14 +132,6 @@ public class CodeWriter {
}
}
public
int
getLine
()
{
return
line
;
}
public
int
getIndent
()
{
return
indent
;
}
public
void
incIndent
()
{
incIndent
(
1
);
}
...
...
@@ -167,6 +154,10 @@ public class CodeWriter {
updateIndent
();
}
public
int
getLine
()
{
return
line
;
}
private
static
class
DefinitionWrapper
{
private
final
LineAttrNode
node
;
...
...
jadx-core/src/main/java/jadx/core/codegen/RegionGen.java
View file @
95795620
...
...
@@ -203,6 +203,7 @@ public class RegionGen extends InsnGen {
code
.
startLine
(
"switch ("
);
addArg
(
code
,
arg
);
code
.
add
(
") {"
);
code
.
incIndent
();
int
size
=
sw
.
getKeys
().
size
();
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
...
...
@@ -223,18 +224,21 @@ public class RegionGen extends InsnGen {
code
.
startLine
(
"default:"
);
makeCaseBlock
(
sw
.
getDefaultCase
(),
code
);
}
code
.
decIndent
();
code
.
startLine
(
'}'
);
return
code
;
}
private
void
makeCaseBlock
(
IContainer
c
,
CodeWriter
code
)
throws
CodegenException
{
boolean
addBreak
=
true
;
if
(
RegionUtils
.
notEmpty
(
c
))
{
makeRegionIndent
(
code
,
c
);
if
(
RegionUtils
.
hasExitEdge
(
c
))
{
code
.
startLine
(
1
,
"break;"
)
;
if
(
!
RegionUtils
.
hasExitEdge
(
c
))
{
addBreak
=
false
;
}
}
else
{
code
.
startLine
(
1
,
"break;"
);
}
if
(
addBreak
)
{
code
.
startLine
().
addIndent
().
add
(
"break;"
);
}
}
...
...
jadx-core/src/test/java/jadx/api/InternalJadxTest.java
View file @
95795620
package
jadx
.
api
;
import
jadx.core.Jadx
;
import
jadx.core.codegen.CodeWriter
;
import
jadx.core.dex.attributes.AttributeFlag
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.core.dex.nodes.MethodNode
;
...
...
@@ -25,7 +24,7 @@ import static junit.framework.Assert.assertFalse;
import
static
junit
.
framework
.
Assert
.
assertNotNull
;
import
static
junit
.
framework
.
Assert
.
fail
;
public
abstract
class
InternalJadxTest
{
public
abstract
class
InternalJadxTest
extends
TestUtils
{
protected
boolean
outputCFG
=
false
;
protected
boolean
deleteTmpJar
=
true
;
...
...
@@ -151,14 +150,6 @@ public abstract class InternalJadxTest {
}
}
protected
String
makeIndent
(
int
indent
)
{
StringBuilder
sb
=
new
StringBuilder
(
indent
*
CodeWriter
.
INDENT
.
length
());
for
(
int
i
=
0
;
i
<
indent
;
i
++)
{
sb
.
append
(
CodeWriter
.
INDENT
);
}
return
sb
.
toString
();
}
// Use only for debug purpose
@Deprecated
protected
void
setOutputCFG
()
{
...
...
jadx-core/src/test/java/jadx/api/TestUtils.java
0 → 100644
View file @
95795620
package
jadx
.
api
;
import
jadx.core.codegen.CodeWriter
;
public
class
TestUtils
{
public
static
String
indent
(
int
indent
)
{
StringBuilder
sb
=
new
StringBuilder
(
indent
*
CodeWriter
.
INDENT
.
length
());
for
(
int
i
=
0
;
i
<
indent
;
i
++)
{
sb
.
append
(
CodeWriter
.
INDENT
);
}
return
sb
.
toString
();
}
public
static
int
count
(
String
string
,
String
substring
)
{
int
count
=
0
;
int
idx
=
0
;
while
((
idx
=
string
.
indexOf
(
substring
,
idx
))
!=
-
1
)
{
idx
++;
count
++;
}
return
count
;
}
}
jadx-core/src/test/java/jadx/tests/internal/TestSwitch.java
0 → 100644
View file @
95795620
package
jadx
.
tests
.
internal
;
import
jadx.api.InternalJadxTest
;
import
jadx.core.dex.nodes.ClassNode
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
CoreMatchers
.
containsString
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
TestSwitch
extends
InternalJadxTest
{
public
static
class
TestCls
{
public
String
escape
(
String
str
)
{
int
len
=
str
.
length
();
StringBuilder
sb
=
new
StringBuilder
(
len
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
char
c
=
str
.
charAt
(
i
);
switch
(
c
)
{
case
'.'
:
case
'/'
:
sb
.
append
(
'_'
);
break
;
case
']'
:
sb
.
append
(
'A'
);
break
;
case
'?'
:
break
;
default
:
sb
.
append
(
c
);
break
;
}
}
return
sb
.
toString
();
}
}
@Test
public
void
test
()
{
ClassNode
cls
=
getClassNode
(
TestCls
.
class
);
String
code
=
cls
.
getCode
().
toString
();
System
.
out
.
println
(
code
);
assertThat
(
code
,
containsString
(
"case '/':"
));
assertThat
(
code
,
containsString
(
indent
(
5
)
+
"break;"
));
}
}
jadx-core/src/test/java/jadx/tests/internal/TestSynchronized.java
View file @
95795620
...
...
@@ -38,6 +38,6 @@ public class TestSynchronized extends InternalJadxTest {
assertThat
(
code
,
containsString
(
"return this.f"
));
assertThat
(
code
,
containsString
(
"synchronized (this.o) {"
));
assertThat
(
code
,
not
(
containsString
(
makeI
ndent
(
3
)
+
";"
)));
assertThat
(
code
,
not
(
containsString
(
i
ndent
(
3
)
+
";"
)));
}
}
jadx-core/src/test/java/jadx/tests/internal/TestVariablesDefinitions.java
View file @
95795620
...
...
@@ -43,7 +43,7 @@ public class TestVariablesDefinitions extends InternalJadxTest {
System
.
out
.
println
(
code
);
// 'iterator' variable must be declared inside 'try' block
assertThat
(
code
,
containsString
(
makeI
ndent
(
3
)
+
"Iterator<IDexTreeVisitor> iterator = "
));
assertThat
(
code
,
containsString
(
i
ndent
(
3
)
+
"Iterator<IDexTreeVisitor> iterator = "
));
assertThat
(
code
,
not
(
containsString
(
"iterator;"
)));
}
}
jadx-core/src/test/java/jadx/tests/internal/inner/TestAnonymousClass3.java
View file @
95795620
...
...
@@ -44,8 +44,8 @@ public class TestAnonymousClass3 extends InternalJadxTest {
String
code
=
cls
.
getCode
().
toString
();
System
.
out
.
println
(
code
);
assertThat
(
code
,
containsString
(
makeI
ndent
(
4
)
+
"public void run() {"
));
assertThat
(
code
,
containsString
(
makeI
ndent
(
3
)
+
"}.start();"
));
assertThat
(
code
,
containsString
(
i
ndent
(
4
)
+
"public void run() {"
));
assertThat
(
code
,
containsString
(
i
ndent
(
3
)
+
"}.start();"
));
// assertThat(code, not(containsString("synthetic")));
// 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