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

#include <psxtypes/psxtypes.h>
#include <pemagine/pe_structs.h>
#include <pemagine/pemagine.h>

int pe_enum_image_import_hdrs(
	const void *				base,
	pe_enum_image_import_hdrs_callback *	callback,
	void *					ctx)
{
	struct pe_raw_import_hdr*imp_hdr;
	int			ret;

	if (!(imp_hdr = pe_get_image_import_dir_addr(base,0))) {
		callback(base,0,PE_CALLBACK_REASON_ERROR,ctx);
		return -1;
	}

	if ((ret = callback(base,0,PE_CALLBACK_REASON_INIT,ctx)) <= 0)
		return ret;

	while (imp_hdr->ih_name_rva[0]) {
		if ((ret = callback(base,imp_hdr,PE_CALLBACK_REASON_ITEM,ctx)) <= 0)
			return ret;
		imp_hdr++;
	};

	return callback(base,imp_hdr,PE_CALLBACK_REASON_DONE,ctx);
}