Search in sources :

Example 1 with TaintedBooleanWithIntTag

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

the class NativeHelper method ensureIsBoxed.

@SuppressWarnings("rawtypes")
public static final Collection ensureIsBoxed(Collection in) {
    if (in != null) {
        Collection tmp = null;
        for (Object o : in) {
            if (o == null)
                break;
            Type t = Type.getType(o.getClass());
            if (t.getSort() == Type.ARRAY && t.getElementType().getSort() != Type.OBJECT) {
                if (tmp == null) {
                    try {
                        tmp = (Collection) in.getClass().getConstructor().newInstance(null);
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
                tmp.add$$PHOSPHORTAGGED(MultiDTaintedArrayWithIntTag.boxIfNecessary(o), new TaintedBooleanWithIntTag());
            } else
                break;
        }
        if (tmp != null) {
            in.clear();
            tmp.add$$PHOSPHORTAGGED(tmp, new TaintedBooleanWithIntTag());
        }
    }
    return in;
}
Also used : Type(org.objectweb.asm.Type) TaintedBooleanWithIntTag(edu.columbia.cs.psl.phosphor.struct.TaintedBooleanWithIntTag) Collection(java.util.Collection)

Example 2 with TaintedBooleanWithIntTag

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

the class NativeHelper method ensureIsUnBoxed.

public static final Collection ensureIsUnBoxed(Collection in) {
    if (in != null) {
        Collection tmp = null;
        for (Object o : in) {
            if (o != null && MultiDTaintedArrayWithIntTag.isPrimitiveBoxClass(o.getClass()) != null) {
                if (tmp == null) {
                    try {
                        tmp = (Collection) in.getClass().getConstructor().newInstance(null);
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
                tmp.add$$PHOSPHORTAGGED(MultiDTaintedArrayWithIntTag.unboxRaw(o), new TaintedBooleanWithIntTag());
            } else
                break;
        }
        if (tmp != null) {
            in.clear();
            tmp.add$$PHOSPHORTAGGED(tmp, new TaintedBooleanWithIntTag());
        }
    }
    return in;
}
Also used : TaintedBooleanWithIntTag(edu.columbia.cs.psl.phosphor.struct.TaintedBooleanWithIntTag) Collection(java.util.Collection)

Example 3 with TaintedBooleanWithIntTag

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

the class MultiDTaintedArrayWithIntTag method boxIfNecessary.

public static final Object boxIfNecessary(final Object in, final HashSet<Object> includedObjs) {
    if (in != null && in.getClass().isArray()) {
        Class tmp = in.getClass();
        int dims = 0;
        while (tmp.isArray()) {
            tmp = tmp.getComponentType();
            dims++;
        }
        if (tmp.isPrimitive()) {
            // Is prim arraytype
            if (dims > 1) {
                // this should never be possible.
                Type t = Type.getType(in.getClass());
                return initWithEmptyTaints((Object[]) in, t.getElementType().getSort(), t.getDimensions());
            } else {
                if (tmp == Boolean.TYPE)
                    return new LazyBooleanArrayIntTags((boolean[]) in);
                if (tmp == Byte.TYPE)
                    return new LazyByteArrayIntTags(((byte[]) in));
                if (tmp == Character.TYPE)
                    return new LazyCharArrayIntTags(((char[]) in));
                if (tmp == Double.TYPE)
                    return new LazyDoubleArrayIntTags(((double[]) in));
                if (tmp == Float.TYPE)
                    return new LazyFloatArrayIntTags(((float[]) in));
                if (tmp == Integer.TYPE)
                    return new LazyIntArrayIntTags(((int[]) in));
                if (tmp == Long.TYPE)
                    return new LazyLongArrayIntTags(((long[]) in));
                if (tmp == Short.TYPE)
                    return new LazyShortArrayIntTags(((short[]) in));
                throw new IllegalArgumentException();
            }
        } else if (in.getClass().getComponentType().getName().equals("java.lang.Object")) {
            TaintedBooleanWithIntTag tmpRet = new TaintedBooleanWithIntTag();
            Object[] _in = (Object[]) in;
            for (int i = 0; i < _in.length; i++) {
                if (includedObjs.add$$PHOSPHORTAGGED(_in[i], tmpRet).val)
                    _in[i] = boxIfNecessary(_in[i], includedObjs);
            }
        }
    }
    return in;
}
Also used : TaintedBooleanWithIntTag(edu.columbia.cs.psl.phosphor.struct.TaintedBooleanWithIntTag) LazyFloatArrayIntTags(edu.columbia.cs.psl.phosphor.struct.LazyFloatArrayIntTags) LazyIntArrayIntTags(edu.columbia.cs.psl.phosphor.struct.LazyIntArrayIntTags) LazyShortArrayIntTags(edu.columbia.cs.psl.phosphor.struct.LazyShortArrayIntTags) Type(org.objectweb.asm.Type) LazyLongArrayIntTags(edu.columbia.cs.psl.phosphor.struct.LazyLongArrayIntTags) LazyDoubleArrayIntTags(edu.columbia.cs.psl.phosphor.struct.LazyDoubleArrayIntTags) LazyBooleanArrayIntTags(edu.columbia.cs.psl.phosphor.struct.LazyBooleanArrayIntTags) LazyByteArrayIntTags(edu.columbia.cs.psl.phosphor.struct.LazyByteArrayIntTags) LazyCharArrayIntTags(edu.columbia.cs.psl.phosphor.struct.LazyCharArrayIntTags)

Example 4 with TaintedBooleanWithIntTag

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

the class BoxedPrimitiveStoreWithIntTags method booleanValue.

public static TaintedBooleanWithIntTag booleanValue(Boolean z) {
    TaintedBooleanWithIntTag ret = new TaintedBooleanWithIntTag();
    ret.val = z;
    if (z.valueOf && tags.containsKey(z))
        ret.taint = tags.get(z);
    return ret;
}
Also used : TaintedBooleanWithIntTag(edu.columbia.cs.psl.phosphor.struct.TaintedBooleanWithIntTag)

Example 5 with TaintedBooleanWithIntTag

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

TaintedBooleanWithIntTag (edu.columbia.cs.psl.phosphor.struct.TaintedBooleanWithIntTag)5 Collection (java.util.Collection)2 Type (org.objectweb.asm.Type)2 LazyArrayIntTags (edu.columbia.cs.psl.phosphor.struct.LazyArrayIntTags)1 LazyArrayObjTags (edu.columbia.cs.psl.phosphor.struct.LazyArrayObjTags)1 LazyBooleanArrayIntTags (edu.columbia.cs.psl.phosphor.struct.LazyBooleanArrayIntTags)1 LazyByteArrayIntTags (edu.columbia.cs.psl.phosphor.struct.LazyByteArrayIntTags)1 LazyCharArrayIntTags (edu.columbia.cs.psl.phosphor.struct.LazyCharArrayIntTags)1 LazyDoubleArrayIntTags (edu.columbia.cs.psl.phosphor.struct.LazyDoubleArrayIntTags)1 LazyFloatArrayIntTags (edu.columbia.cs.psl.phosphor.struct.LazyFloatArrayIntTags)1 LazyIntArrayIntTags (edu.columbia.cs.psl.phosphor.struct.LazyIntArrayIntTags)1 LazyLongArrayIntTags (edu.columbia.cs.psl.phosphor.struct.LazyLongArrayIntTags)1 LazyShortArrayIntTags (edu.columbia.cs.psl.phosphor.struct.LazyShortArrayIntTags)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