本文整理匯總了Java中org.objectweb.asm.commons.GeneratorAdapter.returnValue方法的典型用法代碼示例。如果您正苦於以下問題:Java GeneratorAdapter.returnValue方法的具體用法?Java GeneratorAdapter.returnValue怎麽用?Java GeneratorAdapter.returnValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.objectweb.asm.commons.GeneratorAdapter
的用法示例。
在下文中一共展示了GeneratorAdapter.returnValue方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: visitEnd
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
public void visitEnd() {
if (! doneAddField) {
doneAddField = true;
super.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, CLASS_FIELD, Type.getDescriptor(Agent.class), null, null);
}
if (! doneAddMethod) {
doneAddMethod = true;
GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, new Method(LOG_CLASS_METHOD, LOG_CLASS_SIGNATURE), LOG_CLASS_SIGNATURE, new Type[] {}, this);
Label target = mg.newLabel();
mg.getStatic(JAVA_LANG_SYSTEM_TYPE, CLASS_FIELD, JAVA_LANG_CLASS_TYPE);
mg.ifNull(target);
mg.push(LOG_INTERNAL_TYPE);
mg.putStatic(JAVA_LANG_SYSTEM_TYPE, CLASS_FIELD, JAVA_LANG_CLASS_TYPE);
mg.mark(target);
mg.getStatic(JAVA_LANG_SYSTEM_TYPE, CLASS_FIELD, JAVA_LANG_CLASS_TYPE);
mg.returnValue();
}
super.visitEnd();
}
示例2: visitEnd
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public void visitEnd() {
if (!done && found) {
done = true;
try {
GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, new Method(LOG_INTERNAL_METHOD, LOG_METHOD_SIGNATURE), LOG_METHOD_SIGNATURE, new Type[] {}, this);
Label start = mg.mark();
mg.invokeStatic(LOG_INTERNAL_TYPE, Method.getMethod(LOG_INTERNAL_CLASS.getMethod(LOG_METHOD_NAME)));
mg.returnValue();
Label end = mg.mark();
mg.catchException(start, end, JAVA_LANG_THROWABLE_TYPE);
mg.returnValue();
mg.endMethod();
} catch (NoSuchMethodException nsme) {
System.err.println("Unable to find Agent.rlogCallChain method");
System.err.println("M:"+nsme);
nsme.printStackTrace();
}
}
super.visitEnd();
}
示例3: visitEnd
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public void visitEnd() {
if (!foundClinit && instrument()) {
// didn't find <clinit> so lets make one
try {
GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, new Method(CLINIT_NAME, CLINIT_SIGNATURE), CLINIT_SIGNATURE, new Type[] {}, this);
Label start = mg.mark();
mg.push(className);
mg.invokeStatic(LOG_INTERNAL_TYPE, Method.getMethod(LOG_INTERNAL_CLASS.getMethod(LOG_METHOD_NAME, String.class)));
Label end = mg.mark();
mg.returnValue();
mg.catchException(start, end, JAVA_LANG_THROWABLE_TYPE);
mg.returnValue();
mg.endMethod();
} catch (NoSuchMethodException nsme) {
System.out.println("Unable to find Agent.reportClass method");
}
}
super.visitEnd();
}
示例4: redirect
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
/**
* Adds the instructions to do a generic redirection.
*/
protected void redirect(GeneratorAdapter mv, int change) {
// code to check if a new implementation of the current class is available.
Label l0 = new Label();
mv.loadLocal(change);
mv.visitJumpInsn(Opcodes.IFNULL, l0);
doRedirect(mv, change);
// Return
if (type == Type.VOID_TYPE) {
mv.pop();
} else {
ByteCodeUtils.unbox(mv, type);
}
mv.returnValue();
// jump label for classes without any new implementation, just invoke the original
// method implementation.
mv.visitLabel(l0);
}
示例5: emitMethods
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
protected void emitMethods(ClassVisitor cv){
//override of invoke/doInvoke for each method
for(ISeq s = RT.seq(methods); s != null; s = s.next())
{
ObjMethod method = (ObjMethod) s.first();
method.emit(this, cv);
}
if(isVariadic())
{
GeneratorAdapter gen = new GeneratorAdapter(ACC_PUBLIC,
Method.getMethod("int getRequiredArity()"),
null,
null,
cv);
gen.visitCode();
gen.push(variadicMethod.reqParms.count());
gen.returnValue();
gen.endMethod();
}
}
示例6: doEmit
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
public void doEmit(ObjExpr fn, ClassVisitor cv){
Method m = new Method(getMethodName(), getReturnType(), getArgTypes());
GeneratorAdapter gen = new GeneratorAdapter(ACC_PUBLIC,
m,
null,
//todo don't hardwire this
EXCEPTION_TYPES,
cv);
gen.visitCode();
Label loopLabel = gen.mark();
gen.visitLineNumber(line, loopLabel);
try
{
Var.pushThreadBindings(RT.map(LOOP_LABEL, loopLabel, METHOD, this));
body.emit(C.RETURN, fn, gen);
Label end = gen.mark();
gen.visitLocalVariable("this", "Ljava/lang/Object;", null, loopLabel, end, 0);
for(ISeq lbs = argLocals.seq(); lbs != null; lbs = lbs.next())
{
LocalBinding lb = (LocalBinding) lbs.first();
gen.visitLocalVariable(lb.name, "Ljava/lang/Object;", null, loopLabel, end, lb.idx);
}
}
finally
{
Var.popThreadBindings();
}
gen.returnValue();
//gen.visitMaxs(1, 1);
gen.endMethod();
}
示例7: emit
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
public void emit(ObjExpr fn, ClassVisitor cv){
Method m = new Method(getMethodName(), getReturnType(), getArgTypes());
GeneratorAdapter gen = new GeneratorAdapter(ACC_PUBLIC,
m,
null,
//todo don't hardwire this
EXCEPTION_TYPES,
cv);
gen.visitCode();
Label loopLabel = gen.mark();
gen.visitLineNumber(line, loopLabel);
try
{
Var.pushThreadBindings(RT.map(LOOP_LABEL, loopLabel, METHOD, this));
body.emit(C.RETURN, fn, gen);
Label end = gen.mark();
gen.visitLocalVariable("this", "Ljava/lang/Object;", null, loopLabel, end, 0);
for(ISeq lbs = argLocals.seq(); lbs != null; lbs = lbs.next())
{
LocalBinding lb = (LocalBinding) lbs.first();
gen.visitLocalVariable(lb.name, "Ljava/lang/Object;", null, loopLabel, end, lb.idx);
}
}
finally
{
Var.popThreadBindings();
}
gen.returnValue();
//gen.visitMaxs(1, 1);
gen.endMethod();
}
示例8: generateMethodProxy
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
@Contract("null, null, null, null, null, null, null, null, _, _ -> fail")
static void generateMethodProxy(ClassVisitor cv, Method interfaceMethod,
Type reflectorClass, Type targetClass, Type interfaceClass,
String targetMethodName, Type[] targetParameters, Type targetReturnType,
int flags, int mhIndex) {
String methodName = interfaceMethod.getName();
String methodDesc = Type.getMethodDescriptor(interfaceMethod);
MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, methodName, methodDesc, null, null);
GeneratorAdapter adapter = new GeneratorAdapter(mv, ACC_PUBLIC, methodName, methodDesc);
adapter.visitCode();
/* Load MethodHandle, if required */
loadMH(adapter, reflectorClass, flags, mhIndex);
/* Load instance, if required */
loadInstance(adapter, reflectorClass, targetClass, flags);
/* Load method parameters into stack */
loadArguments(adapter, Type.getArgumentTypes(interfaceMethod), targetParameters, (flags & Magic.TARGET_CLASS_VISIBILITY_PUBLIC) != 0);
if((flags & Magic.REFLECTOR_METHOD_USE_METHODHANDLE) != 0) {
/* Build MethodHandle descriptor (invokeExact is polymorphic) */
String mhDescriptor = convertDesc(targetParameters,
((flags & Magic.RETURN_TYPE_PUBLIC) != 0 ? targetReturnType : OBJECT),
(flags & Magic.REFLECTOR_METHOD_USE_INSTANCE) != 0 ? ((flags & Magic.TARGET_CLASS_VISIBILITY_PUBLIC) != 0 ? targetClass : OBJECT) : null);
/* Select right MethodHandle invoker */
String mhInvoker = (flags & Magic.TARGET_CLASS_VISIBILITY_PUBLIC) != 0 && (flags & Magic.RETURN_TYPE_PUBLIC) != 0 ? "invokeExact" : "invoke";
/* Invoke MethodHandle */
mv.visitMethodInsn(INVOKEVIRTUAL, MH.getInternalName(), mhInvoker, mhDescriptor, false);
} else {
/* Figure out what opcode to use */
int opCode = (flags & Magic.REFLECTOR_METHOD_USE_INVOKEINTERFACE) != 0 ?
((flags & Magic.REFLECTOR_METHOD_USE_INSTANCE) != 0 ? INVOKEINTERFACE : INVOKESTATIC)
:
((flags & Magic.REFLECTOR_METHOD_USE_INSTANCE) != 0 ? INVOKEVIRTUAL : INVOKESTATIC);
/* Build descriptor & select target class */
String targetDescriptor = convertDesc(targetParameters, targetReturnType, null);
String targetName = (flags & Magic.REFLECTOR_METHOD_USE_INVOKEINTERFACE) != 0 ? interfaceClass.getInternalName() : targetClass.getInternalName();
/* Invoke method */
adapter.visitMethodInsn(opCode, targetName, targetMethodName, targetDescriptor, (flags & Magic.REFLECTOR_METHOD_USE_INVOKEINTERFACE) != 0);
}
/* Return */
handleReturn(adapter, interfaceMethod, targetReturnType);
adapter.returnValue();
/* End method */
adapter.endMethod();
}
示例9: generateConstructorProxy
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
@Contract("null, null, null, null, null, _, _ -> fail")
static void generateConstructorProxy(ClassVisitor cv, Method interfaceMethod,
Type reflectorClass, Type targetClass,
Type[] targetParameters,
int flags, int mhIndex) {
String methodName = interfaceMethod.getName();
String methodDesc = Type.getMethodDescriptor(interfaceMethod);
String targetClassName = targetClass.getInternalName();
MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, methodName, methodDesc, null, null);
GeneratorAdapter adapter = new GeneratorAdapter(mv, ACC_PUBLIC, methodName, methodDesc);
adapter.visitCode();
/* Load MethodHandle, if required */
loadMH(adapter, reflectorClass, flags, mhIndex);
if((flags & Magic.REFLECTOR_METHOD_USE_METHODHANDLE) == 0) {
adapter.visitTypeInsn(NEW, targetClassName);
adapter.visitInsn(DUP);
}
/* Load method parameters into stack */
loadArguments(adapter, Type.getArgumentTypes(interfaceMethod), targetParameters, (flags & Magic.RETURN_TYPE_PUBLIC) != 0);
if((flags & Magic.REFLECTOR_METHOD_USE_METHODHANDLE) != 0) {
/* Build MethodHandle descriptor */
String mhDescriptor = convertDesc(targetParameters,
(flags & Magic.RETURN_TYPE_PUBLIC) != 0 ? targetClass : OBJECT, null);
/* Select right MethodHandle invoker */
String mhInvoker = (flags & Magic.RETURN_TYPE_PUBLIC) != 0 ? "invokeExact" : "invoke";
/* Invoke MethodHandle */
mv.visitMethodInsn(INVOKEVIRTUAL, MH.getInternalName(), mhInvoker, mhDescriptor, false);
} else {
/* Build target descriptor */
String targetDesc = convertDesc(targetParameters, Type.VOID_TYPE, null);
/* Invoke constructor */
adapter.visitMethodInsn(INVOKESPECIAL, targetClassName, "<init>", targetDesc, false);
}
/* Return */
handleReturn(adapter, interfaceMethod, (flags & Magic.RETURN_TYPE_PUBLIC) != 0 ? targetClass : OBJECT);
adapter.returnValue();
/* End method */
adapter.endMethod();
}
示例10: generateFieldReadMethod
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
@Contract("null, null, null, null, null, null, _, _ -> fail")
static void generateFieldReadMethod(ClassVisitor cv, Method interfaceMethod,
Type reflectorClass, Type targetClass, Type fieldType, String fieldName,
int flags, int mhIndex) {
String methodName = interfaceMethod.getName();
String methodDesc = Type.getMethodDescriptor(interfaceMethod);
MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, methodName, methodDesc, null, null);
GeneratorAdapter adapter = new GeneratorAdapter(mv, ACC_PUBLIC, methodName, methodDesc);
adapter.visitCode();
/* Load MethodHandle, if required */
loadMH(adapter, reflectorClass, flags, mhIndex);
/* Load instance, if required */
loadInstance(adapter, reflectorClass, targetClass, flags);
if((flags & Magic.REFLECTOR_METHOD_USE_METHODHANDLE) != 0) {
/* Build MethodHandle descriptor */
String mhDescriptor = newDescriptor()
.accepts((flags & Magic.REFLECTOR_METHOD_USE_INSTANCE) != 0 ? ((flags & Magic.TARGET_CLASS_VISIBILITY_PUBLIC) != 0 ? targetClass : OBJECT).getDescriptor() : "")
.returns(fieldType.getDescriptor())
.toString();
/* Select right MethodHandle invoker */
String mhInvoker = (flags & Magic.TARGET_CLASS_VISIBILITY_PUBLIC) != 0 && (flags & Magic.RETURN_TYPE_PUBLIC) != 0 ? "invokeExact" : "invoke";
/* Invoke MethodHandle */
adapter.visitMethodInsn(INVOKEVIRTUAL, MH.getInternalName(), mhInvoker, mhDescriptor, false);
} else {
if((flags & Magic.REFLECTOR_METHOD_USE_INSTANCE) != 0)
adapter.getField(targetClass, fieldName, fieldType);
else
adapter.getStatic(targetClass, fieldName, fieldType);
}
/* Return */
handleReturn(adapter, interfaceMethod, fieldType);
adapter.returnValue();
/* End method */
adapter.endMethod();
}
示例11: generateFieldWriteMethod
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
@Contract("null, null, null, null, null, null, _, _ -> fail")
static void generateFieldWriteMethod(ClassVisitor cv, Method interfaceMethod,
Type reflectorClass, Type targetClass, Type fieldType, String fieldName,
int flags, int mhIndex) {
String methodName = interfaceMethod.getName();
String methodDesc = Type.getMethodDescriptor(interfaceMethod);
MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, methodName, methodDesc, null, null);
GeneratorAdapter adapter = new GeneratorAdapter(mv, ACC_PUBLIC, methodName, methodDesc);
adapter.visitCode();
/* Load MethodHandle, if required */
loadMH(adapter, reflectorClass, flags, mhIndex);
/* Load instance, if required */
loadInstance(adapter, reflectorClass, targetClass, flags);
/* Load method parameter into stack */
adapter.loadArg(0);
if((flags & Magic.REFLECTOR_METHOD_USE_METHODHANDLE) != 0) {
/* Build MethodHandle descriptor */
String mhDescriptor = newDescriptor()
.accepts(((flags & Magic.REFLECTOR_METHOD_USE_INSTANCE) != 0 ?
((flags & Magic.TARGET_CLASS_VISIBILITY_PUBLIC) != 0 ? targetClass : OBJECT).getDescriptor(): "")
+ fieldType.getDescriptor())
.toString();
/* Select right MethodHandle invoker */
String mhInvoker = (flags & Magic.TARGET_CLASS_VISIBILITY_PUBLIC) != 0 && (flags & Magic.RETURN_TYPE_PUBLIC) != 0 ? "invokeExact" : "invoke";
/* Invoke MethodHandle */
adapter.visitMethodInsn(INVOKEVIRTUAL, MH.getInternalName(), mhInvoker, mhDescriptor, false);
} else {
if((flags & Magic.REFLECTOR_METHOD_USE_INSTANCE) != 0)
adapter.putField(targetClass, fieldName, fieldType);
else
adapter.putStatic(targetClass, fieldName, fieldType);
}
/* Return */
adapter.returnValue();
/* End method */
adapter.endMethod();
}
示例12: transform
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
@Override
@Unsafe(Unsafe.ASM_API)
public byte[] transform(String name, String transformedName, byte[] basicClass) {
String srgName = this.srgName;
if (!AlchemyEngine.isRuntimeDeobfuscationEnabled())
srgName = DeobfuscatingRemapper.instance().mapMethodName(transformedName, this.srgName, desc);
AlchemyTransformerManager.transform("<proxy>" + name + "|" + transformedName + "#" + proxyMethod.name + proxyMethod.signature
+ "\n-> " + target + "#" + srgName + desc);
ClassReader reader = new ClassReader(basicClass);
ClassWriter writer = ASMHelper.newClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
ClassNode node = new ClassNode(ASM5);
reader.accept(node, 0);
MethodNode oldMethod = null, newMethod = new MethodNode(proxyMethod.access, proxyMethod.name, proxyMethod.desc, proxyMethod.signature,
proxyMethod.exceptions.toArray(new String[proxyMethod.exceptions.size()]));
for (MethodNode method : node.methods)
if (method.name.equals(proxyMethod.name) && method.desc.equals(proxyMethod.desc)) {
oldMethod = method;
GeneratorAdapter adapter = new GeneratorAdapter(newMethod, method.access, method.name, method.desc);
Type owner = Type.getType(ASMHelper.getClassDesc(target));
Method targetMethod = new Method(srgName, desc);
switch (opcode) {
case INVOKESTATIC:
adapter.loadArgs();
adapter.invokeStatic(owner, targetMethod);
break;
case INVOKEVIRTUAL:
adapter.loadArgs();
adapter.invokeVirtual(owner, targetMethod);
break;
case INVOKESPECIAL:
adapter.invokeStatic(Type.getType(AlchemyEngine.class), new Method("lookup",
"()Ljava/lang/invoke/MethodHandles$Lookup;"));
adapter.push(srgName);
Type args[] = Type.getArgumentTypes(desc);
adapter.visitFieldInsn(GETSTATIC, "java/lang/Void", "TYPE", "Ljava/lang/Class;");
adapter.push(args.length);
adapter.newArray(Type.getType(Class.class));
for (Type arg : args) {
adapter.dup();
adapter.push(arg);
adapter.arrayStore(Type.getType(Class.class));
}
adapter.invokeStatic(Type.getType(MethodType.class), new Method("methodType",
"(Ljava/lang/Class;[Ljava/lang/Class;)Ljava/lang/invoke/MethodType;"));
adapter.push(owner);
adapter.dupX2();
adapter.invokeVirtual(Type.getType(MethodHandles.Lookup.class), new Method("findSpecial",
"(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/Class;)Ljava/lang/invoke/MethodHandle;"));
adapter.loadArgs();
adapter.invokeVirtual(Type.getType(MethodHandle.class), new Method("invoke", proxyMethod.desc));
break;
case INVOKEINTERFACE:
adapter.loadArgs();
adapter.invokeInterface(owner, targetMethod);
break;
default:
AlchemyRuntimeException.onException(new RuntimeException("Unsupported opcode: " + opcode));
}
adapter.returnValue();
adapter.endMethod();
break;
}
node.methods.remove(oldMethod);
node.methods.add(newMethod);
node.accept(writer);
return writer.toByteArray();
}
示例13: restore
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
/**
* For methods, restore creates a return from the dispatch call, to exit the method
* once the new implementation has been executed. for void methods, this is an empty return
* and for all other methods, it returns the value from the dispatch call.
* <p/>
* Note that the generated bytecode does not have a direct translation to code, but as an
* example, this restore implementation in combination with the base class generates the
* following for methods with avoid return type:
* <code>
* if ($change != null) {
* $change.access$dispatch($name, new object[] { arg0, ... argsN })
* return;
* }
* $originalMethodBody
* </code>
* and the following for methods with a non-void return type:
* <code>
* if ($change != null) {
* return $change.access$dispatch($name, new object[] { arg0, ... argsN })
* }
* $originalMethodBody
* </code>
*/
@Override
protected void restore(GeneratorAdapter mv, List<Type> args) {
if (type == Type.VOID_TYPE) {
mv.pop();
} else {
ByteCodeUtils.unbox(mv, type);
}
mv.returnValue();
}