Blame src/imports/pe_enum_image_import_hdrs.c

feffc7
/*****************************************************************************/
feffc7
/*  pemagination: a (virtual) tour into portable bits and executable bytes   */
b6ea9a
/*  Copyright (C) 2013--2017  Z. Gilboa                                      */
feffc7
/*  Released under GPLv2 and GPLv3; see COPYING.PEMAGINE.                    */
feffc7
/*****************************************************************************/
feffc7
feffc7
#include <psxtypes/psxtypes.h>
feffc7
#include <pemagine/pe_structs.h>
feffc7
#include <pemagine/pemagine.h>
feffc7
feffc7
int pe_enum_image_import_hdrs(
feffc7
	const void *				base,
feffc7
	pe_enum_image_import_hdrs_callback *	callback,
feffc7
	void *					ctx)
feffc7
{
504536
	struct pe_raw_import_hdr*imp_hdr;
feffc7
	int			ret;
feffc7
feffc7
	if (!(imp_hdr = pe_get_image_import_dir_addr(base,0))) {
feffc7
		callback(base,0,PE_CALLBACK_REASON_ERROR,ctx);
feffc7
		return -1;
feffc7
	}
feffc7
feffc7
	if ((ret = callback(base,0,PE_CALLBACK_REASON_INIT,ctx)) <= 0)
feffc7
		return ret;
feffc7
c2233d
	while (imp_hdr->ih_name_rva[0]) {
feffc7
		if ((ret = callback(base,imp_hdr,PE_CALLBACK_REASON_ITEM,ctx)) <= 0)
feffc7
			return ret;
feffc7
		imp_hdr++;
feffc7
	};
feffc7
feffc7
	return callback(base,imp_hdr,PE_CALLBACK_REASON_DONE,ctx);
feffc7
}