diff --git a/modules/ModuleCmd/syscall.cpp b/modules/ModuleCmd/syscall.cpp new file mode 100644 index 0000000..bebace8 --- /dev/null +++ b/modules/ModuleCmd/syscall.cpp @@ -0,0 +1,57 @@ +#include "syscall.hpp" + + +DWORD GlobalHash = 0x0; + + +EXTERN_C DWORD getGlobalHash() +{ + return GlobalHash; +} + + +DWORD SW3_HashSyscall(const char *FunctionName) +{ + DWORD Hash = 0x811C9DC5; // FNV offset basis + DWORD FNV_prime = 0x01000193; // FNV prime + + int c; + while (c = *FunctionName++) + { + Hash ^= c; // XOR the byte into the lowest byte of the hash + Hash *= FNV_prime; // Multiply by FNV prime + } + + return Hash & 0xFFFFFFFF; // Ensure the result is a 32-bit hash +} + +bool compareEntry(Entry i1, Entry i2) +{ + return (i1.getAddress() < i2.getAddress()); +} + +SyscallList* SyscallList::singleton_= nullptr; + + +SyscallList *SyscallList::GetInstance() +{ + if(singleton_==nullptr){ + singleton_ = new SyscallList(); + } + return singleton_; +} + + +EXTERN_C DWORD SW3_GetSyscallNumber(DWORD FunctionHash) +{ + SyscallList* singleton = SyscallList::GetInstance(); + return singleton->getSyscallNumber(FunctionHash); +} + + +EXTERN_C PVOID SW3_GetSyscallAddress(DWORD FunctionHash) +{ + SyscallList* singleton = SyscallList::GetInstance(); + return singleton->getSyscallAddress(FunctionHash); +} + diff --git a/modules/ModuleCmd/syscall.hpp b/modules/ModuleCmd/syscall.hpp index 94ab183..0661688 100644 --- a/modules/ModuleCmd/syscall.hpp +++ b/modules/ModuleCmd/syscall.hpp @@ -1,3 +1,5 @@ +#pragma once + #include #include #include "include.hpp" @@ -6,7 +8,9 @@ #include #include +extern DWORD GlobalHash; +EXTERN_C DWORD getGlobalHash(); DWORD SW3_HashSyscall(PCSTR FunctionName); EXTERN_C DWORD SW3_GetSyscallNumber(DWORD FunctionHash); EXTERN_C PVOID SW3_GetSyscallAddress(DWORD FunctionHash); @@ -124,31 +128,6 @@ IN SIZE_T BufferSize, OUT PSIZE_T NumberOfBytesRead OPTIONAL); -DWORD GlobalHash = 0x0; - - -EXTERN_C DWORD getGlobalHash() -{ - return GlobalHash; -} - - -DWORD SW3_HashSyscall(const char *FunctionName) -{ - DWORD Hash = 0x811C9DC5; // FNV offset basis - DWORD FNV_prime = 0x01000193; // FNV prime - - int c; - while (c = *FunctionName++) - { - Hash ^= c; // XOR the byte into the lowest byte of the hash - Hash *= FNV_prime; // Multiply by FNV prime - } - - return Hash & 0xFFFFFFFF; // Ensure the result is a 32-bit hash -} - - template NTSTATUS Sw3NtAllocateVirtualMemory_(Args&&... args) { @@ -353,10 +332,7 @@ private: }; -bool compareEntry(Entry i1, Entry i2) -{ - return (i1.getAddress() < i2.getAddress()); -} +bool compareEntry(Entry i1, Entry i2); class SyscallList @@ -525,30 +501,3 @@ public: return NULL; } }; - - -SyscallList* SyscallList::singleton_= nullptr; - - -SyscallList *SyscallList::GetInstance() -{ - if(singleton_==nullptr){ - singleton_ = new SyscallList(); - } - return singleton_; -} - - -EXTERN_C DWORD SW3_GetSyscallNumber(DWORD FunctionHash) -{ - SyscallList* singleton = SyscallList::GetInstance(); - return singleton->getSyscallNumber(FunctionHash); -} - - -EXTERN_C PVOID SW3_GetSyscallAddress(DWORD FunctionHash) -{ - SyscallList* singleton = SyscallList::GetInstance(); - return singleton->getSyscallAddress(FunctionHash); -} -