Search in sources :

Example 1 with LazyArrayObjTags

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

the class RuntimeReflectionPropogator method set$$PHOSPHORTAGGED.

public static void set$$PHOSPHORTAGGED(Field f, Object obj, Object val, ControlTaintTagStack ctrl) throws IllegalArgumentException, IllegalAccessException {
    if (f.getType().isPrimitive()) {
        if (val instanceof Integer && f.getType().equals(Integer.TYPE)) {
            Integer i = (Integer) val;
            f.setAccessible(true);
            f.setInt(obj, i.intValue());
            try {
                Field tf = f.getDeclaringClass().getDeclaredField(f.getName() + TaintUtils.TAINT_FIELD);
                tf.setAccessible(true);
                tf.set(obj, Taint.combineTags(getTagObj(val), ctrl));
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            } catch (SecurityException e) {
                e.printStackTrace();
            }
            return;
        } else if (val instanceof Boolean && f.getType().equals(Boolean.TYPE)) {
            Boolean i = (Boolean) val;
            f.setAccessible(true);
            f.setBoolean(obj, i.booleanValue());
            // }
            return;
        } else if (val instanceof Byte && f.getType().equals(Byte.TYPE)) {
            Byte i = (Byte) val;
            f.setAccessible(true);
            f.setByte(obj, i.byteValue());
            try {
                Field tf = f.getDeclaringClass().getDeclaredField(f.getName() + TaintUtils.TAINT_FIELD);
                tf.setAccessible(true);
                tf.set(obj, Taint.combineTags(getTagObj(val), ctrl));
            } catch (SecurityException e) {
                e.printStackTrace();
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            }
            return;
        } else if (val instanceof Character && f.getType().equals(Character.TYPE)) {
            Character i = (Character) val;
            f.setAccessible(true);
            f.setChar(obj, i.charValue());
            try {
                Field tf = f.getDeclaringClass().getDeclaredField(f.getName() + TaintUtils.TAINT_FIELD);
                tf.setAccessible(true);
                tf.set(obj, Taint.combineTags(getTagObj(val), ctrl));
            } catch (SecurityException e) {
                e.printStackTrace();
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            }
            return;
        } else if (val instanceof Double && f.getType().equals(Double.TYPE)) {
            Double i = (Double) val;
            f.setAccessible(true);
            f.setDouble(obj, i.doubleValue());
            try {
                Field tf = f.getDeclaringClass().getDeclaredField(f.getName() + TaintUtils.TAINT_FIELD);
                tf.setAccessible(true);
                tf.set(obj, Taint.combineTags(getTagObj(val), ctrl));
            } catch (SecurityException e) {
                e.printStackTrace();
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            }
            return;
        } else if (val instanceof Float && f.getType().equals(Float.TYPE)) {
            Float i = (Float) val;
            f.setAccessible(true);
            f.setFloat(obj, i.floatValue());
            try {
                Field tf = f.getDeclaringClass().getDeclaredField(f.getName() + TaintUtils.TAINT_FIELD);
                tf.setAccessible(true);
                tf.set(obj, Taint.combineTags(getTagObj(val), ctrl));
            } catch (SecurityException e) {
                e.printStackTrace();
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            }
            return;
        } else if (val instanceof Long && f.getType().equals(Long.TYPE)) {
            Long i = (Long) val;
            f.setAccessible(true);
            f.setLong(obj, i.longValue());
            try {
                Field tf = f.getDeclaringClass().getDeclaredField(f.getName() + TaintUtils.TAINT_FIELD);
                tf.setAccessible(true);
                tf.set(obj, Taint.combineTags(getTagObj(val), ctrl));
            } catch (SecurityException e) {
                e.printStackTrace();
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            }
            return;
        } else if (val instanceof Short && f.getType().equals(Short.TYPE)) {
            Short i = (Short) val;
            f.setAccessible(true);
            f.setShort(obj, i.shortValue());
            try {
                Field tf = f.getDeclaringClass().getDeclaredField(f.getName() + TaintUtils.TAINT_FIELD);
                tf.setAccessible(true);
                tf.set(obj, Taint.combineTags(getTagObj(val), ctrl));
            } catch (SecurityException e) {
                e.printStackTrace();
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            }
            return;
        }
    }
    Taint.combineTagsOnObject(obj, ctrl);
    f.setAccessible(true);
    f.set(obj, val);
    if (f.getType().isArray() && (val instanceof LazyArrayObjTags || val instanceof LazyArrayIntTags)) {
        try {
            Field taintField = f.getDeclaringClass().getDeclaredField(f.getName() + TaintUtils.TAINT_FIELD);
            Unsafe u = getUnsafe();
            u.putObject(obj, u.objectFieldOffset(taintField), val);
        } catch (NoSuchFieldException e) {
        } catch (SecurityException e) {
        }
    }
}
Also used : Unsafe(sun.misc.Unsafe) Field(java.lang.reflect.Field) LazyArrayObjTags(edu.columbia.cs.psl.phosphor.struct.LazyArrayObjTags) LazyArrayIntTags(edu.columbia.cs.psl.phosphor.struct.LazyArrayIntTags)

Example 2 with LazyArrayObjTags

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

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

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

the class RuntimeReflectionPropogator method set.

public static void set(Field f, Object obj, Object val, boolean isObjTags) throws IllegalArgumentException, IllegalAccessException {
    if (f.getType().isPrimitive()) {
        if (val instanceof Integer && f.getType().equals(Integer.TYPE)) {
            Integer i = (Integer) val;
            f.setAccessible(true);
            f.setInt(obj, i.intValue());
            try {
                if (!isObjTags) {
                    Field tf = f.getDeclaringClass().getDeclaredField(f.getName() + TaintUtils.TAINT_FIELD);
                    tf.setAccessible(true);
                    tf.setInt(obj, getTag(val));
                } else {
                    Field tf = f.getDeclaringClass().getDeclaredField(f.getName() + TaintUtils.TAINT_FIELD);
                    tf.setAccessible(true);
                    tf.set(obj, getTagObj(val));
                }
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            } catch (SecurityException e) {
                e.printStackTrace();
            }
            return;
        } else if (val instanceof Boolean && f.getType().equals(Boolean.TYPE)) {
            Boolean i = (Boolean) val;
            f.setAccessible(true);
            f.setBoolean(obj, i.booleanValue());
            try {
            // if (!isObjTags)
            // f.getDeclaringClass().getDeclaredField(f.getName() + TaintUtils.TAINT_FIELD).setInt(obj, getTag(val));
            // else
            // f.getDeclaringClass().getDeclaredField(f.getName() + TaintUtils.TAINT_FIELD).set(obj, getTagObj(val));
            // } catch (NoSuchFieldException e) {
            // e.printStackTrace();
            } catch (SecurityException e) {
                e.printStackTrace();
            }
            return;
        } else if (val instanceof Byte && f.getType().equals(Byte.TYPE)) {
            Byte i = (Byte) val;
            f.setAccessible(true);
            f.setByte(obj, i.byteValue());
            try {
                if (!isObjTags) {
                    Field tf = f.getDeclaringClass().getDeclaredField(f.getName() + TaintUtils.TAINT_FIELD);
                    tf.setAccessible(true);
                    tf.setInt(obj, getTag(val));
                } else {
                    Field tf = f.getDeclaringClass().getDeclaredField(f.getName() + TaintUtils.TAINT_FIELD);
                    tf.setAccessible(true);
                    tf.set(obj, getTagObj(val));
                }
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            } catch (SecurityException e) {
                e.printStackTrace();
            }
            return;
        } else if (val instanceof Character && f.getType().equals(Character.TYPE)) {
            Character i = (Character) val;
            f.setAccessible(true);
            f.setChar(obj, i.charValue());
            try {
                if (!isObjTags) {
                    Field tf = f.getDeclaringClass().getDeclaredField(f.getName() + TaintUtils.TAINT_FIELD);
                    tf.setAccessible(true);
                    tf.setInt(obj, getTag(val));
                } else {
                    Field tf = f.getDeclaringClass().getDeclaredField(f.getName() + TaintUtils.TAINT_FIELD);
                    tf.setAccessible(true);
                    tf.set(obj, getTagObj(val));
                }
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            } catch (SecurityException e) {
                e.printStackTrace();
            }
            return;
        } else if (val instanceof Double && f.getType().equals(Double.TYPE)) {
            Double i = (Double) val;
            f.setAccessible(true);
            f.setDouble(obj, i.doubleValue());
            try {
                if (!isObjTags) {
                    Field tf = f.getDeclaringClass().getDeclaredField(f.getName() + TaintUtils.TAINT_FIELD);
                    tf.setAccessible(true);
                    tf.setInt(obj, getTag(val));
                } else {
                    Field tf = f.getDeclaringClass().getDeclaredField(f.getName() + TaintUtils.TAINT_FIELD);
                    tf.setAccessible(true);
                    tf.set(obj, getTagObj(val));
                }
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            } catch (SecurityException e) {
                e.printStackTrace();
            }
            return;
        } else if (val instanceof Float && f.getType().equals(Float.TYPE)) {
            Float i = (Float) val;
            f.setAccessible(true);
            f.setFloat(obj, i.floatValue());
            try {
                if (!isObjTags) {
                    Field tf = f.getDeclaringClass().getDeclaredField(f.getName() + TaintUtils.TAINT_FIELD);
                    tf.setAccessible(true);
                    tf.setInt(obj, getTag(val));
                } else {
                    Field tf = f.getDeclaringClass().getDeclaredField(f.getName() + TaintUtils.TAINT_FIELD);
                    tf.setAccessible(true);
                    tf.set(obj, getTagObj(val));
                }
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            } catch (SecurityException e) {
                e.printStackTrace();
            }
            return;
        } else if (val instanceof Long && f.getType().equals(Long.TYPE)) {
            Long i = (Long) val;
            f.setAccessible(true);
            f.setLong(obj, i.longValue());
            try {
                if (!isObjTags) {
                    Field tf = f.getDeclaringClass().getDeclaredField(f.getName() + TaintUtils.TAINT_FIELD);
                    tf.setAccessible(true);
                    tf.setInt(obj, getTag(val));
                } else {
                    Field tf = f.getDeclaringClass().getDeclaredField(f.getName() + TaintUtils.TAINT_FIELD);
                    tf.setAccessible(true);
                    tf.set(obj, getTagObj(val));
                }
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            } catch (SecurityException e) {
                e.printStackTrace();
            }
            return;
        } else if (val instanceof Short && f.getType().equals(Short.TYPE)) {
            Short i = (Short) val;
            f.setAccessible(true);
            f.setShort(obj, i.shortValue());
            try {
                if (!isObjTags) {
                    Field tf = f.getDeclaringClass().getDeclaredField(f.getName() + TaintUtils.TAINT_FIELD);
                    tf.setAccessible(true);
                    tf.setInt(obj, getTag(val));
                } else {
                    Field tf = f.getDeclaringClass().getDeclaredField(f.getName() + TaintUtils.TAINT_FIELD);
                    tf.setAccessible(true);
                    tf.set(obj, getTagObj(val));
                }
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            } catch (SecurityException e) {
                e.printStackTrace();
            }
            return;
        }
    }
    f.setAccessible(true);
    f.set(obj, val);
    if (f.getType().isArray() && (val instanceof LazyArrayObjTags || val instanceof LazyArrayIntTags)) {
        try {
            Field taintField = f.getDeclaringClass().getDeclaredField(f.getName() + TaintUtils.TAINT_FIELD);
            Unsafe u = getUnsafe();
            u.putObject(obj, u.objectFieldOffset(taintField), val);
        } catch (NoSuchFieldException e) {
        } catch (SecurityException e) {
        }
    }
}
Also used : Unsafe(sun.misc.Unsafe) Field(java.lang.reflect.Field) LazyArrayObjTags(edu.columbia.cs.psl.phosphor.struct.LazyArrayObjTags) LazyArrayIntTags(edu.columbia.cs.psl.phosphor.struct.LazyArrayIntTags)

Example 5 with LazyArrayObjTags

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

the class MultiDTaintedArray method unboxCK_ATTRIBUTE.

public static final CK_ATTRIBUTE[] unboxCK_ATTRIBUTE(CK_ATTRIBUTE[] in) throws NoSuchFieldException, SecurityException, ClassNotFoundException, IllegalArgumentException, IllegalAccessException {
    if (in == null || in[0] == null)
        return null;
    boolean needsFix = false;
    Field f = in[0].getClass().getDeclaredField("pValue");
    for (Object a : in) {
        Object v = f.get(a);
        if (v instanceof LazyArrayIntTags)
            f.set(a, MultiDTaintedArrayWithIntTag.unboxRaw(v));
        else if (v instanceof LazyArrayObjTags)
            f.set(a, MultiDTaintedArrayWithObjTag.unboxRaw(v));
    }
    return in;
}
Also used : Field(java.lang.reflect.Field) LazyArrayObjTags(edu.columbia.cs.psl.phosphor.struct.LazyArrayObjTags) 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