Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 1241

Python • Using Python to patch a binary.

$
0
0
Hi Python-gurus here...

I am an absolute noob in Python.
I am at ease in c++ programming microcontrollers like the ESP8266.
I have written a quite intensive program cf.:
https://github.com/rin67630/Sound-press ... r-Booster.
My problem is that it requires from the users to install an IDE, libraries, configure, compile ...
That is mostly too much for the regular users.
I would like to distribute directly an executable, that is uploaded / flashed with an existing Python script: esptool.py.
https://docs.espressif.com/projects/esp ... est/esp32/

But this executable must be patched to get the WiFi credentials and the credentials of a Cloud account.

I can do it with a hex editor: search for a dummy unique String and overwrite that string with the requested credentials.
N.B. not replace ! Overwrite keeping the overall length of the dummy String and terminating the credential with a "null" character.
That works well, but the user has no hex-editor too.

So, since we need Python anyway, I figured to let Python do the job: load the executable, search for a dummy unique String and overwrite that string with the requested credentials, write the file back, and finally run esptool.py to upload the patched file.

That is surely a teasing challenge: the tricky part appears to be the search and overwriting, not a plain string replacement.

How would you do that?
I would highly appreciate if you could give me an example of that part of the code on which I could elaborate.
The rest (user interaction to get the credentials) is trivial, i can do that...
Thank you very much for your estimated help.


P.S. the usual way of doing it, being to program a temporary website to enter the credentials is just too much code for my weak ESP device: i am already a the max of code memory

Statistics: Posted by rin67630 — Tue Jul 02, 2024 8:07 pm



Viewing all articles
Browse latest Browse all 1241

Trending Articles