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) {
}
}
}
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;
}
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;
}
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) {
}
}
}
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;
}
Aggregations