use of org.objectweb.asm.ClassReader in project pinpoint by naver.
the class ASMClassNodeAdapter method get.
public static ASMClassNodeAdapter get(final InstrumentContext pluginContext, final ClassLoader classLoader, final String classInternalName, final boolean skipCode) {
if (pluginContext == null || classInternalName == null) {
throw new IllegalArgumentException("plugin context or class name must not be null.");
}
InputStream in = null;
try {
in = pluginContext.getResourceAsStream(classLoader, classInternalName + ".class");
if (in != null) {
final ClassReader classReader = new ClassReader(in);
final ClassNode classNode = new ClassNode();
if (skipCode) {
classReader.accept(classNode, ClassReader.SKIP_CODE);
} else {
classReader.accept(classNode, 0);
}
return new ASMClassNodeAdapter(pluginContext, classLoader, classNode, skipCode);
}
} catch (IOException ignored) {
// not found class.
} finally {
if (in != null) {
try {
in.close();
} catch (IOException ignored) {
}
}
}
return null;
}
use of org.objectweb.asm.ClassReader in project pinpoint by naver.
the class ASMClassWriter method get.
private String get(final String type1ClassInternalName, final String type2ClassInternalName) {
if (type1ClassInternalName == null || type1ClassInternalName.equals(OBJECT_CLASS_INTERNAL_NAME) || type2ClassInternalName == null || type2ClassInternalName.equals(OBJECT_CLASS_INTERNAL_NAME)) {
// object is the root of the class hierarchy.
return OBJECT_CLASS_INTERNAL_NAME;
}
if (type1ClassInternalName.equals(type2ClassInternalName)) {
// two equal.
return type1ClassInternalName;
}
// current class.
if (type1ClassInternalName.equals(classInternalName)) {
return getCommonSuperClass(superClassInternalName, type2ClassInternalName);
} else if (type2ClassInternalName.equals(classInternalName)) {
return getCommonSuperClass(type1ClassInternalName, superClassInternalName);
}
ClassReader type1ClassReader = getClassReader(type1ClassInternalName);
ClassReader type2ClassReader = getClassReader(type2ClassInternalName);
if (type1ClassReader == null || type2ClassReader == null) {
logger.warn("Skip get common super class. not found class {type1ClassInternalName={}, reader={}}, {type2ClassInternalName={}, reader={}}", type1ClassInternalName, type1ClassReader, type2ClassInternalName, type2ClassReader);
return OBJECT_CLASS_INTERNAL_NAME;
}
// interface.
if (isInterface(type1ClassReader)) {
String interfaceInternalName = type1ClassInternalName;
if (isImplements(interfaceInternalName, type2ClassReader)) {
return interfaceInternalName;
}
if (isInterface(type2ClassReader)) {
interfaceInternalName = type2ClassInternalName;
if (isImplements(interfaceInternalName, type1ClassReader)) {
return interfaceInternalName;
}
}
return OBJECT_CLASS_INTERNAL_NAME;
}
// interface.
if (isInterface(type2ClassReader)) {
String interfaceName = type2ClassInternalName;
if (isImplements(interfaceName, type1ClassReader)) {
return interfaceName;
}
return OBJECT_CLASS_INTERNAL_NAME;
}
// class.
final Set<String> superClassNames = new HashSet<String>();
superClassNames.add(type1ClassInternalName);
superClassNames.add(type2ClassInternalName);
String type1SuperClassName = type1ClassReader.getSuperName();
if (!superClassNames.add(type1SuperClassName)) {
// find common superClass.
return type1SuperClassName;
}
String type2SuperClassName = type2ClassReader.getSuperName();
if (!superClassNames.add(type2SuperClassName)) {
// find common superClass.
return type2SuperClassName;
}
while (type1SuperClassName != null || type2SuperClassName != null) {
if (type1SuperClassName != null) {
type1SuperClassName = getSuperClassInternalName(type1SuperClassName);
if (type1SuperClassName != null) {
if (!superClassNames.add(type1SuperClassName)) {
return type1SuperClassName;
}
}
}
if (type2SuperClassName != null) {
type2SuperClassName = getSuperClassInternalName(type2SuperClassName);
if (type2SuperClassName != null) {
if (!superClassNames.add(type2SuperClassName)) {
return type2SuperClassName;
}
}
}
}
return OBJECT_CLASS_INTERNAL_NAME;
}
use of org.objectweb.asm.ClassReader in project pinpoint by naver.
the class ASMEngine method getClass.
@Override
public InstrumentClass getClass(InstrumentContext instrumentContext, ClassLoader classLoader, String className, byte[] classFileBuffer) throws NotFoundInstrumentException {
if (className == null) {
throw new NullPointerException("class name must not be null.");
}
try {
if (classFileBuffer == null) {
ASMClassNodeAdapter classNode = ASMClassNodeAdapter.get(instrumentContext, classLoader, JavaAssistUtils.javaNameToJvmName(className));
if (classNode == null) {
return null;
}
ApiMetaDataService apiMetaDataService = this.apiMetaDataService.get();
return new ASMClass(objectBinderFactory, instrumentContext, interceptorRegistryBinder, apiMetaDataService, classLoader, classNode);
}
// Use ASM tree api.
final ClassReader classReader = new ClassReader(classFileBuffer);
final ClassNode classNode = new ClassNode();
classReader.accept(classNode, 0);
ApiMetaDataService apiMetaDataService = this.apiMetaDataService.get();
return new ASMClass(objectBinderFactory, instrumentContext, interceptorRegistryBinder, apiMetaDataService, classLoader, classNode);
} catch (Exception e) {
throw new NotFoundInstrumentException(e);
}
}
use of org.objectweb.asm.ClassReader in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class ValkyrienWarfareTransformer method transform.
@Override
public byte[] transform(String name, String transformedName, byte[] classData) {
classData = transformer.transform(classData);
TransformAdapter adapter = new TransformAdapter(ASM5, ValkyrienWarfarePlugin.isObfuscatedEnvironment, transformedName);
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS);
adapter.setCV(classWriter);
try {
new ClassReader(classData).accept(adapter, ClassReader.EXPAND_FRAMES);
classData = classWriter.toByteArray();
//Performs sanity checks and frame stack recalculations before pushing the new bytecode
// ClassReader cr = new ClassReader(byteArray);
// ClassWriter checkedWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS);
// CheckClassAdapter adapterChecker = new CheckClassAdapter(checkedWriter, true);
// cr.accept(adapterChecker, ClassReader.EXPAND_FRAMES);
// return checkedWriter.toByteArray();
} catch (Exception e) {
// System.out.println(transformedName);
e.printStackTrace();
}
return classData;
}
use of org.objectweb.asm.ClassReader in project Engine by VoltzEngine-Project.
the class ASMHelper method createClassNode.
public static ClassNode createClassNode(byte[] bytes, int flags) {
ClassNode cnode = new ClassNode();
ClassReader reader = new ClassReader(bytes);
reader.accept(cnode, flags);
return cnode;
}
Aggregations