Search in sources :

Example 1 with TaintedWithIntTag

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

the class ReflectionMasker method fixAllArgs.

@SuppressWarnings("rawtypes")
public static Object[] fixAllArgs(Object[] in, Constructor c, boolean isObjTags) {
    // System.out.println("Making constructo rcall to " + c);
    if (c != null && in != null && c.getParameterTypes().length != in.length) {
        Object[] ret = new Object[c.getParameterTypes().length];
        int j = 0;
        for (int i = 0; i < in.length; i++) {
            if (c.getParameterTypes()[j].isPrimitive()) {
                if (in[i] instanceof TaintedWithIntTag)
                    ret[j] = ((TaintedWithIntTag) in[i]).getPHOSPHOR_TAG();
                else if (in[i] instanceof TaintedWithObjTag)
                    ret[j] = ((TaintedWithObjTag) in[i]).getPHOSPHOR_TAG();
                else
                    ret[j] = 0;
                j++;
            } else if (c.getParameterTypes()[j] == Configuration.TAINT_TAG_OBJ_CLASS) {
                if (in[i] instanceof TaintedWithObjTag)
                    ret[j] = ((TaintedWithObjTag) in[i]).getPHOSPHOR_TAG();
                else
                    ret[j] = null;
                j++;
            } else if (LazyArrayIntTags.class.isAssignableFrom(c.getParameterTypes()[j])) {
                LazyArrayIntTags arr = ((LazyArrayIntTags) in[i]);
                if (arr == null) {
                    ret[j] = null;
                    j++;
                    ret[j] = null;
                    j++;
                } else {
                    ret[j] = arr.taints;
                    j++;
                    ret[j] = arr.getVal();
                    j++;
                }
                continue;
            } else if (LazyArrayObjTags.class.isAssignableFrom(c.getParameterTypes()[j])) {
                LazyArrayObjTags arr = ((LazyArrayObjTags) in[i]);
                if (arr == null) {
                    ret[j] = null;
                    j++;
                    ret[j] = null;
                    j++;
                } else {
                    ret[j] = arr.taints;
                    j++;
                    ret[j] = arr.getVal();
                    j++;
                }
                continue;
            }
            ret[j] = in[i];
            j++;
        }
        return ret;
    } else if (in == null && c.getParameterTypes().length == 1) {
        Object[] ret = new Object[1];
        ret[0] = null;
        return ret;
    } else if (in == null && c.getParameterTypes().length == 2) {
        Object[] ret = new Object[2];
        ret[0] = new ControlTaintTagStack();
        ret[1] = null;
        return ret;
    }
    return in;
}
Also used : ControlTaintTagStack(edu.columbia.cs.psl.phosphor.struct.ControlTaintTagStack) LazyArrayObjTags(edu.columbia.cs.psl.phosphor.struct.LazyArrayObjTags) TaintedWithIntTag(edu.columbia.cs.psl.phosphor.struct.TaintedWithIntTag) LazyArrayIntTags(edu.columbia.cs.psl.phosphor.struct.LazyArrayIntTags) TaintedWithObjTag(edu.columbia.cs.psl.phosphor.struct.TaintedWithObjTag)

Example 2 with TaintedWithIntTag

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

the class ReflectionMasker method fixAllArgs.

public static Object[] fixAllArgs(Object[] in, Constructor c, ControlTaintTagStack ctrl) {
    // System.out.println("Making constructo rcall to " + c);
    if (c != null && in != null && c.getParameterTypes().length != in.length) {
        Object[] ret = new Object[c.getParameterTypes().length];
        int j = 0;
        for (int i = 0; i < in.length; i++) {
            if (c.getParameterTypes()[j].isPrimitive()) {
                if (in[i] instanceof TaintedWithIntTag)
                    ret[j] = ((TaintedWithIntTag) in[i]).getPHOSPHOR_TAG();
                else if (in[i] instanceof TaintedWithObjTag)
                    ret[j] = ((TaintedWithObjTag) in[i]).getPHOSPHOR_TAG();
                else
                    ret[j] = 0;
                j++;
            } else if (c.getParameterTypes()[j] == Configuration.TAINT_TAG_OBJ_CLASS) {
                if (in[i] instanceof TaintedWithObjTag)
                    ret[j] = ((TaintedWithObjTag) in[i]).getPHOSPHOR_TAG();
                else
                    ret[j] = null;
                j++;
            } else if (c.getParameterTypes()[j].isArray() && (c.getParameterTypes()[j].getComponentType().isPrimitive() || Configuration.TAINT_TAG_OBJ_CLASS.isAssignableFrom(c.getParameterTypes()[j].getComponentType()))) {
                LazyArrayObjTags arr = ((LazyArrayObjTags) in[i]);
                ret[j] = arr.taints;
                j++;
                ret[j] = arr.getVal();
                j++;
                continue;
            }
            ret[j] = in[i];
            j++;
        }
        ret[ret.length - 2] = ctrl;
        return ret;
    } else if (in == null && c.getParameterTypes().length == 1) {
        Object[] ret = new Object[1];
        ret[0] = null;
        return ret;
    } else if (in == null && c.getParameterTypes().length == 2) {
        Object[] ret = new Object[2];
        ret[0] = ctrl;
        ret[1] = null;
        return ret;
    }
    return in;
}
Also used : LazyArrayObjTags(edu.columbia.cs.psl.phosphor.struct.LazyArrayObjTags) TaintedWithIntTag(edu.columbia.cs.psl.phosphor.struct.TaintedWithIntTag) TaintedWithObjTag(edu.columbia.cs.psl.phosphor.struct.TaintedWithObjTag)

Example 3 with TaintedWithIntTag

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

the class ReflectionMasker method fixAllArgs.

public static MethodInvoke fixAllArgs(Method m, Object owner, Object[] in, ControlTaintTagStack ctrl) {
    // System.out.println("Making slow call to  " + m);
    MethodInvoke ret = new MethodInvoke();
    m.setAccessible(true);
    if (Instrumenter.isIgnoredClass(m.getDeclaringClass().getName().replace('.', '/'))) {
        ret.a = in;
        ret.o = owner;
        ret.m = m;
        return ret;
    }
    if ((IS_KAFFE) || !m.PHOSPHOR_TAGmarked) {
        if (IS_KAFFE) {
            if (in.length > 0)
                m = getTaintMethodControlTrack(m);
        } else {
            m = getTaintMethodControlTrack(m);
        }
    }
    m.setAccessible(true);
    ret.a = in;
    ret.o = owner;
    ret.m = m;
    // System.out.println("FAA: " +m + " "+owner + " " + Arrays.toString(in));
    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
                    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 (m.getParameterTypes()[j].isArray() && (m.getParameterTypes()[j].getComponentType().isPrimitive() || m.getParameterTypes()[j].getComponentType().equals(Configuration.TAINT_TAG_OBJ_CLASS))) {
                LazyArrayObjTags arr = ((LazyArrayObjTags) in[i]);
                ret.a[j] = arr.taints;
                j++;
                ret.a[j] = arr.getVal();
                j++;
                continue;
            }
            ret.a[j] = in[i];
            j++;
        }
    }
    if (ret.a != null && ret.a.length > j) {
        ret.a[j] = ctrl;
        j++;
    }
    // System.out.println("So far, " + Arrays.toString(ret.a));
    if (in == null && m != null && m.getParameterTypes().length == 1) {
        ret.a = new Object[1];
        ret.a[0] = ctrl;
    } else if ((in == null && m != null && m.getParameterTypes().length == 2) || (in != null && j != in.length - 1)) {
        if (in == null) {
            ret.a = new Object[2];
            ret.a[0] = ctrl;
            j++;
        }
        final Class returnType = m.getReturnType();
        if (TaintedPrimitiveWithIntTag.class.isAssignableFrom(returnType) || TaintedPrimitiveWithObjTag.class.isAssignableFrom(returnType)) {
            try {
                // System.out.println(returnType + "  is return type");
                ret.a[j] = returnType.newInstance();
                // System.out.println("new inst " + returnType.newInstance());
                if (ret.a[j].getClass().equals(Boolean.class)) {
                    System.exit(-1);
                }
            } 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) TaintedWithIntTag(edu.columbia.cs.psl.phosphor.struct.TaintedWithIntTag) TaintedWithObjTag(edu.columbia.cs.psl.phosphor.struct.TaintedWithObjTag) MethodInvoke(edu.columbia.cs.psl.phosphor.struct.MethodInvoke)

Example 4 with TaintedWithIntTag

use of edu.columbia.cs.psl.phosphor.struct.TaintedWithIntTag 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 5 with TaintedWithIntTag

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

the class TaintUtils method enumValueOf.

public static <T extends Enum<T>> T enumValueOf(Class<T> enumType, String name) {
    T ret = Enum.valueOf(enumType, name);
    if (((Object) name) instanceof TaintedWithIntTag) {
        int tag = ((TaintedWithIntTag) ((Object) name)).getPHOSPHOR_TAG();
        if (tag != 0) {
            ret = shallowClone(ret);
            ((TaintedWithIntTag) ret).setPHOSPHOR_TAG(tag);
        }
    } else if (((Object) name) instanceof TaintedWithObjTag) {
        Object tag = ((TaintedWithObjTag) ((Object) name)).getPHOSPHOR_TAG();
        if (tag != null) {
            ret = shallowClone(ret);
            ((TaintedWithObjTag) ret).setPHOSPHOR_TAG(tag);
        }
    }
    return ret;
}
Also used : TaintedWithIntTag(edu.columbia.cs.psl.phosphor.struct.TaintedWithIntTag) Taint(edu.columbia.cs.psl.phosphor.runtime.Taint) TaintedWithObjTag(edu.columbia.cs.psl.phosphor.struct.TaintedWithObjTag)

Aggregations

TaintedWithIntTag (edu.columbia.cs.psl.phosphor.struct.TaintedWithIntTag)5 TaintedWithObjTag (edu.columbia.cs.psl.phosphor.struct.TaintedWithObjTag)5 LazyArrayObjTags (edu.columbia.cs.psl.phosphor.struct.LazyArrayObjTags)4 LazyArrayIntTags (edu.columbia.cs.psl.phosphor.struct.LazyArrayIntTags)2 MethodInvoke (edu.columbia.cs.psl.phosphor.struct.MethodInvoke)2 Taint (edu.columbia.cs.psl.phosphor.runtime.Taint)1 ControlTaintTagStack (edu.columbia.cs.psl.phosphor.struct.ControlTaintTagStack)1 TaintedPrimitiveWithIntTag (edu.columbia.cs.psl.phosphor.struct.TaintedPrimitiveWithIntTag)1 TaintedPrimitiveWithObjTag (edu.columbia.cs.psl.phosphor.struct.TaintedPrimitiveWithObjTag)1