forked from tecknicaltom/HT-Editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtnenms.cc
107 lines (94 loc) · 2.79 KB
/
htnenms.cc
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
/*
* HT Editor
* htnenms.cc
*
* Copyright (C) 1999-2002 Stefan Weyergraf
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "atom.h"
#include "endianess.h"
#include "htne.h"
#include "htnenms.h"
#include "httag.h"
#include "formats.h"
#include "snprintf.h"
#include <stdlib.h>
#include <string.h>
static void assign_entrypoint_name(ht_ne_shared_data *ne_shared, uint i, char *name)
{
if (ne_shared->entrypoints) {
ht_ne_entrypoint *e = (ht_ne_entrypoint*)(*ne_shared->entrypoints)[i];
if (e) {
e->name = strdup(name);
} /*else fprintf(stderr, "entry %d not available\n", i);*/
} /* else trouble :-) */
}
static ht_view *htnenames_init(Bounds *b, File *file, ht_format_group *group)
{
ht_ne_shared_data *ne_shared=(ht_ne_shared_data *)group->get_shared_data();
uint32 h=ne_shared->hdr_ofs;
ht_uformat_viewer *v=new ht_uformat_viewer();
v->init(b, DESC_NE_NAMES, VC_EDIT | VC_SEARCH, file, group);
ht_mask_sub *m=new ht_mask_sub();
m->init(file, 0);
char line[256]; /* secure */
char *n;
int i;
ht_snprintf(line, sizeof line, "* NE resident names table at offset 0x%08qx", h+ne_shared->hdr.restab);
m->add_mask(line);
file->seek(h+ne_shared->hdr.restab);
i=0;
while (*(n = file->readstrp())) {
char buf[2];
file->read(buf, 2);
uint16 ent = createHostInt(buf, 2, little_endian);
if (!i) {
ht_snprintf(line, sizeof line, "description: %s", n);
} else {
ht_snprintf(line, sizeof line, "%04x %s", ent, n);
assign_entrypoint_name(ne_shared, ent, n);
}
free(n);
m->add_mask(line);
i++;
}
free(n);
m->add_mask("----------------------------------------------------------------");
ht_snprintf(line, sizeof line, "* NE non-resident names table at offset %08x", ne_shared->hdr.nrestab);
m->add_mask(line);
file->seek(ne_shared->hdr.nrestab);
i=0;
while (*(n = file->readstrp())) {
char buf[2];
file->read(buf, 2);
uint16 ent = createHostInt(buf, 2, little_endian);
if (!i) {
ht_snprintf(line, sizeof line, "description: %s", n);
} else {
ht_snprintf(line, sizeof line, "%04x %s", ent, n);
assign_entrypoint_name(ne_shared, ent, n);
}
free(n);
m->add_mask(line);
i++;
}
free(n);
v->insertsub(m);
return v;
}
format_viewer_if htnenames_if = {
htnenames_init,
NULL
};