/[RomCheater]/trunk/RomCheater.Core/PEData.cs
ViewVC logotype

Contents of /trunk/RomCheater.Core/PEData.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 797 - (show annotations) (download)
Mon Apr 7 12:03:17 2014 UTC (6 years, 6 months ago) by william
File size: 3932 byte(s)
+ fix hex format of values in PEData/IPEData

1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.ComponentModel;
6 using System.Diagnostics;
7
8 namespace RomCheater.Core
9 {
10 public class PEData : IPEDData
11 {
12 #region IPEDData Members
13 public IMAGE_DOS_HEADER DosHeader { get { if (reader == null) { return new IMAGE_DOS_HEADER(); } else { return reader.DosHeader; } } }
14 public string NTSignature { get { if (reader == null) { return "0"; } else { return reader.NTSignature; } } }
15 public IMAGE_FILE_HEADER FileHeader { get { if (reader == null) { return new IMAGE_FILE_HEADER(); } else { return reader.FileHeader; } } }
16 public IMAGE_OPTIONAL_HEADER32 OptionalHeader32 { get { if (reader == null) { return new IMAGE_OPTIONAL_HEADER32(); } else { return reader.OptionalHeader32; } } }
17 public IMAGE_OPTIONAL_HEADER64 OptionalHeader64 { get { if (reader == null) { return new IMAGE_OPTIONAL_HEADER64(); } else { return reader.OptionalHeader64; } } }
18
19 public IMAGE_SECTION_HEADER[] SectionHeaders { get { if (reader == null) { return new IMAGE_SECTION_HEADER[0]; } else { return reader.ImageSectionHeaders; } } }
20
21 private ISECTION_DATA[] _SectionData;
22 public ISECTION_DATA[] SectionData { get { return _SectionData; } private set { _SectionData = value; } }
23
24 public Boolean Is32bitAssembly() { if (reader == null) { return true; } else { return reader.Is32BitHeader; } }
25
26
27 [Browsable(false)]
28 public ulong _VirtualEntryPoint { get; private set; }
29 public string VirtualEntryPoint { get { return string.Format("0x{0}", _VirtualEntryPoint.ToString("X")); } }
30
31 [Browsable(false)]
32 public ulong _VirtualRVA
33 {
34 get
35 {
36 if (this.Is32bitAssembly())
37 {
38 return (_VirtualEntryPoint - OptionalHeader32._AddressOfEntryPoint);
39 }
40 else
41 {
42 return (_VirtualEntryPoint - OptionalHeader64._AddressOfEntryPoint);
43 }
44 }
45 }
46 public string VirtualRVA { get { return string.Format("0x{0}", _VirtualRVA.ToString("X")); } }
47
48 [Browsable(false)]
49 public ulong _VirtualImageBase { get; private set; }
50 public string VirtualImageBase
51 {
52 get
53 {
54 return string.Format("0x{0}", _VirtualImageBase.ToString("X"));
55 }
56 }
57
58
59 #endregion
60
61 private PeHeaderReader reader = null;
62
63 public static readonly IPEDData Empty = new PEData();
64
65 protected PEData() { }
66 public PEData(IAcceptsProcess iap)
67 {
68 if (iap == null) { throw new ArgumentNullException("iap", "The selected process cannot be null"); }
69 Process p = iap.AcceptedProcess;
70 reader = new PeHeaderReader(p);
71
72 if (this.Is32bitAssembly())
73 {
74 this._VirtualEntryPoint = (uint)p.MainModule.EntryPointAddress;
75 this._VirtualImageBase = (uint)p.MainModule.BaseAddress;
76 }
77 else
78 {
79 this._VirtualEntryPoint = (ulong)p.MainModule.EntryPointAddress;
80 this._VirtualImageBase = (ulong)p.MainModule.BaseAddress;
81 }
82
83 this.SectionData = new ISECTION_DATA[this.SectionHeaders.Length];
84
85 for (int i = 0; i < this.SectionHeaders.Length; i++)
86 {
87 var t = this.SectionHeaders[i];
88 SECTION_DATA data = new SECTION_DATA(t.Name, t._VirtualAddress, this._VirtualRVA, t._VirtualSize);
89 this.SectionData[i] = (ISECTION_DATA)data;
90 }
91 }
92 public PEData(IAcceptsProcessAndConfig iapc) : this((IAcceptsProcess)iapc) { }
93 }
94 }

  ViewVC Help
Powered by ViewVC 1.1.22