Search in sources :

Example 6 with LazyArrayIntTags

use of edu.columbia.cs.psl.phosphor.struct.LazyArrayIntTags in project phosphor by gmu-swe.

the class ReflectionMasker method fixAllArgs.

// static long time;
// static Thread printerThread;
// static boolean printerStarted = false;
// static{
// printerThread = new Thread(new Runnable() {
// 
// @Override
// public void run() {
// PrintStream os = System.out;
// while(true)
// {
// os.println("Time in FAA: " + time);
// try {
// Thread.currentThread().sleep(2000);
// } catch (InterruptedException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
// 
// }
// });
// 
// }
public static MethodInvoke fixAllArgs(Method m, Object owner, Object[] in, boolean isObjTags) {
    // System.out.println("Making slow call to  " + m);
    // if(!printerStarted)
    // {
    // printerThread.setDaemon(true);
    // printerThread.start();
    // printerStarted = true;
    // }
    // long start = System.currentTimeMillis();
    MethodInvoke ret = new MethodInvoke();
    if (m == null) {
        ret.a = in;
        ret.o = owner;
        ret.m = m;
        // time += (System.currentTimeMillis() - start);
        return ret;
    }
    if (Instrumenter.isIgnoredClass(m.getDeclaringClass().getName().replace('.', '/'))) {
        ret.a = in;
        ret.o = owner;
        ret.m = m;
        // time += (System.currentTimeMillis() - start);
        return ret;
    }
    m.setAccessible(true);
    if ((!m.PHOSPHOR_TAGmarked) && !"java.lang.Object".equals(m.getDeclaringClass().getName())) {
        m = getTaintMethod(m, isObjTags);
    }
    m.setAccessible(true);
    ret.a = in;
    ret.o = owner;
    ret.m = m;
    // if(in != null)
    // System.out.println("FAA: " +m + " "+owner);
    int j = 0;
    if (in != null && m.getParameterTypes().length != in.length) {
        ret.a = new Object[m.getParameterTypes().length];
        for (int i = 0; i < in.length; i++) {
            if (m.getParameterTypes()[j].isPrimitive()) {
                if (in[i] instanceof TaintedWithIntTag)
                    ret.a[j] = ((TaintedWithIntTag) in[i]).getPHOSPHOR_TAG();
                else if (in[i] instanceof TaintedWithObjTag)
                    ret.a[j] = ((TaintedWithObjTag) in[i]).getPHOSPHOR_TAG();
                else if (isObjTags)
                    ret.a[j] = null;
                else
                    ret.a[j] = 0;
                j++;
            } else if (m.getParameterTypes()[j] == Configuration.TAINT_TAG_OBJ_CLASS) {
                if (in[i] instanceof TaintedWithObjTag)
                    ret.a[j] = ((TaintedWithObjTag) in[i]).getPHOSPHOR_TAG();
                else
                    ret.a[j] = null;
                j++;
            } else if (LazyArrayIntTags.class.isAssignableFrom(m.getParameterTypes()[j])) {
                LazyArrayIntTags arr = ((LazyArrayIntTags) in[i]);
                ret.a[j] = arr;
                j++;
                if (arr != null)
                    ret.a[j] = arr.getVal();
                j++;
                continue;
            } else if (LazyArrayObjTags.class.isAssignableFrom(m.getParameterTypes()[j])) {
                LazyArrayObjTags arr = ((LazyArrayObjTags) in[i]);
                ret.a[j] = arr;
                j++;
                ret.a[j] = arr.getVal();
                j++;
                continue;
            }
            ret.a[j] = in[i];
            j++;
        }
    }
    if ((in == null && m != null && m.getParameterTypes().length == 1) || (in != null && j != in.length - 1)) {
        if (in == null)
            ret.a = new Object[1];
        final Class returnType = m.getReturnType();
        if (TaintedPrimitiveWithIntTag.class.isAssignableFrom(returnType) || TaintedPrimitiveWithObjTag.class.isAssignableFrom(returnType)) {
            try {
                ret.a[j] = returnType.newInstance();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }
    // System.out.println("Fix all args slow: " + Arrays.toString(ret.a) + " for " + m);
    return ret;
}
Also used : LazyArrayObjTags(edu.columbia.cs.psl.phosphor.struct.LazyArrayObjTags) TaintedPrimitiveWithObjTag(edu.columbia.cs.psl.phosphor.struct.TaintedPrimitiveWithObjTag) TaintedWithIntTag(edu.columbia.cs.psl.phosphor.struct.TaintedWithIntTag) LazyArrayIntTags(edu.columbia.cs.psl.phosphor.struct.LazyArrayIntTags) TaintedPrimitiveWithIntTag(edu.columbia.cs.psl.phosphor.struct.TaintedPrimitiveWithIntTag) TaintedWithObjTag(edu.columbia.cs.psl.phosphor.struct.TaintedWithObjTag) MethodInvoke(edu.columbia.cs.psl.phosphor.struct.MethodInvoke)

Example 7 with LazyArrayIntTags

use of edu.columbia.cs.psl.phosphor.struct.LazyArrayIntTags in project phosphor by gmu-swe.

the class ReflectionMasker method fixAllArgsUninst.

public static MethodInvoke fixAllArgsUninst(Method m, Object owner, Object[] in, ControlTaintTagStack ctrl) {
    MethodInvoke ret = new MethodInvoke();
    if (m == null) {
        ret.a = in;
        ret.o = owner;
        ret.m = m;
        return ret;
    }
    ret.m = getOrigMethod(m, true);
    ret.o = owner;
    ret.a = in;
    for (int i = 0; i < ret.a.length; i++) {
        if (ret.a[i] instanceof LazyArrayIntTags) {
            ret.a[i] = ((LazyArrayIntTags) ret.a[i]).getVal();
        } else if (ret.a[i] instanceof MultiDTaintedArrayWithObjTag) {
            ret.a[i] = ((MultiDTaintedArrayWithObjTag) ret.a[i]).getVal();
        }
    }
    return ret;
}
Also used : MultiDTaintedArrayWithObjTag(edu.columbia.cs.psl.phosphor.struct.multid.MultiDTaintedArrayWithObjTag) LazyArrayIntTags(edu.columbia.cs.psl.phosphor.struct.LazyArrayIntTags) MethodInvoke(edu.columbia.cs.psl.phosphor.struct.MethodInvoke)

Example 8 with LazyArrayIntTags

use of edu.columbia.cs.psl.phosphor.struct.LazyArrayIntTags in project phosphor by gmu-swe.

the class RuntimeReflectionPropogator method get.

public static Object get(Field f, Object obj, boolean isObjTags) throws IllegalArgumentException, IllegalAccessException {
    f.setAccessible(true);
    Object ret;
    if (f.getType().isPrimitive()) {
        if (f.getType() == Boolean.TYPE)
            if (isObjTags)
                ret = getBoolean$$PHOSPHORTAGGED(f, obj, new TaintedBooleanWithObjTag());
            else
                ret = getBoolean$$PHOSPHORTAGGED(f, obj, new TaintedBooleanWithIntTag());
        else if (f.getType() == Byte.TYPE)
            if (isObjTags)
                ret = getByte$$PHOSPHORTAGGED(f, obj, new TaintedByteWithObjTag());
            else
                ret = getByte$$PHOSPHORTAGGED(f, obj, new TaintedByteWithIntTag());
        else if (f.getType() == Character.TYPE)
            if (isObjTags)
                ret = getChar$$PHOSPHORTAGGED(f, obj, new TaintedCharWithObjTag());
            else
                ret = getChar$$PHOSPHORTAGGED(f, obj, new TaintedCharWithIntTag());
        else if (f.getType() == Double.TYPE)
            if (isObjTags)
                ret = getDouble$$PHOSPHORTAGGED(f, obj, new TaintedDoubleWithObjTag());
            else
                ret = getDouble$$PHOSPHORTAGGED(f, obj, new TaintedDoubleWithIntTag());
        else if (f.getType() == Float.TYPE)
            if (isObjTags)
                ret = getFloat$$PHOSPHORTAGGED(f, obj, new TaintedFloatWithObjTag());
            else
                ret = getFloat$$PHOSPHORTAGGED(f, obj, new TaintedFloatWithIntTag());
        else if (f.getType() == Long.TYPE)
            if (isObjTags)
                ret = getLong$$PHOSPHORTAGGED(f, obj, new TaintedLongWithObjTag());
            else
                ret = getLong$$PHOSPHORTAGGED(f, obj, new TaintedLongWithIntTag());
        else if (f.getType() == Integer.TYPE)
            if (isObjTags)
                ret = getInt$$PHOSPHORTAGGED(f, obj, new TaintedIntWithObjTag());
            else
                ret = getInt$$PHOSPHORTAGGED(f, obj, new TaintedIntWithIntTag());
        else if (f.getType() == Short.TYPE)
            if (isObjTags)
                ret = getShort$$PHOSPHORTAGGED(f, obj, new TaintedShortWithObjTag());
            else
                ret = getShort$$PHOSPHORTAGGED(f, obj, new TaintedShortWithIntTag());
        else
            throw new IllegalArgumentException();
    } else
        ret = f.get(obj);
    if (f.getType().isArray() && f.getType().getComponentType().isPrimitive()) {
        Object taint = null;
        try {
            try {
                if (ret instanceof LazyArrayIntTags && ((LazyArrayIntTags) ret).taints != null) {
                    return ret;
                } else if (ret instanceof LazyArrayObjTags && ((LazyArrayObjTags) ret).taints != null) {
                    return ret;
                } else {
                    Field taintField;
                    if (fieldToField.containsKey(f))
                        taintField = fieldToField.get(f);
                    else {
                        taintField = f.getDeclaringClass().getDeclaredField(f.getName() + TaintUtils.TAINT_FIELD);
                        taintField.setAccessible(true);
                        fieldToField.put(f, taintField);
                    }
                    taint = taintField.get(obj);
                    return taint;
                }
            } catch (NoSuchFieldException t) {
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    if (ret instanceof TaintedPrimitiveWithIntTag) {
        return ((TaintedPrimitiveWithIntTag) ret).toPrimitiveType();
    }
    if (ret instanceof TaintedPrimitiveWithObjTag) {
        return ((TaintedPrimitiveWithObjTag) ret).toPrimitiveType();
    }
    return ret;
}
Also used : TaintedShortWithObjTag(edu.columbia.cs.psl.phosphor.struct.TaintedShortWithObjTag) TaintedPrimitiveWithIntTag(edu.columbia.cs.psl.phosphor.struct.TaintedPrimitiveWithIntTag) Field(java.lang.reflect.Field) TaintedByteWithObjTag(edu.columbia.cs.psl.phosphor.struct.TaintedByteWithObjTag) TaintedLongWithIntTag(edu.columbia.cs.psl.phosphor.struct.TaintedLongWithIntTag) LazyArrayObjTags(edu.columbia.cs.psl.phosphor.struct.LazyArrayObjTags) TaintedDoubleWithIntTag(edu.columbia.cs.psl.phosphor.struct.TaintedDoubleWithIntTag) TaintedBooleanWithObjTag(edu.columbia.cs.psl.phosphor.struct.TaintedBooleanWithObjTag) TaintedDoubleWithObjTag(edu.columbia.cs.psl.phosphor.struct.TaintedDoubleWithObjTag) TaintedCharWithIntTag(edu.columbia.cs.psl.phosphor.struct.TaintedCharWithIntTag) TaintedBooleanWithIntTag(edu.columbia.cs.psl.phosphor.struct.TaintedBooleanWithIntTag) TaintedPrimitiveWithObjTag(edu.columbia.cs.psl.phosphor.struct.TaintedPrimitiveWithObjTag) TaintedFloatWithIntTag(edu.columbia.cs.psl.phosphor.struct.TaintedFloatWithIntTag) TaintedLongWithObjTag(edu.columbia.cs.psl.phosphor.struct.TaintedLongWithObjTag) TaintedByteWithIntTag(edu.columbia.cs.psl.phosphor.struct.TaintedByteWithIntTag) TaintedIntWithObjTag(edu.columbia.cs.psl.phosphor.struct.TaintedIntWithObjTag) TaintedFloatWithObjTag(edu.columbia.cs.psl.phosphor.struct.TaintedFloatWithObjTag) TaintedShortWithIntTag(edu.columbia.cs.psl.phosphor.struct.TaintedShortWithIntTag) TaintedIntWithIntTag(edu.columbia.cs.psl.phosphor.struct.TaintedIntWithIntTag) TaintedCharWithObjTag(edu.columbia.cs.psl.phosphor.struct.TaintedCharWithObjTag) LazyArrayIntTags(edu.columbia.cs.psl.phosphor.struct.LazyArrayIntTags)

Aggregations

LazyArrayIntTags (edu.columbia.cs.psl.phosphor.struct.LazyArrayIntTags)8 LazyArrayObjTags (edu.columbia.cs.psl.phosphor.struct.LazyArrayObjTags)6 Field (java.lang.reflect.Field)4 MethodInvoke (edu.columbia.cs.psl.phosphor.struct.MethodInvoke)3 TaintedPrimitiveWithIntTag (edu.columbia.cs.psl.phosphor.struct.TaintedPrimitiveWithIntTag)2 TaintedPrimitiveWithObjTag (edu.columbia.cs.psl.phosphor.struct.TaintedPrimitiveWithObjTag)2 TaintedWithIntTag (edu.columbia.cs.psl.phosphor.struct.TaintedWithIntTag)2 TaintedWithObjTag (edu.columbia.cs.psl.phosphor.struct.TaintedWithObjTag)2 MultiDTaintedArrayWithObjTag (edu.columbia.cs.psl.phosphor.struct.multid.MultiDTaintedArrayWithObjTag)2 Unsafe (sun.misc.Unsafe)2 ControlTaintTagStack (edu.columbia.cs.psl.phosphor.struct.ControlTaintTagStack)1 TaintedBooleanWithIntTag (edu.columbia.cs.psl.phosphor.struct.TaintedBooleanWithIntTag)1 TaintedBooleanWithObjTag (edu.columbia.cs.psl.phosphor.struct.TaintedBooleanWithObjTag)1 TaintedByteWithIntTag (edu.columbia.cs.psl.phosphor.struct.TaintedByteWithIntTag)1 TaintedByteWithObjTag (edu.columbia.cs.psl.phosphor.struct.TaintedByteWithObjTag)1 TaintedCharWithIntTag (edu.columbia.cs.psl.phosphor.struct.TaintedCharWithIntTag)1 TaintedCharWithObjTag (edu.columbia.cs.psl.phosphor.struct.TaintedCharWithObjTag)1 TaintedDoubleWithIntTag (edu.columbia.cs.psl.phosphor.struct.TaintedDoubleWithIntTag)1 TaintedDoubleWithObjTag (edu.columbia.cs.psl.phosphor.struct.TaintedDoubleWithObjTag)1 TaintedFloatWithIntTag (edu.columbia.cs.psl.phosphor.struct.TaintedFloatWithIntTag)1