CommonLib
Loading...
Searching...
No Matches
ThisProcess.h
Go to the documentation of this file.
1#pragma once
2
3#include <filesystem>
4#include <vector>
5
6#include "StackFrame.h"
7
8namespace hedgedev::csl::diag::this_process
9{
10 ///
11 /// Gets the command line arguments that were passed into this process at launch.
12 ///
13 template <typename TString>
15
16 ///
17 /// Gets the path to the executable this process started from.
18 ///
20
21 ///
22 /// Gets the path to the directory containing executable this process started from.
23 ///
25
26 ///
27 /// Gets the path to the module containing the specified address.
28 ///
29 /// \param in_pAddr The address to search for.
30 ///
32
33 ///
34 /// Gets the working directory of this process.
35 ///
37
38 ///
39 /// Gets a stack trace.
40 ///
41 /// \param in_pContext A pointer to a CPU context structure.
42 /// \param in_maxFrames The maximum number of stack frames to capture.
43 ///
44 /// \returns A collection of stack frames.
45 ///
46 inline std::vector<StackFrame> GetStackTrace(const void* in_pContext, const size_t in_maxFrames = 0);
47
48 ///
49 /// Checks if this process is the owner of the specified address.
50 ///
51 /// \param in_pAddr The address to search for.
52 ///
53 inline bool HasAddress(const void* in_pAddr);
54
55 ///
56 /// Checks if a path is in the same directory as the executable this process started from.
57 ///
58 /// \param in_rPath The path to check.
59 ///
60 /// \returns `true` if both paths are in the same directory. Otherwise, `false`.
61 ///
62 inline bool IsNeighbour(const std::filesystem::path& in_rPath);
63
64 ///
65 /// Restarts this process.
66 ///
67 /// \param in_rArgs The command line arguments to pass into the new process.
68 ///
69 /// \returns `true` if this process was terminated successfully. Otherwise, `false`.
70 ///
71 template <typename TString>
72 inline bool Restart(const std::vector<TString>& in_rArgs);
73
74 ///
75 /// Restarts this process.
76 ///
77 /// \returns `true` if this process was terminated successfully. Otherwise, `false`.
78 ///
79 inline bool Restart();
80}
81
82#include "ThisProcess.inl"
83
84#ifdef WIN32
85#include "Win32/ThisProcess.inl"
86#endif
#define __CMNLIB_INTERNAL_MAKE_NAMESPACE_ALIAS(PARENT, NAME, ALIAS)
Definition CommonLib.h:6
#define ASSERT_RETURN(CONDITION, RETURN_VALUE)
Definition Preprocessor.h:17
#define ASSERT_RETURN_FALSE(CONDITION)
Definition Preprocessor.h:33
Definition StringTypes.h:89
Definition StringTypes.h:83
Definition StringTypes.h:77
Definition StringTypes.h:59
Definition StringTypes.h:65
Definition StringTypes.h:71
bool Read(const std::filesystem::path &in_rPath, const std::filesystem::path &in_rValueName, T &out_rData)
Definition Registry.inl:41
bool Write(const std::filesystem::path &in_rPath, const T &in_rData)
Definition Registry.inl:179
bool Write(const std::filesystem::path &in_rPath, const std::filesystem::path &in_rValueName, const T &in_rData)
Definition Registry.inl:122
bool Read(const std::filesystem::path &in_rPath, T &out_rData)
Definition Registry.inl:116
Definition Process.inl:2
bool Start(const std::filesystem::path &in_rPath, const std::vector< TString > &in_rArgs, std::optional< std::filesystem::path > in_work)
Definition Process.inl:4
std::vector< StackFrame > GetStackTrace(const void *in_pContext, const size_t in_maxFrames)
Definition ThisProcess.inl:65
std::filesystem::path GetWorkingDirectory()
Definition ThisProcess.inl:55
bool Restart()
Definition ThisProcess.inl:166
bool IsNeighbour(const std::filesystem::path &in_rPath)
Definition ThisProcess.inl:10
std::vector< TString > GetCommandLineArguments()
Definition ThisProcess.inl:9
bool Restart(const std::vector< TString > &in_rArgs)
Definition ThisProcess.inl:159
std::filesystem::path GetModulePathFromAddress(const void *in_pAddr)
Definition ThisProcess.inl:37
std::filesystem::path GetExecutablePath()
Definition ThisProcess.inl:27
bool HasAddress(const void *in_pAddr)
Definition ThisProcess.inl:141
std::filesystem::path GetExecutableRoot()
Definition ThisProcess.inl:5
Definition ThisProcess.inl:4
Definition Memory.h:25
void * ToASLR(void *in_pAddress, void *in_pBaseAddress=nullptr)
Definition Memory.inl:52
bool Write(void *in_pAddress, const std::vector< T > &in_rData)
Definition Memory.inl:41
void * FromASLR(void *in_pAddress, void *in_pBaseAddress=nullptr)
Definition Memory.inl:60
bool Write(void *in_pAddress, const T &in_rData, size_t in_count=1)
Definition Memory.inl:23
std::array< T, Count > Read(void *in_pAddress)
Definition Memory.inl:12
PageProtection
Definition Memory.h:27
@ X
Definition Memory.h:39
@ Write
Definition Memory.h:31
@ Execute
Definition Memory.h:32
@ RWX
Definition Memory.h:42
@ RW
Definition Memory.h:40
@ W
Definition Memory.h:38
@ ReadWriteExecute
Definition Memory.h:35
@ ReadWrite
Definition Memory.h:33
@ Read
Definition Memory.h:30
@ ReadExecute
Definition Memory.h:34
@ NoAccess
Definition Memory.h:28
@ R
Definition Memory.h:37
@ RX
Definition Memory.h:41
BranchType
Definition Memory.inl:4
bool IsNop(void *in_pAddress)
Definition Memory.inl:37
void * ReadInstructionAddress(void *in_pAddress, size_t in_offset, size_t in_stride)
Definition Memory.inl:124
bool WriteNop(void *in_pAddress, size_t in_count=1)
Definition Memory.inl:182
bool WriteCall(void *in_pAddress, void *in_pDestination)
Definition Memory.inl:142
bool WriteString(void *in_pAddress, const T &in_rStr)
Definition Memory.inl:58
BranchCondition
Definition Memory.inl:18
bool WriteJump(void *in_pAddress, void *in_pDestination, bool in_isCall=false)
Definition Memory.inl:147
bool WriteStringFixedLength(void *in_pAddress, const T &in_rStr, size_t in_length=0)
Definition Memory.inl:69
BranchDistance
Definition Memory.inl:11
BranchInfo GetBranchInfo(void *in_pAddress)
Definition Memory.inl:42
bool Protect(void *in_pAddress, size_t in_length, uint32_t in_newProtectionFlags, uint32_t *out_pOldProtectionFlags=nullptr)
Definition Memory.inl:47
void * GetOriginalModuleBase()
Definition Memory.inl:6
void * ReadCall(void *in_pAddress)
Definition Memory.inl:132
void * ReadJump(void *in_pAddress)
Definition Memory.inl:137
uint32_t GetProtectionFlags(PageProtection in_protection)
Definition Memory.inl:18
T Read(void *in_pAddress)
Definition Memory.inl:6
constexpr bool HasFlag(T in_mask, T in_flag)
Definition Expressions.inl:4
constexpr bool IsSameUnderlyingCharType
Definition StringTypes.h:95
std::tuple_element_t< Index, std::tuple< TArgs... > > GetPackType
Definition Expressions.h:9
constexpr bool IsBasicString_v
Definition StringTypes.h:47
constexpr TDst CreateInferredString(const TSrc &in_rStr)
Definition StringTypes.inl:4
constexpr size_t GetStringTypePrecedence()
Definition StringTypes.inl:12
constexpr bool IsBasicStringView_v
Definition StringTypes.h:53
constexpr bool IsAllSame
Definition Expressions.h:15
Definition FileSystem.inl:4
std::error_code TruncateFilesByAge(const std::filesystem::path &in_rPath, std::string_view in_extension, size_t in_max)
Definition FileSystem.inl:44
std::error_code TruncateFiles(const std::filesystem::path &in_rPath, std::string_view in_extension, size_t in_max, T &&in_rrCompare)
Definition FileSystem.inl:11
bool IsNeighbour(const std::filesystem::path &in_rPathA, const std::filesystem::path &in_rPathB)
Definition FileSystem.inl:5
std::filesystem::path FindInEnvironment(const std::filesystem::path &in_rFileName)
Definition FileSystem.inl:3
Definition String.h:8
size_t GetWidth(const TString &in_rStr)
Definition String.inl:133
bool Contains(const TString &in_rStr, const TSubString &in_rSubStr, bool in_isCaseSensitive=true)
Definition String.inl:26
TString ToHex(TValue in_value, size_t in_maxLength=sizeof(size_t) *2, bool in_prefix=true)
Definition String.inl:427
std::vector< TOut > Split(const TString &in_rStr, const TDelimiter &in_rDelimiter)
Definition String.inl:283
std::array< TOut, sizeof...(TArgs)> PrecedentConvert(const TArgs &... in_rArgs)
Definition String.inl:228
expr::InferredString< TString > Escape(const TString &in_rStr, TChar in_searchChar, TChar in_escapeChar=TChar('\\'))
Definition String.inl:74
expr::InferredString< TString > TrimEnd(const TString &in_rStr, std::optional< std::vector< TChar > > in_trimChars={})
Definition String.inl:361
TOut Pad(const TString &in_rStr, const TPadString &in_rPadStr)
Definition String.inl:203
TOut Parse(const TString &in_rStr)
Definition String.inl:218
TOut Hyperlink(const TString &in_rStr, const TUrl &in_rUrl)
Definition String.inl:147
expr::InferredString< TCollection > Join(const TDelimiter &in_rDelimiter, const std::vector< TCollection > &in_rStrings)
Definition String.inl:167
bool TryParse(const TString &in_rStr, TOut &out_rValue)
Definition String.inl:516
TOut Join(const TDelimiter &in_rDelimiter, const TArgs &... in_rArgs)
Definition String.inl:195
bool Compare(const TLeft &in_rLeft, const TRight &in_rRight, bool in_isCaseSensitive=true)
Definition String.inl:9
expr::InferredString< TString > Truncate(const TString &in_rStr, size_t in_maxLength, bool in_truncateEnd=true, bool in_ellipsis=true)
Definition String.inl:387
expr::InferredString< TString > RemoveXmlTags(const TString &in_rStr)
Definition String.inl:275
expr::InferredString< TString > Wrap(const TString &in_rStr, size_t in_maxWidth)
Definition String.inl:546
expr::InferredString< TString > ToLower(const TString &in_rStr)
Definition String.inl:314
expr::InferredString< TString > Format(const TString in_str,...)
Definition String.inl:90
expr::InferredString< TString > TrimStart(const TString &in_rStr, std::optional< std::vector< TChar > > in_trimChars={})
Definition String.inl:342
bool TryConvert(const TSrc &in_rSrc, TDst &out_rDst)
Definition String.inl:447
expr::InferredString< TString > ToUpper(const TString &in_rStr)
Definition String.inl:328
expr::InferredString< TString > Trim(const TString &in_rStr, std::optional< std::vector< TChar > > in_trimChars={})
Definition String.inl:381
Definition Expressions.inl:2
Definition Registry.inl:2
Definition Memory.h:50
uint8_t InstrLength
Definition Memory.h:55
BranchDistance Distance
Definition Memory.h:52
uint8_t OpcodeLength
Definition Memory.h:54
BranchType Type
Definition Memory.h:51
BranchCondition Condition
Definition Memory.h:53
void * pDestination
Definition Memory.h:56
Definition StringTypes.h:11
Definition StringTypes.h:26