Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
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
d0f120c3
Commit
d0f120c3
authored
Jul 31, 2013
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: fix string concatenation
parent
54f4c6d2
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
30 deletions
+49
-30
InsnGen.java
jadx-core/src/main/java/jadx/core/codegen/InsnGen.java
+11
-6
InsnArg.java
...rc/main/java/jadx/core/dex/instructions/args/InsnArg.java
+8
-2
CodeShrinker.java
...re/src/main/java/jadx/core/dex/visitors/CodeShrinker.java
+26
-22
build.gradle
jadx-samples/build.gradle
+4
-0
No files found.
jadx-core/src/main/java/jadx/core/codegen/InsnGen.java
View file @
d0f120c3
...
@@ -303,14 +303,19 @@ public class InsnGen {
...
@@ -303,14 +303,19 @@ public class InsnGen {
break
;
break
;
case
STR_CONCAT:
case
STR_CONCAT:
// TODO: wrap in braces only if necessary
StringBuilder
sb
=
new
StringBuilder
();
code
.
add
(
'('
);
for
(
Iterator
<
InsnArg
>
it
=
insn
.
getArguments
().
iterator
();
it
.
hasNext
();
)
{
for
(
Iterator
<
InsnArg
>
it
=
insn
.
getArguments
().
iterator
();
it
.
hasNext
();
)
{
code
.
add
(
arg
(
it
.
next
()));
sb
.
append
(
arg
(
it
.
next
()));
if
(
it
.
hasNext
())
if
(
it
.
hasNext
())
{
code
.
add
(
" + "
);
sb
.
append
(
" + "
);
}
}
// TODO: wrap in braces only if necessary
if
(
state
.
contains
(
InsnGenState
.
BODY_ONLY
))
{
code
.
add
(
'('
).
add
(
sb
.
toString
()).
add
(
')'
);
}
else
{
code
.
add
(
sb
.
toString
());
}
}
code
.
add
(
')'
);
break
;
break
;
case
MONITOR_ENTER:
case
MONITOR_ENTER:
...
...
jadx-core/src/main/java/jadx/core/dex/instructions/args/InsnArg.java
View file @
d0f120c3
package
jadx
.
core
.
dex
.
instructions
.
args
;
package
jadx
.
core
.
dex
.
instructions
.
args
;
import
jadx.core.dex.instructions.InsnType
;
import
jadx.core.dex.nodes.InsnNode
;
import
jadx.core.dex.nodes.InsnNode
;
import
jadx.core.utils.InsnUtils
;
import
jadx.core.utils.InsnUtils
;
...
@@ -57,12 +58,17 @@ public abstract class InsnArg extends Typed {
...
@@ -57,12 +58,17 @@ public abstract class InsnArg extends Typed {
this
.
parentInsn
=
parentInsn
;
this
.
parentInsn
=
parentInsn
;
}
}
public
Insn
Wrap
Arg
wrapInstruction
(
InsnNode
insn
)
{
public
InsnArg
wrapInstruction
(
InsnNode
insn
)
{
assert
parentInsn
!=
insn
:
"Can't wrap instruction info itself"
;
assert
parentInsn
!=
insn
:
"Can't wrap instruction info itself"
;
int
count
=
parentInsn
.
getArgsCount
();
int
count
=
parentInsn
.
getArgsCount
();
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
if
(
parentInsn
.
getArg
(
i
)
==
this
)
{
if
(
parentInsn
.
getArg
(
i
)
==
this
)
{
InsnWrapArg
arg
=
wrap
(
insn
);
InsnArg
arg
;
if
(
insn
.
getType
()
==
InsnType
.
MOVE
)
{
arg
=
insn
.
getArg
(
0
);
}
else
{
arg
=
wrap
(
insn
);
}
parentInsn
.
setArg
(
i
,
arg
);
parentInsn
.
setArg
(
i
,
arg
);
return
arg
;
return
arg
;
}
}
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/CodeShrinker.java
View file @
d0f120c3
...
@@ -36,7 +36,7 @@ public class CodeShrinker extends AbstractVisitor {
...
@@ -36,7 +36,7 @@ public class CodeShrinker extends AbstractVisitor {
return
;
return
;
shrink
(
mth
);
shrink
(
mth
);
pretify
(
mth
);
pret
t
ify
(
mth
);
}
}
private
static
void
shrink
(
MethodNode
mth
)
{
private
static
void
shrink
(
MethodNode
mth
)
{
...
@@ -93,14 +93,14 @@ public class CodeShrinker extends AbstractVisitor {
...
@@ -93,14 +93,14 @@ public class CodeShrinker extends AbstractVisitor {
}
}
}
}
private
static
void
pretify
(
MethodNode
mth
)
{
private
static
void
pret
t
ify
(
MethodNode
mth
)
{
for
(
BlockNode
block
:
mth
.
getBasicBlocks
())
{
for
(
BlockNode
block
:
mth
.
getBasicBlocks
())
{
for
(
int
i
=
0
;
i
<
block
.
getInstructions
().
size
();
i
++)
{
List
<
InsnNode
>
list
=
block
.
getInstructions
();
InsnNode
insn
=
block
.
getInstructions
().
get
(
i
);
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
InsnNode
modInsn
=
pretifyInsn
(
mth
,
list
.
get
(
i
));
InsnNode
ni
=
pretifyInsn
(
mth
,
insn
);
if
(
modInsn
!=
null
)
{
if
(
ni
!=
null
)
list
.
set
(
i
,
modInsn
);
block
.
getInstructions
().
set
(
i
,
ni
);
}
}
}
}
}
}
}
...
@@ -166,6 +166,7 @@ public class CodeShrinker extends AbstractVisitor {
...
@@ -166,6 +166,7 @@ public class CodeShrinker extends AbstractVisitor {
if
(
callMth
.
getDeclClass
().
getFullName
().
equals
(
Consts
.
CLASS_STRING_BUILDER
)
if
(
callMth
.
getDeclClass
().
getFullName
().
equals
(
Consts
.
CLASS_STRING_BUILDER
)
&&
callMth
.
getShortId
().
equals
(
"toString()"
)
&&
callMth
.
getShortId
().
equals
(
"toString()"
)
&&
insn
.
getArg
(
0
).
isInsnWrap
())
{
&&
insn
.
getArg
(
0
).
isInsnWrap
())
{
try
{
List
<
InsnNode
>
chain
=
flattenInsnChain
(
insn
);
List
<
InsnNode
>
chain
=
flattenInsnChain
(
insn
);
if
(
chain
.
size
()
>
1
&&
chain
.
get
(
0
).
getType
()
==
InsnType
.
CONSTRUCTOR
)
{
if
(
chain
.
size
()
>
1
&&
chain
.
get
(
0
).
getType
()
==
InsnType
.
CONSTRUCTOR
)
{
ConstructorInsn
constr
=
(
ConstructorInsn
)
chain
.
get
(
0
);
ConstructorInsn
constr
=
(
ConstructorInsn
)
chain
.
get
(
0
);
...
@@ -180,6 +181,9 @@ public class CodeShrinker extends AbstractVisitor {
...
@@ -180,6 +181,9 @@ public class CodeShrinker extends AbstractVisitor {
return
concatInsn
;
return
concatInsn
;
}
}
}
}
}
catch
(
Throwable
e
)
{
LOG
.
debug
(
"Can't convert string concatenation: {} insn: {}"
,
mth
,
insn
,
e
);
}
}
}
break
;
break
;
...
...
jadx-samples/build.gradle
View file @
d0f120c3
...
@@ -18,6 +18,10 @@ sourceSets {
...
@@ -18,6 +18,10 @@ sourceSets {
}
}
}
}
compileJava
{
options
.
compilerArgs
<<
'-g:none'
}
task
samplesRun
(
type:
JavaExec
,
dependsOn:
compileJava
)
{
task
samplesRun
(
type:
JavaExec
,
dependsOn:
compileJava
)
{
classpath
=
sourceSets
.
main
.
output
classpath
=
sourceSets
.
main
.
output
main
=
mainSamplesClass
main
=
mainSamplesClass
...
...
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