pwn++  0.1.4
A (toy) Windows & Linux pwn library to play with modern C++.
System.hpp
Go to the documentation of this file.
1 
11 #pragma once
12 
13 #include "Common.hpp"
14 
15 
16 namespace pwn::System
17 {
18 
19 namespace details
20 {
28 Result<PVOID>
29 QueryInternal(const SYSTEM_INFORMATION_CLASS, const usize);
30 } // namespace details
31 
37 auto
38 PageSize() -> u32;
39 
46 u32
47 ProcessId(const HANDLE hProcess = ::GetCurrentProcess());
48 
49 
56 auto
57 ParentProcessId(const u32 dwProcessId) -> Result<u32>;
58 
65 auto
66 PidOf(std::wstring_view const targetProcessName) -> Result<std::vector<u32>>;
67 
73 const std::wstring
75 
81 Result<std::wstring>
83 
90 Result<std::wstring>
91 ModuleName(HMODULE hModule);
92 
98 Result<std::wstring>
100 
106 std::tuple<u32, u32, u32>
108 
116 template<class T>
117 Result<std::shared_ptr<T>>
118 Query(SYSTEM_INFORMATION_CLASS SystemInformationClass)
119 {
120  auto res = details::QueryInternal(SystemInformationClass, sizeof(T));
121  if ( Failed(res) )
122  {
123  return Error(res);
124  }
125 
126  const auto p = reinterpret_cast<T*>(Value(res));
127  auto deleter = [](T* x)
128  {
129  ::LocalFree(x);
130  };
131  return Ok(std::shared_ptr<T>(p, deleter));
132 }
133 
134 
142 Result<std::tuple<u8, u8, u8, u8, u8>>
144 
145 
151 Result<std::vector<RTL_PROCESS_MODULE_INFORMATION>>
153 
154 
160 Result<std::vector<SYSTEM_HANDLE_TABLE_ENTRY_INFO>>
162 
163 
169 Result<std::vector<std::tuple<u32, u32>>>
171 } // namespace pwn::System
Result< std::shared_ptr< T > > Query(SYSTEM_INFORMATION_CLASS SystemInformationClass)
Query system information.
Definition: System.hpp:118
Result< std::wstring > ModuleName(HMODULE hModule)
Result< std::wstring > UserName()
Result< std::vector< std::tuple< u32, u32 > > > Threads()
Enumerate all {ProcessId, ThreadId} currently running.
Result< std::vector< RTL_PROCESS_MODULE_INFORMATION > > Modules()
Get the kernel modules.
Result< std::tuple< u8, u8, u8, u8, u8 > > ProcessorCount()
Retrieves the system number of processors and their cache.
Result< std::wstring > FileName()
const std::wstring ComputerName()
std::tuple< u32, u32, u32 > WindowsVersion()
Get the Windows version as a tuple of int, or raise an exception.
auto PageSize() -> u32
Get the page size of the targeted system.
Result< PVOID > QueryInternal(const SYSTEM_INFORMATION_CLASS, const usize)
Should not be called directly.
Result< std::vector< SYSTEM_HANDLE_TABLE_ENTRY_INFO > > Handles()
Enumerate all the system handles.
auto ParentProcessId(const u32 dwProcessId) -> Result< u32 >
u32 ProcessId(const HANDLE hProcess=::GetCurrentProcess())
auto PidOf(std::wstring_view const targetProcessName) -> Result< std::vector< u32 >>