Skip to content

Commit

Permalink
now also reading in attribute values
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenArzt committed Jul 21, 2017
1 parent 3068fee commit 429b4da
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
19 changes: 15 additions & 4 deletions src/soot/asm/TagBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package soot.asm;

import java.lang.reflect.Field;

import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.ClassVisitor;
Expand All @@ -40,12 +42,12 @@ final class TagBuilder {
private VisibilityAnnotationTag invisibleTag, visibleTag;
private final Host host;
private final SootClassBuilder scb;

TagBuilder(Host host, SootClassBuilder scb) {
this.host = host;
this.scb = scb;
}

/**
* @see FieldVisitor#visitAnnotation(String, boolean)
* @see MethodVisitor#visitAnnotation(String, boolean)
Expand Down Expand Up @@ -83,7 +85,16 @@ public void visitEnd() {
* @see ClassVisitor#visitAttribute(Attribute)
*/
public void visitAttribute(Attribute attr) {
host.addTag(new GenericAttribute(attr.type,null));
//throw new UnsupportedOperationException("Unknown attribute: " + attr);
// SA, 2017-07-21: As of ASM 5.1, there is no better way to obtain
// attribute values.
byte[] value = null;
try {
Field fld = Attribute.class.getDeclaredField("value");
fld.setAccessible(true);
value = (byte[]) fld.get(attr);
} catch (Exception ex) {
// Just carry on
}
host.addTag(new GenericAttribute(attr.type, value));
}
}
15 changes: 8 additions & 7 deletions src/soot/tagkit/Attribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@

package soot.tagkit;

/**
* Tags that are attached to the class file, field, method, or method body
* should implement this interface.
/**
* Tags that are attached to the class file, field, method, or method body
* should implement this interface.
*/

public interface Attribute extends Tag
{
/** Sets the value of the attribute from a byte[]. */
public void setValue(byte[] v);
public interface Attribute extends Tag {

/** Sets the value of the attribute from a byte[]. */
public void setValue(byte[] v);

}

0 comments on commit 429b4da

Please sign in to comment.