Java Code Examples for org.objectweb.asm.Opcodes#ASM4

The following examples show how to use org.objectweb.asm.Opcodes#ASM4 . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityInjector.java    From TickDynamic with MIT License 6 votes vote down vote up
@Override
public byte[] transform(String name, String transformedName,
		byte[] basicClass) {
	
	if(!transformedName.equals("net.minecraft.entity.Entity") && !transformedName.equals("net.minecraft.tileentity.TileEntity"))
		return basicClass;
	System.out.println("Entity Inject: " + transformedName);
	
	ClassReader cr = new ClassReader(basicClass);
	ClassWriter cw = new ClassWriter(0);
	ClassInjectorVisitor iv = new ClassInjectorVisitor(Opcodes.ASM4, cw);
	cr.accept(iv, ClassReader.EXPAND_FRAMES);
	
	
	return cw.toByteArray();
}
 
Example 2
Source File: SignatureVisitor.java    From Cafebabe with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Constructs a new {@link SignatureVisitor}.
 *
 * @param api
 *          the ASM API version implemented by this visitor. Must be one of {@link Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6} or {@link Opcodes#ASM7}.
 */
public SignatureVisitor(final int api) {
	if (api != Opcodes.ASM7 && api != Opcodes.ASM6 && api != Opcodes.ASM5 && api != Opcodes.ASM4) {
		throw new IllegalArgumentException("Unsupported api " + api);
	}
	this.api = api;
}
 
Example 3
Source File: SignatureVisitor.java    From Concurnas with MIT License 5 votes vote down vote up
/**
 * Constructs a new {@link SignatureVisitor}.
 *
 * @param api the ASM API version implemented by this visitor. Must be one of {@link
 *     Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6} or {@link Opcodes#ASM7}.
 */
public SignatureVisitor(final int api) {
  if (api != Opcodes.ASM7 && api != Opcodes.ASM6 && api != Opcodes.ASM5 && api != Opcodes.ASM4) {
    throw new IllegalArgumentException("Unsupported api " + api);
  }
  this.api = api;
}
 
Example 4
Source File: ConfigureMapReduceAdapter.java    From jumbune with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * <p>
 * This method adds a new method (setup or cleanup) to the class
 * </p>.
 *
 * @param isSetup true if method is setup
 */
@SuppressWarnings(UNCHECKED_WARNING)
private void addCleanupSetupMethodOldApi(boolean isSetup) {
	// new method
	MethodNode newMN = new MethodNode(Opcodes.ASM4, Opcodes.ACC_PUBLIC,
			null, null, null, new String[] { CLASSNAME_IOEXCEPTION });
	InsnList il = new InsnList();
	il.add(new LabelNode());
	// method name
	if (isSetup) {
		LOGGER.debug(MessageFormat.format(InstrumentationMessageLoader
				.getMessage(MessageConstants.LOG_ADDING_SETUP_METHOD),
				getClassName()));
		newMN.name = CONFIGURE_METHOD;
		newMN.desc = DESCRIPTOR_MAPPER_CONFIGURE;
		il.add(new VarInsnNode(Opcodes.ALOAD, 0));
		il.add(new VarInsnNode(Opcodes.ALOAD, 1));
	} else {
		LOGGER.debug(MessageFormat.format(InstrumentationMessageLoader
				.getMessage(MessageConstants.LOG_ADDING_CLEANUP_METHODD),
				getClassName()));
		newMN.name = CLOSE_METHOD;
		newMN.desc = DESCRIPTOR_MAPPER_CLOSE;
		il.add(new VarInsnNode(Opcodes.ALOAD, 0));
	}

	// adding call to super method
	il.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, getSuperClassName(),
			isSetup ? CONFIGURE_METHOD : CLOSE_METHOD, newMN.desc));

	il.add(prepareMapReduceForJumbuneInstructions(isSetup, newMN));

	il.add(new InsnNode(Opcodes.RETURN));

	newMN.instructions = il;
	methods.add(0, newMN);
}
 
Example 5
Source File: SignatureVisitor.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a new {@link SignatureVisitor}.
 *
 * @param api the ASM API version implemented by this visitor. Must be one of {@link
 *     Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6} or {@link
 *     Opcodes#ASM7_EXPERIMENTAL}.
 */
public SignatureVisitor(final int api) {
  if (api != Opcodes.ASM6
      && api != Opcodes.ASM5
      && api != Opcodes.ASM4
      && api != Opcodes.ASM7_EXPERIMENTAL) {
    throw new IllegalArgumentException();
  }
  this.api = api;
}
 
Example 6
Source File: DelegatedTransformer.java    From CodeChickenCore with MIT License 5 votes vote down vote up
private static void defineDependancies(byte[] bytes, JarFile jar, File jarFile, Stack<String> depStack) throws Exception
{
    ClassReader reader = new ClassReader(bytes);
    DependancyLister lister = new DependancyLister(Opcodes.ASM4);
    reader.accept(lister, 0);
    
    depStack.push(reader.getClassName());
    
    for(String dependancy : lister.getDependancies())
    {
        if(depStack.contains(dependancy))
            continue;
        
        try
        {
            Launch.classLoader.loadClass(dependancy.replace('/', '.'));
        }
        catch(ClassNotFoundException cnfe)
        {
            ZipEntry entry = jar.getEntry(dependancy+".class");
            if(entry == null)
                throw new Exception("Dependency "+dependancy+" not found in jar file "+jarFile.getName());
            
            byte[] depbytes = readFully(jar.getInputStream(entry));
            defineDependancies(depbytes, jar, jarFile, depStack);

            logger.debug("Defining dependancy: "+dependancy);
            
            defineClass(dependancy.replace('/', '.'), depbytes);
        }
    }
    
    depStack.pop();
}
 
Example 7
Source File: JarTraversal.java    From jumbune with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * This method will read each file available in jar and will then filter out
 * any class that has main method. To filter out it assumes that any class
 * that is creating Hadoop Job should has main method. It will add all those
 * classes name in a list and will return the same.
 * 
 * @param String
 *            jarPath
 * @return List<String>
 * @throws IOException
 */
public List<String> getAlljobs(String jarPath) throws IOException {
	ZipEntry entry;
	JarInputStream inputStream = null;
	byte[] outputBytes = null;
	try {
		inputStream = getJarInputStream(jarPath);
		if (inputStream == null) {
			return null;
		}

		ClassWriter wr = new ClassWriter(ClassWriter.COMPUTE_MAXS);
		HTFClassVisitor cvmr = new HTFClassVisitor(Opcodes.ASM4, wr);

		while ((entry = inputStream.getNextEntry()) != null) {
			if (entry.getName().endsWith(CLASS_FILE_EXTN)) {
				// This classreader should be created for every nextEntry of
				// input stream. Whenever inputStream.nextEntry
				// is called it points to a new class/folder. So all the
				// same inputStream is used but it points to a new
				// class
				outputBytes = InstrumentUtil
						.getEntryBytesFromZip(inputStream);
				ClassReader cr = new ClassReader(outputBytes);
				cr.accept(cvmr, 0);
			}
		}
		return cvmr.getJobClassList();
	} finally {
		if (inputStream != null) {
			inputStream.close();
		}
	}

}
 
Example 8
Source File: ClassPrinter.java    From java-agent-asm-javassist-sample with MIT License 4 votes vote down vote up
public ClassPrinter(ClassWriter writer) {
    super(Opcodes.ASM4, writer);
}
 
Example 9
Source File: StateImplementationVisitor.java    From ForgeWurst with GNU General Public License v3.0 4 votes vote down vote up
public ShouldSideBeRenderedVisitor(MethodVisitor mv)
{
	super(Opcodes.ASM4, mv);
}
 
Example 10
Source File: MethodReplaceClazzVisitor.java    From atlas with Apache License 2.0 4 votes vote down vote up
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    MethodVisitor methodVisitor = super.visitMethod(access, name, desc, signature, exceptions);
    return new MethodReplaceMethodVisitor(Opcodes.ASM4, methodVisitor, methodStore,stringBuilder);
}
 
Example 11
Source File: ClassVisitorImpl.java    From SocialSdkLibrary with Apache License 2.0 4 votes vote down vote up
public SocialConfigMethodVisitorImpl(MethodVisitor mv) {
    super(Opcodes.ASM4, mv);
}
 
Example 12
Source File: NetHandlerPlayClientVisitor.java    From ForgeWurst with GNU General Public License v3.0 4 votes vote down vote up
public SendPacketVisitor(MethodVisitor mv)
{
	super(Opcodes.ASM4, mv);
}
 
Example 13
Source File: GuiContainerCreativeVisitor.java    From ForgeWurst with GNU General Public License v3.0 4 votes vote down vote up
public InitGuiVisitor(MethodVisitor mv)
{
	super(Opcodes.ASM4, mv);
}
 
Example 14
Source File: ConfigureMapReduceAdapter.java    From jumbune with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * <p>
 * This method adds a new method (setup or cleanup) to the class
 * </p>.
 *
 * @param isSetup true if method is setup
 */
@SuppressWarnings(UNCHECKED_WARNING)
private void addCleanupSetupMethod(boolean isSetup) {
	// new method
	MethodNode newMN = new MethodNode(Opcodes.ASM4, Opcodes.ACC_PROTECTED,
			null, null, null, new String[] { CLASSNAME_IOEXCEPTION,
					CLASSNAME_INTERRUPTEDEXCEPTION });

	// method name
	if (isSetup) {
		LOGGER.debug(MessageFormat.format(InstrumentationMessageLoader
				.getMessage(MessageConstants.LOG_ADDING_SETUP_METHOD),
				getClassName()));
		newMN.name = SETUP_METHOD;
	} else {
		LOGGER.debug(MessageFormat.format(InstrumentationMessageLoader
				.getMessage(MessageConstants.LOG_ADDING_CLEANUP_METHODD),
				getClassName()));
		newMN.name = CLEANUP_METHOD;
	}

	// method descriptor
	if (isMapperClass()) {
		newMN.desc = DESCRIPTOR_MAPPER_CLEANUP;
	} else {
		newMN.desc = DESCRIPTOR_REDUCER_CLEANUP;
	}

	InsnList il = new InsnList();

	// adding call to super method
	il.add(new LabelNode());
	il.add(new VarInsnNode(Opcodes.ALOAD, 0));
	il.add(new VarInsnNode(Opcodes.ALOAD, 1));
	il.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, getSuperClassName(),
			isSetup ? SETUP_METHOD : CLEANUP_METHOD, newMN.desc));

	il.add(prepareMapReduceForJumbuneInstructions(isSetup, newMN));

	il.add(new InsnNode(Opcodes.RETURN));

	newMN.instructions = il;
	methods.add(0, newMN);
}
 
Example 15
Source File: EntityPlayerSPVisitor.java    From ForgeWurst with GNU General Public License v3.0 4 votes vote down vote up
public OnUpdateWalkingPlayerVisitor(MethodVisitor mv)
{
	super(Opcodes.ASM4, mv);
}
 
Example 16
Source File: ClassVisitorImpl.java    From SocialSdkLibrary with Apache License 2.0 4 votes vote down vote up
public SocialPlatformMethodVisitorImpl(MethodVisitor mv) {
    super(Opcodes.ASM4, mv);
}
 
Example 17
Source File: MREntryExitAdapter.java    From jumbune with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * <p>
 * Create a new instance of MREntryExitAdapter.
 * </p>
 * 
 * @param cv
 *            Class visitor
 */
public MREntryExitAdapter(Config config, ClassVisitor cv) {
	super(config, Opcodes.ASM4);
	this.cv = cv;
}
 
Example 18
Source File: BlockLogAdapter.java    From jumbune with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * <p>
 * Create a new instance of BlockLogAdapter.
 * </p>
 * @param loader
 * @param cv
 * @param env
 */
public BlockLogAdapter(Config config, ClassVisitor cv, Environment env) {
	super(config, Opcodes.ASM4);
	this.cv = cv;
	this.env = env;
}
 
Example 19
Source File: TimerAdapter.java    From jumbune with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * <p>
 * Create a new instance of TimerAdapter.
 * </p>
 * 
 * @param cv
 *            Class Visitor
 */
//TODO: No ref found....
public TimerAdapter(Config config, ClassVisitor cv) {
	super(config, Opcodes.ASM4);
	this.cv = cv;
}
 
Example 20
Source File: ContextWriteLogAdapter.java    From jumbune with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * <p>
 * Create a new instance of ContextWriteLogAdapter.
 * </p>
 * 
 * @param cv
 *            Class visitor
 */
public ContextWriteLogAdapter(Config config, ClassVisitor cv) {
	super(config, Opcodes.ASM4);
	this.cv = cv;
}