Repository navigation
Expand file tree
/
Copy pathidaldr.h
More file actions
executable file
·148 lines (136 loc) · 3.72 KB
/
Copy pathidaldr.h
File metadata and controls
executable file
·148 lines (136 loc) · 3.72 KB
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
#ifndef __IDALDR_H__
#define __IDALDR_H__
#include <ida.hpp>
#include <fpro.h>
#include <idp.hpp>
#include <loader.hpp>
#include <name.hpp>
#include <bytes.hpp>
#include <offset.hpp>
#include <segment.hpp>
#include <srarea.hpp>
#include <fixup.hpp>
#include <entry.hpp>
#include <auto.hpp>
#include <diskio.hpp>
#include <kernwin.hpp>
#include <typeinf.hpp>
//----------------------------------
#define CLASS_CODE "CODE"
#define NAME_CODE ".text"
#define CLASS_DATA "DATA"
#define CLASS_CONST "CONST"
#define NAME_DATA ".data"
#define CLASS_BSS "BSS"
#define NAME_BSS ".bss"
#define NAME_EXTERN "extern"
#define NAME_COMMON "common"
#define NAME_ABS "abs"
#define NAME_UNDEF "UNDEF"
#define CLASS_STACK "STACK"
#define CLASS_RES16 "RESOURCE"
#define LDR_NODE "$ IDALDR node for ids loading $"
#define LDR_INFO_NODE "$ IDALDR node for unload $"
//--------------------------------------------------------------------------
template <class T> bool _validate_array_count(
linput_t *li,
T *p_cnt,
size_t elsize,
int64 current_offset=-1,
int64 max_offset=-1)
{
if ( current_offset == -1 )
current_offset = qltell64(li);
if ( max_offset == -1 )
max_offset = qlsize64(li);
int64 rest = max_offset - current_offset;
T cnt = *p_cnt;
if ( current_offset >= 0 && rest >= 0 )
{
if ( is_mul_ok<size_t>(elsize, cnt) )
{
size_t needed = elsize * cnt;
if ( rest >= needed )
return true; // all ok
}
cnt = rest / elsize;
}
else
{
cnt = 0;
}
*p_cnt = cnt;
return false;
}
//--------------------------------------------------------------------------
// Validate a counter taken from the input file. If there are not enough bytes
// in the input file, ask the user if we may continue and fix the counter.
template <class T> void validate_array_count(
linput_t *li,
T *p_cnt,
size_t elsize,
const char *counter_name,
int64 curoff=-1,
int64 maxoff=-1)
{
if ( !_validate_array_count(li, p_cnt, elsize, curoff, maxoff) )
{
static const char format[] = "%s is incorrect, maximum possible value is %u%s";
#ifdef __LOADER__
if ( askyn_c(ASKBTN_YES, format, counter_name, uint(*p_cnt),
". Do you want to continue with the new value?") != ASKBTN_YES )
{
loader_failure(NULL);
}
#else
warning(format, counter_name, uint(*p_cnt), "");
#endif
}
}
//--------------------------------------------------------------------------
// Validate a counter taken from the input file. If there are not enough bytes
// in the input file, die.
template <class T> void validate_array_count_or_die(
linput_t *li,
T cnt,
size_t elsize,
const char *counter_name,
int64 curoff=-1,
int64 maxoff=-1)
{
if ( !_validate_array_count(li, &cnt, elsize, curoff, maxoff) )
{
static const char format[] = "%s is incorrect, maximum possible value is %u%s";
#ifdef __LOADER__
loader_failure(format, counter_name, uint(cnt), "");
#else
error(format, counter_name, uint(cnt), "");
#endif
}
}
//----------------------------------
inline uchar readchar(linput_t *li)
{
uchar x;
lread(li, &x, sizeof(x));
return x;
}
//----------------------------------
inline uint16 readshort(linput_t *li)
{
uint16 x;
lread(li, &x, sizeof(x));
return x;
}
//----------------------------------
inline uint32 readlong(linput_t *li)
{
uint32 x;
lread(li, &x, sizeof(x));
return x;
}
inline uint32 mf_readlong(linput_t *li) { return swap32(readlong(li)); }
inline uint16 mf_readshort(linput_t *li) { return swap16(readshort(li)); }
// each loader must declare and export this symbol:
idaman loader_t ida_module_data LDSC;
#endif // __IDALDR_H__