ROSE
0.9.6a
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
PeImportItem.C
Go to the documentation of this file.
1
9
#include "
sage3basic.h
"
10
#include "
MemoryMap.h
"
11
12
void
13
SgAsmPEImportItem::ctor
(
SgAsmPEImportItemList
*parent)
14
{
15
set_parent
(parent);
16
if
(parent)
17
parent->
get_vector
().push_back(
this
);
18
set_by_ordinal
(
true
);
19
set_ordinal
(0);
20
set_hint
(0);
21
set_hintname_rva
(0);
22
set_hintname_nalloc
(0);
23
set_bound_rva
(0);
24
25
SgAsmBasicString
*
name
=
new
SgAsmBasicString
(
""
);
26
set_name
(name);
27
name->
set_parent
(
this
);
28
}
29
30
void
31
SgAsmPEImportItem::ctor
(
SgAsmPEImportDirectory
*idir)
32
{
33
ctor
(idir->
get_imports
());
34
}
35
36
void
37
SgAsmPEImportItem::ctor
(
SgAsmPEImportDirectory
*idir,
const
std::string &
name
,
unsigned
hint)
38
{
39
ctor
(idir);
40
set_by_ordinal
(
false
);
41
get_name
()->
set_string
(name);
42
set_hint
(hint);
43
}
44
45
void
46
SgAsmPEImportItem::ctor
(
SgAsmPEImportDirectory
*idir,
unsigned
ordinal)
47
{
48
ctor
(idir);
49
set_by_ordinal
(
true
);
50
set_ordinal
(ordinal);
51
}
52
56
size_t
57
SgAsmPEImportItem::hintname_required_size
()
const
58
{
59
return
ALIGN_UP
(2
/*hint*/
+
p_name
->
get_string
().size() + 1
/*NUL*/
, 2);
60
}
61
64
rose_addr_t
65
SgAsmPEImportItem::get_iat_entry_va
()
const
66
{
67
SgAsmPEImportDirectory
*idir = SageInterface::getEnclosingNode<SgAsmPEImportDirectory>(
this
);
68
assert(idir!=NULL);
// we need some context in order to find the address
69
int
idx = idir->
find_import_item
(
this
);
70
assert(idx>=0);
// parent/child connectivity problem
71
SgAsmPEFileHeader
*fhdr = SageInterface::getEnclosingNode<SgAsmPEFileHeader>(idir);
72
assert(fhdr!=NULL);
73
rose_addr_t
entry_size = fhdr->
get_word_size
();
74
return
idir->
get_iat_rva
().
get_va
() + idx * entry_size;
75
}
76
78
void
79
SgAsmPEImportItem::dump
(FILE *f,
const
char
*
prefix
, ssize_t idx)
const
80
{
81
char
p[4096];
82
if
(idx>=0) {
83
sprintf(p,
"%sImportItem[%zd]."
, prefix, idx);
84
}
else
{
85
sprintf(p,
"%sImportItem."
, prefix);
86
}
87
88
const
int
w =
std::max
(1,
DUMP_FIELD_WIDTH
-(
int
)strlen(p));
89
90
if
(
p_by_ordinal
) {
91
fprintf(f,
"%s%-*s = 0x%04x (%u)"
, p, w,
"ordinal"
,
p_ordinal
,
p_ordinal
);
92
if
(
p_hintname_rva
.
get_rva
()!=0 ||
p_hint
!=0 || !
p_name
->
get_string
().empty())
93
fprintf(f,
" (hint/name rva %s %zu bytes, hint=0x%04x (%u), name=\"%s\")"
,
94
p_hintname_rva
.
to_string
().c_str(),
p_hintname_nalloc
,
p_hint
,
p_hint
,
p_name
->
get_string
(
true
).c_str());
95
fprintf(f,
"\n"
);
96
}
else
{
97
fprintf(f,
"%s%-*s = rva %s %zu bytes, hint=0x%04x (%u), name=\"%s\""
,
98
p, w,
"hint/name"
,
p_hintname_rva
.
to_string
().c_str(),
p_hintname_nalloc
,
99
p_hint
,
p_hint
,
p_name
->
get_string
(
true
).c_str());
100
if
(
p_ordinal
!=0)
101
fprintf(f,
" (ordinal=0x%02x (%u))"
,
p_ordinal
,
p_ordinal
);
102
fprintf(f,
"\n"
);
103
}
104
105
if
(
p_bound_rva
.
get_rva
()!=0)
106
fprintf(f,
"%s%-*s = %s\n"
, p, w,
"bound"
,
p_bound_rva
.
to_string
().c_str());
107
}
rose-edg4x
src
frontend
BinaryFormats
PeImportItem.C
Generated on Mon May 5 2014 17:29:25 for ROSE by
1.8.4