From 414c97446c4bfa635e2d2aac2f6085b976b5e9cd Mon Sep 17 00:00:00 2001 From: vit9696 Date: Thu, 21 Nov 2019 19:19:56 +0300 Subject: [PATCH] Added support for per-process (LocalOnly) userspace patches --- Changelog.md | 1 + Lilu/Headers/kern_user.hpp | 13 +++++++++++++ Lilu/Sources/kern_user.cpp | 4 ++++ 3 files changed, 18 insertions(+) diff --git a/Changelog.md b/Changelog.md index befcdc35..701bd354 100644 --- a/Changelog.md +++ b/Changelog.md @@ -3,6 +3,7 @@ Lilu Changelog #### v1.4.0 - Fixed mishandling user patches process list after processKernel API call - Fixed extra I/O in user patcher even when no patches were needed +- Added support for per-process (LocalOnly) userspace patches #### v1.3.9 - Added QEMU/KVM vendor compatibility to device detection logic diff --git a/Lilu/Headers/kern_user.hpp b/Lilu/Headers/kern_user.hpp index 11e3ec96..db9890a3 100644 --- a/Lilu/Headers/kern_user.hpp +++ b/Lilu/Headers/kern_user.hpp @@ -88,11 +88,22 @@ class UserPatcher { "__common" }; + /** + * Binary modification patches flags + */ + enum BinaryModPatchFlags { + /* + * Only applies to one process, not globally. + */ + LocalOnly = 1 + }; + /** * Structure holding lookup-style binary patches */ struct BinaryModPatch { cpu_type_t cpu; + uint32_t flags; const uint8_t *find; const uint8_t *replace; size_t size; @@ -102,6 +113,8 @@ class UserPatcher { uint32_t section; }; + static_assert(sizeof(BinaryModPatch) == 56, "BinaryModPatch ABI compatibility failure"); + /** * Structure describing the modifications for the binary */ diff --git a/Lilu/Sources/kern_user.cpp b/Lilu/Sources/kern_user.cpp index 27c2d89c..fc545f53 100644 --- a/Lilu/Sources/kern_user.cpp +++ b/Lilu/Sources/kern_user.cpp @@ -219,6 +219,10 @@ void UserPatcher::performPagePatch(const void *data_ptr, size_t data_size) { auto &rpatch = storage->mod->patches[ref->i]; sz = ref->pageOffs.size(); + // Skip patches that are meant to apply only to select processes. + if (rpatch.flags & LocalOnly) { + continue; + } DBGLOG("user", "found what we are looking for %X %X %X %X %X %X %X %X", rpatch.find[0], rpatch.size > 1 ? rpatch.find[1] : 0xff,