From b3839d3afe7beff853c2e55246210c176f2c60db Mon Sep 17 00:00:00 2001 From: Rasta Mouse Date: Tue, 14 Oct 2025 11:00:33 +0100 Subject: [PATCH] Initial commit --- .gitattributes | 2 ++ .gitignore | 52 ++++++++++++++++++++++++++++++++++++++ LICENSE | 21 ++++++++++++++++ Makefile | 14 +++++++++++ README.md | 3 +++ src/tp.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/tp.h | 15 +++++++++++ 7 files changed, 175 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README.md create mode 100644 src/tp.c create mode 100644 src/tp.h diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c6127b3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,52 @@ +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1e90607 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Rasta Mouse + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..efee58e --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ +CC_64=x86_64-w64-mingw32-gcc + +all: libtp.x64.zip + +bin: + mkdir bin + +libtp.x64.zip: bin + $(CC_64) -DWIN_X64 -shared -Wall -Wno-pointer-arith -c src/tp.c -o bin/tp.x64.o + zip -q -j libtp.x64.zip bin/*.x64.o + +clean: + rm -rf bin/*.o + rm -f libtp.x64.zip diff --git a/README.md b/README.md new file mode 100644 index 0000000..6fbbce8 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# LibTP + +A shared Crystal Palace library for proxying Nt API calls via the Threadpool. diff --git a/src/tp.c b/src/tp.c new file mode 100644 index 0000000..afaff3b --- /dev/null +++ b/src/tp.c @@ -0,0 +1,68 @@ +/* + * Copyright 2025 Raphael Mudge, Adversary Fan Fiction Writers Guild + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "tp.h" + +WINBASEAPI VOID NTAPI NTDLL$TpAllocWork (PTP_WORK*, PTP_WORK_CALLBACK, PVOID, PTP_CALLBACK_ENVIRON); +WINBASEAPI VOID NTAPI NTDLL$TpPostWork (PTP_WORK); +WINBASEAPI VOID NTAPI NTDLL$TpReleaseWork (PTP_WORK); +WINBASEAPI DWORD WINAPI KERNEL32$WaitForSingleObject (HANDLE, DWORD); + +void __attribute__((naked)) WorkCallback() +{ + __asm__ __volatile__ ( + ".intel_syntax noprefix;" + "mov rbx, rdx;" + + "mov rax, [rbx];" + "mov rcx, [rbx + 0x8];" + "mov rdx, [rbx + 0x10];" + "mov r8, [rbx + 0x18];" + "mov r9, [rbx + 0x20];" + + "mov r10, [rbx + 0x30];" + "mov [rsp + 0x30], r10;" + + "mov r10, [rbx + 0x28];" + "mov [rsp + 0x28], r10;" + + "jmp rax;" + ".att_syntax prefix;" + ); +} + +VOID ProxyNtApi(NTARGS * args, DWORD delay) +{ + PTP_WORK WorkReturn = NULL; + + NTDLL$TpAllocWork(&WorkReturn, (PTP_WORK_CALLBACK)WorkCallback, args, NULL); + NTDLL$TpPostWork(WorkReturn); + NTDLL$TpReleaseWork(WorkReturn); + + KERNEL32$WaitForSingleObject((HANDLE)(-1), delay); +} \ No newline at end of file diff --git a/src/tp.h b/src/tp.h new file mode 100644 index 0000000..4e82b28 --- /dev/null +++ b/src/tp.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +typedef struct { + ULONG_PTR functionPtr; + ULONG_PTR argument1; + ULONG_PTR argument2; + ULONG_PTR argument3; + ULONG_PTR argument4; + ULONG_PTR argument5; + ULONG_PTR argument6; +} NTARGS; + +VOID ProxyNtApi(NTARGS * args, DWORD delay); \ No newline at end of file