Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/imagehlp/tests/Makefile.in | 1 + dlls/imagehlp/tests/image.c | 67 +++++-------------------- dlls/imagehlp/tests/integrity.c | 88 +++++++++------------------------ 3 files changed, 35 insertions(+), 121 deletions(-)
diff --git a/dlls/imagehlp/tests/Makefile.in b/dlls/imagehlp/tests/Makefile.in index 6c784401e99..43b434f690a 100644 --- a/dlls/imagehlp/tests/Makefile.in +++ b/dlls/imagehlp/tests/Makefile.in @@ -1,4 +1,5 @@ TESTDLL = imagehlp.dll +IMPORTS = imagehlp psapi
C_SRCS = \ image.c \ diff --git a/dlls/imagehlp/tests/image.c b/dlls/imagehlp/tests/image.c index 875d919bb75..c8d1a520c96 100644 --- a/dlls/imagehlp/tests/image.c +++ b/dlls/imagehlp/tests/image.c @@ -28,16 +28,6 @@
#include "wine/test.h"
-static HMODULE hImageHlp; - -static BOOL (WINAPI *pImageGetDigestStream)(HANDLE, DWORD, DIGEST_FUNCTION, DIGEST_HANDLE); -static BOOL (WINAPI *pBindImageEx)(DWORD Flags, const char *ImageName, const char *DllPath, - const char *SymbolPath, PIMAGEHLP_STATUS_ROUTINE StatusRoutine); -static DWORD (WINAPI *pGetImageUnusedHeaderBytes)(PLOADED_IMAGE, LPDWORD); -static PLOADED_IMAGE (WINAPI *pImageLoad)(PCSTR, PCSTR); -static BOOL (WINAPI *pImageUnload)(PLOADED_IMAGE); - - /* minimal PE file image */ #define VA_START 0x400000 #define FILE_PE_START 0x50 @@ -322,13 +312,8 @@ static void test_get_digest_stream(void) DWORD count; struct update_accum accum = { 0, NULL };
- if (!pImageGetDigestStream) - { - win_skip("ImageGetDigestStream function is not available\n"); - return; - } SetLastError(0xdeadbeef); - ret = pImageGetDigestStream(NULL, 0, NULL, NULL); + ret = ImageGetDigestStream(NULL, 0, NULL, NULL); ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); file = create_temp_file(temp_file); @@ -338,16 +323,16 @@ static void test_get_digest_stream(void) return; } SetLastError(0xdeadbeef); - ret = pImageGetDigestStream(file, 0, NULL, NULL); + ret = ImageGetDigestStream(file, 0, NULL, NULL); ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); SetLastError(0xdeadbeef); - ret = pImageGetDigestStream(NULL, 0, accumulating_stream_output, &accum); + ret = ImageGetDigestStream(NULL, 0, accumulating_stream_output, &accum); ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); /* Even with "valid" parameters, it fails with an empty file */ SetLastError(0xdeadbeef); - ret = pImageGetDigestStream(file, 0, accumulating_stream_output, &accum); + ret = ImageGetDigestStream(file, 0, accumulating_stream_output, &accum); ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); /* Finally, with a valid executable in the file, it succeeds. Note that @@ -362,11 +347,11 @@ static void test_get_digest_stream(void) bin.nt_headers.OptionalHeader.SizeOfInitializedData = 0; bin.nt_headers.OptionalHeader.SizeOfImage = 0;
- ret = pImageGetDigestStream(file, 0, accumulating_stream_output, &accum); + ret = ImageGetDigestStream(file, 0, accumulating_stream_output, &accum); ok(ret, "ImageGetDigestStream failed: %d\n", GetLastError()); check_updates("flags = 0", &a1, &accum); free_updates(&accum); - ret = pImageGetDigestStream(file, CERT_PE_IMAGE_DIGEST_ALL_IMPORT_INFO, + ret = ImageGetDigestStream(file, CERT_PE_IMAGE_DIGEST_ALL_IMPORT_INFO, accumulating_stream_output, &accum); ok(ret, "ImageGetDigestStream failed: %d\n", GetLastError()); check_updates("flags = CERT_PE_IMAGE_DIGEST_ALL_IMPORT_INFO", &a2, &accum); @@ -382,15 +367,9 @@ static void test_bind_image_ex(void) char temp_file[MAX_PATH]; DWORD count;
- if (!pBindImageEx) - { - win_skip("BindImageEx function is not available\n"); - return; - } - /* call with a non-existent file */ SetLastError(0xdeadbeef); - ret = pBindImageEx(BIND_NO_BOUND_IMPORTS | BIND_NO_UPDATE | BIND_ALL_IMAGES, "nonexistent.dll", 0, 0, + ret = BindImageEx(BIND_NO_BOUND_IMPORTS | BIND_NO_UPDATE | BIND_ALL_IMAGES, "nonexistent.dll", 0, 0, testing_status_routine); todo_wine ok(!ret && ((GetLastError() == ERROR_FILE_NOT_FOUND) || (GetLastError() == ERROR_INVALID_PARAMETER)), @@ -408,12 +387,12 @@ static void test_bind_image_ex(void) CloseHandle(file);
/* call with a proper PE file, but with StatusRoutine set to NULL */ - ret = pBindImageEx(BIND_NO_BOUND_IMPORTS | BIND_NO_UPDATE | BIND_ALL_IMAGES, temp_file, 0, 0, + ret = BindImageEx(BIND_NO_BOUND_IMPORTS | BIND_NO_UPDATE | BIND_ALL_IMAGES, temp_file, 0, 0, NULL); ok(ret, "BindImageEx failed: %d\n", GetLastError());
/* call with a proper PE file and StatusRoutine */ - ret = pBindImageEx(BIND_NO_BOUND_IMPORTS | BIND_NO_UPDATE | BIND_ALL_IMAGES, temp_file, 0, 0, + ret = BindImageEx(BIND_NO_BOUND_IMPORTS | BIND_NO_UPDATE | BIND_ALL_IMAGES, temp_file, 0, 0, testing_status_routine); ok(ret, "BindImageEx failed: %d\n", GetLastError());
@@ -436,12 +415,6 @@ static void test_image_load(void) DWORD ret, count; HANDLE file;
- if (!pImageLoad || !pImageUnload || !pGetImageUnusedHeaderBytes) - { - win_skip("ImageLoad functions are not available\n"); - return; - } - file = create_temp_file(temp_file); if (file == INVALID_HANDLE_VALUE) { @@ -452,7 +425,7 @@ static void test_image_load(void) WriteFile(file, &bin, sizeof(bin), &count, NULL); CloseHandle(file);
- img = pImageLoad(temp_file, NULL); + img = ImageLoad(temp_file, NULL); ok(img != NULL, "ImageLoad unexpectedly failed\n");
if (img) @@ -499,13 +472,13 @@ static void test_image_load(void) "unexpected SizeOfImage, got 0x%x instead of 0x600\n", img->SizeOfImage);
count = 0xdeadbeef; - ret = pGetImageUnusedHeaderBytes(img, &count); + ret = GetImageUnusedHeaderBytes(img, &count); todo_wine ok(ret == 448, "GetImageUnusedHeaderBytes returned %u instead of 448\n", ret); todo_wine ok(count == 64, "unexpected size for unused header bytes, got %u instead of 64\n", count);
- pImageUnload(img); + ImageUnload(img); }
DeleteFileA(temp_file); @@ -513,23 +486,7 @@ static void test_image_load(void)
START_TEST(image) { - hImageHlp = LoadLibraryA("imagehlp.dll"); - - if (!hImageHlp) - { - win_skip("ImageHlp unavailable\n"); - return; - } - - pImageGetDigestStream = (void *) GetProcAddress(hImageHlp, "ImageGetDigestStream"); - pBindImageEx = (void *) GetProcAddress(hImageHlp, "BindImageEx"); - pGetImageUnusedHeaderBytes = (void *) GetProcAddress(hImageHlp, "GetImageUnusedHeaderBytes"); - pImageLoad = (void *) GetProcAddress(hImageHlp, "ImageLoad"); - pImageUnload = (void *) GetProcAddress(hImageHlp, "ImageUnload"); - test_get_digest_stream(); test_bind_image_ex(); test_image_load(); - - FreeLibrary(hImageHlp); } diff --git a/dlls/imagehlp/tests/integrity.c b/dlls/imagehlp/tests/integrity.c index 3b85c6a3a29..6d820fa0b1d 100644 --- a/dlls/imagehlp/tests/integrity.c +++ b/dlls/imagehlp/tests/integrity.c @@ -26,20 +26,12 @@ #include "winerror.h" #include "winnt.h" #include "imagehlp.h" +#define PSAPI_VERSION 1 #include "psapi.h"
-static HMODULE hImageHlp, hPsapi, hNtdll; +static HMODULE hNtdll; static char test_dll_path[MAX_PATH];
-static BOOL (WINAPI *pImageAddCertificate)(HANDLE, LPWIN_CERTIFICATE, PDWORD); -static BOOL (WINAPI *pImageEnumerateCertificates)(HANDLE, WORD, PDWORD, PDWORD, DWORD); -static BOOL (WINAPI *pImageGetCertificateData)(HANDLE, DWORD, LPWIN_CERTIFICATE, PDWORD); -static BOOL (WINAPI *pImageGetCertificateHeader)(HANDLE, DWORD, LPWIN_CERTIFICATE); -static BOOL (WINAPI *pImageRemoveCertificate)(HANDLE, DWORD); -static PIMAGE_NT_HEADERS (WINAPI *pCheckSumMappedFile)(PVOID, DWORD, PDWORD, PDWORD); - -static BOOL (WINAPI *pGetModuleInformation)(HANDLE, HMODULE, LPMODULEINFO, DWORD); - static PIMAGE_NT_HEADERS (WINAPI *pRtlImageNtHeader)(PVOID);
static const char test_cert_data[] = @@ -193,7 +185,7 @@ static DWORD test_add_certificate(const char *cert_data, int len) cert->wCertificateType = WIN_CERT_TYPE_PKCS_SIGNED_DATA; CopyMemory(cert->bCertificate, cert_data, len);
- ret = pImageAddCertificate(hFile, cert, &index); + ret = ImageAddCertificate(hFile, cert, &index); ok(ret, "Unable to add certificate to image, error %x\n", GetLastError()); trace("added cert index %d\n", index);
@@ -218,7 +210,7 @@ static void test_get_certificate(const char *cert_data, int index) return; }
- ret = pImageGetCertificateData(hFile, index, NULL, &cert_len); + ret = ImageGetCertificateData(hFile, index, NULL, &cert_len); err = GetLastError();
ok ((ret == FALSE) && (err == ERROR_INSUFFICIENT_BUFFER), "ImageGetCertificateData gave unexpected result; ret=%d / err=%x\n", ret, err); @@ -232,7 +224,7 @@ static void test_get_certificate(const char *cert_data, int index) return; }
- ret = pImageGetCertificateData(hFile, index, cert, &cert_len); + ret = ImageGetCertificateData(hFile, index, cert, &cert_len); ok(ret, "Unable to retrieve certificate; err=%x\n", GetLastError()); ok(memcmp(cert->bCertificate, cert_data, cert_len - sizeof(WIN_CERTIFICATE)) == 0, "Certificate retrieved did not match original\n");
@@ -254,13 +246,13 @@ static void test_remove_certificate(int index) return; }
- ret = pImageEnumerateCertificates(hFile, CERT_SECTION_TYPE_ANY, &orig_count, NULL, 0); + ret = ImageEnumerateCertificates(hFile, CERT_SECTION_TYPE_ANY, &orig_count, NULL, 0); ok (ret, "Unable to enumerate certificates in file; err=%x\n", GetLastError()); - ret = pImageRemoveCertificate(hFile, index); + ret = ImageRemoveCertificate(hFile, index); ok (ret, "Unable to remove certificate from file; err=%x\n", GetLastError());
/* Test to see if the certificate has actually been removed */ - pImageEnumerateCertificates(hFile, CERT_SECTION_TYPE_ANY, &count, NULL, 0); + ImageEnumerateCertificates(hFile, CERT_SECTION_TYPE_ANY, &count, NULL, 0); ok (count == orig_count - 1, "Certificate count mismatch; orig=%d new=%d\n", orig_count, count);
CloseHandle(hFile); @@ -275,20 +267,14 @@ static void test_pe_checksum(void) char buffer[20]; BOOL ret_bool;
- if (!pCheckSumMappedFile) - { - win_skip("CheckSumMappedFile not supported, skipping tests\n"); - return; - } - SetLastError(0xdeadbeef); - ret = pCheckSumMappedFile(NULL, 0, &checksum_orig, &checksum_new); + ret = CheckSumMappedFile(NULL, 0, &checksum_orig, &checksum_new); ok(!ret, "Expected CheckSumMappedFile to fail, got %p\n", ret); ok(((GetLastError() == ERROR_INVALID_PARAMETER)||(GetLastError() == 0xdeadbeef)), "Expected 0xdeadbeef (XP) or ERROR_INVALID_PARAMETER (Vista+), got %x\n", GetLastError());
SetLastError(0xdeadbeef); - ret = pCheckSumMappedFile((void *)0xdeadbeef, 0, &checksum_orig, &checksum_new); + ret = CheckSumMappedFile((void *)0xdeadbeef, 0, &checksum_orig, &checksum_new); ok(!ret, "Expected CheckSumMappedFile to fail, got %p\n", ret); ok(((GetLastError() == ERROR_INVALID_PARAMETER)||(GetLastError() == 0xdeadbeef)), "Expected 0xdeadbeef (XP) or ERROR_INVALID_PARAMETER (Vista+), got %x\n", GetLastError()); @@ -296,53 +282,47 @@ static void test_pe_checksum(void) /* basic checksum tests */ memset(buffer, 0x11, sizeof(buffer)); checksum_orig = checksum_new = 0xdeadbeef; - ret = pCheckSumMappedFile(buffer, sizeof(buffer), &checksum_orig, &checksum_new); + ret = CheckSumMappedFile(buffer, sizeof(buffer), &checksum_orig, &checksum_new); ok(ret == NULL, "Expected NULL, got %p\n", ret); todo_wine ok(checksum_orig == 0, "Expected 0, got %x\n", checksum_orig); todo_wine ok(checksum_new == 0xaabe, "Expected 0xaabe, got %x\n", checksum_new);
memset(buffer, 0x22, sizeof(buffer)); checksum_orig = checksum_new = 0xdeadbeef; - ret = pCheckSumMappedFile(buffer, sizeof(buffer), &checksum_orig, &checksum_new); + ret = CheckSumMappedFile(buffer, sizeof(buffer), &checksum_orig, &checksum_new); ok(ret == NULL, "Expected NULL, got %p\n", ret); todo_wine ok(checksum_orig == 0, "Expected 0, got %x\n", checksum_orig); todo_wine ok(checksum_new == 0x5569, "Expected 0x5569, got %x\n", checksum_new);
memset(buffer, 0x22, sizeof(buffer)); checksum_orig = checksum_new = 0xdeadbeef; - ret = pCheckSumMappedFile(buffer, 10, &checksum_orig, &checksum_new); + ret = CheckSumMappedFile(buffer, 10, &checksum_orig, &checksum_new); ok(ret == NULL, "Expected NULL, got %p\n", ret); todo_wine ok(checksum_orig == 0, "Expected 0, got %x\n", checksum_orig); todo_wine ok(checksum_new == 0xaab4, "Expected 0xaab4, got %x\n", checksum_new);
memset(buffer, 0x22, sizeof(buffer)); checksum_orig = checksum_new = 0xdeadbeef; - ret = pCheckSumMappedFile(buffer, 11, &checksum_orig, &checksum_new); + ret = CheckSumMappedFile(buffer, 11, &checksum_orig, &checksum_new); ok(ret == NULL, "Expected NULL, got %p\n", ret); todo_wine ok(checksum_orig == 0, "Expected 0, got %x\n", checksum_orig); todo_wine ok(checksum_new == 0xaad7, "Expected 0xaad7, got %x\n", checksum_new);
/* test checksum of PE module */ checksum_orig = checksum_new = 0xdeadbeef; - ret = pCheckSumMappedFile(test_pe_executable, sizeof(test_pe_executable), + ret = CheckSumMappedFile(test_pe_executable, sizeof(test_pe_executable), &checksum_orig, &checksum_new); ok((char *)ret == test_pe_executable + 0x80, "Expected %p, got %p\n", test_pe_executable + 0x80, ret); ok(checksum_orig == 0xabcdef11, "Expected 0xabcdef11, got %x\n", checksum_orig); ok(checksum_new == 0xaa4, "Expected 0xaa4, got %x\n", checksum_new);
- if (!pGetModuleInformation) - { - win_skip("GetModuleInformation not supported, skipping tests\n"); - return; - } - - ret_bool = pGetModuleInformation(GetCurrentProcess(), GetModuleHandleA(NULL), + ret_bool = GetModuleInformation(GetCurrentProcess(), GetModuleHandleA(NULL), &modinfo, sizeof(modinfo)); ok(ret_bool, "GetModuleInformation failed, error: %x\n", GetLastError());
SetLastError(0xdeadbeef); checksum_orig = checksum_new = 0xdeadbeef; - ret = pCheckSumMappedFile(modinfo.lpBaseOfDll, modinfo.SizeOfImage, &checksum_orig, &checksum_new); + ret = CheckSumMappedFile(modinfo.lpBaseOfDll, modinfo.SizeOfImage, &checksum_orig, &checksum_new); ok(ret != NULL, "Expected CheckSumMappedFile to succeed\n"); ok(GetLastError() == 0xdeadbeef, "Expected err=0xdeadbeef, got %x\n", GetLastError()); ok(checksum_orig != 0xdeadbeef, "Expected orig checksum != 0xdeadbeef\n"); @@ -350,7 +330,7 @@ static void test_pe_checksum(void)
SetLastError(0xdeadbeef); checksum_orig = checksum_new = 0xdeadbeef; - ret = pCheckSumMappedFile((char *)modinfo.lpBaseOfDll + 100, modinfo.SizeOfImage - 100, + ret = CheckSumMappedFile((char *)modinfo.lpBaseOfDll + 100, modinfo.SizeOfImage - 100, &checksum_orig, &checksum_new); ok(!ret, "Expected CheckSumMappedFile to fail, got %p\n", ret); ok(GetLastError() == 0xdeadbeef, "Expected err=0xdeadbeef, got %x\n", GetLastError()); @@ -361,27 +341,27 @@ static void test_pe_checksum(void) checksum_correct = nt_header->OptionalHeader.CheckSum;
checksum_orig = checksum_new = 0xdeadbeef; - ret = pCheckSumMappedFile(modinfo.lpBaseOfDll, (char *)nt_header - (char *)modinfo.lpBaseOfDll, + ret = CheckSumMappedFile(modinfo.lpBaseOfDll, (char *)nt_header - (char *)modinfo.lpBaseOfDll, &checksum_orig, &checksum_new); ok(!ret || (ret == nt_header), "Expected CheckSumMappedFile to fail, got %p\n", ret); ok((checksum_orig == 0) || (checksum_orig == checksum_correct), "Expected %x, got %x\n", checksum_correct, checksum_orig); ok(checksum_new != 0 && checksum_new != 0xdeadbeef, "Got unexpected value %x\n", checksum_new);
checksum_orig = checksum_new = 0xdeadbeef; - ret = pCheckSumMappedFile(modinfo.lpBaseOfDll, sizeof(IMAGE_DOS_HEADER), + ret = CheckSumMappedFile(modinfo.lpBaseOfDll, sizeof(IMAGE_DOS_HEADER), &checksum_orig, &checksum_new); ok(!ret || (ret == nt_header), "Expected CheckSumMappedFile to fail, got %p\n", ret); ok((checksum_orig == 0) || (checksum_orig == checksum_correct), "Expected %x, got %x\n", checksum_correct, checksum_orig); ok(checksum_new != 0 && checksum_new != 0xdeadbeef, "Got unexpected value %x\n", checksum_new);
checksum_orig = checksum_new = 0xdeadbeef; - ret = pCheckSumMappedFile(modinfo.lpBaseOfDll, 0, &checksum_orig, &checksum_new); + ret = CheckSumMappedFile(modinfo.lpBaseOfDll, 0, &checksum_orig, &checksum_new); ok(!ret || (ret == nt_header), "Expected CheckSumMappedFile to fail, got %p\n", ret); ok((checksum_orig == 0xdeadbeef) || (checksum_orig == checksum_correct), "Expected %x, got %x\n", checksum_correct, checksum_orig); ok((checksum_new == 0xdeadbeef) || (checksum_new != 0 && checksum_new != 0xdeadbeef), "Got unexpected value %x\n", checksum_new);
checksum_orig = checksum_new = 0xdeadbeef; - ret = pCheckSumMappedFile((char *)modinfo.lpBaseOfDll + 1, 0, + ret = CheckSumMappedFile((char *)modinfo.lpBaseOfDll + 1, 0, &checksum_orig, &checksum_new); ok(ret == NULL, "Expected NULL, got %p\n", ret); ok((checksum_orig == 0) || (checksum_orig == 0xdeadbeef), "Expected 0, got %x\n", checksum_orig); @@ -392,33 +372,11 @@ START_TEST(integrity) { DWORD file_size, file_size_orig, first, second;
- hImageHlp = LoadLibraryA("imagehlp.dll"); - - if (!hImageHlp) - { - win_skip("ImageHlp unavailable\n"); - return; - } - if (!copy_dll_file()) - { - FreeLibrary(hImageHlp); return; - }
file_size_orig = get_file_size();
- pImageAddCertificate = (void *) GetProcAddress(hImageHlp, "ImageAddCertificate"); - pImageEnumerateCertificates = (void *) GetProcAddress(hImageHlp, "ImageEnumerateCertificates"); - pImageGetCertificateData = (void *) GetProcAddress(hImageHlp, "ImageGetCertificateData"); - pImageGetCertificateHeader = (void *) GetProcAddress(hImageHlp, "ImageGetCertificateHeader"); - pImageRemoveCertificate = (void *) GetProcAddress(hImageHlp, "ImageRemoveCertificate"); - pCheckSumMappedFile = (void *) GetProcAddress(hImageHlp, "CheckSumMappedFile"); - - hPsapi = LoadLibraryA("psapi.dll"); - if (hPsapi) - pGetModuleInformation = (void *) GetProcAddress(hPsapi, "GetModuleInformation"); - hNtdll = LoadLibraryA("ntdll.dll"); if (hNtdll) pRtlImageNtHeader = (void *) GetProcAddress(hNtdll, "RtlImageNtHeader"); @@ -450,8 +408,6 @@ START_TEST(integrity)
test_pe_checksum();
- if (hPsapi) FreeLibrary(hPsapi); if (hNtdll) FreeLibrary(hNtdll); - FreeLibrary(hImageHlp); DeleteFileA(test_dll_path); }
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/imagehlp/tests/integrity.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/dlls/imagehlp/tests/integrity.c b/dlls/imagehlp/tests/integrity.c index 6d820fa0b1d..fbe40995f2f 100644 --- a/dlls/imagehlp/tests/integrity.c +++ b/dlls/imagehlp/tests/integrity.c @@ -29,11 +29,8 @@ #define PSAPI_VERSION 1 #include "psapi.h"
-static HMODULE hNtdll; static char test_dll_path[MAX_PATH];
-static PIMAGE_NT_HEADERS (WINAPI *pRtlImageNtHeader)(PVOID); - static const char test_cert_data[] = {0x30,0x82,0x02,0xE1,0x06,0x09,0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x02 ,0xA0,0x82,0x02,0xD2,0x30,0x82,0x02,0xCE,0x02,0x01,0x01,0x31,0x00,0x30,0x0B @@ -337,7 +334,7 @@ static void test_pe_checksum(void) todo_wine ok(checksum_orig == 0, "Expected 0, got %x\n", checksum_orig); todo_wine ok(checksum_new != 0 && checksum_new != 0xdeadbeef, "Got unexpected value %x\n", checksum_new);
- nt_header = pRtlImageNtHeader( modinfo.lpBaseOfDll ); + nt_header = ImageNtHeader( modinfo.lpBaseOfDll ); checksum_correct = nt_header->OptionalHeader.CheckSum;
checksum_orig = checksum_new = 0xdeadbeef; @@ -377,10 +374,6 @@ START_TEST(integrity)
file_size_orig = get_file_size();
- hNtdll = LoadLibraryA("ntdll.dll"); - if (hNtdll) - pRtlImageNtHeader = (void *) GetProcAddress(hNtdll, "RtlImageNtHeader"); - first = test_add_certificate(test_cert_data, sizeof(test_cert_data)); test_get_certificate(test_cert_data, first); test_remove_certificate(first); @@ -408,6 +401,5 @@ START_TEST(integrity)
test_pe_checksum();
- if (hNtdll) FreeLibrary(hNtdll); DeleteFileA(test_dll_path); }
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/imagehlp/tests/Makefile.in | 8 +- dlls/imagehlp/tests/image.c | 163 +++++++++++++++++-------------- dlls/imagehlp/tests/testdll.c | 30 ++++++ dlls/imagehlp/tests/testdll.spec | 2 + 4 files changed, 127 insertions(+), 76 deletions(-) create mode 100644 dlls/imagehlp/tests/testdll.c create mode 100644 dlls/imagehlp/tests/testdll.spec
diff --git a/dlls/imagehlp/tests/Makefile.in b/dlls/imagehlp/tests/Makefile.in index 43b434f690a..1a5c393add5 100644 --- a/dlls/imagehlp/tests/Makefile.in +++ b/dlls/imagehlp/tests/Makefile.in @@ -1,6 +1,10 @@ TESTDLL = imagehlp.dll IMPORTS = imagehlp psapi
-C_SRCS = \ +testdll_IMPORTS = oleaut32 comdlg32 shlwapi + +SOURCES = \ image.c \ - integrity.c + integrity.c \ + testdll.c \ + testdll.spec diff --git a/dlls/imagehlp/tests/image.c b/dlls/imagehlp/tests/image.c index c8d1a520c96..888744ac203 100644 --- a/dlls/imagehlp/tests/image.c +++ b/dlls/imagehlp/tests/image.c @@ -24,10 +24,36 @@ #include <winbase.h> #include <winver.h> #include <winnt.h> +#include <winuser.h> #include <imagehlp.h>
#include "wine/test.h"
+static char *load_resource(const char *name) +{ + static char path[MAX_PATH]; + DWORD written; + HANDLE file; + HRSRC res; + void *ptr; + + GetTempPathA(ARRAY_SIZE(path), path); + strcat(path, name); + + file = CreateFileA(path, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0); + ok(file != INVALID_HANDLE_VALUE, "Failed to create file %s, error %u.\n", + debugstr_a(path), GetLastError()); + + res = FindResourceA(NULL, name, "TESTDLL"); + ok(!!res, "Failed to load resource, error %u.\n", GetLastError()); + ptr = LockResource(LoadResource(GetModuleHandleA(NULL), res)); + WriteFile(file, ptr, SizeofResource( GetModuleHandleA(NULL), res), &written, NULL); + ok(written == SizeofResource(GetModuleHandleA(NULL), res), "Failed to write resource.\n"); + CloseHandle(file); + + return path; +} + /* minimal PE file image */ #define VA_START 0x400000 #define FILE_PE_START 0x50 @@ -145,9 +171,6 @@ struct expected_update_accum BOOL todo; };
-static int status_routine_called[BindSymbolsNotUpdated+1]; - - static BOOL WINAPI accumulating_stream_output(DIGEST_HANDLE handle, BYTE *pb, DWORD cb) { @@ -270,40 +293,6 @@ static void update_checksum(void) bin.nt_headers.OptionalHeader.CheckSum = sum; }
-static BOOL CALLBACK testing_status_routine(IMAGEHLP_STATUS_REASON reason, const char *ImageName, - const char *DllName, ULONG_PTR Va, ULONG_PTR Parameter) -{ - char kernel32_path[MAX_PATH]; - - if (0 <= (int)reason && reason <= BindSymbolsNotUpdated) - status_routine_called[reason]++; - else - ok(0, "expected reason between 0 and %d, got %d\n", BindSymbolsNotUpdated+1, reason); - - switch(reason) - { - case BindImportModule: - ok(!strcmp(DllName, "KERNEL32.DLL"), "expected DllName to be KERNEL32.DLL, got %s\n", - DllName); - break; - - case BindImportProcedure: - case BindForwarderNOT: - GetSystemDirectoryA(kernel32_path, MAX_PATH); - strcat(kernel32_path, "\KERNEL32.DLL"); - ok(!lstrcmpiA(DllName, kernel32_path), "expected DllName to be %s, got %s\n", - kernel32_path, DllName); - ok(!strcmp((char *)Parameter, "ExitProcess"), - "expected Parameter to be ExitProcess, got %s\n", (char *)Parameter); - break; - - default: - ok(0, "got unexpected reason %d\n", reason); - break; - } - return TRUE; -} - static void test_get_digest_stream(void) { BOOL ret; @@ -360,52 +349,78 @@ static void test_get_digest_stream(void) DeleteFileA(temp_file); }
-static void test_bind_image_ex(void) +static unsigned int got_SysAllocString, got_GetOpenFileNameA, got_SHRegGetIntW; + +static BOOL WINAPI bind_image_cb(IMAGEHLP_STATUS_REASON reason, const char *file, + const char *module, ULONG_PTR va, ULONG_PTR param) { - BOOL ret; - HANDLE file; - char temp_file[MAX_PATH]; - DWORD count; + static char last_module[MAX_PATH];
- /* call with a non-existent file */ - SetLastError(0xdeadbeef); - ret = BindImageEx(BIND_NO_BOUND_IMPORTS | BIND_NO_UPDATE | BIND_ALL_IMAGES, "nonexistent.dll", 0, 0, - testing_status_routine); - todo_wine ok(!ret && ((GetLastError() == ERROR_FILE_NOT_FOUND) || - (GetLastError() == ERROR_INVALID_PARAMETER)), - "expected ERROR_FILE_NOT_FOUND or ERROR_INVALID_PARAMETER, got %d\n", - GetLastError()); + if (winetest_debug > 1) + trace("reason %u, file %s, module %s, va %#Ix, param %#Ix\n", + reason, debugstr_a(file), debugstr_a(module), va, param);
- file = create_temp_file(temp_file); - if (file == INVALID_HANDLE_VALUE) + if (reason == BindImportModule) { - skip("couldn't create temp file\n"); - return; + ok(!strchr(module, '\'), "got module name %s\n", debugstr_a(module)); + strcpy(last_module, module); + ok(!va, "got VA %#Ix\n", va); + ok(!param, "got param %#Ix\n", param); } + else if (reason == BindImportProcedure) + { + char full_path[MAX_PATH]; + BOOL ret;
- WriteFile(file, &bin, sizeof(bin), &count, NULL); - CloseHandle(file); - - /* call with a proper PE file, but with StatusRoutine set to NULL */ - ret = BindImageEx(BIND_NO_BOUND_IMPORTS | BIND_NO_UPDATE | BIND_ALL_IMAGES, temp_file, 0, 0, - NULL); - ok(ret, "BindImageEx failed: %d\n", GetLastError()); - - /* call with a proper PE file and StatusRoutine */ - ret = BindImageEx(BIND_NO_BOUND_IMPORTS | BIND_NO_UPDATE | BIND_ALL_IMAGES, temp_file, 0, 0, - testing_status_routine); - ok(ret, "BindImageEx failed: %d\n", GetLastError()); + ok(!!va, "expected nonzero VA\n"); + ret = SearchPathA(NULL, last_module, ".dll", sizeof(full_path), full_path, NULL); + ok(ret, "got error %u\n", GetLastError()); + ok(!strcmp(module, full_path), "expected %s, got %s\n", debugstr_a(full_path), debugstr_a(module));
- todo_wine ok(status_routine_called[BindImportModule] == 1, - "StatusRoutine was called %d times\n", status_routine_called[BindImportModule]); + if (!strcmp((const char *)param, "SysAllocString")) + { + ok(!strcmp(last_module, "oleaut32.dll"), "got wrong module %s\n", debugstr_a(module)); + ++got_SysAllocString; + } + else if (!strcmp((const char *)param, "GetOpenFileNameA")) + { + ok(!strcmp(last_module, "comdlg32.dll"), "got wrong module %s\n", debugstr_a(module)); + ++got_GetOpenFileNameA; + } + else if (!strcmp((const char *)param, "Ordinal117")) + { + ok(!strcmp(last_module, "shlwapi.dll"), "got wrong module %s\n", debugstr_a(module)); + ++got_SHRegGetIntW; + } + } + else + { + ok(0, "got unexpected reason %#x\n", reason); + } + return TRUE; +}
- todo_wine ok((status_routine_called[BindImportProcedure] == 1) -#if defined(_WIN64) - || broken(status_routine_called[BindImportProcedure] == 0) /* < Win8 */ -#endif - , "StatusRoutine was called %d times\n", status_routine_called[BindImportProcedure]); +static void test_bind_image_ex(void) +{ + const char *filename = load_resource("testdll.dll"); + BOOL ret;
- DeleteFileA(temp_file); + SetLastError(0xdeadbeef); + ret = BindImageEx(BIND_ALL_IMAGES | BIND_NO_BOUND_IMPORTS | BIND_NO_UPDATE, + "nonexistent.dll", 0, 0, bind_image_cb); + todo_wine ok(!ret, "expected failure\n"); + todo_wine ok(GetLastError() == ERROR_FILE_NOT_FOUND || GetLastError() == ERROR_INVALID_PARAMETER, + "got error %u\n", GetLastError()); + + ret = BindImageEx(BIND_ALL_IMAGES | BIND_NO_BOUND_IMPORTS | BIND_NO_UPDATE, + filename, NULL, NULL, bind_image_cb); + ok(ret, "got error %u\n", GetLastError()); + todo_wine ok(got_SysAllocString == 1, "got %u imports of SysAllocString\n", got_SysAllocString); + todo_wine ok(got_GetOpenFileNameA == 1, "got %u imports of GetOpenFileNameA\n", got_GetOpenFileNameA); + todo_wine ok(got_SHRegGetIntW == 1, "got %u imports of SHRegGetIntW\n", got_SHRegGetIntW); + + ret = DeleteFileA(filename); + ok(ret, "got error %u\n", GetLastError()); }
static void test_image_load(void) diff --git a/dlls/imagehlp/tests/testdll.c b/dlls/imagehlp/tests/testdll.c new file mode 100644 index 00000000000..3c079bfffd3 --- /dev/null +++ b/dlls/imagehlp/tests/testdll.c @@ -0,0 +1,30 @@ +/* + * Copyright 2021 Zebediah Figura + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include <oaidl.h> +#include <commdlg.h> +#include <shlwapi.h> + +extern DWORD WINAPI StrCmpCA(const char *, const char *); + +void export(void) +{ + SysAllocString(NULL); + GetOpenFileNameA(NULL); + SHRegGetIntW(NULL, NULL, 0); +} diff --git a/dlls/imagehlp/tests/testdll.spec b/dlls/imagehlp/tests/testdll.spec new file mode 100644 index 00000000000..7d5774e346b --- /dev/null +++ b/dlls/imagehlp/tests/testdll.spec @@ -0,0 +1,2 @@ +@ cdecl export() +@ stdcall VariantInit(ptr) oleaut32.VariantInit
From: Bernhard Reiter ockham@raz.or.at
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=3591 Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/imagehlp/modify.c | 92 +++++++++++++++++++++++++++++++++---- dlls/imagehlp/tests/image.c | 10 ++-- 2 files changed, 89 insertions(+), 13 deletions(-)
diff --git a/dlls/imagehlp/modify.c b/dlls/imagehlp/modify.c index 434a666ae94..cad689e275a 100644 --- a/dlls/imagehlp/modify.c +++ b/dlls/imagehlp/modify.c @@ -44,15 +44,91 @@ BOOL WINAPI BindImage( /*********************************************************************** * BindImageEx (IMAGEHLP.@) */ -BOOL WINAPI BindImageEx( - DWORD Flags, PCSTR ImageName, PCSTR DllPath, PCSTR SymbolPath, - PIMAGEHLP_STATUS_ROUTINE StatusRoutine) +BOOL WINAPI BindImageEx(DWORD flags, const char *module, const char *dll_path, + const char *symbol_path, PIMAGEHLP_STATUS_ROUTINE cb) { - FIXME("(%d, %s, %s, %s, %p): stub\n", - Flags, debugstr_a(ImageName), debugstr_a(DllPath), - debugstr_a(SymbolPath), StatusRoutine - ); - return TRUE; + static const WORD magic = (sizeof(void *) == 8) ? IMAGE_NT_OPTIONAL_HDR64_MAGIC : IMAGE_NT_OPTIONAL_HDR32_MAGIC; + const IMAGE_IMPORT_DESCRIPTOR *import; + LOADED_IMAGE image; + ULONG size; + + TRACE("flags %#x, module %s, dll_path %s, symbol_path %s, cb %p.\n", + flags, debugstr_a(module), debugstr_a(dll_path), debugstr_a(symbol_path), cb); + + if (!(flags & BIND_NO_UPDATE)) + FIXME("Image modification is not implemented.\n"); + if (flags & ~BIND_NO_UPDATE) + FIXME("Ignoring flags %#x.\n", flags); + + if (!MapAndLoad(module, dll_path, &image, TRUE, TRUE)) + return FALSE; + + if (!(import = ImageDirectoryEntryToData(image.MappedAddress, FALSE, IMAGE_DIRECTORY_ENTRY_IMPORT, &size))) + { + UnMapAndLoad(&image); + return TRUE; /* no imports */ + } + + if (image.FileHeader->OptionalHeader.Magic != magic) + { + FIXME("Unhandled architecture %#x.\n", image.FileHeader->OptionalHeader.Magic); + UnMapAndLoad(&image); + return TRUE; + } + + for (; import->Name && import->FirstThunk; ++import) + { + char full_path[MAX_PATH]; + IMAGE_THUNK_DATA *thunk; + const char *dll_name; + DWORD thunk_rva; + + if (!(dll_name = ImageRvaToVa(image.FileHeader, image.MappedAddress, import->Name, 0))) + { + ERR("Failed to get VA for import name RVA %#x.\n", import->Name); + continue; + } + + if (cb) cb(BindImportModule, module, dll_name, 0, 0); + + if (!SearchPathA(dll_path, dll_name, 0, sizeof(full_path), full_path, 0)) + { + ERR("Import %s was not found.\n", debugstr_a(dll_path)); + continue; + } + + thunk_rva = import->OriginalFirstThunk ? import->OriginalFirstThunk : import->FirstThunk; + if (!(thunk = ImageRvaToVa(image.FileHeader, image.MappedAddress, thunk_rva, 0))) + { + ERR("Failed to get VA for import thunk RVA %#x.\n", thunk_rva); + continue; + } + + for (; thunk->u1.Ordinal; ++thunk) + { + if (IMAGE_SNAP_BY_ORDINAL(thunk->u1.Ordinal)) + { + /* FIXME: We apparently need to subtract the actual module's + * ordinal base. */ + FIXME("Ordinal imports are not implemented.\n"); + } + else + { + IMAGE_IMPORT_BY_NAME *name; + + if (!(name = ImageRvaToVa(image.FileHeader, image.MappedAddress, thunk->u1.AddressOfData, 0))) + { + ERR("Failed to get VA for name RVA %#x.\n", thunk->u1.AddressOfData); + continue; + } + + if (cb) cb(BindImportProcedure, module, full_path, 0, (ULONG_PTR)name->Name); + } + } + } + + UnMapAndLoad(&image); + return TRUE; }
diff --git a/dlls/imagehlp/tests/image.c b/dlls/imagehlp/tests/image.c index 888744ac203..e2aa9485510 100644 --- a/dlls/imagehlp/tests/image.c +++ b/dlls/imagehlp/tests/image.c @@ -372,7 +372,7 @@ static BOOL WINAPI bind_image_cb(IMAGEHLP_STATUS_REASON reason, const char *file char full_path[MAX_PATH]; BOOL ret;
- ok(!!va, "expected nonzero VA\n"); + todo_wine ok(!!va, "expected nonzero VA\n"); ret = SearchPathA(NULL, last_module, ".dll", sizeof(full_path), full_path, NULL); ok(ret, "got error %u\n", GetLastError()); ok(!strcmp(module, full_path), "expected %s, got %s\n", debugstr_a(full_path), debugstr_a(module)); @@ -408,15 +408,15 @@ static void test_bind_image_ex(void) SetLastError(0xdeadbeef); ret = BindImageEx(BIND_ALL_IMAGES | BIND_NO_BOUND_IMPORTS | BIND_NO_UPDATE, "nonexistent.dll", 0, 0, bind_image_cb); - todo_wine ok(!ret, "expected failure\n"); - todo_wine ok(GetLastError() == ERROR_FILE_NOT_FOUND || GetLastError() == ERROR_INVALID_PARAMETER, + ok(!ret, "expected failure\n"); + ok(GetLastError() == ERROR_FILE_NOT_FOUND || GetLastError() == ERROR_INVALID_PARAMETER, "got error %u\n", GetLastError());
ret = BindImageEx(BIND_ALL_IMAGES | BIND_NO_BOUND_IMPORTS | BIND_NO_UPDATE, filename, NULL, NULL, bind_image_cb); ok(ret, "got error %u\n", GetLastError()); - todo_wine ok(got_SysAllocString == 1, "got %u imports of SysAllocString\n", got_SysAllocString); - todo_wine ok(got_GetOpenFileNameA == 1, "got %u imports of GetOpenFileNameA\n", got_GetOpenFileNameA); + ok(got_SysAllocString == 1, "got %u imports of SysAllocString\n", got_SysAllocString); + ok(got_GetOpenFileNameA == 1, "got %u imports of GetOpenFileNameA\n", got_GetOpenFileNameA); todo_wine ok(got_SHRegGetIntW == 1, "got %u imports of SHRegGetIntW\n", got_SHRegGetIntW);
ret = DeleteFileA(filename);