List of usage examples for org.objectweb.asm Opcodes ACC_NATIVE
int ACC_NATIVE
To view the source code for org.objectweb.asm Opcodes ACC_NATIVE.
Click Source Link
From source file:com.android.tools.layoutlib.create.DelegateClassAdapter.java
License:Apache License
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { boolean isStatic = (access & Opcodes.ACC_STATIC) != 0; boolean isNative = (access & Opcodes.ACC_NATIVE) != 0; boolean useDelegate = (isNative && mDelegateMethods.contains(ALL_NATIVES)) || mDelegateMethods.contains(name); if (!useDelegate) { // Not creating a delegate for this method, pass it as-is from the reader // to the writer. return super.visitMethod(access, name, desc, signature, exceptions); }/*from w w w. j a v a 2s. c o m*/ if (useDelegate) { if (CONSTRUCTOR.equals(name) || CLASS_INIT.equals(name)) { // We don't currently support generating delegates for constructors. throw new UnsupportedOperationException( String.format("Delegate doesn't support overriding constructor %1$s:%2$s(%3$s)", //$NON-NLS-1$ mClassName, name, desc)); } } if (isNative) { // Remove native flag access = access & ~Opcodes.ACC_NATIVE; MethodVisitor mwDelegate = super.visitMethod(access, name, desc, signature, exceptions); DelegateMethodAdapter2 a = new DelegateMethodAdapter2(mLog, null /*mwOriginal*/, mwDelegate, mClassName, name, desc, isStatic); // A native has no code to visit, so we need to generate it directly. a.generateDelegateCode(); return mwDelegate; } // Given a non-native SomeClass.MethodName(), we want to generate 2 methods: // - A copy of the original method named SomeClass.MethodName_Original(). // The content is the original method as-is from the reader. // - A brand new implementation of SomeClass.MethodName() which calls to a // non-existing method named SomeClass_Delegate.MethodName(). // The implementation of this 'delegate' method is done in layoutlib_brigde. int accessDelegate = access; // change access to public for the original one if (Main.sOptions.generatePublicAccess) { access &= ~(Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE); access |= Opcodes.ACC_PUBLIC; } MethodVisitor mwOriginal = super.visitMethod(access, name + ORIGINAL_SUFFIX, desc, signature, exceptions); MethodVisitor mwDelegate = super.visitMethod(accessDelegate, name, desc, signature, exceptions); DelegateMethodAdapter2 a = new DelegateMethodAdapter2(mLog, mwOriginal, mwDelegate, mClassName, name, desc, isStatic); return a; }
From source file:com.android.tools.layoutlib.create.TransformClassAdapter.java
License:Apache License
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { if (mDeleteReturns != null) { Type t = Type.getReturnType(desc); if (t.getSort() == Type.OBJECT) { String returnType = t.getInternalName(); if (returnType != null) { if (mDeleteReturns.contains(returnType)) { return null; }//from w ww .j a v a 2s . co m } } } String methodSignature = mClassName.replace('/', '.') + "#" + name; // change access to public access &= ~(Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE); access |= Opcodes.ACC_PUBLIC; // remove final access = access & ~Opcodes.ACC_FINAL; // stub this method if they are all to be stubbed or if it is a native method // and don't try to stub interfaces nor abstract non-native methods. if (!mIsInterface && ((access & (Opcodes.ACC_ABSTRACT | Opcodes.ACC_NATIVE)) != Opcodes.ACC_ABSTRACT) && (mStubAll || (access & Opcodes.ACC_NATIVE) != 0) || mStubMethods.contains(methodSignature)) { boolean isStatic = (access & Opcodes.ACC_STATIC) != 0; boolean isNative = (access & Opcodes.ACC_NATIVE) != 0; // remove abstract, final and native access = access & ~(Opcodes.ACC_ABSTRACT | Opcodes.ACC_FINAL | Opcodes.ACC_NATIVE); String invokeSignature = methodSignature + desc; mLog.debug(" Stub: %s (%s)", invokeSignature, isNative ? "native" : ""); MethodVisitor mw = super.visitMethod(access, name, desc, signature, exceptions); return new StubMethodAdapter(mw, name, returnType(desc), invokeSignature, isStatic, isNative); } else { mLog.debug(" Keep: %s %s", name, desc); return super.visitMethod(access, name, desc, signature, exceptions); } }
From source file:com.codename1.tools.translator.BytecodeMethod.java
License:Open Source License
public BytecodeMethod(String clsName, int access, String name, String desc, String signature, String[] exceptions) {/*from ww w . j av a 2 s. c o m*/ methodName = name; this.clsName = clsName; this.desc = desc; privateMethod = (access & Opcodes.ACC_PRIVATE) == Opcodes.ACC_PRIVATE; nativeMethod = (access & Opcodes.ACC_NATIVE) == Opcodes.ACC_NATIVE; staticMethod = (access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC; finalMethod = (access & Opcodes.ACC_FINAL) == Opcodes.ACC_FINAL; synchronizedMethod = (access & Opcodes.ACC_SYNCHRONIZED) == Opcodes.ACC_SYNCHRONIZED; int pos = desc.lastIndexOf(')'); if (!staticMethod) { if (!dependentClasses.contains("java_lang_NullPointerException")) { dependentClasses.add("java_lang_NullPointerException"); } } // if (methodName.equals("<init>")) { methodName = "__INIT__"; constructor = true; returnType = new ByteCodeMethodArg(Void.TYPE, 0); } else { if (methodName.equals("<clinit>")) { methodName = "__CLINIT__"; returnType = new ByteCodeMethodArg(Void.TYPE, 0); staticMethod = true; } else { String retType = desc.substring(pos + 1); if (retType.equals("V")) { returnType = new ByteCodeMethodArg(Void.TYPE, 0); } else { int dim = 0; while (retType.startsWith("[")) { retType = retType.substring(1); dim++; } char currentType = retType.charAt(0); switch (currentType) { case 'L': // Object skip until ; int idx = retType.indexOf(';'); String objectType = retType.substring(1, idx); objectType = objectType.replace('/', '_').replace('$', '_'); if (!dependentClasses.contains(objectType)) { dependentClasses.add(objectType); } //if (!this.isPrivate() && !exportedClasses.contains(objectType)) { // exportedClasses.add(objectType); //} returnType = new ByteCodeMethodArg(objectType, dim); break; case 'I': returnType = new ByteCodeMethodArg(Integer.TYPE, dim); break; case 'J': returnType = new ByteCodeMethodArg(Long.TYPE, dim); break; case 'B': returnType = new ByteCodeMethodArg(Byte.TYPE, dim); break; case 'S': returnType = new ByteCodeMethodArg(Short.TYPE, dim); break; case 'F': returnType = new ByteCodeMethodArg(Float.TYPE, dim); break; case 'D': returnType = new ByteCodeMethodArg(Double.TYPE, dim); break; case 'Z': returnType = new ByteCodeMethodArg(Boolean.TYPE, dim); break; case 'C': returnType = new ByteCodeMethodArg(Character.TYPE, dim); break; } } } } int currentArrayDim = 0; desc = desc.substring(1, pos); for (int i = 0; i < desc.length(); i++) { char currentType = desc.charAt(i); switch (currentType) { case '[': // array of... currentArrayDim++; continue; case 'L': // Object skip until ; int idx = desc.indexOf(';', i); String objectType = desc.substring(i + 1, idx); objectType = objectType.replace('/', '_').replace('$', '_'); if (!dependentClasses.contains(objectType)) { dependentClasses.add(objectType); } //if (!this.isPrivate() && !exportedClasses.contains(objectType)) { // exportedClasses.contains(objectType); //} i = idx; arguments.add(new ByteCodeMethodArg(objectType, currentArrayDim)); break; case 'I': arguments.add(new ByteCodeMethodArg(Integer.TYPE, currentArrayDim)); break; case 'J': arguments.add(new ByteCodeMethodArg(Long.TYPE, currentArrayDim)); break; case 'B': arguments.add(new ByteCodeMethodArg(Byte.TYPE, currentArrayDim)); break; case 'S': arguments.add(new ByteCodeMethodArg(Short.TYPE, currentArrayDim)); break; case 'F': arguments.add(new ByteCodeMethodArg(Float.TYPE, currentArrayDim)); break; case 'D': arguments.add(new ByteCodeMethodArg(Double.TYPE, currentArrayDim)); break; case 'Z': arguments.add(new ByteCodeMethodArg(Boolean.TYPE, currentArrayDim)); break; case 'C': arguments.add(new ByteCodeMethodArg(Character.TYPE, currentArrayDim)); break; } currentArrayDim = 0; } }
From source file:com.facebook.buck.jvm.java.abi.AccessFlags.java
License:Apache License
/** Gets the access flag (see JVMS8 4.1, 4.5, 4.6) corresponding to the given modifier. */ private static int modifierToAccessFlag(Modifier modifier) { switch (modifier) { case PUBLIC:/*from w w w . j a va 2 s.c om*/ return Opcodes.ACC_PUBLIC; case PROTECTED: return Opcodes.ACC_PROTECTED; case PRIVATE: return Opcodes.ACC_PRIVATE; case ABSTRACT: return Opcodes.ACC_ABSTRACT; case DEFAULT: return 0; case STATIC: return Opcodes.ACC_STATIC; case FINAL: return Opcodes.ACC_FINAL; case TRANSIENT: return Opcodes.ACC_TRANSIENT; case VOLATILE: return Opcodes.ACC_VOLATILE; case SYNCHRONIZED: return Opcodes.ACC_SYNCHRONIZED; case NATIVE: return Opcodes.ACC_NATIVE; case STRICTFP: return Opcodes.ACC_STRICT; default: throw new IllegalArgumentException(String.format("Unexpected modifier: %s", modifier)); } }
From source file:com.facebook.buck.jvm.java.abi.AccessFlagsTest.java
License:Apache License
@Test public void testNativeFlag() throws IOException { compile(Joiner.on('\n').join("class Foo {", " native void method();", "}")); assertEquals(Opcodes.ACC_NATIVE, accessFlags.getAccessFlags(findMethod("method", elements.getTypeElement("Foo")))); }
From source file:com.gargoylesoftware.js.nashorn.internal.ir.debug.NashornTextifier.java
License:Open Source License
@Override public NashornTextifier visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) { graph = new Graph(name); final List<Label> extraLabels = cr.getExtraLabels(currentClassName, name, desc); this.labelIter = extraLabels == null ? null : extraLabels.iterator(); final StringBuilder sb = new StringBuilder(); sb.append('\n'); if ((access & Opcodes.ACC_DEPRECATED) != 0) { sb.append(tab).append("// DEPRECATED\n"); }//from w ww . j a v a2s .c om sb.append(tab).append("// access flags 0x").append(Integer.toHexString(access).toUpperCase()).append('\n'); if (signature != null) { sb.append(tab); appendDescriptor(sb, METHOD_SIGNATURE, signature); final TraceSignatureVisitor v = new TraceSignatureVisitor(0); final SignatureReader r = new SignatureReader(signature); r.accept(v); final String genericDecl = v.getDeclaration(); final String genericReturn = v.getReturnType(); final String genericExceptions = v.getExceptions(); sb.append(tab).append("// declaration: ").append(genericReturn).append(' ').append(name) .append(genericDecl); if (genericExceptions != null) { sb.append(" throws ").append(genericExceptions); } sb.append('\n'); } sb.append(tab); appendAccess(sb, access); if ((access & Opcodes.ACC_NATIVE) != 0) { sb.append("native "); } if ((access & Opcodes.ACC_VARARGS) != 0) { sb.append("varargs "); } if ((access & Opcodes.ACC_BRIDGE) != 0) { sb.append("bridge "); } sb.append(name); appendDescriptor(sb, METHOD_DESCRIPTOR, desc); if (exceptions != null && exceptions.length > 0) { sb.append(" throws "); for (final String exception : exceptions) { appendDescriptor(sb, INTERNAL_NAME, exception); sb.append(' '); } } sb.append('\n'); addText(sb); final NashornTextifier t = createNashornTextifier(); addText(t.getText()); return t; }
From source file:com.github.jasmo.obfuscate.FullAccessFlags.java
License:Open Source License
private int access(int access) { int a = Opcodes.ACC_PUBLIC; if ((access & Opcodes.ACC_NATIVE) != 0) a |= Opcodes.ACC_NATIVE;//from ww w. j a v a 2 s . c om if ((access & Opcodes.ACC_ABSTRACT) != 0) a |= Opcodes.ACC_ABSTRACT; if ((access & Opcodes.ACC_ANNOTATION) != 0) a |= Opcodes.ACC_ANNOTATION; if ((access & Opcodes.ACC_BRIDGE) != 0) a |= Opcodes.ACC_BRIDGE; //if ((access & Opcodes.ACC_DEPRECATED) != 0) a |= Opcodes.ACC_DEPRECATED; if ((access & Opcodes.ACC_ENUM) != 0) a |= Opcodes.ACC_ENUM; if ((access & Opcodes.ACC_FINAL) != 0) a |= Opcodes.ACC_FINAL; if ((access & Opcodes.ACC_INTERFACE) != 0) a |= Opcodes.ACC_INTERFACE; if ((access & Opcodes.ACC_MANDATED) != 0) a |= Opcodes.ACC_MANDATED; if ((access & Opcodes.ACC_MODULE) != 0) a |= Opcodes.ACC_MODULE; if ((access & Opcodes.ACC_OPEN) != 0) a |= Opcodes.ACC_OPEN; if ((access & Opcodes.ACC_STATIC) != 0) a |= Opcodes.ACC_STATIC; if ((access & Opcodes.ACC_STATIC_PHASE) != 0) a |= Opcodes.ACC_STATIC_PHASE; if ((access & Opcodes.ACC_STRICT) != 0) a |= Opcodes.ACC_STRICT; if ((access & Opcodes.ACC_SUPER) != 0) a |= Opcodes.ACC_SUPER; if ((access & Opcodes.ACC_SYNCHRONIZED) != 0) a |= Opcodes.ACC_SYNCHRONIZED; if ((access & Opcodes.ACC_SYNTHETIC) != 0) a |= Opcodes.ACC_SYNTHETIC; if ((access & Opcodes.ACC_TRANSIENT) != 0) a |= Opcodes.ACC_TRANSIENT; if ((access & Opcodes.ACC_TRANSITIVE) != 0) a |= Opcodes.ACC_TRANSITIVE; if ((access & Opcodes.ACC_VARARGS) != 0) a |= Opcodes.ACC_VARARGS; if ((access & Opcodes.ACC_VOLATILE) != 0) a |= Opcodes.ACC_VOLATILE; return a; }
From source file:com.github.jasmo.obfuscate.ScrambleMethods.java
License:Open Source License
@Override public void transform(Map<String, ClassNode> classMap) { this.classMap = classMap; // loads all jre libraries from 'java.class.path' system property this.env = ClassPath.getInstance(); // todo: add more in-depth verification List<String> pass = Arrays.asList("main", "createUI"); // reset the unique string generator, so that is starts at 'a' generator.reset();/*ww w.j av a 2 s . c o m*/ Map<String, String> mappings = new HashMap<>(); List<MethodNode> methods = new LinkedList<>(); for (ClassNode c : classMap.values()) methods.addAll(c.methods); // shuffle the methods so that there isn't a naming pattern Collections.shuffle(methods); // create obfuscated name mappings methods: for (MethodNode m : methods) { ClassNode owner = getOwner(m); // skip entry points, constructors etc if (m.name.indexOf('<') != -1 || pass.contains(m.name) || (m.access & Opcodes.ACC_NATIVE) != 0) { log.debug("Skipping method: {}.{}{}", owner.name, m.name, m.desc); continue; } Stack<ClassNode> stack = new Stack<>(); stack.add(owner); // check this is the top-level method while (stack.size() > 0) { ClassNode node = stack.pop(); if (node != owner && getMethod(node, m.name, m.desc) != null) // not top-level member continue methods; // push superclass ClassNode parent = getClassNode(node.superName); if (parent != null) stack.push(parent); // push interfaces Set<ClassNode> interfaces = new HashSet<>(); String[] interfacesNames = node.interfaces.toArray(new String[node.interfaces.size()]); for (String iname : interfacesNames) { ClassNode iface = getClassNode(iname); if (iface != null) { interfaces.add(iface); } } stack.addAll(interfaces); } // generate obfuscated name String name = generator.next(); stack.add(owner); // go through all sub-classes, and define the new name // regardless of if the method exists in the given class or not while (stack.size() > 0) { ClassNode node = stack.pop(); String key = node.name + '.' + m.name + m.desc; mappings.put(key, name); // push subclasses classMap.values().forEach(c -> { if (c.superName.equals(node.name) || c.interfaces.contains(node.name)) stack.push(c); }); } } BytecodeHelper.applyMappings(classMap, mappings); }
From source file:com.google.devtools.build.android.desugar.CoreLibrarySupport.java
License:Open Source License
/** Includes the given method definition in any applicable core interface emulation logic. */ public void registerIfEmulatedCoreInterface(int access, String owner, String name, String desc, String[] exceptions) {//from ww w . j av a2s.c o m Class<?> emulated = getEmulatedCoreClassOrInterface(owner); if (emulated == null) { return; } checkArgument(emulated.isInterface(), "Shouldn't be called for a class: %s.%s", owner, name); checkArgument( BitFlags.noneSet(access, Opcodes.ACC_ABSTRACT | Opcodes.ACC_NATIVE | Opcodes.ACC_STATIC | Opcodes.ACC_BRIDGE), "Should only be called for default methods: %s.%s", owner, name); emulatedDefaultMethods.put(name + ":" + desc, EmulatedMethod.create(access, emulated, name, desc, exceptions)); }
From source file:com.google.devtools.build.android.desugar.InterfaceDesugaring.java
License:Open Source License
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { MethodVisitor result;/*from w ww. jav a 2s . c om*/ if (BitFlags.isSet(accessFlags, Opcodes.ACC_INTERFACE) && BitFlags.noneSet(access, Opcodes.ACC_ABSTRACT | Opcodes.ACC_BRIDGE) && !"<clinit>".equals(name)) { checkArgument(BitFlags.noneSet(access, Opcodes.ACC_NATIVE), "Forbidden per JLS ch 9.4"); boolean isLambdaBody = name.startsWith("lambda$") && BitFlags.isSet(access, Opcodes.ACC_SYNTHETIC); if (isLambdaBody) { access &= ~Opcodes.ACC_PUBLIC; // undo visibility change from LambdaDesugaring // Rename lambda method to reflect the new owner. Not doing so confuses LambdaDesugaring // if it's run over this class again. name += COMPANION_SUFFIX; } if (BitFlags.isSet(access, Opcodes.ACC_STATIC)) { // Completely move static interface methods, which requires rewriting call sites result = companion().visitMethod(access & ~Opcodes.ACC_PRIVATE, name, desc, signature, exceptions); } else { MethodVisitor abstractDest; if (isLambdaBody) { // Completely move lambda bodies, which requires rewriting call sites access &= ~Opcodes.ACC_PRIVATE; abstractDest = null; } else { // Make default methods abstract but move their implementation into a static method with // corresponding signature. Doesn't require callsite rewriting but implementing classes // may need to implement default methods explicitly. checkArgument(BitFlags.noneSet(access, Opcodes.ACC_PRIVATE), "Unexpected private interface method %s.%s : %s", name, internalName, desc); abstractDest = super.visitMethod(access | Opcodes.ACC_ABSTRACT, name, desc, signature, exceptions); } // TODO(b/37110951): adjust signature with explicit receiver type, which may be generic MethodVisitor codeDest = companion().visitMethod(access | Opcodes.ACC_STATIC, name, companionDefaultMethodDescriptor(internalName, desc), (String) null, // drop signature, since given one doesn't include the new param exceptions); result = abstractDest != null ? new MultiplexAnnotations(codeDest, abstractDest) : codeDest; } } else { result = super.visitMethod(access, name, desc, signature, exceptions); } return result != null ? new InterfaceInvocationRewriter(result) : null; }