0

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

我怎样才能做到这一点 ?

4

2 回答 2

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);

希望这能推动您朝着正确的方向前进。

于 2012-05-29T18:23:11.973 回答
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 的命令行选项会很有帮助,以便我们可以帮助您构建适当的包装器。

于 2012-05-29T19:44:29.597 回答