├── .gitignore
├── .tfignore
├── Relocation Section Editor.sln
└── Relocation Section Editor
├── Program.cs
├── Properties
├── AssemblyInfo.cs
├── Resources.Designer.cs
├── Resources.resx
├── Settings.Designer.cs
└── Settings.settings
├── Relocation Section Editor.csproj
├── Relocations.cs
├── frmAddRelocation.Designer.cs
├── frmAddRelocation.cs
├── frmAddRelocation.resx
├── frmEditRelocation.Designer.cs
├── frmEditRelocation.cs
├── frmEditRelocation.resx
├── frmMain.Designer.cs
├── frmMain.cs
└── frmMain.resx
/.gitignore:
--------------------------------------------------------------------------------
1 | Thumbs.db
2 | *.obj
3 | *.exe
4 | *.pdb
5 | *.user
6 | *.aps
7 | *.pch
8 | *.vspscc
9 | *_i.c
10 | *_p.c
11 | *.ncb
12 | *.suo
13 | *.sln.docstates
14 | *.tlb
15 | *.tlh
16 | *.bak
17 | *.cache
18 | *.ilk
19 | *.log
20 | [Bb]in
21 | [Dd]ebug*/
22 | *.lib
23 | *.sbr
24 | obj/
25 | [Rr]elease*/
26 | _ReSharper*/
27 | [Tt]est[Rr]esult*
28 | *.vssscc
29 | $tf*/
--------------------------------------------------------------------------------
/.tfignore:
--------------------------------------------------------------------------------
1 | \.git
--------------------------------------------------------------------------------
/Relocation Section Editor.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 11.00
3 | # Visual Studio 2010
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Relocation Section Editor", "Relocation Section Editor\Relocation Section Editor.csproj", "{6868093F-E5F3-4848-803E-FEE6B0D5A534}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|x86 = Debug|x86
9 | Release|x86 = Release|x86
10 | EndGlobalSection
11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
12 | {6868093F-E5F3-4848-803E-FEE6B0D5A534}.Debug|x86.ActiveCfg = Debug|x86
13 | {6868093F-E5F3-4848-803E-FEE6B0D5A534}.Debug|x86.Build.0 = Debug|x86
14 | {6868093F-E5F3-4848-803E-FEE6B0D5A534}.Release|x86.ActiveCfg = Release|x86
15 | {6868093F-E5F3-4848-803E-FEE6B0D5A534}.Release|x86.Build.0 = Release|x86
16 | EndGlobalSection
17 | GlobalSection(SolutionProperties) = preSolution
18 | HideSolutionNode = FALSE
19 | EndGlobalSection
20 | EndGlobal
21 |
--------------------------------------------------------------------------------
/Relocation Section Editor/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Windows.Forms;
4 |
5 | namespace Relocation_Section_Editor
6 | {
7 | static class Program
8 | {
9 | ///
10 | /// Point d'entrée principal de l'application.
11 | ///
12 | [STAThread]
13 | static void Main(string[] args)
14 | {
15 | Application.EnableVisualStyles();
16 | Application.SetCompatibleTextRenderingDefault(false);
17 | Application.Run(new frmMain(args));
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Relocation Section Editor/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // Les informations générales relatives à un assembly dépendent de
6 | // l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations
7 | // associées à un assembly.
8 | [assembly: AssemblyTitle("Relocation Section Editor")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Relocation Section Editor")]
13 | [assembly: AssemblyCopyright("Copyright © 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // L'affectation de la valeur false à ComVisible rend les types invisibles dans cet assembly
18 | // aux composants COM. Si vous devez accéder à un type dans cet assembly à partir de
19 | // COM, affectez la valeur true à l'attribut ComVisible sur ce type.
20 | [assembly: ComVisible(false)]
21 |
22 | // Le GUID suivant est pour l'ID de la typelib si ce projet est exposé à COM
23 | [assembly: Guid("4e2c0614-2d95-4cba-88d8-86b9c57f2be9")]
24 |
25 | // Les informations de version pour un assembly se composent des quatre valeurs suivantes :
26 | //
27 | // Version principale
28 | // Version secondaire
29 | // Numéro de build
30 | // Révision
31 | //
32 | // Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut
33 | // en utilisant '*', comme indiqué ci-dessous :
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Relocation Section Editor/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // Ce code a été généré par un outil.
4 | // Version du runtime :4.0.30319.269
5 | //
6 | // Les modifications apportées à ce fichier peuvent provoquer un comportement incorrect et seront perdues si
7 | // le code est régénéré.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace Relocation_Section_Editor.Properties
12 | {
13 |
14 |
15 | ///
16 | /// Une classe de ressource fortement typée destinée, entre autres, à la consultation des chaînes localisées.
17 | ///
18 | // Cette classe a été générée automatiquement par la classe StronglyTypedResourceBuilder
19 | // à l'aide d'un outil, tel que ResGen ou Visual Studio.
20 | // Pour ajouter ou supprimer un membre, modifiez votre fichier .ResX, puis réexécutez ResGen
21 | // avec l'option /str ou régénérez votre projet VS.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources
26 | {
27 |
28 | private static global::System.Resources.ResourceManager resourceMan;
29 |
30 | private static global::System.Globalization.CultureInfo resourceCulture;
31 |
32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
33 | internal Resources()
34 | {
35 | }
36 |
37 | ///
38 | /// Retourne l'instance ResourceManager mise en cache utilisée par cette classe.
39 | ///
40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
41 | internal static global::System.Resources.ResourceManager ResourceManager
42 | {
43 | get
44 | {
45 | if ((resourceMan == null))
46 | {
47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Relocation_Section_Editor.Properties.Resources", typeof(Resources).Assembly);
48 | resourceMan = temp;
49 | }
50 | return resourceMan;
51 | }
52 | }
53 |
54 | ///
55 | /// Remplace la propriété CurrentUICulture du thread actuel pour toutes
56 | /// les recherches de ressources à l'aide de cette classe de ressource fortement typée.
57 | ///
58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
59 | internal static global::System.Globalization.CultureInfo Culture
60 | {
61 | get
62 | {
63 | return resourceCulture;
64 | }
65 | set
66 | {
67 | resourceCulture = value;
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/Relocation Section Editor/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/Relocation Section Editor/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.269
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace Relocation_Section_Editor.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Relocation Section Editor/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Relocation Section Editor/Relocation Section Editor.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | x86
6 | 8.0.30703
7 | 2.0
8 | {6868093F-E5F3-4848-803E-FEE6B0D5A534}
9 | WinExe
10 | Properties
11 | Relocation_Section_Editor
12 | Relocation Section Editor
13 | v2.0
14 | 512
15 |
16 |
17 | x86
18 | true
19 | full
20 | false
21 | bin\Debug\
22 | DEBUG;TRACE
23 | prompt
24 | 4
25 |
26 |
27 | x86
28 | pdbonly
29 | true
30 | bin\Release\
31 | TRACE
32 | prompt
33 | 4
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 | Form
46 |
47 |
48 | frmAddRelocation.cs
49 |
50 |
51 | Form
52 |
53 |
54 | frmEditRelocation.cs
55 |
56 |
57 | Form
58 |
59 |
60 | frmMain.cs
61 |
62 |
63 |
64 |
65 |
66 | frmAddRelocation.cs
67 |
68 |
69 | frmEditRelocation.cs
70 |
71 |
72 | frmMain.cs
73 |
74 |
75 | ResXFileCodeGenerator
76 | Resources.Designer.cs
77 | Designer
78 |
79 |
80 | True
81 | Resources.resx
82 |
83 |
84 | SettingsSingleFileGenerator
85 | Settings.Designer.cs
86 |
87 |
88 | True
89 | Settings.settings
90 | True
91 |
92 |
93 |
94 |
101 |
--------------------------------------------------------------------------------
/Relocation Section Editor/Relocations.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Collections;
5 |
6 | namespace Relocation_Section_Editor
7 | {
8 | public class Relocations
9 | {
10 | public enum BASE_RELOCATION_TYPE
11 | {
12 | ABSOLUTE = 0,
13 | HIGH = 1,
14 | LOW = 2,
15 | HIGHLOW = 3,
16 | HIGHADJ = 4,
17 | JMPADDR = 5,
18 | MIPS_JMPADDR16 = 9,
19 | DIR64 = 10
20 | }
21 | public struct Page
22 | {
23 | public uint address;
24 | public uint size;
25 | public uint count;
26 | }
27 | public struct Reloc
28 | {
29 | public ushort offset;
30 | public BASE_RELOCATION_TYPE type;
31 | }
32 |
33 | private uint imageBase;
34 | private uint virtualAddress;
35 | private uint virtualSize;
36 | private uint RawAddress;
37 | private uint RawSize;
38 |
39 | private long addressVirtualSize;
40 |
41 | private SortedDictionary> pages;
42 | private string path;
43 |
44 | public bool IsNotSaved { get; private set; }
45 |
46 | ///
47 | /// Open the file specified into the , read the relocation section
48 | /// and load it.
49 | ///
50 | ///
51 | public Relocations(string path)
52 | {
53 | if (!File.Exists(path))
54 | throw new FileNotFoundException();
55 |
56 | this.path = path;
57 | this.IsNotSaved = false;
58 |
59 | BinaryReader br = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read));
60 |
61 | if (br.ReadInt16() != 0x5A4D) // MZ signature
62 | {
63 | br.Close();
64 | throw new InvalidOperationException("MZ");
65 | }
66 |
67 | br.BaseStream.Seek(0x3C, SeekOrigin.Begin); // go to ptr to COFF File Header
68 | br.BaseStream.Seek(br.ReadInt32(), SeekOrigin.Begin); // go to COFF File Header
69 |
70 | if (br.ReadInt32() != 0x00004550) // PE\0\0
71 | {
72 | br.Close();
73 | throw new InvalidOperationException("PE");
74 | }
75 |
76 | br.ReadUInt16(); // machine ID. Ignored
77 | uint numbersOfSections = br.ReadUInt16();
78 |
79 | br.BaseStream.Seek(20 - 4, SeekOrigin.Current); // go to magic number (PE or PE+ = x86 or x64)
80 |
81 | if (br.ReadInt16() != 0x010B)
82 | {
83 | br.Close();
84 | throw new InvalidOperationException("X86");
85 | }
86 |
87 | br.BaseStream.Seek(26, SeekOrigin.Current); // go to ImageBase
88 | imageBase = br.ReadUInt32();
89 | br.BaseStream.Seek(64 + 40, SeekOrigin.Current); // go to Data Directories -> Base Relocation Table
90 |
91 | virtualAddress = br.ReadUInt32();
92 | addressVirtualSize = br.BaseStream.Position;
93 | virtualSize = br.ReadUInt32();
94 |
95 | br.BaseStream.Seek(80, SeekOrigin.Current); // jump to Section Table
96 |
97 | // find the RAW address/size
98 | RawAddress = 0;
99 | RawSize = 0;
100 |
101 | for (int i = 0; i < numbersOfSections; i++)
102 | {
103 | br.BaseStream.Seek(12, SeekOrigin.Current);
104 |
105 | if (br.ReadUInt32() == virtualAddress)
106 | {
107 | RawSize = br.ReadUInt32();
108 | RawAddress = br.ReadUInt32();
109 | break;
110 | }
111 |
112 | br.BaseStream.Seek(24, SeekOrigin.Current); // place the pointer to the next section
113 | }
114 |
115 | if (RawAddress == 0x00 || RawSize == 0x00)
116 | {
117 | br.Close();
118 | throw new InvalidOperationException("RAW");
119 | }
120 |
121 | // reading relocation section
122 | br.BaseStream.Seek(RawAddress, SeekOrigin.Begin);
123 |
124 | pages = new SortedDictionary>();
125 |
126 | while (br.BaseStream.Position < RawAddress + virtualSize) // 4K block loop
127 | {
128 | uint address = br.ReadUInt32();
129 | uint size = br.ReadUInt32();
130 | uint count = (size - 8) / 2;
131 |
132 | List relocs = new List();
133 |
134 | for (int i = 0; i < count; i++) // offsets loop
135 | {
136 | ushort data = br.ReadUInt16();
137 | BASE_RELOCATION_TYPE type = (BASE_RELOCATION_TYPE)((data & 0xF000) >> 12);
138 | ushort offset = (ushort)(data & 0x0FFF);
139 |
140 | Reloc reloc = new Reloc();
141 | reloc.offset = offset;
142 | reloc.type = type;
143 |
144 | relocs.Add(reloc);
145 | }
146 |
147 | pages.Add(address, relocs);
148 | }
149 |
150 | br.Close();
151 | }
152 |
153 | ///
154 | /// Edit an specific address
155 | ///
156 | /// Old address
157 | /// New address
158 | /// New type
159 | /// True if edited with success, else false
160 | public bool EditRelocation(uint address, uint newAddress, BASE_RELOCATION_TYPE newType)
161 | {
162 | uint oldAddress = (address & 0xFFFFF000) - imageBase;
163 | ushort oldOffset = (ushort)(address & 0x00000FFF);
164 |
165 | BASE_RELOCATION_TYPE oldType = BASE_RELOCATION_TYPE.ABSOLUTE;
166 | List relocs;
167 |
168 | if (!pages.TryGetValue(oldAddress, out relocs))
169 | return false;
170 |
171 | foreach (Reloc reloc in relocs)
172 | {
173 | if (reloc.offset == oldOffset)
174 | {
175 | oldType = reloc.type;
176 | break;
177 | }
178 | }
179 |
180 | if (oldType == BASE_RELOCATION_TYPE.ABSOLUTE)
181 | return false;
182 |
183 | // delete old address and add new address. If not success, restore old address
184 | if (!DeleteRelocation(address))
185 | return false;
186 |
187 | if (AddRelocation(newAddress, newType) <= 0)
188 | {
189 | AddRelocation(address, oldType);
190 | return false;
191 | }
192 |
193 | IsNotSaved = true;
194 | return true;
195 | }
196 |
197 | ///
198 | /// Remove a specific address
199 | ///
200 | /// Address to remove
201 | /// True if removed with success, else false
202 | public bool DeleteRelocation(uint address)
203 | {
204 | List relocs;
205 |
206 | // search if 4K address exists
207 | if (!pages.TryGetValue((address & 0xFFFFF000) - imageBase, out relocs))
208 | return false;
209 |
210 | ushort offset = (ushort)(address & 0x0FFF);
211 |
212 | // search if offset exists
213 | foreach (Reloc reloc in relocs)
214 | {
215 | if (reloc.offset == offset && reloc.type != BASE_RELOCATION_TYPE.ABSOLUTE)
216 | {
217 | relocs.Remove(reloc);
218 | virtualSize -= 2;
219 |
220 | if (relocs.Count % 2 != 0) // align in 32bits
221 | {
222 | bool isAlignDeleted = false;
223 |
224 | foreach (Reloc item in relocs) // search if align already exists
225 | {
226 | if (item.offset == 0 && item.type == BASE_RELOCATION_TYPE.ABSOLUTE)
227 | {
228 | relocs.Remove(item);
229 | isAlignDeleted = true;
230 | virtualSize -= 2;
231 | break;
232 | }
233 | }
234 |
235 | if (!isAlignDeleted) // if no align reloc found, add it
236 | {
237 | Reloc item = new Reloc();
238 | item.offset = 0;
239 | item.type = BASE_RELOCATION_TYPE.ABSOLUTE;
240 |
241 | relocs.Add(item);
242 | virtualSize += 2;
243 | }
244 | }
245 |
246 | if (relocs.Count == 0) // remove page if nothing offset
247 | {
248 | pages.Remove((address & 0xFFFFF000) - imageBase);
249 | virtualSize -= 8;
250 | }
251 |
252 | IsNotSaved = true;
253 | return true;
254 | }
255 | }
256 |
257 | return false;
258 | }
259 |
260 | ///
261 | /// Add a relocation address
262 | ///
263 | /// Address to add
264 | /// Type of relocation
265 | /// -1 if duplicated, 0 if not added, 1 if added a page and 2 if added only in reloc of page
266 | public int AddRelocation(uint address, BASE_RELOCATION_TYPE type)
267 | {
268 | if (address < imageBase)
269 | return 0;
270 |
271 | uint page = (address & 0xFFFFF000) - imageBase;
272 | ushort offset = (ushort)(address & 0x00000FFF);
273 |
274 | if (!pages.ContainsKey(page)) // create a new page if doesn't exists
275 | {
276 | if (RawSize - virtualSize < 12)
277 | return 0;
278 |
279 | List relocs = new List();
280 |
281 | Reloc reloc = new Reloc();
282 | reloc.offset = offset;
283 | reloc.type = type;
284 | relocs.Add(reloc);
285 |
286 | reloc = new Reloc();
287 | reloc.offset = 0;
288 | reloc.type = BASE_RELOCATION_TYPE.ABSOLUTE;
289 | relocs.Add(reloc);
290 |
291 | pages.Add(page, relocs);
292 |
293 | virtualSize += 12;
294 |
295 | IsNotSaved = true;
296 | return 1;
297 | }
298 | else // just added the offset
299 | {
300 | List relocs;
301 |
302 | if (!pages.TryGetValue(page, out relocs))
303 | return 0;
304 |
305 | foreach (Reloc item in relocs) // search if address already present
306 | {
307 | if (item.offset == offset && item.type != BASE_RELOCATION_TYPE.ABSOLUTE)
308 | return -1;
309 | }
310 |
311 | if (relocs.Count % 2 == 0) // align in 32bits
312 | {
313 | bool isAlignDeleted = false;
314 |
315 | foreach (Reloc item in relocs) // search if align already exists
316 | {
317 | if (item.offset == 0 && item.type == BASE_RELOCATION_TYPE.ABSOLUTE)
318 | {
319 | relocs.Remove(item);
320 | isAlignDeleted = true;
321 | virtualSize -= 2;
322 | break;
323 | }
324 | }
325 |
326 | if (!isAlignDeleted) // if no align reloc found, add it
327 | {
328 | if (RawSize - virtualSize < 4)
329 | return 0;
330 |
331 | Reloc item = new Reloc();
332 | item.offset = 0;
333 | item.type = BASE_RELOCATION_TYPE.ABSOLUTE;
334 |
335 | relocs.Add(item);
336 | virtualSize += 2;
337 | }
338 | }
339 |
340 | Reloc reloc = new Reloc();
341 | reloc.offset = offset;
342 | reloc.type = type;
343 |
344 | relocs.Add(reloc);
345 |
346 | virtualSize += 2;
347 |
348 | IsNotSaved = true;
349 | return 2;
350 | }
351 | }
352 |
353 | ///
354 | /// Obtain a list of pages available
355 | ///
356 | /// A list of pages available
357 | public List GetPages()
358 | {
359 | List result = new List();
360 |
361 | SortedDictionary>.Enumerator enumerator = pages.GetEnumerator();
362 |
363 | while (enumerator.MoveNext())
364 | {
365 | Page p = new Page();
366 |
367 | p.address = enumerator.Current.Key + imageBase;
368 | p.count = (uint)enumerator.Current.Value.Count;
369 | p.size = (p.count * 2) + 8;
370 |
371 | result.Add(p);
372 | }
373 |
374 | return result;
375 | }
376 |
377 | ///
378 | /// Try to obtain a list of relocations for an address given
379 | ///
380 | /// Base address of relocations
381 | /// List of relocations for this address
382 | /// True if relocations given with success, else false
383 | public bool TryGetRelocs(uint baseAddress, out List relocs)
384 | {
385 | return pages.TryGetValue(baseAddress - imageBase, out relocs);
386 | }
387 |
388 | ///
389 | /// Obtain the Size of Relocation section into the RAM
390 | ///
391 | /// The virtual size
392 | public uint GetVirtuallSize()
393 | {
394 | return virtualSize;
395 | }
396 |
397 | ///
398 | /// Obtain the Size of Relocation section into the disk
399 | ///
400 | /// The RAW size
401 | public uint GetRawSize()
402 | {
403 | return RawSize;
404 | }
405 |
406 | ///
407 | /// Obtain the file path
408 | ///
409 | /// The file path
410 | public string GetPath()
411 | {
412 | return path;
413 | }
414 |
415 | ///
416 | /// Write the relocations section into the file
417 | ///
418 | /// True if written with success, else false
419 | public bool WriteRelocations(string newPath = "")
420 | {
421 | if (!File.Exists(path))
422 | return false;
423 |
424 | if (!string.IsNullOrEmpty(newPath) && newPath != path) // save as
425 | {
426 | try
427 | {
428 | File.Copy(path, newPath, true);
429 | path = newPath;
430 | }
431 | catch (Exception)
432 | {
433 | return false;
434 | }
435 | }
436 |
437 | BinaryWriter bw = new BinaryWriter(new FileStream(path, FileMode.Open, FileAccess.Write, FileShare.None));
438 |
439 | // write new relocation size
440 | bw.BaseStream.Seek(addressVirtualSize, SeekOrigin.Begin);
441 | bw.Write((uint)virtualSize);
442 |
443 | // go to beginning of relocation section
444 | bw.BaseStream.Seek(RawAddress, SeekOrigin.Begin);
445 |
446 | foreach (KeyValuePair> page in pages)
447 | {
448 | // write page
449 | bw.Write(page.Key);
450 | bw.Write(page.Value.Count * 2 + 8);
451 |
452 | foreach (Reloc reloc in page.Value)
453 | {
454 | // write reloc
455 | ushort temp = (ushort)((ushort)reloc.type << 12);
456 | temp += reloc.offset;
457 | bw.Write(temp);
458 | }
459 | }
460 |
461 | // fill the end with null bytes
462 | while (bw.BaseStream.Position < RawAddress + RawSize)
463 | bw.Write((int)0x00000000);
464 |
465 | bw.Close();
466 |
467 | IsNotSaved = false;
468 | return true;
469 | }
470 | }
471 | }
472 |
--------------------------------------------------------------------------------
/Relocation Section Editor/frmAddRelocation.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace Relocation_Section_Editor
2 | {
3 | partial class frmAddRelocation
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows Form Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.lblAddress = new System.Windows.Forms.Label();
32 | this.lblType = new System.Windows.Forms.Label();
33 | this.cboType = new System.Windows.Forms.ComboBox();
34 | this.btnOK = new System.Windows.Forms.Button();
35 | this.btnCancel = new System.Windows.Forms.Button();
36 | this.txtAddress = new System.Windows.Forms.TextBox();
37 | this.lblHexa = new System.Windows.Forms.Label();
38 | this.SuspendLayout();
39 | //
40 | // lblAddress
41 | //
42 | this.lblAddress.AutoSize = true;
43 | this.lblAddress.Location = new System.Drawing.Point(14, 15);
44 | this.lblAddress.Name = "lblAddress";
45 | this.lblAddress.Size = new System.Drawing.Size(48, 13);
46 | this.lblAddress.TabIndex = 0;
47 | this.lblAddress.Text = "Address:";
48 | //
49 | // lblType
50 | //
51 | this.lblType.AutoSize = true;
52 | this.lblType.Location = new System.Drawing.Point(28, 41);
53 | this.lblType.Name = "lblType";
54 | this.lblType.Size = new System.Drawing.Size(34, 13);
55 | this.lblType.TabIndex = 2;
56 | this.lblType.Text = "Type:";
57 | //
58 | // cboType
59 | //
60 | this.cboType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
61 | this.cboType.FormattingEnabled = true;
62 | this.cboType.Items.AddRange(new object[] {
63 | "HIGH",
64 | "LOW",
65 | "HIGHLOW",
66 | "HIGHADJ",
67 | "JMPADDR",
68 | "MIPS_JMPADDR16",
69 | "DIR64"});
70 | this.cboType.Location = new System.Drawing.Point(82, 38);
71 | this.cboType.Name = "cboType";
72 | this.cboType.Size = new System.Drawing.Size(122, 21);
73 | this.cboType.TabIndex = 3;
74 | //
75 | // btnOK
76 | //
77 | this.btnOK.Location = new System.Drawing.Point(26, 81);
78 | this.btnOK.Name = "btnOK";
79 | this.btnOK.Size = new System.Drawing.Size(75, 23);
80 | this.btnOK.TabIndex = 4;
81 | this.btnOK.Text = "&OK";
82 | this.btnOK.UseVisualStyleBackColor = true;
83 | this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
84 | //
85 | // btnCancel
86 | //
87 | this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
88 | this.btnCancel.Location = new System.Drawing.Point(127, 81);
89 | this.btnCancel.Name = "btnCancel";
90 | this.btnCancel.Size = new System.Drawing.Size(75, 23);
91 | this.btnCancel.TabIndex = 5;
92 | this.btnCancel.Text = "&Cancel";
93 | this.btnCancel.UseVisualStyleBackColor = true;
94 | this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
95 | //
96 | // txtAddress
97 | //
98 | this.txtAddress.Location = new System.Drawing.Point(82, 12);
99 | this.txtAddress.MaxLength = 8;
100 | this.txtAddress.Name = "txtAddress";
101 | this.txtAddress.Size = new System.Drawing.Size(68, 20);
102 | this.txtAddress.TabIndex = 1;
103 | this.txtAddress.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtAddress_KeyPress);
104 | this.txtAddress.KeyUp += new System.Windows.Forms.KeyEventHandler(this.txtAddress_KeyUp);
105 | //
106 | // lblHexa
107 | //
108 | this.lblHexa.AutoSize = true;
109 | this.lblHexa.Location = new System.Drawing.Point(66, 15);
110 | this.lblHexa.Name = "lblHexa";
111 | this.lblHexa.Size = new System.Drawing.Size(18, 13);
112 | this.lblHexa.TabIndex = 6;
113 | this.lblHexa.Text = "0x";
114 | //
115 | // frmAddRelocation
116 | //
117 | this.AcceptButton = this.btnOK;
118 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
119 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
120 | this.CancelButton = this.btnCancel;
121 | this.ClientSize = new System.Drawing.Size(229, 121);
122 | this.Controls.Add(this.btnCancel);
123 | this.Controls.Add(this.btnOK);
124 | this.Controls.Add(this.cboType);
125 | this.Controls.Add(this.lblType);
126 | this.Controls.Add(this.txtAddress);
127 | this.Controls.Add(this.lblAddress);
128 | this.Controls.Add(this.lblHexa);
129 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
130 | this.MaximizeBox = false;
131 | this.MinimizeBox = false;
132 | this.Name = "frmAddRelocation";
133 | this.ShowIcon = false;
134 | this.ShowInTaskbar = false;
135 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
136 | this.Text = "Add a Relocation Address";
137 | this.Load += new System.EventHandler(this.frmAddRelocation_Load);
138 | this.ResumeLayout(false);
139 | this.PerformLayout();
140 |
141 | }
142 |
143 | #endregion
144 |
145 | private System.Windows.Forms.Label lblAddress;
146 | private System.Windows.Forms.Label lblType;
147 | private System.Windows.Forms.ComboBox cboType;
148 | private System.Windows.Forms.Button btnOK;
149 | private System.Windows.Forms.Button btnCancel;
150 | private System.Windows.Forms.TextBox txtAddress;
151 | private System.Windows.Forms.Label lblHexa;
152 | }
153 | }
--------------------------------------------------------------------------------
/Relocation Section Editor/frmAddRelocation.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Data;
5 | using System.Drawing;
6 | using System.Text;
7 | using System.Windows.Forms;
8 |
9 | namespace Relocation_Section_Editor
10 | {
11 | public partial class frmAddRelocation : Form
12 | {
13 | private uint address;
14 | private Relocations.BASE_RELOCATION_TYPE type;
15 |
16 | public frmAddRelocation()
17 | {
18 | InitializeComponent();
19 | }
20 |
21 | private void frmAddRelocation_Load(object sender, EventArgs e)
22 | {
23 | cboType.SelectedIndex = 2;
24 | }
25 |
26 | private void btnCancel_Click(object sender, EventArgs e)
27 | {
28 | this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
29 | }
30 |
31 | private void btnOK_Click(object sender, EventArgs e)
32 | {
33 | if (!uint.TryParse(txtAddress.Text, System.Globalization.NumberStyles.AllowHexSpecifier, null, out address))
34 | {
35 | MessageBox.Show("\"" + txtAddress.Text.ToUpper() + "\" isn't a valid address");
36 | return;
37 | }
38 |
39 | type = (Relocations.BASE_RELOCATION_TYPE)(cboType.SelectedIndex + 1);
40 |
41 | this.DialogResult = System.Windows.Forms.DialogResult.OK;
42 | }
43 |
44 | private void txtAddress_KeyPress(object sender, KeyPressEventArgs e)
45 | {
46 | string chars = "0123456789abcdefABCDEF";
47 |
48 | if (e.KeyChar == (char)Keys.Back)
49 | return;
50 |
51 | if (!chars.Contains(e.KeyChar.ToString()))
52 | e.Handled = true;
53 | }
54 |
55 | public uint GetAddress()
56 | {
57 | return address;
58 | }
59 |
60 | public Relocations.BASE_RELOCATION_TYPE GetRelocType()
61 | {
62 | return type;
63 | }
64 |
65 | private void txtAddress_KeyUp(object sender, KeyEventArgs e)
66 | {
67 | if (e.Control && e.KeyCode == Keys.V)
68 | {
69 | txtAddress.Text = Clipboard.GetText();
70 | txtAddress.SelectionStart = txtAddress.Text.Length;
71 | txtAddress.SelectionLength = 0;
72 | }
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/Relocation Section Editor/frmAddRelocation.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
--------------------------------------------------------------------------------
/Relocation Section Editor/frmEditRelocation.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace Relocation_Section_Editor
2 | {
3 | partial class frmEditRelocation
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows Form Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.btnCancel = new System.Windows.Forms.Button();
32 | this.btnOK = new System.Windows.Forms.Button();
33 | this.cboType = new System.Windows.Forms.ComboBox();
34 | this.lblType = new System.Windows.Forms.Label();
35 | this.txtAddress = new System.Windows.Forms.TextBox();
36 | this.lblAddress = new System.Windows.Forms.Label();
37 | this.lblHexa = new System.Windows.Forms.Label();
38 | this.lblNewAddress = new System.Windows.Forms.Label();
39 | this.lblHexa2 = new System.Windows.Forms.Label();
40 | this.txtNewAddress = new System.Windows.Forms.TextBox();
41 | this.SuspendLayout();
42 | //
43 | // btnCancel
44 | //
45 | this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
46 | this.btnCancel.Location = new System.Drawing.Point(127, 91);
47 | this.btnCancel.Name = "btnCancel";
48 | this.btnCancel.Size = new System.Drawing.Size(75, 23);
49 | this.btnCancel.TabIndex = 6;
50 | this.btnCancel.Text = "&Cancel";
51 | this.btnCancel.UseVisualStyleBackColor = true;
52 | this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
53 | //
54 | // btnOK
55 | //
56 | this.btnOK.Location = new System.Drawing.Point(26, 91);
57 | this.btnOK.Name = "btnOK";
58 | this.btnOK.Size = new System.Drawing.Size(75, 23);
59 | this.btnOK.TabIndex = 5;
60 | this.btnOK.Text = "&OK";
61 | this.btnOK.UseVisualStyleBackColor = true;
62 | this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
63 | //
64 | // cboType
65 | //
66 | this.cboType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
67 | this.cboType.FormattingEnabled = true;
68 | this.cboType.Items.AddRange(new object[] {
69 | "HIGH",
70 | "LOW",
71 | "HIGHLOW",
72 | "HIGHADJ",
73 | "JMPADDR",
74 | "MIPS_JMPADDR16",
75 | "DIR64"});
76 | this.cboType.Location = new System.Drawing.Point(93, 64);
77 | this.cboType.Name = "cboType";
78 | this.cboType.Size = new System.Drawing.Size(122, 21);
79 | this.cboType.TabIndex = 4;
80 | //
81 | // lblType
82 | //
83 | this.lblType.AutoSize = true;
84 | this.lblType.Location = new System.Drawing.Point(39, 67);
85 | this.lblType.Name = "lblType";
86 | this.lblType.Size = new System.Drawing.Size(34, 13);
87 | this.lblType.TabIndex = 3;
88 | this.lblType.Text = "Type:";
89 | //
90 | // txtAddress
91 | //
92 | this.txtAddress.Location = new System.Drawing.Point(93, 12);
93 | this.txtAddress.MaxLength = 8;
94 | this.txtAddress.Name = "txtAddress";
95 | this.txtAddress.ReadOnly = true;
96 | this.txtAddress.Size = new System.Drawing.Size(68, 20);
97 | this.txtAddress.TabIndex = 9;
98 | //
99 | // lblAddress
100 | //
101 | this.lblAddress.AutoSize = true;
102 | this.lblAddress.Location = new System.Drawing.Point(25, 15);
103 | this.lblAddress.Name = "lblAddress";
104 | this.lblAddress.Size = new System.Drawing.Size(48, 13);
105 | this.lblAddress.TabIndex = 7;
106 | this.lblAddress.Text = "Address:";
107 | //
108 | // lblHexa
109 | //
110 | this.lblHexa.AutoSize = true;
111 | this.lblHexa.Location = new System.Drawing.Point(77, 15);
112 | this.lblHexa.Name = "lblHexa";
113 | this.lblHexa.Size = new System.Drawing.Size(18, 13);
114 | this.lblHexa.TabIndex = 8;
115 | this.lblHexa.Text = "0x";
116 | //
117 | // lblNewAddress
118 | //
119 | this.lblNewAddress.AutoSize = true;
120 | this.lblNewAddress.Location = new System.Drawing.Point(0, 38);
121 | this.lblNewAddress.Name = "lblNewAddress";
122 | this.lblNewAddress.Size = new System.Drawing.Size(73, 13);
123 | this.lblNewAddress.TabIndex = 0;
124 | this.lblNewAddress.Text = "New Address:";
125 | //
126 | // lblHexa2
127 | //
128 | this.lblHexa2.AutoSize = true;
129 | this.lblHexa2.Location = new System.Drawing.Point(77, 40);
130 | this.lblHexa2.Name = "lblHexa2";
131 | this.lblHexa2.Size = new System.Drawing.Size(18, 13);
132 | this.lblHexa2.TabIndex = 1;
133 | this.lblHexa2.Text = "0x";
134 | //
135 | // txtNewAddress
136 | //
137 | this.txtNewAddress.Location = new System.Drawing.Point(93, 38);
138 | this.txtNewAddress.MaxLength = 8;
139 | this.txtNewAddress.Name = "txtNewAddress";
140 | this.txtNewAddress.Size = new System.Drawing.Size(68, 20);
141 | this.txtNewAddress.TabIndex = 2;
142 | this.txtNewAddress.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtNewAddress_KeyPress);
143 | this.txtNewAddress.KeyUp += new System.Windows.Forms.KeyEventHandler(this.txtNewAddress_KeyUp);
144 | //
145 | // frmEditRelocation
146 | //
147 | this.AcceptButton = this.btnOK;
148 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
149 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
150 | this.CancelButton = this.btnCancel;
151 | this.ClientSize = new System.Drawing.Size(229, 121);
152 | this.Controls.Add(this.txtNewAddress);
153 | this.Controls.Add(this.lblHexa2);
154 | this.Controls.Add(this.lblNewAddress);
155 | this.Controls.Add(this.btnCancel);
156 | this.Controls.Add(this.btnOK);
157 | this.Controls.Add(this.cboType);
158 | this.Controls.Add(this.lblType);
159 | this.Controls.Add(this.txtAddress);
160 | this.Controls.Add(this.lblAddress);
161 | this.Controls.Add(this.lblHexa);
162 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
163 | this.MaximizeBox = false;
164 | this.MinimizeBox = false;
165 | this.Name = "frmEditRelocation";
166 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
167 | this.Text = "Edit Relocation";
168 | this.ResumeLayout(false);
169 | this.PerformLayout();
170 |
171 | }
172 |
173 | #endregion
174 |
175 | private System.Windows.Forms.Button btnCancel;
176 | private System.Windows.Forms.Button btnOK;
177 | private System.Windows.Forms.ComboBox cboType;
178 | private System.Windows.Forms.Label lblType;
179 | private System.Windows.Forms.TextBox txtAddress;
180 | private System.Windows.Forms.Label lblAddress;
181 | private System.Windows.Forms.Label lblHexa;
182 | private System.Windows.Forms.Label lblNewAddress;
183 | private System.Windows.Forms.Label lblHexa2;
184 | private System.Windows.Forms.TextBox txtNewAddress;
185 | }
186 | }
--------------------------------------------------------------------------------
/Relocation Section Editor/frmEditRelocation.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Data;
5 | using System.Drawing;
6 | using System.Text;
7 | using System.Windows.Forms;
8 |
9 | namespace Relocation_Section_Editor
10 | {
11 | public partial class frmEditRelocation : Form
12 | {
13 | private uint oldAddress;
14 | private uint newAddress;
15 | private Relocations.BASE_RELOCATION_TYPE type;
16 |
17 | public frmEditRelocation(uint oldAddress, Relocations.BASE_RELOCATION_TYPE oldType)
18 | {
19 | InitializeComponent();
20 |
21 | this.oldAddress = oldAddress;
22 |
23 | txtAddress.Text = oldAddress.ToString("X8");
24 | cboType.SelectedIndex = (int)oldType - 1;
25 | }
26 |
27 | private void btnCancel_Click(object sender, EventArgs e)
28 | {
29 | this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
30 | }
31 |
32 | private void txtNewAddress_KeyPress(object sender, KeyPressEventArgs e)
33 | {
34 | string chars = "0123456789abcdefABCDEF";
35 |
36 | if (e.KeyChar == (char)Keys.Back)
37 | return;
38 |
39 | if (!chars.Contains(e.KeyChar.ToString()))
40 | e.Handled = true;
41 | }
42 |
43 | private void btnOK_Click(object sender, EventArgs e)
44 | {
45 | if (!uint.TryParse(txtNewAddress.Text, System.Globalization.NumberStyles.AllowHexSpecifier, null, out newAddress))
46 | {
47 | MessageBox.Show("\"" + txtNewAddress.Text.ToUpper() + "\" isn't a valid address");
48 | return;
49 | }
50 |
51 | type = (Relocations.BASE_RELOCATION_TYPE)(cboType.SelectedIndex + 1);
52 |
53 | this.DialogResult = System.Windows.Forms.DialogResult.OK;
54 | }
55 |
56 | public uint GetOldAddress()
57 | {
58 | return oldAddress;
59 | }
60 |
61 | public uint GetNewAddress()
62 | {
63 | return newAddress;
64 | }
65 |
66 | public Relocations.BASE_RELOCATION_TYPE GetRelocType()
67 | {
68 | return type;
69 | }
70 |
71 | private void txtNewAddress_KeyUp(object sender, KeyEventArgs e)
72 | {
73 | if (e.Control && e.KeyCode == Keys.V)
74 | {
75 | txtNewAddress.Text = Clipboard.GetText();
76 | txtNewAddress.SelectionStart = txtNewAddress.Text.Length;
77 | txtNewAddress.SelectionLength = 0;
78 | }
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/Relocation Section Editor/frmEditRelocation.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
--------------------------------------------------------------------------------
/Relocation Section Editor/frmMain.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace Relocation_Section_Editor
2 | {
3 | partial class frmMain
4 | {
5 | ///
6 | /// Variable nécessaire au concepteur.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Nettoyage des ressources utilisées.
12 | ///
13 | /// true si les ressources managées doivent être supprimées ; sinon, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Code généré par le Concepteur Windows Form
24 |
25 | ///
26 | /// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
27 | /// le contenu de cette méthode avec l'éditeur de code.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.components = new System.ComponentModel.Container();
32 | this.mnuMain = new System.Windows.Forms.MenuStrip();
33 | this.mnuMainFile = new System.Windows.Forms.ToolStripMenuItem();
34 | this.mnuMainFileOpen = new System.Windows.Forms.ToolStripMenuItem();
35 | this.mnuMainFileSave = new System.Windows.Forms.ToolStripMenuItem();
36 | this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
37 | this.mnuMainFileExit = new System.Windows.Forms.ToolStripMenuItem();
38 | this.mnuMainHelp = new System.Windows.Forms.ToolStripMenuItem();
39 | this.mnuMainHelpAbout = new System.Windows.Forms.ToolStripMenuItem();
40 | this.sptMain = new System.Windows.Forms.SplitContainer();
41 | this.grpPage = new System.Windows.Forms.GroupBox();
42 | this.lvPage = new System.Windows.Forms.ListView();
43 | this.colPageRVA = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
44 | this.colBlockSize = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
45 | this.colCount = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
46 | this.cmnuPages = new System.Windows.Forms.ContextMenuStrip(this.components);
47 | this.cmnuPagesAdd = new System.Windows.Forms.ToolStripMenuItem();
48 | this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
49 | this.cmnuPagesDelete = new System.Windows.Forms.ToolStripMenuItem();
50 | this.grpRelocation = new System.Windows.Forms.GroupBox();
51 | this.lvRelocation = new System.Windows.Forms.ListView();
52 | this.colOffset = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
53 | this.colType = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
54 | this.cmnuRelocations = new System.Windows.Forms.ContextMenuStrip(this.components);
55 | this.cmnuRelocationsAdd = new System.Windows.Forms.ToolStripMenuItem();
56 | this.cmnuRelocationsEdit = new System.Windows.Forms.ToolStripMenuItem();
57 | this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
58 | this.cmnuRelocationsDelete = new System.Windows.Forms.ToolStripMenuItem();
59 | this.dlgOpen = new System.Windows.Forms.OpenFileDialog();
60 | this.staInfo = new System.Windows.Forms.StatusStrip();
61 | this.staLblCurrentSize = new System.Windows.Forms.ToolStripStatusLabel();
62 | this.staLblMaxSize = new System.Windows.Forms.ToolStripStatusLabel();
63 | this.staPbSize = new System.Windows.Forms.ToolStripProgressBar();
64 | this.mnuMainFileSaveAs = new System.Windows.Forms.ToolStripMenuItem();
65 | this.dlgSave = new System.Windows.Forms.SaveFileDialog();
66 | this.mnuMain.SuspendLayout();
67 | this.sptMain.Panel1.SuspendLayout();
68 | this.sptMain.Panel2.SuspendLayout();
69 | this.sptMain.SuspendLayout();
70 | this.grpPage.SuspendLayout();
71 | this.cmnuPages.SuspendLayout();
72 | this.grpRelocation.SuspendLayout();
73 | this.cmnuRelocations.SuspendLayout();
74 | this.staInfo.SuspendLayout();
75 | this.SuspendLayout();
76 | //
77 | // mnuMain
78 | //
79 | this.mnuMain.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
80 | this.mnuMainFile,
81 | this.mnuMainHelp});
82 | this.mnuMain.Location = new System.Drawing.Point(0, 0);
83 | this.mnuMain.Name = "mnuMain";
84 | this.mnuMain.Size = new System.Drawing.Size(796, 24);
85 | this.mnuMain.TabIndex = 0;
86 | this.mnuMain.Text = "menuStrip1";
87 | //
88 | // mnuMainFile
89 | //
90 | this.mnuMainFile.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
91 | this.mnuMainFileOpen,
92 | this.mnuMainFileSave,
93 | this.mnuMainFileSaveAs,
94 | this.toolStripSeparator1,
95 | this.mnuMainFileExit});
96 | this.mnuMainFile.Name = "mnuMainFile";
97 | this.mnuMainFile.Size = new System.Drawing.Size(37, 20);
98 | this.mnuMainFile.Text = "&File";
99 | //
100 | // mnuMainFileOpen
101 | //
102 | this.mnuMainFileOpen.Name = "mnuMainFileOpen";
103 | this.mnuMainFileOpen.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O)));
104 | this.mnuMainFileOpen.Size = new System.Drawing.Size(191, 22);
105 | this.mnuMainFileOpen.Text = "&Open...";
106 | this.mnuMainFileOpen.Click += new System.EventHandler(this.mnuMainFileOpen_Click);
107 | //
108 | // mnuMainFileSave
109 | //
110 | this.mnuMainFileSave.Name = "mnuMainFileSave";
111 | this.mnuMainFileSave.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.S)));
112 | this.mnuMainFileSave.Size = new System.Drawing.Size(191, 22);
113 | this.mnuMainFileSave.Text = "&Save";
114 | this.mnuMainFileSave.Click += new System.EventHandler(this.mnuMainFileSave_Click);
115 | //
116 | // toolStripSeparator1
117 | //
118 | this.toolStripSeparator1.Name = "toolStripSeparator1";
119 | this.toolStripSeparator1.Size = new System.Drawing.Size(188, 6);
120 | //
121 | // mnuMainFileExit
122 | //
123 | this.mnuMainFileExit.Name = "mnuMainFileExit";
124 | this.mnuMainFileExit.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.F4)));
125 | this.mnuMainFileExit.Size = new System.Drawing.Size(191, 22);
126 | this.mnuMainFileExit.Text = "&Exit";
127 | this.mnuMainFileExit.Click += new System.EventHandler(this.mnuMainFileExit_Click);
128 | //
129 | // mnuMainHelp
130 | //
131 | this.mnuMainHelp.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
132 | this.mnuMainHelpAbout});
133 | this.mnuMainHelp.Name = "mnuMainHelp";
134 | this.mnuMainHelp.Size = new System.Drawing.Size(24, 20);
135 | this.mnuMainHelp.Text = "&?";
136 | //
137 | // mnuMainHelpAbout
138 | //
139 | this.mnuMainHelpAbout.Name = "mnuMainHelpAbout";
140 | this.mnuMainHelpAbout.Size = new System.Drawing.Size(152, 22);
141 | this.mnuMainHelpAbout.Text = "&About";
142 | this.mnuMainHelpAbout.Click += new System.EventHandler(this.mnuMainHelpAbout_Click);
143 | //
144 | // sptMain
145 | //
146 | this.sptMain.Dock = System.Windows.Forms.DockStyle.Fill;
147 | this.sptMain.FixedPanel = System.Windows.Forms.FixedPanel.Panel1;
148 | this.sptMain.Location = new System.Drawing.Point(0, 24);
149 | this.sptMain.Name = "sptMain";
150 | //
151 | // sptMain.Panel1
152 | //
153 | this.sptMain.Panel1.Controls.Add(this.grpPage);
154 | //
155 | // sptMain.Panel2
156 | //
157 | this.sptMain.Panel2.Controls.Add(this.grpRelocation);
158 | this.sptMain.Size = new System.Drawing.Size(796, 416);
159 | this.sptMain.SplitterDistance = 228;
160 | this.sptMain.TabIndex = 1;
161 | //
162 | // grpPage
163 | //
164 | this.grpPage.Controls.Add(this.lvPage);
165 | this.grpPage.Dock = System.Windows.Forms.DockStyle.Fill;
166 | this.grpPage.Location = new System.Drawing.Point(0, 0);
167 | this.grpPage.Name = "grpPage";
168 | this.grpPage.Size = new System.Drawing.Size(228, 416);
169 | this.grpPage.TabIndex = 0;
170 | this.grpPage.TabStop = false;
171 | this.grpPage.Text = "Page";
172 | //
173 | // lvPage
174 | //
175 | this.lvPage.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
176 | this.colPageRVA,
177 | this.colBlockSize,
178 | this.colCount});
179 | this.lvPage.ContextMenuStrip = this.cmnuPages;
180 | this.lvPage.Dock = System.Windows.Forms.DockStyle.Fill;
181 | this.lvPage.FullRowSelect = true;
182 | this.lvPage.GridLines = true;
183 | this.lvPage.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
184 | this.lvPage.HideSelection = false;
185 | this.lvPage.Location = new System.Drawing.Point(3, 16);
186 | this.lvPage.MultiSelect = false;
187 | this.lvPage.Name = "lvPage";
188 | this.lvPage.Size = new System.Drawing.Size(222, 397);
189 | this.lvPage.TabIndex = 0;
190 | this.lvPage.UseCompatibleStateImageBehavior = false;
191 | this.lvPage.View = System.Windows.Forms.View.Details;
192 | this.lvPage.SelectedIndexChanged += new System.EventHandler(this.lvPage_SelectedIndexChanged);
193 | //
194 | // colPageRVA
195 | //
196 | this.colPageRVA.Text = "Page RVA";
197 | this.colPageRVA.Width = 75;
198 | //
199 | // colBlockSize
200 | //
201 | this.colBlockSize.Text = "Block Size";
202 | this.colBlockSize.Width = 75;
203 | //
204 | // colCount
205 | //
206 | this.colCount.Text = "# items";
207 | this.colCount.Width = 50;
208 | //
209 | // cmnuPages
210 | //
211 | this.cmnuPages.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
212 | this.cmnuPagesAdd,
213 | this.toolStripSeparator3,
214 | this.cmnuPagesDelete});
215 | this.cmnuPages.Name = "cmnuPages";
216 | this.cmnuPages.Size = new System.Drawing.Size(173, 54);
217 | //
218 | // cmnuPagesAdd
219 | //
220 | this.cmnuPagesAdd.Name = "cmnuPagesAdd";
221 | this.cmnuPagesAdd.ShortcutKeys = System.Windows.Forms.Keys.Insert;
222 | this.cmnuPagesAdd.Size = new System.Drawing.Size(172, 22);
223 | this.cmnuPagesAdd.Text = "&Add";
224 | this.cmnuPagesAdd.Click += new System.EventHandler(this.mnuAdd_Click);
225 | //
226 | // toolStripSeparator3
227 | //
228 | this.toolStripSeparator3.Name = "toolStripSeparator3";
229 | this.toolStripSeparator3.Size = new System.Drawing.Size(169, 6);
230 | //
231 | // cmnuPagesDelete
232 | //
233 | this.cmnuPagesDelete.Name = "cmnuPagesDelete";
234 | this.cmnuPagesDelete.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Delete)));
235 | this.cmnuPagesDelete.Size = new System.Drawing.Size(172, 22);
236 | this.cmnuPagesDelete.Text = "&Delete";
237 | this.cmnuPagesDelete.Click += new System.EventHandler(this.cmnuPagesDelete_Click);
238 | //
239 | // grpRelocation
240 | //
241 | this.grpRelocation.Controls.Add(this.lvRelocation);
242 | this.grpRelocation.Dock = System.Windows.Forms.DockStyle.Fill;
243 | this.grpRelocation.Location = new System.Drawing.Point(0, 0);
244 | this.grpRelocation.Name = "grpRelocation";
245 | this.grpRelocation.Size = new System.Drawing.Size(564, 416);
246 | this.grpRelocation.TabIndex = 0;
247 | this.grpRelocation.TabStop = false;
248 | this.grpRelocation.Text = "Relocation";
249 | //
250 | // lvRelocation
251 | //
252 | this.lvRelocation.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
253 | this.colOffset,
254 | this.colType});
255 | this.lvRelocation.ContextMenuStrip = this.cmnuRelocations;
256 | this.lvRelocation.Dock = System.Windows.Forms.DockStyle.Fill;
257 | this.lvRelocation.FullRowSelect = true;
258 | this.lvRelocation.GridLines = true;
259 | this.lvRelocation.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
260 | this.lvRelocation.HideSelection = false;
261 | this.lvRelocation.Location = new System.Drawing.Point(3, 16);
262 | this.lvRelocation.MultiSelect = false;
263 | this.lvRelocation.Name = "lvRelocation";
264 | this.lvRelocation.Size = new System.Drawing.Size(558, 397);
265 | this.lvRelocation.Sorting = System.Windows.Forms.SortOrder.Ascending;
266 | this.lvRelocation.TabIndex = 0;
267 | this.lvRelocation.UseCompatibleStateImageBehavior = false;
268 | this.lvRelocation.View = System.Windows.Forms.View.Details;
269 | //
270 | // colOffset
271 | //
272 | this.colOffset.Text = "Offset";
273 | this.colOffset.Width = 70;
274 | //
275 | // colType
276 | //
277 | this.colType.Text = "Type";
278 | this.colType.Width = 220;
279 | //
280 | // cmnuRelocations
281 | //
282 | this.cmnuRelocations.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
283 | this.cmnuRelocationsAdd,
284 | this.cmnuRelocationsEdit,
285 | this.toolStripSeparator2,
286 | this.cmnuRelocationsDelete});
287 | this.cmnuRelocations.Name = "cmnuRelocations";
288 | this.cmnuRelocations.Size = new System.Drawing.Size(153, 98);
289 | //
290 | // cmnuRelocationsAdd
291 | //
292 | this.cmnuRelocationsAdd.Name = "cmnuRelocationsAdd";
293 | this.cmnuRelocationsAdd.ShortcutKeys = System.Windows.Forms.Keys.Insert;
294 | this.cmnuRelocationsAdd.Size = new System.Drawing.Size(152, 22);
295 | this.cmnuRelocationsAdd.Text = "&Add";
296 | this.cmnuRelocationsAdd.Click += new System.EventHandler(this.mnuAdd_Click);
297 | //
298 | // cmnuRelocationsEdit
299 | //
300 | this.cmnuRelocationsEdit.Name = "cmnuRelocationsEdit";
301 | this.cmnuRelocationsEdit.ShortcutKeys = System.Windows.Forms.Keys.F2;
302 | this.cmnuRelocationsEdit.Size = new System.Drawing.Size(152, 22);
303 | this.cmnuRelocationsEdit.Text = "&Edit";
304 | this.cmnuRelocationsEdit.Click += new System.EventHandler(this.mnuRelocationsEdit_Click);
305 | //
306 | // toolStripSeparator2
307 | //
308 | this.toolStripSeparator2.Name = "toolStripSeparator2";
309 | this.toolStripSeparator2.Size = new System.Drawing.Size(149, 6);
310 | //
311 | // cmnuRelocationsDelete
312 | //
313 | this.cmnuRelocationsDelete.Name = "cmnuRelocationsDelete";
314 | this.cmnuRelocationsDelete.ShortcutKeys = System.Windows.Forms.Keys.Delete;
315 | this.cmnuRelocationsDelete.Size = new System.Drawing.Size(152, 22);
316 | this.cmnuRelocationsDelete.Text = "&Delete";
317 | this.cmnuRelocationsDelete.Click += new System.EventHandler(this.cmuRelocationsDelete_Click);
318 | //
319 | // staInfo
320 | //
321 | this.staInfo.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
322 | this.staLblCurrentSize,
323 | this.staLblMaxSize,
324 | this.staPbSize});
325 | this.staInfo.Location = new System.Drawing.Point(0, 440);
326 | this.staInfo.Name = "staInfo";
327 | this.staInfo.Size = new System.Drawing.Size(796, 22);
328 | this.staInfo.TabIndex = 1;
329 | this.staInfo.Text = "statusStrip1";
330 | //
331 | // staLblCurrentSize
332 | //
333 | this.staLblCurrentSize.Name = "staLblCurrentSize";
334 | this.staLblCurrentSize.Size = new System.Drawing.Size(72, 17);
335 | this.staLblCurrentSize.Text = "Current size:";
336 | //
337 | // staLblMaxSize
338 | //
339 | this.staLblMaxSize.Name = "staLblMaxSize";
340 | this.staLblMaxSize.Size = new System.Drawing.Size(54, 17);
341 | this.staLblMaxSize.Text = "Max size:";
342 | //
343 | // staPbSize
344 | //
345 | this.staPbSize.Name = "staPbSize";
346 | this.staPbSize.Size = new System.Drawing.Size(100, 16);
347 | //
348 | // mnuMainFileSaveAs
349 | //
350 | this.mnuMainFileSaveAs.Name = "mnuMainFileSaveAs";
351 | this.mnuMainFileSaveAs.ShortcutKeys = ((System.Windows.Forms.Keys)(((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Shift)
352 | | System.Windows.Forms.Keys.S)));
353 | this.mnuMainFileSaveAs.Size = new System.Drawing.Size(191, 22);
354 | this.mnuMainFileSaveAs.Text = "Save &As...";
355 | this.mnuMainFileSaveAs.Click += new System.EventHandler(this.mnuMainFileSaveAs_Click);
356 | //
357 | // frmMain
358 | //
359 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
360 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
361 | this.ClientSize = new System.Drawing.Size(796, 462);
362 | this.Controls.Add(this.sptMain);
363 | this.Controls.Add(this.mnuMain);
364 | this.Controls.Add(this.staInfo);
365 | this.MainMenuStrip = this.mnuMain;
366 | this.Name = "frmMain";
367 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
368 | this.Text = "Relocation Section Editor";
369 | this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmMain_FormClosing);
370 | this.Load += new System.EventHandler(this.frmMain_Load);
371 | this.mnuMain.ResumeLayout(false);
372 | this.mnuMain.PerformLayout();
373 | this.sptMain.Panel1.ResumeLayout(false);
374 | this.sptMain.Panel2.ResumeLayout(false);
375 | this.sptMain.ResumeLayout(false);
376 | this.grpPage.ResumeLayout(false);
377 | this.cmnuPages.ResumeLayout(false);
378 | this.grpRelocation.ResumeLayout(false);
379 | this.cmnuRelocations.ResumeLayout(false);
380 | this.staInfo.ResumeLayout(false);
381 | this.staInfo.PerformLayout();
382 | this.ResumeLayout(false);
383 | this.PerformLayout();
384 |
385 | }
386 |
387 | #endregion
388 |
389 | private System.Windows.Forms.MenuStrip mnuMain;
390 | private System.Windows.Forms.ToolStripMenuItem mnuMainFile;
391 | private System.Windows.Forms.ToolStripMenuItem mnuMainFileExit;
392 | private System.Windows.Forms.SplitContainer sptMain;
393 | private System.Windows.Forms.GroupBox grpPage;
394 | private System.Windows.Forms.ListView lvPage;
395 | private System.Windows.Forms.GroupBox grpRelocation;
396 | private System.Windows.Forms.ListView lvRelocation;
397 | private System.Windows.Forms.ToolStripMenuItem mnuMainHelp;
398 | private System.Windows.Forms.ToolStripMenuItem mnuMainHelpAbout;
399 | private System.Windows.Forms.ColumnHeader colPageRVA;
400 | private System.Windows.Forms.ColumnHeader colBlockSize;
401 | private System.Windows.Forms.ColumnHeader colOffset;
402 | private System.Windows.Forms.ColumnHeader colType;
403 | private System.Windows.Forms.ToolStripMenuItem mnuMainFileOpen;
404 | private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
405 | private System.Windows.Forms.ColumnHeader colCount;
406 | private System.Windows.Forms.OpenFileDialog dlgOpen;
407 | private System.Windows.Forms.ContextMenuStrip cmnuRelocations;
408 | private System.Windows.Forms.ToolStripMenuItem cmnuRelocationsDelete;
409 | private System.Windows.Forms.StatusStrip staInfo;
410 | private System.Windows.Forms.ToolStripStatusLabel staLblCurrentSize;
411 | private System.Windows.Forms.ToolStripStatusLabel staLblMaxSize;
412 | private System.Windows.Forms.ToolStripProgressBar staPbSize;
413 | private System.Windows.Forms.ContextMenuStrip cmnuPages;
414 | private System.Windows.Forms.ToolStripMenuItem cmnuPagesDelete;
415 | private System.Windows.Forms.ToolStripMenuItem cmnuRelocationsAdd;
416 | private System.Windows.Forms.ToolStripMenuItem cmnuPagesAdd;
417 | private System.Windows.Forms.ToolStripSeparator toolStripSeparator3;
418 | private System.Windows.Forms.ToolStripMenuItem cmnuRelocationsEdit;
419 | private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
420 | private System.Windows.Forms.ToolStripMenuItem mnuMainFileSave;
421 | private System.Windows.Forms.ToolStripMenuItem mnuMainFileSaveAs;
422 | private System.Windows.Forms.SaveFileDialog dlgSave;
423 | }
424 | }
425 |
426 |
--------------------------------------------------------------------------------
/Relocation Section Editor/frmMain.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Data;
5 | using System.Drawing;
6 | using System.Text;
7 | using System.Windows.Forms;
8 | using System.IO;
9 |
10 | namespace Relocation_Section_Editor
11 | {
12 | public partial class frmMain : Form
13 | {
14 | private Relocations rel = null;
15 | private int pageIndex = 0;
16 | private uint baseAddress = 0;
17 | private string argPath = "";
18 |
19 | public frmMain(string[] args)
20 | {
21 | InitializeComponent();
22 |
23 | if (args.Length > 0)
24 | argPath = args[0];
25 | }
26 |
27 | private void mnuMainFileExit_Click(object sender, EventArgs e)
28 | {
29 | Application.Exit();
30 | }
31 |
32 | private void mnuMainHelpAbout_Click(object sender, EventArgs e)
33 | {
34 | MessageBox.Show("This program has been coded by gta126");
35 | }
36 |
37 | private void mnuMainFileOpen_Click(object sender, EventArgs e)
38 | {
39 | string path = "";
40 |
41 | if (!string.IsNullOrEmpty(argPath))
42 | {
43 | path = argPath;
44 | argPath = "";
45 | }
46 | else
47 | {
48 | dlgOpen.Title = "Select an executable file";
49 | dlgOpen.Filter = "Executable (*.exe)|*.exe" +
50 | "|Dynamic Link Library (*.dll)|*.dll" +
51 | "|Drivers (*.sys)|*.sys" +
52 | "|Windows Visual Style (*.msstyles)|*.msstyles" +
53 | "|Configuration Panel Widget (*.cpl)|*.cpl" +
54 | "|ActiveX Library (*.ocx)|*.ocx" +
55 | "|ActiveX Cache Library (*.oca)|*.oca" +
56 | "|Multi User Interface (*.mui)|*.mui" +
57 | "|Codecs (*.acm, *.ax)|*.acm;*.ax" +
58 | "|Borland / Delphi Library (*.bpl, *.dpl)|*.bpl;*.dpl" +
59 | "|Screensaver (*.scr)|*.scr" +
60 | "|All Executables (*.exe, *.dll, *.sys, *.msstyles, *.cpl, *.ocx, *.oca, *.mui, *.acm, *.ax, *.bpl, *.dpl, *.scr)|*.exe;*.dll;*.sys;*.msstyles;*.cpl;*.ocx;*.oca;*.mui;*.acm;*.ax;*.bpl;*.dpl;*.scr" +
61 | "|All Files (*.*)|*.*";
62 |
63 | if (dlgOpen.ShowDialog() != System.Windows.Forms.DialogResult.OK)
64 | return;
65 |
66 | path = dlgOpen.FileName;
67 | }
68 |
69 | try
70 | {
71 | rel = new Relocations(path);
72 |
73 | this.Text = "Relocation Section Editor - " + rel.GetPath();
74 |
75 | RefreshData();
76 |
77 | cmnuPages.Enabled = true;
78 | cmnuRelocations.Enabled = true;
79 | mnuMainFileSaveAs.Enabled = true;
80 | mnuMainFileSave.Enabled = true;
81 | }
82 | catch (FileNotFoundException)
83 | {
84 | MessageBox.Show("File not found");
85 | }
86 | catch (InvalidOperationException ex)
87 | {
88 | switch (ex.Message)
89 | {
90 | case "MZ":
91 | MessageBox.Show("MZ Header not found");
92 | break;
93 | case "PE":
94 | MessageBox.Show("PE Header not found");
95 | break;
96 | case "X86":
97 | MessageBox.Show("Is not a 32bits executable");
98 | break;
99 | case "RAW":
100 | MessageBox.Show("No relocation table in this file");
101 | break;
102 | default:
103 | MessageBox.Show("Unknown error");
104 | break;
105 | }
106 | }
107 | }
108 |
109 | private void lvPage_SelectedIndexChanged(object sender, EventArgs e)
110 | {
111 | if (lvPage.SelectedItems.Count < 1)
112 | return;
113 |
114 | lvRelocation.Items.Clear();
115 |
116 | uint address = (uint)lvPage.SelectedItems[0].Tag;
117 | baseAddress = address;
118 | pageIndex = lvPage.SelectedItems[0].Index;
119 |
120 | List relocs;
121 | if (!rel.TryGetRelocs(address, out relocs))
122 | return;
123 |
124 | foreach (Relocations.Reloc reloc in relocs)
125 | {
126 | ListViewItem item;
127 |
128 | if (reloc.type == Relocations.BASE_RELOCATION_TYPE.ABSOLUTE)
129 | item = new ListViewItem("0x" + reloc.offset.ToString("X8"));
130 | else
131 | item = new ListViewItem("0x" + (address + reloc.offset).ToString("X8"));
132 | item.SubItems.Add(reloc.type.ToString());
133 | item.Tag = reloc;
134 |
135 | lvRelocation.Items.Add(item);
136 | }
137 | }
138 |
139 | private void cmuRelocationsDelete_Click(object sender, EventArgs e)
140 | {
141 | if (lvRelocation.SelectedIndices.Count < 1)
142 | return;
143 |
144 | Relocations.Reloc reloc = (Relocations.Reloc)lvRelocation.SelectedItems[0].Tag;
145 | if (MessageBox.Show("Are you sure to delete the relocation address \"" + (baseAddress + reloc.offset) + "\" ?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == System.Windows.Forms.DialogResult.No)
146 | return;
147 |
148 | rel.DeleteRelocation(baseAddress + reloc.offset);
149 |
150 | RefreshData();
151 | }
152 |
153 | private void RefreshData()
154 | {
155 | int index = lvPage.SelectedIndices.Count < 1 ? 0 : lvPage.SelectedIndices[0];
156 | lvPage.Items.Clear();
157 | lvRelocation.Items.Clear();
158 |
159 | foreach (Relocations.Page page in rel.GetPages())
160 | {
161 | ListViewItem item = new ListViewItem("0x" + page.address.ToString("X8"));
162 | item.SubItems.Add("0x" + page.size.ToString("X8"));
163 | item.SubItems.Add(page.count.ToString());
164 | item.Tag = page.address;
165 |
166 | lvPage.Items.Add(item);
167 | }
168 |
169 | if (index < lvPage.Items.Count)
170 | lvPage.Items[index].Selected = true;
171 | else
172 | lvPage.Items[0].Selected = true;
173 |
174 | RefreshSize();
175 | }
176 |
177 | private void RefreshSize()
178 | {
179 | staLblCurrentSize.Text = "Current size: 0x" + rel.GetVirtuallSize().ToString("X8");
180 | staLblMaxSize.Text = "Max size: 0x" + rel.GetRawSize().ToString("X8");
181 |
182 | staPbSize.Minimum = 0;
183 | staPbSize.Maximum = (int)rel.GetRawSize();
184 | staPbSize.Value = (int)rel.GetVirtuallSize();
185 | }
186 |
187 | private void frmMain_Load(object sender, EventArgs e)
188 | {
189 | cmnuPages.Enabled = false;
190 | cmnuRelocations.Enabled = false;
191 | mnuMainFileSaveAs.Enabled = false;
192 | mnuMainFileSave.Enabled = false;
193 |
194 | if (!string.IsNullOrEmpty(argPath))
195 | mnuMainFileOpen_Click(null, null);
196 | }
197 |
198 | private void cmnuPagesDelete_Click(object sender, EventArgs e)
199 | {
200 | if (lvPage.SelectedItems.Count < 1)
201 | return;
202 |
203 | if (MessageBox.Show("Are you sure to delete this page ?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == System.Windows.Forms.DialogResult.No)
204 | return;
205 |
206 | foreach (ListViewItem item in lvRelocation.Items)
207 | {
208 | Relocations.Reloc reloc = (Relocations.Reloc)item.Tag;
209 | rel.DeleteRelocation(baseAddress + reloc.offset);
210 | }
211 |
212 | lvRelocation.Items.Clear();
213 | lvPage.Items[lvPage.SelectedIndices[0]].Remove();
214 |
215 | RefreshSize();
216 | }
217 |
218 | private void mnuAdd_Click(object sender, EventArgs e)
219 | {
220 | frmAddRelocation frm = new frmAddRelocation();
221 |
222 | if (frm.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
223 | return;
224 |
225 | int code = rel.AddRelocation(frm.GetAddress(), frm.GetRelocType());
226 |
227 | switch (code)
228 | {
229 | case -1:
230 | MessageBox.Show("This address is already in the relocation table");
231 | break;
232 | case 0:
233 | MessageBox.Show("Cannot add this address (0x" + frm.GetAddress().ToString("X8") + ")");
234 | break;
235 | case 1:
236 | case 2:
237 | RefreshData();
238 | break;
239 | default:
240 | MessageBox.Show("Unknown error");
241 | break;
242 | }
243 |
244 | }
245 |
246 | private void mnuRelocationsEdit_Click(object sender, EventArgs e)
247 | {
248 | if (lvRelocation.SelectedItems.Count < 1)
249 | return;
250 |
251 | Relocations.Reloc reloc = (Relocations.Reloc)lvRelocation.SelectedItems[0].Tag;
252 | frmEditRelocation frm = new frmEditRelocation(baseAddress + reloc.offset, reloc.type);
253 |
254 | if (frm.ShowDialog() != System.Windows.Forms.DialogResult.OK)
255 | return;
256 |
257 | if (!rel.EditRelocation(frm.GetOldAddress(), frm.GetNewAddress(), frm.GetRelocType()))
258 | {
259 | MessageBox.Show("Cannot edit this address");
260 | return;
261 | }
262 |
263 | RefreshData();
264 | }
265 |
266 | private void mnuMainFileSave_Click(object sender, EventArgs e)
267 | {
268 | if (!rel.WriteRelocations())
269 | MessageBox.Show("File not saved");
270 | }
271 |
272 | private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
273 | {
274 | if (rel != null && rel.IsNotSaved)
275 | {
276 | if (MessageBox.Show("Would you really exit this program without save the data ?", "Not Saved", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.No)
277 | e.Cancel = true;
278 | }
279 | }
280 |
281 | private void mnuMainFileSaveAs_Click(object sender, EventArgs e)
282 | {
283 | dlgSave.Filter = "Executable (*.exe)|*.exe" +
284 | "|Dynamic Link Library (*.dll)|*.dll" +
285 | "|Drivers (*.sys)|*.sys" +
286 | "|Windows Visual Style (*.msstyles)|*.msstyles" +
287 | "|Configuration Panel Widget (*.cpl)|*.cpl" +
288 | "|ActiveX Library (*.ocx)|*.ocx" +
289 | "|ActiveX Cache Library (*.oca)|*.oca" +
290 | "|Multi User Interface (*.mui)|*.mui" +
291 | "|Codecs (*.acm, *.ax)|*.acm;*.ax" +
292 | "|Borland / Delphi Library (*.bpl, *.dpl)|*.bpl;*.dpl" +
293 | "|Screensaver (*.scr)|*.scr" +
294 | "|All Executables (*.exe, *.dll, *.sys, *.msstyles, *.cpl, *.ocx, *.oca, *.mui, *.acm, *.ax, *.bpl, *.dpl, *.scr)|*.exe;*.dll;*.sys;*.msstyles;*.cpl;*.ocx;*.oca;*.mui;*.acm;*.ax;*.bpl;*.dpl;*.scr" +
295 | "|All Files (*.*)|*.*";
296 |
297 | switch (Path.GetExtension(rel.GetPath()))
298 | {
299 | case ".exe":
300 | dlgSave.FilterIndex = 1;
301 | break;
302 | case ".dll":
303 | dlgSave.FilterIndex = 2;
304 | break;
305 | case ".sys":
306 | dlgSave.FilterIndex = 3;
307 | break;
308 | case ".msstyles":
309 | dlgSave.FilterIndex = 4;
310 | break;
311 | case ".cpl":
312 | dlgSave.FilterIndex = 5;
313 | break;
314 | case ".ocx":
315 | dlgSave.FilterIndex = 6;
316 | break;
317 | case ".oca":
318 | dlgSave.FilterIndex = 7;
319 | break;
320 | case ".mui":
321 | dlgSave.FilterIndex = 8;
322 | break;
323 | case ".acm":
324 | case ".ax":
325 | dlgSave.FilterIndex = 9;
326 | break;
327 | case ".bpl":
328 | case ".dpl":
329 | dlgSave.FilterIndex = 10;
330 | break;
331 | case ".scr":
332 | dlgSave.FilterIndex = 11;
333 | break;
334 | }
335 |
336 |
337 | if (dlgSave.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
338 | return;
339 |
340 | if (!rel.WriteRelocations(dlgSave.FileName))
341 | MessageBox.Show("File not saved");
342 | else
343 | this.Text = "Relocation Section Editor - " + rel.GetPath();
344 | }
345 | }
346 | }
347 |
--------------------------------------------------------------------------------
/Relocation Section Editor/frmMain.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 | 17, 17
122 |
123 |
124 | 454, 17
125 |
126 |
127 | 220, 17
128 |
129 |
130 | 121, 17
131 |
132 |
133 | 365, 17
134 |
135 |
136 | 568, 17
137 |
138 |
--------------------------------------------------------------------------------