2012-05-29 96 views
0

我想自动执行十六进制编辑, 十六进制编辑器是HxD.exe 我将HxD.exe复制到将被编辑的exe文件夹中。 我想某种: 开放hxd.exe开放etc.exe 变化0004A0-0004A3 00 00 80 3F 到 00 00 40 3F创建bat文件

我怎么能这样做?

回答

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

希望这能为您带来正确的方向。

0

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

复制以下到一个名为编辑-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的命令行选项会很有帮助,以便我们可以帮助您构建适当的包装。