Commit e3a10391 authored by Skylot's avatar Skylot

Fix codegen for arith ops, rename reserved arg names in methods

parent 8da0ba82
...@@ -571,7 +571,7 @@ public class InsnGen { ...@@ -571,7 +571,7 @@ public class InsnGen {
code.add('(').add(v1).add(' ').add(op.getSymbol()).add(' ').add(v2).add(')'); code.add('(').add(v1).add(' ').add(op.getSymbol()).add(' ').add(v2).add(')');
} else { } else {
String res = arg(insn.getResult()); String res = arg(insn.getResult());
if (res.equals(v1)) { if (res.equals(v1) && insn.getResult().equals(insn.getArg(0))) {
state.add(InsnGenState.NO_RESULT); state.add(InsnGenState.NO_RESULT);
// "++" or "--" // "++" or "--"
if (insn.getArg(1).isLiteral() && (op == ArithOp.ADD || op == ArithOp.SUB)) { if (insn.getArg(1).isLiteral() && (op == ArithOp.ADD || op == ArithOp.SUB)) {
......
...@@ -194,7 +194,7 @@ public class MethodGen { ...@@ -194,7 +194,7 @@ public class MethodGen {
String r; String r;
int i = 2; int i = 2;
do { do {
r = name + i; r = name + "_" + i;
i++; i++;
} while (varNames.contains(r)); } while (varNames.contains(r));
varNames.add(r); varNames.add(r);
......
...@@ -9,6 +9,7 @@ import jadx.dex.nodes.IRegion; ...@@ -9,6 +9,7 @@ import jadx.dex.nodes.IRegion;
import jadx.dex.nodes.InsnNode; import jadx.dex.nodes.InsnNode;
import jadx.dex.nodes.MethodNode; import jadx.dex.nodes.MethodNode;
import jadx.dex.trycatch.ExceptionHandler; import jadx.dex.trycatch.ExceptionHandler;
import jadx.utils.BlockUtils;
import jadx.utils.InsnUtils; import jadx.utils.InsnUtils;
import jadx.utils.Utils; import jadx.utils.Utils;
...@@ -131,9 +132,11 @@ public class DotGraphVisitor extends AbstractVisitor { ...@@ -131,9 +132,11 @@ public class DotGraphVisitor extends AbstractVisitor {
for (BlockNode next : block.getDominatesOn()) for (BlockNode next : block.getDominatesOn())
conn.startLine(makeName(block) + " -> " + makeName(next) + "[style=dotted];"); conn.startLine(makeName(block) + " -> " + makeName(next) + "[style=dotted];");
// // add all dominators connections // add all dominators connections
// for (BlockNode next : BlockUtils.bitsetToBlocks(mth, block.getDoms())) if (false) {
// conn.startLine(makeName(block) + " -> " + makeName(next) + "[style=dotted, color=green];"); for (BlockNode next : BlockUtils.bitsetToBlocks(mth, block.getDoms()))
conn.startLine(makeName(block) + " -> " + makeName(next) + "[style=dotted, color=green];");
}
} }
private String attributesString(IAttributeNode block) { private String attributesString(IAttributeNode block) {
...@@ -180,6 +183,7 @@ public class DotGraphVisitor extends AbstractVisitor { ...@@ -180,6 +183,7 @@ public class DotGraphVisitor extends AbstractVisitor {
.replace("{", "\\{").replace("}", "\\}") .replace("{", "\\{").replace("}", "\\}")
.replace("\"", "\\\"") .replace("\"", "\\\"")
.replace("-", "\\-") .replace("-", "\\-")
.replace("|", "\\|")
.replace("\n", NL); .replace("\n", NL);
} }
} }
package jadx.dex.visitors; package jadx.dex.visitors;
import jadx.Consts; import jadx.Consts;
import jadx.deobf.NameMapper;
import jadx.dex.attributes.AttributeType; import jadx.dex.attributes.AttributeType;
import jadx.dex.info.MethodInfo; import jadx.dex.info.MethodInfo;
import jadx.dex.instructions.IndexInsnNode; import jadx.dex.instructions.IndexInsnNode;
...@@ -37,9 +38,10 @@ public class ModVisitor extends AbstractVisitor { ...@@ -37,9 +38,10 @@ public class ModVisitor extends AbstractVisitor {
return; return;
removeStep(mth); removeStep(mth);
replaceStep(mth); replaceStep(mth);
checkArgsNames(mth);
for (BlockNode block : mth.getBasicBlocks()) { for (BlockNode block : mth.getBasicBlocks()) {
processExceptionHander(mth, block); processExceptionHander(mth, block);
} }
...@@ -229,4 +231,14 @@ public class ModVisitor extends AbstractVisitor { ...@@ -229,4 +231,14 @@ public class ModVisitor extends AbstractVisitor {
replaceInsn(block, pos, newInsn); replaceInsn(block, pos, newInsn);
return true; return true;
} }
private void checkArgsNames(MethodNode mth) {
for(RegisterArg arg : mth.getArguments(false)) {
String name = arg.getTypedVar().getName();
if(name != null && NameMapper.isReserved(name)) {
name = name + "_" ;
arg.getTypedVar().setName(name);
}
}
}
} }
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