-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatch_sof_binary.ps1
48 lines (37 loc) · 1.35 KB
/
patch_sof_binary.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Function to convert ASCII string to byte array
function Convert-StringToBytes($asciiString) {
$encoding = [System.Text.Encoding]::ASCII
$byteArray = $encoding.GetBytes($asciiString)
return $byteArray
}
# Function to write hex bytes directly to a file at a specified offset
function Write-HexBytes($filePath, $offset, $hexBytes) {
$fileContent = [System.IO.File]::ReadAllBytes($filePath)
for ($i = 0; $i -lt $hexBytes.Length; $i++) {
$fileContent[$offset + $i] = $hexBytes[$i]
}
[IO.File]::WriteAllBytes($filePath, $fileContent)
}
# must supply a string
if (-not $args) {
Write-Output "Error: string to write is required."
Exit 1
}
Write-Output "Linking SoF.exe to $($args[0])"
# Get the script directory using a compatible method
$scriptDirectory = Split-Path -Parent $MyInvocation.MyCommand.Definition
$binaryFilePath = "$scriptDirectory\SoF.exe"
# Check if the .exe file exists
if (Test-Path "$binaryFilePath" -PathType Leaf) {
Write-Output "Found SoF.exe at $binaryFilePath"
} else {
Write-Output "Run this script inside your SoF root directory"
Exit 1
}
$offset = 0x11AD72
$userAsciiString = $args[0]
$userByteArray = Convert-StringToBytes $userAsciiString
$userByteArray += 0x00
Write-HexBytes "$binaryFilePath" $offset $userByteArray
Write-Output "Patching completed."
Read-Host -Prompt "Press Enter to exit"