Rewrite field inliner
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
package net.runelite.deob.deobfuscators;
|
package net.runelite.deob.deobfuscators;
|
||||||
|
|
||||||
|
import com.google.common.collect.HashMultimap;
|
||||||
|
import com.google.common.collect.Multimap;
|
||||||
import net.runelite.asm.ClassFile;
|
import net.runelite.asm.ClassFile;
|
||||||
import net.runelite.asm.ClassGroup;
|
import net.runelite.asm.ClassGroup;
|
||||||
import net.runelite.deob.Deobfuscator;
|
import net.runelite.deob.Deobfuscator;
|
||||||
@@ -18,13 +20,16 @@ import net.runelite.asm.attributes.code.instructions.LDC_W;
|
|||||||
import net.runelite.asm.attributes.code.instructions.NOP;
|
import net.runelite.asm.attributes.code.instructions.NOP;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction;
|
||||||
|
|
||||||
public class FieldInliner implements Deobfuscator
|
public class FieldInliner implements Deobfuscator
|
||||||
{
|
{
|
||||||
private ClassGroup group;
|
private ClassGroup group;
|
||||||
|
private Multimap<Field, FieldInstruction> fieldInstructions = HashMultimap.create();
|
||||||
private List<Field> fields = new ArrayList<>();
|
private List<Field> fields = new ArrayList<>();
|
||||||
|
|
||||||
private List<FieldInstruction> findFieldIns(Field field, boolean set)
|
private void findFieldIns()
|
||||||
{
|
{
|
||||||
List<FieldInstruction> ins = new ArrayList<>();
|
List<FieldInstruction> ins = new ArrayList<>();
|
||||||
|
|
||||||
@@ -44,18 +49,13 @@ public class FieldInliner implements Deobfuscator
|
|||||||
|
|
||||||
FieldInstruction sf = (FieldInstruction) i;
|
FieldInstruction sf = (FieldInstruction) i;
|
||||||
|
|
||||||
if (sf.getMyField() != field)
|
if (sf.getMyField() == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (sf instanceof SetFieldInstruction != set)
|
fieldInstructions.put(sf.getMyField(), sf);
|
||||||
continue;
|
|
||||||
|
|
||||||
ins.add(sf);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ins;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void makeConstantValues()
|
private void makeConstantValues()
|
||||||
@@ -71,8 +71,8 @@ public class FieldInliner implements Deobfuscator
|
|||||||
ConstantValue constantValue = (ConstantValue) attributes.findType(AttributeType.CONSTANT_VALUE);
|
ConstantValue constantValue = (ConstantValue) attributes.findType(AttributeType.CONSTANT_VALUE);
|
||||||
if (constantValue != null)
|
if (constantValue != null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
List<FieldInstruction> sfis = findFieldIns(f, true);
|
List<FieldInstruction> sfis = fieldInstructions.get(f).stream().filter(f2 -> f2 instanceof SetFieldInstruction).collect(Collectors.toList());
|
||||||
if (sfis.size() != 1)
|
if (sfis.size() != 1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -126,7 +126,7 @@ public class FieldInliner implements Deobfuscator
|
|||||||
for (Field f : fields)
|
for (Field f : fields)
|
||||||
{
|
{
|
||||||
// replace getfield with constant push
|
// replace getfield with constant push
|
||||||
List<FieldInstruction> fins = findFieldIns(f, false);
|
List<FieldInstruction> fins = fieldInstructions.get(f).stream().filter(f2 -> f2 instanceof GetFieldInstruction).collect(Collectors.toList());
|
||||||
ConstantValue value = (ConstantValue) f.getAttributes().findType(AttributeType.CONSTANT_VALUE);
|
ConstantValue value = (ConstantValue) f.getAttributes().findType(AttributeType.CONSTANT_VALUE);
|
||||||
|
|
||||||
for (FieldInstruction fin : fins)
|
for (FieldInstruction fin : fins)
|
||||||
@@ -161,6 +161,7 @@ public class FieldInliner implements Deobfuscator
|
|||||||
public void run(ClassGroup group)
|
public void run(ClassGroup group)
|
||||||
{
|
{
|
||||||
this.group = group;
|
this.group = group;
|
||||||
|
findFieldIns();
|
||||||
makeConstantValues();
|
makeConstantValues();
|
||||||
int count = inlineUse();
|
int count = inlineUse();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package net.runelite.deob.deobfuscators;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import net.runelite.asm.ClassGroup;
|
||||||
|
import net.runelite.deob.util.JarUtil;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.TemporaryFolder;
|
||||||
|
|
||||||
|
public class FieldInlinerTest
|
||||||
|
{
|
||||||
|
private static final File GAMEPACK = new File(RenameUniqueTest.class.getResource("/gamepack_v16.jar").getFile());
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public TemporaryFolder folder = new TemporaryFolder();
|
||||||
|
|
||||||
|
private ClassGroup group;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void before() throws IOException
|
||||||
|
{
|
||||||
|
group = JarUtil.loadJar(GAMEPACK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void after() throws IOException
|
||||||
|
{
|
||||||
|
JarUtil.saveJar(group, folder.newFile());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRun()
|
||||||
|
{
|
||||||
|
FieldInliner fi = new FieldInliner();
|
||||||
|
fi.run(group);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user