Skip to content
This repository was archived by the owner on Jun 5, 2019. It is now read-only.

Commit 9414036

Browse files
committed
Merge pull request #431 from smaillet-ms/DisAsmPE
Updated DisAsmPE sample
2 parents a35ee52 + 0127191 commit 9414036

18 files changed

+941
-683
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@ ReleaseNotesCrypto.txt
5555
/tools/DisAsmPE/Debug
5656
/tools/DisAsmPE/DisAsmPE/Debug
5757
/tools/DisAsmPE/NETMF.PE.Metadata/Debug
58+
/tools/DisAsmPE/DisAsmPE/*.txt
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
##### AssemblyRefTableEntry
2+
The assembly Reference table contains references to other assemblies. The runtime will lookup the assembly by name and version
3+
when resolving the reference to an assembly header.
4+
5+
The format of the AssemblyRefTableEntry is as follows:
6+
7+
| Name | Type | Description
8+
|-----------|-----------------------|------------
9+
| Name | StringTableIndex | index into the string table blob for the name of the referenced assembly
10+
| {padding} | uint16_t | Unused padding (Must be 0)
11+
| Version | VersionInfo | VersionInfo structure for the version of the assembly (Checked at runtime for an EXACT match)
12+

tools/DisAsmPE/DisAsmPE.sln

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DisAsmPE", "DisAsmPE\DisAsm
99
EndProject
1010
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C3C6516C-47F7-4675-8934-9264C513CC96}"
1111
ProjectSection(SolutionItems) = preProject
12+
AssemblyRefTableEntry.md = AssemblyRefTableEntry.md
1213
PeFileFormat.md = PeFileFormat.md
14+
readme.md = readme.md
15+
TypeRefTableEntry.md = TypeRefTableEntry.md
1316
EndProjectSection
1417
EndProject
1518
Global
Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
#pragma once
2+
////////////////////////////////////////////////////////////////////////////////////////////////
3+
// Copyright (c) Microsoft, Inc. All rights reserved.
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use these files
6+
// except in compliance with the License.
7+
// You may obtain a copy of the License at:
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software distributed under the
12+
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13+
// either express or implied. See the License for the specific language governing permissions
14+
// and limitations under the License.
15+
//
16+
////////////////////////////////////////////////////////////////////////////////////////////////
17+
#include "stdafx.h"
18+
#include <iostream>
19+
#include "MetadataTables.h"
20+
#include "CommonFormatting.h"
21+
22+
using namespace NETMF::Metadata;
23+
using namespace NETMF::Graphics;
24+
25+
std::ios_base& HEX( std::ios_base& strm )
26+
{
27+
return std::uppercase( std::hex( strm ) );
28+
}
29+
30+
std::ostream& operator<<( std::ostream& strm, NETMF::Metadata::VersionInfo const& version )
31+
{
32+
strm << version.MajorVersion << '.' << version.MinorVersion << '.' << version.BuildNumber << '.' << version.RevisionNumber;
33+
return strm;
34+
}
35+
36+
// create an std::string with whitespace control chars replaced as standard C++ char escape style
37+
std::string FormatString( const char* peString )
38+
{
39+
std::string retVal( peString );
40+
// not the most efficient implementation, but this is an illustrative app, not a production one...
41+
FindAndReplace( retVal, std::string("\n"), std::string("\\n") );
42+
FindAndReplace( retVal, std::string("\r"), std::string("\\r") );
43+
FindAndReplace( retVal, std::string("\t"), std::string("\\t") );
44+
return retVal;
45+
}
46+
47+
std::ostream& operator<<( std::ostream& strm, TableKind kind )
48+
{
49+
switch( kind )
50+
{
51+
case NETMF::Metadata::TableKind::AssemblyRef:
52+
strm << "AssemblyRef";
53+
break;
54+
case NETMF::Metadata::TableKind::TypeRef:
55+
strm << "TypeRef";
56+
break;
57+
case NETMF::Metadata::TableKind::FieldRef:
58+
strm << "FieldRef";
59+
break;
60+
case NETMF::Metadata::TableKind::MethodRef:
61+
strm << "MethodRef";
62+
break;
63+
case NETMF::Metadata::TableKind::TypeDef:
64+
strm << "TypeDef";
65+
break;
66+
case NETMF::Metadata::TableKind::FieldDef:
67+
strm << "FieldDef";
68+
break;
69+
case NETMF::Metadata::TableKind::MethodDef:
70+
strm << "MethodDef";
71+
break;
72+
case NETMF::Metadata::TableKind::Attributes:
73+
strm << "Attributes";
74+
break;
75+
case NETMF::Metadata::TableKind::TypeSpec:
76+
strm << "TypeSpec";
77+
break;
78+
case NETMF::Metadata::TableKind::Resources:
79+
strm << "Resources";
80+
break;
81+
case NETMF::Metadata::TableKind::ResourcesData:
82+
strm << "ResourcesData";
83+
break;
84+
case NETMF::Metadata::TableKind::Strings:
85+
strm << "Strings";
86+
break;
87+
case NETMF::Metadata::TableKind::Signatures:
88+
strm << "Signatures";
89+
break;
90+
case NETMF::Metadata::TableKind::ByteCode:
91+
strm << "ByteCode";
92+
break;
93+
case NETMF::Metadata::TableKind::ResourcesFiles:
94+
strm << "ResourcesFiles";
95+
break;
96+
case NETMF::Metadata::TableKind::EndOfAssembly:
97+
strm << "EndOfAssembly";
98+
break;
99+
default:
100+
strm << "<invalid>";
101+
break;
102+
}
103+
return strm;
104+
}
105+
106+
std::ostream& operator<<( std::ostream& strm, ResourceKind kind )
107+
{
108+
switch( kind )
109+
{
110+
case NETMF::Metadata::ResourceKind::Invalid:
111+
strm << "Invalid";
112+
break;
113+
case NETMF::Metadata::ResourceKind::Bitmap:
114+
strm << "Bitmap";
115+
break;
116+
case NETMF::Metadata::ResourceKind::Font:
117+
strm << "Font";
118+
break;
119+
case NETMF::Metadata::ResourceKind::String:
120+
strm << "String";
121+
break;
122+
case NETMF::Metadata::ResourceKind::Binary:
123+
strm << "Binary";
124+
break;
125+
default:
126+
strm << "Unknown ResourceKind: " << static_cast< uint16_t >( kind );
127+
break;
128+
}
129+
return strm;
130+
}
131+
132+
std::ostream& operator<<( std::ostream& strm, AssemblyHeaderFlags flags )
133+
{
134+
static std::map< AssemblyHeaderFlags, char const*> const flagNamesMap =
135+
{
136+
{ AssemblyHeaderFlags::None , "None" },
137+
{ AssemblyHeaderFlags::NeedReboot, "NeedReboot" },
138+
{ AssemblyHeaderFlags::Patch , "Patch" },
139+
{ AssemblyHeaderFlags::NeedReboot, "NeedReboot" }
140+
};
141+
142+
OutputEnumFlags( strm, flags, flagNamesMap );
143+
return strm;
144+
}
145+
146+
std::ostream& operator<<( std::ostream& strm, TypeDefFlags flags )
147+
{
148+
static std::map< TypeDefFlags, char const*> const flagNamesMap =
149+
{
150+
{ TypeDefFlags::None ,"None" },
151+
{ TypeDefFlags::ScopeMask ,"ScopeMask" },
152+
{ TypeDefFlags::NotPublic ,"NotPublic" },
153+
{ TypeDefFlags::Public ,"Public" },
154+
{ TypeDefFlags::NestedPublic ,"NestedPublic" },
155+
{ TypeDefFlags::NestedPrivate ,"NestedPrivate" },
156+
{ TypeDefFlags::NestedFamily ,"NestedFamily" },
157+
{ TypeDefFlags::NestedAssembly ,"NestedAssembly" },
158+
{ TypeDefFlags::NestedFamANDAssem ,"NestedFamANDAssem" },
159+
{ TypeDefFlags::NestedFamORAssem ,"NestedFamORAssem" },
160+
{ TypeDefFlags::Serializable ,"Serializable" },
161+
{ TypeDefFlags::SemanticsMask ,"SemanticsMask" },
162+
{ TypeDefFlags::Class ,"Class" },
163+
{ TypeDefFlags::ValueType ,"ValueType" },
164+
{ TypeDefFlags::Interface ,"Interface" },
165+
{ TypeDefFlags::Enum ,"Enum" },
166+
{ TypeDefFlags::Abstract ,"Abstract" },
167+
{ TypeDefFlags::Sealed ,"Sealed" },
168+
{ TypeDefFlags::SpecialName ,"SpecialName" },
169+
{ TypeDefFlags::Delegate ,"Delegate" },
170+
{ TypeDefFlags::MulticastDelegate ,"MulticastDelegate" },
171+
{ TypeDefFlags::Patched ,"Patched" },
172+
{ TypeDefFlags::BeforeFieldInit ,"BeforeFieldInit" },
173+
{ TypeDefFlags::HasSecurity ,"HasSecurity" },
174+
{ TypeDefFlags::HasFinalizer ,"HasFinalizer" },
175+
{ TypeDefFlags::HasAttributes ,"HasAttributes" },
176+
};
177+
178+
OutputEnumFlags( strm, flags, flagNamesMap );
179+
return strm;
180+
}
181+
182+
std::ostream& operator<<( std::ostream& strm, MethodDefFlags flags )
183+
{
184+
static std::map< MethodDefFlags, char const*> const flagNamesMap =
185+
{
186+
{ MethodDefFlags::ScopeMask ,"ScopeMask" },
187+
{ MethodDefFlags::PrivateScope ,"PrivateScope" },
188+
{ MethodDefFlags::Private ,"Private" },
189+
{ MethodDefFlags::FamANDAssem ,"FamANDAssem" },
190+
{ MethodDefFlags::Assem ,"Assem" },
191+
{ MethodDefFlags::Family ,"Family" },
192+
{ MethodDefFlags::FamORAssem ,"FamORAssem" },
193+
{ MethodDefFlags::Public ,"Public" },
194+
{ MethodDefFlags::Static ,"Static" },
195+
{ MethodDefFlags::Final ,"Final" },
196+
{ MethodDefFlags::Virtual ,"Virtual" },
197+
{ MethodDefFlags::HideBySig ,"HideBySig" },
198+
{ MethodDefFlags::VtableLayoutMask ,"VtableLayoutMask" },
199+
{ MethodDefFlags::ReuseSlot ,"ReuseSlot" },
200+
{ MethodDefFlags::NewSlot ,"NewSlot" },
201+
{ MethodDefFlags::Abstract ,"Abstract" },
202+
{ MethodDefFlags::SpecialName ,"SpecialName" },
203+
{ MethodDefFlags::NativeProfiled ,"NativeProfiled" },
204+
{ MethodDefFlags::Constructor ,"Constructor" },
205+
{ MethodDefFlags::StaticConstructor ,"StaticConstructor" },
206+
{ MethodDefFlags::Finalizer ,"Finalizer" },
207+
{ MethodDefFlags::DelegateConstructor ,"DelegateConstructor" },
208+
{ MethodDefFlags::DelegateInvoke ,"DelegateInvoke" },
209+
{ MethodDefFlags::DelegateBeginInvoke ,"DelegateBeginInvoke" },
210+
{ MethodDefFlags::DelegateEndInvoke ,"DelegateEndInvoke" },
211+
{ MethodDefFlags::Synchronized ,"Synchronized" },
212+
{ MethodDefFlags::GloballySynchronized ,"GloballySynchronized" },
213+
{ MethodDefFlags::Patched ,"Patched" },
214+
{ MethodDefFlags::EntryPoint ,"EntryPoint" },
215+
{ MethodDefFlags::RequireSecObject ,"RequireSecObject" },
216+
{ MethodDefFlags::HasSecurity ,"HasSecurity" },
217+
{ MethodDefFlags::HasExceptionHandlers ,"HasExceptionHandlers" },
218+
{ MethodDefFlags::HasAttributes ,"HasAttributes" }
219+
};
220+
221+
OutputEnumFlags( strm, flags, flagNamesMap );
222+
return strm;
223+
}
224+
225+
std::ostream& operator<<( std::ostream& strm, FieldDefFlags flags )
226+
{
227+
std::map<FieldDefFlags, char const*> const flagNamesMap =
228+
{
229+
{ FieldDefFlags::None , "None" },
230+
{ FieldDefFlags::ScopeMask , "ScopeMask" },
231+
{ FieldDefFlags::Private , "Private" },
232+
{ FieldDefFlags::FamANDAssem , "FamANDAssem" },
233+
{ FieldDefFlags::Assembly , "Assembly" },
234+
{ FieldDefFlags::Family , "Family" },
235+
{ FieldDefFlags::FamORAssem , "FamORAssem" },
236+
{ FieldDefFlags::Public , "Public" },
237+
{ FieldDefFlags::NotSerialized , "NotSerialized" },
238+
{ FieldDefFlags::Static , "Static" },
239+
{ FieldDefFlags::InitOnly , "InitOnly" },
240+
{ FieldDefFlags::Literal , "Literal" },
241+
{ FieldDefFlags::SpecialName , "SpecialName" },
242+
{ FieldDefFlags::HasDefault , "HasDefault" },
243+
{ FieldDefFlags::HasFieldRVA , "HasFieldRVA" },
244+
{ FieldDefFlags::NoReflection , "NoReflection" },
245+
{ FieldDefFlags::HasAttributes , "HasAttributes" }
246+
};
247+
248+
OutputEnumFlags( strm, flags, flagNamesMap );
249+
return strm;
250+
}
251+
252+
std::ostream& operator<<( std::ostream& strm, NETMF::Graphics::BitmapDescriptorFlags flags )
253+
{
254+
static std::map< BitmapDescriptorFlags, char const*> flagNamesMap =
255+
{
256+
{ BitmapDescriptorFlags::None , "None" },
257+
{ BitmapDescriptorFlags::ReadOnly , "ReadOnly" },
258+
{ BitmapDescriptorFlags::Compressed, "Compressed" }
259+
};
260+
261+
OutputEnumFlags( strm, flags, flagNamesMap );
262+
return strm;
263+
}
264+
265+
std::ostream& operator<<( std::ostream& strm, NETMF::Graphics::BitmapImageType kind )
266+
{
267+
switch( kind )
268+
{
269+
case NETMF::Graphics::BitmapImageType::TinyCLRBitmap:
270+
strm << "TinyCLRBitmap";
271+
break;
272+
case NETMF::Graphics::BitmapImageType::Gif:
273+
strm << "Gif";
274+
break;
275+
case NETMF::Graphics::BitmapImageType::JPeg:
276+
strm << "JPeg";
277+
break;
278+
case NETMF::Graphics::BitmapImageType::Bmp:
279+
strm << "Bmp";
280+
break;
281+
default:
282+
break;
283+
}
284+
return strm;
285+
}
286+

0 commit comments

Comments
 (0)