Java Code Examples for org.jf.util.IndentingWriter#printSignedIntAsDec()

The following examples show how to use org.jf.util.IndentingWriter#printSignedIntAsDec() . 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: ArrayDataMethodItem.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public boolean writeTo(IndentingWriter writer) throws IOException {
    int elementWidth = instruction.getElementWidth();

    writer.write(".array-data ");
    writer.printSignedIntAsDec(instruction.getElementWidth());
    writer.write('\n');

    writer.indent(4);

    List<Number> elements = instruction.getArrayElements();

    String suffix = "";
    switch (elementWidth) {
        case 1:
            suffix = "t";
            break;
        case 2:
            suffix = "s";
            break;
    }

    for (Number number: elements) {
        LongRenderer.writeSignedIntOrLongTo(writer, number.longValue());
        writer.write(suffix);
        if (elementWidth == 4)
            writeResourceId(writer, number.intValue());
        writer.write("\n");
    }
    writer.deindent(4);
    writer.write(".end array-data");
    return true;
}
 
Example 2
Source File: RegisterFormatter.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
/**
 * Writes a register with the appropriate format. If baksmali.noParameterRegisters is true, then it will always
 * output a register in the v<n> format. If false, then it determines if the register is a parameter register,
 * and if so, formats it in the p<n> format instead.
 *
 * @param writer the <code>IndentingWriter</code> to write to
 * @param register the register number
 */
public void writeTo(IndentingWriter writer, int register) throws IOException {
    if (!options.noParameterRegisters) {
        if (register >= registerCount - parameterRegisterCount) {
            writer.write('p');
            writer.printSignedIntAsDec((register - (registerCount - parameterRegisterCount)));
            return;
        }
    }
    writer.write('v');
    writer.printSignedIntAsDec(register);
}
 
Example 3
Source File: MethodDefinition.java    From zjdroid with 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 4
Source File: RegisterFormatter.java    From atlas with Apache License 2.0 5 votes vote down vote up
/**
 * Writes a register with the appropriate format. If baksmali.noParameterRegisters is true, then it will always
 * output a register in the v<n> format. If false, then it determines if the register is a parameter register,
 * and if so, formats it in the p<n> format instead.
 *
 * @param writer the <code>IndentingWriter</code> to write to
 * @param register the register number
 */
public void writeTo(IndentingWriter writer, int register) throws IOException {
    if (!options.parameterRegisters) {
        if (register >= registerCount - parameterRegisterCount) {
            writer.write('p');
            writer.printSignedIntAsDec((register - (registerCount - parameterRegisterCount)));
            return;
        }
    }
    writer.write('v');
    writer.printSignedIntAsDec(register);
}
 
Example 5
Source File: MethodDefinition.java    From ZjDroid with 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 6
Source File: MethodDefinition.java    From HeyGirl with 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 7
Source File: ArrayDataMethodItem.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
public boolean writeTo(IndentingWriter writer) throws IOException {
    int elementWidth = instruction.getElementWidth();

    writer.write(".array-data ");
    writer.printSignedIntAsDec(instruction.getElementWidth());
    writer.write('\n');

    writer.indent(4);

    List<Number> elements = instruction.getArrayElements();

    String suffix = "";
    switch (elementWidth) {
        case 1:
            suffix = "t";
            break;
        case 2:
            suffix = "s";
            break;
    }

    for (Number number: elements) {
        LongRenderer.writeSignedIntOrLongTo(writer, number.longValue());
        writer.write(suffix);
        if (elementWidth == 4)
            writeResourceId(writer, number.intValue());
        writer.write("\n");
    }
    writer.deindent(4);
    writer.write(".end array-data");
    return true;
}
 
Example 8
Source File: PackedSwitchMethodItem.java    From ZjDroid with Apache License 2.0 4 votes vote down vote up
public void writeTargetTo(IndentingWriter writer) throws IOException {
    if (target >= 0) {
        writer.write('+');
    }
    writer.printSignedIntAsDec(target);
}
 
Example 9
Source File: InstructionMethodItem.java    From ZjDroid with Apache License 2.0 4 votes vote down vote up
protected void writeVtableIndex(IndentingWriter writer) throws IOException {
    writer.write("vtable@");
    writer.printSignedIntAsDec(((VtableIndexInstruction)instruction).getVtableIndex());
}
 
Example 10
Source File: InstructionMethodItem.java    From ZjDroid with Apache License 2.0 4 votes vote down vote up
protected void writeInlineIndex(IndentingWriter writer) throws IOException {
    writer.write("inline@");
    writer.printSignedIntAsDec(((InlineIndexInstruction)instruction).getInlineIndex());
}
 
Example 11
Source File: SparseSwitchMethodItem.java    From zjdroid with Apache License 2.0 4 votes vote down vote up
public void writeTargetTo(IndentingWriter writer) throws IOException {
    if (target >= 0) {
        writer.write('+');
    }
    writer.printSignedIntAsDec(target);
}
 
Example 12
Source File: PackedSwitchMethodItem.java    From zjdroid with Apache License 2.0 4 votes vote down vote up
public void writeTargetTo(IndentingWriter writer) throws IOException {
    if (target >= 0) {
        writer.write('+');
    }
    writer.printSignedIntAsDec(target);
}
 
Example 13
Source File: InstructionMethodItem.java    From zjdroid with Apache License 2.0 4 votes vote down vote up
protected void writeVtableIndex(IndentingWriter writer) throws IOException {
    writer.write("vtable@");
    writer.printSignedIntAsDec(((VtableIndexInstruction)instruction).getVtableIndex());
}
 
Example 14
Source File: InstructionMethodItem.java    From atlas with Apache License 2.0 4 votes vote down vote up
protected void writeVtableIndex(IndentingWriter writer) throws IOException {
    writer.write("vtable@");
    writer.printSignedIntAsDec(((VtableIndexInstruction)instruction).getVtableIndex());
}
 
Example 15
Source File: PackedSwitchMethodItem.java    From atlas with Apache License 2.0 4 votes vote down vote up
public void writeTargetTo(IndentingWriter writer) throws IOException {
    if (target >= 0) {
        writer.write('+');
    }
    writer.printSignedIntAsDec(target);
}
 
Example 16
Source File: SparseSwitchMethodItem.java    From ZjDroid with Apache License 2.0 4 votes vote down vote up
public void writeTargetTo(IndentingWriter writer) throws IOException {
    if (target >= 0) {
        writer.write('+');
    }
    writer.printSignedIntAsDec(target);
}
 
Example 17
Source File: MethodDefinition.java    From zjdroid with Apache License 2.0 4 votes vote down vote up
public void writeTo(IndentingWriter writer) throws IOException {
    int parameterRegisterCount = 0;
    if (!AccessFlags.STATIC.isSet(method.getAccessFlags())) {
        parameterRegisterCount++;
    }

    writer.write(".method ");
    writeAccessFlags(writer, method.getAccessFlags());
    writer.write(method.getName());
    writer.write("(");
    for (MethodParameter parameter: methodParameters) {
        String type = parameter.getType();
        writer.write(type);
        parameterRegisterCount++;
        if (TypeUtils.isWideType(type)) {
            parameterRegisterCount++;
        }
    }
    writer.write(")");
    writer.write(method.getReturnType());
    writer.write('\n');

    writer.indent(4);
    if (classDef.options.useLocalsDirective) {
        writer.write(".locals ");
        writer.printSignedIntAsDec(methodImpl.getRegisterCount() - parameterRegisterCount);
    } else {
        writer.write(".registers ");
        writer.printSignedIntAsDec(methodImpl.getRegisterCount());
    }
    writer.write('\n');
    writeParameters(writer, method, methodParameters, classDef.options);

    if (registerFormatter == null) {
        registerFormatter = new RegisterFormatter(classDef.options, methodImpl.getRegisterCount(),
                parameterRegisterCount);
    }

    AnnotationFormatter.writeTo(writer, method.getAnnotations());

    writer.write('\n');

    List<MethodItem> methodItems = getMethodItems();
    for (MethodItem methodItem: methodItems) {
        if (methodItem.writeTo(writer)) {
            writer.write('\n');
        }
    }
    writer.deindent(4);
    writer.write(".end method\n");
}
 
Example 18
Source File: PackedSwitchMethodItem.java    From HeyGirl with Apache License 2.0 4 votes vote down vote up
public void writeTargetTo(IndentingWriter writer) throws IOException {
    if (target >= 0) {
        writer.write('+');
    }
    writer.printSignedIntAsDec(target);
}
 
Example 19
Source File: InstructionMethodItem.java    From ZjDroid with Apache License 2.0 4 votes vote down vote up
protected void writeVtableIndex(IndentingWriter writer) throws IOException {
    writer.write("vtable@");
    writer.printSignedIntAsDec(((VtableIndexInstruction)instruction).getVtableIndex());
}
 
Example 20
Source File: MethodDefinition.java    From ZjDroid with Apache License 2.0 4 votes vote down vote up
public void writeTo(IndentingWriter writer) throws IOException {
    int parameterRegisterCount = 0;
    if (!AccessFlags.STATIC.isSet(method.getAccessFlags())) {
        parameterRegisterCount++;
    }

    writer.write(".method ");
    writeAccessFlags(writer, method.getAccessFlags());
    writer.write(method.getName());
    writer.write("(");
    for (MethodParameter parameter: methodParameters) {
        String type = parameter.getType();
        writer.write(type);
        parameterRegisterCount++;
        if (TypeUtils.isWideType(type)) {
            parameterRegisterCount++;
        }
    }
    writer.write(")");
    writer.write(method.getReturnType());
    writer.write('\n');

    writer.indent(4);
    if (classDef.options.useLocalsDirective) {
        writer.write(".locals ");
        writer.printSignedIntAsDec(methodImpl.getRegisterCount() - parameterRegisterCount);
    } else {
        writer.write(".registers ");
        writer.printSignedIntAsDec(methodImpl.getRegisterCount());
    }
    writer.write('\n');
    writeParameters(writer, method, methodParameters, classDef.options);

    if (registerFormatter == null) {
        registerFormatter = new RegisterFormatter(classDef.options, methodImpl.getRegisterCount(),
                parameterRegisterCount);
    }

    AnnotationFormatter.writeTo(writer, method.getAnnotations());

    writer.write('\n');

    List<MethodItem> methodItems = getMethodItems();
    for (MethodItem methodItem: methodItems) {
        if (methodItem.writeTo(writer)) {
            writer.write('\n');
        }
    }
    writer.deindent(4);
    writer.write(".end method\n");
}