powershell- Function Convert-HexToByteArray {
-
- [cmdletbinding()]
-
- param(
- [parameter(Mandatory=$true)]
- [String]
- $HexString
- )
-
- $Bytes = [byte[]]::new($HexString.Length / 2)
-
- For($i=0; $i -lt $HexString.Length; $i+=2){
- $Bytes[$i/2] = [convert]::ToByte($HexString.Substring($i, 2), 16)
- }
-
- $Bytes
- }
-
- $bytes = [System.IO.File]::ReadAllBytes('title.tmd')
- $file = Get-ChildItem -recurse | Where{$_.Name -match "^[0-9a-fA-F]{8}$"}
- $nameBytes = Convert-HexToByteArray($file.Name)
- for ($i = 0; $i -lt 4; $i++) {
- $bytes[480+$i] = $nameBytes[$i]
- 'title.tmd: {0} => {1}' -f $bytes[480+$i],$nameBytes[$i]
- }
- [System.IO.File]::WriteAllBytes('title.tmd',$bytes)
复制代码
|