Search in sources :

Example 6 with LazyArrayObjTags

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

the class MultiDTaintedArrayWithObjTag method unboxVal.

public static final Object unboxVal(final Object _in, final int componentType, final int dims) {
    if (dims == 0) {
        switch(componentType) {
            case Type.BOOLEAN:
            case Type.BYTE:
            case Type.CHAR:
            case Type.DOUBLE:
            case Type.FLOAT:
            case Type.INT:
            case Type.LONG:
            case Type.SHORT:
                return ((LazyArrayObjTags) _in).getVal();
            default:
                throw new IllegalArgumentException();
        }
    } else if (dims == 1) {
        final Object[] in = (Object[]) _in;
        switch(componentType) {
            case Type.BOOLEAN:
                boolean[][] retz = new boolean[in.length][];
                for (int i = 0; i < in.length; i++) if (in[i] != null)
                    retz[i] = ((LazyBooleanArrayObjTags) in[i]).val;
                return retz;
            case Type.BYTE:
                byte[][] retb = new byte[in.length][];
                for (int i = 0; i < in.length; i++) if (in[i] != null)
                    retb[i] = ((LazyByteArrayObjTags) in[i]).val;
                return retb;
            case Type.CHAR:
                char[][] retc = new char[in.length][];
                for (int i = 0; i < in.length; i++) if (in[i] != null)
                    retc[i] = ((LazyCharArrayObjTags) in[i]).val;
                return retc;
            case Type.DOUBLE:
                double[][] retd = new double[in.length][];
                for (int i = 0; i < in.length; i++) if (in[i] != null)
                    retd[i] = ((LazyDoubleArrayObjTags) in[i]).val;
                return retd;
            case Type.FLOAT:
                float[][] retf = new float[in.length][];
                for (int i = 0; i < in.length; i++) if (in[i] != null)
                    retf[i] = ((LazyFloatArrayObjTags) in[i]).val;
                return retf;
            case Type.INT:
                int[][] reti = new int[in.length][];
                for (int i = 0; i < in.length; i++) if (in[i] != null)
                    reti[i] = ((LazyIntArrayObjTags) in[i]).val;
                return reti;
            case Type.LONG:
                long[][] retl = new long[in.length][];
                for (int i = 0; i < in.length; i++) if (in[i] != null)
                    retl[i] = ((LazyLongArrayObjTags) in[i]).val;
                return retl;
            case Type.SHORT:
                short[][] rets = new short[in.length][];
                for (int i = 0; i < in.length; i++) if (in[i] != null)
                    rets[i] = ((LazyShortArrayObjTags) in[i]).val;
                return rets;
        }
    } else if (dims == 2) {
        final Object[][] ina = (Object[][]) _in;
        final Object[] in = (Object[]) _in;
        switch(componentType) {
            case Type.BOOLEAN:
                boolean[][][] retz = new boolean[in.length][][];
                for (int i = 0; i < in.length; i++) {
                    retz[i] = new boolean[ina[i].length][];
                    for (int j = 0; j < ina[i].length; j++) retz[i][j] = ((LazyBooleanArrayObjTags) ina[i][j]).val;
                }
                return retz;
            case Type.BYTE:
                byte[][][] retb = new byte[in.length][][];
                for (int i = 0; i < in.length; i++) {
                    retb[i] = new byte[ina[i].length][];
                    for (int j = 0; j < ina[i].length; j++) retb[i][j] = ((LazyByteArrayObjTags) ina[i][j]).val;
                }
                return retb;
            case Type.CHAR:
                char[][][] retc = new char[in.length][][];
                for (int i = 0; i < in.length; i++) {
                    retc[i] = new char[ina[i].length][];
                    for (int j = 0; j < ina[i].length; j++) retc[i][j] = ((LazyCharArrayObjTags) ina[i][j]).val;
                }
                return retc;
            case Type.DOUBLE:
                double[][][] retd = new double[in.length][][];
                for (int i = 0; i < in.length; i++) {
                    retd[i] = new double[ina[i].length][];
                    for (int j = 0; j < ina[i].length; j++) retd[i][j] = ((LazyDoubleArrayObjTags) ina[i][j]).val;
                }
                return retd;
            case Type.FLOAT:
                float[][][] retf = new float[in.length][][];
                for (int i = 0; i < in.length; i++) {
                    retf[i] = new float[ina[i].length][];
                    for (int j = 0; j < ina[i].length; j++) retf[i][j] = ((LazyFloatArrayObjTags) ina[i][j]).val;
                }
                return retf;
            case Type.INT:
                int[][][] reti = new int[in.length][][];
                for (int i = 0; i < in.length; i++) {
                    reti[i] = new int[ina[i].length][];
                    for (int j = 0; j < ina[i].length; j++) reti[i][j] = ((LazyIntArrayObjTags) ina[i][j]).val;
                }
                return reti;
            case Type.LONG:
                long[][][] retl = new long[in.length][][];
                for (int i = 0; i < in.length; i++) {
                    retl[i] = new long[ina[i].length][];
                    for (int j = 0; j < ina[i].length; j++) retl[i][j] = ((LazyLongArrayObjTags) ina[i][j]).val;
                }
                return retl;
            case Type.SHORT:
                short[][][] rets = new short[in.length][][];
                for (int i = 0; i < in.length; i++) {
                    rets[i] = new short[ina[i].length][];
                    for (int j = 0; j < ina[i].length; j++) rets[i][j] = ((LazyShortArrayObjTags) ina[i][j]).val;
                }
                return rets;
        }
    }
    throw new IllegalArgumentException();
}
Also used : LazyByteArrayObjTags(edu.columbia.cs.psl.phosphor.struct.LazyByteArrayObjTags) LazyLongArrayObjTags(edu.columbia.cs.psl.phosphor.struct.LazyLongArrayObjTags) LazyCharArrayObjTags(edu.columbia.cs.psl.phosphor.struct.LazyCharArrayObjTags) LazyFloatArrayObjTags(edu.columbia.cs.psl.phosphor.struct.LazyFloatArrayObjTags) Taint(edu.columbia.cs.psl.phosphor.runtime.Taint) LazyArrayObjTags(edu.columbia.cs.psl.phosphor.struct.LazyArrayObjTags) LazyIntArrayObjTags(edu.columbia.cs.psl.phosphor.struct.LazyIntArrayObjTags) LazyDoubleArrayObjTags(edu.columbia.cs.psl.phosphor.struct.LazyDoubleArrayObjTags) LazyShortArrayObjTags(edu.columbia.cs.psl.phosphor.struct.LazyShortArrayObjTags) LazyBooleanArrayObjTags(edu.columbia.cs.psl.phosphor.struct.LazyBooleanArrayObjTags)

Example 7 with LazyArrayObjTags

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

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

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

LazyArrayObjTags (edu.columbia.cs.psl.phosphor.struct.LazyArrayObjTags)9 LazyArrayIntTags (edu.columbia.cs.psl.phosphor.struct.LazyArrayIntTags)6 TaintedWithIntTag (edu.columbia.cs.psl.phosphor.struct.TaintedWithIntTag)4 TaintedWithObjTag (edu.columbia.cs.psl.phosphor.struct.TaintedWithObjTag)4 Field (java.lang.reflect.Field)4 MethodInvoke (edu.columbia.cs.psl.phosphor.struct.MethodInvoke)2 TaintedPrimitiveWithIntTag (edu.columbia.cs.psl.phosphor.struct.TaintedPrimitiveWithIntTag)2 TaintedPrimitiveWithObjTag (edu.columbia.cs.psl.phosphor.struct.TaintedPrimitiveWithObjTag)2 Unsafe (sun.misc.Unsafe)2 Taint (edu.columbia.cs.psl.phosphor.runtime.Taint)1 ControlTaintTagStack (edu.columbia.cs.psl.phosphor.struct.ControlTaintTagStack)1 LazyBooleanArrayObjTags (edu.columbia.cs.psl.phosphor.struct.LazyBooleanArrayObjTags)1 LazyByteArrayObjTags (edu.columbia.cs.psl.phosphor.struct.LazyByteArrayObjTags)1 LazyCharArrayObjTags (edu.columbia.cs.psl.phosphor.struct.LazyCharArrayObjTags)1 LazyDoubleArrayObjTags (edu.columbia.cs.psl.phosphor.struct.LazyDoubleArrayObjTags)1 LazyFloatArrayObjTags (edu.columbia.cs.psl.phosphor.struct.LazyFloatArrayObjTags)1 LazyIntArrayObjTags (edu.columbia.cs.psl.phosphor.struct.LazyIntArrayObjTags)1 LazyLongArrayObjTags (edu.columbia.cs.psl.phosphor.struct.LazyLongArrayObjTags)1 LazyShortArrayObjTags (edu.columbia.cs.psl.phosphor.struct.LazyShortArrayObjTags)1 TaintedBooleanWithIntTag (edu.columbia.cs.psl.phosphor.struct.TaintedBooleanWithIntTag)1