Wine detect patch (ignore previous whitespace patch)

Jakob Eriksson jakov at vmlinux.org
Wed Apr 21 16:00:32 CDT 2004



Ok, this is the detect Wine patch.
It creates an obviously bogus Windows version signature when winetest.exe
is run from Wine.  That's to avoid misdetection of Wine as Windows XP or
any other real Windows version.

(Sorry about the linespace noise after print_version(),
 emacs seems to change stuff behind my back when I save.)


regards,
Jakob

-------------- next part --------------
Index: main.c
===================================================================
RCS file: /home/wine/wine/programs/winetest/main.c,v
retrieving revision 1.11
diff -u -r1.11 main.c
--- main.c	20 Apr 2004 04:00:07 -0000	1.11
+++ main.c	21 Apr 2004 20:55:58 -0000
@@ -59,17 +59,32 @@
 
 static const char *wineloader;
 
+static int running_on_wine ()
+{
+    HMODULE module = LoadLibrary("ntdll");
+    FARPROC proc;
+
+    if (!module)
+        return 0;
+
+    proc = GetProcAddress(module, "wine_get_unix_file_name");
+    FreeLibrary(module);
+
+    return proc != NULL;
+}
+
 void print_version ()
 {
     OSVERSIONINFOEX ver;
     BOOL ext;
+    static const TCHAR wine[128] = {"Wine"};
 
     ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
     if (!(ext = GetVersionEx ((OSVERSIONINFO *) &ver)))
     {
-	ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-	if (!GetVersionEx ((OSVERSIONINFO *) &ver))
-	    report (R_FATAL, "Can't get OS version.");
+        ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+        if (!GetVersionEx ((OSVERSIONINFO *) &ver))
+            report (R_FATAL, "Can't get OS version.");
     }
 
     xprintf ("    dwMajorVersion=%ld\n    dwMinorVersion=%ld\n"
@@ -77,6 +92,16 @@
              ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber,
              ver.dwPlatformId, ver.szCSDVersion);
 
+    if (running_on_wine ()) {  /* Make a an obvious signature for Wine */
+       ext = 1;
+
+       ver.dwMajorVersion = 1;
+       ver.dwMinorVersion = 1;
+       ver.dwBuildNumber  = 1;
+       ver.dwPlatformId   = 1;
+       strncpy (ver.szCSDVersion, wine, sizeof (wine));
+   }
+
     if (!ext) return;
 
     xprintf ("    wServicePackMajor=%d\n    wServicePackMinor=%d\n"
@@ -124,18 +149,18 @@
 const char* get_test_source_file(const char* test, const char* subtest)
 {
     static const char* special_dirs[][2] = {
-	{ "gdi32", "gdi"}, { "kernel32", "kernel" },
-	{ "user32", "user" }, { "winspool.drv", "winspool" },
-	{ "ws2_32", "winsock" }, { 0, 0 }
+        { "gdi32", "gdi"}, { "kernel32", "kernel" },
+        { "user32", "user" }, { "winspool.drv", "winspool" },
+        { "ws2_32", "winsock" }, { 0, 0 }
     };
     static char buffer[MAX_PATH];
     int i;
 
     for (i = 0; special_dirs[i][0]; i++) {
-	if (strcmp(test, special_dirs[i][0]) == 0) {
-	    test = special_dirs[i][1];
-	    break;
-	}
+        if (strcmp(test, special_dirs[i][0]) == 0) {
+            test = special_dirs[i][1];
+            break;
+        }
     }
 
     snprintf(buffer, sizeof(buffer), "dlls/%s/tests/%s.c", test, subtest);
@@ -145,9 +170,9 @@
 const char* get_file_rev(const char* file)
 {
     const struct rev_info* rev;
- 
+
     for(rev = rev_infos; rev->file; rev++) {
-	if (strcmp(rev->file, file) == 0) return rev->rev;
+        if (strcmp(rev->file, file) == 0) return rev->rev;
     }
 
     return "-";
@@ -160,21 +185,21 @@
     HMODULE module = GetModuleHandle (NULL);
 
     for (i = 0; TRUE; i++) {
-	if (i >= size) {
-	    size += 100;
-	    rev_infos = xrealloc (rev_infos, size * sizeof (*rev_infos));
-	}
-	memset(rev_infos + i, 0, sizeof(rev_infos[i]));
+        if (i >= size) {
+            size += 100;
+            rev_infos = xrealloc (rev_infos, size * sizeof (*rev_infos));
+        }
+        memset(rev_infos + i, 0, sizeof(rev_infos[i]));
 
         len = LoadStringA (module, i + 30000, revinfo, sizeof(revinfo));
         if (len == 0) break; /* end of revision info */
-	if (len >= sizeof(revinfo) - 1) 
-	    report (R_FATAL, "Revision info too long.");
-	if(!(p = strrchr(revinfo, ':')))
-	    report (R_FATAL, "Revision info malformed (i=%d)", i);
-	*p = 0;
-	rev_infos[i].file = strdup(revinfo);
-	rev_infos[i].rev = strdup(p + 1);
+        if (len >= sizeof(revinfo) - 1)
+            report (R_FATAL, "Revision info too long.");
+        if(!(p = strrchr(revinfo, ':')))
+            report (R_FATAL, "Revision info malformed (i=%d)", i);
+        *p = 0;
+        rev_infos[i].file = strdup(revinfo);
+        rev_infos[i].rev = strdup(p + 1);
     }
 }
 
@@ -183,7 +208,7 @@
     HRSRC rsrc;
     HGLOBAL hdl;
     LPVOID addr = NULL;
-    
+
     if (!(rsrc = FindResource (0, (LPTSTR)id, TESTRESOURCE)) ||
         !(*size = SizeofResource (0, rsrc)) ||
         !(hdl = LoadResource (0, rsrc)) ||
@@ -457,10 +482,10 @@
         struct wine_test *test = wine_tests + i;
         int j;
 
-	for (j = 0; j < test->subtest_count; j++) {
+        for (j = 0; j < test->subtest_count; j++) {
             report (R_STEP, "Running: %s:%s", test->name,
                     test->subtests[j]);
-	    run_test (test, test->subtests[j]);
+            run_test (test, test->subtests[j]);
         }
     }
     report (R_DELTA, 0, "Running: Done");


More information about the wine-patches mailing list