Edit Binary File
Posted: 10 Mar 2019 12:08
Hello friends! I need a script ...
Who could help me?
Basically I would like to create a program to edit a binary file.
That is, it should look for the hexadecimal in the offsets and replace them with the ones I set them.
Obviously you do not have to give a search command, but you have to go looking for it.
I have created this! but I do not search because I set the offsets
In practice it is a program to remove EGR control on cars! But unfortunately with the same ECU sometimes the offsets change and set an offset is not good because I would like the program to be able to find the bits to change ...
OPEN PROGRAM TO CLICK ON SELECT.BAT
EGROFF.BAT
Can you help me create this little program?
Who could help me?
Basically I would like to create a program to edit a binary file.
That is, it should look for the hexadecimal in the offsets and replace them with the ones I set them.
Obviously you do not have to give a search command, but you have to go looking for it.
I have created this! but I do not search because I set the offsets
In practice it is a program to remove EGR control on cars! But unfortunately with the same ECU sometimes the offsets change and set an offset is not good because I would like the program to be able to find the bits to change ...
OPEN PROGRAM TO CLICK ON SELECT.BAT
Code: Select all
<# : chooser.bat
@echo off
setlocal
for /f "delims=" %%I in ('powershell -noprofile "iex (${%~f0} | out-string)"') do (
start C:\SolutionDPFErasePack\Fiat\mjd6f3\egroff.bat %%~I
exit
)
goto :EOF
: end Batch portion / begin PowerShell hybrid chimera #>
Add-Type -AssemblyName System.Windows.Forms
$f = new-object Windows.Forms.OpenFileDialog
$f.InitialDirectory = pwd
$f.Filter = "File Binari (*.bin)|*.bin|File Ori (*.ori*)|*.ori*|Tutti i File (*.*)|*.*"
$f.ShowHelp = $false
$f.Multiselect = $false
[void]$f.ShowDialog()
if ($f.Multiselect) { $f.FileNames } else { $f.FileName }
Code: Select all
MKDIR "%userprofile%\desktop\File DPFErasePack"
if exist "%userprofile%\desktop\File DPFErasePack" Erase /F /S /Q "%userprofile%\desktop\File DPFErasePack"
xcopy %1 "%userprofile%\desktop\File DPFErasePack"
@echo off
setlocal EnableDelayedExpansion
rem FILE TRASCINATO SUL BAT
set "file=%1"
for %%a in ("%file%") do set "hex=%%~Na.hex"
rem Specifica i valori Offset da cambiare
set "changes=84750:B9 84751:92"
rem Codifica il file in HEX
certutil -f -encodehex "%file%" "%hex%"
rem Crea una lista di line-offsets per cercare i valori Offset da Modificare
set "offsets="
for %%c in (%changes%) do for /F "tokens=1,2 delims=:" %%a in ("%%c") do (
set "offset=%%a"
set "offsets=!offsets! !offset:~0,-1!"
)
rem Converti line-Offsets in un elenco di numeri in riga
set "lines="
for /F "delims=:" %%a in ('findstr /N /I "%offsets%" "%hex%"') do set "lines=!lines! %%a"
rem Elabora il file esadecimale ed esegue le modifiche desiderate
set "tokens=%%A %%B %%C %%D %%E %%F %%G %%H %%I %%J %%K %%L %%M %%N %%O %%P %%Q"
set "letter=ABCDEFGHIJKLMNOPQ"
for /F "tokens=1*" %%a in ("%changes%") do set "change=%%a" & set "changes=%%b"
set "last=1"
< "%hex%" (
rem Elabora le linee di destinazione
for %%l in (%lines%) do (
rem Copia le linee tra quelle di destinazione
set /A skip=%%l-last, last=%%l+1
for /L %%i in (1,1,!skip!) do (
set /P "line="
echo !line!
)
rem Elabora la linea di destinazione
set /P "line="
for /F "tokens=1*" %%x in ("!line!") do (
set "ofs=%%x" & set "values=%%y"
for /L %%# in (1,1,16) do for /F "tokens=1,2 delims=:" %%a in ("!change!") do (
set "offset=%%a"
if /I "!offset:~0,-1!" equ "!ofs!" (
set /A "token=0x!offset:~-1!"
for /F %%x in ("!token!") do for /F %%y in ("!letter:~%%x,1!") do call :ChangeValue %%y
if defined changes (
for /F "tokens=1*" %%x in ("!changes!") do set "change=%%x" & set "changes=%%y"
) else (
set "change="
)
)
)
)
echo !ofs! !values!
)
rem Copia le linee dopo l'ultima destinazione
findstr "^"
) > temp.hex
del "%hex%"
set "name=%~n1"
rem Codifica file HEX in file NOEGR.bin
certutil -f -decodehex temp.hex %name%NOEGR.bin
xcopy %name%NOEGR.bin "%userprofile%\desktop\File DPFErasePack"
del temp.hex
del %name%NOEGR.bin
goto :EOF
:ChangeValue token
set "newVals=!tokens:%1=b!"
for /F "tokens=1-16*" %%A in ("%values%") do set "values=%newVals%"
exit /B