use of edu.columbia.cs.psl.phosphor.struct.LazyArrayIntTags 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;
}
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, ControlTaintTagStack ctrl) {
MethodInvoke ret = new MethodInvoke();
if (m == null) {
ret.a = in;
ret.o = owner;
ret.m = m;
return ret;
}
ret.m = getOrigMethod(m, true);
ret.o = owner;
ret.a = in;
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();
}
}
return ret;
}
use of edu.columbia.cs.psl.phosphor.struct.LazyArrayIntTags 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;
}
Aggregations