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);
/* minimal PE file image */
#define VA_START 0x400000
BOOL todo;
};
+static int status_routine_called[BindSymbolsNotUpdated+1];
+
+
static BOOL WINAPI accumulating_stream_output(DIGEST_HANDLE handle, BYTE *pb,
DWORD cb)
{
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;
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);
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
DeleteFileA(temp_file);
}
+static void test_bind_image_ex(void)
+{
+ BOOL ret;
+ HANDLE file;
+ 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,
+ 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());
+
+ file = create_temp_file(temp_file);
+ if (file == INVALID_HANDLE_VALUE)
+ {
+ skip("couldn't create temp file\n");
+ return;
+ }
+
+ WriteFile(file, &bin, sizeof(bin), &count, NULL);
+ 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,
+ 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,
+ testing_status_routine);
+ ok(ret, "BindImageEx failed: %d\n", GetLastError());
+
+ todo_wine ok(status_routine_called[BindImportModule] == 1,
+ "StatusRoutine was called %d times\n", status_routine_called[BindImportModule]);
+
+ 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]);
+
+ DeleteFileA(temp_file);
+}
+
START_TEST(image)
{
hImageHlp = LoadLibraryA("imagehlp.dll");
}
pImageGetDigestStream = (void *) GetProcAddress(hImageHlp, "ImageGetDigestStream");
+ pBindImageEx = (void *) GetProcAddress(hImageHlp, "BindImageEx");
- if (!pImageGetDigestStream)
- {
- win_skip("ImageGetDigestStream function is not available\n");
- } else
- {
- test_get_digest_stream();
- }
+ test_get_digest_stream();
+ test_bind_image_ex();
FreeLibrary(hImageHlp);
}
return filesize;
}
-static void test_add_certificate(const char *cert_data, int len)
+static DWORD test_add_certificate(const char *cert_data, int len)
{
HANDLE hFile;
LPWIN_CERTIFICATE cert;
if (hFile == INVALID_HANDLE_VALUE)
{
skip("Unable to open %s, skipping test\n", test_dll_path);
- return;
+ return ~0;
}
cert_len = sizeof(WIN_CERTIFICATE) + len;
{
skip("Unable to allocate memory, skipping test\n");
CloseHandle(hFile);
- return;
+ return ~0;
}
cert->dwLength = cert_len;
ret = pImageAddCertificate(hFile, cert, &index);
ok(ret, "Unable to add certificate to image, error %x\n", GetLastError());
+ trace("added cert index %d\n", index);
HeapFree(GetProcessHeap(), 0, cert);
CloseHandle(hFile);
+ return index;
}
static void test_get_certificate(const char *cert_data, int index)
START_TEST(integrity)
{
- DWORD file_size, file_size_orig;
+ DWORD file_size, file_size_orig, first, second;
hImageHlp = LoadLibraryA("imagehlp.dll");
pImageGetCertificateHeader = (void *) GetProcAddress(hImageHlp, "ImageGetCertificateHeader");
pImageRemoveCertificate = (void *) GetProcAddress(hImageHlp, "ImageRemoveCertificate");
- test_add_certificate(test_cert_data, sizeof(test_cert_data));
- test_get_certificate(test_cert_data, 0);
- test_remove_certificate(0);
+ first = test_add_certificate(test_cert_data, sizeof(test_cert_data));
+ test_get_certificate(test_cert_data, first);
+ test_remove_certificate(first);
file_size = get_file_size();
ok(file_size == file_size_orig, "File size different after add and remove (old: %d; new: %d)\n", file_size_orig, file_size);
/* Try adding multiple certificates */
- test_add_certificate(test_cert_data, sizeof(test_cert_data));
- test_add_certificate(test_cert_data_2, sizeof(test_cert_data_2));
+ first = test_add_certificate(test_cert_data, sizeof(test_cert_data));
+ second = test_add_certificate(test_cert_data_2, sizeof(test_cert_data_2));
+ ok(second == first + 1, "got %d %d\n", first, second);
- test_get_certificate(test_cert_data, 0);
- test_get_certificate(test_cert_data_2, 1);
+ test_get_certificate(test_cert_data, first);
+ test_get_certificate(test_cert_data_2, second);
/* Remove the first one and verify the second certificate is intact */
- test_remove_certificate(0);
- test_get_certificate(test_cert_data_2, 0);
+ test_remove_certificate(first);
+ second--;
+ test_get_certificate(test_cert_data_2, second);
- test_remove_certificate(0);
+ test_remove_certificate(second);
file_size = get_file_size();
ok(file_size == file_size_orig, "File size different after add and remove (old: %d; new: %d)\n", file_size_orig, file_size);