-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConvert-Gothic-Names.ps1
More file actions
114 lines (103 loc) · 4.08 KB
/
Convert-Gothic-Names.ps1
File metadata and controls
114 lines (103 loc) · 4.08 KB
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
<#
.SYNOPSIS
Converts a Gothic API Names.txt to the Union format
.DESCRIPTION
The Convert-Gothic-Names function reads a file with the export of all Gothic symbols with addresses0
and converts it to the format supported by Union Framework (tab-separated values)
.EXAMPLE
./Convert-Gothic-Names.ps1 -Filename Path/to/Gothic/Names.txt -OutputFilename Output_Names.tsv
# Convert file quietly
.EXAMPLE
./Convert-Gothic-Names.ps1 -Filename Path/to/Gothic/Names.txt -OutputFilename Output_Names.tsv -Warnings
# Print a warning if something can't be converted
.EXAMPLE
./Convert-Gothic-Names.ps1 -Filename Path/to/Gothic/Names.txt -OutputFilename Output_Names.tsv -Warnings -PrintStdOut
# Output the converted file contents to standard output
#>
param(
[Parameter(mandatory = $true, HelpMessage = "Input file")]
[string]$Filename,
[Parameter(mandatory = $false, HelpMessage = "Output file")]
[string]$OutputFilename,
[Parameter(mandatory = $false, HelpMessage = "Enable warnings about not converted line")]
[switch]$Warnings = $false,
[Parameter(mandatory = $false, HelpMessage = "Print output on stdout")]
[switch]$PrintStdOut = $false
)
function Convert-Gothic-Names
{
param(
[Parameter(mandatory = $true, HelpMessage = "Input file")]
[string]$Filename,
[Parameter(mandatory = $false, HelpMessage = "Output file")]
[string]$OutputFilename,
[Parameter(mandatory = $false, HelpMessage = "Enable warnings about not converted line")]
[switch]$Warnings = $false,
[Parameter(mandatory = $false, HelpMessage = "Print output on stdout")]
[switch]$PrintStdOut = $false
)
if (-not (Get-Item -Path $Filename).Exists)
{
Write-Error "Input file does not exist: $Filename"
return
}
$output = @()
$lines = Get-Content -Path $Filename
foreach ($line in $lines)
{
$originalLine = $line
$line = $line.Replace("public: ", "")
$line = $line.Replace("protected: ", "")
$line = $line.Replace("private: ", "")
$line = $line.Replace("static ", "")
$line = $line.Replace("virtual ", "")
$line = $line.Replace("enum ", "")
$line = $line.Replace("struct ", "")
$line = $line.Replace("[thunk]:", "")
$matches = [System.Text.RegularExpressions.Regex]::Matches(
$line,
"(0x[0-9A-F]+) ([a-zA-Z0-9\s_\*:&<>\(\),]+)?\s?(__[a-z]+) ([a-zA-Z0-9<> \*~]+::)?([^\(]+)\((.*)");
if (($matches.Count -eq 0) -and ($Warnings))
{
Write-Warning "Could not convert: $originalLine"
Write-Warning " pre-processed: $line"
}
foreach ($match in $matches)
{
$address = $match.Groups[1].Value
$returnType = $match.Groups[2].Value.Trim()
$callingConvention = $match.Groups[3].Value
$class = $match.Groups[4].Value.Replace("::", "")
$name = $match.Groups[5].Value
$arguments = $match.Groups[6].Value.Replace(",", "`t")
$arguments = $arguments.Replace("struct ", "")
$arguments = $arguments.Replace("class ", "")
$arguments = $arguments.Replace(" *", "*")
$arguments = $arguments.Replace(" &", "&")
$arguments = $arguments -replace "\)$",""
$out = @()
$out += $address
$out += $returnType
$out += $callingConvention
$out += $class
$out += $name
$out += $arguments
$outstring = [string]::Join("`t", $out)
$output += $outstring
if ($PrintStdOut)
{
Write-Host $outstring
}
}
}
if ($OutputFilename)
{
Set-Content -Path $OutputFilename -Value ([string]::Join("`n", $output)) -Force -ErrorVariable $ErrorMessage
if ($ErrorMessage)
{
Write-Error "Could not save the file: $ErrorMessage"
}
}
return $output
}
Convert-Gothic-Names @PSBoundParameters | Out-Null