-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathCommon.cpp
More file actions
84 lines (67 loc) · 2.46 KB
/
Copy pathCommon.cpp
File metadata and controls
84 lines (67 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//----------------------------------------------------------------------------
// History: 2015-06-19 Dwayne Robinson - Created
//----------------------------------------------------------------------------
#include "precomp.h"
#include <string>
#include <stdint.h>
#include <stdexcept>
#include "Common.h"
#if USE_CPP_MODULES
import Common.String;
#else
#include "Common.ArrayRef.h"
#include "Common.String.h"
#endif
////////////////////////////////////////
bool ThrowIf(bool value, _In_opt_z_ char const* message)
{
if (value)
throw std::runtime_error(message != nullptr ? message : "Unexpected failure");
return value;
}
bool TestBit(void const* memoryBase, uint32_t bitIndex) noexcept
{
return _bittest( reinterpret_cast<long const*>(memoryBase), bitIndex) != 0;
}
bool ClearBit(void* memoryBase, uint32_t bitIndex) noexcept
{
return _bittestandreset( reinterpret_cast<long*>(memoryBase), bitIndex) != 0;
}
bool SetBit(void* memoryBase, uint32_t bitIndex) noexcept
{
return _bittestandset( reinterpret_cast<long*>(memoryBase), bitIndex) != 0;
}
void GetCommandLineArguments(_Inout_ std::u16string& commandLine)
{
// Get the original command line argument string as a single string,
// not the preparsed argv or CommandLineToArgvW, which fragments everything
// into separate words which aren't really useable when you have your own
// syntax to parse. Skip the module filename because we're only interested
// in the parameters following it.
// Skip the module name.
const wchar_t* initialCommandLine = GetCommandLine();
wchar_t ch = initialCommandLine[0];
if (ch == '"')
{
do
{
ch = *(++initialCommandLine);
} while (ch != '\0' && ch != '"');
if (ch == '"')
++initialCommandLine;
}
else
{
while (ch != '\0' && ch != ' ')
{
ch = *(++initialCommandLine);
}
}
// Assign it and strip any leading or trailing spaces.
auto commandLineLength = wcslen(initialCommandLine);
commandLine.assign(initialCommandLine, &initialCommandLine[commandLineLength]);
TrimSpaces(IN OUT commandLine);
}
static constexpr uint32_t g_endiannessSignature = 0x01020304;
static constexpr uint8_t g_lowByteOfEndiannessSignature = (const uint8_t&)(g_endiannessSignature);
static_assert(g_lowByteOfEndiannessSignature & 4, "Must be logical endian");