本文整理汇总了Java中org.frustra.filament.hooking.BadHookException类的典型用法代码示例。如果您正苦于以下问题:Java BadHookException类的具体用法?Java BadHookException怎么用?Java BadHookException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BadHookException类属于org.frustra.filament.hooking包,在下文中一共展示了BadHookException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: inject
import org.frustra.filament.hooking.BadHookException; //导入依赖的package包/类
public void inject(FilamentClassNode node) throws BadHookException {
for (MethodNode method : (List<MethodNode>) node.methods) {
// Find the method matching the ExampleC.printOne hook
if (HookUtil.compareMethodNode(method, "ExampleC.printOne")) {
// Loop through the bytecode instructions inside the printOne function
AbstractInsnNode insn = method.instructions.getFirst();
while (insn != null) {
// Find the first Load Constant instruction
if (insn instanceof LdcInsnNode) {
LdcInsnNode insn2 = (LdcInsnNode) insn;
// Replace the text inside the string constant
insn2.cst = ((String) insn2.cst).replace("World", "Shopify");
return;
}
insn = insn.getNext();
}
}
}
}
示例2: inject
import org.frustra.filament.hooking.BadHookException; //导入依赖的package包/类
public void inject(FilamentClassNode node) throws BadHookException {
for (MethodNode method : (List<MethodNode>) node.methods) {
// Find the main method within ExampleB
if (method.name.equals("main")) {
// Loop through the bytecode instructions inside the main function
AbstractInsnNode insn = method.instructions.getFirst();
while (insn != null) {
// Find the first Load Constant instruction
if (insn instanceof LdcInsnNode) {
LdcInsnNode insn2 = (LdcInsnNode) insn;
// Replace the text inside the string constant
insn2.cst = ((String) insn2.cst).replace("World", "Shopify");
return;
}
insn = insn.getNext();
}
}
}
}
示例3: doHooking
import org.frustra.filament.hooking.BadHookException; //导入依赖的package包/类
private static void doHooking() throws BadHookException {
if (Filament.filament.debug) {
System.out.println();
System.out.println("Executing hooks...");
}
hooks.clear();
try {
for (Integer pass : Filament.filament.hooks.keySet()) {
doHookingPass(pass);
}
} finally {
if (Filament.filament.debug) {
debugHooks();
System.out.println("Hooking complete");
System.out.println();
}
}
}
示例4: doInject
import org.frustra.filament.hooking.BadHookException; //导入依赖的package包/类
public void doInject(FilamentClassNode node) {
try {
if (!match(node)) return;
} catch (BadHookException e1) {
return;
}
try {
inject(node);
} catch (BadHookException e) {
e.printStackTrace();
}
}
示例5: createFieldInsnNode
import org.frustra.filament.hooking.BadHookException; //导入依赖的package包/类
/**
* Create an ASM {@link FieldInsnNode} from an opcode, name, and field signature, to be used for injecting.
* <p>
* The cls and type arguments can each be one of the following:
* <pre>
* String - The name of a class hook
* Type - an ASM {@link Type}
* Class - a java class
* FilamentClassNode - a {@link FilamentClassNode} or ASM {@link ClassNode}
* </pre>
*
* Example:
* <p>
* <code>HookUtil.createFieldInsnNode(Opcodes.GETSTATIC, Opcodes.class, "ALOAD", Type.INT_TYPE)</code>
*
* @param opcode the integer opcode of the instruction to create
* @param cls the class containing the field
* @param name the name of a field to get
* @param type the class matching the field's type
* @return a {@link FieldInsnNode} with the specified opcode, that will get the specified field
* @throws BadHookException if the specified hook is undefined or is the wrong type
*/
public static FieldInsnNode createFieldInsnNode(int opcode, Object cls, String name, Object type) throws BadHookException {
if (cls == null || name == null || type == null) return null;
String clsName = null;
if (cls instanceof String) {
clsName = Hooks.getClassName((String) cls);
} else if (cls instanceof Class<?>) {
clsName = Type.getInternalName((Class<?>) cls);
} else if (cls instanceof Type) {
clsName = ((Type) cls).getInternalName();
} else if (cls instanceof ClassNode) {
clsName = ((ClassNode) cls).name;
} else throw new ClassCastException("Class param must be a String, Type, Class or ClassNode, got " + cls.getClass().getName());
String desc = null;
if (type instanceof String) {
desc = Type.getObjectType(Hooks.getClassName((String) type)).getDescriptor();
} else if (type instanceof Class<?>) {
desc = Type.getType((Class<?>) type).getDescriptor();
} else if (type instanceof Type) {
desc = ((Type) type).getDescriptor();
} else if (type instanceof ClassNode) {
desc = Type.getObjectType(((ClassNode) type).name).getDescriptor();
} else throw new ClassCastException("Field type must be a String, Type, Class or ClassNode, got " + type.getClass().getName());
if (clsName == null) throw new NullPointerException("Class name resolved to null!");
if (desc == null) throw new NullPointerException("Field type resolved to null!");
return new FieldInsnNode(opcode, clsName, name, desc);
}
示例6: getClass
import org.frustra.filament.hooking.BadHookException; //导入依赖的package包/类
/**
* Get the value of a hook casted to a {@link FilamentClassNode}. See above for hook name formats.
*
* @param hook the name of a hook
* @return the hook's value
* @throws BadHookException if the specified hook is undefined or is the wrong type
*/
public static final FilamentClassNode getClass(String hook) throws BadHookException {
try {
return (FilamentClassNode) get(hook);
} catch (ClassCastException e) {
throw new BadHookException("Referenced hook is wrong type: " + hook, e);
}
}
示例7: getField
import org.frustra.filament.hooking.BadHookException; //导入依赖的package包/类
/**
* Get the value of a hook casted to a {@link FieldNode}. See above for hook name formats.
*
* @param hook the name of a hook
* @return the hook's value
* @throws BadHookException if the specified hook is undefined or is the wrong type
*/
public static final FieldNode getField(String hook) throws BadHookException {
try {
return (FieldNode) get(hook);
} catch (ClassCastException e) {
throw new BadHookException("Referenced hook is wrong type: " + hook, e);
}
}
示例8: getMethod
import org.frustra.filament.hooking.BadHookException; //导入依赖的package包/类
/**
* Get the value of a hook casted to a {@link MethodNode}. See above for hook name formats.
*
* @param hook the name of a hook
* @return the hook's value
* @throws BadHookException if the specified hook is undefined or is the wrong type
*/
public static final MethodNode getMethod(String hook) throws BadHookException {
try {
return (MethodNode) get(hook);
} catch (ClassCastException e) {
throw new BadHookException("Referenced hook is wrong type: " + hook, e);
}
}
示例9: getString
import org.frustra.filament.hooking.BadHookException; //导入依赖的package包/类
/**
* Get the value of a hook casted to a {@link String}. See above for hook name formats.
*
* @param hook the name of a hook
* @return the hook's value
* @throws BadHookException if the specified hook is undefined or is the wrong type
*/
public static final String getString(String hook) throws BadHookException {
try {
return (String) get(hook);
} catch (ClassCastException e) {
throw new BadHookException("Referenced hook is wrong type: " + hook, e);
}
}
示例10: get
import org.frustra.filament.hooking.BadHookException; //导入依赖的package包/类
/**
* Get the value of a hook without casting its type. See above for hook name formats.
*
* @param hook the name of a hook
* @return the hook's value
* @throws BadHookException if the specified hook is undefined
*/
public static final Object get(String hook) throws BadHookException {
Object val = hooks.get(hook);
if (val == null) {
System.out.println(Hooks.class.getClassLoader());
throw new BadHookException("Referenced undefined hook: " + hook);
}
return val;
}
示例11: doComplete
import org.frustra.filament.hooking.BadHookException; //导入依赖的package包/类
public final void doComplete() throws BadHookException {
if (error != null) {
throw new BadHookException("Error in matcher", this, error);
} else if (matches < 1) {
throw new BadHookException("Provider found no matches", this);
} else if (matches > 1) {
throw new BadHookException("Provider found multiple matches", this);
}
try {
complete();
} catch (Throwable e) {
error = e;
throw new BadHookException("Error on completion", this, error);
}
}
示例12: createMethodInsnNode
import org.frustra.filament.hooking.BadHookException; //导入依赖的package包/类
/**
* Create an ASM {@link MethodInsnNode} from an opcode, name, and method signature, to be used for injecting.
* <p>
* The cls, ret, and param arguments can each be one of the following:
* <pre>
* String - The name of a class hook
* Type - an ASM {@link Type}
* Class - a java class
* FilamentClassNode - a {@link FilamentClassNode} or ASM {@link ClassNode}
* </pre>
*
* Example:
* <p>
* <code>HookUtil.createMethodInsnNode(Opcodes.INVOKEVIRTUAL, String.class, "valueOf", String.class, "ClassHookName")</code>
*
* @param opcode the integer opcode of the instruction to create
* @param cls the class containing the method
* @param name the name of a method to call
* @param ret the return type of the method
* @param params a list of classes matching the parameter types of the method
* @return a {@link MethodInsnNode} with the specified opcode, that will call the specified method
* @throws BadHookException if a specified hook is undefined or is the wrong type
*/
public static MethodInsnNode createMethodInsnNode(int opcode, Object cls, String name, Object ret, Object... params) throws BadHookException {
if (cls == null || name == null || ret == null) return null;
String clsName = null;
if (cls instanceof String) {
clsName = Hooks.getClassName((String) cls);
} else if (cls instanceof Class<?>) {
clsName = Type.getInternalName((Class<?>) cls);
} else if (cls instanceof Type) {
clsName = ((Type) cls).getInternalName();
} else if (cls instanceof ClassNode) {
clsName = ((ClassNode) cls).name;
} else throw new ClassCastException("Class param must be a String, Type, Class or ClassNode, got " + cls.getClass().getName());
Type retType = null;
if (ret instanceof String) {
retType = Type.getObjectType(Hooks.getClassName((String) ret));
} else if (ret instanceof Class<?>) {
retType = Type.getType((Class<?>) ret);
} else if (ret instanceof Type) {
retType = (Type) ret;
} else if (ret instanceof ClassNode) {
retType = Type.getObjectType(((ClassNode) ret).name);
} else throw new ClassCastException("Return type must be a String, Type, Class or ClassNode, got " + ret.getClass().getName());
ArrayList<Type> paramTypes = new ArrayList<Type>();
for (Object param : params) {
Type tmpType = null;
if (param instanceof String) {
tmpType = Type.getObjectType(Hooks.getClassName((String) param));
} else if (param instanceof Class<?>) {
tmpType = Type.getType((Class<?>) param);
} else if (param instanceof Type) {
tmpType = (Type) param;
} else if (param instanceof ClassNode) {
tmpType = Type.getObjectType(((ClassNode) param).name);
} else throw new ClassCastException("Param types must be String, Type, Class or ClassNode, got " + param.getClass().getName());
paramTypes.add(tmpType);
}
String desc = Type.getMethodDescriptor(retType, paramTypes.toArray(new Type[0]));
if (clsName == null) throw new NullPointerException("Class name resolved to null!");
if (desc == null) throw new NullPointerException("Method descriptor resolved to null!");
return new MethodInsnNode(opcode, clsName, name, desc);
}
示例13: load
import org.frustra.filament.hooking.BadHookException; //导入依赖的package包/类
/**
* Load all hook providers contained within the specified package, and run them on the global Filament instance.
* A FilamentClassLoader must be created in order to initialize the Filament instance.
* <p>
* A hook provider is any class that extends {@link HookProvider}.
* Hook providers have a {@link HookingPass} annotation to define what order they are processed in.
* Any hook providers loaded with a previous call to load will be overwritten.
*
* @param packageName the name of the package containing hook providers
* @throws ReflectiveOperationException if the package or any classes cannot be loaded
* @throws BadHookException if there is an error while processing the hooks
* @throws IOException if one of the provider classes could not be read
* @see FilamentClassLoader
* @see HookProvider
* @see HookingPass
*/
public static final void load(String packageName) throws ReflectiveOperationException, IOException, BadHookException {
String[] hooks = Filament.filament.classLoader.listPackage(packageName);
Filament.filament.hooks.clear();
for (String name : hooks) {
Class<?> cls = Filament.filament.classLoader.loadClass(name);
if (HookProvider.class.isAssignableFrom(cls)) {
addHook((HookProvider) cls.newInstance());
if (Filament.filament.debug) {
System.out.println("Loaded Hook: " + cls.getSimpleName());
}
}
}
doHooking();
}
示例14: complete
import org.frustra.filament.hooking.BadHookException; //导入依赖的package包/类
public void complete() throws BadHookException {
complete(cNode);
}
示例15: match
import org.frustra.filament.hooking.BadHookException; //导入依赖的package包/类
public boolean match(FilamentClassNode node) throws BadHookException {
return true;
}