提交 ccb8ed13 编写于 作者: S Skylot

fix: add assign for inlined getter methods

上级 8d68d409
......@@ -40,6 +40,7 @@ import jadx.core.dex.instructions.args.InsnArg;
import jadx.core.dex.instructions.args.InsnWrapArg;
import jadx.core.dex.instructions.args.LiteralArg;
import jadx.core.dex.instructions.args.Named;
import jadx.core.dex.instructions.args.NamedArg;
import jadx.core.dex.instructions.args.RegisterArg;
import jadx.core.dex.instructions.args.SSAVar;
import jadx.core.dex.instructions.mods.ConstructorInsn;
......@@ -874,6 +875,13 @@ public class InsnGen {
if (Consts.DEBUG) {
code.add("/* inline method: ").add(callMthNode.toString()).add("*/").startLine();
}
if (forceAssign(inl, insn, callMthNode)) {
ArgType varType = callMthNode.getReturnType();
useType(code, varType);
code.add(' ');
code.add(mgen.getNameGen().assignNamedArg(new NamedArg("unused", varType)));
code.add(" = ");
}
if (callMthNode.getMethodInfo().getArgumentsTypes().isEmpty()) {
makeInsn(inl, code, Flags.BODY_ONLY);
} else {
......@@ -907,6 +915,19 @@ public class InsnGen {
return true;
}
private boolean forceAssign(InsnNode inlineInsn, InvokeNode parentInsn, MethodNode callMthNode) {
if (parentInsn.getResult() != null) {
return false;
}
if (parentInsn.contains(AFlag.WRAPPED)) {
return false;
}
if (callMthNode.getReturnType().equals(ArgType.VOID)) {
return false;
}
return true;
}
private void makeTernary(TernaryInsn insn, CodeWriter code, Set<Flags> state) throws CodegenException {
boolean wrap = state.contains(Flags.BODY_ONLY);
if (wrap) {
......
package jadx.tests.integration.inline;
import org.junit.jupiter.api.Test;
import jadx.core.dex.nodes.ClassNode;
import jadx.tests.api.SmaliTest;
import static jadx.tests.api.utils.JadxMatchers.containsOne;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
public class TestGetterInlineNegative extends SmaliTest {
// @formatter:off
/*
public class TestGetterInlineNegative {
public static final String field = "some string";
public static synthetic String getter() {
return field;
}
public void test() {
getter(); // inline will produce 'field;' and fail to compile with 'not a statement' error
}
public String test2() {
return getter();
}
}
*/
// @formatter:on
@Test
public void test() {
ClassNode cls = getClassNodeFromSmali();
String code = cls.getCode().toString();
assertThat(code, not(containsString(indent() + "field;")));
assertThat(code, containsOne("return field;"));
}
}
.class public Linline/TestGetterInlineNegative;
.super Ljava/lang/Object;
.field public static final field:Ljava/lang/String; = "some string"
.method public static synthetic getter()Ljava/lang/String;
.locals 1
sget-object v0, Linline/TestGetterInlineNegative;->field:Ljava/lang/String;
return-object v0
.end method
.method public test()V
.locals 1
invoke-static {}, Linline/TestGetterInlineNegative;->getter()Ljava/lang/String;
return-void
.end method
.method public test2()Ljava/lang/String;
.locals 2
invoke-static {}, Linline/TestGetterInlineNegative;->getter()Ljava/lang/String;
move-result-object v1
return-object v1
.end method
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册