Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions examples/basic-usage.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#include <iostream>
#include <syscalls-cpp/syscall.hpp>
int main()
int main()
{
syscall::Manager<syscall::policies::allocator::section, syscall::policies::generator::direct> syscallManager;
if (!syscallManager.initialize())
{
std::optional optSyscallManager = syscall::Manager<syscall::policies::allocator::section, syscall::policies::generator::direct>::initialize();
if (!optSyscallManager.has_value()) {
std::cerr << "initialization failed!\n";
return 1;
}

auto& syscallManager = optSyscallManager.value();

PVOID pBaseAddress = nullptr;
SIZE_T uSize = 0x1000;

Expand Down
6 changes: 4 additions & 2 deletions examples/custom-generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,15 @@ struct EncryptedShellGenerator

int main()
{
syscall::Manager < syscall::policies::allocator::section, EncryptedShellGenerator> syscallManager;
if (!syscallManager.initialize())
std::optional optSyscallManager = syscall::Manager<syscall::policies::allocator::section, EncryptedShellGenerator>::initialize();
if (!optSyscallManager.has_value())
{
std::cerr << "failed to initialize syscall manager" << std::endl;
return 1;
}

auto& syscallManager = optSyscallManager.value();

std::cout << "syscall manager initialized successfully" << std::endl;

NTSTATUS status;
Expand Down
42 changes: 28 additions & 14 deletions include/syscalls-cpp/aliases.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,41 @@

namespace syscall
{
using DefaultParserChain = syscall::ParserChain_t<
syscall::policies::parser::directory,
syscall::policies::parser::signature
>;

// @note / sapdragon: fucking templates, is that a legal cpp hack? unpack overloads...
template<typename AllocPolicy, typename StubPolicy, typename... ParserArgs>
class Manager : public Manager<AllocPolicy, StubPolicy, DefaultParserChain>
class Manager;

template<typename AllocPolicy, typename StubPolicy>
class Manager<AllocPolicy, StubPolicy>
: public Manager<AllocPolicy, StubPolicy, syscall::policies::parser::directory, syscall::policies::parser::signature>
{
public:
static std::optional<Manager> initialize( const std::vector<SyscallKey_t>& vecModuleKeys = { SYSCALL_ID("ntdll.dll") } )
{
std::optional optManager = Manager<AllocPolicy, StubPolicy, syscall::policies::parser::directory, syscall::policies::parser::signature>::initialize(vecModuleKeys);

if (!optManager.has_value())
return std::nullopt;

return Manager(std::move(optManager.value()));
}
};

template< typename AllocPolicy, typename StubPolicy, IsSyscallParsingPolicy... ParsersInChain >
class Manager<AllocPolicy, StubPolicy, ParserChain_t<ParsersInChain...>>
class Manager<AllocPolicy, StubPolicy, ParsersInChain...>
: public ManagerImpl<AllocPolicy, StubPolicy, ParsersInChain...>
{
};

template< typename AllocPolicy, typename StubPolicy, typename FirstParser, typename... FallbackParsers>
class Manager<AllocPolicy, StubPolicy, FirstParser, FallbackParsers...>
: public ManagerImpl<AllocPolicy, StubPolicy, FirstParser, FallbackParsers...>
{
Manager(ManagerImpl<AllocPolicy, StubPolicy, ParsersInChain...>&& managerImpl)
: ManagerImpl<AllocPolicy, StubPolicy, ParsersInChain...>(std::move(managerImpl))
{ }
public:
static std::optional<Manager> initialize(const std::vector<SyscallKey_t>& vecModuleKeys = { SYSCALL_ID("ntdll.dll") })
{
std::optional optManagerImpl = ManagerImpl<AllocPolicy, StubPolicy, ParsersInChain...>::initialize(vecModuleKeys);
if (!optManagerImpl.has_value())
return std::nullopt;

return Manager(std::move(optManagerImpl.value()));
}
};

#if SYSCALL_PLATFORM_WINDOWS_64
Expand Down
2 changes: 1 addition & 1 deletion include/syscalls-cpp/shared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace syscall::native
}


[[nodiscard]] constexpr HANDLE getCurrentProcess() noexcept
[[nodiscard]] static HANDLE getCurrentProcess() noexcept
{
return reinterpret_cast<HANDLE>(-1);
}
Expand Down
Loading
Loading