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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 686 - (hide annotations) (download)
Mon Jun 17 09:31:52 2013 UTC (7 years, 4 months ago) by william
File size: 4006 byte(s)
+ massive move of source files

1 william 686 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 uint _VirtualEntryPoint { get; private set; }
29     public string VirtualEntryPoint { get { return string.Format("0x{0:x8}", _VirtualEntryPoint); } }
30    
31     [Browsable(false)]
32     public uint _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:x8}", _VirtualRVA); } }
47    
48     [Browsable(false)]
49     public ulong _VirtualImageBase { get; private set; }
50     public string VirtualImageBase
51     {
52     get
53     {
54     if (this.Is32bitAssembly())
55     {
56     return string.Format("0x{0:x8}", _VirtualImageBase);
57     }
58     else
59     {
60     return string.Format("0x{0:x16}", _VirtualImageBase);
61     }
62     }
63     }
64    
65    
66     #endregion
67    
68     private PeHeaderReader reader = null;
69    
70     public static readonly IPEDData Empty = new PEData();
71    
72     protected PEData() { }
73     public PEData(IAcceptsProcess iap)
74     {
75     if (iap == null) { throw new ArgumentNullException("iap", "The selected process cannot be null"); }
76     Process p = iap.AcceptedProcess;
77     reader = new PeHeaderReader(p);
78    
79     this._VirtualEntryPoint = (uint)p.MainModule.EntryPointAddress;
80     if (this.Is32bitAssembly())
81     {
82     this._VirtualImageBase = (uint)p.MainModule.BaseAddress;
83     }
84     else
85     {
86     this._VirtualImageBase = (ulong)p.MainModule.BaseAddress;
87     }
88    
89     this.SectionData = new ISECTION_DATA[this.SectionHeaders.Length];
90    
91     for (int i = 0; i < this.SectionHeaders.Length; i++)
92     {
93     var t = this.SectionHeaders[i];
94     SECTION_DATA data = new SECTION_DATA(t.Name, t._VirtualAddress, this._VirtualRVA, t._VirtualSize);
95     this.SectionData[i] = (ISECTION_DATA)data;
96     }
97     }
98     public PEData(IAcceptsProcessAndConfig iapc) : this((IAcceptsProcess)iapc) { }
99     }
100     }

  ViewVC Help
Powered by ViewVC 1.1.22