/// <summary> /// Calls a static method with an object return type. /// </summary> /// <returns>The invoke call.</returns> /// <param name="type">Type.</param> /// <param name="name">Name.</param> /// <param name="sig">Sig.</param> /// <param name="args">Arguments.</param> /// <typeparam name="T">The 1st type parameter.</typeparam> public static T StaticInvokeObjectCall <T>( string type, string name, string sig, params object[] args) { IntPtr rawClass = AndroidJNI.FindClass(type); IntPtr method = AndroidJNI.GetStaticMethodID(rawClass, name, sig); jvalue[] jArgs = ConstructArgArray(args); try { IntPtr val = AndroidJNI.CallStaticObjectMethod(rawClass, method, jArgs); ConstructorInfo c = typeof(T).GetConstructor(new Type[] { val.GetType() }); if (c != null) { return((T)c.Invoke(new object[] { val })); } if (typeof(T).IsArray) { // make an array //TODO: handle arrays of objects return(AndroidJNIHelper.ConvertFromJNIArray <T>(val)); } Debug.Log("Trying cast...."); Type t = typeof(T); return((T)Marshal.PtrToStructure(val, t)); } finally { AndroidJNIHelper.DeleteJNIArgArray(args, jArgs); } }
public Object ObjectCallAutoResolve(string name, params object[] args) { IntPtr value = ObjectCall(name, GetClass().Replace('.', '/'), args); if (value == IntPtr.Zero) { return(null); } var clsname = new Object(value).GetClass().GetName(); var t = GetCsharpClass(clsname); if (t == null) { return(null); } ConstructorInfo c = t.GetConstructor(new[] { value.GetType() }); if (c != null) { return((Object)c.Invoke(new object[] { value })); } else { DebugPrint("Can't instantiate class, probably no constructor with IntPtr arg"); } return(null); }
/// <summary> /// Invokes a method that returns an object. /// </summary> /// <returns>The object call.</returns> /// <param name="name">Name.</param> /// <param name="sig">Sig.</param> /// <param name="theArgs">The arguments.</param> /// <typeparam name="T">The 1st type parameter.</typeparam> public T InvokeObjectCall <T>(string name, string sig, params object[] theArgs) { IntPtr methodId = AndroidJNI.GetMethodID(RawClass, name, sig); jvalue[] jArgs = ConstructArgArray(theArgs); try { IntPtr val = AndroidJNI.CallObjectMethod(raw, methodId, jArgs); if (val.Equals(IntPtr.Zero)) { return(default(T)); } ConstructorInfo ctor = typeof(T).GetConstructor(new Type[] { val.GetType() }); if (ctor != null) { return((T)ctor.Invoke(new object[] { val })); } Type t = typeof(T); return((T)Marshal.PtrToStructure(val, t)); } finally { AndroidJNIHelper.DeleteJNIArgArray(theArgs, jArgs); } }
public T InvokeObjectCall <T>(string name, string sig, params object[] theArgs) { IntPtr methodID = AndroidJNI.GetMethodID(RawClass, name, sig); jvalue[] array = ConstructArgArray(theArgs); IntPtr intPtr = AndroidJNI.CallObjectMethod(raw, methodID, array); if (intPtr.Equals(IntPtr.Zero)) { return(default(T)); } ConstructorInfo constructor = typeof(T).GetConstructor(new Type[1] { intPtr.GetType() }); if (constructor != null) { return((T)constructor.Invoke(new object[1] { intPtr })); } Type typeFromHandle = typeof(T); return((T)Marshal.PtrToStructure(intPtr, typeFromHandle)); }
public T InvokeObjectCall <T>(string name, string sig, params object[] theArgs) { T local2; IntPtr methodID = AndroidJNI.GetMethodID(this.RawClass, name, sig); jvalue[] args = ConstructArgArray(theArgs); try { IntPtr ptr = AndroidJNI.CallObjectMethod(this.raw, methodID, args); if (ptr.Equals(IntPtr.Zero)) { return(default(T)); } Type[] types = new Type[] { ptr.GetType() }; ConstructorInfo constructor = typeof(T).GetConstructor(types); if (constructor != null) { object[] parameters = new object[] { ptr }; return((T)constructor.Invoke(parameters)); } Type structureType = typeof(T); local2 = (T)Marshal.PtrToStructure(ptr, structureType); } finally { AndroidJNIHelper.DeleteJNIArgArray(theArgs, args); } return(local2); }
public static T StaticInvokeObjectCall <T>(string type, string name, string sig, params object[] args) { IntPtr intPtr = AndroidJNI.FindClass(type); IntPtr staticMethodID = AndroidJNI.GetStaticMethodID(intPtr, name, sig); jvalue[] array = ConstructArgArray(args); IntPtr intPtr2 = AndroidJNI.CallStaticObjectMethod(intPtr, staticMethodID, array); ConstructorInfo constructor = typeof(T).GetConstructor(new Type[1] { intPtr2.GetType() }); if (constructor != null) { return((T)constructor.Invoke(new object[1] { intPtr2 })); } if (typeof(T).IsArray) { return(AndroidJNIHelper.ConvertFromJNIArray <T>(intPtr2)); } Debug.Log((object)"Trying cast...."); Type typeFromHandle = typeof(T); return((T)Marshal.PtrToStructure(intPtr2, typeFromHandle)); }
public static int ClrFuncType(IntPtr l) { var type = l.GetType(1); l.PushLua(type); return(1); }
public static int ClrFuncConvert(IntPtr l) { var stype = l.GetType(1); Type dtype; l.GetLua(2, out dtype); if (dtype == null) { return(ClrFuncWrap(l)); } else { ILuaTypeHub sub = LuaTypeHub.GetTypeHub(stype); ILuaConvert nsub = sub as ILuaConvert; if (nsub != null) { var meta = nsub.GetConverter(dtype); if (meta != null) { return(meta(l, 1)); } } } var val = l.GetLua(1); l.PushLuaObject(val.ConvertTypeEx(dtype), dtype); return(1); }
public static T StaticInvokeObjectCall <T>(string type, string name, string sig, params object[] args) { IntPtr clazz = AndroidJNI.FindClass(type); IntPtr methodID = AndroidJNI.GetStaticMethodID(clazz, name, sig); jvalue[] jvalueArray = ConstructArgArray(args); IntPtr array = AndroidJNI.CallStaticObjectMethod(clazz, methodID, jvalueArray); Type[] types = new Type[] { array.GetType() }; ConstructorInfo constructor = typeof(T).GetConstructor(types); if (constructor != null) { object[] parameters = new object[] { array }; return((T)constructor.Invoke(parameters)); } if (typeof(T).IsArray) { return(AndroidJNIHelper.ConvertFromJNIArray <T>(array)); } Debug.Log("Trying cast...."); Type structureType = typeof(T); return((T)Marshal.PtrToStructure(array, structureType)); }
public static T StaticInvokeObjectCall <T>(string type, string name, string sig, params object[] args) { IntPtr num = AndroidJNI.FindClass(type); IntPtr staticMethodId = AndroidJNI.GetStaticMethodID(num, name, sig); jvalue[] jvalueArray = JavaObjWrapper.ConstructArgArray(args); IntPtr ptr = AndroidJNI.CallStaticObjectMethod(num, staticMethodId, jvalueArray); ConstructorInfo constructor = typeof(T).GetConstructor(new Type[1] { ptr.GetType() }); if ((object)constructor != null) { return((T)constructor.Invoke(new object[1] { (object)ptr })); } if (typeof(T).IsArray) { return(AndroidJNIHelper.ConvertFromJNIArray <T>(ptr)); } Debug.Log((object)"Trying cast...."); Type structureType = typeof(T); return((T)Marshal.PtrToStructure(ptr, structureType)); }
public static void TestUseCase(Assert assert) { assert.Expect(7); var t1 = new Type(); assert.Ok(t1 != null, "#565 t1"); var t2 = new ValueType(); assert.Ok(t2 != null, "#565 t2"); var t3 = new IntPtr(); assert.Ok(t3.GetType() == typeof(IntPtr), "#565 t3"); var t4 = new UIntPtr(); assert.Ok(t4.GetType() == typeof(UIntPtr), "#565 t4"); var t5 = new ParamArrayAttribute(); assert.Ok(t5 != null, "#565 t5"); var t6 = new RuntimeTypeHandle(); assert.Ok(t6.GetType() == typeof(RuntimeTypeHandle), "#565 t6"); var t7 = new RuntimeFieldHandle(); assert.Ok(t7.GetType() == typeof(RuntimeFieldHandle), "#565 t7"); }
public void Respawn(IntPtr body) { //IPhysicsObject prueba = (IPhysicsObject)body; string dato = body.GetType().ToString(); Notifier.AddMessage("Respawned"); Matrix mat = Matrix.CreateTranslation(StartPos) * Matrix.CreateRotationX(MathHelper.ToRadians(90)); Newton.NewtonBodySetMatrixRecursive(body, MatrixHelper.ToFloats(mat)); }
public static object GetInstance(IntPtr ptr, CLR_VERSION clrVersion) { object refer = ptr.GetType(); IntPtr objPtr = ptr; unsafe { *(&objPtr - (int)clrVersion) = *(&objPtr); } return(refer); }
public static object GetInstance(IntPtr ptrIN) { object refer = ptrIN.GetType(); IntPtr pointer = ptrIN; unsafe { *(&pointer - clrSub) = *(&pointer); //move the pointer of our object into the actual object on the stack! This tricks the Framework to think that "object" was declared here! } //System.Windows.Forms.MessageBox.Show(refer.ToString()); return(refer); }
private void Dispose(bool isDisposing) { Object obj = intPtr.GetType(); if (!isDisposed) { if (isDisposing) { } unsafe { } } }
public void TestInvalidType() { object x = new IntPtr(); var s = new CSerializer(); var doc = s.Serialize(x); var elem = doc.DocumentElement; Print(doc); Assert.AreEqual(0, elem.ChildNodes.Count, "Should be no children"); Assert.AreEqual(1, elem.Attributes.Count, "Should be only 1 attribute (the Type)"); Assert.AreEqual(x.GetType().AssemblyQualifiedName, XmlExtensions.GetAttributeValue(elem, s.Context.TypeAttributeName), "The Type attribute is wrong"); }
/// <summary> /// Gets the value of a static field returning an object. /// </summary> /// <returns>The static object field.</returns> /// <param name="clsName">Cls name.</param> /// <param name="name">Name.</param> /// <param name="sig">Sig.</param> /// <typeparam name="T">The 1st type parameter.</typeparam> public static T GetStaticObjectField <T>(string clsName, string name, string sig) { IntPtr rawClass = AndroidJNI.FindClass(clsName); IntPtr id = AndroidJNI.GetStaticFieldID(rawClass, name, sig); IntPtr val = AndroidJNI.GetStaticObjectField(rawClass, id); ConstructorInfo c = typeof(T).GetConstructor(new Type[] { val.GetType() }); if (c != null) { return((T)c.Invoke(new object[] { val })); } Type t = typeof(T); return((T)Marshal.PtrToStructure(val, t)); }
public static int ClrFuncWrap(IntPtr l) { var type = l.GetType(1); ILuaTypeHub sub = LuaTypeHub.GetTypeHub(type); ILuaNative nsub = sub as ILuaNative; if (nsub == null) { l.PushLuaObject(l.GetLua(1)); return(1); } else { nsub.Wrap(l, 1); return(1); } }
public static T GetStaticObjectField <T>(string clsName, string name, string sig) { IntPtr clazz = AndroidJNI.FindClass(clsName); IntPtr fieldID = AndroidJNI.GetStaticFieldID(clazz, name, sig); IntPtr staticObjectField = AndroidJNI.GetStaticObjectField(clazz, fieldID); System.Type[] types = new System.Type[] { staticObjectField.GetType() }; ConstructorInfo constructor = typeof(T).GetConstructor(types); if (constructor != null) { object[] parameters = new object[] { staticObjectField }; return((T)constructor.Invoke(parameters)); } System.Type structureType = typeof(T); return((T)Marshal.PtrToStructure(staticObjectField, structureType)); }
/// <summary> /// Execute a payload in the target process at a specified address. /// </summary> /// <author>The Wover (@TheRealWover)</author> /// <param name="Payload">The type of payload to execute.</param> /// <param name="BaseAddress">The base address of the payload.</param> /// <param name="Process">The target process.</param> /// <returns>bool</returns> public virtual bool Inject(PayloadType Payload, IntPtr BaseAddress, Process Process) { Type[] funcPrototype = new Type[] { Payload.GetType(), BaseAddress.GetType(), Process.GetType() }; try { // Get delegate to the overload of Inject that supports the type of payload passed in MethodInfo inject = this.GetType().GetMethod("Inject", funcPrototype); // Dynamically invoke the appropriate Allocate overload return((bool)inject.Invoke(this, new object[] { Payload, BaseAddress, Process })); } // If there is no such method catch (ArgumentNullException) { throw new PayloadTypeNotSupported(Payload.GetType()); } }
/// <summary> /// Allocate the payload to the target process at a specified address. /// </summary> /// <author>The Wover (@TheRealWover)</author> /// <param name="Payload">The payload to allocate to the target process.</param> /// <param name="Process">The target process.</param> /// <param name="Address">The address at which to allocate the payload in the target process.</param> /// <returns>True when allocation was successful. Otherwise, throws relevant exceptions.</returns> public virtual IntPtr Allocate(PayloadType Payload, Process Process, IntPtr Address) { Type[] funcPrototype = new Type[] { Payload.GetType(), typeof(Process), Address.GetType() }; try { // Get delegate to the overload of Allocate that supports the type of payload passed in MethodInfo allocate = this.GetType().GetMethod("Allocate", funcPrototype); // Dynamically invoke the appropriate Allocate overload return((IntPtr)allocate.Invoke(this, new object[] { Payload, Process, Address })); } // If there is no such method catch (ArgumentNullException) { throw new PayloadTypeNotSupported(Payload.GetType()); } }
public static object GetInstance64(IntPtr wantedObject) { if (wantedObject == null) { return(IntPtr.Zero); } IntPtr objectPointer = wantedObject; object refer = wantedObject.GetType(); IntPtr objectPointer2 = (IntPtr)8; unsafe { //System.Windows.Forms.MessageBox.Show("Address of objectPointer:" + (uint)(&objectPointer) + " address of objectPointer 2 " + (uint)(&objectPointer2)); *(&objectPointer + clrSub) = *(&objectPointer); } //System.Windows.Forms.MessageBox.Show(refer.ToString()); return(refer); }
public static T GetStaticObjectField <T>(string clsName, string name, string sig) { IntPtr num = AndroidJNI.FindClass(clsName); IntPtr staticFieldId = AndroidJNI.GetStaticFieldID(num, name, sig); IntPtr staticObjectField = AndroidJNI.GetStaticObjectField(num, staticFieldId); ConstructorInfo constructor = typeof(T).GetConstructor(new Type[1] { staticObjectField.GetType() }); if ((object)constructor != null) { return((T)constructor.Invoke(new object[1] { (object)staticObjectField })); } Type structureType = typeof(T); return((T)Marshal.PtrToStructure(staticObjectField, structureType)); }
public void onResult(AndroidJavaObject arg_Result_1) { R local; IntPtr rawObject = arg_Result_1.GetRawObject(); Type[] types = new Type[] { rawObject.GetType() }; ConstructorInfo constructor = typeof(R).GetConstructor(types); if (constructor != null) { object[] parameters = new object[] { rawObject }; local = (R)constructor.Invoke(parameters); } else { local = (R)typeof(R).GetConstructor(new Type[0]).Invoke(new object[0]); Marshal.PtrToStructure <R>(rawObject, local); } this.OnResult(local); }
// Returns true if the expected result is right // Returns false if the expected result is wrong public bool PosTest2() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest2: The Type is IntPtr "); try { IntPtr myInt = new IntPtr(5); if (myInt.GetType().HasElementType) { TestLibrary.TestFramework.LogError("001", "HasElementType should return false."); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e); retVal = false; } return(retVal); }
static void Main() { // ↓数値で初期化できない IntPtr oldType = new IntPtr(0); // ↓数値で初期化できる nint newType = 0; // ↓できない //oldType++; // ↓できる newType++; // ↓できる newType = oldType; // ↓できる oldType = newType; // 値の型名を教えて Console.WriteLine(oldType.GetType().Name); Console.WriteLine(newType.GetType().Name); }
public static T GetStaticObjectField <T>(string clsName, string name, string sig) { IntPtr intPtr = AndroidJNI.FindClass(clsName); IntPtr staticFieldID = AndroidJNI.GetStaticFieldID(intPtr, name, sig); IntPtr staticObjectField = AndroidJNI.GetStaticObjectField(intPtr, staticFieldID); ConstructorInfo constructor = typeof(T).GetConstructor(new Type[1] { staticObjectField.GetType() }); if (constructor != null) { return((T)constructor.Invoke(new object[1] { staticObjectField })); } Type typeFromHandle = typeof(T); return((T)Marshal.PtrToStructure(staticObjectField, typeFromHandle)); }
public T InvokeObjectCall <T>(string name, string sig, params object[] theArgs) { IntPtr ptr = AndroidJNI.CallObjectMethod(this.raw, AndroidJNI.GetMethodID(AndroidJNI.GetObjectClass(this.raw), name, sig), JavaObjWrapper.ConstructArgArray(theArgs)); if (ptr.Equals((object)IntPtr.Zero)) { return(default(T)); } ConstructorInfo constructor = typeof(T).GetConstructor(new Type[1] { ptr.GetType() }); if ((object)constructor != null) { return((T)constructor.Invoke(new object[1] { (object)ptr })); } Type structureType = typeof(T); return((T)Marshal.PtrToStructure(ptr, structureType)); }
// Returns true if the expected result is right // Returns false if the expected result is wrong public bool PosTest2() { bool retVal = true; TestLibrary.TestFramework.BeginScenario("PosTest2: The Type is IntPtr "); try { IntPtr myInt=new IntPtr(5); if (myInt.GetType().HasElementType) { TestLibrary.TestFramework.LogError("001", "HasElementType should return false."); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e); retVal = false; } return retVal; }
public T InvokeObjectCall <T>(string name, string sig, params object[] theArgs) { IntPtr methodID = AndroidJNI.GetMethodID(AndroidJNI.GetObjectClass(this.raw), name, sig); jvalue[] args = ConstructArgArray(theArgs); IntPtr ptr = AndroidJNI.CallObjectMethod(this.raw, methodID, args); if (ptr.Equals(IntPtr.Zero)) { return(default(T)); } System.Type[] types = new System.Type[] { ptr.GetType() }; ConstructorInfo constructor = typeof(T).GetConstructor(types); if (constructor != null) { object[] parameters = new object[] { ptr }; return((T)constructor.Invoke(parameters)); } System.Type structureType = typeof(T); return((T)Marshal.PtrToStructure(ptr, structureType)); }
public void onResult(AndroidJavaObject arg_Result_1) { IntPtr rawObject = arg_Result_1.GetRawObject(); ConstructorInfo constructor = typeof(R).GetConstructor(new Type[1] { rawObject.GetType() }); R arg_Result_1_1; if ((object)constructor != null) { arg_Result_1_1 = (R)constructor.Invoke(new object[1] { (object)rawObject }); } else { arg_Result_1_1 = (R)typeof(R).GetConstructor(new Type[0]).Invoke(new object[0]); Marshal.PtrToStructure(rawObject, (object)arg_Result_1_1); } this.OnResult(arg_Result_1_1); }