com.android.dx.rop.cst.CstString Java Examples
The following examples show how to use
com.android.dx.rop.cst.CstString.
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: OutputFinisher.java From buck with Apache License 2.0 | 6 votes |
/** * Helper for {@link #getAllConstants} which adds all the info for * a single {@code RegisterSpec}. * * @param result {@code non-null;} result set to add to * @param spec {@code null-ok;} register spec to add */ private static void addConstants(HashSet<Constant> result, RegisterSpec spec) { if (spec == null) { return; } LocalItem local = spec.getLocalItem(); CstString name = local.getName(); CstString signature = local.getSignature(); Type type = spec.getType(); if (type != Type.KNOWN_NULL) { result.add(CstType.intern(type)); } if (name != null) { result.add(name); } if (signature != null) { result.add(signature); } }
Example #2
Source File: BasicBlocker.java From Box with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override public void visitConstant(int opcode, int offset, int length, Constant cst, int value) { visitCommon(offset, length, true); if (cst instanceof CstMemberRef || cst instanceof CstType || cst instanceof CstString || cst instanceof CstInvokeDynamic || cst instanceof CstMethodHandle || cst instanceof CstProtoRef) { /* * Instructions with these sorts of constants have the * possibility of throwing, so this instruction needs to * end its block (since it can throw, and possible-throws * are branch points). */ visitThrowing(offset, length, true); } }
Example #3
Source File: DexFile.java From Box with Apache License 2.0 | 6 votes |
/** * Interns the given constant in the appropriate section of this * instance, or do nothing if the given constant isn't the sort * that should be interned. * * @param cst {@code non-null;} constant to possibly intern */ /*package*/ void internIfAppropriate(Constant cst) { if (cst == null) { throw new NullPointerException("cst == null"); } if (cst instanceof CstString) { stringIds.intern((CstString) cst); } else if (cst instanceof CstType) { typeIds.intern((CstType) cst); } else if (cst instanceof CstBaseMethodRef) { methodIds.intern((CstBaseMethodRef) cst); } else if (cst instanceof CstFieldRef) { fieldIds.intern((CstFieldRef) cst); } else if (cst instanceof CstEnumRef) { fieldIds.intern(((CstEnumRef) cst).getFieldRef()); } else if (cst instanceof CstProtoRef) { protoIds.intern(((CstProtoRef) cst).getPrototype()); } else if (cst instanceof CstMethodHandle) { methodHandles.intern((CstMethodHandle) cst); } }
Example #4
Source File: Annotation.java From buck with Apache License 2.0 | 6 votes |
/** * Add an element to the set of (name, value) pairs for this instance. * It is an error to call this method if there is a preexisting element * with the same name. * * @param pair {@code non-null;} the (name, value) pair to add to this instance */ public void add(NameValuePair pair) { throwIfImmutable(); if (pair == null) { throw new NullPointerException("pair == null"); } CstString name = pair.getName(); if (elements.get(name) != null) { throw new IllegalArgumentException("name already added: " + name); } elements.put(name, pair); }
Example #5
Source File: DexFile.java From J2ME-Loader with Apache License 2.0 | 6 votes |
/** * Interns the given constant in the appropriate section of this * instance, or do nothing if the given constant isn't the sort * that should be interned. * * @param cst {@code non-null;} constant to possibly intern */ /*package*/ void internIfAppropriate(Constant cst) { if (cst instanceof CstString) { stringIds.intern((CstString) cst); } else if (cst instanceof CstType) { typeIds.intern((CstType) cst); } else if (cst instanceof CstBaseMethodRef) { methodIds.intern((CstBaseMethodRef) cst); } else if (cst instanceof CstFieldRef) { fieldIds.intern((CstFieldRef) cst); } else if (cst instanceof CstEnumRef) { fieldIds.intern(((CstEnumRef) cst).getFieldRef()); } else if (cst == null) { throw new NullPointerException("cst == null"); } }
Example #6
Source File: LocalVariableList.java From J2ME-Loader with Apache License 2.0 | 6 votes |
/** * Returns an instance which is the result of merging the two * given instances, where one instance should have only type * descriptors and the other only type signatures. The merged * result is identical to the one with descriptors, except that * any element whose {name, index, start, length} matches an * element in the signature list gets augmented with the * corresponding signature. The result is immutable. * * @param descriptorList {@code non-null;} list with descriptors * @param signatureList {@code non-null;} list with signatures * @return {@code non-null;} the merged result */ public static LocalVariableList mergeDescriptorsAndSignatures( LocalVariableList descriptorList, LocalVariableList signatureList) { int descriptorSize = descriptorList.size(); LocalVariableList result = new LocalVariableList(descriptorSize); for (int i = 0; i < descriptorSize; i++) { Item item = descriptorList.get(i); Item signatureItem = signatureList.itemToLocal(item); if (signatureItem != null) { CstString signature = signatureItem.getSignature(); item = item.withSignature(signature); } result.set(i, item); } result.setImmutable(); return result; }
Example #7
Source File: DexFile.java From buck with Apache License 2.0 | 6 votes |
/** * Gets the {@link IndexedItem} corresponding to the given constant, * if it is a constant that has such a correspondence, or return * {@code null} if it isn't such a constant. This will throw * an exception if the given constant <i>should</i> have been found * but wasn't. * * @param cst {@code non-null;} the constant to look up * @return {@code null-ok;} its corresponding item, if it has a corresponding * item, or {@code null} if it's not that sort of constant */ /*package*/ IndexedItem findItemOrNull(Constant cst) { IndexedItem item; if (cst instanceof CstString) { return stringIds.get(cst); } else if (cst instanceof CstType) { return typeIds.get(cst); } else if (cst instanceof CstBaseMethodRef) { return methodIds.get(cst); } else if (cst instanceof CstFieldRef) { return fieldIds.get(cst); } else { return null; } }
Example #8
Source File: LocalVariableList.java From Box with Apache License 2.0 | 6 votes |
/** * Returns an instance which is the result of merging the two * given instances, where one instance should have only type * descriptors and the other only type signatures. The merged * result is identical to the one with descriptors, except that * any element whose {name, index, start, length} matches an * element in the signature list gets augmented with the * corresponding signature. The result is immutable. * * @param descriptorList {@code non-null;} list with descriptors * @param signatureList {@code non-null;} list with signatures * @return {@code non-null;} the merged result */ public static LocalVariableList mergeDescriptorsAndSignatures( LocalVariableList descriptorList, LocalVariableList signatureList) { int descriptorSize = descriptorList.size(); LocalVariableList result = new LocalVariableList(descriptorSize); for (int i = 0; i < descriptorSize; i++) { Item item = descriptorList.get(i); Item signatureItem = signatureList.itemToLocal(item); if (signatureItem != null) { CstString signature = signatureItem.getSignature(); item = item.withSignature(signature); } result.set(i, item); } result.setImmutable(); return result; }
Example #9
Source File: ClassDefItem.java From buck with Apache License 2.0 | 6 votes |
/** * Constructs an instance. Its sets of members and annotations are * initially empty. * * @param thisClass {@code non-null;} type constant for this class * @param accessFlags access flags * @param superclass {@code null-ok;} superclass or {@code null} if * this class is a/the root class * @param interfaces {@code non-null;} list of implemented interfaces * @param sourceFile {@code null-ok;} source file name or * {@code null} if unknown */ public ClassDefItem(CstType thisClass, int accessFlags, CstType superclass, TypeList interfaces, CstString sourceFile) { if (thisClass == null) { throw new NullPointerException("thisClass == null"); } /* * TODO: Maybe check accessFlags and superclass, at * least for easily-checked stuff? */ if (interfaces == null) { throw new NullPointerException("interfaces == null"); } this.thisClass = thisClass; this.accessFlags = accessFlags; this.superclass = superclass; this.interfaces = (interfaces.size() == 0) ? null : new TypeListItem(interfaces); this.sourceFile = sourceFile; this.classData = new ClassDataItem(thisClass); this.staticValuesItem = null; this.annotationsDirectory = new AnnotationsDirectoryItem(); }
Example #10
Source File: StdAttributeFactory.java From Box with Apache License 2.0 | 6 votes |
/** * Parses a {@code SourceFile} attribute. */ private Attribute sourceFile(DirectClassFile cf, int offset, int length, ParseObserver observer) { if (length != 2) { throwBadLength(2); } ByteArray bytes = cf.getBytes(); ConstantPool pool = cf.getConstantPool(); int idx = bytes.getUnsignedShort(offset); CstString cst = (CstString) pool.get(idx); Attribute result = new AttSourceFile(cst); if (observer != null) { observer.parsed(bytes, offset, 2, "source: " + cst); } return result; }
Example #11
Source File: AttConstantValue.java From Box with Apache License 2.0 | 6 votes |
/** * Constructs an instance. * * @param constantValue {@code non-null;} the constant value, which must * be an instance of one of: {@code CstString}, * {@code CstInteger}, {@code CstLong}, * {@code CstFloat}, or {@code CstDouble} */ public AttConstantValue(TypedConstant constantValue) { super(ATTRIBUTE_NAME); if (!((constantValue instanceof CstString) || (constantValue instanceof CstInteger) || (constantValue instanceof CstLong) || (constantValue instanceof CstFloat) || (constantValue instanceof CstDouble))) { if (constantValue == null) { throw new NullPointerException("constantValue == null"); } throw new IllegalArgumentException("bad type for constantValue"); } this.constantValue = constantValue; }
Example #12
Source File: DexFile.java From Box with Apache License 2.0 | 6 votes |
/** * Gets the {@link IndexedItem} corresponding to the given constant, * if it is a constant that has such a correspondence, or return * {@code null} if it isn't such a constant. This will throw * an exception if the given constant <i>should</i> have been found * but wasn't. * * @param cst {@code non-null;} the constant to look up * @return {@code null-ok;} its corresponding item, if it has a corresponding * item, or {@code null} if it's not that sort of constant */ /*package*/ IndexedItem findItemOrNull(Constant cst) { if (cst instanceof CstString) { return stringIds.get(cst); } else if (cst instanceof CstType) { return typeIds.get(cst); } else if (cst instanceof CstBaseMethodRef) { return methodIds.get(cst); } else if (cst instanceof CstFieldRef) { return fieldIds.get(cst); } else if (cst instanceof CstEnumRef) { return fieldIds.intern(((CstEnumRef) cst).getFieldRef()); } else if (cst instanceof CstProtoRef) { return protoIds.get(cst); } else if (cst instanceof CstMethodHandle) { return methodHandles.get(cst); } else if (cst instanceof CstCallSiteRef) { return callSiteIds.get(cst); } else { return null; } }
Example #13
Source File: StringIdsSection.java From buck with Apache License 2.0 | 6 votes |
/** * Gets the index of the given string, which must have been added * to this instance. * * @param string {@code non-null;} the string to look up * @return {@code >= 0;} the string's index */ public int indexOf(CstString string) { if (string == null) { throw new NullPointerException("string == null"); } throwIfNotPrepared(); StringIdItem s = strings.get(string); if (s == null) { throw new IllegalArgumentException("not found"); } return s.getIndex(); }
Example #14
Source File: ThrowingCstInsn.java From Box with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public String getInlineString() { Constant cst = getConstant(); String constantString = cst.toHuman(); if (cst instanceof CstString) { constantString = ((CstString) cst).toQuoted(); } return constantString + " " + ThrowingInsn.toCatchString(catches); }
Example #15
Source File: AnnotationItem.java From J2ME-Loader with Apache License 2.0 | 5 votes |
/** * Write a (listing file) annotation for this instance to the given * output, that consumes no bytes of output. This is for annotating * a reference to this instance at the point of the reference. * * @param out {@code non-null;} where to output to * @param prefix {@code non-null;} prefix for each line of output */ public void annotateTo(AnnotatedOutput out, String prefix) { out.annotate(0, prefix + "visibility: " + annotation.getVisibility().toHuman()); out.annotate(0, prefix + "type: " + annotation.getType().toHuman()); for (NameValuePair pair : annotation.getNameValuePairs()) { CstString name = pair.getName(); Constant value = pair.getValue(); out.annotate(0, prefix + name.toHuman() + ": " + ValueEncoder.constantToHuman(value)); } }
Example #16
Source File: StdAttributeFactory.java From J2ME-Loader with Apache License 2.0 | 5 votes |
/** * Parses a {@code SourceDebugExtesion} attribute. */ private Attribute sourceDebugExtension(DirectClassFile cf, int offset, int length, ParseObserver observer) { ByteArray bytes = cf.getBytes().slice(offset, offset + length); CstString smapString = new CstString(bytes); Attribute result = new AttSourceDebugExtension(smapString); if (observer != null) { String decoded = smapString.getString(); observer.parsed(bytes, offset, length, "sourceDebugExtension: " + decoded); } return result; }
Example #17
Source File: AnnotationItem.java From buck with Apache License 2.0 | 5 votes |
/** * Write a (listing file) annotation for this instance to the given * output, that consumes no bytes of output. This is for annotating * a reference to this instance at the point of the reference. * * @param out {@code non-null;} where to output to * @param prefix {@code non-null;} prefix for each line of output */ public void annotateTo(AnnotatedOutput out, String prefix) { out.annotate(0, prefix + "visibility: " + annotation.getVisibility().toHuman()); out.annotate(0, prefix + "type: " + annotation.getType().toHuman()); for (NameValuePair pair : annotation.getNameValuePairs()) { CstString name = pair.getName(); Constant value = pair.getValue(); out.annotate(0, prefix + name.toHuman() + ": " + ValueEncoder.constantToHuman(value)); } }
Example #18
Source File: Annotation.java From Box with Apache License 2.0 | 5 votes |
/** * Construct an instance. It initially contains no elements. * * @param type {@code non-null;} type of the annotation * @param visibility {@code non-null;} the visibility of the annotation */ public Annotation(CstType type, AnnotationVisibility visibility) { if (type == null) { throw new NullPointerException("type == null"); } if (visibility == null) { throw new NullPointerException("visibility == null"); } this.type = type; this.visibility = visibility; this.elements = new TreeMap<CstString, NameValuePair>(); }
Example #19
Source File: NameValuePair.java From Box with Apache License 2.0 | 5 votes |
/** * Construct an instance. * * @param name {@code non-null;} the name * @param value {@code non-null;} the value */ public NameValuePair(CstString name, Constant value) { if (name == null) { throw new NullPointerException("name == null"); } if (value == null) { throw new NullPointerException("value == null"); } this.name = name; this.value = value; }
Example #20
Source File: AttSignature.java From J2ME-Loader with Apache License 2.0 | 5 votes |
/** * Constructs an instance. * * @param signature {@code non-null;} the signature string */ public AttSignature(CstString signature) { super(ATTRIBUTE_NAME); if (signature == null) { throw new NullPointerException("signature == null"); } this.signature = signature; }
Example #21
Source File: DirectClassFile.java From Box with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public CstString getSourceFile() { AttributeList attribs = getAttributes(); Attribute attSf = attribs.findFirst(AttSourceFile.ATTRIBUTE_NAME); if (attSf instanceof AttSourceFile) { return ((AttSourceFile) attSf).getSourceFile(); } return null; }
Example #22
Source File: LocalItem.java From Box with Apache License 2.0 | 5 votes |
/** * Compares two strings like String.compareTo(), excepts treats a null * as the least-possible string value. * * @return negative integer, zero, or positive integer in accordance * with Comparable.compareTo() */ private static int compareHandlesNulls(CstString a, CstString b) { if (a == b) { return 0; } else if (a == null) { return -1; } else if (b == null) { return 1; } else { return a.compareTo(b); } }
Example #23
Source File: AttSourceFile.java From J2ME-Loader with Apache License 2.0 | 5 votes |
/** * Constructs an instance. * * @param sourceFile {@code non-null;} the name of the source file */ public AttSourceFile(CstString sourceFile) { super(ATTRIBUTE_NAME); if (sourceFile == null) { throw new NullPointerException("sourceFile == null"); } this.sourceFile = sourceFile; }
Example #24
Source File: StringDataItem.java From Box with Apache License 2.0 | 5 votes |
/** * 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; }
Example #25
Source File: FieldId.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
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); }
Example #26
Source File: AnnotationUtils.java From Box with Apache License 2.0 | 5 votes |
/** * Constructs a standard {@code SourceDebugExtension} annotation. * * @param smapString {@code non-null;} the SMAP string associated with * @return {@code non-null;} the annotation */ public static Annotation makeSourceDebugExtension(CstString smapString) { Annotation result = new Annotation(SOURCE_DEBUG_EXTENSION_TYPE, SYSTEM); result.put(new NameValuePair(VALUE_STRING, smapString)); result.setImmutable(); return result; }
Example #27
Source File: AttSourceDebugExtension.java From Box with Apache License 2.0 | 5 votes |
/** * Constructs an instance. * * @param smapString {@code non-null;} the SMAP data from the class file. */ public AttSourceDebugExtension(CstString smapString) { super(ATTRIBUTE_NAME); if (smapString == null) { throw new NullPointerException("smapString == null"); } this.smapString = smapString; }
Example #28
Source File: AttSignature.java From Box with Apache License 2.0 | 5 votes |
/** * Constructs an instance. * * @param signature {@code non-null;} the signature string */ public AttSignature(CstString signature) { super(ATTRIBUTE_NAME); if (signature == null) { throw new NullPointerException("signature == null"); } this.signature = signature; }
Example #29
Source File: DebugInfoDecoder.java From buck with Apache License 2.0 | 5 votes |
/** * Constructs an instance. * * @param encoded encoded debug info * @param codesize size of code block in code units * @param regSize register size, in register units, of the register space * used by this method * @param isStatic true if method is static * @param ref method descriptor of method this debug info is for * @param file dex file this debug info will be stored in */ DebugInfoDecoder(byte[] encoded, int codesize, int regSize, boolean isStatic, CstMethodRef ref, DexFile file) { if (encoded == null) { throw new NullPointerException("encoded == null"); } this.encoded = encoded; this.isStatic = isStatic; this.desc = ref.getPrototype(); this.file = file; this.regSize = regSize; positions = new ArrayList<PositionEntry>(); locals = new ArrayList<LocalEntry>(); this.codesize = codesize; lastEntryForReg = new LocalEntry[regSize]; int idx = -1; try { idx = file.getStringIds().indexOf(new CstString("this")); } catch (IllegalArgumentException ex) { /* * Silently tolerate not finding "this". It just means that * no method has local variable info that looks like * a standard instance method. */ } thisStringIdx = idx; }
Example #30
Source File: TypeIdItem.java From J2ME-Loader with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void writeTo(DexFile file, AnnotatedOutput out) { CstType type = getDefiningClass(); CstString descriptor = type.getDescriptor(); int idx = file.getStringIds().indexOf(descriptor); if (out.annotates()) { out.annotate(0, indexString() + ' ' + descriptor.toHuman()); out.annotate(4, " descriptor_idx: " + Hex.u4(idx)); } out.writeInt(idx); }