]> git.eshelyaron.com Git - emacs.git/commitdiff
(w32_executable_type): Handle 64 bit executables.
authorJason Rumney <jasonr@gnu.org>
Wed, 18 Jul 2007 22:20:42 +0000 (22:20 +0000)
committerJason Rumney <jasonr@gnu.org>
Wed, 18 Jul 2007 22:20:42 +0000 (22:20 +0000)
src/ChangeLog
src/w32proc.c

index c5d7ac769baafe77b0f163b169da770062a99542..af13ba0f3032262559e44c237d6c99853bdc42b1 100644 (file)
@@ -1,3 +1,7 @@
+2007-07-18  Jason Rumney  <jasonr@gnu.org>
+
+       * w32proc.c (w32_executable_type): Handle 64 bit executables.
+
 2007-07-16  Juanma Barranquero  <lekktu@gmail.com>
 
        * coding.c (Ffind_operation_coding_system):
index 2120a51fb89b4cf8c7e2e23751d3d311d902006d..7d1717792abae88924d44197d24fa0ab605098d1 100644 (file)
@@ -650,33 +650,54 @@ w32_executable_type (char * filename, int * is_dos_app, int * is_cygnus_app, int
        }
       else if (nt_header->Signature == IMAGE_NT_SIGNATURE)
        {
-         /* Look for cygwin.dll in DLL import list. */
-         IMAGE_DATA_DIRECTORY import_dir =
-           nt_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT];
-         IMAGE_IMPORT_DESCRIPTOR * imports;
-         IMAGE_SECTION_HEADER * section;
-
-         section = rva_to_section (import_dir.VirtualAddress, nt_header);
-         imports = RVA_TO_PTR (import_dir.VirtualAddress, section, executable);
-
-         for ( ; imports->Name; imports++)
-           {
-             char * dllname = RVA_TO_PTR (imports->Name, section, executable);
-
-             /* The exact name of the cygwin dll has changed with
-                various releases, but hopefully this will be reasonably
-                future proof.  */
-             if (strncmp (dllname, "cygwin", 6) == 0)
-               {
-                 *is_cygnus_app = TRUE;
-                 break;
-               }
-           }
-
-         /* Check whether app is marked as a console or windowed (aka
-             GUI) app.  Accept Posix and OS2 subsytem apps as console
-             apps.  */
-         *is_gui_app = (nt_header->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI);
+          IMAGE_DATA_DIRECTORY *data_dir = NULL;
+          if (nt_header->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC)
+            {
+              /* Ensure we are using the 32 bit structure.  */
+              IMAGE_OPTIONAL_HEADER32 *opt
+                = (IMAGE_OPTIONAL_HEADER32*) &(nt_header->OptionalHeader);
+              data_dir = opt->DataDirectory;
+              *is_gui_app = (opt->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI);
+            }
+          /* MingW 3.12 has the required 64 bit structs, but in case older
+             versions don't, only check 64 bit exes if we know how.  */
+#ifdef IMAGE_NT_OPTIONAL_HDR64_MAGIC
+          else if (nt_header->OptionalHeader.Magic
+                   == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
+            {
+              IMAGE_OPTIONAL_HEADER64 *opt
+                = (IMAGE_OPTIONAL_HEADER64*) &(nt_header->OptionalHeader);
+              data_dir = opt->DataDirectory;
+              *is_gui_app = (opt->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI);
+            }
+#endif
+          if (data_dir)
+            {
+              /* Look for cygwin.dll in DLL import list. */
+              IMAGE_DATA_DIRECTORY import_dir =
+                data_dir[IMAGE_DIRECTORY_ENTRY_IMPORT];
+              IMAGE_IMPORT_DESCRIPTOR * imports;
+              IMAGE_SECTION_HEADER * section;
+
+              section = rva_to_section (import_dir.VirtualAddress, nt_header);
+              imports = RVA_TO_PTR (import_dir.VirtualAddress, section,
+                                    executable);
+
+              for ( ; imports->Name; imports++)
+                {
+                  char * dllname = RVA_TO_PTR (imports->Name, section,
+                                               executable);
+                  
+                  /* The exact name of the cygwin dll has changed with
+                     various releases, but hopefully this will be reasonably
+                     future proof.  */
+                  if (strncmp (dllname, "cygwin", 6) == 0)
+                    {
+                      *is_cygnus_app = TRUE;
+                      break;
+                    }
+                }
+            }
        }
     }