use of edu.columbia.cs.psl.phosphor.struct.TaintedWithObjTag in project phosphor by gmu-swe.
the class ReflectionMasker method fixAllArgs.
public static MethodInvoke fixAllArgs(Method m, Object owner, Object[] in, ControlTaintTagStack ctrl) {
// System.out.println("Making slow call to " + m);
MethodInvoke ret = new MethodInvoke();
m.setAccessible(true);
if (Instrumenter.isIgnoredClass(m.getDeclaringClass().getName().replace('.', '/'))) {
ret.a = in;
ret.o = owner;
ret.m = m;
return ret;
}
if ((IS_KAFFE) || !m.PHOSPHOR_TAGmarked) {
if (IS_KAFFE) {
if (in.length > 0)
m = getTaintMethodControlTrack(m);
} else {
m = getTaintMethodControlTrack(m);
}
}
m.setAccessible(true);
ret.a = in;
ret.o = owner;
ret.m = m;
// System.out.println("FAA: " +m + " "+owner + " " + Arrays.toString(in));
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
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 (m.getParameterTypes()[j].isArray() && (m.getParameterTypes()[j].getComponentType().isPrimitive() || m.getParameterTypes()[j].getComponentType().equals(Configuration.TAINT_TAG_OBJ_CLASS))) {
LazyArrayObjTags arr = ((LazyArrayObjTags) in[i]);
ret.a[j] = arr.taints;
j++;
ret.a[j] = arr.getVal();
j++;
continue;
}
ret.a[j] = in[i];
j++;
}
}
if (ret.a != null && ret.a.length > j) {
ret.a[j] = ctrl;
j++;
}
// System.out.println("So far, " + Arrays.toString(ret.a));
if (in == null && m != null && m.getParameterTypes().length == 1) {
ret.a = new Object[1];
ret.a[0] = ctrl;
} else if ((in == null && m != null && m.getParameterTypes().length == 2) || (in != null && j != in.length - 1)) {
if (in == null) {
ret.a = new Object[2];
ret.a[0] = ctrl;
j++;
}
final Class returnType = m.getReturnType();
if (TaintedPrimitiveWithIntTag.class.isAssignableFrom(returnType) || TaintedPrimitiveWithObjTag.class.isAssignableFrom(returnType)) {
try {
// System.out.println(returnType + " is return type");
ret.a[j] = returnType.newInstance();
// System.out.println("new inst " + returnType.newInstance());
if (ret.a[j].getClass().equals(Boolean.class)) {
System.exit(-1);
}
} 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.TaintedWithObjTag 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.TaintedWithObjTag in project phosphor by gmu-swe.
the class TaintUtils method enumValueOf.
public static <T extends Enum<T>> T enumValueOf(Class<T> enumType, String name) {
T ret = Enum.valueOf(enumType, name);
if (((Object) name) instanceof TaintedWithIntTag) {
int tag = ((TaintedWithIntTag) ((Object) name)).getPHOSPHOR_TAG();
if (tag != 0) {
ret = shallowClone(ret);
((TaintedWithIntTag) ret).setPHOSPHOR_TAG(tag);
}
} else if (((Object) name) instanceof TaintedWithObjTag) {
Object tag = ((TaintedWithObjTag) ((Object) name)).getPHOSPHOR_TAG();
if (tag != null) {
ret = shallowClone(ret);
((TaintedWithObjTag) ret).setPHOSPHOR_TAG(tag);
}
}
return ret;
}
Aggregations