Re: How can you capture the input and output of a serial port in wine

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 26 Feb 2002, Andreas Mohr Usenet 10/01 wrote:

> David Bronaugh <dbronaugh@linuxboxen.org> wrote:
> > I'm curious about this. I'm trying to reverse-engineer a really neato-device that hooks up to the serial port and has Windows software. I've figured out the protocol the device sends; I'm just not sure how the device is initialized. So I'd love to capture the Windows software doing the dirty deed.. and WINE is IMHO just the tool. So, question is:
>
> > How do you capture serial ports transmissions and/or receives in WINE?
> wine --debugmsg +relay,+comm,+file prg.exe &>/tmp/wine.log
>
>
This is kind of a dreadful hack, but it has been useful to me some time
in the past so I remade it to apply to the current CVS.  You might want
to edit the hardcoded path for the trace file it captures to (isn't
everybody keeps a /gp/windose directory).  If the logfile exists, it
will not overwrite it, but it is happy to make a new one.
I took the trouble to hand-patch it from a year ago, so you may as well
have the use of it in case it is useful.  Maybe you want to fix the
hacks and offer it to Wine.

Lawson

Though wise men at their end know dark is right,
Because their words had forked no lightning they
Do not go gentle into that good night.    - Dylan Thomas
diff -ur was/files/file.c is/files/file.c
--- was/files/file.c	Fri Feb 22 19:33:03 2002
+++ is/files/file.c	Tue Feb 26 22:04:59 2002
@@ -60,6 +60,7 @@
 
 static HANDLE dos_handles[DOS_TABLE_SIZE];
 
+static HFILE craw, hcraw;
 
 /***********************************************************************
  *              FILE_ConvertOFMode
@@ -326,6 +327,7 @@
         if (err) SetLastError( RtlNtStatusToDosError(err) );
 
         if (!ret) WARN("Unable to create file '%s' (GLE %ld)\n", filename, GetLastError());
+        if (ret == hcraw) craw = hcraw = 0;
         return ret;
     }
 }
@@ -497,6 +499,10 @@
             ERR("Couldn't open device '%s'!\n",filename);
             SetLastError( ERROR_FILE_NOT_FOUND );
         }
+        if (HFILE_ERROR==(craw=FILE_CreateFile("/gp/windose/logs/craw",
+	    GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, 0, TRUE, NULL))) craw=0;
+	if (craw) hcraw = ret;
+
         goto done;
     }
 
@@ -1454,7 +1460,7 @@
 BOOL WINAPI ReadFile( HANDLE hFile, LPVOID buffer, DWORD bytesToRead,
                         LPDWORD bytesRead, LPOVERLAPPED overlapped )
 {
-    int unix_handle, result;
+    int unix_handle, result, uh;
     enum fd_type type;
     DWORD flags;
 
@@ -1494,6 +1500,14 @@
             else
                 result = 0;
         }
+        if ((craw) && (hcraw == hFile))
+        {
+            uh = FILE_GetUnixHandle(craw, GENERIC_WRITE);
+            write(uh, "\n__read___", 10);
+            write(uh, buffer, result);
+            close(uh);
+        }
+
         
         /* if we read enough to keep the app happy, then return now */
         if(result>=bytesToRead)
@@ -1676,7 +1690,7 @@
 BOOL WINAPI WriteFile( HANDLE hFile, LPCVOID buffer, DWORD bytesToWrite,
                          LPDWORD bytesWritten, LPOVERLAPPED overlapped )
 {
-    int unix_handle, result;
+    int unix_handle, result, uh;
     enum fd_type type;
     DWORD flags;
 
@@ -1685,6 +1699,14 @@
 
     if (bytesWritten) *bytesWritten = 0;  /* Do this before anything else */
     if (!bytesToWrite) return TRUE;
+    if ((craw) && (hcraw == hFile))
+    {
+        uh = FILE_GetUnixHandle(craw, GENERIC_WRITE);
+        write(uh, "\n__write__", 10);
+        write(uh, buffer, bytesToWrite);
+        close(uh);
+    }        
+
 
     unix_handle = FILE_GetUnixHandleType( hFile, GENERIC_WRITE, &type, &flags );
 

[Index of Archives]     [Gimp for Windows]     [Red Hat]     [Samba]     [Yosemite Camping]     [Graphics Cards]     [Wine Home]

  Powered by Linux