From 729123e57a514422ff0f52e29b97306e23263194 Mon Sep 17 00:00:00 2001 From: Luke Usher Date: Sat, 2 Apr 2016 19:41:20 +0100 Subject: [PATCH] Re-enabled all FS patches, it does not seem to have any effect on compatibilty, but it's better to be safe, we don't want Xbox code playing around with Windows TLS if we can help it. --- src/CxbxKrnl/EmuFS.cpp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/CxbxKrnl/EmuFS.cpp b/src/CxbxKrnl/EmuFS.cpp index 663cafa2f..210329d44 100644 --- a/src/CxbxKrnl/EmuFS.cpp +++ b/src/CxbxKrnl/EmuFS.cpp @@ -259,24 +259,24 @@ void EmuInitFS() * The entries must be in order of size, to keep the chance of false positives to a minimum. */ std::vector fsInstructions; - //fsInstructions.push_back({ { 0x64, 0x0F, 0xB6, 0x05, 0x24, 0x00, 0x00, 0x00 }, &EmuMzxEaxBytePtrFs24 });// movzx eax, large byte ptr fs:24 - //fsInstructions.push_back({ { 0x64, 0x3B, 0x35, 0x00, 0x00, 0x00, 0x00 }, &EmuCmpEsiFs00 }); // cmp esi, large fs:0 - //fsInstructions.push_back({ { 0x64, 0x8B, 0x1D, 0x00, 0x00, 0x00, 0x00 }, &EmuMEbxFs00 }); // mov ebx, large fs:0 - //fsInstructions.push_back({ { 0x64, 0x8B, 0x0D, 0x00, 0x00, 0x00, 0x00 }, &EmuMEcxFs00 }); // mov ecx, large fs:0 + fsInstructions.push_back({ { 0x64, 0x0F, 0xB6, 0x05, 0x24, 0x00, 0x00, 0x00 }, &EmuMzxEaxBytePtrFs24 });// movzx eax, large byte ptr fs:24 + fsInstructions.push_back({ { 0x64, 0x3B, 0x35, 0x00, 0x00, 0x00, 0x00 }, &EmuCmpEsiFs00 }); // cmp esi, large fs:0 + fsInstructions.push_back({ { 0x64, 0x8B, 0x1D, 0x00, 0x00, 0x00, 0x00 }, &EmuMEbxFs00 }); // mov ebx, large fs:0 + fsInstructions.push_back({ { 0x64, 0x8B, 0x0D, 0x00, 0x00, 0x00, 0x00 }, &EmuMEcxFs00 }); // mov ecx, large fs:0 fsInstructions.push_back({ { 0x64, 0x8B, 0x0D, 0x04, 0x00, 0x00, 0x00 }, &EmuMEcxFs04 }); // mov ecx, large fs:4 - //fsInstructions.push_back({ { 0x64, 0x8B, 0x3D, 0x00, 0x00, 0x00, 0x00 }, &EmuMEdiFs00 }); // mov edi, large fs:0 + fsInstructions.push_back({ { 0x64, 0x8B, 0x3D, 0x00, 0x00, 0x00, 0x00 }, &EmuMEdiFs00 }); // mov edi, large fs:0 fsInstructions.push_back({ { 0x64, 0x8B, 0x3D, 0x04, 0x00, 0x00, 0x00 }, &EmuMEdiFs04 }); // mov edi, large fs:4 - //fsInstructions.push_back({ { 0x64, 0x8B, 0x35, 0x00, 0x00, 0x00, 0x00 }, &EmuMEsiFs00 }); // mov esi, large fs:0 - //fsInstructions.push_back({ { 0x64, 0x89, 0x1D, 0x00, 0x00, 0x00, 0x00 }, &EmuMFs00Ebx }); // mov large fs:0, ebx - //fsInstructions.push_back({ { 0x64, 0x89, 0x0D, 0x00, 0x00, 0x00, 0x00 }, &EmuMFs00Ecx }); // mov large fs:0, ecx - //fsInstructions.push_back({ { 0x64, 0x89, 0x25, 0x00, 0x00, 0x00, 0x00 }, &EmuMFs00Esp }); // mov large fs:0, esp - //fsInstructions.push_back({ { 0x64, 0x8F, 0x05, 0x00, 0x00, 0x00, 0x00 }, &EmuPopDwordPtrFs00 }); // pop large dword ptr fs:0 - //fsInstructions.push_back({ { 0x64, 0xFF, 0x35, 0x00, 0x00, 0x00, 0x00 }, &EmuPushDwordPtrFs00 }); // push large dword ptr fs:0 - //fsInstructions.push_back({ { 0x64, 0xA1, 0x00, 0x00, 0x00, 0x00 }, &EmuMEaxFs00 }); // mov eax, large fs:0 + fsInstructions.push_back({ { 0x64, 0x8B, 0x35, 0x00, 0x00, 0x00, 0x00 }, &EmuMEsiFs00 }); // mov esi, large fs:0 + fsInstructions.push_back({ { 0x64, 0x89, 0x1D, 0x00, 0x00, 0x00, 0x00 }, &EmuMFs00Ebx }); // mov large fs:0, ebx + fsInstructions.push_back({ { 0x64, 0x89, 0x0D, 0x00, 0x00, 0x00, 0x00 }, &EmuMFs00Ecx }); // mov large fs:0, ecx + fsInstructions.push_back({ { 0x64, 0x89, 0x25, 0x00, 0x00, 0x00, 0x00 }, &EmuMFs00Esp }); // mov large fs:0, esp + fsInstructions.push_back({ { 0x64, 0x8F, 0x05, 0x00, 0x00, 0x00, 0x00 }, &EmuPopDwordPtrFs00 }); // pop large dword ptr fs:0 + fsInstructions.push_back({ { 0x64, 0xFF, 0x35, 0x00, 0x00, 0x00, 0x00 }, &EmuPushDwordPtrFs00 }); // push large dword ptr fs:0 + fsInstructions.push_back({ { 0x64, 0xA1, 0x00, 0x00, 0x00, 0x00 }, &EmuMEaxFs00 }); // mov eax, large fs:0 fsInstructions.push_back({ { 0x64, 0xA1, 0x20, 0x00, 0x00, 0x00 }, &EmuMEaxFs20 }); // mov eax, large fs:20 fsInstructions.push_back({ { 0x64, 0xA1, 0x28, 0x00, 0x00, 0x00 }, &EmuMEaxFs28 }); // mov eax, large fs:28 - //fsInstructions.push_back({ { 0x64, 0xA1, 0x58, 0x00, 0x00, 0x00 }, &EmuMEaxFs58 }); // mov eax, large fs:58 - //fsInstructions.push_back({ { 0x64, 0xA3, 0x00, 0x00, 0x00, 0x00 }, &EmuMFs00Eax }); // mov large fs:0, eax + fsInstructions.push_back({ { 0x64, 0xA1, 0x58, 0x00, 0x00, 0x00 }, &EmuMEaxFs58 }); // mov eax, large fs:58 + fsInstructions.push_back({ { 0x64, 0xA3, 0x00, 0x00, 0x00, 0x00 }, &EmuMFs00Eax }); // mov large fs:0, eax DbgPrintf("Patching FS Register Accesses\n"); DWORD sizeOfImage = CxbxKrnl_XbeHeader->dwSizeofImage; @@ -290,6 +290,8 @@ void EmuInitFS() if (memcmp((void*)addr, &fsInstructions[i].data[0], sizeOfData) == 0) { + DbgPrintf("Patching FS Instruction at 0x%08X", addr); + // Write Call opcode *(uint08*)addr = 0xE8; *(uint32*)(addr + 1) = (uint32)fsInstructions[i].functionPtr - addr - 5; @@ -298,7 +300,7 @@ void EmuInitFS() int remaining_bytes = fsInstructions[i].data.size() - 5; memset((void*)(addr + 5), 0x90, remaining_bytes); addr += sizeOfData - 1; - continue; + break; } } }