Closed phra closed 4 years ago
-std=c++17
#include <winternl.h>
#include <ntstatus.h>
#include <windows.h>
#include <iostream>
// This header contains the initialization function. // If you already initialized, inline_syscall.hpp contains all you need.
// I'd recommend https://github.com/processhacker/phnt for these definitions NTSTATUS NtAllocateVirtualMemory(HANDLE ProcessHandle, PVOID *BaseAddress, ULONG_PTR ZeroBits, PSIZE_T RegionSize, ULONG AllocationType, ULONG Protect);
int main() { // Needs to be called once at startup before INLINE_SYSCALL is used. jm::init_syscalls_list();
// Usage of the main macro INLINE_SYSCALL
void* allocation = nullptr;
SIZE_T size = 0x1000;
NTSTATUS status = INLINE_SYSCALL(NtAllocateVirtualMemory)((HANDLE)-1, &allocation, 0, &size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
return 0;
}
it works, thank you @JustasMasiulis !
i have another question: is it possible to check at runtime if the syscall is available on the host operating system? eg:
if (!GetProcAddress(GetModuleHandle("NTDLL.DLL"), "NtQuerySecurityPolicy")) {
// NtQuerySecurityPolicy is not available, os < win10
}
template<std::uint32_t Hash>
JM_INLINE_SYSCALL_FORCEINLINE bool syscall_present_impl() {
::jm::detail::exports_directory exports(static_cast<const char*>(::jm::detail::ntdll_base()));
for(auto i = exports.size();; --i) {
if(::jm::hash(exports.name(i)) == Hash)
return true;
}
return false;
}
#define SYSCALL_PRESENT(syscall_name) (syscall_present_impl<::jm::hash(#syscall_name)>())
syscall_entry_full
and check if ID is 0 (won't work for 0th syscall but eh)thanks again!
hello,
i am trying to use the library with https://github.com/tpoechtrager/wclang in order to compile a PE from linux. i have tried with both clang-6 and clang-8 but i always get the following error:
The source code of hello.cpp is the following:
any idea on how to fix the template error?