Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.arch.embedded > #32133

Re: Patch fixed strings in .hex file

From David Brown <david.brown@hesbynett.no>
Newsgroups comp.arch.embedded
Subject Re: Patch fixed strings in .hex file
Date 2024-01-16 18:50 +0100
Organization A noiseless patient Spider
Message-ID <uo6fl2$1i0eu$2@dont-email.me> (permalink)
References <uo5s8d$1cjl8$1@dont-email.me> <uo5u4r$1e6ae$1@dont-email.me> <uo64kj$1cjl7$1@dont-email.me> <1t86o9tvhrt2a.o9j4cdok7vth$.dlg@40tude.net>

Show all headers | View raw


On 16/01/2024 16:47, dalai lamah wrote:
> Un bel giorno pozz digitò:
> 
>>> In the source code, put the serial number in as "PQRXYZ" or some other
>>> distinct string of characters.  Generate bin files, not hex (or convert
>>> with objcopy).  Then do a simple search for the special string to find
>>> its position and replace it with the serial number using a simple Python
>>> script or your other favourite tool (awk, sed, perl, whatever).
>>
>> I thought about this approach, but is it so difficult to have the same
>> exact sequence of bytes somewhere else in the output?
> 
> Extremely unlikely, especially since you use text strings and therefore you
> actually use 64 bits (eigth ASCII characters) to represent a 32 bit number.
> Besides, you don't need to use an ASCII string as the placeholder, you can
> use any 64 bit number.
> 
> If for example your binary file is 1 MB, there is one chance over 2.2
> trillion to have the same number duplicated somewhere else.
> 
>>> Oh, and in the source code, don't forget to make the string "volatile".
>>
>> Why?
> 
> To avoid that the compiler will optimize the code and "obfuscate" your
> string. I don't think it is very likely, but it is not impossible,
> especially if you use a very aggressive optimization level.
> 

Actually, this sort of thing really does happen in practice.  In one of 
my current projects, I have some data that is filled in by 
post-processing the binary file, and I had to use volatile accesses to 
read the data or the compiler would optimise based on its knowledge of 
the contents it saw at compile time.  This is not just theoretical.

(To be fair, it is a bit more likely if - like in my case - the source 
file uses null characters rather than a pseudo-random string of characters.)

Back to comp.arch.embedded | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Patch fixed strings in .hex file pozz <pozzugno@gmail.com> - 2024-01-16 13:19 +0100
  Re: Patch fixed strings in .hex file David Brown <david.brown@hesbynett.no> - 2024-01-16 13:51 +0100
    Re: Patch fixed strings in .hex file pozz <pozzugno@gmail.com> - 2024-01-16 15:42 +0100
      Re: Patch fixed strings in .hex file David Brown <david.brown@hesbynett.no> - 2024-01-16 16:36 +0100
        Re: Patch fixed strings in .hex file pozz <pozzugno@gmail.com> - 2024-01-16 16:57 +0100
      Re: Patch fixed strings in .hex file dalai lamah <antonio12358@hotmail.com> - 2024-01-16 16:47 +0100
        Re: Patch fixed strings in .hex file David Brown <david.brown@hesbynett.no> - 2024-01-16 18:50 +0100
  Re: Patch fixed strings in .hex file Herbert Kleebauer <klee@unibwm.de> - 2024-01-16 15:07 +0100
    Re: Patch fixed strings in .hex file pozz <pozzugno@gmail.com> - 2024-01-16 15:42 +0100
  Re: Patch fixed strings in .hex file Grant Edwards <invalid@invalid.invalid> - 2024-01-16 15:24 +0000
    Re: Patch fixed strings in .hex file David Brown <david.brown@hesbynett.no> - 2024-01-16 16:38 +0100
      Re: Patch fixed strings in .hex file Grant Edwards <invalid@invalid.invalid> - 2024-01-16 18:32 +0000
    Re: Patch fixed strings in .hex file pozz <pozzugno@gmail.com> - 2024-01-16 17:01 +0100
  Re: Patch fixed strings in .hex file David Brown <david.brown@hesbynett.no> - 2024-01-16 16:39 +0100
    Re: Patch fixed strings in .hex file Tauno Voipio <tauno.voipio@notused.fi.invalid> - 2024-01-17 20:19 +0200
  Re: Patch fixed strings in .hex file Stefan Reuther <stefan.news@arcor.de> - 2024-01-16 17:44 +0100
    Re: Patch fixed strings in .hex file Grant Edwards <invalid@invalid.invalid> - 2024-01-16 18:39 +0000
    Re: Patch fixed strings in .hex file Michael Schwingen <news-1513678000@discworld.dascon.de> - 2024-01-16 19:30 +0000
  Re: Patch fixed strings in .hex file Hans-Bernhard Bröker <HBBroeker@gmail.com> - 2024-01-16 19:35 +0100
    Re: Patch fixed strings in .hex file pozz <pozzugno@gmail.com> - 2024-01-17 08:45 +0100
      Re: Patch fixed strings in .hex file pozz <pozzugno@gmail.com> - 2024-01-17 09:07 +0100
      Re: Patch fixed strings in .hex file David Brown <david.brown@hesbynett.no> - 2024-01-17 11:27 +0100
        Re: Patch fixed strings in .hex file pozz <pozzugno@gmail.com> - 2024-01-17 12:54 +0100
          Re: Patch fixed strings in .hex file David Brown <david.brown@hesbynett.no> - 2024-01-17 13:54 +0100
          Re: Patch fixed strings in .hex file Stefan Reuther <stefan.news@arcor.de> - 2024-01-17 17:39 +0100
            Re: Patch fixed strings in .hex file David Brown <david.brown@hesbynett.no> - 2024-01-17 18:28 +0100
            Re: Patch fixed strings in .hex file Grant Edwards <invalid@invalid.invalid> - 2024-01-17 19:00 +0000
            Re: Patch fixed strings in .hex file pozz <pozzugno@gmail.com> - 2024-01-19 09:10 +0100
      Re: Patch fixed strings in .hex file Hans-Bernhard Bröker <HBBroeker@gmail.com> - 2024-01-18 18:49 +0100
  Re: Patch fixed strings in .hex file pozz <pozzugno@gmail.com> - 2024-01-17 09:57 +0100
  Re: Patch fixed strings in .hex file Don Y <blockedofcourse@foo.invalid> - 2024-01-17 10:03 -0700
  Re: Patch fixed strings in .hex file Paul Rubin <no.email@nospam.invalid> - 2024-01-17 21:42 -0800

csiph-web