-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmacrowriter.cpp
More file actions
128 lines (90 loc) · 3.46 KB
/
macrowriter.cpp
File metadata and controls
128 lines (90 loc) · 3.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
MIT License
Copyright (c) 2020 Jason Johnson
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "pch.h"
#include "macrowriter.h"
/*++
Routine Description:
Generates a C-compatible macro function from the list of changed bytes and their locations
Operates on the notion that the process handle will be passed upon call
Parameters:
MacroName - The name of the macro generated
List - the list of changes, to be parsed into program statements for a macro
Return Value:
A macro, a sequence of program statements
--*/
std::vector<std::pair<std::string, std::string>> GeneratePairMacro(std::string MacroName, std::vector<std::pair<BYTE, PVOID>> List)
{
//
// Store program statements in a vector to parse for output
//
std::vector<std::pair<std::string, std::string>> Macros;
//
// If macro/function name is not specified, use a default name
//
if (MacroName == "")
{
MacroName = "DefaultMacroName";
}
//
// Parse the function name into a declaration, then iterate over each needed WriteProcessMemory sequence
//
std::string FunctionInit = "void " + MacroName + "(HANDLE ProcessHandle)\n{\n";
std::string FunctionEnd = "}";
Macros.push_back({ FunctionInit, FunctionEnd });
for (size_t Item = 0; Item < List.size(); Item++)
{
//
// Create a buffer named after the item index
// Set the buffer to the first value of the Item in List[Item]
//
std::string VarInit = "\tBYTE Buffer" + std::to_string(Item);
VarInit += " = " + std::to_string(List[Item].first) + "L;\n";
//
// Write the BufferN to the process using the decimal formatted second value of the Item in List[Item], indicating the virtual address
//
std::string WriteInit = "\tWriteProcessMemory(ProcessHandle, (PVOID)";
WriteInit += std::to_string((DWORD_PTR)List[Item].second) + "L, &Buffer" + std::to_string(Item) + ", 1, NULL);\n\n";
Macros.push_back({ VarInit, WriteInit });
}
return Macros;
}
/*++
Routine Description:
Outputs the parsed macro to the CLI
Parameters:
Macros - The sequence of program statements that make up the macro to be parsed and displayed
Return Value:
None
--*/
void OutputMacro(std::vector<std::pair<std::string, std::string>> Macros)
{
//
// Function header initialization
//
std::cout << Macros[0].first;
for (std::size_t MacIndex = 1; MacIndex < Macros.size(); MacIndex++)
{
std::cout << Macros[MacIndex].first << Macros[MacIndex].second;
}
//
// End of function, second pair value of the first macro
//
std::cout << Macros[0].second << "\n" << std::endl;
}