FieldId(TypeId<D> declaringType, TypeId<V> type, String name) { if (declaringType == null || type == null || name == null) { throw new NullPointerException(); } this.declaringType = declaringType; this.type = type; this.name = name; this.nat = new CstNat(new CstString(name), new CstString(type.name)); this.constant = new CstFieldRef(declaringType.constant, nat); }
private void addDependencies(DirectClassFile classFile) { for (Constant constant : classFile.getConstantPool().getEntries()) { if (constant instanceof CstType) { checkDescriptor(((CstType) constant).getClassType().getDescriptor()); } else if (constant instanceof CstFieldRef) { checkDescriptor(((CstFieldRef) constant).getType().getDescriptor()); } else if (constant instanceof CstBaseMethodRef) { checkPrototype(((CstBaseMethodRef) constant).getPrototype()); } } FieldList fields = classFile.getFields(); int nbField = fields.size(); for (int i = 0; i < nbField; i++) { checkDescriptor(fields.get(i).getDescriptor().getString()); } MethodList methods = classFile.getMethods(); int nbMethods = methods.size(); for (int i = 0; i < nbMethods; i++) { checkPrototype(Prototype.intern(methods.get(i).getDescriptor().getString())); } } private void checkPrototype(Prototype proto) {
/** {@inheritDoc} */ @Override public void writeTo0(DexFile file, AnnotatedOutput out) { ByteArray bytes = value.getBytes(); int utf16Size = value.getUtf16Size(); if (out.annotates()) { out.annotate(Leb128.unsignedLeb128Size(utf16Size), "utf16_size: " + Hex.u4(utf16Size)); out.annotate(bytes.size() + 1, value.toQuoted()); } out.writeUleb128(utf16Size); out.write(bytes); out.writeByte(0); }
/** * Gets the write size for a given value. * * @param value {@code non-null;} the string value * @return {@code >= 2}; the write size, in bytes */ private static int writeSize(CstString value) { int utf16Size = value.getUtf16Size(); // The +1 is for the '\0' termination byte. return Leb128.unsignedLeb128Size(utf16Size) + value.getUtf8Size() + 1; }
/** {@inheritDoc} */ @Override protected int compareTo0(OffsettedItem other) { StringDataItem otherData = (StringDataItem) other; return value.compareTo(otherData.value); } }
/** {@inheritDoc} */ @Override public int hashCode() { return value.hashCode(); }
/** * Gets whether this instance has the name of a signature * polymorphic method. * * @return {@code true} iff the name suggest it could be * signature polymorphic method. */ public final boolean isSignaturePolymorphic() { final String INVOKE = "invoke"; final String INVOKE_EXACT = "invokeExact"; int nameLength = name.getUtf8Size(); if (nameLength == INVOKE.length()) { return name.getString().equals(INVOKE); } else if (nameLength == INVOKE_EXACT.length()) { return name.getString().equals(INVOKE_EXACT); } return false; } }
/** * Constructs an instance from a {@code String}. * * @param string {@code non-null;} the UTF-8 value as a string */ public CstString(String string) { if (string == null) { throw new NullPointerException("string == null"); } this.string = string.intern(); this.bytes = new ByteArray(stringToUtf8Bytes(string)); }
/** {@inheritDoc} */ @Override public int byteLength() { // Add 6 for the standard attribute header: the attribute name // index (2 bytes) and the attribute length (4 bytes). return 6 + smapString.getUtf8Size(); }
/** {@inheritDoc} */ @Override public void writeTo0(DexFile file, AnnotatedOutput out) { ByteArray bytes = value.getBytes(); int utf16Size = value.getUtf16Size(); if (out.annotates()) { out.annotate(Leb128.unsignedLeb128Size(utf16Size), "utf16_size: " + Hex.u4(utf16Size)); out.annotate(bytes.size() + 1, value.toQuoted()); } out.writeUleb128(utf16Size); out.write(bytes); out.writeByte(0); }
/** * Gets the write size for a given value. * * @param value {@code non-null;} the string value * @return {@code >= 2}; the write size, in bytes */ private static int writeSize(CstString value) { int utf16Size = value.getUtf16Size(); // The +1 is for the '\0' termination byte. return Leb128Utils.unsignedLeb128Size(utf16Size) + value.getUtf8Size() + 1; }
/** {@inheritDoc} */ @Override public String toString() { return "string{\"" + toHuman() + "\"}"; }
/** {@inheritDoc} */ @Override public boolean equals(Object other) { if (!(other instanceof StringIdItem)) { return false; } StringIdItem otherString = (StringIdItem) other; return value.equals(otherString.value); }
/** {@inheritDoc} */ @Override public int hashCode() { return sourceFile.hashCode() + address + line; }
/** * Constructs an instance from a {@code String}. * * @param string {@code non-null;} the UTF-8 value as a string */ public CstString(String string) { if (string == null) { throw new NullPointerException("string == null"); } this.string = string.intern(); this.bytes = new ByteArray(stringToUtf8Bytes(string)); }
/** {@inheritDoc} */ @Override public int byteLength() { // Add 6 for the standard attribute header: the attribute name // index (2 bytes) and the attribute length (4 bytes). return 6 + smapString.getUtf8Size(); }
/** {@inheritDoc} */ @Override public void writeTo0(DexFile file, AnnotatedOutput out) { ByteArray bytes = value.getBytes(); int utf16Size = value.getUtf16Size(); if (out.annotates()) { out.annotate(Leb128Utils.unsignedLeb128Size(utf16Size), "utf16_size: " + Hex.u4(utf16Size)); out.annotate(bytes.size() + 1, value.toQuoted()); } out.writeUleb128(utf16Size); out.write(bytes); out.writeByte(0); }