Java Code Examples for org.jf.util.StringUtils

The following examples show how to use org.jf.util.StringUtils. 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: StringIdItem.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
public static SectionAnnotator makeAnnotator(@Nonnull DexAnnotator annotator, @Nonnull MapItem mapItem) {
    return new SectionAnnotator(annotator, mapItem) {
        @Nonnull @Override public String getItemName() {
            return "string_id_item";
        }

        @Override
        public void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            int stringDataOffset = dexFile.readSmallUint(out.getCursor());
            try {
                String stringValue = dexFile.getString(itemIndex);
                out.annotate(4, "string_data_item[0x%x]: \"%s\"", stringDataOffset,
                        StringUtils.escapeString(stringValue));
                return;
            } catch (Exception ex) {
                System.err.print("Error while resolving string value at index: ");
                System.err.print(itemIndex);
                ex.printStackTrace(System.err);
            }

            out.annotate(4, "string_id_item[0x%x]", stringDataOffset);
        }
    };
}
 
Example 2
Source Project: ZjDroid   Source File: StringDataItem.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
public static SectionAnnotator makeAnnotator(@Nonnull DexAnnotator annotator, @Nonnull MapItem mapItem) {
    return new SectionAnnotator(annotator, mapItem) {
        @Nonnull @Override public String getItemName() {
            return "string_data_item";
        }

        @Override
        protected void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            DexReader reader = dexFile.readerAt(out.getCursor());
            int utf16Length = reader.readSmallUleb128();
            out.annotateTo(reader.getOffset(), "utf16_size = %d", utf16Length);

            String value = reader.readString(utf16Length);
            out.annotateTo(reader.getOffset() + 1, "data = \"%s\"", StringUtils.escapeString(value));
        }
    };
}
 
Example 3
Source Project: ZjDroid   Source File: ReferenceUtil.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
public static String getReferenceString(Reference reference) {
    if (reference instanceof StringReference) {
        return String.format("\"%s\"", StringUtils.escapeString(((StringReference)reference).getString()));
    }
    if (reference instanceof TypeReference) {
        return ((TypeReference)reference).getType();
    }
    if (reference instanceof FieldReference) {
        return getFieldDescriptor((FieldReference)reference);
    }
    if (reference instanceof MethodReference) {
        return getMethodDescriptor((MethodReference)reference);
    }
    return null;
}
 
Example 4
Source Project: zjdroid   Source File: StringIdItem.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
public static SectionAnnotator makeAnnotator(@Nonnull DexAnnotator annotator, @Nonnull MapItem mapItem) {
    return new SectionAnnotator(annotator, mapItem) {
        @Nonnull @Override public String getItemName() {
            return "string_id_item";
        }

        @Override
        public void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            int stringDataOffset = dexFile.readSmallUint(out.getCursor());
            try {
                String stringValue = dexFile.getString(itemIndex);
                out.annotate(4, "string_data_item[0x%x]: \"%s\"", stringDataOffset,
                        StringUtils.escapeString(stringValue));
                return;
            } catch (Exception ex) {
                System.err.print("Error while resolving string value at index: ");
                System.err.print(itemIndex);
                ex.printStackTrace(System.err);
            }

            out.annotate(4, "string_id_item[0x%x]", stringDataOffset);
        }
    };
}
 
Example 5
Source Project: zjdroid   Source File: StringDataItem.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
public static SectionAnnotator makeAnnotator(@Nonnull DexAnnotator annotator, @Nonnull MapItem mapItem) {
    return new SectionAnnotator(annotator, mapItem) {
        @Nonnull @Override public String getItemName() {
            return "string_data_item";
        }

        @Override
        protected void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            DexReader reader = dexFile.readerAt(out.getCursor());
            int utf16Length = reader.readSmallUleb128();
            out.annotateTo(reader.getOffset(), "utf16_size = %d", utf16Length);

            String value = reader.readString(utf16Length);
            out.annotateTo(reader.getOffset() + 1, "data = \"%s\"", StringUtils.escapeString(value));
        }
    };
}
 
Example 6
Source Project: zjdroid   Source File: ReferenceUtil.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
public static String getReferenceString(Reference reference) {
    if (reference instanceof StringReference) {
        return String.format("\"%s\"", StringUtils.escapeString(((StringReference)reference).getString()));
    }
    if (reference instanceof TypeReference) {
        return ((TypeReference)reference).getType();
    }
    if (reference instanceof FieldReference) {
        return getFieldDescriptor((FieldReference)reference);
    }
    if (reference instanceof MethodReference) {
        return getMethodDescriptor((MethodReference)reference);
    }
    return null;
}
 
Example 7
Source Project: HeyGirl   Source File: StringIdItem.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
public static SectionAnnotator makeAnnotator(@Nonnull DexAnnotator annotator, @Nonnull MapItem mapItem) {
    return new SectionAnnotator(annotator, mapItem) {
        @Nonnull @Override public String getItemName() {
            return "string_id_item";
        }

        @Override
        public void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            int stringDataOffset = dexFile.readSmallUint(out.getCursor());
            try {
                String stringValue = dexFile.getString(itemIndex);
                out.annotate(4, "string_data_item[0x%x]: \"%s\"", stringDataOffset,
                        StringUtils.escapeString(stringValue));
                return;
            } catch (Exception ex) {
                System.err.print("Error while resolving string value at index: ");
                System.err.print(itemIndex);
                ex.printStackTrace(System.err);
            }

            out.annotate(4, "string_id_item[0x%x]", stringDataOffset);
        }
    };
}
 
Example 8
Source Project: HeyGirl   Source File: StringDataItem.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
public static SectionAnnotator makeAnnotator(@Nonnull DexAnnotator annotator, @Nonnull MapItem mapItem) {
    return new SectionAnnotator(annotator, mapItem) {
        @Nonnull @Override public String getItemName() {
            return "string_data_item";
        }

        @Override
        protected void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            DexReader reader = dexFile.readerAt(out.getCursor());
            int utf16Length = reader.readSmallUleb128();
            out.annotateTo(reader.getOffset(), "utf16_size = %d", utf16Length);

            String value = reader.readString(utf16Length);
            out.annotateTo(reader.getOffset() + 1, "data = \"%s\"", StringUtils.escapeString(value));
        }
    };
}
 
Example 9
Source Project: HeyGirl   Source File: ReferenceUtil.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
public static String getReferenceString(Reference reference) {
    if (reference instanceof StringReference) {
        return String.format("\"%s\"", StringUtils.escapeString(((StringReference)reference).getString()));
    }
    if (reference instanceof TypeReference) {
        return ((TypeReference)reference).getType();
    }
    if (reference instanceof FieldReference) {
        return getFieldDescriptor((FieldReference)reference);
    }
    if (reference instanceof MethodReference) {
        return getMethodDescriptor((MethodReference)reference);
    }
    return null;
}
 
Example 10
Source Project: ZjDroid   Source File: StringIdItem.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
public static SectionAnnotator makeAnnotator(@Nonnull DexAnnotator annotator, @Nonnull MapItem mapItem) {
    return new SectionAnnotator(annotator, mapItem) {
        @Nonnull @Override public String getItemName() {
            return "string_id_item";
        }

        @Override
        public void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            int stringDataOffset = dexFile.readSmallUint(out.getCursor());
            try {
                String stringValue = dexFile.getString(itemIndex);
                out.annotate(4, "string_data_item[0x%x]: \"%s\"", stringDataOffset,
                        StringUtils.escapeString(stringValue));
                return;
            } catch (Exception ex) {
                System.err.print("Error while resolving string value at index: ");
                System.err.print(itemIndex);
                ex.printStackTrace(System.err);
            }

            out.annotate(4, "string_id_item[0x%x]", stringDataOffset);
        }
    };
}
 
Example 11
Source Project: ZjDroid   Source File: StringDataItem.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
public static SectionAnnotator makeAnnotator(@Nonnull DexAnnotator annotator, @Nonnull MapItem mapItem) {
    return new SectionAnnotator(annotator, mapItem) {
        @Nonnull @Override public String getItemName() {
            return "string_data_item";
        }

        @Override
        protected void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            DexReader reader = dexFile.readerAt(out.getCursor());
            int utf16Length = reader.readSmallUleb128();
            out.annotateTo(reader.getOffset(), "utf16_size = %d", utf16Length);

            String value = reader.readString(utf16Length);
            out.annotateTo(reader.getOffset() + 1, "data = \"%s\"", StringUtils.escapeString(value));
        }
    };
}
 
Example 12
Source Project: ZjDroid   Source File: ReferenceUtil.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
public static String getReferenceString(Reference reference) {
    if (reference instanceof StringReference) {
        return String.format("\"%s\"", StringUtils.escapeString(((StringReference)reference).getString()));
    }
    if (reference instanceof TypeReference) {
        return ((TypeReference)reference).getType();
    }
    if (reference instanceof FieldReference) {
        return getFieldDescriptor((FieldReference)reference);
    }
    if (reference instanceof MethodReference) {
        return getMethodDescriptor((MethodReference)reference);
    }
    return null;
}
 
Example 13
Source Project: ZjDroid   Source File: StringIdItem.java    License: Apache License 2.0 5 votes vote down vote up
public static String getReferenceAnnotation(@Nonnull DexBackedDexFile dexFile, int stringIndex, boolean quote) {
    try {
        String string = dexFile.getString(stringIndex);
        if (quote) {
            string = String.format("\"%s\"", StringUtils.escapeString(string));
        }
        return String.format("string_id_item[%d]: %s", stringIndex, string);
    } catch (Exception ex) {
        ex.printStackTrace(System.err);
    }
    return String.format("string_id_item[%d]", stringIndex);
}
 
Example 14
Source Project: ZjDroid   Source File: SetSourceFileMethodItem.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean writeTo(IndentingWriter writer) throws IOException {
    writer.write(".source");

    if (sourceFile != null) {
        writer.write(" \"");
        StringUtils.writeEscapedString(writer, sourceFile);
        writer.write('"');
    }
    return true;
}
 
Example 15
Source Project: ZjDroid   Source File: ClassDefinition.java    License: Apache License 2.0 5 votes vote down vote up
private void writeSourceFile(IndentingWriter writer) throws IOException {
    String sourceFile = classDef.getSourceFile();
    if (sourceFile != null) {
        writer.write(".source \"");
        StringUtils.writeEscapedString(writer, sourceFile);
        writer.write("\"\n");
    }
}
 
Example 16
Source Project: atlas   Source File: SetSourceFileMethodItem.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean writeTo(IndentingWriter writer) throws IOException {
    writer.write(".source");

    if (sourceFile != null) {
        writer.write(" \"");
        StringUtils.writeEscapedString(writer, sourceFile);
        writer.write('"');
    }
    return true;
}
 
Example 17
Source Project: atlas   Source File: ClassDefinition.java    License: Apache License 2.0 5 votes vote down vote up
private void writeSourceFile(IndentingWriter writer) throws IOException {
    String sourceFile = classDef.getSourceFile();
    if (sourceFile != null) {
        writer.write(".source \"");
        StringUtils.writeEscapedString(writer, sourceFile);
        writer.write("\"\n");
    }
}
 
Example 18
Source Project: zjdroid   Source File: StringIdItem.java    License: Apache License 2.0 5 votes vote down vote up
public static String getReferenceAnnotation(@Nonnull DexBackedDexFile dexFile, int stringIndex, boolean quote) {
    try {
        String string = dexFile.getString(stringIndex);
        if (quote) {
            string = String.format("\"%s\"", StringUtils.escapeString(string));
        }
        return String.format("string_id_item[%d]: %s", stringIndex, string);
    } catch (Exception ex) {
        ex.printStackTrace(System.err);
    }
    return String.format("string_id_item[%d]", stringIndex);
}
 
Example 19
Source Project: zjdroid   Source File: SetSourceFileMethodItem.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean writeTo(IndentingWriter writer) throws IOException {
    writer.write(".source");

    if (sourceFile != null) {
        writer.write(" \"");
        StringUtils.writeEscapedString(writer, sourceFile);
        writer.write('"');
    }
    return true;
}
 
Example 20
Source Project: zjdroid   Source File: ClassDefinition.java    License: Apache License 2.0 5 votes vote down vote up
private void writeSourceFile(IndentingWriter writer) throws IOException {
    String sourceFile = classDef.getSourceFile();
    if (sourceFile != null) {
        writer.write(".source \"");
        StringUtils.writeEscapedString(writer, sourceFile);
        writer.write("\"\n");
    }
}
 
Example 21
Source Project: HeyGirl   Source File: StringIdItem.java    License: Apache License 2.0 5 votes vote down vote up
public static String getReferenceAnnotation(@Nonnull DexBackedDexFile dexFile, int stringIndex, boolean quote) {
    try {
        String string = dexFile.getString(stringIndex);
        if (quote) {
            string = String.format("\"%s\"", StringUtils.escapeString(string));
        }
        return String.format("string_id_item[%d]: %s", stringIndex, string);
    } catch (Exception ex) {
        ex.printStackTrace(System.err);
    }
    return String.format("string_id_item[%d]", stringIndex);
}
 
Example 22
Source Project: HeyGirl   Source File: SetSourceFileMethodItem.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean writeTo(IndentingWriter writer) throws IOException {
    writer.write(".source");

    if (sourceFile != null) {
        writer.write(" \"");
        StringUtils.writeEscapedString(writer, sourceFile);
        writer.write('"');
    }
    return true;
}
 
Example 23
Source Project: HeyGirl   Source File: ClassDefinition.java    License: Apache License 2.0 5 votes vote down vote up
private void writeSourceFile(IndentingWriter writer) throws IOException {
    String sourceFile = classDef.getSourceFile();
    if (sourceFile != null) {
        writer.write(".source \"");
        StringUtils.writeEscapedString(writer, sourceFile);
        writer.write("\"\n");
    }
}
 
Example 24
Source Project: ZjDroid   Source File: StringIdItem.java    License: Apache License 2.0 5 votes vote down vote up
public static String getReferenceAnnotation(@Nonnull DexBackedDexFile dexFile, int stringIndex, boolean quote) {
    try {
        String string = dexFile.getString(stringIndex);
        if (quote) {
            string = String.format("\"%s\"", StringUtils.escapeString(string));
        }
        return String.format("string_id_item[%d]: %s", stringIndex, string);
    } catch (Exception ex) {
        ex.printStackTrace(System.err);
    }
    return String.format("string_id_item[%d]", stringIndex);
}
 
Example 25
Source Project: ZjDroid   Source File: SetSourceFileMethodItem.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean writeTo(IndentingWriter writer) throws IOException {
    writer.write(".source");

    if (sourceFile != null) {
        writer.write(" \"");
        StringUtils.writeEscapedString(writer, sourceFile);
        writer.write('"');
    }
    return true;
}
 
Example 26
Source Project: ZjDroid   Source File: ClassDefinition.java    License: Apache License 2.0 5 votes vote down vote up
private void writeSourceFile(IndentingWriter writer) throws IOException {
    String sourceFile = classDef.getSourceFile();
    if (sourceFile != null) {
        writer.write(".source \"");
        StringUtils.writeEscapedString(writer, sourceFile);
        writer.write("\"\n");
    }
}
 
Example 27
Source Project: ZjDroid   Source File: HeaderItem.java    License: Apache License 2.0 4 votes vote down vote up
@Nonnull
public static SectionAnnotator makeAnnotator(@Nonnull DexAnnotator annotator, @Nonnull MapItem mapItem) {
    return new SectionAnnotator(annotator, mapItem) {
        @Nonnull @Override public String getItemName() {
            return "header_item";
        }

        @Override
        protected void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            int startOffset = out.getCursor();
            int headerSize;

            StringBuilder magicBuilder = new StringBuilder();
            for (int i=0; i<8; i++) {
                magicBuilder.append((char)dexFile.readUbyte(startOffset + i));
            }

            out.annotate(8, "magic: %s", StringUtils.escapeString(magicBuilder.toString()));
            out.annotate(4, "checksum");
            out.annotate(20, "signature");
            out.annotate(4, "file_size: %d", dexFile.readInt(out.getCursor()));

            headerSize = dexFile.readInt(out.getCursor());
            out.annotate(4, "header_size: %d", headerSize);

            int endianTag = dexFile.readInt(out.getCursor());
            out.annotate(4, "endian_tag: 0x%x (%s)", endianTag, getEndianText(endianTag));

            out.annotate(4, "link_size: %d", dexFile.readInt(out.getCursor()));
            out.annotate(4, "link_offset: 0x%x", dexFile.readInt(out.getCursor()));

            out.annotate(4, "map_off: 0x%x", dexFile.readInt(out.getCursor()));

            out.annotate(4, "string_ids_size: %d", dexFile.readInt(out.getCursor()));
            out.annotate(4, "string_ids_off: 0x%x", dexFile.readInt(out.getCursor()));

            out.annotate(4, "type_ids_size: %d", dexFile.readInt(out.getCursor()));
            out.annotate(4, "type_ids_off: 0x%x", dexFile.readInt(out.getCursor()));

            out.annotate(4, "proto_ids_size: %d", dexFile.readInt(out.getCursor()));
            out.annotate(4, "proto_ids_off: 0x%x", dexFile.readInt(out.getCursor()));

            out.annotate(4, "field_ids_size: %d", dexFile.readInt(out.getCursor()));
            out.annotate(4, "field_ids_off: 0x%x", dexFile.readInt(out.getCursor()));

            out.annotate(4, "method_ids_size: %d", dexFile.readInt(out.getCursor()));
            out.annotate(4, "method_ids_off: 0x%x", dexFile.readInt(out.getCursor()));

            out.annotate(4, "class_defs_size: %d", dexFile.readInt(out.getCursor()));
            out.annotate(4, "class_defs_off: 0x%x", dexFile.readInt(out.getCursor()));

            out.annotate(4, "data_size: %d", dexFile.readInt(out.getCursor()));
            out.annotate(4, "data_off: 0x%x", dexFile.readInt(out.getCursor()));

            if (headerSize > ITEM_SIZE) {
                out.annotateTo(headerSize, "header padding");
            }
        }
    };
}
 
Example 28
Source Project: ZjDroid   Source File: CharRenderer.java    License: Apache License 2.0 4 votes vote down vote up
public static void writeTo(IndentingWriter writer, char val) throws IOException {
    writer.write('\'');
    StringUtils.writeEscapedChar(writer, val);
    writer.write('\'');
}
 
Example 29
Source Project: ZjDroid   Source File: ReferenceFormatter.java    License: Apache License 2.0 4 votes vote down vote up
public static void writeStringReference(IndentingWriter writer, String item) throws IOException {
    writer.write('"');
    StringUtils.writeEscapedString(writer, item);
    writer.write('"');
}
 
Example 30
Source Project: atlas   Source File: CharRenderer.java    License: Apache License 2.0 4 votes vote down vote up
public static void writeTo(IndentingWriter writer, char val) throws IOException {
    writer.write('\'');
    StringUtils.writeEscapedChar(writer, val);
    writer.write('\'');
}