Search in sources :

Example 1 with LazyArrayIntTags

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

use of edu.columbia.cs.psl.phosphor.struct.LazyArrayIntTags 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 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, boolean isObjTags) {
    MethodInvoke ret = new MethodInvoke();
    if (m == null) {
        ret.a = in;
        ret.o = owner;
        ret.m = m;
        return ret;
    }
    if (// && Instrumenter.isIgnoredMethodFromOurAnalysis(m.getDeclaringClass().getName().replace(".", "/"), m.getName(), Type.getMethodDescriptor(m)))
    Configuration.WITH_SELECTIVE_INST) {
        // ret.m = getUnTaintMethod(m, isObjTags);
        ret.m = getOrigMethod(m, isObjTags);
        ret.o = owner;
        ret.a = in;
        if (ret.a != null && ret.a.getClass().isArray() && ret.a.getClass().getComponentType() == Object.class)
            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();
                }
            }
    } else {
        ret = fixAllArgs(m, owner, in, isObjTags);
    }
    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 4 with LazyArrayIntTags

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

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

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