0

I'm working with a block of data dumped form a EEPROM chip. I'm doing some reverse engineering. I have it read into python as an array (this is an example fragment):

my_array = [63, 67, 62, 127, 106, 241, 65, 219, 249, 02, 03, 05, 03, 255, 255, 01, 01, 03]

I know for example that:

  • The first 3 bytes are an ASCII string with the serial code of the device [63, 67, 62]
  • The following 4 bytes are a 32-bit integer (little endian!) [127, 106, 241, 65]
  • The following 2 bytes are two 8-bit variables [219] [249]
  • The following 4 bytes are a BCD fixed decimal [02, 03, 05, 03] (i.e. 23.53)
  • The following 2 bytes are empty [255, 255]
  • The following 3 bytes are 8-bit variables with single bit flag settings [01, 01, 03]

Now... Some of these I know and some are guesses, which in my case doesn't matter because I'm looking only for like 3 variables in total. The idea is that I dump the memory chip, modify the values and upload it back.

It's annoying having to work with messed up bytes like this. Different data types, lengths, endianness etc. What I would like is some kind on mapping class, where I can put in my array, and then define a map of the memory space to python variables. I might need to add get/set function for some of the weird ones like BDC with decimal point, but that's ok.

I imagine this to look as such (changing the serial code in the first 3 bytes):

my_array = [63, 67, 62, 127, 106, 241, 65, 219, 249, 02, 03, 05, 03, 255, 255, 01, 01, 03]

my_map = {### some mapping of variable names, their length, type, etc###}

data_block = mapper(my_array, my_map)
data_block.serial = 'abc'
print(data_block)

[61, 62, 63, 127, 106, 241, 65, 219, 249, 02, 03, 05, 03, 255, 255, 01, 01, 03]

Is there a smart way of doing this? Maybe a library/tool for it?

Wojciech
  • 1
  • 2
  • create your own class/protocol to read the data? – gold_cy Jun 21 '21 at 11:12
  • Really... I'm asking the question because if there's something like this already, there's no point in spending 10 hours writing it on my own. And even if there's nothing like it, I'm asking for a "smart way of doing this" - i.e. some design pattern or data structure that would best fit this problem – Wojciech Jun 21 '21 at 12:46

0 Answers0