forked from xiaoma99272/ShellcodeLoader-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.h
More file actions
124 lines (105 loc) · 2.37 KB
/
main.h
File metadata and controls
124 lines (105 loc) · 2.37 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
#pragma once
#include<windows.h>
#include<stdio.h>
#define DATA_SIZE 27136
typedef struct
{
DWORD size;
PBYTE ptrbuffer;
}FILEINFO;
FILEINFO Openfile(char* ptrFile)
{
DWORD dwReadTotal = 0;
DWORD dwReaded = 0;
FILEINFO fileinfo = { 0 };
HANDLE hFile = NULL;
hFile = CreateFileA(ptrFile,
FILE_SHARE_READ,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (hFile == INVALID_HANDLE_VALUE)
goto END;
fileinfo.size = GetFileSize(hFile, NULL);
if (fileinfo.size == 0)
goto END;
fileinfo.ptrbuffer = (byte*)HeapAlloc(GetProcessHeap(), 0, fileinfo.size);
if (fileinfo.ptrbuffer == 0)
goto END;
SecureZeroMemory(fileinfo.ptrbuffer, fileinfo.size);
while (dwReadTotal < fileinfo.size
&& ReadFile(hFile, fileinfo.ptrbuffer + dwReadTotal, fileinfo.size - dwReadTotal, &dwReaded, NULL))
{
dwReadTotal += dwReaded;
}
END:
if (hFile != INVALID_HANDLE_VALUE)
{
CloseHandle(hFile);
}
return fileinfo;
};
void* __cdecl Mymemcpy(void* dest,
const void* src,
size_t count
)
{
char* char_dest = (char*)dest;
char* char_src = (char*)src;
if ((char_dest <= char_src) || (char_dest >= (char_src + count)))
{
/* non-overlapping buffers */
while (count > 0)
{
*char_dest = *char_src;
char_dest++;
char_src++;
count--;
}
}
else
{
/* overlaping buffers */
char_dest = (char*)dest + count - 1;
char_src = (char*)src + count - 1;
while (count > 0)
{
*char_dest = *char_src;
char_dest--;
char_src--;
count--;
}
}
return dest;
}
BOOL Write2file(PBYTE file, DWORD contentLen, PCHAR path)//写入文件,测试通过
{
HANDLE pFile;
PBYTE tmpBuf = nullptr;
DWORD dwBytesWrite, dwBytesToWrite;
pFile = CreateFileA(path, GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS, //总是创建文件
FILE_ATTRIBUTE_NORMAL,
NULL);
if (pFile == INVALID_HANDLE_VALUE)
{
CloseHandle(pFile);
HeapFree(GetProcessHeap(), 0, file);
return FALSE;
}
dwBytesToWrite = contentLen;
dwBytesWrite = 0;
tmpBuf = file;
do { //循环写文件,确保完整的文件被写入
WriteFile(pFile, tmpBuf, dwBytesToWrite, &dwBytesWrite, NULL);
dwBytesToWrite -= dwBytesWrite;
tmpBuf += dwBytesWrite;
} while (dwBytesToWrite > 0);
CloseHandle(pFile);
HeapFree(GetProcessHeap(), 0, file);
return TRUE;
}