Java Code Examples for org.jf.dexlib2.AccessFlags

The following examples show how to use org.jf.dexlib2.AccessFlags. These examples are extracted from open source projects. 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 Project: ZjDroid   Source File: MethodAnalyzer.java    License: Apache License 2.0 6 votes vote down vote up
private void analyzeExecuteInline(@Nonnull AnalyzedInstruction analyzedInstruction) {
    if (inlineResolver == null) {
        throw new AnalysisException("Cannot analyze an odexed instruction unless we are deodexing");
    }

    Instruction35mi instruction = (Instruction35mi)analyzedInstruction.instruction;
    Method resolvedMethod = inlineResolver.resolveExecuteInline(analyzedInstruction);

    Opcode deodexedOpcode;
    int acccessFlags = resolvedMethod.getAccessFlags();
    if (AccessFlags.STATIC.isSet(acccessFlags)) {
        deodexedOpcode = Opcode.INVOKE_STATIC;
    } else if (AccessFlags.PRIVATE.isSet(acccessFlags)) {
        deodexedOpcode = Opcode.INVOKE_DIRECT;
    } else {
        deodexedOpcode = Opcode.INVOKE_VIRTUAL;
    }

    Instruction35c deodexedInstruction = new ImmutableInstruction35c(deodexedOpcode, instruction.getRegisterCount(),
            instruction.getRegisterC(), instruction.getRegisterD(), instruction.getRegisterE(),
            instruction.getRegisterF(), instruction.getRegisterG(), resolvedMethod);

    analyzedInstruction.setDeodexedInstruction(deodexedInstruction);
    analyzeInstruction(analyzedInstruction);
}
 
Example 2
Source Project: ZjDroid   Source File: MethodAnalyzer.java    License: Apache License 2.0 6 votes vote down vote up
private void analyzeExecuteInlineRange(@Nonnull AnalyzedInstruction analyzedInstruction) {
    if (inlineResolver == null) {
        throw new AnalysisException("Cannot analyze an odexed instruction unless we are deodexing");
    }

    Instruction3rmi instruction = (Instruction3rmi)analyzedInstruction.instruction;
    Method resolvedMethod = inlineResolver.resolveExecuteInline(analyzedInstruction);

    Opcode deodexedOpcode;
    int acccessFlags = resolvedMethod.getAccessFlags();
    if (AccessFlags.STATIC.isSet(acccessFlags)) {
        deodexedOpcode = Opcode.INVOKE_STATIC_RANGE;
    } else if (AccessFlags.PRIVATE.isSet(acccessFlags)) {
        deodexedOpcode = Opcode.INVOKE_DIRECT_RANGE;
    } else {
        deodexedOpcode = Opcode.INVOKE_VIRTUAL_RANGE;
    }

    Instruction3rc deodexedInstruction = new ImmutableInstruction3rc(deodexedOpcode, instruction.getStartRegister(),
            instruction.getRegisterCount(), resolvedMethod);

    analyzedInstruction.setDeodexedInstruction(deodexedInstruction);
    analyzeInstruction(analyzedInstruction);
}
 
Example 3
Source Project: zjdroid   Source File: MethodAnalyzer.java    License: Apache License 2.0 6 votes vote down vote up
private void analyzeExecuteInline(@Nonnull AnalyzedInstruction analyzedInstruction) {
    if (inlineResolver == null) {
        throw new AnalysisException("Cannot analyze an odexed instruction unless we are deodexing");
    }

    Instruction35mi instruction = (Instruction35mi)analyzedInstruction.instruction;
    Method resolvedMethod = inlineResolver.resolveExecuteInline(analyzedInstruction);

    Opcode deodexedOpcode;
    int acccessFlags = resolvedMethod.getAccessFlags();
    if (AccessFlags.STATIC.isSet(acccessFlags)) {
        deodexedOpcode = Opcode.INVOKE_STATIC;
    } else if (AccessFlags.PRIVATE.isSet(acccessFlags)) {
        deodexedOpcode = Opcode.INVOKE_DIRECT;
    } else {
        deodexedOpcode = Opcode.INVOKE_VIRTUAL;
    }

    Instruction35c deodexedInstruction = new ImmutableInstruction35c(deodexedOpcode, instruction.getRegisterCount(),
            instruction.getRegisterC(), instruction.getRegisterD(), instruction.getRegisterE(),
            instruction.getRegisterF(), instruction.getRegisterG(), resolvedMethod);

    analyzedInstruction.setDeodexedInstruction(deodexedInstruction);
    analyzeInstruction(analyzedInstruction);
}
 
Example 4
Source Project: zjdroid   Source File: MethodAnalyzer.java    License: Apache License 2.0 6 votes vote down vote up
private void analyzeExecuteInlineRange(@Nonnull AnalyzedInstruction analyzedInstruction) {
    if (inlineResolver == null) {
        throw new AnalysisException("Cannot analyze an odexed instruction unless we are deodexing");
    }

    Instruction3rmi instruction = (Instruction3rmi)analyzedInstruction.instruction;
    Method resolvedMethod = inlineResolver.resolveExecuteInline(analyzedInstruction);

    Opcode deodexedOpcode;
    int acccessFlags = resolvedMethod.getAccessFlags();
    if (AccessFlags.STATIC.isSet(acccessFlags)) {
        deodexedOpcode = Opcode.INVOKE_STATIC_RANGE;
    } else if (AccessFlags.PRIVATE.isSet(acccessFlags)) {
        deodexedOpcode = Opcode.INVOKE_DIRECT_RANGE;
    } else {
        deodexedOpcode = Opcode.INVOKE_VIRTUAL_RANGE;
    }

    Instruction3rc deodexedInstruction = new ImmutableInstruction3rc(deodexedOpcode, instruction.getStartRegister(),
            instruction.getRegisterCount(), resolvedMethod);

    analyzedInstruction.setDeodexedInstruction(deodexedInstruction);
    analyzeInstruction(analyzedInstruction);
}
 
Example 5
Source Project: HeyGirl   Source File: MethodAnalyzer.java    License: Apache License 2.0 6 votes vote down vote up
private void analyzeExecuteInline(@Nonnull AnalyzedInstruction analyzedInstruction) {
    if (inlineResolver == null) {
        throw new AnalysisException("Cannot analyze an odexed instruction unless we are deodexing");
    }

    Instruction35mi instruction = (Instruction35mi)analyzedInstruction.instruction;
    Method resolvedMethod = inlineResolver.resolveExecuteInline(analyzedInstruction);

    Opcode deodexedOpcode;
    int acccessFlags = resolvedMethod.getAccessFlags();
    if (AccessFlags.STATIC.isSet(acccessFlags)) {
        deodexedOpcode = Opcode.INVOKE_STATIC;
    } else if (AccessFlags.PRIVATE.isSet(acccessFlags)) {
        deodexedOpcode = Opcode.INVOKE_DIRECT;
    } else {
        deodexedOpcode = Opcode.INVOKE_VIRTUAL;
    }

    Instruction35c deodexedInstruction = new ImmutableInstruction35c(deodexedOpcode, instruction.getRegisterCount(),
            instruction.getRegisterC(), instruction.getRegisterD(), instruction.getRegisterE(),
            instruction.getRegisterF(), instruction.getRegisterG(), resolvedMethod);

    analyzedInstruction.setDeodexedInstruction(deodexedInstruction);
    analyzeInstruction(analyzedInstruction);
}
 
Example 6
Source Project: HeyGirl   Source File: MethodAnalyzer.java    License: Apache License 2.0 6 votes vote down vote up
private void analyzeExecuteInlineRange(@Nonnull AnalyzedInstruction analyzedInstruction) {
    if (inlineResolver == null) {
        throw new AnalysisException("Cannot analyze an odexed instruction unless we are deodexing");
    }

    Instruction3rmi instruction = (Instruction3rmi)analyzedInstruction.instruction;
    Method resolvedMethod = inlineResolver.resolveExecuteInline(analyzedInstruction);

    Opcode deodexedOpcode;
    int acccessFlags = resolvedMethod.getAccessFlags();
    if (AccessFlags.STATIC.isSet(acccessFlags)) {
        deodexedOpcode = Opcode.INVOKE_STATIC_RANGE;
    } else if (AccessFlags.PRIVATE.isSet(acccessFlags)) {
        deodexedOpcode = Opcode.INVOKE_DIRECT_RANGE;
    } else {
        deodexedOpcode = Opcode.INVOKE_VIRTUAL_RANGE;
    }

    Instruction3rc deodexedInstruction = new ImmutableInstruction3rc(deodexedOpcode, instruction.getStartRegister(),
            instruction.getRegisterCount(), resolvedMethod);

    analyzedInstruction.setDeodexedInstruction(deodexedInstruction);
    analyzeInstruction(analyzedInstruction);
}
 
Example 7
Source Project: PATDroid   Source File: SmaliClassDetailLoader.java    License: Apache License 2.0 6 votes vote down vote up
private static int translateAccessFlags(int accessFlags) {
        int f = 0;
        f |= (AccessFlags.ABSTRACT.isSet(accessFlags) ? Modifier.ABSTRACT : 0);
//        f |= (AccessFlags.ANNOTATION.isSet(accessFlags) ? Modifier.ANNOTATION : 0);
//        f |= (AccessFlags.BRIDGE.isSet(accessFlags) ? Modifier.BRIDGE : 0);
//        f |= (AccessFlags.CONSTRUCTOR.isSet(accessFlags) ? Modifier.CONSTRUCTOR : 0);
//        f |= (AccessFlags.DECLARED_SYNCHRONIZED.isSet(accessFlags) ? Modifier.DECLARED_SYNCHRONIZED : 0);
//        f |= (AccessFlags.ENUM.isSet(accessFlags) ? Modifier.ENUM : 0);
        f |= (AccessFlags.FINAL.isSet(accessFlags) ? Modifier.FINAL : 0);
        f |= (AccessFlags.INTERFACE.isSet(accessFlags) ? Modifier.INTERFACE : 0);
        f |= (AccessFlags.NATIVE.isSet(accessFlags) ? Modifier.NATIVE : 0);
        f |= (AccessFlags.PRIVATE.isSet(accessFlags) ? Modifier.PRIVATE : 0);
        f |= (AccessFlags.PROTECTED.isSet(accessFlags) ? Modifier.PROTECTED : 0);
        f |= (AccessFlags.PUBLIC.isSet(accessFlags) ? Modifier.PUBLIC : 0);
        f |= (AccessFlags.STATIC.isSet(accessFlags) ? Modifier.STATIC : 0);
        f |= (AccessFlags.STRICTFP.isSet(accessFlags) ? Modifier.STRICT : 0);
        f |= (AccessFlags.SYNCHRONIZED.isSet(accessFlags) ? Modifier.SYNCHRONIZED : 0);
//        f |= (AccessFlags.SYNTHETIC.isSet(accessFlags) ? Modifier.SYNTHETIC : 0);
        f |= (AccessFlags.TRANSIENT.isSet(accessFlags) ? Modifier.TRANSIENT : 0);
//        f |= (AccessFlags.VARARGS.isSet(accessFlags) ? Modifier.VARARGS : 0);
        f |= (AccessFlags.VOLATILE.isSet(accessFlags) ? Modifier.VOLATILE : 0);
        return f;
    }
 
Example 8
Source Project: ZjDroid   Source File: MethodAnalyzer.java    License: Apache License 2.0 6 votes vote down vote up
private void analyzeExecuteInline(@Nonnull AnalyzedInstruction analyzedInstruction) {
    if (inlineResolver == null) {
        throw new AnalysisException("Cannot analyze an odexed instruction unless we are deodexing");
    }

    Instruction35mi instruction = (Instruction35mi)analyzedInstruction.instruction;
    Method resolvedMethod = inlineResolver.resolveExecuteInline(analyzedInstruction);

    Opcode deodexedOpcode;
    int acccessFlags = resolvedMethod.getAccessFlags();
    if (AccessFlags.STATIC.isSet(acccessFlags)) {
        deodexedOpcode = Opcode.INVOKE_STATIC;
    } else if (AccessFlags.PRIVATE.isSet(acccessFlags)) {
        deodexedOpcode = Opcode.INVOKE_DIRECT;
    } else {
        deodexedOpcode = Opcode.INVOKE_VIRTUAL;
    }

    Instruction35c deodexedInstruction = new ImmutableInstruction35c(deodexedOpcode, instruction.getRegisterCount(),
            instruction.getRegisterC(), instruction.getRegisterD(), instruction.getRegisterE(),
            instruction.getRegisterF(), instruction.getRegisterG(), resolvedMethod);

    analyzedInstruction.setDeodexedInstruction(deodexedInstruction);
    analyzeInstruction(analyzedInstruction);
}
 
Example 9
Source Project: ZjDroid   Source File: MethodAnalyzer.java    License: Apache License 2.0 6 votes vote down vote up
private void analyzeExecuteInlineRange(@Nonnull AnalyzedInstruction analyzedInstruction) {
    if (inlineResolver == null) {
        throw new AnalysisException("Cannot analyze an odexed instruction unless we are deodexing");
    }

    Instruction3rmi instruction = (Instruction3rmi)analyzedInstruction.instruction;
    Method resolvedMethod = inlineResolver.resolveExecuteInline(analyzedInstruction);

    Opcode deodexedOpcode;
    int acccessFlags = resolvedMethod.getAccessFlags();
    if (AccessFlags.STATIC.isSet(acccessFlags)) {
        deodexedOpcode = Opcode.INVOKE_STATIC_RANGE;
    } else if (AccessFlags.PRIVATE.isSet(acccessFlags)) {
        deodexedOpcode = Opcode.INVOKE_DIRECT_RANGE;
    } else {
        deodexedOpcode = Opcode.INVOKE_VIRTUAL_RANGE;
    }

    Instruction3rc deodexedInstruction = new ImmutableInstruction3rc(deodexedOpcode, instruction.getStartRegister(),
            instruction.getRegisterCount(), resolvedMethod);

    analyzedInstruction.setDeodexedInstruction(deodexedInstruction);
    analyzeInstruction(analyzedInstruction);
}
 
Example 10
Source Project: ZjDroid   Source File: MethodAnalyzer.java    License: Apache License 2.0 5 votes vote down vote up
private boolean canAccessClass(@Nonnull ClassDef accessorClassDef, @Nonnull ClassDef accesseeClassDef) {
    if (AccessFlags.PUBLIC.isSet(accesseeClassDef.getAccessFlags())) {
        return true;
    }

    // Classes can only be public or package private. Any private or protected inner classes are actually
    // package private.
    return getPackage(accesseeClassDef.getType()).equals(getPackage(accessorClassDef.getType()));
}
 
Example 11
Source Project: ZjDroid   Source File: MethodDefinition.java    License: Apache License 2.0 5 votes vote down vote up
private static void writeAccessFlags(IndentingWriter writer, int accessFlags)
        throws IOException {
    for (AccessFlags accessFlag: AccessFlags.getAccessFlagsForMethod(accessFlags)) {
        writer.write(accessFlag.toString());
        writer.write(' ');
    }
}
 
Example 12
Source Project: ZjDroid   Source File: MethodDefinition.java    License: Apache License 2.0 5 votes vote down vote up
private static void writeParameters(IndentingWriter writer, Method method,
                                    List<? extends MethodParameter> parameters,
                                    baksmaliOptions options) throws IOException {
    boolean isStatic = AccessFlags.STATIC.isSet(method.getAccessFlags());
    int registerNumber = isStatic?0:1;
    for (MethodParameter parameter: parameters) {
        String parameterType = parameter.getType();
        String parameterName = parameter.getName();
        Collection<? extends Annotation> annotations = parameter.getAnnotations();
        if (parameterName != null || annotations.size() != 0) {
            writer.write(".param p");
            writer.printSignedIntAsDec(registerNumber);

            if (parameterName != null && options.outputDebugInfo) {
                writer.write(", ");
                ReferenceFormatter.writeStringReference(writer, parameterName);
            }
            writer.write("    # ");
            writer.write(parameterType);
            writer.write("\n");
            if (annotations.size() > 0) {
                writer.indent(4);
                AnnotationFormatter.writeTo(writer, annotations);
                writer.deindent(4);
                writer.write(".end param\n");
            }
        }

        registerNumber++;
        if (TypeUtils.isWideType(parameterType)) {
            registerNumber++;
        }
    }
}
 
Example 13
Source Project: ZjDroid   Source File: FieldDefinition.java    License: Apache License 2.0 5 votes vote down vote up
public static void writeTo(IndentingWriter writer, Field field, boolean setInStaticConstructor) throws IOException {
    EncodedValue initialValue = field.getInitialValue();
    int accessFlags = field.getAccessFlags();

    if (setInStaticConstructor &&
            AccessFlags.STATIC.isSet(accessFlags) &&
            AccessFlags.FINAL.isSet(accessFlags) &&
            initialValue != null) {
        if (!EncodedValueUtils.isDefaultValue(initialValue)) {
            writer.write("# The value of this static final field might be set in the static constructor\n");
        } else {
            // don't write out the default initial value for static final fields that get set in the static
            // constructor
            initialValue = null;
        }
    }

    writer.write(".field ");
    writeAccessFlags(writer, field.getAccessFlags());
    writer.write(field.getName());
    writer.write(':');
    writer.write(field.getType());
    if (initialValue != null) {
        writer.write(" = ");
        EncodedValueAdaptor.writeTo(writer, initialValue);
    }

    writer.write('\n');

    Collection<? extends Annotation> annotations = field.getAnnotations();
    if (annotations.size() > 0) {
        writer.indent(4);
        AnnotationFormatter.writeTo(writer, annotations);
        writer.deindent(4);
        writer.write(".end field\n");
    }
}
 
Example 14
Source Project: atlas   Source File: PatchFieldTool.java    License: Apache License 2.0 5 votes vote down vote up
public static DexFile addField(DexFile dexFile, final String className, final Field field) {
    DexRewriter rewriter = new DexRewriter(new RewriterModule() {
        @Nonnull
        @Override
        public Rewriter<ClassDef> getClassDefRewriter(@Nonnull Rewriters rewriters) {
            return new ClassDefRewriter(rewriters) {
                @Nonnull
                @Override
                public ClassDef rewrite(@Nonnull ClassDef classDef) {
                    if (classDef.getType().equals(className)) {
                        return new RewrittenClassDef(classDef) {
                            @Nonnull
                            @Override
                            public Iterable<? extends Field> getInstanceFields() {
                                if ((field.getAccessFlags() & AccessFlags.STATIC.getValue()) == 0) {
                                    return Iterables.concat(super.getInstanceFields(), ImmutableList.of(field));
                                }
                                return super.getInstanceFields();
                            }

                            @Nonnull
                            @Override
                            public Iterable<? extends Field> getStaticFields() {
                                if ((field.getAccessFlags() & AccessFlags.STATIC.getValue()) != 0) {
                                    return Iterables.concat(super.getStaticFields(), ImmutableList.of(field));
                                }
                                return super.getStaticFields();
                            }
                        };
                    }
                    return super.rewrite(classDef);
                }
            };
        }
    });

    return rewriter.rewriteDexFile(dexFile);
}
 
Example 15
Source Project: atlas   Source File: MethodDefinition.java    License: Apache License 2.0 5 votes vote down vote up
private static void writeAccessFlags(IndentingWriter writer, int accessFlags)
        throws IOException {
    for (AccessFlags accessFlag : AccessFlags.getAccessFlagsForMethod(accessFlags)) {
        writer.write(accessFlag.toString());
        writer.write(' ');
    }
}
 
Example 16
Source Project: atlas   Source File: MethodDefinition.java    License: Apache License 2.0 5 votes vote down vote up
private static void writeParameters(IndentingWriter writer, Method method,
                                    List<? extends MethodParameter> parameters,
                                    BaksmaliOptions options) throws IOException {
    boolean isStatic = AccessFlags.STATIC.isSet(method.getAccessFlags());
    int registerNumber = isStatic ? 0 : 1;
    for (MethodParameter parameter : parameters) {
        String parameterType = parameter.getType();
        String parameterName = parameter.getName();
        Collection<? extends Annotation> annotations = parameter.getAnnotations();
        if (parameterName != null || annotations.size() != 0) {
            writer.write(".param p");
            writer.printSignedIntAsDec(registerNumber);

            if (parameterName != null && options.debugInfo) {
                writer.write(", ");
                ReferenceFormatter.writeStringReference(writer, parameterName);
            }
            writer.write("    # ");
            writer.write(parameterType);
            writer.write("\n");
            if (annotations.size() > 0) {
                writer.indent(4);

                String containingClass = null;
                if (options.implicitReferences) {
                    containingClass = method.getDefiningClass();
                }
                AnnotationFormatter.writeTo(writer, annotations, containingClass);
                writer.deindent(4);
                writer.write(".end param\n");
            }
        }

        registerNumber++;
        if (TypeUtils.isWideType(parameterType)) {
            registerNumber++;
        }
    }
}
 
Example 17
Source Project: zjdroid   Source File: MethodAnalyzer.java    License: Apache License 2.0 5 votes vote down vote up
private boolean canAccessClass(@Nonnull ClassDef accessorClassDef, @Nonnull ClassDef accesseeClassDef) {
    if (AccessFlags.PUBLIC.isSet(accesseeClassDef.getAccessFlags())) {
        return true;
    }

    // Classes can only be public or package private. Any private or protected inner classes are actually
    // package private.
    return getPackage(accesseeClassDef.getType()).equals(getPackage(accessorClassDef.getType()));
}
 
Example 18
Source Project: zjdroid   Source File: MethodDefinition.java    License: Apache License 2.0 5 votes vote down vote up
private static void writeAccessFlags(IndentingWriter writer, int accessFlags)
        throws IOException {
    for (AccessFlags accessFlag: AccessFlags.getAccessFlagsForMethod(accessFlags)) {
        writer.write(accessFlag.toString());
        writer.write(' ');
    }
}
 
Example 19
Source Project: zjdroid   Source File: MethodDefinition.java    License: Apache License 2.0 5 votes vote down vote up
private static void writeParameters(IndentingWriter writer, Method method,
                                    List<? extends MethodParameter> parameters,
                                    baksmaliOptions options) throws IOException {
    boolean isStatic = AccessFlags.STATIC.isSet(method.getAccessFlags());
    int registerNumber = isStatic?0:1;
    for (MethodParameter parameter: parameters) {
        String parameterType = parameter.getType();
        String parameterName = parameter.getName();
        Collection<? extends Annotation> annotations = parameter.getAnnotations();
        if (parameterName != null || annotations.size() != 0) {
            writer.write(".param p");
            writer.printSignedIntAsDec(registerNumber);

            if (parameterName != null && options.outputDebugInfo) {
                writer.write(", ");
                ReferenceFormatter.writeStringReference(writer, parameterName);
            }
            writer.write("    # ");
            writer.write(parameterType);
            writer.write("\n");
            if (annotations.size() > 0) {
                writer.indent(4);
                AnnotationFormatter.writeTo(writer, annotations);
                writer.deindent(4);
                writer.write(".end param\n");
            }
        }

        registerNumber++;
        if (TypeUtils.isWideType(parameterType)) {
            registerNumber++;
        }
    }
}
 
Example 20
Source Project: zjdroid   Source File: FieldDefinition.java    License: Apache License 2.0 5 votes vote down vote up
public static void writeTo(IndentingWriter writer, Field field, boolean setInStaticConstructor) throws IOException {
    EncodedValue initialValue = field.getInitialValue();
    int accessFlags = field.getAccessFlags();

    if (setInStaticConstructor &&
            AccessFlags.STATIC.isSet(accessFlags) &&
            AccessFlags.FINAL.isSet(accessFlags) &&
            initialValue != null) {
        if (!EncodedValueUtils.isDefaultValue(initialValue)) {
            writer.write("# The value of this static final field might be set in the static constructor\n");
        } else {
            // don't write out the default initial value for static final fields that get set in the static
            // constructor
            initialValue = null;
        }
    }

    writer.write(".field ");
    writeAccessFlags(writer, field.getAccessFlags());
    writer.write(field.getName());
    writer.write(':');
    writer.write(field.getType());
    if (initialValue != null) {
        writer.write(" = ");
        EncodedValueAdaptor.writeTo(writer, initialValue);
    }

    writer.write('\n');

    Collection<? extends Annotation> annotations = field.getAnnotations();
    if (annotations.size() > 0) {
        writer.indent(4);
        AnnotationFormatter.writeTo(writer, annotations);
        writer.deindent(4);
        writer.write(".end field\n");
    }
}
 
Example 21
@Override
public void jimplify(DexBody body) {
   	int acccessFlags = targetMethod.getAccessFlags();
       if (AccessFlags.STATIC.isSet(acccessFlags))
           jimplifyStatic(body);
       else if (AccessFlags.PRIVATE.isSet(acccessFlags))
           jimplifySpecial(body);
       else
           jimplifyVirtual(body);
}
 
Example 22
Source Project: HeyGirl   Source File: MethodAnalyzer.java    License: Apache License 2.0 5 votes vote down vote up
private boolean canAccessClass(@Nonnull ClassDef accessorClassDef, @Nonnull ClassDef accesseeClassDef) {
    if (AccessFlags.PUBLIC.isSet(accesseeClassDef.getAccessFlags())) {
        return true;
    }

    // Classes can only be public or package private. Any private or protected inner classes are actually
    // package private.
    return getPackage(accesseeClassDef.getType()).equals(getPackage(accessorClassDef.getType()));
}
 
Example 23
Source Project: HeyGirl   Source File: MethodDefinition.java    License: Apache License 2.0 5 votes vote down vote up
private static void writeAccessFlags(IndentingWriter writer, int accessFlags)
        throws IOException {
    for (AccessFlags accessFlag: AccessFlags.getAccessFlagsForMethod(accessFlags)) {
        writer.write(accessFlag.toString());
        writer.write(' ');
    }
}
 
Example 24
Source Project: HeyGirl   Source File: MethodDefinition.java    License: Apache License 2.0 5 votes vote down vote up
private static void writeParameters(IndentingWriter writer, Method method,
                                    List<? extends MethodParameter> parameters,
                                    baksmaliOptions options) throws IOException {
    boolean isStatic = AccessFlags.STATIC.isSet(method.getAccessFlags());
    int registerNumber = isStatic?0:1;
    for (MethodParameter parameter: parameters) {
        String parameterType = parameter.getType();
        String parameterName = parameter.getName();
        Collection<? extends Annotation> annotations = parameter.getAnnotations();
        if (parameterName != null || annotations.size() != 0) {
            writer.write(".param p");
            writer.printSignedIntAsDec(registerNumber);

            if (parameterName != null && options.outputDebugInfo) {
                writer.write(", ");
                ReferenceFormatter.writeStringReference(writer, parameterName);
            }
            writer.write("    # ");
            writer.write(parameterType);
            writer.write("\n");
            if (annotations.size() > 0) {
                writer.indent(4);
                AnnotationFormatter.writeTo(writer, annotations);
                writer.deindent(4);
                writer.write(".end param\n");
            }
        }

        registerNumber++;
        if (TypeUtils.isWideType(parameterType)) {
            registerNumber++;
        }
    }
}
 
Example 25
Source Project: HeyGirl   Source File: FieldDefinition.java    License: Apache License 2.0 5 votes vote down vote up
public static void writeTo(IndentingWriter writer, Field field, boolean setInStaticConstructor) throws IOException {
    EncodedValue initialValue = field.getInitialValue();
    int accessFlags = field.getAccessFlags();

    if (setInStaticConstructor &&
            AccessFlags.STATIC.isSet(accessFlags) &&
            AccessFlags.FINAL.isSet(accessFlags) &&
            initialValue != null) {
        if (!EncodedValueUtils.isDefaultValue(initialValue)) {
            writer.write("# The value of this static final field might be set in the static constructor\n");
        } else {
            // don't write out the default initial value for static final fields that get set in the static
            // constructor
            initialValue = null;
        }
    }

    writer.write(".field ");
    writeAccessFlags(writer, field.getAccessFlags());
    writer.write(field.getName());
    writer.write(':');
    writer.write(field.getType());
    if (initialValue != null) {
        writer.write(" = ");
        EncodedValueAdaptor.writeTo(writer, initialValue);
    }

    writer.write('\n');

    Collection<? extends Annotation> annotations = field.getAnnotations();
    if (annotations.size() > 0) {
        writer.indent(4);
        AnnotationFormatter.writeTo(writer, annotations);
        writer.deindent(4);
        writer.write(".end field\n");
    }
}
 
Example 26
Source Project: PATDroid   Source File: SmaliClassDetailLoader.java    License: Apache License 2.0 5 votes vote down vote up
private MethodInfo translateMethod(ClassInfo ci, Method method, IdentityHashMap<MethodInfo, MethodImplementation> collector) {
    final ClassInfo retType = Dalvik.findOrCreateClass(ci.scope, method.getReturnType());
    final ImmutableList<ClassInfo> paramTypes = findOrCreateClasses(ci.scope, method.getParameterTypes());
    final MethodSignature signature = new MethodSignature(method.getName(), paramTypes);
    final FullMethodSignature fullSignature = new FullMethodSignature(retType, signature);
    final int accessFlags = translateAccessFlags(method.getAccessFlags());
    final MethodInfo mi = new MethodInfo(ci, fullSignature, accessFlags, AccessFlags.SYNTHETIC.isSet(method.getAccessFlags()));
    Log.msg("Translating method: %s", mi.toString());
    collector.put(mi, method.getImplementation());
    return mi;
}
 
Example 27
Source Project: ZjDroid   Source File: MethodAnalyzer.java    License: Apache License 2.0 5 votes vote down vote up
private boolean canAccessClass(@Nonnull ClassDef accessorClassDef, @Nonnull ClassDef accesseeClassDef) {
    if (AccessFlags.PUBLIC.isSet(accesseeClassDef.getAccessFlags())) {
        return true;
    }

    // Classes can only be public or package private. Any private or protected inner classes are actually
    // package private.
    return getPackage(accesseeClassDef.getType()).equals(getPackage(accessorClassDef.getType()));
}
 
Example 28
Source Project: ZjDroid   Source File: MethodDefinition.java    License: Apache License 2.0 5 votes vote down vote up
private static void writeAccessFlags(IndentingWriter writer, int accessFlags)
        throws IOException {
    for (AccessFlags accessFlag: AccessFlags.getAccessFlagsForMethod(accessFlags)) {
        writer.write(accessFlag.toString());
        writer.write(' ');
    }
}
 
Example 29
Source Project: ZjDroid   Source File: MethodDefinition.java    License: Apache License 2.0 5 votes vote down vote up
private static void writeParameters(IndentingWriter writer, Method method,
                                    List<? extends MethodParameter> parameters,
                                    baksmaliOptions options) throws IOException {
    boolean isStatic = AccessFlags.STATIC.isSet(method.getAccessFlags());
    int registerNumber = isStatic?0:1;
    for (MethodParameter parameter: parameters) {
        String parameterType = parameter.getType();
        String parameterName = parameter.getName();
        Collection<? extends Annotation> annotations = parameter.getAnnotations();
        if (parameterName != null || annotations.size() != 0) {
            writer.write(".param p");
            writer.printSignedIntAsDec(registerNumber);

            if (parameterName != null && options.outputDebugInfo) {
                writer.write(", ");
                ReferenceFormatter.writeStringReference(writer, parameterName);
            }
            writer.write("    # ");
            writer.write(parameterType);
            writer.write("\n");
            if (annotations.size() > 0) {
                writer.indent(4);
                AnnotationFormatter.writeTo(writer, annotations);
                writer.deindent(4);
                writer.write(".end param\n");
            }
        }

        registerNumber++;
        if (TypeUtils.isWideType(parameterType)) {
            registerNumber++;
        }
    }
}
 
Example 30
Source Project: ZjDroid   Source File: FieldDefinition.java    License: Apache License 2.0 5 votes vote down vote up
public static void writeTo(IndentingWriter writer, Field field, boolean setInStaticConstructor) throws IOException {
    EncodedValue initialValue = field.getInitialValue();
    int accessFlags = field.getAccessFlags();

    if (setInStaticConstructor &&
            AccessFlags.STATIC.isSet(accessFlags) &&
            AccessFlags.FINAL.isSet(accessFlags) &&
            initialValue != null) {
        if (!EncodedValueUtils.isDefaultValue(initialValue)) {
            writer.write("# The value of this static final field might be set in the static constructor\n");
        } else {
            // don't write out the default initial value for static final fields that get set in the static
            // constructor
            initialValue = null;
        }
    }

    writer.write(".field ");
    writeAccessFlags(writer, field.getAccessFlags());
    writer.write(field.getName());
    writer.write(':');
    writer.write(field.getType());
    if (initialValue != null) {
        writer.write(" = ");
        EncodedValueAdaptor.writeTo(writer, initialValue);
    }

    writer.write('\n');

    Collection<? extends Annotation> annotations = field.getAnnotations();
    if (annotations.size() > 0) {
        writer.indent(4);
        AnnotationFormatter.writeTo(writer, annotations);
        writer.deindent(4);
        writer.write(".end field\n");
    }
}