Skip to content

Commit 24a7a6d

Browse files
author
Dan Dees
committed
test.cpp - add error checks
1 parent 370515d commit 24a7a6d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

test/test.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ PVOID ReadDllFile2(LPCSTR FileName) {
6565
}
6666

6767
int test() {
68-
LPVOID buffer = ReadDllFile2("a.dll");
6968

7069
HMODULE hModule = nullptr;
7170
FARPROC pfn = nullptr;
@@ -77,7 +76,16 @@ int test() {
7776
HGLOBAL gRes;
7877
char str[10];
7978

80-
if (!NT_SUCCESS(LdrLoadDllMemoryExW(&hModule, nullptr, 0, buffer, 0, L"kernel64", nullptr))) goto end;
79+
LPVOID buffer = ReadDllFile2("a.dll");
80+
if ( !buffer ) {
81+
printf("failed to find a.dll.\n");
82+
goto end;
83+
}
84+
85+
if (!NT_SUCCESS(LdrLoadDllMemoryExW(&hModule, nullptr, 0, buffer, 0, L"kernel64", nullptr))) {
86+
printf("LdrLoadDllMemoryExW failed.\n");
87+
goto end;
88+
}
8189

8290
//forward export
8391
pfn = (decltype(pfn))(GetProcAddress(hModule, "Socket")); //ws2_32.WSASocketW

0 commit comments

Comments
 (0)