pwn++  0.1.4
A (toy) Windows & Linux pwn library to play with modern C++.
Context.hpp
1 #pragma once
2 
3 #include "Architecture.hpp"
4 #include "Common.hpp"
5 #include "Log.hpp"
6 #include "Utils.hpp"
7 
8 using namespace pwn;
9 
14 {
15 public:
16  u64 CryptoSeed;
17  std::mutex m_ConsoleMutex;
18  std::mutex m_ConfigMutex;
19  Log::LogLevel LogLevel = Log::LogLevel::Info;
20 
21  Architecture architecture;
22  Endianess endianess;
23  usize ptrsize;
24 
25  GlobalContext();
26 
27 
28  template<typename T>
29  void
30  Set(T const& arg)
31  {
32  if constexpr ( std::is_same_v<T, std::string_view> )
33  {
34  warn("Deprecated, prefer using ArchitectureType");
35  SetArchitecture(arg);
36  return;
37  }
38 
39  if constexpr ( std::is_same_v<T, std::wstring_view> )
40  {
41  warn("Deprecated, prefer using ArchitectureType");
42  SetArchitecture(Utils::StringLib::To<std::string>(arg));
43  return;
44  }
45 
46  if constexpr ( std::is_same_v<T, ArchitectureType> )
47  {
48  SetArchitecture(arg);
49  return;
50  }
51 
52  if constexpr ( std::is_same_v<T, Log::LogLevel> )
53  {
54  SetLogLevel(arg);
55  return;
56  }
57 
58  if constexpr ( std::is_same_v<T, Endianess> )
59  {
60  SetEndianess(arg);
61  return;
62  }
63 
64  throw new std::bad_typeid();
65  }
66 
67 
68 private:
74  void
75  SetArchitecture(ArchitectureType const& arch);
76 
77 
83  void
84  SetArchitecture(std::string_view const& type);
85 
86 
93  void
94  SetEndianess(Endianess end);
95 
96 
102  void SetLogLevel(Log::LogLevel);
103 };
104 
105 
106 extern struct GlobalContext Context;
Logging header: Wide string support on linux is at best flaky, so only Windows version gets both stri...
LogLevel
Define the logging level.
Definition: Log.hpp:60
Global context definition.
Definition: Context.hpp:14
Architecture class definition, with its wstring representation.
Definition: Architecture.hpp:59