forked from pret/pokeemerald
-
Notifications
You must be signed in to change notification settings - Fork 3
/
asmdiff.ps1
116 lines (94 loc) · 2.87 KB
/
asmdiff.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
Param
(
[Parameter(Position = 0)]
[string]$Start,
[Parameter(Position = 1)]
[string]$Offset,
[Parameter()]
[string[]]$DiffTool
)
$ErrorActionPreference = "Stop"
$offset_default_value = "0x100"
$diff_tool_default_value = "diff"
$help = "
$($args[0]) [OPTIONS] Start [Offset]
Performs a diff on the assembly of a function in a rom. 'Start' is the start
location of the function, and 'Offset' is the number of bytes to disassemble.
The assembly is saved to *.dump files.
'Offset' is optional, and defaults to $offset_default_value. If this value is
very large (0x10000+), objdump may hang / freeze.
Requirements:
- A clean copy of the rom named 'baserom.gba'.
- $$ENV:DEVKITARM to point to the installation of devkitpro. By default, it is
installed to 'C:\devkitpro\devkitARM'.
Options:
-DiffTool <tool> The tool to use for diffing. Defaults to '$diff_tool_default_value'. For VSCode,
you can use -DiffTool 'code --diff'. (Quotes are necessary around 'code --diff')
"
if ((-not (Test-Path variable:Start)) -or [string]::IsNullOrWhiteSpace($Start))
{
Write-Host $help
exit
}
if (-not (Test-Path variable:DiffTool) -or [string]::IsNullOrWhiteSpace($DiffTool))
{
$DiffTool = $diff_tool_default_value
}
if (-not (Test-Path variable:Offset) -or [string]::IsNullOrWhiteSpace($Offset))
{
$Offset = $offset_default_value
}
if (-Not (Test-Path env:DEVKITARM))
{
Write-Host "ENV:DEVKITARM variable not set."
Write-Host $help
exit
}
if (-Not (Test-Path $env:DEVKITARM))
{
Write-Host "DEVKITARM path '$env:DEVKITARM' does not exist."
Write-Host $help
exit
}
if (-Not (Test-Path ".\pokeemerald.gba"))
{
Write-Host "File 'pokeemerald.gba' not found."
Write-Host $help
exit
}
if (-Not (Test-Path ".\baserom.gba"))
{
Write-Host "File 'baserom.gba' not found."
}
try
{
$start_num = [System.Convert]::ToUInt64($Start, 16)
}
catch
{
Write-Host "Error parsing '$start_num' as a hex number."
Write-Host $help
exit
}
try
{
$offset_num = [System.Convert]::ToUInt64($Offset, 16)
}
catch
{
Write-Host "Error parsing '$offset_num' as a hex number."
Write-Host $help
exit
}
if ($start_num -gt 0x1000000)
{
Write-Host "Warning: Start address is larger than the ROM file. Hint: ignore the leading number in the address."
}
$end_str = [System.Convert]::ToString($start_num + $offset_num, 16)
$end_str = "0x$end_str"
$start_str = "0x$Start"
Write-Host "$start_str - $end_str"
$objdump = Join-Path -Path $env:DEVKITARM -ChildPath "arm-none-eabi\bin\objdump.exe"
&$objdump -D -bbinary -marmv4t -Mforce-thumb --start-address="$start_str" --stop-address="$end_str" .\baserom.gba > .\baserom.dump
&$objdump -D -bbinary -marmv4t -Mforce-thumb --start-address="$start_str" --stop-address="$end_str" .\pokeemerald.gba > .\pokeemerald.dump
Invoke-Expression "$DiffTool .\baserom.dump .\pokeemerald.dump"