/
NativeFiles.cs
198 lines (197 loc) · 4.62 KB
/
NativeFiles.cs
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Decompiler
{
class NativeFile : Dictionary<uint, string>
{
public string nativefromhash(uint hash)
{
if (Program.nativefile.ContainsKey(hash))
{
return this[hash];
}
else
{
string temps = hash.ToString("X");
while (temps.Length < 8)
temps = "0" + temps;
return "unk_0x" + temps;
}
}
public Dictionary<string, uint> revmap = new Dictionary<string, uint>();
public NativeFile(Stream Nativefile) : base()
{
StreamReader sr = new StreamReader(Nativefile);
while (!sr.EndOfStream)
{
string line = sr.ReadLine();
if (line.Length > 1)
{
string[] data = line.Split(':');
if (data.Length != 3)
continue;
string val = data[0];
if(val.StartsWith("0x"))
{
val = val.Substring(2);
}
uint value;
if (uint.TryParse(val, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out value))
{
if (!ContainsKey(value))
{
string nat = (Program.Show_Nat_Namespace ? (data[1] + "::") : "");
if(Program.Upper_Natives)
{
nat = nat.ToUpper();
if(data[2].StartsWith("_0x"))
{
nat += data[2].Remove(3) + data[2].Substring(3).ToUpper();
}
else
{
nat += data[2].ToUpper();
}
}
else
{
nat = nat.ToLower();
if(data[2].StartsWith("_0x"))
{
nat += data[2].Remove(3) + data[2].Substring(3).ToUpper();
}
else
{
nat += data[2].ToLower();
}
}
Add(value, nat);
revmap.Add(nat, value);
}
}
}
}
sr.Close();
}
}
class x64NativeFile : Dictionary<ulong, string>
{
public ulong TranslateHash(ulong hash)
{
while (TranslationTable.ContainsKey(hash))
{
hash = TranslationTable[hash];
}
return hash;
}
public string nativefromhash(ulong hash)
{
if (Program.x64nativefile.ContainsKey(hash))
{
return this[hash];
}
else
{
string temps = hash.ToString("X");
while (temps.Length < 8)
temps = "0" + temps;
return "unk_0x" + temps;
}
}
public Dictionary<string, ulong> revmap = new Dictionary<string, ulong>();
public Dictionary<ulong, ulong> TranslationTable = new Dictionary<ulong, ulong>();
public x64NativeFile(Stream Nativefile)
: base()
{
StreamReader sr = new StreamReader(Nativefile);
while (!sr.EndOfStream)
{
string line = sr.ReadLine();
if (line.Length > 1)
{
string[] data = line.Split(':');
if (data.Length != 3)
continue;
string val = data[0];
if(val.StartsWith("0x"))
{
val = val.Substring(2);
}
ulong value;
if (ulong.TryParse(val, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out value))
{
string nat = (Program.Show_Nat_Namespace ? (data[1] + "::") : "");
if(Program.Upper_Natives)
{
nat = nat.ToUpper();
if(data[2].StartsWith("_0x"))
{
nat += data[2].Remove(3) + data[2].Substring(3).ToUpper();
}
else
{
nat += data[2].ToUpper();
}
}
else
{
nat = nat.ToLower();
if(data[2].StartsWith("_0x"))
{
nat += data[2].Remove(3) + data[2].Substring(3).ToUpper();
}
else
{
nat += data[2].ToLower();
}
}
if (!ContainsKey(value))
{
Add(value, nat);
revmap.Add(nat, value);
}
}
}
}
sr.Close();
Stream Decompressed = new MemoryStream();
Stream Compressed = new MemoryStream(Properties.Resources.native_translation);
DeflateStream deflate = new DeflateStream(Compressed, CompressionMode.Decompress);
deflate.CopyTo(Decompressed);
deflate.Dispose();
Decompressed.Position = 0;
sr = new StreamReader(Decompressed);
while (!sr.EndOfStream)
{
string line = sr.ReadLine();
if (line.Length > 1)
{
string val = line.Remove(line.IndexOfAny(new char[] { ':', '=' }));
string nat = line.Substring(val.Length + 1);
ulong newer;
ulong older;
if (ulong.TryParse(val, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out newer))
{
if (!ContainsKey(newer))
{
if (ulong.TryParse(nat, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out older))
{
if (!TranslationTable.ContainsKey(newer))
{
TranslationTable.Add(newer, older);
}
}
}
}
}
}
sr.Close();
}
}
}