首页
社区
课程
招聘
[讨论]C/C++写辅助常用函数合集
2023-1-6 09:31 8780

[讨论]C/C++写辅助常用函数合集

2023-1-6 09:31
8780
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
int 汇编_加(int 参数一, int 参数二, int 参数三, int 参数四, int 参数五, int 参数六)
{
    __asm
    {
        mov eax, [参数二]
        add eax, [参数三]
        add eax, [参数四]
        add eax, [参数五]
        add eax, [参数六]
        add[参数一], eax
    }
    return 参数一;
}
 
int 汇编_减(int 参数一, int 参数二, int 参数三, int 参数四, int 参数五, int 参数六)
{
    int 结果 = 0;
    __asm
    {
        mov eax, 参数一
        sub eax, 参数二
        sub eax, 参数三
        sub eax, 参数四
        sub eax, 参数五
        sub eax, 参数六
        mov 结果, eax
    }
    return 结果;
}
 
int 汇编_乘(int 参数一, int 参数二)
{
    __asm
    {
        mov eax, 参数一
        mov ecx, 参数二
        imul eax, ecx
        leave
        retn 0008h
    }
    return 0;
}
 
int 汇编_除(int 参数一, int 参数二)
{
    __asm
    {
        pop ebp
        mov eax, 参数一
        mov ecx, 参数二
        cdq
        div ecx
        retn 0008h
    }
    return 0;
}
 
void JMP跳转(INT64 地址, INT64 跳转地址)
{
    byte Cpi[17] = { 255, 37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 144, 144, 144 };
    *(INT64*)(Cpi + 6) = 跳转地址;
    WriteProcessMemory(GetCurrentProcess(), (LPVOID)地址, Cpi, 17, 0);
}
 
wstring 到文本(int a)
{
    wstring result;
    WCHAR str[10];
    _itow_s(a, str, 10);
    result = str;
    return result;
}
 
ULONG_PTR Alloc(SIZE_T size)
{
    return (ULONG_PTR)VirtualAlloc(NULL, size, MEM_COMMIT | MEM_TOP_DOWN, PAGE_EXECUTE_READWRITE);
}
 
wstring 读文本(INT64 内存地址, int 长度)
{
    wchar_t * temp = new wchar_t[长度];
    memset(temp, 0, 长度);
    wstring text = L"";
    if (IsBadReadPtr(reinterpret_cast<void*>(内存地址), 长度)) return text;
    memcpy(temp, reinterpret_cast<void*>(内存地址), 长度);
    text = temp;
    delete[]temp;
    return text;
}
 
wstring 通关时间(int duration)
{
    int ss = 1000;
    int mi = ss * 60;
    int hh = mi * 60;
    int dd = hh * 24;
    long day = duration / dd;
    long hour = (duration - day * dd) / hh;
    long minute = (duration - day * dd - hour * hh) / mi;
    long second = (duration - day * dd - hour * hh - minute * mi) / ss;
    long milliSecond = duration - day * dd - hour * hh - minute * mi - second * ss;
    wstring hou;// 小时
    wstring min; // 分钟
    wstring sec; //
    wstring msec; // 毫秒
    if (hour != 0) {
        hou = 到文本(hour);
    }
    if (minute != 0) {
        min = 到文本(minute);
    }
    if (second != 0) {
        sec = 到文本(second);
    }
    if (milliSecond != 0) {
        msec = 到文本(milliSecond);
    }
    wstring ret;
    ret.append((hou.empty() ? L"" : hou + L"小时") + (min.empty() ? L"" : min + L"") + (sec.empty() ? L"" : sec + L"") + (msec.empty() ? L"" : msec + L""));
    return ret;
}
 
wstring 取现行时间()
{
    SYSTEMTIME 时间结构;
    GetLocalTime(&时间结构);
    wstring 年 = to_wstring(时间结构.wYear);
    wstring 月 = to_wstring(时间结构.wMonth);
    wstring 日 = to_wstring(时间结构.wDay);
    wstring 星期;
    if (时间结构.wDayOfWeek == 0) 星期 = L"星期日";
    if (时间结构.wDayOfWeek == 1) 星期 = L"星期一";
    if (时间结构.wDayOfWeek == 2) 星期 = L"星期二";
    if (时间结构.wDayOfWeek == 3) 星期 = L"星期三";
    if (时间结构.wDayOfWeek == 4) 星期 = L"星期四";
    if (时间结构.wDayOfWeek == 5) 星期 = L"星期五";
    if (时间结构.wDayOfWeek == 6) 星期 = L"星期六";
 
    wstring 时 = to_wstring(时间结构.wHour);
    if (时间结构.wHour < 10) 时 = L"0" + to_wstring(时间结构.wHour);
 
    wstring 分 = to_wstring(时间结构.wMinute);
    if (时间结构.wMinute < 10) 分 = L"0" + to_wstring(时间结构.wMinute);
 
    wstring 秒 = to_wstring(时间结构.wSecond);
    if (时间结构.wSecond < 10) 秒 = L"0" + to_wstring(时间结构.wSecond);
 
    wstring 毫秒 = to_wstring(时间结构.wMilliseconds);
 
    return + L"年" + + L"月" + + L"日 " + + L":" + + L":" + 秒;
}
 
 
INT64 读偏移型(INT64 address, vector<int> vec)
{
    INT64 tempaddress;
    tempaddress = address;
    for (size_t i = 0; i < vec.size(); ++i)
    {
        tempaddress = 读写_读长整数(tempaddress);
        tempaddress = tempaddress + vec.at(i);
    }
    return tempaddress;
}
 
 
 
double   读写_读小数型(ULONG64 参_内存地址)
{
    if (IsBadReadPtr((VOID*)参_内存地址, 8))
    {
        return 0;
    }
    return *(double*)参_内存地址;
}
 
DWORD    读写_读整数型(ULONG64 参_内存地址)
{
    if (IsBadReadPtr((VOID*)参_内存地址, 4))
    {
        return 0;
    }
    return *(DWORD*)参_内存地址;
}
 
ULONG64  读写_读长整数(ULONG64 参_内存地址)
{
    if (IsBadReadPtr((VOID*)参_内存地址, 8))
    {
        return 0;
    }
    return *(ULONG64*)参_内存地址;
}
 
BYTE     读写_读字节型(ULONG64 参_内存地址)
{
    if (IsBadReadPtr((VOID*)参_内存地址, 1))
    {
        return 0;
    }
    return *(BYTE*)参_内存地址;
}
 
ULONG64     读写_读短整数(ULONG64 参_内存地址)
{
    if (IsBadReadPtr((VOID*)参_内存地址, 2))
    {
        return 0;
    }
    return *(ULONG64*)参_内存地址;
}
 
vector<BYTE> 读写_读字节集(ULONG64 参_内存地址, DWORD 参_读取长度)
{
    vector<BYTE> 局_返回值;
    if (IsBadReadPtr((VOID*)参_内存地址, 参_读取长度))
    {
        return {};
    }
    for (int i = 0; i < 参_读取长度; i++)
    {
        局_返回值.insert(局_返回值.end(), *(BYTE*)参_内存地址++);
    }
    return 局_返回值;
 
}
 
VOID 读写_写长整数(ULONG64 参_内存地址, ULONG64 参_写入数据)
{
    if (IsBadReadPtr((VOID*)参_内存地址, 8))
    {
        return;
    }
    DWORD old_protect;
    VirtualProtect((LPVOID)参_内存地址, 8, 64, &old_protect);
    *(ULONG64*)参_内存地址 = 参_写入数据;
    VirtualProtect((LPVOID)参_内存地址, 8, old_protect, &old_protect);
}
 
VOID 读写_写字节型(ULONG64 参_内存地址, BYTE 参_写入数据)
{
    if (IsBadReadPtr((VOID*)参_内存地址, 4))
    {
        return;
    }
    DWORD old_protect;
    VirtualProtect((LPVOID)参_内存地址, 1, 64, &old_protect);
    *(BYTE*)参_内存地址 = 参_写入数据;
    VirtualProtect((LPVOID)参_内存地址, 1, old_protect, &old_protect);
}
 
VOID 读写_写整数型(ULONG64 参_内存地址, DWORD 参_写入数据)
{
    if (IsBadReadPtr((VOID*)参_内存地址, 4))
    {
        return;
    }
    DWORD old_protect;
    VirtualProtect((LPVOID)参_内存地址, 4, 64, &old_protect);
    *(DWORD*)参_内存地址 = 参_写入数据;
    VirtualProtect((LPVOID)参_内存地址, 4, old_protect, &old_protect);
}
 
VOID 读写_写小数型(ULONG64 参_内存地址, float 参_写入数据)
{
    if (IsBadReadPtr((VOID*)参_内存地址, 4))
    {
        return;
    }
    DWORD old_protect;
    VirtualProtect((LPVOID)参_内存地址, 4, 64, &old_protect);
    *(float*)参_内存地址 = 参_写入数据;
    VirtualProtect((LPVOID)参_内存地址, 4, old_protect, &old_protect);
}
 
VOID 读写_写字节集(ULONG64 参_内存地址, vector<BYTE> 参_写入数据)
{
    if (IsBadReadPtr((VOID*)参_内存地址, 1))
    {
        return;
    }
    DWORD old_protect;
    VirtualProtect((LPVOID)参_内存地址, 参_写入数据.size(), 64, &old_protect);//修改内存属性
    for (size_t i = 0; i < 参_写入数据.size(); i++)
    {
        *(BYTE*)参_内存地址++ = 参_写入数据[i];
    }
    VirtualProtect((LPVOID)参_内存地址, 参_写入数据.size(), old_protect, &old_protect);//还原内存属性
}
 
VOID 读写_写短整数(ULONG64 参_内存地址, WORD 参_写入数据)
{
    if (IsBadReadPtr((VOID*)参_内存地址, 4))
    {
        return;
    }
    DWORD old_protect;
    VirtualProtect((LPVOID)参_内存地址, 4, 64, &old_protect);
    *(WORD*)参_内存地址 = 参_写入数据;
    VirtualProtect((LPVOID)参_内存地址, 4, old_protect, &old_protect);
}
 
wstring 整数到文本(DWORD 参_数值)
{
    wstring 局_返回值;
    WCHAR 局_缓冲区[10] = { 0 };
    _itow_s(参_数值, 局_缓冲区, 10);
    局_返回值 = 局_缓冲区;
    return 局_返回值;
}
 
wstring  长整数到文本(ULONG64 参_数值)
{
    wstring 局_返回值;
    WCHAR 局_缓冲区[30] = { 0 };
    _i64tow_s(参_数值, 局_缓冲区, 30, 10);
    局_返回值 = 局_缓冲区;
    return 局_返回值;
}
 
wstring  长整数到十六进制(ULONG64 参_数值)
{
    wstring 局_返回值;
    WCHAR 局_缓冲区[30] = { 0 };
    _i64tow_s(参_数值, 局_缓冲区, 30, 16);
    wstring 局_临时文本 = 局_缓冲区;
    transform(局_临时文本.begin(), 局_临时文本.end(), back_inserter(局_返回值), toupper);
    return 局_返回值;
}
 
wstring Unicode转Ansi(vector<BYTE> 参_字节集)
{
    DWORD 局_字节长度 = 参_字节集.size();
    CHAR* 局_Unicode = new CHAR[局_字节长度];
    for (size_t i = 0; i < 局_字节长度; i++)
    {
        局_Unicode[i] = 参_字节集[i];
    }
    //UniCode到Ansi
    DWORD 局_计数 = WideCharToMultiByte(936, 512, (LPCWCH)局_Unicode, -1, 0, 0, 0, FALSE);
    CHAR* 缓冲区 = new CHAR[局_计数];
    WideCharToMultiByte(936, 512, (LPCWCH)局_Unicode, -1, 缓冲区, 局_计数, NULL, NULL);
 
    // string转wstring
    DWORD nLen = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, 缓冲区, -1, NULL, 0);
    if (nLen == 0)
    {
        return NULL;
    }
    WCHAR* pResult = new WCHAR[nLen];
    MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, 缓冲区, -1, pResult, nLen);
 
    return pResult;
}

[培训]二进制漏洞攻防(第3期);满10人开班;模糊测试与工具使用二次开发;网络协议漏洞挖掘;Linux内核漏洞挖掘与利用;AOSP漏洞挖掘与利用;代码审计。

收藏
点赞1
打赏
分享
最新回复 (11)
雪    币: 6514
活跃值: (3037)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
sinkay 2023-1-6 10:20
2
2
还不如直接贴易语言 
雪    币: 21
能力值: ( LV1,RANK:0 )
在线值:
发帖
回帖
粉丝
爱吃奥里给 2023-1-17 11:08
3
0

学习了

最后于 2023-1-17 11:08 被爱吃奥里给编辑 ,原因:
雪    币: 247
活跃值: (213317)
能力值: ( LV4,RANK:40 )
在线值:
发帖
回帖
粉丝
shinratensei 1 2023-1-17 11:14
4
0
BIgHand
雪    币: 354
活跃值: (2202)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
Kaining 2023-1-17 11:37
5
0
我TM一看就知道DXF
雪    币: 1655
活跃值: (4280)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
Oxygen1a1 2023-1-17 12:06
6
0
shinratensei BIgHand
戳啦,是BigHands
雪    币: 2
活跃值: (925)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
Hell02W0rld 2023-1-17 13:01
7
0
中文确实骚
雪    币: 93
活跃值: (1483)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
wumnkx 2023-1-17 16:48
8
0
会说话的代码,是真的自解释,优雅
雪    币: 9939
活跃值: (2138)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
VCKFC 2023-1-18 09:05
9
0
使用C++多年,我觉得真的很好, 不然都去学易语言了
雪    币: 231
活跃值: (2261)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
hambaga 2023-1-18 11:20
10
0
unbengable。。。大手指转行c++了
雪    币: 6124
活跃值: (4041)
能力值: ( LV6,RANK:80 )
在线值:
发帖
回帖
粉丝
黑洛 1 2023-1-18 14:41
11
0
好浓的易语言味儿
雪    币: 4119
活跃值: (1500)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
Boring勇哥 2023-1-19 16:25
12
0
易言丁真
游客
登录 | 注册 方可回帖
返回