File: htleent.cc

package info (click to toggle)
ht 0.5.0-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 3,388 kB
  • ctags: 9,064
  • sloc: cpp: 51,336; ansic: 11,954; sh: 2,742; yacc: 1,142; lex: 396; makefile: 178
file content (131 lines) | stat: -rw-r--r-- 3,506 bytes parent folder | download
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
/* 
 *	HT Editor
 *	htleent.cc
 *
 *	Copyright (C) 1999, 2000, 2001 Stefan Weyergraf (stefan@weyergraf.de)
 *
 *	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 "htatom.h"
#include "htnewexe.h"
#include "htle.h"
#include "htlehead.h"
#include "httag.h"
#include "formats.h"

#include "lestruct.h"

/* entry bundle */

ht_tag_flags_s le_entry_bundle_flags[] =
{
	{-1, "LE - entrypoint bundle flags"},
	{0,  "[00] valid"},
	{1,  "[01] 32bit (16bit otherwise)"},
	{0, 0}
};

ht_mask_ptable le_entry_bundle_header[]=
{
	{"number of entries",	STATICTAG_EDIT_BYTE("00000000")},
	{"bundle flags",		STATICTAG_EDIT_BYTE("00000001")" "STATICTAG_FLAGS("00000001", ATOM_LE_ENTRY_BUNDLE_FLAGS_STR)},
	{"object index",		STATICTAG_EDIT_WORD_LE("00000002")},
	{0,0}
};

/* entry */

ht_tag_flags_s le_entry_flags[] =
{
	{-1, "LE - entrypoint flags"},
	{0,  "[00] exported"},
	{1,  "[01] uses shared segment"},
	{0, 0}
};

ht_mask_ptable le_entry16[]=
{
	{"flags",		STATICTAG_EDIT_BYTE("00000000")" "STATICTAG_FLAGS("00000000", ATOM_LE_ENTRY_FLAGS_STR)},
	{"offset",	STATICTAG_EDIT_WORD_LE("00000001")},
	{0, 0}
};

ht_mask_ptable le_entry32[]=
{
	{"flags",		STATICTAG_EDIT_BYTE("00000000")" "STATICTAG_FLAGS("00000000", ATOM_LE_ENTRY_FLAGS_STR)},
	{"offset",	STATICTAG_EDIT_DWORD_LE("00000001")},
	{0, 0}
};

ht_view *htleentrypoints_init(bounds *b, ht_streamfile *file, ht_format_group *group)
{
	ht_le_shared_data *le_shared=(ht_le_shared_data *)group->get_shared_data();

	int h=le_shared->hdr_ofs;
	ht_uformat_viewer *v=new ht_uformat_viewer();
	v->init(b, DESC_LE_ENTRYPOINTS, VC_EDIT, file, group);
	ht_mask_sub *m=new ht_mask_sub();
	m->init(file, 0);
	register_atom(ATOM_LE_ENTRY_FLAGS, le_entry_flags);
	register_atom(ATOM_LE_ENTRY_BUNDLE_FLAGS, le_entry_bundle_flags);
	char info[128];
	
	sprintf(info, "* LE entry header at offset %08x", h+le_shared->hdr.enttab);

/* FIXME: false */
	bool le_bigendian = false;
	m->add_mask(info);
	m->add_staticmask_ptable(le_entry_bundle_header, h+le_shared->hdr.enttab, le_bigendian);
	v->insertsub(m);

	FILEOFS o=h+le_shared->hdr.enttab;
	while (1) {
		char t[32];
		IMAGE_LE_ENTRYPOINT_HEADER hdr;
		hdr.entry_count=0;
		file->seek(o);
		o+=file->read(&hdr, sizeof hdr);
		if (!hdr.entry_count) break;
		char *flags_str;
		if (hdr.flags & IMAGE_LE_ENTRYPOINT_32BIT) {
			flags_str="32-bit";
		} else {
			flags_str="16-bit";
		}
		for (int i=0; i<hdr.entry_count; i++) {
			m=new ht_mask_sub();
			m->init(file, i);
			if (hdr.flags & IMAGE_LE_ENTRYPOINT_32BIT) {
				m->add_staticmask_ptable(le_entry32, o, le_bigendian);
				o+=1+4;
			} else {
				m->add_staticmask_ptable(le_entry16, o, le_bigendian);
				o+=1+2;
			}
			sprintf(t, "--- entry %d (%s) ---", i+1, flags_str);

			ht_collapsable_sub *cs=new ht_collapsable_sub();
			cs->init(file, m, 1, t, 1);
			v->insertsub(cs);
		}
	}
	
	return v;
}

format_viewer_if htleentrypoints_if = {
	htleentrypoints_init,
	0
};