summaryrefslogtreecommitdiffhomepage
path: root/src/headers/pe_get_image_special_hdr_addr.c
blob: 8d1d9c6023d1937a38743737eccfc994e8675961 (plain)
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
/*****************************************************************************/
/*  pemagination: a (virtual) tour into portable bits and executable bytes   */
/*  Copyright (C) 2013--2016  Z. Gilboa                                      */
/*  Released under GPLv2 and GPLv3; see COPYING.PEMAGINE.                    */
/*****************************************************************************/

#include <psxtypes/psxtypes.h>
#include <pemagine/pe_consts.h>
#include <pemagine/pe_structs.h>
#include <pemagine/pemagine.h>
#include "pe_impl.h"


void * pe_get_image_special_hdr_addr(const void * base, uint32_t ordinal, uint32_t * sec_size)
{
	struct pe_raw_data_dirs*dirs;
	struct pe_block *	dir;
	uint32_t *		count;

	if (!(dirs = pe_get_image_data_dirs_addr(base)))
		return 0;

	count = (uint32_t *)dirs->coh_rva_and_sizes;

	if (*count < (ordinal+1))
		return 0;

	dir  = (struct pe_block *)dirs->coh_export_tbl;
	dir += ordinal;

	if (sec_size)
		*sec_size = dir->size;

	return dir->rva
		? pe_va_from_rva(base,dir->rva)
		: 0;
}


struct pe_raw_export_hdr * pe_get_image_export_hdr_addr(const void * base, uint32_t * sec_size)
{
	return (struct pe_raw_export_hdr *)pe_get_image_special_hdr_addr(base,PE_IMAGE_DATA_DIR_ORDINAL_EXPORT,sec_size);
}


struct pe_raw_import_hdr * pe_get_image_import_dir_addr(const void * base, uint32_t * sec_size)
{
	return (struct pe_raw_import_hdr *)pe_get_image_special_hdr_addr(base,PE_IMAGE_DATA_DIR_ORDINAL_IMPORT,sec_size);
}