Add tweakClass param. Define packages

This commit is contained in:
Lassebq 2023-03-29 01:56:45 +03:00
parent 424c6c2d64
commit 553baa7729
No known key found for this signature in database
GPG key ID: DE0866BB0C980B6E
14 changed files with 316 additions and 63 deletions

165
LICENSE Normal file
View file

@ -0,0 +1,165 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.

View file

@ -57,6 +57,7 @@ public class LaunchConfig {
public LaunchParameterFileList icon = new LaunchParameterFileList("icon", null, true);
public LaunchParameterString title = new LaunchParameterString("title", null, true);
public LaunchParameterSwitch oneSixFlag = new LaunchParameterSwitch("oneSixFlag", false, true);
public LaunchParameterString tweakClass = new LaunchParameterString("tweakClass", null, true);
public LaunchConfig() {
}

View file

@ -18,11 +18,16 @@ import org.mcphackers.launchwrapper.tweak.AppletWrapper;
import org.mcphackers.launchwrapper.util.Util;
/**
* DO NOT use this class under any circumstances. This class is meant to be initialized in the context of LaunchClassLoader
* DO NOT use this class under any circumstances. This class is meant to be
* initialized in the context of LaunchClassLoader
*
* @author Lassebq
*
*/
public class Inject {
public final class Inject {
private Inject() {
}
public static AppletWrapper getApplet() {
return new AppletWrapper(Launch.getConfig().getArgsAsMap());
}

View file

@ -18,8 +18,8 @@ import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import org.mcphackers.launchwrapper.inject.ClassNodeSource;
import org.mcphackers.launchwrapper.tweak.ClassLoaderTweak;
import org.mcphackers.launchwrapper.util.ClassNodeSource;
import org.mcphackers.launchwrapper.util.Util;
import org.mcphackers.rdi.util.NodeHelper;
import org.objectweb.asm.ClassReader;
@ -50,7 +50,7 @@ public class LaunchClassLoader extends URLClassLoader implements ClassNodeSource
public void setClassPath(URL[] urls) {
for(URL url : urls) {
super.addURL(url);
addURL(url);
}
}
@ -58,7 +58,7 @@ public class LaunchClassLoader extends URLClassLoader implements ClassNodeSource
debugOutput = directory;
}
protected void addURL(URL url) {
public void addURL(URL url) {
super.addURL(url);
}
@ -169,14 +169,19 @@ public class LaunchClassLoader extends URLClassLoader implements ClassNodeSource
if(node != null) {
return node;
}
byte[] classData = getClassAsBytes(name);
if(classData == null)
try {
InputStream is = getClassAsStream(name);
if(is == null) {
return null;
}
ClassNode classNode = new ClassNode();
ClassReader classReader = new ClassReader(is);
classReader.accept(classNode, 0);
classNodeCache.put(classNode.name, classNode);
return classNode;
} catch (IOException e) {
return null;
ClassNode classNode = new ClassNode();
ClassReader classReader = new ClassReader(classData);
classReader.accept(classNode, 0);
classNodeCache.put(classNode.name, classNode);
return classNode;
}
}
public FieldNode getField(String owner, String name, String desc) {
@ -187,18 +192,22 @@ public class LaunchClassLoader extends URLClassLoader implements ClassNodeSource
return NodeHelper.getMethod(getClass(owner), name, desc);
}
protected Class<?> redefineClass(String name) {
protected Class<?> redefineClass(String name) throws ClassNotFoundException {
ClassNode classNode = getClass(name);
if(classNode != null && tweak != null && tweak.tweakClass(classNode)) {
saveDebugClass(classNode);
return redefineClass(classNode);
}
byte[] classData = getClassAsBytes(name);
if(classData == null) {
return null;
try {
InputStream is = getClassAsStream(name);
if(is == null) {
throw new ClassNotFoundException(name);
}
byte[] classData = Util.readStream(is);
return defineClass(name, classData);
} catch (IOException e) {
throw new ClassNotFoundException(name, e);
}
Class<?> definedClass = defineClass(name, classData, 0, classData.length, getProtectionDomain(name));
return definedClass;
}
private Class<?> redefineClass(ClassNode node) {
@ -209,8 +218,7 @@ public class LaunchClassLoader extends URLClassLoader implements ClassNodeSource
node.accept(writer);
byte[] classData = writer.toByteArray();
String name = className(node.name);
Class<?> definedClass = defineClass(name, classData, 0, classData.length, getProtectionDomain(name));
return definedClass;
return defineClass(name, classData);
}
private static String className(String nameWithSlashes) {
@ -234,22 +242,7 @@ public class LaunchClassLoader extends URLClassLoader implements ClassNodeSource
return parent.getResourceAsStream(className);
}
private byte[] getClassAsBytes(String name) {
InputStream is = getClassAsStream(name);
if(is == null)
return null;
byte[] classData;
try {
classData = Util.readStream(is);
} catch (IOException e) {
Util.closeSilently(is);
return null;
}
Util.closeSilently(is);
return classData;
}
private Class<?> transformedClass(String name) {
private Class<?> transformedClass(String name) throws ClassNotFoundException {
ClassNode transformed = overridenClasses.get(name);
if(transformed != null) {
if(tweak != null) {
@ -267,6 +260,17 @@ public class LaunchClassLoader extends URLClassLoader implements ClassNodeSource
public void setLoaderTweak(ClassLoaderTweak classLoaderTweak) {
tweak = classLoaderTweak;
}
private Class<?> defineClass(String name, byte[] classData) {
int i = name.lastIndexOf('.');
if (i != -1) {
String pkgName = name.substring(0, i);
if(getPackage(pkgName) == null) {
definePackage(pkgName, null, null, null, null, null, null, null);
}
}
return defineClass(name, classData, 0, classData.length, getProtectionDomain(name));
}
private static ClassNode getSystemClass(Class<?> cls) {
InputStream is = ClassLoader.getSystemResourceAsStream(classResourceName(cls.getName()));

View file

@ -22,7 +22,7 @@ public class LegacyURLStreamHandler extends URLStreamHandlerProxy {
String path = url.getPath();
if(host.endsWith(".minecraft.net") || host.equals("s3.amazonaws.com")) {
if(path.equals("/game/joinserver.jsp"))
return new BasicResponseURLConnection(url, "ok");
return super.openConnection(new URL("http", "session.minecraft.net", path));
if(path.equals("/login/session.jsp"))
return new BasicResponseURLConnection(url, "ok");
if(host.equals("login.minecraft.net") && path.equals("/session"))

View file

@ -1,6 +1,6 @@
package org.mcphackers.launchwrapper.tweak;
import static org.mcphackers.launchwrapper.inject.InsnHelper.getLastReturn;
import static org.mcphackers.launchwrapper.util.InsnHelper.getLastReturn;
import static org.objectweb.asm.Opcodes.*;
import java.io.IOException;
@ -11,7 +11,7 @@ import org.mcphackers.launchwrapper.AppletLaunchTarget;
import org.mcphackers.launchwrapper.Launch;
import org.mcphackers.launchwrapper.LaunchConfig;
import org.mcphackers.launchwrapper.LaunchTarget;
import org.mcphackers.launchwrapper.inject.ClassNodeSource;
import org.mcphackers.launchwrapper.util.ClassNodeSource;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.FieldNode;

View file

@ -1,6 +1,6 @@
package org.mcphackers.launchwrapper.tweak;
import static org.mcphackers.launchwrapper.inject.InsnHelper.compareInsn;
import static org.mcphackers.launchwrapper.util.InsnHelper.compareInsn;
import static org.mcphackers.rdi.util.InsnHelper.*;
import static org.objectweb.asm.Opcodes.*;

View file

@ -1,6 +1,6 @@
package org.mcphackers.launchwrapper.tweak;
import static org.mcphackers.launchwrapper.inject.InsnHelper.*;
import static org.mcphackers.launchwrapper.util.InsnHelper.*;
import static org.mcphackers.rdi.util.InsnHelper.*;
import static org.objectweb.asm.Opcodes.*;
@ -14,10 +14,10 @@ import java.net.URL;
import org.mcphackers.launchwrapper.LaunchConfig;
import org.mcphackers.launchwrapper.LaunchTarget;
import org.mcphackers.launchwrapper.MainLaunchTarget;
import org.mcphackers.launchwrapper.inject.ClassNodeSource;
import org.mcphackers.launchwrapper.protocol.LegacyURLStreamHandler;
import org.mcphackers.launchwrapper.protocol.SkinType;
import org.mcphackers.launchwrapper.protocol.URLStreamHandlerProxy;
import org.mcphackers.launchwrapper.util.ClassNodeSource;
import org.mcphackers.launchwrapper.util.UnsafeUtils;
import org.mcphackers.launchwrapper.util.Util;
import org.mcphackers.rdi.injector.data.Access;
@ -42,8 +42,6 @@ import org.objectweb.asm.tree.VarInsnNode;
public class LegacyTweak extends Tweak {
protected LaunchConfig launch;
public static final String[] MAIN_CLASSES = {
"net/minecraft/client/Minecraft",
"com/mojang/minecraft/Minecraft",
@ -81,8 +79,7 @@ public class LegacyTweak extends Tweak {
private boolean classic;
public LegacyTweak(ClassNodeSource source, LaunchConfig launch) {
super(source);
this.launch = launch;
super(source, launch);
}
public boolean transform() {
@ -731,6 +728,7 @@ public class LegacyTweak extends Tweak {
Field userRequested = mergeSort.getDeclaredField("userRequested");
UnsafeUtils.setStaticBoolean(userRequested, true);
} catch (ClassNotFoundException e) {
} catch (SecurityException e) {
} catch (Exception e) {
e.printStackTrace();
}
@ -1193,13 +1191,6 @@ public class LegacyTweak extends Tweak {
insns.add(new VarInsnNode(ALOAD, appletIndex));
insns.add(new LdcInsnNode("Center"));
insns.add(new MethodInsnNode(INVOKEVIRTUAL, "java/awt/Frame", "add", "(Ljava/awt/Component;Ljava/lang/Object;)V"));
insns.add(new VarInsnNode(ALOAD, appletIndex));
insns.add(new TypeInsnNode(NEW, "java/awt/Dimension"));
insns.add(new InsnNode(DUP));
insns.add(intInsn(launch.width.get()));
insns.add(intInsn(launch.height.get()));
insns.add(new MethodInsnNode(INVOKESPECIAL, "java/awt/Dimension", "<init>", "(II)V"));
insns.add(new MethodInsnNode(INVOKEVIRTUAL, "java/awt/Component", "setPreferredSize", "(Ljava/awt/Dimension;)V"));
insns.add(new VarInsnNode(ALOAD, frameIndex));
insns.add(new MethodInsnNode(INVOKEVIRTUAL, "java/awt/Frame", "pack", "()V"));
insns.add(new VarInsnNode(ALOAD, frameIndex));
@ -1292,6 +1283,16 @@ public class LegacyTweak extends Tweak {
AbstractInsnNode[] insns2 = fill(insn, 6);
if(compareInsn(insns2[1], PUTFIELD, minecraftApplet.name, mcField, mcDesc)
&& compareInsn(insns2[0], INVOKESPECIAL, null, "<init>")) {
InsnList insns = new InsnList();
insns.add(new VarInsnNode(ALOAD, 0));
insns.add(new FieldInsnNode(GETFIELD, minecraftApplet.name, canvasField, "Ljava/awt/Canvas;"));
insns.add(new TypeInsnNode(NEW, "java/awt/Dimension"));
insns.add(new InsnNode(DUP));
insns.add(intInsn(launch.width.get()));
insns.add(intInsn(launch.height.get()));
insns.add(new MethodInsnNode(INVOKESPECIAL, "java/awt/Dimension", "<init>", "(II)V"));
insns.add(new MethodInsnNode(INVOKEVIRTUAL, "java/awt/Canvas", "setPreferredSize", "(Ljava/awt/Dimension;)V"));
init.instructions.insert(insns2[1], insns);
MethodInsnNode invoke = (MethodInsnNode) insns2[0];
init.instructions.insertBefore(insns2[1], getNewMinecraftImpl(source.getClass(invoke.owner), canvasField));
IdentifyCall call = new IdentifyCall(invoke);

View file

@ -2,17 +2,19 @@ package org.mcphackers.launchwrapper.tweak;
import org.mcphackers.launchwrapper.LaunchConfig;
import org.mcphackers.launchwrapper.LaunchTarget;
import org.mcphackers.launchwrapper.inject.ClassNodeSource;
import org.mcphackers.launchwrapper.loader.LaunchClassLoader;
import org.mcphackers.launchwrapper.util.ClassNodeSource;
public abstract class Tweak {
private static final boolean DEBUG = false;
protected ClassNodeSource source;
protected LaunchConfig launch;
public Tweak(ClassNodeSource source) {
public Tweak(ClassNodeSource source, LaunchConfig launch) {
this.source = source;
this.launch = launch;
}
public abstract boolean transform();
@ -30,6 +32,17 @@ public abstract class Tweak {
}
private static Tweak getTweak(LaunchClassLoader classLoader, LaunchConfig launch) {
if(launch.tweakClass.get() != null) {
try {
return (Tweak)Class.forName(launch.tweakClass.get())
.getConstructor(ClassNodeSource.class, LaunchConfig.class)
.newInstance(classLoader, launch);
} catch (ClassNotFoundException e) {
return null;
} catch (Exception e) {
e.printStackTrace();
}
}
if(launch.isom.get()) {
return new IsomTweak(classLoader, launch);
}

View file

@ -1,6 +1,6 @@
package org.mcphackers.launchwrapper.tweak;
import static org.mcphackers.launchwrapper.inject.InsnHelper.compareInsn;
import static org.mcphackers.launchwrapper.util.InsnHelper.compareInsn;
import static org.mcphackers.rdi.util.InsnHelper.*;
import static org.objectweb.asm.Opcodes.*;
@ -12,9 +12,9 @@ import org.mcphackers.launchwrapper.LaunchConfig;
import org.mcphackers.launchwrapper.LaunchConfig.LaunchParameter;
import org.mcphackers.launchwrapper.LaunchTarget;
import org.mcphackers.launchwrapper.MainLaunchTarget;
import org.mcphackers.launchwrapper.inject.ClassNodeSource;
import org.mcphackers.launchwrapper.protocol.LegacyURLStreamHandler;
import org.mcphackers.launchwrapper.protocol.URLStreamHandlerProxy;
import org.mcphackers.launchwrapper.util.ClassNodeSource;
import org.mcphackers.rdi.util.IdentifyCall;
import org.mcphackers.rdi.util.NodeHelper;
import org.objectweb.asm.tree.AbstractInsnNode;
@ -29,15 +29,13 @@ import org.objectweb.asm.tree.TypeInsnNode;
public class VanillaTweak extends Tweak {
public static final String MAIN_CLASS = "net/minecraft/client/main/Main";
protected LaunchConfig launch;
protected ClassNode minecraftMain;
protected ClassNode minecraft;
protected MethodNode run;
private List<String> availableParameters = new ArrayList<String>();
public VanillaTweak(ClassNodeSource source, LaunchConfig launch) {
super(source);
this.launch = launch;
super(source, launch);
}
public boolean transform() {

View file

@ -1,4 +1,4 @@
package org.mcphackers.launchwrapper.inject;
package org.mcphackers.launchwrapper.util;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldNode;

View file

@ -1,4 +1,4 @@
package org.mcphackers.launchwrapper.inject;
package org.mcphackers.launchwrapper.util;
import static org.objectweb.asm.Opcodes.*;
import static org.objectweb.asm.tree.AbstractInsnNode.*;

View file

@ -27,6 +27,24 @@ public final class UnsafeUtils {
theUnsafe.putBoolean(staticFieldBase, staticFieldOffset, value);
}
public static void setStaticByte(final Field field, byte value) {
final Object staticFieldBase = theUnsafe.staticFieldBase(field);
final long staticFieldOffset = theUnsafe.staticFieldOffset(field);
theUnsafe.putByte(staticFieldBase, staticFieldOffset, value);
}
public static void setStaticShort(final Field field, short value) {
final Object staticFieldBase = theUnsafe.staticFieldBase(field);
final long staticFieldOffset = theUnsafe.staticFieldOffset(field);
theUnsafe.putShort(staticFieldBase, staticFieldOffset, value);
}
public static void setStaticChar(final Field field, char value) {
final Object staticFieldBase = theUnsafe.staticFieldBase(field);
final long staticFieldOffset = theUnsafe.staticFieldOffset(field);
theUnsafe.putChar(staticFieldBase, staticFieldOffset, value);
}
public static void setStaticInt(final Field field, int value) {
final Object staticFieldBase = theUnsafe.staticFieldBase(field);
final long staticFieldOffset = theUnsafe.staticFieldOffset(field);
@ -64,6 +82,21 @@ public final class UnsafeUtils {
theUnsafe.putBoolean(base, staticFieldOffset, value);
}
public static void setByte(final Object base, final Field field, byte value) {
final long staticFieldOffset = theUnsafe.staticFieldOffset(field);
theUnsafe.putByte(base, staticFieldOffset, value);
}
public static void setShort(final Object base, final Field field, short value) {
final long staticFieldOffset = theUnsafe.staticFieldOffset(field);
theUnsafe.putShort(base, staticFieldOffset, value);
}
public static void setChar(final Object base, final Field field, char value) {
final long staticFieldOffset = theUnsafe.staticFieldOffset(field);
theUnsafe.putChar(base, staticFieldOffset, value);
}
public static void setInt(final Object base, final Field field, int value) {
final long staticFieldOffset = theUnsafe.staticFieldOffset(field);
theUnsafe.putInt(base, staticFieldOffset, value);
@ -97,6 +130,24 @@ public final class UnsafeUtils {
return theUnsafe.getBoolean(staticFieldBase, staticFieldOffset);
}
public static byte getStaticByte(final Field field) {
final Object staticFieldBase = theUnsafe.staticFieldBase(field);
final long staticFieldOffset = theUnsafe.staticFieldOffset(field);
return theUnsafe.getByte(staticFieldBase, staticFieldOffset);
}
public static short getStaticShort(final Field field) {
final Object staticFieldBase = theUnsafe.staticFieldBase(field);
final long staticFieldOffset = theUnsafe.staticFieldOffset(field);
return theUnsafe.getShort(staticFieldBase, staticFieldOffset);
}
public static char getStaticChar(final Field field) {
final Object staticFieldBase = theUnsafe.staticFieldBase(field);
final long staticFieldOffset = theUnsafe.staticFieldOffset(field);
return theUnsafe.getChar(staticFieldBase, staticFieldOffset);
}
public static int getStaticInt(final Field field) {
final Object staticFieldBase = theUnsafe.staticFieldBase(field);
final long staticFieldOffset = theUnsafe.staticFieldOffset(field);
@ -134,6 +185,21 @@ public final class UnsafeUtils {
return theUnsafe.getBoolean(base, fieldOffset);
}
public static byte getByte(final Object base, final Field field) {
final long staticFieldOffset = theUnsafe.staticFieldOffset(field);
return theUnsafe.getByte(base, staticFieldOffset);
}
public static short getShort(final Object base, final Field field) {
final long staticFieldOffset = theUnsafe.staticFieldOffset(field);
return theUnsafe.getShort(base, staticFieldOffset);
}
public static char getChar(final Object base, final Field field) {
final long staticFieldOffset = theUnsafe.staticFieldOffset(field);
return theUnsafe.getChar(base, staticFieldOffset);
}
public static int getInt(final Object base, final Field field) {
final long fieldOffset = theUnsafe.objectFieldOffset(field);
return theUnsafe.getInt(base, fieldOffset);

View file

@ -34,7 +34,7 @@ public final class Util {
while((nRead = stream.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, nRead);
}
stream.close();
return buffer.toByteArray();
}