use of edu.columbia.cs.psl.phosphor.struct.MethodInvoke 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.MethodInvoke 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.MethodInvoke 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.MethodInvoke 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;
}
Aggregations