Example #1
0
  protected Value marshalValueObjectToNative(
      Function fn,
      MarshalerMethod marshalerMethod,
      Type nativeType,
      Value env,
      Value object,
      long flags) {

    Invokestatic invokestatic = marshalerMethod.getInvokeStatic(sootMethod.getDeclaringClass());
    trampolines.add(invokestatic);
    Value result = call(fn, invokestatic.getFunctionRef(), env, object, new IntegerConstant(flags));
    return marshalPrimitiveToNative(fn, marshalerMethod.getMethod(), result);
  }
Example #2
0
  protected Value marshalObjectToNative(
      Function fn,
      MarshalerMethod marshalerMethod,
      MarshaledArg marshaledArg,
      Type nativeType,
      Value env,
      Value object,
      long flags) {

    Invokestatic invokestatic = marshalerMethod.getInvokeStatic(sootMethod.getDeclaringClass());
    trampolines.add(invokestatic);
    Value handle = call(fn, invokestatic.getFunctionRef(), env, object, new IntegerConstant(flags));

    Variable nativeValue = fn.newVariable(nativeType);
    if (nativeType instanceof StructureType || nativeType instanceof ArrayType) {
      Variable tmp = fn.newVariable(new PointerType(nativeType));
      fn.add(new Inttoptr(tmp, handle, tmp.getType()));
      fn.add(new Load(nativeValue, tmp.ref()));
    } else {
      fn.add(new Inttoptr(nativeValue, handle, nativeType));
    }

    if (marshaledArg != null) {
      marshaledArg.handle = handle;
      marshaledArg.object = object;
    }

    return nativeValue.ref();
  }
Example #3
0
  protected Value marshalNativeToArray(
      Function fn,
      MarshalerMethod marshalerMethod,
      Value env,
      String arrayClassName,
      Value nativeValue,
      long flags,
      int[] dimensions) {

    Invokestatic invokeToObject = marshalerMethod.getInvokeStatic(sootMethod.getDeclaringClass());
    trampolines.add(invokeToObject);

    Variable handle = fn.newVariable(I64);
    fn.add(new Ptrtoint(handle, nativeValue, I64));

    Value valueClass = ldcClass(fn, arrayClassName, env);
    List<Value> args = new ArrayList<>();
    args.add(env);
    args.add(valueClass);
    args.add(handle.ref());
    args.add(new IntegerConstant(flags));
    args.addAll(arrayDimensionsValues(dimensions));

    return call(fn, invokeToObject.getFunctionRef(), args);
  }
Example #4
0
  protected Value marshalNativeToValueObject(
      Function fn,
      MarshalerMethod marshalerMethod,
      Value env,
      String valueClassName,
      Value nativeValue,
      long flags) {

    Invokestatic invokeToObject = marshalerMethod.getInvokeStatic(sootMethod.getDeclaringClass());
    trampolines.add(invokeToObject);

    Value valueClass = ldcClass(fn, valueClassName, env);

    nativeValue = marshalNativeToPrimitive(fn, marshalerMethod.getMethod(), 1, nativeValue);

    return call(
        fn,
        invokeToObject.getFunctionRef(),
        env,
        valueClass,
        nativeValue,
        new IntegerConstant(flags));
  }
Example #5
0
  protected Value marshalNativeToObject(
      Function fn,
      MarshalerMethod marshalerMethod,
      MarshaledArg marshaledArg,
      Value env,
      String valueClassName,
      Value nativeValue,
      long flags) {

    if (nativeValue.getType() instanceof StructureType) {
      nativeValue = createStackCopy(fn, nativeValue);
    }

    Invokestatic invokestatic = marshalerMethod.getInvokeStatic(sootMethod.getDeclaringClass());
    trampolines.add(invokestatic);

    Value valueClass = ldcClass(fn, valueClassName, env);

    Variable handle = fn.newVariable(I64);
    fn.add(new Ptrtoint(handle, nativeValue, I64));

    Value object =
        call(
            fn,
            invokestatic.getFunctionRef(),
            env,
            valueClass,
            handle.ref(),
            new IntegerConstant(flags));

    if (marshaledArg != null) {
      marshaledArg.handle = handle.ref();
      marshaledArg.object = object;
    }

    return object;
  }
Example #6
0
  protected void marshalArrayToNative(
      Function fn,
      MarshalerMethod marshalerMethod,
      Value env,
      Value object,
      Value destPtr,
      long flags,
      int[] dimensions) {

    Invokestatic invokestatic = marshalerMethod.getInvokeStatic(sootMethod.getDeclaringClass());
    trampolines.add(invokestatic);

    Variable handle = fn.newVariable(I64);
    fn.add(new Ptrtoint(handle, destPtr, I64));

    List<Value> args = new ArrayList<>();
    args.add(env);
    args.add(object);
    args.add(handle.ref());
    args.add(new IntegerConstant(flags));
    args.addAll(arrayDimensionsValues(dimensions));

    call(fn, invokestatic.getFunctionRef(), args);
  }