use of org.objectweb.asm.tree.FieldNode in project pinpoint by naver.
the class ASMClassNodeAdapter method getField.
public ASMFieldNodeAdapter getField(final String fieldName, final String fieldDesc) {
if (fieldName == null || this.classNode.fields == null) {
return null;
}
final List<FieldNode> fields = this.classNode.fields;
for (FieldNode fieldNode : fields) {
if ((fieldNode.name != null && fieldNode.name.equals(fieldName)) && (fieldDesc == null || (fieldNode.desc != null && fieldNode.desc.equals(fieldDesc)))) {
return new ASMFieldNodeAdapter(fieldNode);
}
}
// find interface.
final List<String> interfaces = this.classNode.interfaces;
if (interfaces != null && interfaces.size() > 0) {
for (String interfaceClassName : interfaces) {
if (interfaceClassName == null) {
continue;
}
final ASMClassNodeAdapter classNodeAdapter = ASMClassNodeAdapter.get(this.pluginContext, this.classLoader, interfaceClassName, true);
if (classNodeAdapter != null) {
final ASMFieldNodeAdapter fieldNode = classNodeAdapter.getField(fieldName, fieldDesc);
if (fieldNode != null) {
return fieldNode;
}
}
}
}
// find super class.
if (this.classNode.superName != null) {
final ASMClassNodeAdapter classNodeAdapter = ASMClassNodeAdapter.get(this.pluginContext, this.classLoader, this.classNode.superName, true);
if (classNodeAdapter != null) {
final ASMFieldNodeAdapter fieldNode = classNodeAdapter.getField(fieldName, fieldDesc);
if (fieldNode != null) {
return fieldNode;
}
}
}
return null;
}
use of org.objectweb.asm.tree.FieldNode in project drill by apache.
the class MergeAdapter method visitEnd.
@Override
public void visitEnd() {
// add all the fields of the class we're going to merge.
for (Iterator<?> it = classToMerge.fields.iterator(); it.hasNext(); ) {
// Special handling for nested classes. Drill uses non-static nested
// "inner" classes in some templates. Prior versions of Drill would
// create the generated nested classes as static, then this line
// would copy the "this$0" field to convert the static nested class
// into a non-static inner class. However, that approach is not
// compatible with plain-old Java compilation. Now, Drill generates
// the nested classes as non-static inner classes. As a result, we
// do not want to copy the hidden fields; we'll end up with two if
// we do.
FieldNode field = (FieldNode) it.next();
if (!field.name.startsWith("this$")) {
field.accept(this);
}
}
// add all the methods that we to include.
for (Iterator<?> it = classToMerge.methods.iterator(); it.hasNext(); ) {
MethodNode mn = (MethodNode) it.next();
if (mn.name.equals("<init>")) {
continue;
}
String[] exceptions = new String[mn.exceptions.size()];
mn.exceptions.toArray(exceptions);
MethodVisitor mv = cv.visitMethod(mn.access | Modifier.FINAL, mn.name, mn.desc, mn.signature, exceptions);
if (verifyBytecode) {
mv = new CheckMethodVisitorFsm(api, mv);
}
mn.instructions.resetLabels();
// mn.accept(new RemappingMethodAdapter(mn.access, mn.desc, mv, new
// SimpleRemapper("org.apache.drill.exec.compile.ExampleTemplate", "Bunky")));
ClassSet top = set;
while (top.parent != null) {
top = top.parent;
}
mn.accept(new RemappingMethodAdapter(mn.access, mn.desc, mv, new SimpleRemapper(top.precompiled.slash, top.generated.slash)));
}
super.visitEnd();
}
use of org.objectweb.asm.tree.FieldNode in project bytecode-viewer by Konloch.
the class ClassNodeDecompiler method decompile.
protected static PrefixedStringBuilder decompile(PrefixedStringBuilder sb, ArrayList<String> decompiledClasses, String containerName, ClassNode cn) {
ArrayList<String> unableToDecompile = new ArrayList<String>();
decompiledClasses.add(cn.name);
sb.append(getAccessString(cn.access));
sb.append(" ");
sb.append(cn.name);
if (cn.superName != null && !cn.superName.equals("java/lang/Object")) {
sb.append(" extends ");
sb.append(cn.superName);
}
int amountOfInterfaces = cn.interfaces.size();
if (amountOfInterfaces > 0) {
sb.append(" implements ");
sb.append(cn.interfaces.get(0));
if (amountOfInterfaces > 1) {
// sb.append(",");
}
for (int i = 1; i < amountOfInterfaces; i++) {
sb.append(", ");
sb.append(cn.interfaces.get(i));
}
}
sb.append(" {");
sb.append(BytecodeViewer.nl);
for (FieldNode fn : (List<FieldNode>) cn.fields) {
sb.append(BytecodeViewer.nl);
sb.append(" ");
FieldNodeDecompiler.decompile(sb, fn);
}
if (cn.fields.size() > 0) {
sb.append(BytecodeViewer.nl);
}
for (MethodNode mn : (List<MethodNode>) cn.methods) {
sb.append(BytecodeViewer.nl);
MethodNodeDecompiler.decompile(sb, mn, cn);
}
for (Object o : cn.innerClasses) {
InnerClassNode innerClassNode = (InnerClassNode) o;
String innerClassName = innerClassNode.name;
if ((innerClassName != null) && !decompiledClasses.contains(innerClassName)) {
decompiledClasses.add(innerClassName);
ClassNode cn1 = BytecodeViewer.getClassNode(containerName, innerClassName);
if (cn1 != null) {
sb.appendPrefix(" ");
sb.append(BytecodeViewer.nl + BytecodeViewer.nl);
sb = decompile(sb, decompiledClasses, containerName, cn1);
sb.trimPrefix(5);
sb.append(BytecodeViewer.nl);
} else {
unableToDecompile.add(innerClassName);
}
}
}
if (!unableToDecompile.isEmpty()) {
sb.append("//the following inner classes couldn't be decompiled: ");
for (String s : unableToDecompile) {
sb.append(s);
sb.append(" ");
}
sb.append(BytecodeViewer.nl);
}
sb.append("}");
// " with prefix length: " + sb.prefix.length());
return sb;
}
use of org.objectweb.asm.tree.FieldNode in project buck by facebook.
the class StaticStateAnalyzer method isClassSafe.
private boolean isClassSafe(ClassNode klass) {
boolean isSafe = true;
// Look for mutable static fields.
for (FieldNode field : klass.fields) {
if ((field.access & Opcodes.ACC_STATIC) == 0) {
continue;
}
if ((field.access & Opcodes.ACC_FINAL) == 0) {
log.add("Non-final static field: " + describe(klass, field));
isSafe = false;
continue;
}
if (!mutabilityAnalyzer.isTypeImmutable(field.desc)) {
log.add("Mut-final static field: " + describe(klass, field));
isSafe = false;
continue;
}
}
// Look for static synchronized methods.
for (MethodNode method : klass.methods) {
if ((method.access & Opcodes.ACC_STATIC) == 0) {
continue;
}
if ((method.access & Opcodes.ACC_SYNCHRONIZED) != 0) {
log.add("Synchronized static method: " + describe(klass, method));
isSafe = false;
continue;
}
}
return isSafe;
}
use of org.objectweb.asm.tree.FieldNode in project MinecraftForge by MinecraftForge.
the class AccessTransformer method transform.
@Override
public byte[] transform(String name, String transformedName, byte[] bytes) {
if (bytes == null) {
return null;
}
if (DEBUG) {
FMLRelaunchLog.fine("Considering all methods and fields on %s (%s)\n", transformedName, name);
}
if (!modifiers.containsKey(transformedName)) {
return bytes;
}
ClassNode classNode = new ClassNode();
ClassReader classReader = new ClassReader(bytes);
classReader.accept(classNode, 0);
Collection<Modifier> mods = modifiers.get(transformedName);
for (Modifier m : mods) {
if (m.modifyClassVisibility) {
classNode.access = getFixedAccess(classNode.access, m);
if (DEBUG) {
System.out.println(String.format("Class: %s %s -> %s", name, toBinary(m.oldAccess), toBinary(m.newAccess)));
}
continue;
}
if (m.desc.isEmpty()) {
for (FieldNode n : classNode.fields) {
if (n.name.equals(m.name) || m.name.equals("*")) {
n.access = getFixedAccess(n.access, m);
if (DEBUG) {
System.out.println(String.format("Field: %s.%s %s -> %s", name, n.name, toBinary(m.oldAccess), toBinary(m.newAccess)));
}
if (!m.name.equals("*")) {
break;
}
}
}
} else {
List<MethodNode> nowOverrideable = Lists.newArrayList();
for (MethodNode n : classNode.methods) {
if ((n.name.equals(m.name) && n.desc.equals(m.desc)) || m.name.equals("*")) {
n.access = getFixedAccess(n.access, m);
// constructors always use INVOKESPECIAL
if (!n.name.equals("<init>")) {
// if we changed from private to something else we need to replace all INVOKESPECIAL calls to this method with INVOKEVIRTUAL
// so that overridden methods will be called. Only need to scan this class, because obviously the method was private.
boolean wasPrivate = (m.oldAccess & ACC_PRIVATE) == ACC_PRIVATE;
boolean isNowPrivate = (m.newAccess & ACC_PRIVATE) == ACC_PRIVATE;
if (wasPrivate && !isNowPrivate) {
nowOverrideable.add(n);
}
}
if (DEBUG) {
System.out.println(String.format("Method: %s.%s%s %s -> %s", name, n.name, n.desc, toBinary(m.oldAccess), toBinary(m.newAccess)));
}
if (!m.name.equals("*")) {
break;
}
}
}
replaceInvokeSpecial(classNode, nowOverrideable);
}
}
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
classNode.accept(writer);
return writer.toByteArray();
}
Aggregations