echo "PA02_2303221" | dd of=./pa02_head.bin bs=1 seek=32 count=12 conv=notrunc 帮我写一个bat脚本,不使用dd程序,也能实现上面linux脚本的功能,即把字符串修改到二进制文件当中,
时间: 2023-05-20 07:06:22 浏览: 71
以下是一个可以实现相同功能的 Windows 批处理脚本:
@echo off
setlocal EnableDelayedExpansion
set "string=PA02_2303221"
set "file=./pa02_head.bin"
set "offset=32"
set "length=12"
set /a "start=%offset% - 1"
set /a "end=%offset% + %length% - 1"
set "hex="
for /l %%i in (%start%, 1, %end%) do (
set "char=!string:~%%i,%1!"
set /a "char=0x!char!"
set "hex=!hex! !char!"
)
for /f "tokens=1-3" %%a in ('certutil -f -encodehex - "%file%" ^| findstr /i /c:"[0-9a-f][0-9a-f]:"') do (
set "line=%%c"
set "line=!line:~2!"
set "line=!line: =!"
set "line=!line: =!"
set "line=!line:~0,%start!*2!!hex!!line:%end%*2%,!"
set "line=!line: =!"
set "line=!line:~0,-2!"
echo !line!>>"%file%.new"
)
move /y "%file%.new" "%file%" >nul
echo Done.
阅读全文