创建一个bat文件

时间:2012-05-29 18:03:32

标签: file batch-file automation hex edit

我想自动执行十六进制编辑, 十六进制编辑器是HxD.exe 我将HxD.exe复制到与将编辑的exe相同的文件夹。 我想要某种形式: 打开hxd.exe打开etcexe 更改0004A0-0004A3 00 00 80 3F 至 00 00 40 3F

我该怎么做?

2 个答案:

答案 0 :(得分:0)

在不知道HxD.exe的细节的情况下,很难准确说出来。但是,您可以使用Windows PowerShell来实现周围的操作。例如:

# Assuming hxd.exe and <SourceFile> exist in c:\MyFolder
Set-Location -Path:c:\MyFolder;
# 
Start-Process -FilePath:hxd.exe -ArgumentList:'-hxd args -go here';

您也可以设置流程的工作目录,而不是更改当前目录上下文:

Start-Process -WorkingDirectory:c:\MyFolder -FilePath:hxd.exe -ArgumentList:'-hxd args -go here';

根据hxd.exe的工作方式,您也可以将hxd.exe放在任意文件夹中,并使用其绝对路径传入源文件:

$SourceFile = 'c:\MyFolder\sourcefile.bin';
$HxD = 'c:\path\to\hxd.exe';
Start-Process -FilePath $HxD -ArgumentList ('-SourceFile "{0}" -Range 0004A0-0004A3' -f $SourceFile);

希望这能让你朝着正确的方向前进。

答案 1 :(得分:0)

我没有看到HxD网站上列出的任何命令行选项,所以我将给你一个纯PowerShell替代方案,假设编辑文件对你来说比你用来制作文件的程序更重要。编辑(并且您可以使用PowerShell)...

将以下内容复制到名为Edit-Hex.ps1的文件中:

<#
.Parameter FileName
The name of the file to open for editing.

.Parameter EditPosition
The position in the file to start writing to.

.Parameter NewBytes
The array of new bytes to write, starting at $EditPosition
#>
param(
    $FileName,
    $EditPosition,
    [Byte[]]$NewBytes
)
$FileName = (Resolve-Path $FileName).Path
if([System.IO.File]::Exists($FileName)) {
    $File = $null
    try {
        $File = [System.IO.File]::Open($FileName, [System.IO.FileMode]::Open)
        $File.Position = $EditPosition
        $File.Write($NewBytes, 0, $NewBytes.Length)
    } finally {
        if($File -ne $null) {
            try {
                $File.Close()
                $File = $null
            } catch {}
        }
    }
} else {
    Write-Error "$Filename does not exist"
}

那么你的例子就是这样的:

.\Edit-Hex.ps1 -FileName c:\temp\etc.exe -EditPosition 0x4a0 -NewBytes 00,00,0x40,0x3f

请注意,必须将新值作为逗号分隔列表输入以生成数组,并且默认情况下,这些值将被解释为十进制,因此您需要转换为十进制或使用0x00格式输入十六进制。

如果这对你不起作用,那么为HxD提供命令行选项会很有帮助,这样我们就可以帮助你构建一个合适的包装器。

相关问题