提交 6996f944 编写于 作者: S Skylot

mod: disable assign inline, force multi returns, disable inline into 'if' (#1184)

上级 2acc14b0
......@@ -740,11 +740,12 @@ public class BlockProcessor extends AbstractVisitor {
if (returnInsn == null) {
return false;
}
if (returnInsn.getArgsCount() == 1
&& exitBlock.getInstructions().size() == 1
&& !isReturnArgAssignInPred(preds, returnInsn)) {
return false;
}
// force multiple returns
// if (returnInsn.getArgsCount() == 1
// && exitBlock.getInstructions().size() == 1
// && !isReturnArgAssignInPred(preds, returnInsn)) {
// return false;
// }
boolean first = true;
for (BlockNode pred : preds) {
......
......@@ -392,30 +392,32 @@ public class IfMakerHelper {
List<InsnNode> forceInlineInsns = new ArrayList<>();
if (!insns.isEmpty()) {
// check that all instructions can be inlined
for (InsnNode insn : insns) {
RegisterArg res = insn.getResult();
if (res == null) {
pass = false;
break;
}
List<RegisterArg> useList = res.getSVar().getUseList();
int useCount = useList.size();
if (useCount == 0) {
// TODO?
pass = false;
break;
}
InsnArg arg = useList.get(0);
InsnNode usePlace = arg.getParentInsn();
if (!BlockUtils.blockContains(block, usePlace)
&& !BlockUtils.blockContains(next, usePlace)) {
pass = false;
break;
}
if (useCount > 1) {
forceInlineInsns.add(insn);
}
}
// for (InsnNode insn : insns) {
// RegisterArg res = insn.getResult();
// if (res == null) {
// pass = false;
// break;
// }
// List<RegisterArg> useList = res.getSVar().getUseList();
// int useCount = useList.size();
// if (useCount == 0) {
// // TODO?
// pass = false;
// break;
// }
// InsnArg arg = useList.get(0);
// InsnNode usePlace = arg.getParentInsn();
// if (!BlockUtils.blockContains(block, usePlace)
// && !BlockUtils.blockContains(next, usePlace)) {
// pass = false;
// break;
// }
// if (useCount > 1) {
// forceInlineInsns.add(insn);
// }
// }
// disable assign inlining
pass = false;
}
if (!pass) {
return null;
......
......@@ -104,6 +104,10 @@ public class CodeShrinkVisitor extends AbstractVisitor {
if (parentInsn != null && parentInsn.contains(AFlag.DONT_GENERATE)) {
return;
}
// don't inline vars into 'if'
if (parentInsn != null && parentInsn.getType() == InsnType.IF) {
return;
}
if (!assignInline && useArg.contains(AFlag.DONT_INLINE_CONST)) {
return;
}
......
package jadx.tests.integration.conditions;
import java.util.zip.ZipEntry;
import org.junit.jupiter.api.Test;
import jadx.tests.api.IntegrationTest;
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat;
public class TestAssignInlineNegative extends IntegrationTest {
@SuppressWarnings("ConstantConditions")
public static class TestCls {
public final ZipEntry test() {
ZipEntry nextEntry = getNextEntry();
if (nextEntry == null) {
return nextEntry;
}
String name = nextEntry.getName();
if (name == null) {
return nextEntry;
}
if (!name.contains("../") && !name.contains("..\\")) {
return nextEntry;
}
throw new SecurityException(":" + nextEntry.getName());
}
private ZipEntry getNextEntry() {
return null;
}
}
@Test
public void test() {
noDebugInfo();
assertThat(getClassNode(TestCls.class))
.code()
.doesNotContain("(name = nextEntry.getName()) == null")
.containsOne("if (name == null) {");
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册