Fix if field mapper to take static/class name into consideration

This commit is contained in:
Adam
2016-03-18 16:12:04 -04:00
parent a2fe796306
commit 4ea2d8d632
3 changed files with 51 additions and 24 deletions

View File

@@ -155,20 +155,6 @@ public abstract class If extends Instruction implements JumpingInstruction, Comp
f2.other = branch1;
branch1.other = f2;
// switch frame order in executor frame list
// Execution e = f1.getExecution(),
// e2 = f2.getExecution();
//
// int i = e2.frames.indexOf(f2),
// i2 = e2.frames.indexOf(branch2);
//
// e2.frames.remove(i);
// e2.frames.add(i, branch2);
//
// e2.frames.remove(i2);
// e2.frames.add(i2, f2);
this.mapArguments(mapping, ctx, other, true);
}
@@ -206,8 +192,20 @@ public abstract class If extends Instruction implements JumpingInstruction, Comp
Field f1 = f1s.get(0), f2 = f2s.get(0);
Field j1 = f1s.get(1), j2 = f2s.get(1);
mapping.map(f1, j2);
mapping.map(j1, f2);
assert !(couldBeSame(f1, f2) && couldBeSame(j1, j2) && couldBeSame(f1, j2) && couldBeSame(j1, f2));
if (couldBeSame(f1, f2) && couldBeSame(j1, j2))
{
mapping.map(f1, f2);
mapping.map(j1, f2);
}
if (couldBeSame(f1, j2) && couldBeSame(j1, f2))
{
mapping.map(f1, j2);
mapping.map(j1, f2);
}
}
else
assert false;
@@ -253,6 +251,18 @@ public abstract class If extends Instruction implements JumpingInstruction, Comp
return (Integer) gfi.getConstant().getObject();
}
private boolean couldBeSame(Field f1, Field f2)
{
if (f1.isStatic() != f2.isStatic())
return false;
if (!f1.isStatic())
if (!f1.getFields().getClassFile().getName().equals(f2.getFields().getClassFile().getName()))
return false;
return f1.getType().equals(f2.getType());
}
protected boolean isSameField(InstructionContext thisIc, InstructionContext otherIc)
{
List<Field> f1s = getComparedFields(thisIc), f2s = getComparedFields(otherIc);
@@ -272,15 +282,23 @@ public abstract class If extends Instruction implements JumpingInstruction, Comp
{
Field f1 = f1s.get(0), f2 = f2s.get(0);
Field j1 = f1s.get(1), j2 = f2s.get(1);
return (f1.getType().equals(f2.getType()) && j1.getType().equals(j2.getType())) ||
(f1.getType().equals(j2.getType()) && j1.getType().equals(f2.getType()));
if (couldBeSame(f1, f2) && couldBeSame(j1, j2) && couldBeSame(f1, j2) && couldBeSame(j1, f2))
return false; // ambiguous
if (couldBeSame(f1, f2) && couldBeSame(j1, j2))
return true;
if (couldBeSame(f1, j2) && couldBeSame(j1, f2))
return true;
return false;
}
else
{
Field f1 = f1s.get(0), f2 = f2s.get(0);
return f1.getType().equals(f2.getType());
return couldBeSame(f1, f2);
}
}

View File

@@ -20,7 +20,6 @@ import net.runelite.deob.attributes.code.instruction.types.GetFieldInstruction;
import net.runelite.deob.attributes.code.instruction.types.MappableInstruction;
import net.runelite.deob.deobfuscators.rename.MappingExecutorUtil;
import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping;
import net.runelite.deob.execution.Execution;
public abstract class If0 extends Instruction implements JumpingInstruction, ComparisonInstruction, MappableInstruction
{
@@ -202,6 +201,13 @@ public abstract class If0 extends Instruction implements JumpingInstruction, Com
if (f1 == null || f2 == null)
return true;
if (f1.isStatic() != f2.isStatic())
return false;
if (!f1.isStatic())
if (!f1.getFields().getClassFile().getName().equals(f2.getFields().getClassFile().getName()))
return false;
return f1.getType().equals(f2.getType());
}

View File

@@ -8,8 +8,9 @@ import org.junit.Test;
public class AnnotationMapperTest
{
private static final String JAR1 = MapStaticTest.class.getResource("/adamin1.jar").getFile(),
JAR2 = MapStaticTest.class.getResource("/adamin2.jar").getFile();
private static final String JAR1 = "C:\\Users\\Adam\\.m2\\repository\\net\\runelite\\rs\\rs-client\\1.0-SNAPSHOT\\rs-client-1.0-SNAPSHOT.jar",
JAR2 = "c:/rs/gamepack_v18_deobbed.jar",
OUT = "c:/rs/adamout.jar";
@Test
public void testRun() throws IOException
@@ -23,6 +24,8 @@ public class AnnotationMapperTest
AnnotationMapper amapper = new AnnotationMapper(group1, group2, mapping);
amapper.run();
JarUtil.saveJar(group2, new File(OUT));
}
}