Pages: [1]   Go Down
Author Topic: Com port sniffer logger (java based)  (Read 1938 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
God Member
*****
Karma: 1
Posts: 513
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I was messing around with upload protocols and wanted to see one in action and came up with this.  Maybe it's useful for someone.   Yes, I'm sure it's been done a million times before smiley

Basically I used com0com and rxtx to write a little java program to intercept the bytes between avrdude and my usual com port (COM4) to see what exactly was being sent and received.  I set com0com to bridge from com2 to com7, told arduino to use com2, and told my program to wait for com7 activity and proxy/log it to com4.

Here's the program:
Code:
/* simple Java serial port proxy logger */
//leverages com0com http://sourceforge.net/projects/com0com/
//and rxtx http://users.frii.com/jarvi/rxtx/download.html

//note, if you installed arduino, then you already have the rxtx jars and shared libraries in your arduino directory
//and if you got avrstudio working with your usbtinyisp, then you have com0com installed too.

//It's a CPU hog so don't leave it running all day.


import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;


public class ComProxy {
      public static final String applicationComPort = "COM7";
      public static final String deviceComport = "COM4";
    public static final int baud=19200;
      
      
      static InputStream input1;
      static OutputStream output1;

      static InputStream input2;
      static OutputStream output2;

      static OutputStream out;
      
      public static void main(String[] args) throws Exception {
//            out=new FileOutputStream("/comproxy.log");
            out=System.out;

            CommPortIdentifier portId1 = CommPortIdentifier
            .getPortIdentifier(applicationComPort);

            CommPortIdentifier portId2 = CommPortIdentifier
            .getPortIdentifier(deviceComport);

            System.out.println("Serial Proxy Starting");
            System.out.println("Serial application port: " + portId1.getName());
            System.out.println("Serial proxied to device port: " + portId2.getName());


            SerialPort port1 = (SerialPort) portId1.open("serial madness1", 4000);
            input1 = port1.getInputStream();
            output1 = port1.getOutputStream();
            port1.setSerialPortParams(baud,
                        SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
                        SerialPort.PARITY_NONE);
            //this assumes the application starts the serial conversation
               while(input1.available() > 0){ input1.read();};
                    System.out.println("waiting for "+applicationComPort+" activity...");
               while(input1.available() ==0);

            
            SerialPort port2 = (SerialPort) portId2.open("serial madness2", 4001);
            input2 = port2.getInputStream();
            output2 = port2.getOutputStream();
            port2.setSerialPortParams(baud,
                        SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
                        SerialPort.PARITY_NONE);
               while(input2.available() > 0){ input2.read();};

            
            
              System.out.println("proxy started");

            while (true) {
              int c;      
              if(input1.available() > 0){
                    c=input1.read();
                    out.write(("I"+hexval(c)+"\n").getBytes());
                    output2.write(c);
              }
              if(input2.available() > 0){
                    c=input2.read();
                    out.write(("O"+hexval(c)+"\n").getBytes());
                    output1.write(c);
              }
            }
      }
      public static void waitfor(int w) throws Exception{
            int c;
            do{
                  while(input2.available() == 0);
                  c=input2.read();
                  System.out.println((char)c + " " + (int) c);
            }while(c != w);
      }
      
      
static String hexvals[] = {
      "0", "1","2","3","4","5","6","7","8","9", "A", "B", "C", "D", "E","F"};

static String hexval(int i){
      return hexvals[i/16] + hexvals[i%16];
}      
}

Here is the output, lines starting with I are bytes going to the arduino, lines staring with an O are responses from the arduino.  (I'm uploading Blink here)
Code:
Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version   = RXTX-2.1-7
Serial Proxy Starting
Serial application port: COM7
Serial proxied to device port: COM4
waiting for COM7 activity...
proxy started
I30
I20
I30
I20
O14
O10
I30
I20
O14
O10
I41
I80
I20
O14
O02
O10
I41
I81
I20
O14
O01
O10
I41
I82
I20
O14
O10
O10
I41
I98
I20
O14
O03
O10
I41
I84
I20
O14
O00
O10
I41
I85
I20
O14
O00
O10
I41
I86
I20
O14
O00
O10
I41
I87
I20
O14
O00
O10
I41
I89
I20
O14
O00
O10
I41
I81
I20
O14
O01
O10
I41
I82
I20
O14
O10
O10
I42
I86
I00
I00
I01
I01
I01
I01
I03
IFF
IFF
IFF
IFF
I00
I80
I02
I00
I00
I00
I40
I00
I20
O14
O10
I45
I05
I04
ID7
IC2
I00
I20
O14
O10
I50
I20
O14
O10
I75
I20
O14
O1E
O94
O06
O10
I56
IA0
I01
IFC
I00
I20
O14
O00
O10
I56
IA0
I01
IFD
I00
I20
O14
O00
O10
I56
IA0
I01
IFE
I00
I20
O14
O00
O10
I56
IA0
I01
IFF
I00
I20
O14
O00
O10
I55
I00
I00
I20
O14
O10
I64
I00
I80
I46
I0C
I94
I5A
I00
I0C
I94
I77
I00
I0C
I94
I77
I00
I0C
I94
I77
I00
I0C
I94
I77
I00
I0C
I94
I77
I00
I0C
I94
I77
I00
I0C
I94
I77
I00
I0C
I94
I77
I00
I0C
I94
I77
I00
I0C
I94
I77
I00
I0C
I94
I77
I00
I0C
I94
I77
I00
I0C
I94
I77
I00
I0C
I94
I77
I00
I0C
I94
I77
I00
I0C
I94
I9D
I00
I0C
I94
I77
I00
I0C
I94
I77
I00
I0C
I94
I77
I00
I0C
I94
I77
I00
I0C
I94
I77
I00
I0C
I94
I77
I00
I0C
I94
I77
I00
I0C
I94
I77
I00
I0C
I94
I77
I00
I00
I00
I24
I27
I2A
I00
I00
I25
I28
I2B
I00
I00
I23
I26
I29
I04
I04
I04
I04
I04
I04
I04
I04
I02
I20
O14
O10
I55
I40
I00
I20
O14
O10
I64
I00
I80
I46
I02
I02
I02
I02
I02
I03
I03
I03
I03
I03
I03
I01
I02
I04
I08
I10
I20
I40
I80
I01
I02
I04
I08
I10
I20
I01
I02
I04
I08
I10
I20
I00
I00
I00
I07
I00
I02
I01
I00
I00
I03
I04
I06
I00
I00
I00
I00
I00
I00
I00
I00
I00
I11
I24
I1F
IBE
ICF
IEF
ID4
IE0
IDE
IBF
ICD
IBF
I11
IE0
IA0
IE0
IB1
IE0
IE6
IE4
IF4
IE0
I02
IC0
I05
I90
I0D
I92
IA2
I30
IB1
I07
ID9
IF7
I11
IE0
IA2
IE0
IB1
IE0
I01
IC0
I1D
I92
IA6
I30
IB1
I07
IE1
IF7
I0E
I94
I96
I00
I0C
I94
I22
I02
I0C
I94
I00
I00
I61
IE0
I80
I91
I00
I01
I0E
I94
IB5
I01
I68
IEE
I73
IE0
I20
O14
O10
I55
I80
I00
I20
O14
O10
I64
I00
I80
I46
I80
IE0
I90
IE0
I0E
I94
IDA
I00
I60
IE0
I80
I91
I00
I01
I0E
I94
IB5
I01
I68
IEE
I73
IE0
I80
IE0
I90
IE0
I0E
I94
IDA
I00
I08
I95
I61
IE0
I80
I91
I00
I01
I0E
I94
I4B
I01
I08
I95
I0E
I94
I09
I01
I0E
I94
I90
I00
I0E
I94
I79
I00
IFD
ICF
I1F
I92
I0F
I92
I0F
IB6
I0F
I92
I11
I24
I8F
I93
I9F
I93
IAF
I93
IBF
I93
I80
I91
I02
I01
I90
I91
I03
I01
IA0
I91
I04
I01
IB0
I91
I05
I01
I01
I96
IA1
I1D
IB1
I1D
I80
I93
I02
I01
I90
I93
I03
I01
IA0
I93
I04
I01
IB0
I93
I05
I01
IBF
I91
IAF
I91
I9F
I91
I8F
I91
I0F
I90
I0F
IBE
I0F
I90
I20
O14
O10
I55
IC0
I00
I20
O14
O10
I64
I00
I80
I46
I1F
I90
I18
I95
I60
I91
I02
I01
I70
I91
I03
I01
I80
I91
I04
I01
I90
I91
I05
I01
I27
IE0
I66
I0F
I77
I1F
I88
I1F
I99
I1F
I2A
I95
ID1
IF7
I2D
IE7
I30
IE0
I40
IE0
I50
IE0
I0E
I94
I00
I02
ICA
I01
IB9
I01
I08
I95
IAF
I92
IBF
I92
ICF
I92
IDF
I92
IEF
I92
IFF
I92
I0F
I93
I1F
I93
I5B
I01
I6C
I01
I0E
I94
IC2
I00
I7B
I01
I8C
I01
I0E
I94
IC2
I00
I6E
I19
I7F
I09
I80
I0B
I91
I0B
I6A
I15
I7B
I05
I8C
I05
I9D
I05
IA8
IF3
I1F
I91
I0F
I91
IFF
I90
IEF
I90
IDF
I90
ICF
I90
IBF
I90
IAF
I90
I08
I95
I01
I97
I51
IF0
I88
I0F
I99
I1F
I20
O14
O10
I55
I00
I01
I20
O14
O10
I64
I00
I80
I46
I88
I0F
I99
I1F
I02
I97
I2F
IB7
IF8
I94
I01
I97
IF1
IF7
I2F
IBF
I08
I95
I78
I94
I10
I92
I02
I01
I10
I92
I03
I01
I10
I92
I04
I01
I10
I92
I05
I01
I84
IB5
I82
I60
I84
IBD
I84
IB5
I81
I60
I84
IBD
I85
IB5
I82
I60
I85
IBD
I85
IB5
I81
I60
I85
IBD
IEE
IE6
IF0
IE0
I80
I81
I81
I60
I80
I83
IE1
IE8
IF0
IE0
I80
I81
I82
I60
I80
I83
I80
I81
I81
I60
I80
I83
IE0
IE8
IF0
IE0
I80
I81
I81
I60
I80
I83
IE1
IEB
IF0
IE0
I80
I81
I84
I60
I80
I83
IE0
IEB
IF0
IE0
I80
I81
I81
I60
I80
I83
IEA
IE7
IF0
IE0
I80
I81
I84
I60
I80
I83
I80
I81
I20
O14
O10
I55
I40
I01
I20
O14
O10
I64
I00
I80
I46
I82
I60
I80
I83
I80
I81
I81
I60
I80
I83
I80
I81
I80
I68
I80
I83
I10
I92
IC1
I00
I08
I95
I28
I2F
I33
I27
IC9
I01
I85
I57
I9F
I4F
IFC
I01
I94
I91
I29
I58
I3F
I4F
IF9
I01
I84
I91
I88
I23
I81
IF0
IE8
I2F
IFF
I27
IE8
I59
IFF
I4F
IE4
I91
IFF
I27
I66
I23
I29
IF4
I80
I81
I90
I95
I89
I23
I80
I83
I08
I95
I80
I81
I89
I2B
I80
I83
I08
I95
I48
I2F
I55
I27
ICA
I01
I81
I56
I9F
I4F
IFC
I01
I24
I91
ICA
I01
I85
I57
I9F
I4F
IFC
I01
I94
I91
I49
I58
I5F
I4F
IFA
I01
I34
I91
I33
I23
I19
IF4
I80
IE0
I90
IE0
I08
I95
I22
I23
I31
IF1
I20
O14
O10
I55
I80
I01
I20
O14
O10
I64
I00
I80
I46
I23
I30
I21
IF4
I80
I91
I80
I00
I8F
I77
I05
IC0
I24
I30
I31
IF4
I80
I91
I80
I00
I8F
I7D
I80
I93
I80
I00
I18
IC0
I21
I30
I19
IF4
I84
IB5
I8F
I77
I04
IC0
I22
I30
I21
IF4
I84
IB5
I8F
I7D
I84
IBD
I0D
IC0
I26
I30
I21
IF4
I80
I91
IB0
I00
I8F
I77
I05
IC0
I27
I30
I29
IF4
I80
I91
IB0
I00
I8F
I7D
I80
I93
IB0
I00
IE3
I2F
IFF
I27
IEE
I58
IFF
I4F
IE4
I91
IFF
I27
I80
I81
I20
IE0
I30
IE0
I89
I23
I11
IF0
I21
IE0
I30
IE0
IC9
I01
I08
I95
I48
I2F
I55
I27
ICA
I01
I81
I56
I9F
I4F
IFC
I01
I24
I91
ICA
I01
I85
I57
I9F
I4F
IFC
I01
I20
O14
O10
I55
IC0
I01
I20
O14
O10
I64
I00
I80
I46
I94
I91
I49
I58
I5F
I4F
IFA
I01
I34
I91
I33
I23
IC1
IF1
I22
I23
I31
IF1
I23
I30
I21
IF4
I80
I91
I80
I00
I8F
I77
I05
IC0
I24
I30
I31
IF4
I80
I91
I80
I00
I8F
I7D
I80
I93
I80
I00
I18
IC0
I21
I30
I19
IF4
I84
IB5
I8F
I77
I04
IC0
I22
I30
I21
IF4
I84
IB5
I8F
I7D
I84
IBD
I0D
IC0
I26
I30
I21
IF4
I80
I91
IB0
I00
I8F
I77
I05
IC0
I27
I30
I29
IF4
I80
I91
IB0
I00
I8F
I7D
I80
I93
IB0
I00
IE3
I2F
IFF
I27
IE3
I59
IFF
I4F
IE4
I91
IFF
I27
I66
I23
I29
IF4
I80
I81
I90
I95
I89
I23
I80
I83
I08
I95
I80
I81
I89
I2B
I80
I83
I08
I95
I20
O14
O10
I55
I00
I02
I20
O14
O10
I64
I00
I48
I46
IA1
IE2
I1A
I2E
IAA
I1B
IBB
I1B
IFD
I01
I0D
IC0
IAA
I1F
IBB
I1F
IEE
I1F
IFF
I1F
IA2
I17
IB3
I07
IE4
I07
IF5
I07
I20
IF0
IA2
I1B
IB3
I0B
IE4
I0B
IF5
I0B
I66
I1F
I77
I1F
I88
I1F
I99
I1F
I1A
I94
I69
IF7
I60
I95
I70
I95
I80
I95
I90
I95
I9B
I01
IAC
I01
IBD
I01
ICF
I01
I08
I95
IFF
ICF
I0D
I00
I20
O14
O10
I55
I00
I00
I20
O14
O10
I74
I00
I80
I46
I20
O14
O0C
O94
O5A
O00
O0C
O94
O77
O00
O0C
...
« Last Edit: January 30, 2009, 12:15:08 pm by dcb » Logged

Pages: [1]   Go Up
Jump to: