Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Probably need to adjust code to deal with self-remmapping program #169

Open
s0duku opened this issue Dec 20, 2024 · 0 comments
Open

Probably need to adjust code to deal with self-remmapping program #169

s0duku opened this issue Dec 20, 2024 · 0 comments

Comments

@s0duku
Copy link

s0duku commented Dec 20, 2024

https://github.com/x64dbg/ScyllaHide/blob/master/HookLibrary/HookedFunctions.cpp

Patch_ImageBase + Patch_NtHeaders->OptionalHeader.SizeOfImage and RtlImageNtHeader access the main module memory section every time after a syscall return.

Normally this will not be a problem, but when dealing with the self-remmaping code (return from the unmap syscall), it crash the process.

Currently, I just use global variables to store the value, maybe still not good enough, but works fine for me, so I suggest to ajust this part of codes to counter self-remmaping codes.

// to counter self-remmaping code
static PVOID PE_ImageBase = NULL;
static PIMAGE_NT_HEADERS PE_NtHeaders = NULL;
static ULONG_PTR PE_ExeMaxAddr = NULL;

extern "C"
ULONG_PTR
NTAPI
InstrumentationCallback(
    _In_ ULONG_PTR ReturnAddress, // ECX/R10
    _Inout_ ULONG_PTR ReturnVal // EAX/RAX
    )
{
    if (InterlockedOr(TlsGetInstrumentationCallbackDisabled(), 0x1) == 0x1)
        return ReturnVal; // Do not recurse

    if (!PE_ImageBase)
        PE_ImageBase = NtCurrentPeb()->ImageBaseAddress;
    if (!PE_NtHeaders)
        PE_NtHeaders = RtlImageNtHeader(PE_ImageBase);
    if (!PE_ExeMaxAddr)
        PE_ExeMaxAddr = (ULONG_PTR)PE_ImageBase + PE_NtHeaders->OptionalHeader.SizeOfImage;
.......
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant