Esempio n. 1
0
        public void RestoreCode()
        {
            //Suspend execution of Dark Souls process:
            DARKSOULS.Suspend();

            //Restore the original local code:
            WBytes((OriginalLocalCodeStartOffset, OriginalLocalCodeStartOffset), OriginalLocalCode);

            //Flush the instruction cache over the span of the local code:
            Kernel.FlushInstructionCache(DARKSOULS.GetHandle(), OriginalLocalCodeStartOffset, (UIntPtr)OriginalLocalCodeLength);

            //Resume execution of Dark Souls process:
            DARKSOULS.Resume();

            IsPatched = false;
        }
Esempio n. 2
0
        public void PatchCode(bool force = false)
        {
            if (IsPatched && !force)
            {
                return;
            }

            //Write the wrapped code to the allocated memory region:
            var wrappedCodeHandle = CustomRemoteCodeHandle.GetHandle();

            WBytes((wrappedCodeHandle, wrappedCodeHandle), CustomRemoteCode);

            //Flush instruction cache for wrapped code:
            Kernel.FlushInstructionCache(DARKSOULS.GetHandle(), CustomRemoteCodeHandle.GetHandle(), (UIntPtr)CustomLocalCodeAllocSize);

            /*
             *
             * >> The rest of this method: <<
             *
             * Patch original local code while Dark Souls is suspended so that there will be a 0.0% chance of the
             * game trying to execute only-partially-overridden code instead of the usual 0.00000001% chance ;)
             *
             */

            //Suspend execution of Dark Souls process:
            DARKSOULS.Suspend();

            //Overwrite the original local code with the custom local code:
            WBytes((OriginalLocalCodeStartOffset, OriginalLocalCodeStartOffset), CustomLocalCode);

            //Flush the instruction cache over the span of the local code:
            Kernel.FlushInstructionCache(DARKSOULS.GetHandle(), OriginalLocalCodeStartOffset, (UIntPtr)OriginalLocalCodeLength);

            //Resume execution of Dark Souls process:
            DARKSOULS.Resume();

            IsPatched = true;
        }