Skip to content

Commit

Permalink
include pwn.hpp -> include pwn (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugsy committed Nov 5, 2023
1 parent 7d2cd10 commit 321fab1
Show file tree
Hide file tree
Showing 19 changed files with 153 additions and 130 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,5 +3,6 @@ Build*
pwn++/Include/pwn_export.hpp
pwn++/Include/constants.hpp
pwn++/Include/pwn.hpp
pwn++/Include/pwn
Docs/conf/Doxyfile
Docs/api/
2 changes: 1 addition & 1 deletion Docs/examples/common/assembly.md
Expand Up @@ -8,7 +8,7 @@ Requirements:
- `PWN_DISASSEMBLE_ARM64` cmake flag to enable [binja-arm64](https://github.com/Vector35/arch-arm64) for arm64

```cpp
#include <pwn.hpp>
#include <pwn>
using namespace pwn;

int wmain()
Expand Down
2 changes: 1 addition & 1 deletion Docs/examples/common/basic.md
Expand Up @@ -6,7 +6,7 @@ The most basic example for using `pwn++`.

```c++
// 1. include the header
#include <pwn.hpp>
#include <pwn>
// 2. invoke the namespace
using namespace pwn;
// 3. that's it!
Expand Down
2 changes: 1 addition & 1 deletion Docs/examples/common/utils.md
Expand Up @@ -90,7 +90,7 @@ int wmain()
using `ExportImport` macro, then copy/paste the definition (from MSDN, ReactOS, Pinvoke, NirSoft, etc.)

```cpp
#include <pwn.hpp>
#include <pwn>

ExportImport( \
"ntdll.dll", \
Expand Down
4 changes: 2 additions & 2 deletions Docs/examples/win32/alpc.md
Expand Up @@ -4,7 +4,7 @@ Namespace: `pwn::windows::alpc`

## Server
```cpp
#include <pwn.hpp>
#include <pwn>

int wmain(int argc, wchar_t** argv)
{
Expand Down Expand Up @@ -58,7 +58,7 @@ int wmain(int argc, wchar_t** argv)
## Client
```cpp
#include <pwn.hpp>
#include <pwn>
int wmain(int argc, wchar_t** argv)
{
Expand Down
118 changes: 68 additions & 50 deletions Modules/Process/Include/Win32/Job.hpp
@@ -1,50 +1,68 @@
#pragma once

#include "Common.hpp"
#include "Error.hpp"
#include "Handle.hpp"


namespace pwn::Job
{

// todo:
// limit_cpufreq_for_job
// assign_job_to_core

class Job
{
public:
Job(_In_ LPCWSTR name = nullptr) : m_Name(name), m_Valid {false}
{
HANDLE hJob = ::CreateJobObjectW(nullptr, name);
if ( !hJob && ::GetLastError() == ERROR_ALREADY_EXISTS )
{
hJob = ::OpenJobObjectW(JOB_OBJECT_ALL_ACCESS, FALSE, name);
}

if ( !hJob )
throw std::exception("cannot create job");

m_hJob = UniqueHandle {hJob};

m_Valid = true;
}

bool
IsValid() const
{
return m_Valid;
}


private:
auto
AddProcess(u32 ProcessId) -> Result<bool>;

bool m_Valid {false};
std::wstring m_Name {};
UniqueHandle m_hJob {};
std::vector<UniqueHandle> m_Handles {};
};
} // namespace Job
#pragma once

#include "Common.hpp"
#include "Error.hpp"
#include "Handle.hpp"


namespace pwn::Job
{

// todo:
// limit_cpufreq_for_job
// assign_job_to_core

class Job
{
public:
Job(_In_ LPCWSTR name = nullptr) : m_Name(name), m_Valid {false}
{
HANDLE hJob = ::CreateJobObjectW(nullptr, name);
if ( !hJob && ::GetLastError() == ERROR_ALREADY_EXISTS )
{
hJob = ::OpenJobObjectW(JOB_OBJECT_ALL_ACCESS, FALSE, name);
}

if ( !hJob )
throw std::exception("cannot create job");

m_hJob = UniqueHandle {hJob};

m_Valid = true;
}

bool
IsValid() const
{
return m_Valid;
}

auto
AddProcess(u32 ProcessId) -> Result<bool>;

///
///@brief Simple C++ friendly wrapper for `AddProcess`
///
///@param ProcessId
///@return Job&
///@throws `runtime_error` if adding process to the job failed
///
Job&
operator+=(u32 ProcessId)
{
if ( Success(AddProcess(ProcessId)) )
{
return *this;
}

throw std::runtime_error("Error adding process to job");
}


private:
bool m_Valid {false};
std::wstring m_Name {};
UniqueHandle m_hJob {};
std::vector<UniqueHandle> m_Handles {};
};
} // namespace pwn::Job
2 changes: 1 addition & 1 deletion Tools/Linux/ExploitTemplate/main.cpp
@@ -1,4 +1,4 @@
#include <pwn.hpp>
#include <pwn>
using namespace pwn;

int
Expand Down
4 changes: 3 additions & 1 deletion Tools/Win32/AppContainMe/AppContainMe.cpp
Expand Up @@ -11,8 +11,10 @@
#include <filesystem>
#include <iostream>

#include "pwn.hpp"
// clang-format off
#include <pwn>
using namespace pwn;
// clang-format on

auto
wmain(_In_ int argc, _In_ const wchar_t** argv) -> int
Expand Down
2 changes: 1 addition & 1 deletion Tools/Win32/Backdoor/Backdoor.cpp
Expand Up @@ -6,7 +6,7 @@
/// @brief
///

#include <pwn.hpp>
#include <pwn>
using namespace pwn;


Expand Down
2 changes: 1 addition & 1 deletion Tools/Win32/BasicExample/main.cpp
Expand Up @@ -3,7 +3,7 @@
///
///

#include "pwn.hpp"
#include <pwn>
using namespace pwn;

// constexpr PROCESS_INFORMATION_CLASS ProcessDebugAuthInformation =
Expand Down
2 changes: 1 addition & 1 deletion Tools/Win32/ExploitTemplate/xp.cpp
@@ -1,4 +1,4 @@
#include <pwn.hpp>
#include <pwn>
using namespace pwn;

int
Expand Down
2 changes: 1 addition & 1 deletion Tools/Win32/HexdumpFile/HexdumpFile.cpp
@@ -1,4 +1,4 @@
#include <pwn.hpp>
#include <pwn>
using namespace pwn;

auto
Expand Down
4 changes: 3 additions & 1 deletion Tools/Win32/LoadDriver/LoadDriver.cpp
@@ -1,9 +1,11 @@
#include <argparse.hpp>
#include <filesystem>
#include <pwn.hpp>
#include <ranges>

// clang-format off
#include <pwn>
using namespace pwn;
// clang-format on

int
ListServices()
Expand Down
2 changes: 1 addition & 1 deletion Tools/Win32/ProcessGhosting/ProcessGhosting.cpp
Expand Up @@ -9,7 +9,7 @@
/// @ref Gabriel Landau - https://www.elastic.co/blog/process-ghosting-a-new-executable-image-tampering-attack
///

#include <pwn.hpp>
#include <pwn>
#include <stdexcept>
using namespace pwn;

Expand Down
2 changes: 1 addition & 1 deletion Tools/Win32/ProcessReparent/ProcessReparent.cpp
Expand Up @@ -6,7 +6,7 @@
/// @brief Simple script using pwn++ to spawn a process reparented
///

#include <pwn.hpp>
#include <pwn>
using namespace pwn;

auto
Expand Down
2 changes: 1 addition & 1 deletion Tools/Win32/SyscallTrace/SyscallTrace.cpp
Expand Up @@ -8,7 +8,7 @@
/// @ref Alex Ionescu - Hooking Nirvana (https://github.com/ionescu007/HookingNirvana)
///

#include <pwn.hpp>
#include <pwn>
using namespace pwn;

EXTERN_C_START
Expand Down
2 changes: 1 addition & 1 deletion pwn++/CMakeLists.txt
Expand Up @@ -25,7 +25,7 @@ endif()
message(STATUS "Generating 'pwn.hpp'")
list(TRANSFORM PWN_MODULES PREPEND PWN:: OUTPUT_VARIABLE MODULE_NAMESPACES)
list(LENGTH MODULE_NAMESPACES PWN_MODULES_LENGTH)
configure_file(${PROJECT_SOURCE_DIR}/pwn.hpp.in ${INTERFACE_DIR}/pwn.hpp NEWLINE_STYLE WIN32)
configure_file(${PROJECT_SOURCE_DIR}/pwn.hpp.in ${INTERFACE_DIR}/pwn NEWLINE_STYLE WIN32)

if(WIN32)
target_sources(${PROJECT_NAME} PRIVATE ${SOURCE_DIR}/Win32/dllmain.cpp)
Expand Down
2 changes: 1 addition & 1 deletion pwn++/Source/Linux/dllmain.cpp
@@ -1,4 +1,4 @@
#include "pwn.hpp"
#include "pwn"


static __attribute__((constructor)) void
Expand Down

0 comments on commit 321fab1

Please sign in to comment.