-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresource.h
300 lines (252 loc) · 10.7 KB
/
resource.h
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#include <iostream>
#include <Windows.h>
#include <vector>
#include <fstream>
#include <string>
#include <iterator>
#include <random>
#include <iostream>
#include <list>
#include <sstream>
using namespace std;
const string g_szTemplatePath = "C:\\PermutativeAssembler\\PermutativeAssembler\\Template\\"; // C:\Permutative assembler\PermutativeAssembler\Template
const string g_szOpcodePath = "C:\\PermutativeAssembler\\PermutativeAssembler\\Block algorithms\\Trash\\Ops\\";
// ------------------------------------------------------------------------------------------
// ALL STRUCTURES
//-------------------------------------------------------------------------------------------
struct TEXTFILENAMES
{
string g_aszTextFiles[5]; // 0 : data.txt, 1 : Entry.txt, 2 : Header.txt, 3 : Import.txt, 4 : Include.txt, 5 : Text.txt
TEXTFILENAMES()
{
g_aszTextFiles[0] = g_szTemplatePath;
g_aszTextFiles[0] += "Header.txt";
g_aszTextFiles[1] = g_szTemplatePath;
g_aszTextFiles[1] += "Include.txt";
g_aszTextFiles[2] = g_szTemplatePath;
g_aszTextFiles[2] += "Entry.txt";
g_aszTextFiles[3] = g_szTemplatePath;
g_aszTextFiles[3] += "Data.txt";
g_aszTextFiles[4] = g_szTemplatePath;
g_aszTextFiles[4] += "Text.txt";
g_aszTextFiles[5] = g_szTemplatePath;
g_aszTextFiles[5] += "Import.txt";
}
};
struct EXTRACTDECRYPT
{
bool m_bExtractPath;
bool m_bExtractData;
bool m_bDecryptData;
bool m_bDecryptPath;
bool m_bCompleted;
};
struct REG_INTERNAL
{
unsigned int m_uiNumberOfRegistersUsed; // number of registers in the used register vector
string m_szRegister; // Two possible registers generated from output
//unsigned int m_uiRegisterIndex; // identifies bits of which register was used last
unsigned int m_uiSecondaryRegisterIndex; // Secondary index, used as compareson, and shows what register was generated last!
};
struct INSTRUCTIONSCOMPLETED
{
EXTRACTDECRYPT m_stExtractDecrypt;
};
struct OPERANDACCESSLEVELS
{
unsigned int m_uiNumberOfOperands;
unsigned int m_uiOperand[3];
};
// ------------------------------------------------------------------------------------------
// ALL CLASSES
//-------------------------------------------------------------------------------------------
/*
class GLOBALVARIABLESUSED
{
std::vector <std::string> m_vszGlobalVariablesUsed; // the strings of global variables in output program
std::vector <std::string>::iterator m_vszGlobalVariablesUsedIterator; // the iterator
std::vector <bool> m_vbGlobalVariablesAvaliable; // parallel vector to the global variable vector
std::vector <bool>::iterator m_vbGlobalVariablesAvaliableIterator;// indicating the variables which are
// and are not currently in use by main
unsigned int m_uiGlobalVariablesCount; // program!
GLOBALVARIABLESUSED::GLOBALVARIABLESUSED(unsigned int m_uiCount); // each string offset is hardcoded
// v
};
*/
class BASEBLOCK
{
public:
vector <string> m_vszBuffer;
};
class BLOCKOBJ: public BASEBLOCK
{
public:
BLOCKOBJ::BLOCKOBJ(string m_lpBufferArg); // Constructor, set buffer internally
//vector <string> m_vszBuffer;
// all inherited classes have access to this classes protected parameters
bool m_bCompleted; // Has this block been completed?
bool m_bJunkSwitch; // Temporary switch generated from random generator
unsigned int m_uiJunkRounds; // How many rounds of junk have been added to this block?
};
class AVALIABLEOPERANDS
{
public:
bool m_bAddition;
bool m_bSubtraction;
bool m_bDivision;
bool m_bMultiplication;
};
class THIRTYTWO_BITREG
{
public:
THIRTYTWO_BITREG::THIRTYTWO_BITREG();
string m_szRegArray[6];
};
class SIXTEEN_BITREG
{
public:
SIXTEEN_BITREG::SIXTEEN_BITREG();
string m_szRegArray[6];
};
class EIGHT_BITREG
{
public:
EIGHT_BITREG::EIGHT_BITREG();
string m_szRegArray[8];
};
class AVALIABLEREG // global struct of the registers avaliable to use safely by the junk generator
{ // currently only in 32-bit mode (may expand)
// initially true unless altered
public:
unsigned int EAX; // can only be 0, 1, or 2
unsigned int EBX; // 2 = Avaliable
unsigned int ECX; // 1 = In use by JUNK, so it ok to use lower two 8 bit segments
unsigned int EDX; // 0 = In use by PROGRAM - DO NOT USE
bool ESI;
bool EDI;
unsigned int AX;
unsigned int BX;
unsigned int CX;
unsigned int DX;
unsigned int SI;
unsigned int DI;
bool AH;
bool AL;
bool BH;
bool BL;
bool CH;
bool CL;
bool DH;
bool DL;
AVALIABLEREG::AVALIABLEREG();
};
class LABEL
{
public:
string m_szLabel;
bool m_bJMP;
bool m_bProc; // called through stdcall
};
class TRASHOBJ : public BASEBLOCK
{ // can be partially filled out, then put into global list
public: // contains trash buffer as well!
AVALIABLEREG m_stAvaliableReg;
LABEL m_stLabel;
unsigned int m_uiDwordsToReserveForStack;// used to setup local stack frame!
vector<string> m_vszLabelsCalled; // the calls that this trashobj makes via stdcall
bool m_bMakesStdcall;
}; // m_vszLabelsCalled is the main thing that needs to be fixed up
class VARIABLE
{
public:
bool m_bVariableInUse; // is the variable critical / in use by the actual program?
bool m_bJunkVariable; // is the variable a junk variable, or must we check it everytime it is access
unsigned int m_uiTypeVariable; // 0 = byte, 1 = word, 2 = dword,
string m_szVariableName; // the name of the variable
string m_szVariableDeclaration; // formatted string of how the variable is declared
};
class API_CALL
{
public:
unsigned int m_uiOperandsRequired;
};
class OPERAND_INTERNAL
{
public:
unsigned int m_uiNumberOfOperands;
unsigned int m_uiTypeOfOperandGenerated; // 0 - 8bit, 1 - 16 bit, 2 - 32bit
unsigned int * m_uiOperandArray;
bool m_bCanUseDifferentSizeReg; // can this operation use different sized registers?
bool m_bCanUseSameRegister; // can this op use the same register? ie mov ebx, ebx
bool m_bDereference[2]; // a flag for memory, whether we should add square brackets to argument!
bool m_bCannotBeTwoMemory; // there cannot be two memory operands
bool m_bMemoryGenerated;
bool m_bIsDereferenceSet;
bool m_bRegisterGenerated; // set if first operand is memory/reg
bool m_bOutOfRange; // if we use two mem of dw db will there be error?
OPERAND_INTERNAL::OPERAND_INTERNAL(OPERANDACCESSLEVELS*);
OPERAND_INTERNAL::~OPERAND_INTERNAL();
};
/* List for m_uiOperandArray for set values
0 = REG only (memory address) eg eax
1 = MEM only (dereferenced) eg [m_hello]
2 = MEM only (memory address) m_hello
3 = REG 8-bit only
4 = REG 16-bit only
5 = REG 32-but only
6 = REG/MEM
7 = 16bit or higher
*/
// ------------------------------------------------------------------------------------------
// All GLOBAL VARIABLES
//-----------------------------------------------------------------------------------------------
extern std::list<TRASHOBJ> g_lsGlobalTrashProcedure;
extern std::list<TRASHOBJ>::iterator g_lsGlobalTrashProcedureIterator;
extern std::list<TRASHOBJ> g_lsGlobalTrashJMP;
extern std::list<TRASHOBJ>::iterator g_lsGlobalTrashJMPIterator;
extern std::list<TRASHOBJ> g_lsGlobalTrashDirectInsert;
extern std::list<TRASHOBJ>::iterator g_lsGlobalTrashDirectInsertIterator;
extern std::list<API_CALL> g_lsGlobalAPICall;
extern std::list<API_CALL>::iterator g_lsGlobalAPICallIterator;
extern std::list<VARIABLE> g_lsGlobalVariable;
extern std::list<VARIABLE>::iterator g_lsGlobalVariableIterator;
extern std::vector<string> g_vszActualCode;
extern std::vector <string> g_vszGeneratedLabels; // labels generated previously by program, used as a check
extern std::vector <string> g_vszGlobalTrashJMPLabels; // where code can randomly jump - fucking powerful feature
extern bool g_bShouldJMP; // should the code jmp to a random label
extern unsigned int g_uiLevelsIntoTrash; // how many "levels" from actual code, how many procedures in are we?
extern BLOCKOBJ m_sectionArray[5]; // The FASM total file section array
extern BLOCKOBJ m_opcodeArray[8];
extern AVALIABLEREG m_stAvaliableReg; // Registers avaliable
extern EIGHT_BITREG m_stEightBitReg;
extern SIXTEEN_BITREG m_stSixteenBitReg;
extern THIRTYTWO_BITREG m_stThirtytwoBitReg;
extern unsigned int g_uiTotalTrashObjs; // Generated at start of program, how many trash objs to create
extern unsigned int g_uiTotalTrashProcObjs; // how many of each?
extern unsigned int g_uiTotalTrashDirectInsertObjs;
extern unsigned int g_uiTotalTrashJMPObjs;
extern unsigned int g_uiTotalAPICalls;
extern unsigned int g_uiDwordsTillStackCorrupts;
extern unsigned int g_uiGeneratedOpcodeIndex[2];
extern unsigned int g_uiGlobalRegisterFailCount;
// ------------------------------------------------------------------------------------------
// ALL FUNCTIONS
//-------------------------------------------------------------------------------------------
void WriteFile();
extern string GenerateRegister(REG_INTERNAL*, unsigned int m_uiRegType, bool m_bCanUseSameRegister,OPERAND_INTERNAL * m_stOperandInternal); // Generates a register which is not currently in use to be used
extern string GenerateLabel(unsigned int Len); // Generates a random label for use in either jumps or procedures
extern inline unsigned int GenerateRandom(unsigned int Min, unsigned int Max); // generates a random number
extern void AllocateVectorList(); // done once in program, loads opcodes
extern inline string GenerateOpcode(bool m_bFromProc); // Generates opcodes
extern void ProcessTrash();
extern string LookUpTable(string m_szOpcode); // Function sole purpose is to generate A VALID line from input (mainly in junkcode generation)
extern inline string DereferenceOperand(string m_szOperand,OPERAND_INTERNAL * m_stOperandInternal, bool m_bFromStdcall);
string GenerateLine(string m_szOpcode, OPERAND_INTERNAL*, REG_INTERNAL *);
void RepeatReg(REG_INTERNAL * m_stRegBits, unsigned int m_uiRegType);
extern void InitiateVariableList();
extern string GenerateVariable();
extern string CreateLabel();
extern string GenerateMemory(OPERAND_INTERNAL * m_stOperandInternal, unsigned int m_uiOperandIndex, bool m_bDereferenceMem, bool m_bFromStdcall);
extern void JMPStdcall();
extern string FormattedStdcall(OPERAND_INTERNAL * m_stOperandInternal, REG_INTERNAL * m_stRegInternal,TRASHOBJ *, bool m_bFromProc);
extern void GenerateAllProcedures(unsigned int m_uiNumberOfProcedures);