In a nutshell: I've sniffed the data that goes from the controlling PC to the modem via RS232 serial port by building a little Y-adapter, now I want to figure out how to reverse engineer that data so that I can have full access to the device. My approach is to do one operation at a time and look for a pattern in the incoming data.

However, I have some problems with the code I received by using PySerial in Python. I hope you can help me. Here is an example for one single operation:

b'_S\xf0\xfb\x15\xf5_S\xf0S%\xc5_S\xf0\x1bY\xf7_S\xf0\xda\xd1\xf7_S\xf0_=\xf3' (marked as byte string by the 'b')

Or sorted as 'question' and 'answer': data sent by DTE (left) and DCE (right)

    DTE (PC)  DCE (modem)
    _S\xf0    \xfb\x15\xf5 
    _S\xf0    S%\xc5 
    _S\xf0    \x1bY\xf7 
    _S\xf0    \xda\xd1\xf7 
    _S\xf0    _=\xf3 

As you can see some of it is hexadecimal code (marked by the '/x')- some of it is not. I tried to understand it for quite some time now, but I'm still not sure if this is really the raw code or Python has to convert some of it to ASCII on order to be able to show it to me (like the '_S' letters).

I need to know this because as a next step I want my Python script to act as the new controlling PC. For this I want to use the serial.write-command of PySerial. It seems that it doesn't work to just send the string I received. Maybe I made some other mistake but my question remains: is this the raw code the device sends and receives? Or do I have to convert it some other way?

Thanks in advance. Tobi


I would just put this as a comment but I don't have enough rep yet. Yes your correct, Python is showing some characters as their ASCII representations. The ones marked as hexadecimal are the characters that don't have a printable ASCII representation. Using that string as-is should work fine to send with write.

EDIT: maybe I don't quite understand but if you want to mimic the controlling PC (or the modem for that matter) you only want to send half of the data you have sniffed to the other device (i.e the "question"s or DTE (whatever that means)). Sending all data sniffed to a single device would likely end in confusion.

EDIT#2: From your comment, it seems as though you are unsure of how binary data (i.e. data consisting of mostly non-printable characters) can be represented in strings:

"_" == "\x5f" # => True
"S" == "\x53" # => True
# therefore:
b'_S\xf0' == '\x5f\x53\xf0' # => True

Hexadecimal is merely another way of representing ASCII characters and is just for us humans. While it may look like its in two forms when printed, in memory its all just bytes. Its tricky to explain and its one of these things that you'll just eventually understand. I couldn't find a good tutorial on it unfortunately.

  • Thank you for your answer. Firstly: yes, I want to mimic the controlling PC (which would be the 'DTE'). By disconnecting some cables off my adapter I am pretty sure to know which data came from the modem and which came from the PC. Therefore I know what to send. Are you sure sending the string as-is would work? I mean, if they are in fact ASCII representations? As I understand the part with hexadecimal code is really like the 'raw' data, but the ASCII letters are the converted ones, which would mean I cannot send them simply in that form... I thought? – Tobitobitobi Jan 20 '17 at 9:38
  • I've updated my answer. If its full duplex serial, are you sure you've got the transmit/recieve connected the right way round now its an endpoint? – scruffy Jan 20 '17 at 16:01
  • As you said "its one of these things that you'll just eventually understand" and I just got it. Thanks scruffy! I believe its half-duplex. However, after reading your answer I'm not sure anymore if I connected it the right way. I'll check again on monday, when I have access to the device again. So thanks a second time! – Tobitobitobi Jan 21 '17 at 17:54

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.