Commit d0f120c3 authored by Skylot's avatar Skylot

core: fix string concatenation

parent 54f4c6d2
......@@ -303,14 +303,19 @@ public class InsnGen {
break;
case STR_CONCAT:
// TODO: wrap in braces only if necessary
code.add('(');
StringBuilder sb = new StringBuilder();
for (Iterator<InsnArg> it = insn.getArguments().iterator(); it.hasNext(); ) {
code.add(arg(it.next()));
if (it.hasNext())
code.add(" + ");
sb.append(arg(it.next()));
if (it.hasNext()) {
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;
case MONITOR_ENTER:
......
package jadx.core.dex.instructions.args;
import jadx.core.dex.instructions.InsnType;
import jadx.core.dex.nodes.InsnNode;
import jadx.core.utils.InsnUtils;
......@@ -57,12 +58,17 @@ public abstract class InsnArg extends Typed {
this.parentInsn = parentInsn;
}
public InsnWrapArg wrapInstruction(InsnNode insn) {
public InsnArg wrapInstruction(InsnNode insn) {
assert parentInsn != insn : "Can't wrap instruction info itself";
int count = parentInsn.getArgsCount();
for (int i = 0; i < count; i++) {
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);
return arg;
}
......
......@@ -36,7 +36,7 @@ public class CodeShrinker extends AbstractVisitor {
return;
shrink(mth);
pretify(mth);
prettify(mth);
}
private static void shrink(MethodNode mth) {
......@@ -93,14 +93,14 @@ public class CodeShrinker extends AbstractVisitor {
}
}
private static void pretify(MethodNode mth) {
private static void prettify(MethodNode mth) {
for (BlockNode block : mth.getBasicBlocks()) {
for (int i = 0; i < block.getInstructions().size(); i++) {
InsnNode insn = block.getInstructions().get(i);
InsnNode ni = pretifyInsn(mth, insn);
if (ni != null)
block.getInstructions().set(i, ni);
List<InsnNode> list = block.getInstructions();
for (int i = 0; i < list.size(); i++) {
InsnNode modInsn = pretifyInsn(mth, list.get(i));
if (modInsn != null) {
list.set(i, modInsn);
}
}
}
}
......@@ -166,6 +166,7 @@ public class CodeShrinker extends AbstractVisitor {
if (callMth.getDeclClass().getFullName().equals(Consts.CLASS_STRING_BUILDER)
&& callMth.getShortId().equals("toString()")
&& insn.getArg(0).isInsnWrap()) {
try {
List<InsnNode> chain = flattenInsnChain(insn);
if (chain.size() > 1 && chain.get(0).getType() == InsnType.CONSTRUCTOR) {
ConstructorInsn constr = (ConstructorInsn) chain.get(0);
......@@ -180,6 +181,9 @@ public class CodeShrinker extends AbstractVisitor {
return concatInsn;
}
}
} catch (Throwable e) {
LOG.debug("Can't convert string concatenation: {} insn: {}", mth, insn, e);
}
}
break;
......
......@@ -18,6 +18,10 @@ sourceSets {
}
}
compileJava {
options.compilerArgs << '-g:none'
}
task samplesRun(type: JavaExec, dependsOn: compileJava) {
classpath = sourceSets.main.output
main = mainSamplesClass
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment