1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
/*************************************************************************/
/* Copyright (c) 2015 dx, http://kaimi.ru */
/* */
/* Permission is hereby granted, free of charge, to any person */
/* obtaining a copy of this software and associated documentation */
/* files (the "Software"), to deal in the Software without */
/* restriction, including without limitation the rights to use, */
/* copy, modify, merge, publish, distribute, sublicense, and/or */
/* sell copies of the Software, and to permit persons to whom the */
/* Software is furnished to do so, subject to the following conditions: */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include <string.h>
#include "pe_dotnet.h"
namespace pe_bliss
{
using namespace pe_win;
//.NET
basic_dotnet_info::basic_dotnet_info()
{
memset(&header_, 0, sizeof(header_));
}
//Constructor from data
basic_dotnet_info::basic_dotnet_info(const image_cor20_header& header)
:header_(header)
{}
//Returns major runtime version
uint16_t basic_dotnet_info::get_major_runtime_version() const
{
return header_.MajorRuntimeVersion;
}
//Returns minor runtime version
uint16_t basic_dotnet_info::get_minor_runtime_version() const
{
return header_.MinorRuntimeVersion;
}
//Returns RVA of metadata (symbol table and startup information)
uint32_t basic_dotnet_info::get_rva_of_metadata() const
{
return header_.MetaData.VirtualAddress;
}
//Returns size of metadata (symbol table and startup information)
uint32_t basic_dotnet_info::get_size_of_metadata() const
{
return header_.MetaData.Size;
}
//Returns flags
uint32_t basic_dotnet_info::get_flags() const
{
return header_.Flags;
}
//Returns true if entry point is native
bool basic_dotnet_info::is_native_entry_point() const
{
return (header_.Flags & comimage_flags_native_entrypoint) ? true : false;
}
//Returns true if 32 bit required
bool basic_dotnet_info::is_32bit_required() const
{
return (header_.Flags & comimage_flags_32bitrequired) ? true : false;
}
//Returns true if image is IL library
bool basic_dotnet_info::is_il_library() const
{
return (header_.Flags & comimage_flags_il_library) ? true : false;
}
//Returns true if image uses IL only
bool basic_dotnet_info::is_il_only() const
{
return (header_.Flags & comimage_flags_ilonly) ? true : false;
}
//Returns entry point RVA (if entry point is native)
//Returns entry point managed token (if entry point is managed)
uint32_t basic_dotnet_info::get_entry_point_rva_or_token() const
{
return header_.EntryPointToken;
}
//Returns RVA of managed resources
uint32_t basic_dotnet_info::get_rva_of_resources() const
{
return header_.Resources.VirtualAddress;
}
//Returns size of managed resources
uint32_t basic_dotnet_info::get_size_of_resources() const
{
return header_.Resources.Size;
}
//Returns RVA of strong name signature
uint32_t basic_dotnet_info::get_rva_of_strong_name_signature() const
{
return header_.StrongNameSignature.VirtualAddress;
}
//Returns size of strong name signature
uint32_t basic_dotnet_info::get_size_of_strong_name_signature() const
{
return header_.StrongNameSignature.Size;
}
//Returns RVA of code manager table
uint32_t basic_dotnet_info::get_rva_of_code_manager_table() const
{
return header_.CodeManagerTable.VirtualAddress;
}
//Returns size of code manager table
uint32_t basic_dotnet_info::get_size_of_code_manager_table() const
{
return header_.CodeManagerTable.Size;
}
//Returns RVA of VTable fixups
uint32_t basic_dotnet_info::get_rva_of_vtable_fixups() const
{
return header_.VTableFixups.VirtualAddress;
}
//Returns size of VTable fixups
uint32_t basic_dotnet_info::get_size_of_vtable_fixups() const
{
return header_.VTableFixups.Size;
}
//Returns RVA of export address table jumps
uint32_t basic_dotnet_info::get_rva_of_export_address_table_jumps() const
{
return header_.ExportAddressTableJumps.VirtualAddress;
}
//Returns size of export address table jumps
uint32_t basic_dotnet_info::get_size_of_export_address_table_jumps() const
{
return header_.ExportAddressTableJumps.Size;
}
//Returns RVA of managed native header
//(precompiled header info, usually set to zero, for internal use)
uint32_t basic_dotnet_info::get_rva_of_managed_native_header() const
{
return header_.ManagedNativeHeader.VirtualAddress;
}
//Returns size of managed native header
//(precompiled header info, usually set to zero, for internal use)
uint32_t basic_dotnet_info::get_size_of_managed_native_header() const
{
return header_.ManagedNativeHeader.Size;
}
//Returns basic .NET information
//If image is not native, throws an exception
const basic_dotnet_info get_basic_dotnet_info(const pe_base& pe)
{
//If there's no debug directory, return empty list
if(!pe.is_dotnet())
throw pe_exception("Image does not have managed code", pe_exception::image_does_not_have_managed_code);
//Return basic .NET information
return basic_dotnet_info(pe.section_data_from_rva<image_cor20_header>(pe.get_directory_rva(image_directory_entry_com_descriptor), section_data_virtual, true));
}
}
|