title: Is it possible to edit a binary file using Windows command line?
body: <p>Is there a way in Windows to edit a binary file, from the command line? i.e. a way that could be written into a batch file?</p>
  
  <p>I want to be able to edit a single byte, at a known position, in an existing file.</p>
  
  <p>This existing question[1] is solved, but that's a Linux solution. I'm looking for something similar for Windows.</p>
  
  <p><strong>Background</strong></p>
  
  <p>There's a bug in GTA 1 when downloaded from Steam whereby the save-game data file gets corrupted on exit. As a result, the game can be played fine the first time but subsequently crashes. It turns out this can be fixed by changing the 5th byte in the file (i.e. the byte at address 0x04) from x00 to x06[2].</p>
  
  <p>I can do this in Python easily, e.g.:</p>
  
  <pre><code>with open("PLAYER_A.DAT", "rb") as f:
      bytes = f.read()
  bytes = bytes[:4] + '\x06' + bytes[5:]
  with open("PLAYER_A.DAT", "wb") as g:
      for b in bytes: g.write(b)
  </code></pre>
  
  <p>Ideally though I'd rather do this in a batch job that does the following:</p>
  
  <ul>
  <li>fixes the data file</li>
  <li>launches GTA</li>
  </ul>
  
  <p>I could make something that works for me (using Python), but that wouldn't help random other people who don't have Python (yes I know it's easy to get &amp; install, but still). Similarly, there is a freeware available that claims to do just this, but I don't want to run a random .exe on my PC, and I don't think anyone else should either. For that reason, I'd like to present a batch file, that people can inspect, and - if they're happy with what it does - run for themselves.</p>
  
  <p>Thanks for you help!</p>
  
  <p>[1] <a href="https://stackoverflow.com/questions/4783657/cli-write-byte-at-address-hexedit-modify-binary-from-the-command-line">CLI: Write byte at address (hexedit/modify binary from the command line)</a></p>
  
  <p>[2] <a href="http://forums.steampowered.com/forums/showthread.php?t=1597746" rel="nofollow noreferrer">http://forums.steampowered.com/forums/showthread.php?t=1597746</a></p>
  
  <p>[edit] Fixed up the Python script, as I found it didn't work as-is (file.read() returns an immutable object, so you can't just update one of the values).</p>