The VG Resource
hex editing multiple files - Printable Version

+- The VG Resource (https://www.vg-resource.com)
+-- Forum: Discussion Boards (https://www.vg-resource.com/forum-133.html)
+--- Forum: Help me! (https://www.vg-resource.com/forum-137.html)
+--- Thread: hex editing multiple files (/thread-27227.html)



hex editing multiple files - SuperFlomm - 06-02-2015

The Sims 1 has sound files in XA format. I can convert them with Audacity to wav or mp3. However Audacity refuses to load most of them because they have a broken(?) header. A simple hex edit can fix this but there are over 3000 files and I have only extracted them from the Makin' Magic addon.

Is there a way to fix all the files in one go? I really don't want to edit each file manually. Unimpressed


RE: hex editing multiple files - Petie - 06-02-2015

You could do it from the command line (natively on Mac and Linux, probably also available on Windows in some way or another) with the command "sed" and a regular expression.

An example is available here: http://unix.stackexchange.com/questions/78625/using-sed-to-find-and-replace-complex-string-preferrably-with-regex

I can also probably format the command for you if you tell me what you're replacing with what.


RE: hex editing multiple files - SuperFlomm - 06-02-2015

Yes, Windows has a command line. Natively there is no sed command but I found this. Should work right?

This is what I have to do to make it load.
   


RE: hex editing multiple files - Petie - 06-02-2015

Can you upload a zip of a few of the files so I can see how they look when edited directly and also test the code?


RE: hex editing multiple files - SuperFlomm - 06-02-2015

Here you go. clown_cry_sfx3.XA is the only working file.


RE: hex editing multiple files - puggsoy - 06-03-2015

Put all your files in a folder, for simplicity let's say you put it in C:\MyFiles. Then you'd use this script:

Code:
Get-ChildItem "C:\MyFiles" -Filter *.XA | `
Foreach-Object{
   $bytes = [System.IO.File]::ReadAllBytes($_.FullName);
   $bytes[2] = 0x4A;
   
   [System.IO.File]::WriteAllBytes("C:\MyFiles\" + $_.BaseName + ".XA", $bytes);
}

Change the directory on the first and second-to-last lines to the one your files are actually in. Make sure it's the absolute path, with the drive letter and everything. Save the file with a .ps1 extension.

To use this you need to run PowerShell in administrator mode. PowerShell comes along with Windows 7 and later, for previous versions you can download it manually.
Navigate to the place your script is in (using the "cd" command) and then run it using "& scriptname.ps1". I don't know how long it'll take but once it's done you'll be able to type stuff into the console again.

Not sure if sed is a better option, if it works and is easier than this then that's good. I found this though and thought it's pretty neat, I didn't even know this was possible before now Smile


RE: hex editing multiple files - SuperFlomm - 06-03-2015

(06-03-2015, 02:18 AM)puggsoy Wrote:
Code:
Get-ChildItem "C:\MyFiles" -Filter *.XA | `
Foreach-Object{
   $bytes = [System.IO.File]::ReadAllBytes($_.FullName);
   $bytes[2] = 0x4A;
   
   [System.IO.File]::WriteAllBytes("C:\MyFiles\" + $_.BaseName + ".XA", $bytes);
}

Thank you! This works beautifully. Good Job.
A small bug though: the .txt in the first line has to be .XA Wink


RE: hex editing multiple files - Petie - 06-03-2015

Very nice! I hadn't even thought about using PowerShell but it's perfectly suited to this task.

As I expected, the files are gibberish when opened directly so sed wouldn't have even worked directly. Apparently, you can do hex replacements in most modern versions of it but it would have been much more complicated than the PS script puggsoy provided.


RE: hex editing multiple files - puggsoy - 06-03-2015

(06-03-2015, 12:25 PM)SuperFlomm Wrote: A small bug though: the .txt in the first line has to be .XA Wink

Whoops, nice catch. Fixed my post, just for correctness.