1 /*
2  *	HT Editor
3  *	htxbe.h
4  *
5  *	Copyright (C) 2003 Stefan Esser
6  *
7  *	This program is free software; you can redistribute it and/or modify
8  *	it under the terms of the GNU General Public License version 2 as
9  *	published by the Free Software Foundation.
10  *
11  *	This program is distributed in the hope that it will be useful,
12  *	but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *	GNU General Public License for more details.
15  *
16  *	You should have received a copy of the GNU General Public License
17  *	along with this program; if not, write to the Free Software
18  *	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */
20 
21 #ifndef __HTXBE_H__
22 #define __HTXBE_H__
23 
24 #include "formats.h"
25 #include "xbestruct.h"
26 #include "htxbeimp.h"
27 
28 #define DESC_XBE "xbe - XBOX executable"
29 #define DESC_XBE_HEADER "xbe/header"
30 #define DESC_XBE_IMAGE "xbe/image"
31 #define DESC_XBE_IMPORTS "xbe/imports"
32 
33 
34 #define ATOM_XBE_INIT_FLAGS 			0x58420000
35 #define ATOM_XBE_INIT_FLAGS_STR			 "58420000"
36 
37 #define ATOM_XBE_SECTION_FLAGS 			0x58420001
38 #define ATOM_XBE_SECTION_FLAGS_STR 		 "58420001"
39 
40 #define ATOM_XBE_MEDIA_FLAGS 			0x58420002
41 #define ATOM_XBE_MEDIA_FLAGS_STR 		 "58420002"
42 
43 #define ATOM_XBE_REGION 			0x58420003
44 #define ATOM_XBE_REGION_STR 			 "58420003"
45 
46 #define ATOM_XBE_LIBRARY_FLAGS 			0x58420004
47 #define ATOM_XBE_LIBRARY_FLAGS_STR 		 "58420004"
48 
49 
50 extern format_viewer_if htxbe_if;
51 
52 struct xbe_section_headers {
53 	uint32	number_of_sections;
54 	uint32	base_address;
55 	XBE_SECTION_HEADER *sections;
56 };
57 
58 struct ht_xbe_shared_data {
59 	XBE_IMAGE_HEADER header;
60 	XBE_CERTIFICATE certificate;
61 	XBE_LIBRARY_VERSION *libraries;
62 
63 	char *headerspace;
64 	xbe_section_headers sections;
65 
66 	ht_xbe_import imports;
67 
68 
69 	ht_format_viewer *v_header;
70 	ht_view *v_exports;
71 	ht_view *v_imports;
72 	ht_view *v_dimports;
73 	ht_view *v_resources;
74 	ht_view *v_il;
75 	ht_format_viewer *v_image;
76 };
77 
78 /*
79  *	ht_xbe
80  */
81 class ht_xbe: public ht_format_group {
82 protected:
83 	bool loc_enum;
84 public:
85 		void init(Bounds *b, File *file, format_viewer_if **ifs, ht_format_group *format_group, FileOfs header_ofs);
86 	virtual	void done();
87 	/* overwritten */
88 	virtual   void loc_enum_start();
89 	virtual   bool loc_enum_next(ht_format_loc *loc);
90 };
91 
92 bool xbe_rva_to_section(xbe_section_headers *section_headers, RVA rva, int *section);
93 bool xbe_rva_to_ofs(xbe_section_headers *section_headers, RVA rva, FileOfs *ofs);
94 bool xbe_rva_is_valid(xbe_section_headers *section_headers, RVA rva);
95 bool xbe_rva_is_physical(xbe_section_headers *section_headers, RVA rva);
96 
97 bool xbe_ofs_to_rva(xbe_section_headers *section_headers, FileOfs ofs, RVA *rva);
98 bool xbe_ofs_to_section(xbe_section_headers *section_headers, FileOfs ofs, int *section);
99 bool xbe_ofs_to_rva_and_section(xbe_section_headers *section_headers, FileOfs ofs, RVA *rva, int *section);
100 
101 bool xbe_section_name_to_section(xbe_section_headers *section_headers, const char *name, int *section);
102 
103 #endif /* !__HTXBE_H__ */
104