Skip to content

Commit

Permalink
Removed more useless classes. Everything runs correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
jtamayo committed Jul 3, 2010
1 parent 77031b1 commit 115ceb7
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 89 deletions.
28 changes: 16 additions & 12 deletions pepe/src/edu/stanford/pepe/PepeAgent.java
Expand Up @@ -26,8 +26,8 @@
* *
* @author jtamayo * @author jtamayo
*/ */
public class PepeAgent implements ClassFileTransformer,Opcodes { public class PepeAgent implements ClassFileTransformer, Opcodes {

public static final Logger logger = Logger.getLogger("edu.stanford.pepe"); public static final Logger logger = Logger.getLogger("edu.stanford.pepe");
{ {
for (Handler h : Logger.getLogger("").getHandlers()) { for (Handler h : Logger.getLogger("").getHandlers()) {
Expand All @@ -46,10 +46,9 @@ public class PepeAgent implements ClassFileTransformer,Opcodes {
*/ */
public static void premain(String agentArgs, Instrumentation inst) { public static void premain(String agentArgs, Instrumentation inst) {
logger.info("Pepe agent started"); logger.info("Pepe agent started");
logger.info("Using classloader " + PepeAgent.class.getClassLoader());

inst.addTransformer(new PepeAgent()); inst.addTransformer(new PepeAgent());

Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override @Override
public void uncaughtException(Thread t, Throwable e) { public void uncaughtException(Thread t, Throwable e) {
Expand Down Expand Up @@ -85,19 +84,19 @@ public static String printClassLoader(ClassLoader cl) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined,
ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException { ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
if ((!InstrumentationPolicy.isTypeInstrumentable(className) if ((!InstrumentationPolicy.isTypeInstrumentable(className) || InstrumentationPolicy
|| InstrumentationPolicy.isSpecialJavaClass(className)) .isSpecialJavaClass(className))
&& !InstrumentationPolicy.isSpecialPepeClass(className)) { && !InstrumentationPolicy.isSpecialPepeClass(className)) {
// Types in the ignore list, and special java classes must be ignored. // Types in the ignore list, and special java classes must be ignored.
// Special Pepe classes, even if in the ignore list, must be instrumented // Special Pepe classes, even if in the ignore list, must be instrumented
return null; return null;
} }

try { try {
ClassNode cn = new ClassNode(); ClassNode cn = new ClassNode();
ClassReader cr = new ClassReader(classfileBuffer); ClassReader cr = new ClassReader(classfileBuffer);
cr.accept(cn, 0); // Makes the ClassReader visit the ClassNode cr.accept(cn, 0); // Makes the ClassReader visit the ClassNode
for (FieldNode fn : (List<FieldNode>)cn.fields) { for (FieldNode fn : (List<FieldNode>) cn.fields) {
if (fn.name.equals(ShadowFieldRewriter.TAINT_MARK)) { if (fn.name.equals(ShadowFieldRewriter.TAINT_MARK)) {
logger.info("Skipping already instrumented class " + cn.name); logger.info("Skipping already instrumented class " + cn.name);
return null; return null;
Expand Down Expand Up @@ -145,18 +144,23 @@ public static byte[] instrumentClass(ClassNode cn) {
} else { } else {
// First add the taint fields // First add the taint fields
ShadowFieldRewriter.rewrite(cn); ShadowFieldRewriter.rewrite(cn);
// // Now add the shadow stack // Now add the shadow stack
ClassWriter cw = new ClassWriter(0); ClassWriter cw = new ClassWriter(0);
ClassVisitor verifier = new CheckClassAdapter(cw); // For debugging purposes, the bytecode should be as sane as possible ClassVisitor verifier = new CheckClassAdapter(cw); // For debugging purposes, the bytecode should be as sane as possible
ShadowStackRewriter.rewrite(cn, verifier); ShadowStackRewriter.rewrite(cn, verifier);
return cw.toByteArray(); return cw.toByteArray();
} }
} }


private static void printClass(byte[] bs) { /**
* For debugging purposes. Prints the disassembly list of the class,
* toghether with the inferred types in the stack and the local variables.
*
* @param bs
*/
static void printClass(byte[] bs) {
ClassReader cr = new ClassReader(bs); ClassReader cr = new ClassReader(bs);
CheckClassAdapter.verify(cr, true, new PrintWriter(System.out)); CheckClassAdapter.verify(cr, true, new PrintWriter(System.out));
} }



} }
31 changes: 0 additions & 31 deletions pepe/src/edu/stanford/pepe/PrimitiveWrapperInstrumenter.java

This file was deleted.

41 changes: 22 additions & 19 deletions pepe/src/edu/stanford/pepe/SerialVersionUidGenerator.java
Expand Up @@ -3,6 +3,7 @@
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectStreamClass;
import java.io.Serializable; import java.io.Serializable;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
Expand All @@ -18,7 +19,12 @@
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;



/**
* Class for generating serialVersionUid without taking into account shadow
* fields. The code was shamelessly stolen from {@link ObjectStreamClass}.
*
* @author jtamayo
*/
public class SerialVersionUidGenerator { public class SerialVersionUidGenerator {


/** /**
Expand Down Expand Up @@ -49,31 +55,28 @@ public MemberSignature(Method meth) {
signature = getMethodSignature(meth.getParameterTypes(), meth.getReturnType()); signature = getMethodSignature(meth.getParameterTypes(), meth.getReturnType());
} }
} }



/** /**
* Returns JVM type signature for given list of parameters and return type. * Returns JVM type signature for given list of parameters and return type.
*/ */
private static String getMethodSignature(Class[] paramTypes, private static String getMethodSignature(Class[] paramTypes, Class retType) {
Class retType) StringBuffer sbuf = new StringBuffer();
{ sbuf.append('(');
StringBuffer sbuf = new StringBuffer(); for (int i = 0; i < paramTypes.length; i++) {
sbuf.append('('); sbuf.append(getClassSignature(paramTypes[i]));
for (int i = 0; i < paramTypes.length; i++) { }
sbuf.append(getClassSignature(paramTypes[i])); sbuf.append(')');
sbuf.append(getClassSignature(retType));
return sbuf.toString();
} }
sbuf.append(')');
sbuf.append(getClassSignature(retType));
return sbuf.toString();
}


/** /**
* Computes the default serial version UID value for the given class. * Computes the default serial version UID value for the given class.
*/ */
public static long computeDefaultSUID(Class cl) { public static long computeDefaultSUID(Class cl) {
if (!Serializable.class.isAssignableFrom(cl) || Proxy.isProxyClass(cl)) { if (!Serializable.class.isAssignableFrom(cl) || Proxy.isProxyClass(cl)) {
return 0L; return 0L;
} }


try { try {
ByteArrayOutputStream bout = new ByteArrayOutputStream(); ByteArrayOutputStream bout = new ByteArrayOutputStream();
Expand Down Expand Up @@ -119,7 +122,7 @@ public static long computeDefaultSUID(Class cl) {
filteredFields.add(field); filteredFields.add(field);
} }
} }
fields = filteredFields.toArray(new Field[]{}); fields = filteredFields.toArray(new Field[] {});
/// End pepe hack /// End pepe hack
MemberSignature[] fieldSigs = new MemberSignature[fields.length]; MemberSignature[] fieldSigs = new MemberSignature[fields.length];
for (int i = 0; i < fields.length; i++) { for (int i = 0; i < fields.length; i++) {
Expand Down Expand Up @@ -165,7 +168,7 @@ public int compare(Object o1, Object o2) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
/// end pepe hack /// end pepe hack

if (hasClinit) { if (hasClinit) {
dout.writeUTF("<clinit>"); dout.writeUTF("<clinit>");
dout.writeInt(Modifier.STATIC); dout.writeInt(Modifier.STATIC);
Expand Down
5 changes: 1 addition & 4 deletions pepe/src/edu/stanford/pepe/ShadowFieldRewriter.java
Expand Up @@ -12,6 +12,7 @@


/** /**
* Adds the shadow fields to a {@link ClassNode} object. * Adds the shadow fields to a {@link ClassNode} object.
*
* @author jtamayo * @author jtamayo
*/ */
public class ShadowFieldRewriter implements Opcodes { public class ShadowFieldRewriter implements Opcodes {
Expand Down Expand Up @@ -62,11 +63,7 @@ public static void rewrite(ClassNode cn) {


cn.fields.addAll(shadowFields); cn.fields.addAll(shadowFields);


// TODO: What should we do with volatile fields? Should the shadow be volatile or not?
// TODO: Make our fields transient, so they are not serialized - Change the computeSErialVersionUid
// TODO: What do we do with static final fields? do we instrument them or not? are they really constants? is it easier to keep an always 0 shadow field? Doesn't happen in real life
// TODO: How about the this$0 parameter, equivalent to the (OuterClass) this pointer in inner classes? // TODO: How about the this$0 parameter, equivalent to the (OuterClass) this pointer in inner classes?

} }




Expand Down
23 changes: 0 additions & 23 deletions pepe/src/edu/stanford/pepe/Taint.java

This file was deleted.

0 comments on commit 115ceb7

Please sign in to comment.