Nmap Development mailing list archives

Re: nmap 3.3+V-2.99


From: "Gisle Vanem" <giva () bgnett no>
Date: Mon, 1 Sep 2003 00:54:23 +0200

"Jay Freeman (saurik)" <saurik () saurik com> said:

Considering the first entry in my CHANGELOG was "I broke the Win32 build." I
would have to say "no, I didn't test it on Windows, I didn't even realize
anyone else was going to be able to compile it on Windows", hehe. It totally
slipped my mind that you could still use gcc to get it to compile on
Windows.

Funny that you seem to prefer Linux, but you post using
X-Mailer: Microsoft Outlook Express 6.00.2600.0000

 :-)

Here's some patches that works for me:

diff -u3 -H -B -r .\menes-ext\refcount.hpp ..\menes-ext\refcount.hpp
--- .\menes-ext\refcount.hpp    Sun Aug 31 07:05:09 2003
+++ ..\menes-ext\refcount.hpp   Sun Aug 31 18:45:41 2003
@@ -114,7 +114,8 @@
     typedef Counted_ Value;

     inline void Clear(Value &value) const {
-        value = NULL;
+        if (value)
+                       value = NULL;
     }

Not sure why, but Clear() is using a NULL-ptr somewhere.
And most importantly:

diff -u3 -H -B -r .\utils.cc ..\utils.cc
--- .\utils.cc Sun Aug 31 07:05:09 2003
+++ ..\utils.cc Sun Aug 31 20:49:36 2003
@@ -45,6 +45,9 @@
 /* $Id: utils.cc,v 1.1.1.4 2003/07/18 19:32:27 saurik Exp $ */

 #include "utils.h"
+#include "NmapOps.h"
+
+extern NmapOps o;

 /* Return num if it is between min and max.  Otherwise return min or
    max (whichever is closest to num), */
@@ -616,9 +619,12 @@
    file at a time (note how gmap is used).*/
 /* I believe this was written by Ryan Permeh ( ryan () eeye com) */

-HANDLE gmap = 0;
-char *mmapfile(char *fname, int *length, int openflags) {
+static HANDLE gmap = NULL;
+
+char *mmapfile(char *fname, int *length, int openflags)
+{
  HANDLE fd;
+ DWORD mflags, oflags;
  char *fileptr;

  if (!length || !fname) {
@@ -626,27 +632,44 @@
   return NULL;
  }

- *length = -1;
+ if (openflags == O_RDONLY) {
+  oflags = GENERIC_READ;
+  mflags = PAGE_READONLY;
+  }
+ else {
+  oflags = GENERIC_READ | GENERIC_WRITE;
+  mflags = PAGE_READONLY | PAGE_READWRITE;
+ }
+
+ fd = CreateFile (
+   fname,
+   oflags,                       // open flags
+   0,                            // do not share
+   NULL,                         // no security
+   OPEN_EXISTING,                // open existing
+   FILE_ATTRIBUTE_NORMAL,
+   NULL);                        // no attr. template
+ if (!fd)
+  pfatal ("%s(%u): CreateFile()", __FILE__, __LINE__);
+
+ *length = (int) GetFileSize (fd, NULL);
+
+ gmap = CreateFileMapping (fd, NULL, mflags, 0, 0, NULL);
+ if (!gmap)
+  pfatal ("%s(%u): CreateFileMapping(), file '%s', length %d, mflags %08lX",
+    __FILE__, __LINE__, fname, *length, mflags);
+
+ fileptr = (char*) MapViewOfFile (gmap, oflags == GENERIC_READ ? FILE_MAP_READ : FILE_MAP_WRITE,
+                                     0, 0, 0);
+ if (!fileptr)
+  pfatal ("%s(%u): MapViewOfFile()", __FILE__, __LINE__);
+
+ CloseHandle (fd);
+
+ if (o.debugging > 2)
+  printf ("mmapfile(): fd %08lX, gmap %08lX, fileptr %08lX, length %d\n",
+    (DWORD)fd, (DWORD)gmap, (DWORD)fileptr, *length);

- fd= CreateFile(fname,
-  openflags,                // open for writing
-  0,                            // do not share
-  NULL,                         // no security
-  OPEN_EXISTING,                // overwrite existing
-  FILE_ATTRIBUTE_NORMAL,
-  NULL);                        // no attr. template
-
- gmap=CreateFileMapping(fd,NULL, (openflags & O_RDONLY)? PAGE_READONLY:(openflags & O_RDWR)? 
(PAGE_READONLY|PAGE_READWRITE) :
PAGE_READWRITE,0,0,NULL);
-
- fileptr = (char *)MapViewOfFile(gmap, FILE_MAP_ALL_ACCESS,0,0,0);
- *length = (int) GetFileSize(fd,NULL);
- CloseHandle(fd);
-
- #ifdef MAP_FAILED
- if (fileptr == MAP_FAILED) return NULL;
- #else
- if (fileptr == (char *) -1) return NULL;
- #endif
  return fileptr;
 }

@@ -655,12 +678,13 @@
    works if the file is the most recently mapped one */
 int win32_munmap(char *filestr, int filelen)
 {
- if(gmap == 0)
-  fatal("win32_munmap: no current mapping !\n");
- FlushViewOfFile(filestr, filelen);
- UnmapViewOfFile(filestr);
- CloseHandle(gmap);
- gmap = 0;
+ if(gmap)
+ {
+  FlushViewOfFile(filestr, filelen);
+  UnmapViewOfFile(filestr);
+  CloseHandle(gmap);
+ }
+ gmap = NULL;
  return 0;
 }

Sorry about the wrapping lines and OE collapsing tabs.
But you figure it out.

--
Gisle V.

Not what you think it is;  http://www.nice-tits.org






---------------------------------------------------------------------
For help using this (nmap-dev) mailing list, send a blank email to 
nmap-dev-help () insecure org . List run by ezmlm-idx (www.ezmlm.org).



Current thread: