Java源码示例:soot.tagkit.Tag
示例1
/**
* Returns the Android resource Id of the attribute which has the given name.
*
* @param name the attribute's name.
* @return the resource Id defined by Android or -1 if the attribute does not exist.
* @see android.R.attr
*/
public static int getAttributeResourceId(String name) {
// try to get attribute's resource Id from Androids R class. Since we
// don't want a hard-coded reference to the Android classes, we maintain
// our own list.
if (name.equals("name"))
return resId_name;
else if (name.equals("maxSdkVersion"))
return resId_maxSdkVersion;
else if (name.equals("minSdkVersion"))
return resId_minSdkVersion;
else if (name.equals("onClick"))
return resId_onClick;
// If we couldn't find the value, try to find Android's R class in Soot
SootClass rClass = Scene.v().forceResolve("android.R$attr", SootClass.BODIES);
if (!rClass.declaresFieldByName(name))
return -1;
SootField idField = rClass.getFieldByName(name);
for (Tag t : idField.getTags())
if (t instanceof IntegerConstantValueTag) {
IntegerConstantValueTag cvt = (IntegerConstantValueTag) t;
return cvt.getIntValue();
}
return -1;
}
示例2
private Set<Annotation> buildMethodParameterAnnotations(SootMethod m,
final int paramIdx) {
Set<String> skipList = new HashSet<String>();
Set<Annotation> annotations = buildCommonAnnotations(m, skipList);
for (Tag t : m.getTags()) {
if (t.getName().equals("VisibilityParameterAnnotationTag")) {
VisibilityParameterAnnotationTag vat = (VisibilityParameterAnnotationTag)t;
List<ImmutableAnnotation> visibilityItems = buildVisibilityParameterAnnotationTag
(vat, skipList, paramIdx);
annotations.addAll(visibilityItems);
}
}
return annotations;
}
示例3
public void printAllTags(PrintWriter writer){
this.writerOut = writer;
if (tags != null) {
Iterator<Tag> it = tags.iterator();
while (it.hasNext()){
printAttributeTag(it.next());
}
}
if (vbAttrs != null) {
Iterator<PosColorAttribute> vbIt = vbAttrs.iterator();
while (vbIt.hasNext()){
PosColorAttribute attr = vbIt.next();
if (attr.hasColor()){
startPrintValBoxAttr();
printSourcePositionAttr(attr.javaStartPos(), attr.javaEndPos());
printJimplePositionAttr(attr.jimpleStartPos(), attr.jimpleEndPos());
//printColorAttr(attr.color().red(), attr.color().green(), attr.color().blue(), attr.color().fg());
endPrintValBoxAttr();
}
}
}
}
示例4
@Override
public FieldVisitor visitField(int access, String name,
String desc, String signature, Object value) {
soot.Type type = AsmUtil.toJimpleType(desc);
addDep(type);
SootField field = new SootField(name, type, access);
Tag tag;
if (value instanceof Integer)
tag = new IntegerConstantValueTag((Integer) value);
else if (value instanceof Float)
tag = new FloatConstantValueTag((Float) value);
else if (value instanceof Long)
tag = new LongConstantValueTag((Long) value);
else if (value instanceof Double)
tag = new DoubleConstantValueTag((Double) value);
else if (value instanceof String)
tag = new StringConstantValueTag(value.toString());
else
tag = null;
if (tag != null)
field.addTag(tag);
if (signature != null)
field.addTag(new SignatureTag(signature));
klass.addField(field);
return new FieldBuilder(field, this);
}
示例5
private void addNodeTag( Node node, SootMethod m ) {
if( nodeToTag != null ) {
Tag tag;
if( m == null ) {
tag = new StringTag( node.toString() );
} else {
tag = new LinkTag( node.toString(), m, m.getDeclaringClass().getName() );
}
nodeToTag.put( node, tag );
}
}
示例6
private Set<Annotation> buildFieldAnnotations(SootField f) {
Set<String> skipList = new HashSet<String>();
Set<Annotation> annotations = buildCommonAnnotations(f, skipList);
for (Tag t : f.getTags()) {
if (t.getName().equals("VisibilityAnnotationTag")){
List<ImmutableAnnotation> visibilityItems = buildVisibilityAnnotationTag
((VisibilityAnnotationTag) t, skipList);
annotations.addAll(visibilityItems);
}
}
return annotations;
}
示例7
private Set<Annotation> buildMethodAnnotations(SootMethod m) {
Set<String> skipList = new HashSet<String>();
Set<Annotation> annotations = buildCommonAnnotations(m, skipList);
for (Tag t : m.getTags()) {
if (t.getName().equals("VisibilityAnnotationTag")){
List<ImmutableAnnotation> visibilityItems = buildVisibilityAnnotationTag
((VisibilityAnnotationTag) t, skipList);
annotations.addAll(visibilityItems);
}
}
return annotations;
}
示例8
/**
* Add constant tag. Should only be called if field is final.
* @param df
* @param sf
*/
private static void addConstantTag(SootField df, Field sf) {
Tag tag = null;
EncodedValue ev = sf.getInitialValue();
if (ev instanceof BooleanEncodedValue) {
tag = new IntegerConstantValueTag(((BooleanEncodedValue) ev).getValue() ==true?1:0);
} else if (ev instanceof ByteEncodedValue) {
tag = new IntegerConstantValueTag(((ByteEncodedValue) ev).getValue());
} else if (ev instanceof CharEncodedValue) {
tag = new IntegerConstantValueTag(((CharEncodedValue) ev).getValue());
} else if (ev instanceof DoubleEncodedValue) {
tag = new DoubleConstantValueTag(((DoubleEncodedValue) ev).getValue());
} else if (ev instanceof FloatEncodedValue) {
tag = new FloatConstantValueTag(((FloatEncodedValue) ev).getValue());
} else if (ev instanceof IntEncodedValue) {
tag = new IntegerConstantValueTag(((IntEncodedValue) ev).getValue());
} else if (ev instanceof LongEncodedValue) {
tag = new LongConstantValueTag(((LongEncodedValue) ev).getValue());
} else if (ev instanceof ShortEncodedValue) {
tag = new IntegerConstantValueTag(((ShortEncodedValue) ev).getValue());
} else if (ev instanceof StringEncodedValue) {
tag = new StringConstantValueTag(((StringEncodedValue) ev).getValue());
}
if (tag != null)
df.addTag(tag);
}
示例9
public Tag getTag() {
if (instructionTag == null) {
throw new RuntimeException("Must tag instruction first! (0x"
+ Integer.toHexString(codeAddress) + ": " + instruction
+ ")");
}
return instructionTag;
}
示例10
/**
* Emits the bytecode for all attributes of the class
*/
protected void generateAttributes() {
for (Tag t : sc.getTags()) {
if (t instanceof Attribute) {
cv.visitAttribute(createASMAttribute((Attribute) t));
}
}
}
示例11
/**
* Emits the bytecode for all attributes of a field
* @param fv The FieldVisitor to emit the bytecode to
* @param f The SootField the bytecode is to be emitted for
*/
protected void generateAttributes(FieldVisitor fv, SootField f) {
for (Tag t : f.getTags()) {
if (t instanceof Attribute) {
org.objectweb.asm.Attribute a = createASMAttribute((Attribute) t);
fv.visitAttribute(a);
}
}
}
示例12
/**
* Emits the bytecode for all attributes of a method
* @param fv The MethodVisitor to emit the bytecode to
* @param f The SootMethod the bytecode is to be emitted for
*/
protected void generateAttributes(MethodVisitor mv, SootMethod m) {
for (Tag t : m.getTags()) {
if (t instanceof Attribute) {
org.objectweb.asm.Attribute a = createASMAttribute((Attribute) t);
mv.visitAttribute(a);
}
}
}
示例13
private int getJavaLnOfHost(Host h){
Iterator<Tag> it = h.getTags().iterator();
while (it.hasNext()){
Tag t = it.next();
if (t instanceof SourceLnPosTag) {
return ((SourceLnPosTag)t).startLn();
}
else if (t instanceof LineNumberTag){
return (new Integer(((LineNumberTag)t).toString())).intValue();
}
}
return 0;
}
示例14
private int getJimpleLnOfHost(Host h){
Iterator<Tag> it = h.getTags().iterator();
while (it.hasNext()){
Tag t = it.next();
if (t instanceof JimpleLineNumberTag) {
return ((JimpleLineNumberTag)t).getStartLineNumber();
}
}
return 0;
}
示例15
public void printInfoTags(PrintWriter writer){
this.writerOut = writer;
Iterator<Tag> it = tags.iterator();
while (it.hasNext()){
printAttributeTag(it.next());
}
}
示例16
private int getJavaLnOfHost(Host h){
Iterator<Tag> it = h.getTags().iterator();
while (it.hasNext()){
Tag t = it.next();
//G.v().out.println(t.getClass().toString());
if (t instanceof SourceLnPosTag) {
//G.v().out.println("t is LineNumberTag");
return ((SourceLnPosTag)t).startLn();
}
else if (t instanceof LineNumberTag){
return (new Integer(((LineNumberTag)t).toString())).intValue();
}
}
return 0;
}
示例17
private int getJimpleLnOfHost(Host h){
Iterator<Tag> it = h.getTags().iterator();
while (it.hasNext()){
Tag t = it.next();
if (t instanceof JimpleLineNumberTag) {
return ((JimpleLineNumberTag)t).getStartLineNumber();
}
}
return 0;
}
示例18
/**
* Prints out the method corresponding to b Body, (declaration and body),
* in the textual format corresponding to the IR used to encode b body.
*
* @param out a PrintWriter instance to print to.
*/
private void printTo(Body b, PrintWriter out) {
b.validate();
String decl = b.getMethod().getDavaDeclaration();
{
out.println(" " + decl);
for( Iterator<Tag> tIt = b.getMethod().getTags().iterator(); tIt.hasNext(); ) {
final Tag t = tIt.next();
if (Options.v().print_tags_in_output()){
out.println(t);
}
}
out.println(" {");
/*
The locals are now printed out from within the toString method of ASTMethodNode
Nomair A Naeem 10-MARCH-2005
*/
//printLocalsInBody(b, out);
}
printStatementsInBody(b, out);
out.println(" }");
}
示例19
void setUnit(AbstractInsnNode insn, Unit u) {
if (Options.v().keep_line_number() && lastLineNumber >= 0) {
Tag lineTag = u.getTag("LineNumberTag");
if (lineTag == null) {
lineTag = new LineNumberTag(lastLineNumber);
u.addTag(lineTag);
}
else if (((LineNumberTag) lineTag).getLineNumber() != lastLineNumber)
throw new RuntimeException("Line tag mismatch");
}
Unit o = units.put(insn, u);
if (o != null)
throw new AssertionError(insn.getOpcode() + " already has a unit, " + o);
}
示例20
/**
* Copy all the tags of {from} to {to}, if {to} already contain the copied tag, then overwrite it.
*
* @param from
* @param to
*/
public static void copyTags(Unit from, Unit to)
{
List<Tag> tags = from.getTags();
for (Tag tag : tags)
{
to.removeTag(tag.getName()); //exception??
to.addTag(tag);
}
}
示例21
/**
* Finds the last assignment to the given local representing a resource ID
* by searching upwards from the given statement
*
* @param stmt
* The statement from which to look backwards
* @param local
* The variable for which to look for assignments
* @return The last value assigned to the given variable
*/
private Integer findLastResIDAssignment(Stmt stmt, Local local, BiDiInterproceduralCFG<Unit, SootMethod> cfg, Set<Stmt> doneSet) {
if (!doneSet.add(stmt))
return null;
// If this is an assign statement, we need to check whether it changes
// the variable we're looking for
if (stmt instanceof AssignStmt) {
AssignStmt assign = (AssignStmt) stmt;
if (assign.getLeftOp() == local) {
// ok, now find the new value from the right side
if (assign.getRightOp() instanceof IntConstant)
return ((IntConstant) assign.getRightOp()).value;
else if (assign.getRightOp() instanceof FieldRef) {
SootField field = ((FieldRef) assign.getRightOp()).getField();
for (Tag tag : field.getTags())
if (tag instanceof IntegerConstantValueTag)
return ((IntegerConstantValueTag) tag).getIntValue();
else
System.err.println("Constant " + field + " was of unexpected type");
} else if (assign.getRightOp() instanceof InvokeExpr) {
InvokeExpr inv = (InvokeExpr) assign.getRightOp();
if (inv.getMethod().getName().equals("getIdentifier") && inv.getMethod().getDeclaringClass().getName().equals("android.content.res.Resources") && this.resourcePackages != null) {
// The right side of the assignment is a call into the
// well-known
// Android API method for resource handling
if (inv.getArgCount() != 3) {
System.err.println("Invalid parameter count for call to getIdentifier");
return null;
}
// Find the parameter values
String resName = "";
String resID = "";
String packageName = "";
// In the trivial case, these values are constants
if (inv.getArg(0) instanceof StringConstant)
resName = ((StringConstant) inv.getArg(0)).value;
if (inv.getArg(1) instanceof StringConstant)
resID = ((StringConstant) inv.getArg(1)).value;
if (inv.getArg(2) instanceof StringConstant)
packageName = ((StringConstant) inv.getArg(2)).value;
else if (inv.getArg(2) instanceof Local)
packageName = findLastStringAssignment(stmt, (Local) inv.getArg(2), cfg);
else {
System.err.println("Unknown parameter type in call to getIdentifier");
return null;
}
// Find the resource
ARSCFileParser.AbstractResource res = findResource(resName, resID, packageName);
if (res != null)
return res.getResourceID();
}
}
}
}
// Continue the search upwards
for (Unit pred : cfg.getPredsOf(stmt)) {
if (!(pred instanceof Stmt))
continue;
Integer lastAssignment = findLastResIDAssignment((Stmt) pred, local, cfg, doneSet);
if (lastAssignment != null)
return lastAssignment;
}
return null;
}
示例22
public PAG( final SparkOptions opts ) {
this.opts = opts;
if( opts.add_tags() ) {
nodeToTag = new HashMap<Node, Tag>();
}
if (opts.rta() && opts.on_fly_cg()) {
throw new RuntimeException("Incompatible options rta:true and on-fly-cg:true for cg.spark. Use -p cg-"
+ ".spark on-fly-cg:false when using RTA.");
}
typeManager = new TypeManager(this);
if( !opts.ignore_types() ) {
typeManager.setFastHierarchy( Scene.v().getOrMakeFastHierarchy() );
}
switch( opts.set_impl() ) {
case SparkOptions.set_impl_hash:
setFactory = HashPointsToSet.getFactory();
break;
case SparkOptions.set_impl_hybrid:
setFactory = HybridPointsToSet.getFactory();
break;
case SparkOptions.set_impl_heintze:
setFactory = SharedHybridSet.getFactory();
break;
case SparkOptions.set_impl_sharedlist:
setFactory = SharedListSet.getFactory();
break;
case SparkOptions.set_impl_array:
setFactory = SortedArraySet.getFactory();
break;
case SparkOptions.set_impl_bit:
setFactory = BitPointsToSet.getFactory();
break;
case SparkOptions.set_impl_double:
P2SetFactory oldF;
P2SetFactory newF;
switch( opts.double_set_old() ) {
case SparkOptions.double_set_old_hash:
oldF = HashPointsToSet.getFactory();
break;
case SparkOptions.double_set_old_hybrid:
oldF = HybridPointsToSet.getFactory();
break;
case SparkOptions.double_set_old_heintze:
oldF = SharedHybridSet.getFactory();
break;
case SparkOptions.double_set_old_sharedlist:
oldF = SharedListSet.getFactory();
break;
case SparkOptions.double_set_old_array:
oldF = SortedArraySet.getFactory();
break;
case SparkOptions.double_set_old_bit:
oldF = BitPointsToSet.getFactory();
break;
default:
throw new RuntimeException();
}
switch( opts.double_set_new() ) {
case SparkOptions.double_set_new_hash:
newF = HashPointsToSet.getFactory();
break;
case SparkOptions.double_set_new_hybrid:
newF = HybridPointsToSet.getFactory();
break;
case SparkOptions.double_set_new_heintze:
newF = SharedHybridSet.getFactory();
break;
case SparkOptions.double_set_new_sharedlist:
newF = SharedListSet.getFactory();
break;
case SparkOptions.double_set_new_array:
newF = SortedArraySet.getFactory();
break;
case SparkOptions.double_set_new_bit:
newF = BitPointsToSet.getFactory();
break;
default:
throw new RuntimeException();
}
setFactory = DoublePointsToSet.getFactory( newF, oldF );
break;
default:
throw new RuntimeException();
}
runGeomPTA = opts.geom_pta();
}
示例23
public Map<Node, Tag> getNodeTags() {
return nodeToTag;
}
示例24
protected void addTag( Host h, Node n, Map<Node, Tag> nodeToTag, Tag unknown ) {
if( nodeToTag.containsKey( n ) ) h.addTag( nodeToTag.get(n) );
else h.addTag( unknown );
}
示例25
private EncodedValue makeConstantItem(SootField sf, Tag t) {
if (!(t instanceof ConstantValueTag))
throw new RuntimeException("error: t not ConstantValueTag.");
if (t instanceof IntegerConstantValueTag) {
Type sft = sf.getType();
IntegerConstantValueTag i = (IntegerConstantValueTag) t;
if (sft instanceof BooleanType) {
int v = i.getIntValue();
if (v == 0) {
return ImmutableBooleanEncodedValue.FALSE_VALUE;
} else if (v == 1) {
return ImmutableBooleanEncodedValue.TRUE_VALUE;
} else {
throw new RuntimeException(
"error: boolean value from int with value != 0 or 1.");
}
} else if (sft instanceof CharType) {
return new ImmutableCharEncodedValue((char) i.getIntValue());
} else if (sft instanceof ByteType) {
return new ImmutableByteEncodedValue((byte) i.getIntValue());
} else if (sft instanceof IntType) {
return new ImmutableIntEncodedValue(i.getIntValue());
} else if (sft instanceof ShortType) {
return new ImmutableShortEncodedValue((short) i.getIntValue());
} else {
throw new RuntimeException("error: unexpected constant tag type: " + t
+ " for field " + sf);
}
} else if (t instanceof LongConstantValueTag) {
LongConstantValueTag l = (LongConstantValueTag) t;
return new ImmutableLongEncodedValue(l.getLongValue());
} else if (t instanceof DoubleConstantValueTag) {
DoubleConstantValueTag d = (DoubleConstantValueTag) t;
return new ImmutableDoubleEncodedValue(d.getDoubleValue());
} else if (t instanceof FloatConstantValueTag) {
FloatConstantValueTag f = (FloatConstantValueTag) t;
return new ImmutableFloatEncodedValue(f.getFloatValue());
} else if (t instanceof StringConstantValueTag) {
StringConstantValueTag s = (StringConstantValueTag) t;
return new ImmutableStringEncodedValue(s.getStringValue());
} else
throw new RuntimeException("Unexpected constant type");
}
示例26
private void addAsClassDefItem(SootClass c) {
// add source file tag if any
String sourceFile = null;
if (c.hasTag("SourceFileTag")) {
SourceFileTag sft = (SourceFileTag) c.getTag("SourceFileTag");
sourceFile = sft.getSourceFile();
}
String classType = SootToDexUtils.getDexTypeDescriptor(c.getType());
int accessFlags = c.getModifiers();
String superClass = c.hasSuperclass() ?
SootToDexUtils.getDexTypeDescriptor(c.getSuperclass().getType()) : null;
List<String> interfaces = null;
if (!c.getInterfaces().isEmpty()) {
interfaces = new ArrayList<String>();
for (SootClass ifc : c.getInterfaces())
interfaces.add(SootToDexUtils.getDexTypeDescriptor(ifc.getType()));
}
List<BuilderField> fields = null;
if (!c.getFields().isEmpty()) {
fields = new ArrayList<BuilderField>();
for (SootField f : c.getFields()) {
// Look for a static initializer
EncodedValue staticInit = null;
for (Tag t : f.getTags()) {
if (t instanceof ConstantValueTag) {
if (staticInit != null) {
G.v().out.println("warning: more than one constant tag for field: " + f + ": "
+ t);
} else {
staticInit = makeConstantItem(f, t);
}
}
}
if (staticInit == null)
staticInit = BuilderEncodedValues.defaultValueForType
(SootToDexUtils.getDexTypeDescriptor(f.getType()));
// Build field annotations
Set<Annotation> fieldAnnotations = buildFieldAnnotations(f);
BuilderField field = dexFile.internField(classType,
f.getName(),
SootToDexUtils.getDexTypeDescriptor(f.getType()),
f.getModifiers(),
staticInit,
fieldAnnotations);
fields.add(field);
}
}
dexFile.internClassDef(classType,
accessFlags,
superClass,
interfaces,
sourceFile,
buildClassAnnotations(c),
fields,
toMethods(c));
}
示例27
private List<Annotation> buildInnerClassAttribute(SootClass parentClass,
InnerClassAttribute t, Set<String> skipList) {
if (t.getSpecs() == null)
return null;
List<Annotation> anns = null;
for (Tag t2 : t.getSpecs()) {
InnerClassTag icTag = (InnerClassTag) t2;
// In Dalvik, both the EnclosingMethod/EnclosingClass tag and the
// InnerClass tag are written to the inner class which is different
// to Java. We thus check whether this tag actually points to our
// outer class.
String outerClass = getOuterClassNameFromTag(icTag);
String innerClass = icTag.getInnerClass().replaceAll("/", ".");
// Only write the InnerClass tag to the inner class itself, not
// the other one. If the outer class points to our parent, but
// this is simply the wrong inner class, we also continue with the
// next tag.
if (!parentClass.hasOuterClass()
|| !innerClass.equals(parentClass.getName()))
continue;
// If the outer class points to the very same class, we null it
if (parentClass.getName().equals(outerClass)
&& icTag.getOuterClass() == null)
outerClass = null;
// Do not write garbage. Never.
if (parentClass.getName().equals(outerClass))
continue;
// This is an actual inner class. Write the annotation
if (skipList.add("Ldalvik/annotation/InnerClass;")) {
// InnerClass annotation
List<AnnotationElement> elements = new ArrayList<AnnotationElement>();
ImmutableAnnotationElement flagsElement = new ImmutableAnnotationElement
("accessFlags", new ImmutableIntEncodedValue(icTag.getAccessFlags()));
elements.add(flagsElement);
ImmutableEncodedValue nameValue;
if (icTag.getShortName() != null && !icTag.getShortName().isEmpty())
nameValue = new ImmutableStringEncodedValue(icTag.getShortName());
else
nameValue = ImmutableNullEncodedValue.INSTANCE;
ImmutableAnnotationElement nameElement = new ImmutableAnnotationElement
("name", nameValue);
elements.add(nameElement);
if (anns == null) anns = new ArrayList<Annotation>();
anns.add(new ImmutableAnnotation(AnnotationVisibility.SYSTEM,
"Ldalvik/annotation/InnerClass;",
elements));
}
}
return anns;
}
示例28
private List<Annotation> buildMemberClassesAttribute(SootClass parentClass,
InnerClassAttribute t, Set<String> skipList) {
List<Annotation> anns = null;
Set<String> memberClasses = null;
// Collect the inner classes
for (Tag t2 : t.getSpecs()) {
InnerClassTag icTag = (InnerClassTag) t2;
String outerClass = getOuterClassNameFromTag(icTag);
// Only classes with names are member classes
if (icTag.getOuterClass() != null
&& parentClass.getName().equals(outerClass)) {
if (memberClasses == null)
memberClasses = new HashSet<String>();
memberClasses.add(SootToDexUtils.getDexClassName(icTag.getInnerClass()));
}
}
// Write the member classes
if (memberClasses != null
&& !memberClasses.isEmpty()
&& skipList.add("Ldalvik/annotation/MemberClasses;")) {
List<EncodedValue> classes = new ArrayList<EncodedValue>();
for (String memberClass : memberClasses) {
ImmutableTypeEncodedValue classValue = new ImmutableTypeEncodedValue(memberClass);
classes.add(classValue);
}
ImmutableArrayEncodedValue classesValue =
new ImmutableArrayEncodedValue(classes);
ImmutableAnnotationElement element =
new ImmutableAnnotationElement("value", classesValue);
ImmutableAnnotation memberAnnotation =
new ImmutableAnnotation(AnnotationVisibility.SYSTEM,
"Ldalvik/annotation/MemberClasses;",
Collections.singletonList(element));
if (anns == null) anns = new ArrayList<Annotation>();
anns.add(memberAnnotation);
}
return anns;
}
示例29
public void setTag(Tag t) {
tag = t;
}
示例30
public void setTag(Tag t) {
instructionTag = t;
}