예제 #1
0
        public void ClearBlockedAnimationIds()
        {
            NativeScript.Globals globals = ReadValue <NativeScript.Globals>(nativeScriptGlobalsAddress);
            byte[] blockedAnimationIds   = globals.BlockedAnimationIds;
            if (blockedAnimationIds == null)
            {
                return;
            }

            byte[] buffer = new byte[globals.BlockedAnimationIds.Length];

            IntPtr written;

            WriteProcessMemoryEx(ProcessHandle, nativeScriptGlobalsAddress + NativeScript.Globals.OffsetBlockedAnimationIds,
                                 buffer, (IntPtr)buffer.Length, out written);
        }
예제 #2
0
        public byte[] GetBlockedAnimationIds()
        {
            List <byte> result = new List <byte>();

            if (!UpdateState())
            {
                return(result.ToArray());
            }

            NativeScript.Globals globals = ReadValue <NativeScript.Globals>(nativeScriptGlobalsAddress);
            for (int i = 0; i < globals.BlockedAnimationIds.Length; i++)
            {
                if (globals.BlockedAnimationIds[i] != 0)
                {
                    result.Add((byte)i);
                }
            }

            return(result.ToArray());
        }
예제 #3
0
        private void BlockUnblockAnimationIds(int[] animationIds, bool block)
        {
            if (!UpdateState() || animationIds == null)
            {
                return;
            }

            NativeScript.Globals globals = ReadValue <NativeScript.Globals>(nativeScriptGlobalsAddress);
            byte[] buffer = globals.BlockedAnimationIds.ToArray();

            foreach (byte animationId in animationIds)
            {
                if (animationId < buffer.Length)
                {
                    buffer[animationId] = (byte)(block ? 1 : 0);
                }
            }

            IntPtr written;

            WriteProcessMemoryEx(ProcessHandle, nativeScriptGlobalsAddress + NativeScript.Globals.OffsetBlockedAnimationIds,
                                 buffer, (IntPtr)buffer.Length, out written);
        }
예제 #4
0
        private bool LoadNativeScript(ref NativeScript.Globals globals, bool callEntryPoint)
        {
            if (!UpdateState() || IsNativeScriptLoaded)
            {
                return(false);
            }

            IntPtr processHandle = ProcessHandle;

            // Buffer for the NativeScript code
            byte[] buffer = new byte[NativeScript.Scripts[Version].Buffer.Length];
            Buffer.BlockCopy(NativeScript.Scripts[Version].Buffer, 0, buffer, 0, buffer.Length);

            IntPtr address = VirtualAllocEx(processHandle, IntPtr.Zero, (IntPtr)buffer.Length,
                                            AllocationType.Commit, MemoryProtection.ExecuteReadWrite);

            if (address == IntPtr.Zero)
            {
                return(false);
            }

            // Write the NativeScript code
            IntPtr bytesWritten;

            if (!WriteProcessMemoryEx(processHandle, (IntPtr)address.ToInt64(), buffer, (IntPtr)buffer.Length, out bytesWritten) ||
                bytesWritten.ToInt32() != buffer.Length)
            {
                return(false);
            }

            // Set the Globals base address and write the Globals structure to memory
            globals.BaseAddress = address;

            byte[] globalsBuffer  = StructToByteArray(globals);
            IntPtr globalsAddress = VirtualAllocEx(processHandle, IntPtr.Zero, (IntPtr)globalsBuffer.Length,
                                                   AllocationType.Commit, MemoryProtection.ReadWrite);

            if (globalsAddress == IntPtr.Zero ||
                !WriteProcessMemoryEx(processHandle, globalsAddress, globalsBuffer, (IntPtr)globalsBuffer.Length, out bytesWritten) ||
                bytesWritten.ToInt32() != globalsBuffer.Length)
            {
                return(false);
            }

            // Write the globals address to the NativeScript GetGlobals function
            byte[] globalsAddressBuffer = BitConverter.GetBytes(globalsAddress.ToInt64());
            Debug.Assert(globalsAddressBuffer.Length == 8);
            if (!WriteProcessMemoryEx(processHandle, (IntPtr)(address.ToInt64() + NativeScript.Scripts[Version].GlobalsAddressOffset), globalsAddressBuffer,
                                      (IntPtr)globalsAddressBuffer.Length, out bytesWritten) || bytesWritten.ToInt32() != globalsAddressBuffer.Length)
            {
                return(false);
            }

            nativeScriptAddress        = address;
            nativeScriptGlobalsAddress = globalsAddress;

            if (callEntryPoint)
            {
                CallNativeScriptFunction("EntryPoint");
            }

            return(true);
        }
예제 #5
0
 private bool LoadNativeScript(ref NativeScript.Globals globals)
 {
     return(LoadNativeScript(ref globals, true));
 }
예제 #6
0
        public void SetTimeMultiplier(double multiplier, bool enable)
        {
            if (!UpdateState() || nativeScriptGlobalsAddress == IntPtr.Zero)
            {
                return;
            }

            // Suspend the process
            List <IntPtr> threadHandles = BeginSuspendProcess();

            NativeScript.Globals globals = ReadValue <NativeScript.Globals>(nativeScriptGlobalsAddress);

            bool firstRun = !timeMultiplierHooksInitialized;

            if (!timeMultiplierHooksInitialized)
            {
                if (globals.QueryPerformanceCounterFuncAddr != IntPtr.Zero && queryPerformanceCounterAddress != IntPtr.Zero)
                {
                    WriteValue(queryPerformanceCounterAddress, GetNativeScriptFunctionAddress("QueryPerformanceCounter_hook"));
                }
                if (globals.GetTickCount64FuncAddr != IntPtr.Zero && getTickCount64Address != IntPtr.Zero)
                {
                    WriteValue(getTickCount64Address, GetNativeScriptFunctionAddress("GetTickCount64_hook"));
                }
                if (globals.GetTickCountFuncAddr != IntPtr.Zero && getTickCountAddress != IntPtr.Zero)
                {
                    WriteValue(getTickCountAddress, GetNativeScriptFunctionAddress("GetTickCount_hook"));
                }
                if (globals.TimeGetTimeFuncAddr != IntPtr.Zero && timeGetTimeAddress != IntPtr.Zero)
                {
                    WriteValue(timeGetTimeAddress, GetNativeScriptFunctionAddress("timeGetTime_hook"));
                }
                timeMultiplierHooksInitialized = true;
            }

            double oldMultiplier = firstRun ? 1 : globals.TimeMultiplier.Multiplier;

            NativeScript.TimeMultiplierInfo timeMultiplier = globals.TimeMultiplier;
            timeMultiplier.Multiplier = enable ? multiplier : 1;
            timeMultiplier.Enabled    = enable;

            // Rebase the initial times so that our new multiplier if offset correctly
            if (globals.QueryPerformanceCounterFuncAddr != IntPtr.Zero)
            {
                long performanceCounter;
                QueryPerformanceCounter(out performanceCounter);
                RebaseTimeMultiplier(ref timeMultiplier.InitialPerformanceCounter, ref timeMultiplier.OffsetPerformanceCounter,
                                     performanceCounter, oldMultiplier, firstRun);
            }
            if (globals.GetTickCount64FuncAddr != IntPtr.Zero)
            {
                RebaseTimeMultiplier(ref timeMultiplier.InitialTickCount64, ref timeMultiplier.OffsetTickCount64,
                                     GetTickCount64(), oldMultiplier, firstRun);
            }
            if (globals.GetTickCountFuncAddr != IntPtr.Zero)
            {
                RebaseTimeMultiplier(ref timeMultiplier.InitialTickCount, ref timeMultiplier.OffsetTickCount,
                                     GetTickCount(), oldMultiplier, firstRun);
            }
            if (globals.TimeGetTimeFuncAddr != IntPtr.Zero)
            {
                RebaseTimeMultiplier(ref timeMultiplier.InitialTimeGetTime, ref timeMultiplier.OffsetTimeGetTime,
                                     TimeGetTime(), oldMultiplier, firstRun);
            }

            CallNativeScriptFunctionWithStruct("SetTimeMultiplierInfo", timeMultiplier);

            TimeMultiplierEnabled = enable;
            TimeMultiplier        = multiplier;

            // Resume the thread handles we managed to suspend
            EndSuspendProcess(threadHandles);
        }