Esempio n. 1
0
        private void SetupVTables(bool destructorOnly = false)
        {
            if (__OriginalVTables != null)
            {
                return;
            }
            var native = (IBar.__Internal *)__Instance.ToPointer();

            __OriginalVTables = new void *[] { native->vptr_IBar.ToPointer() };

            if (_Thunks == null)
            {
                _Thunks = new void *[2];
                _GetNumber_0DelegateInstance += _GetNumber_0DelegateHook;
                _Thunks[0] = Marshal.GetFunctionPointerForDelegate(_GetNumber_0DelegateInstance).ToPointer();
                _dtor_0DelegateInstance += _dtor_0DelegateHook;
                _Thunks[1] = Marshal.GetFunctionPointerForDelegate(_dtor_0DelegateInstance).ToPointer();
            }

            if (destructorOnly)
            {
                if (__ManagedVTablesDtorOnly == null)
                {
                    __ManagedVTablesDtorOnly = new void *[1];
                    var vtptr  = Marshal.AllocHGlobal(5 * 8);
                    var vfptr0 = vtptr + 2 * 8;
                    __ManagedVTablesDtorOnly[0] = vfptr0.ToPointer();
                    *(void **)(vfptr0 + -16)    = *(void **)(native->vptr_IBar + -16);
                    *(void **)(vfptr0 + -8)     = *(void **)(native->vptr_IBar + -8);
                    *(void **)(vfptr0 + 0)      = *(void **)(native->vptr_IBar + 0);
                    *(void **)(vfptr0 + 8)      = *(void **)(native->vptr_IBar + 8);
                    *(void **)(vfptr0 + 16)     = _Thunks[1];
                }

                native->vptr_IBar = new IntPtr(__ManagedVTablesDtorOnly[0]);
            }
            else
            {
                if (__ManagedVTables == null)
                {
                    __ManagedVTables = new void *[1];
                    var vtptr  = Marshal.AllocHGlobal(5 * 8);
                    var vfptr0 = vtptr + 2 * 8;
                    __ManagedVTables[0]      = vfptr0.ToPointer();
                    *(void **)(vfptr0 + -16) = *(void **)(native->vptr_IBar + -16);
                    *(void **)(vfptr0 + -8)  = *(void **)(native->vptr_IBar + -8);
                    *(void **)(vfptr0 + 0)   = _Thunks[0];
                    *(void **)(vfptr0 + 8)   = *(void **)(native->vptr_IBar + 8);
                    *(void **)(vfptr0 + 16)  = _Thunks[1];
                }

                native->vptr_IBar = new IntPtr(__ManagedVTables[0]);
            }
        }
Esempio n. 2
0
        private void SetupVTables(bool destructorOnly = false)
        {
            if (__OriginalVTables != null)
                return;
            var native = (Internal*) __Instance.ToPointer();

            __OriginalVTables = new void*[] { ((Internal*) native)->vfptr0.ToPointer() };

            if (_Thunks == null)
            {
                _Thunks = new void*[2];
                _dtor_0DelegateInstance += _dtor_0DelegateHook;
                _Thunks[0] = Marshal.GetFunctionPointerForDelegate(_dtor_0DelegateInstance).ToPointer();
                _DoExecute_0DelegateInstance += _DoExecute_0DelegateHook;
                _Thunks[1] = Marshal.GetFunctionPointerForDelegate(_DoExecute_0DelegateInstance).ToPointer();
            }

            if (destructorOnly)
            {
                if (__ManagedVTablesDtorOnly == null)
                {
                    __ManagedVTablesDtorOnly = new void*[1];
                    var vtptr = Marshal.AllocHGlobal(5 * 4);
                    var vfptr0 = vtptr + 2 * 4;
                    __ManagedVTablesDtorOnly[0] = vfptr0.ToPointer();
                    *(void**)(vfptr0 + -8) = *(void**)(native->vfptr0 + -8);
                    *(void**)(vfptr0 + -4) = *(void**)(native->vfptr0 + -4);
                    *(void**)(vfptr0 + 0) = *(void**)(native->vfptr0 + 0);
                    *(void**)(vfptr0 + 4) = _Thunks[0];
                    *(void**)(vfptr0 + 8) = *(void**)(native->vfptr0 + 8);
                }

                native->vfptr0 = new IntPtr(__ManagedVTablesDtorOnly[0]);
            }
            else
            {
                if (__ManagedVTables == null)
                {
                    __ManagedVTables = new void*[1];
                    var vtptr = Marshal.AllocHGlobal(5 * 4);
                    var vfptr0 = vtptr + 2 * 4;
                    __ManagedVTables[0] = vfptr0.ToPointer();
                    *(void**)(vfptr0 + -8) = *(void**)(native->vfptr0 + -8);
                    *(void**)(vfptr0 + -4) = *(void**)(native->vfptr0 + -4);
                    *(void**)(vfptr0 + 0) = *(void**)(native->vfptr0 + 0);
                    *(void**)(vfptr0 + 4) = _Thunks[0];
                    *(void**)(vfptr0 + 8) = _Thunks[1];
                }

                native->vfptr0 = new IntPtr(__ManagedVTables[0]);
            }
        }