├── SKLib-v
├── src
│ ├── VMTimers.cpp
│ ├── iommu.cpp
│ ├── VMCSCheck.cpp
│ ├── VMExitHandlers.cpp
│ ├── windowspoof.cpp
│ ├── event.cpp
│ ├── VMMAllocator.cpp
│ ├── exception.cpp
│ ├── ioctrlhook.cpp
│ ├── spoof.cpp
│ ├── Vmoperations.cpp
│ ├── Vmexit.cpp
│ ├── VTxException.cpp
│ ├── VmIDT-helper.asm
│ ├── efispoof.cpp
│ ├── eac.cpp
│ ├── wmispoof.cpp
│ ├── usbspoof.cpp
│ └── volumespoof.cpp
├── include
│ ├── windowspoof.h
│ ├── smbiosspoof.h
│ ├── efispoof.h
│ ├── VMMAllocator.h
│ ├── usbspoof.h
│ ├── gpuspoof.h
│ ├── spoof.h
│ ├── VTx.h
│ ├── EPT.h
│ ├── VTxException.h
│ ├── VMExitHandlers.h
│ ├── VmIDT.h
│ ├── ddma.h
│ ├── event.h
│ ├── Vmoperations.h
│ ├── VMTimers.h
│ ├── Vmexit.h
│ ├── VMCSCheck.h
│ ├── eac.h
│ ├── volumespoof.h
│ ├── ioctlhook.h
│ └── Vmcall.h
├── SKLib-v.vcxproj.user
└── vcpkg.json
├── SKLib
├── src
│ ├── Setup.cpp
│ ├── xor.cpp
│ ├── bitmap.cpp
│ ├── timing.cpp
│ ├── IDT-helper.asm
│ ├── queue.cpp
│ ├── utils.cpp
│ ├── std.cpp
│ ├── defender.cpp
│ ├── file.cpp
│ ├── disassembler.cpp
│ ├── threading.cpp
│ ├── data.cpp
│ ├── power.cpp
│ ├── sharedpool.cpp
│ └── collector.cpp
├── README.md
├── include
│ ├── xor.h
│ ├── acl.h
│ ├── defender.h
│ ├── disassembler.h
│ ├── queue.h
│ ├── SKLib.h
│ ├── file.h
│ ├── utils.h
│ ├── timing.h
│ ├── power.h
│ ├── bitmap.h
│ ├── spinlock.h
│ ├── status.h
│ ├── collector.h
│ ├── sharedpool.h
│ ├── exception.h
│ ├── cpp.h
│ ├── eventlogger.h
│ ├── StringArray.h
│ ├── Arch
│ │ ├── Interrupts.h
│ │ └── Intrinsics.h
│ ├── threading.h
│ ├── std.h
│ ├── ioctl.h
│ ├── bugcheck.h
│ ├── RandEx.h
│ ├── IDT.h
│ ├── macros.h
│ ├── VirtualizerSDKMacros.h
│ ├── data.h
│ ├── signatures.h
│ ├── paging.h
│ ├── registry.h
│ ├── StringEx.h
│ └── MapEx.h
├── SKLib.vcxproj.user
├── .gitignore
├── SKLib.cv
└── SKLib.inf
├── Pdbparser
├── md5.cpp
├── Pdbparser.vcxproj.user
├── md5.h
├── pdbparse.h
├── Pdbparser.vcxproj.filters
└── EzPdb.h
├── kdmapper_lib
├── .gitignore
├── kdmapper
│ ├── include
│ │ ├── service.hpp
│ │ ├── portable_executable.hpp
│ │ ├── utils.hpp
│ │ ├── kdmapper.hpp
│ │ └── nt.hpp
│ ├── kdmapper.vcxproj.filters
│ └── src
│ │ ├── service.cpp
│ │ ├── portable_executable.cpp
│ │ └── utils.cpp
└── kdmapper.sln
├── phymeme_lib
├── dbrequest-helper.asm
├── phymeme_lib
│ ├── phymeme_lib.vcxproj.user
│ └── phymeme_lib.vcxproj.filters
├── .gitignore
├── kernel_ctx
│ ├── dbrequest.cpp
│ ├── dbrequest.h
│ └── kernel_ctx.h
├── map_driver.hpp
├── phymeme_lib.sln
├── physmeme_lib.vcxproj.user
├── map_driver.cpp
├── drv_image
│ └── drv_image.h
├── physmeme
│ └── physmeme.hpp
├── physmeme_lib.vcxproj.filters
└── util
│ ├── nt.hpp
│ └── hook.hpp
├── vcpkg.json
├── .gitignore
└── SKLib.sln
/SKLib-v/src/VMTimers.cpp:
--------------------------------------------------------------------------------
1 | #include "VMTimers.h"
--------------------------------------------------------------------------------
/SKLib/src/Setup.cpp:
--------------------------------------------------------------------------------
1 | #include "Setup.hpp"
2 |
--------------------------------------------------------------------------------
/SKLib/README.md:
--------------------------------------------------------------------------------
1 | # SKLib
2 | Standard Kernel Library
3 |
--------------------------------------------------------------------------------
/Pdbparser/md5.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cutecatsandvirtualmachines/SKLib/HEAD/Pdbparser/md5.cpp
--------------------------------------------------------------------------------
/kdmapper_lib/.gitignore:
--------------------------------------------------------------------------------
1 | .vs
2 | kdmapper/x64
3 | kdmapper/kdmapper.vcxproj.user
4 | x64
5 | HelloWorld/.vs
--------------------------------------------------------------------------------
/SKLib-v/src/iommu.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cutecatsandvirtualmachines/SKLib/HEAD/SKLib-v/src/iommu.cpp
--------------------------------------------------------------------------------
/SKLib-v/src/VMCSCheck.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cutecatsandvirtualmachines/SKLib/HEAD/SKLib-v/src/VMCSCheck.cpp
--------------------------------------------------------------------------------
/SKLib-v/src/VMExitHandlers.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cutecatsandvirtualmachines/SKLib/HEAD/SKLib-v/src/VMExitHandlers.cpp
--------------------------------------------------------------------------------
/SKLib/include/xor.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "cpp.h"
4 |
5 | namespace encryption {
6 | void xorBytes(PVOID pBase, SIZE_T sz, SIZE_T key);
7 | }
--------------------------------------------------------------------------------
/SKLib-v/include/windowspoof.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "cpp.h"
4 | #include "Setup.hpp"
5 |
6 | namespace window {
7 | void Hide(int hwnd, char* pTeb);
8 | }
--------------------------------------------------------------------------------
/SKLib-v/include/smbiosspoof.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "ioctlhook.h"
4 | #include "smbios.h"
5 |
6 | namespace smbios {
7 | bool Spoof(DWORD64 seed = TEST_SEED);
8 | }
--------------------------------------------------------------------------------
/phymeme_lib/dbrequest-helper.asm:
--------------------------------------------------------------------------------
1 |
2 | .code _text
3 |
4 | ;DWORD64 DbRequest(DWORD64 code, PDB_INFO pDbInfo)
5 | DbRequest proc
6 | int 3
7 | ret
8 | DbRequest endp
9 |
10 | END
--------------------------------------------------------------------------------
/SKLib-v/include/efispoof.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "ioctlhook.h"
4 |
5 | namespace efi {
6 | bool Spoof(DWORD64 seed = TEST_SEED);
7 | }
8 |
9 | #define VARIABLE_ATTRIBUTE_NON_VOLATILE 1
--------------------------------------------------------------------------------
/SKLib-v/include/VMMAllocator.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "cpp.h"
4 |
5 | namespace vmm {
6 | BOOLEAN InitAllocator();
7 |
8 | PVOID malloc(SIZE_T sz);
9 | VOID free(PVOID pMem);
10 | }
--------------------------------------------------------------------------------
/Pdbparser/Pdbparser.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/SKLib/include/acl.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "cpp.h"
3 |
4 | NTSTATUS CreateStandardSCAndACL(OUT PSECURITY_DESCRIPTOR* SecurityDescriptor, OUT PACL* Acl);
5 | NTSTATUS GrantAccess(HANDLE hSection, IN PACL StandardAcl);
--------------------------------------------------------------------------------
/SKLib/include/defender.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #ifdef _KERNEL_MODE
4 | #include "winternlex.h"
5 | #include "MemoryEx.h"
6 |
7 | namespace defender {
8 | bool CleanFilterList(string driverName);
9 | }
10 | #endif
--------------------------------------------------------------------------------
/phymeme_lib/phymeme_lib/phymeme_lib.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/SKLib-v/include/usbspoof.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "ioctlhook.h"
4 | #include
5 |
6 | #ifdef _KERNEL_MODE
7 |
8 | namespace usb {
9 | bool Spoof(DWORD64 seed = TEST_SEED);
10 | }
11 |
12 | #endif
--------------------------------------------------------------------------------
/Pdbparser/md5.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | // swprintf
4 | #pragma warning (disable : 4996)
5 |
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | std::string Md5(PVOID buffer, ULONG bufferLen);
--------------------------------------------------------------------------------
/SKLib/SKLib.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | false
5 |
6 |
--------------------------------------------------------------------------------
/SKLib-v/SKLib-v.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | false
5 |
6 |
--------------------------------------------------------------------------------
/phymeme_lib/.gitignore:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # This .gitignore file was automatically created by Microsoft(R) Visual Studio.
3 | ################################################################################
4 |
5 | /.vs
6 | /x64
7 |
--------------------------------------------------------------------------------
/SKLib/include/disassembler.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #ifdef _KERNEL_MODE
4 |
5 | #define ZYDIS_DISABLE_FORMATTER
6 |
7 | #include
8 |
9 | #include "cpp.h"
10 |
11 | namespace disassembler {
12 | size_t GetInstrBoundaryLen(PVOID pBase, size_t targetLen);
13 | }
14 |
15 | #endif
--------------------------------------------------------------------------------
/SKLib/include/queue.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #ifdef _KERNEL_MODE
3 |
4 | #include "cpp.h"
5 | #include "VectorEx.h"
6 | #include "RandEx.h"
7 |
8 | #define DEFAULT_QUEUE_RESERVE 20
9 |
10 | class Queue {
11 | vector queue;
12 |
13 | Queue();
14 |
15 | void Lock();
16 | void Unlock();
17 | };
18 | #endif
--------------------------------------------------------------------------------
/kdmapper_lib/kdmapper/include/service.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | #include
5 | #include "intel_driver.hpp"
6 |
7 | namespace service
8 | {
9 | bool RegisterAndStart(const std::wstring& driver_path);
10 | bool StopAndRemove(const std::wstring& driver_name);
11 | };
--------------------------------------------------------------------------------
/SKLib-v/src/windowspoof.cpp:
--------------------------------------------------------------------------------
1 | #include "windowspoof.h"
2 | #include
3 |
4 | void window::Hide(int hwnd, char* pTeb)
5 | {
6 | DWORD64* pClientInfo = (DWORD64*)(pTeb + offsets.ClientInfo);
7 | pClientInfo[offsets.HwndCache] = (DWORD64)hwnd;
8 | pClientInfo[offsets.HwndCache + 1] = 0; //tagWND cache
9 | }
10 |
--------------------------------------------------------------------------------
/SKLib-v/include/gpuspoof.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "ioctlhook.h"
4 | #include "disassembler.h"
5 |
6 | namespace gpu {
7 | bool Spoof(DWORD64 seed = TEST_SEED);
8 | }
9 |
10 | #define NV_MAX_DEVICES 32
11 | #define IOCTL_NVIDIA_SMIL (0x8DE0008)
12 | #define IOCTL_NVIDIA_SMIL_MAX (512)
13 | #define GPU_SERIAL_OFFSET 0x1AC
--------------------------------------------------------------------------------
/SKLib/src/xor.cpp:
--------------------------------------------------------------------------------
1 | #include "xor.h"
2 |
3 | void encryption::xorBytes(PVOID pBase, SIZE_T sz, SIZE_T key)
4 | {
5 | if (sz % 8) {
6 | for (SIZE_T i = 0; i < sz; i++) {
7 | *(char*)pBase ^= key;
8 | }
9 | }
10 | else {
11 | for (SIZE_T i = 0; i < sz; i += 8) {
12 | *(DWORD64*)pBase ^= key;
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/SKLib/include/SKLib.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | #ifdef _KERNEL_MODE
9 |
10 | extern "C" NTSTATUS IoCreateDriver(
11 | IN PUNICODE_STRING DriverName OPTIONAL,
12 | IN PDRIVER_INITIALIZE InitializationFunction
13 | );
14 |
15 | #endif
--------------------------------------------------------------------------------
/vcpkg.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
3 | "name": "sklib",
4 | "version": "1.0.0",
5 | "dependencies": [
6 | {
7 | "name": "zydis",
8 | "platform": "x64"
9 | }
10 | ],
11 | "builtin-baseline": "3426db05b996481ca31e95fff3734cf23e0f51bc"
12 | }
--------------------------------------------------------------------------------
/SKLib-v/vcpkg.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
3 | "name": "sklib",
4 | "version": "1.0.0",
5 | "dependencies": [
6 | {
7 | "name": "zydis",
8 | "platform": "x64"
9 | }
10 | ],
11 | "builtin-baseline": "3426db05b996481ca31e95fff3734cf23e0f51bc"
12 | }
--------------------------------------------------------------------------------
/SKLib/include/file.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "cpp.h"
4 | #include "winternlex.h"
5 |
6 | namespace file {
7 | class fstream {
8 | private:
9 | HANDLE hFile;
10 | OBJECT_ATTRIBUTES ObjectAttributes;
11 |
12 | public:
13 | fstream(string&& path);
14 | fstream(string& path);
15 | ~fstream();
16 |
17 | HANDLE Handle();
18 | };
19 | }
20 |
--------------------------------------------------------------------------------
/SKLib/include/utils.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #ifdef _KERNEL_MODE
3 | #ifndef _WDMDDK_
4 | #include
5 | #endif
6 | #endif
7 |
8 | #include "cpp.h"
9 | #include "StringEx.h"
10 |
11 | #ifdef _KERNEL_MODE
12 | //Remember to deallocate string's buffer after you're done using the UNICODE_STRING returned from this function
13 | UNICODE_STRING GetModuleNameFromPath(PUNICODE_STRING path);
14 | #endif
--------------------------------------------------------------------------------
/SKLib-v/include/spoof.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "cpp.h"
4 | #include "diskspoof.h"
5 | #include "volumespoof.h"
6 | #include "nicspoof.h"
7 | #include "smbiosspoof.h"
8 | #include "gpuspoof.h"
9 | #include "efispoof.h"
10 | #include "wmispoof.h"
11 | #include "usbspoof.h"
12 |
13 | namespace spoofer {
14 | NTSTATUS SpoofAll(DWORD64 seed = TEST_SEED);
15 |
16 | extern DWORD64 seed;
17 | }
18 |
--------------------------------------------------------------------------------
/SKLib-v/src/event.cpp:
--------------------------------------------------------------------------------
1 | #include "event.h"
2 |
3 | #include
4 |
5 | bool SKLibEvent::Triggered()
6 | {
7 | return bPreNotified;
8 | }
9 |
10 | void SKLibEvent::Await()
11 | {
12 | if (bPreNotified)
13 | return;
14 |
15 | _lock.Lock();
16 | _lock.Lock();
17 | _lock.Unlock();
18 | }
19 |
20 | void SKLibEvent::Trigger()
21 | {
22 | bPreNotified = true;
23 | _lock.Unlock();
24 | }
25 |
--------------------------------------------------------------------------------
/SKLib/.gitignore:
--------------------------------------------------------------------------------
1 | # Prerequisites
2 | *.d
3 |
4 | # Compiled Object files
5 | *.slo
6 | *.lo
7 | *.o
8 | *.obj
9 |
10 | # Precompiled Headers
11 | *.gch
12 | *.pch
13 |
14 | # Compiled Dynamic libraries
15 | *.so
16 | *.dylib
17 | *.dll
18 |
19 | # Fortran module files
20 | *.mod
21 | *.smod
22 |
23 | # Compiled Static libraries
24 | *.lai
25 | *.la
26 | *.a
27 | *.lib
28 |
29 | # Executables
30 | *.exe
31 | *.out
32 | *.app
33 |
--------------------------------------------------------------------------------
/SKLib-v/include/VTx.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #pragma warning (disable:4267)
4 | #pragma warning (disable:4201)
5 | #pragma warning (disable:4334)
6 |
7 | #include "macros.h"
8 | #include "data.h"
9 | #include "MemoryEx.h"
10 | #include "VMCSCheck.h"
11 | #include "power.h"
12 | #include "bitmap.h"
13 | #include "VMTimers.h"
14 | #include "VMExitHandlers.h"
15 | #include "winternlex.h"
16 | #include "bugcheck.h"
17 | #include "VMMDef.h"
18 |
--------------------------------------------------------------------------------
/SKLib-v/include/EPT.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #pragma warning (disable:4353)
4 |
5 | #ifdef _KERNEL_MODE
6 | #include
7 | #endif
8 |
9 | #include "VMMDef.h"
10 | #include "ia32.h"
11 | #include "cpp.h"
12 | #include "cpu.h"
13 | #include "MemoryEx.h"
14 | #include "ListEx.h"
15 | #include "VectorEx.h"
16 | #include "spinlock.h"
17 | #include "IDT.h"
18 | #include "paging.h"
19 | #include "disassembler.h"
20 | #include "VTxException.h"
21 | #include "PE.h"
22 | #include "VMMAllocator.h"
23 |
--------------------------------------------------------------------------------
/SKLib-v/include/VTxException.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #ifdef _KERNEL_MODE
4 | #include
5 | #endif
6 |
7 | #include
8 |
9 | #include "cpp.h"
10 | #include "cpu.h"
11 | #include "VMMDef.h"
12 |
13 | #define RST_CNT_IO_PORT (USHORT)0xCF9
14 |
15 | #define DUMP_SECTION_NAME "SKLibDump"
16 |
17 | #ifdef _KERNEL_MODE
18 | namespace VTx {
19 | namespace Exceptions {
20 | extern "C" bool InjectException(EXCEPTION_VECTOR ex, DWORD32 eCode = 0);
21 | void ApHardReset();
22 | }
23 | }
24 | #endif
--------------------------------------------------------------------------------
/SKLib/src/bitmap.cpp:
--------------------------------------------------------------------------------
1 | #include "bitmap.h"
2 |
3 | DWORD64 Power2(DWORD64 pw) {
4 | return 1ull << pw;
5 | }
6 |
7 | void bitmap::SetBit(PVOID va, DWORD32 bit, BOOLEAN bSet)
8 | {
9 | DWORD32 byte = bit / 8;
10 | bit %= 8;
11 |
12 | if (bSet) {
13 | ((PUCHAR)va)[byte] |= Power2(bit);
14 | }
15 | else {
16 | ((PUCHAR)va)[byte] &= ~Power2(bit);
17 | }
18 | }
19 |
20 | BOOLEAN bitmap::GetBit(PVOID va, DWORD32 bit)
21 | {
22 | UCHAR byte = ((PUCHAR)va)[bit / 8];
23 | bit %= 8;
24 |
25 | return byte & Power2(bit);
26 | }
27 |
--------------------------------------------------------------------------------
/SKLib-v/include/VMExitHandlers.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "EPT.h"
4 | #include "VTxException.h"
5 |
6 | #ifdef _KERNEL_MODE
7 |
8 | namespace VTx {
9 | namespace VMExitHandlers {
10 | bool HandleCPUID(PREGS pContext);
11 | bool HandleCR(PREGS pContext);
12 | bool HandleGDTRIDTR(PREGS pContext);
13 | bool HandleRDMSR(PREGS pContext);
14 | bool HandleWRMSR(PREGS pContext);
15 | bool HandleXSetBv(PREGS pContext);
16 | bool HandleInvpcid(PREGS pContext);
17 | }
18 | }
19 |
20 | #endif
--------------------------------------------------------------------------------
/SKLib/include/timing.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "cpp.h"
4 |
5 | #define TICKS_TO_S(ns) ((ns) / 10000000)
6 | #define S_TO_TICKS(s) ((s) * 10000000)
7 | #define TICKS_TO_MS(ns) ((ns) / 10000)
8 | #define MS_TO_TICKS(s) ((s) * 10000)
9 |
10 | namespace timing {
11 | LARGE_INTEGER currentTime();
12 |
13 | class StopWatch {
14 | private:
15 | LARGE_INTEGER start;
16 | LARGE_INTEGER stop;
17 |
18 | public:
19 | StopWatch();
20 |
21 | DWORD64 ms();
22 | DWORD64 s();
23 | DWORD64 ticks();
24 |
25 | void reset();
26 | };
27 | }
--------------------------------------------------------------------------------
/SKLib-v/include/VmIDT.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 |
4 | #ifdef _KERNEL_MODE
5 |
6 | extern "C" void generic_interrupt_handler_vm();
7 | extern "C" void generic_interrupt_handler_ecode_vm();
8 | extern "C" void __nmi_handler_vm();
9 | extern "C" void __gp_handler_vm();
10 | extern "C" void __pf_handler_vm();
11 | extern "C" void __de_handler_vm();
12 |
13 | extern "C" void seh_handler_ecode_vm(PIDT_REGS_ECODE regs);
14 | extern "C" void seh_handler_vm(PIDT_REGS regs);
15 |
16 | extern "C" void NmiHandler();
17 |
18 | void SetupIDTVm(IDT& idt);
19 |
20 | #endif
--------------------------------------------------------------------------------
/SKLib-v/include/ddma.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "cpp.h"
4 |
5 | #ifdef _KERNEL_MODE
6 |
7 | typedef struct _DISK {
8 | PDEVICE_OBJECT Device;
9 | // Buffer holding sectors original data
10 | UINT8 Buffer[PAGE_SIZE];
11 | } DISK, * PDISK;
12 |
13 | class DdmaProvider {
14 | private:
15 | PDISK pDisk;
16 | BOOLEAN bScsi;
17 |
18 | public:
19 | DdmaProvider();
20 | ~DdmaProvider();
21 |
22 | NTSTATUS ReadPage(OUT PVOID dest);
23 |
24 | NTSTATUS WritePage(IN PVOID src);
25 |
26 | NTSTATUS DiskCopyPage(PVOID dest, PVOID src);
27 | };
28 |
29 | #endif
--------------------------------------------------------------------------------
/phymeme_lib/kernel_ctx/dbrequest.cpp:
--------------------------------------------------------------------------------
1 | #include "dbrequest.h"
2 |
3 | PVOID db::AllocatePool(SIZE_T size)
4 | {
5 | volatile PVOID pOut = 0;
6 | PDB_INFO pDbInfo = (PDB_INFO)_aligned_malloc(sizeof(*pDbInfo), 0x1000);
7 | if (!pDbInfo)
8 | return nullptr;
9 |
10 | pDbInfo->allocate.pOut = (PVOID*)&pOut;
11 | pDbInfo->allocate.sz = size;
12 |
13 | DbRequest(DB_ALLOCATE, pDbInfo);
14 |
15 | int i = 0;
16 | while (!pOut) {
17 | Sleep(1);
18 |
19 | if (i > 1000) {
20 | return nullptr;
21 | }
22 | i++;
23 | }
24 |
25 | _aligned_free(pDbInfo);
26 | return pOut;
27 | }
28 |
--------------------------------------------------------------------------------
/SKLib-v/include/event.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "spinlock.h"
4 | #include "RandEx.h"
5 |
6 | class SKLibEvent {
7 | private:
8 | Spinlock _lock;
9 | bool bPreNotified;
10 |
11 | DWORD64 _id;
12 |
13 | public:
14 | SKLibEvent() : bPreNotified(false), _id(random::NextHardware(0, MAXULONG64)) {};
15 |
16 | bool Triggered();
17 | void Await();
18 |
19 | #ifdef _KERNEL_MODE
20 | void Trigger();
21 | #endif
22 |
23 | __forceinline bool operator==(SKLibEvent& rhs) {
24 | return _id == rhs._id;
25 | }
26 | __forceinline bool operator!=(SKLibEvent& rhs) {
27 | return !(*this == rhs);
28 | }
29 | };
--------------------------------------------------------------------------------
/SKLib/include/power.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #ifdef _KERNEL_MODE
3 |
4 | #include "cpp.h"
5 | #include "StringEx.h"
6 | #include "ListEx.h"
7 |
8 | typedef void (*fnPowerCallback)(PVOID, PVOID, PVOID);
9 |
10 | namespace Power {
11 | extern bool bInit;
12 |
13 | extern list* vCallbackObjs;
14 | extern list* vRegistrationObjs;
15 |
16 | void Init();
17 | void Dispose();
18 |
19 | //The returned index is necessary to unregister the callback later on
20 | NTSTATUS RegisterCallback(fnPowerCallback fnCallback, int* index = nullptr);
21 | void UnregisterCallback(int index);
22 | }
23 | #endif
--------------------------------------------------------------------------------
/phymeme_lib/map_driver.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | #include
5 |
6 | namespace physmeme
7 | {
8 | void Init();
9 | std::string DriverName();
10 | DWORD32 DriverTimestamp();
11 | HANDLE DriverHandle();
12 |
13 | NTSTATUS __cdecl map_driver(std::string driver_name, uintptr_t param1, uintptr_t param2, bool bAllocationPtrParam1 = false, bool bAllocationSizeParam2 = false, uintptr_t* allocBase = 0);
14 | NTSTATUS __cdecl map_driver(const std::vector& raw_driver, uintptr_t param1, uintptr_t param2, bool bAllocationPtrParam1 = false, bool bAllocationSizeParam2 = false, uintptr_t* allocBase = 0);
15 | }
--------------------------------------------------------------------------------
/SKLib/include/bitmap.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "cpp.h"
4 |
5 | namespace bitmap {
6 | typedef struct _LARGE_BITMAP {
7 | DWORD64 low;
8 | DWORD64 high;
9 | } LARGE_BITMAP, *PLARGE_BITMAP;
10 |
11 | VOID SetBit(PVOID va, DWORD32 bit, BOOLEAN bSet);
12 | BOOLEAN GetBit(PVOID va, DWORD32 bit);
13 |
14 | template
15 | T bits(DWORD64 value, DWORD64 start, DWORD64 end) {
16 | if (end <= start)
17 | return 0;
18 | DWORD64 bitmask = 0;
19 | for (DWORD32 i = 0; i < sizeof(bitmask) * 8; i++) {
20 | if(i <= end && i >= start)
21 | SetBit(&bitmask, i, true);
22 | }
23 |
24 | return (T)((value & bitmask) >> start);
25 | }
26 | }
--------------------------------------------------------------------------------
/SKLib/include/spinlock.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "cpp.h"
4 |
5 | #define SPINLOCK_MAX_WAIT ~0ul
6 |
7 | #pragma pack(push, 1)
8 | class Spinlock {
9 | public:
10 | Spinlock() {
11 | Init();
12 | }
13 |
14 | void Unlock() {
15 | InterlockedExchange(&_lock, 0);
16 | }
17 | void Disable() {
18 | _bDisabled = true;
19 | }
20 | void Enable() {
21 | _bDisabled = false;
22 | }
23 |
24 | void Init() {
25 | _lock = 0;
26 | _bDisabled = false;
27 | }
28 | void Lock() {
29 | while (!_bDisabled && (InterlockedCompareExchange(&_lock, 1, 0) == 1))
30 | ;
31 | }
32 | private:
33 | long _lock;
34 | bool _bDisabled;
35 | };
36 | #pragma pack(pop)
--------------------------------------------------------------------------------
/SKLib-v/src/VMMAllocator.cpp:
--------------------------------------------------------------------------------
1 | #include "VMMAllocator.h"
2 |
3 | PVOID pPreallocatedBuffer = nullptr;
4 | constexpr SIZE_T szBuffer = 0x800000; //8MB
5 | SIZE_T szAllocated = 0;
6 |
7 | BOOLEAN vmm::InitAllocator()
8 | {
9 | pPreallocatedBuffer = cpp::kMallocZero(szBuffer, PAGE_READWRITE);
10 | if (!pPreallocatedBuffer)
11 | return FALSE;
12 | return TRUE;
13 | }
14 |
15 | PVOID vmm::malloc(SIZE_T sz)
16 | {
17 | PVOID retValue = 0;
18 | if (szAllocated + sz <= szBuffer) {
19 | retValue = (PVOID)((SIZE_T)pPreallocatedBuffer + szAllocated + sz);
20 | }
21 | else {
22 | return nullptr;
23 | }
24 |
25 | szAllocated += sz;
26 | return retValue;
27 | }
28 |
29 | VOID vmm::free(PVOID pMem)
30 | {
31 | return VOID();
32 | }
33 |
--------------------------------------------------------------------------------
/SKLib/src/timing.cpp:
--------------------------------------------------------------------------------
1 | #include "timing.h"
2 |
3 | LARGE_INTEGER timing::currentTime()
4 | {
5 | LARGE_INTEGER currTime = { 0 };
6 | KeQuerySystemTime(&currTime);
7 | return currTime;
8 | }
9 |
10 | timing::StopWatch::StopWatch()
11 | {
12 | start = currentTime();
13 | stop = start;
14 | }
15 |
16 | DWORD64 timing::StopWatch::ms()
17 | {
18 | return TICKS_TO_MS(ticks());
19 | }
20 |
21 | DWORD64 timing::StopWatch::s()
22 | {
23 | return TICKS_TO_S(ticks());
24 | }
25 |
26 | DWORD64 timing::StopWatch::ticks()
27 | {
28 | stop = currentTime();
29 | return stop.QuadPart - start.QuadPart;
30 | }
31 |
32 | void timing::StopWatch::reset()
33 | {
34 | start = currentTime();
35 | stop = start;
36 | }
37 |
--------------------------------------------------------------------------------
/SKLib/src/IDT-helper.asm:
--------------------------------------------------------------------------------
1 |
2 | .code _text
3 |
4 | EXTERN seh_handler : proc
5 | EXTERN seh_handler_ecode : proc
6 |
7 | ; #DE has no error code...
8 | generic_interrupt_handler PROC
9 | __de_handler proc
10 | iretq
11 | __de_handler endp
12 | generic_interrupt_handler ENDP
13 |
14 | ; PF and GP have error code...
15 | generic_interrupt_handler_ecode PROC
16 | __pf_handler proc
17 | __gp_handler proc
18 | add rsp, 8 ; remove error code on the stack...
19 |
20 | iretq
21 | __gp_handler endp
22 | __pf_handler endp
23 | generic_interrupt_handler_ecode ENDP
24 |
25 | __db_handler proc
26 | push rax
27 | pushfq
28 | pop rax
29 |
30 | btr rax, 8
31 |
32 | push rax
33 | popfq
34 | pop rax
35 | iretq
36 | __db_handler endp
37 |
38 | END
--------------------------------------------------------------------------------
/SKLib-v/src/exception.cpp:
--------------------------------------------------------------------------------
1 | #include "exception.h"
2 |
3 | cpp::exception::EX_CTL cpp::exception::HandleStdEx(PEXCEPTION_POINTERS pEx)
4 | {
5 | if (pEx->ExceptionRecord->ExceptionCode == STD_EXCEPTION
6 | && cpp::IsInRange(pEx->ExceptionRecord->ExceptionAddress, Throw, 50)) {
7 | DbgMsg("[EXCEPTION] Caught standard exception, executing handler!");
8 | return cpp::exception::EXECUTE_HANDLER;
9 | }
10 |
11 | DbgMsg("[EXCEPTION] Non standard exception caught, continuing search: 0x%x", pEx->ExceptionRecord->ExceptionCode);
12 | return cpp::exception::CONTINUE_SEARCH;
13 | }
14 |
15 | #pragma warning (disable:6011)
16 | void cpp::exception::Throw()
17 | {
18 | volatile int* zero = nullptr;
19 | *zero = 0;
20 | }
21 | #pragma warning (default:6011)
--------------------------------------------------------------------------------
/SKLib/src/queue.cpp:
--------------------------------------------------------------------------------
1 | #include "queue.h"
2 |
3 | Queue::Queue() {
4 | queue.reserve(DEFAULT_QUEUE_RESERVE);
5 | }
6 |
7 | void Queue::Lock()
8 | {
9 | unsigned int wait = 1;
10 | unsigned int maxWait = ~0ul;
11 |
12 | DWORD32 curIndex = (DWORD32)random::Next32(0, MAXUINT32);
13 | queue.Append(curIndex);
14 |
15 | while (!(queue[0] == curIndex))
16 | {
17 | for (unsigned i = 0; i < wait; ++i)
18 | {
19 | _mm_pause();
20 | }
21 |
22 | // Don't call "pause" too many times. If the wait becomes too big,
23 | // clamp it to the max_wait.
24 |
25 | if (wait * 2 > maxWait)
26 | {
27 | wait = maxWait;
28 | }
29 | else
30 | {
31 | wait = wait * 2;
32 | }
33 | }
34 | }
35 |
36 | void Queue::Unlock()
37 | {
38 | queue.RemoveAt(0);
39 | }
40 |
--------------------------------------------------------------------------------
/SKLib/src/utils.cpp:
--------------------------------------------------------------------------------
1 | #include "utils.h"
2 |
3 | UNICODE_STRING GetModuleNameFromPath(PUNICODE_STRING path)
4 | {
5 | UNICODE_STRING s;
6 |
7 | char* char_arr = (char*)ExAllocatePool(NonPagedPoolNx, (size_t)path->Length + 1);
8 | wcstombs(char_arr, path->Buffer, (size_t)path->Length);
9 | string* full_path = string::create(char_arr);
10 |
11 | int index = full_path->last_of('\\');
12 | string modName = full_path->substring(index + 1);
13 | PCWSTR wstr = (PCWSTR)cpp::kMalloc(((size_t)modName.Length() + 1) * 2, PAGE_READWRITE);
14 | mbstowcs((wchar_t*)wstr, (char*)modName.pBuffer, modName.Length());
15 | RtlInitUnicodeString(&s, wstr);
16 |
17 | full_path->Dispose();
18 | modName.Dispose();
19 | cpp::kFree(full_path);
20 | ExFreePool(char_arr);
21 |
22 | return s;
23 | }
--------------------------------------------------------------------------------
/SKLib-v/include/Vmoperations.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #ifdef _KERNEL_MODE
4 | #include "Vmexit.h"
5 | #include "bitmap.h"
6 |
7 | typedef void (*fnVmOperation)(ONEXIT_DATA data);
8 |
9 | typedef struct _OPERATION_DATA {
10 | fnVmOperation operation;
11 | bitmap::LARGE_BITMAP executedBitmap;
12 | bitmap::LARGE_BITMAP executionBitmap;
13 |
14 | __forceinline bool operator==(_OPERATION_DATA& rhs) {
15 | return memcmp(this, &rhs, sizeof(rhs)) == 0;
16 | }
17 | __forceinline bool operator!=(_OPERATION_DATA& rhs) {
18 | return !(*this == rhs);
19 | }
20 | } OPERATION_DATA, *POPERATION_DATA;
21 |
22 | namespace vmoperations {
23 | void Init();
24 |
25 | void ExecuteOperations(ONEXIT_DATA data);
26 | void InsertOperation(bitmap::LARGE_BITMAP executionBitmap, fnVmOperation operation);
27 | }
28 | #endif
--------------------------------------------------------------------------------
/Pdbparser/pdbparse.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include