Describe the bug
it will produce wrong result when reassmbly if the method reuses local variable slot
To Reproduce
Steps to reproduce the behavior:
- Compile this code
import sun.misc.Unsafe;
import sun.reflect.ReflectionFactory;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
public class UnsafeUtility {
private UnsafeUtility() {
throw new UnsupportedOperationException();
}
public static final MethodHandles.Lookup TRUSTED_LOOKUP;
public static final Unsafe UNSAFE;
static {
{
MethodHandles.Lookup temp;
try {
Constructor<?> ctor = ReflectionFactory.getReflectionFactory()
.newConstructorForSerialization(MethodHandles.Lookup.class, MethodHandles.Lookup.class.getDeclaredConstructor(Class.class, Class.class, int.class));
temp = (MethodHandles.Lookup) ctor.newInstance(Object.class, null, -1);
} catch (ReflectiveOperationException e) {
temp = null;
}
TRUSTED_LOOKUP = temp;
}
{
Unsafe temp;
try {
Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe");
unsafeField.setAccessible(true);
temp = (Unsafe) unsafeField.get(null);
} catch (IllegalAccessException | NoSuchFieldException e) {
temp = null;
}
UNSAFE = temp;
}
}
}
- Drag and drop the class into recaf
- Assembly the method "<clinit>"
- Press "Ctrl + S"
Screenshots
Before:
After:
As we can see, normally the temp2 will be the UNSAFE's result, but it assembly as temp3.
Describe the bug
To Reproduce
Steps to reproduce the behavior:
Screenshots
Before:
After:
As we can see, normally the
temp2will be theUNSAFE's result, but it assembly astemp3.