Blame src/internal/pe_impl.h

3f9c39
/*****************************************************************************/
3f9c39
/*  pemagination: a (virtual) tour into portable bits and executable bytes   */
b6ea9a
/*  Copyright (C) 2013--2017  Z. Gilboa                                      */
3f9c39
/*  Released under GPLv2 and GPLv3; see COPYING.PEMAGINE.                    */
3f9c39
/*****************************************************************************/
3f9c39
feffc7
#include <psxtypes/psxtypes.h>
feffc7
#include <pemagine/pemagine.h>
feffc7
feffc7
#define PE_STR_MAX_SYMBOL_LEN_ALLOWED			(uint32_t)0x10000
feffc7
feffc7
#define IN_LOAD_ORDER_MODULE_LIST_OFFSET		(intptr_t)0x00
feffc7
#define IN_MEMORY_ORDER_MODULE_LIST_OFFSET		(intptr_t)0x01 * sizeof(struct pe_list_entry)
feffc7
#define IN_INITIALIZATION_ORDER_MODULE_LIST_OFFSET	(intptr_t)0x02 * sizeof(struct pe_list_entry)
feffc7
feffc7
struct pe_block {
feffc7
	uint32_t	rva;
feffc7
	uint32_t	size;
feffc7
};
feffc7
3f9c39
5d9c48
static __inline__ intptr_t pe_impl_strlen_ansi(const char * str)
3f9c39
{
3f9c39
	const char * ch;
3f9c39
	const char * upper_bound;
3f9c39
3f9c39
	upper_bound = str + PE_STR_MAX_SYMBOL_LEN_ALLOWED;
3f9c39
3f9c39
	for (ch=str; *ch && ch
3f9c39
		ch++;
3f9c39
3f9c39
	return (ch < upper_bound)
3f9c39
		? ch - str
3f9c39
		: -1;
3f9c39
}
3f9c39
3f9c39
5d9c48
static __inline__ intptr_t pe_impl_strlen_utf16(const wchar16_t * str)
3f9c39
{
3f9c39
	const wchar16_t * wch;
3f9c39
	const wchar16_t * upper_bound;
3f9c39
3f9c39
	upper_bound = str + PE_STR_MAX_SYMBOL_LEN_ALLOWED;
3f9c39
3f9c39
	for (wch=str; *wch && wch
3f9c39
		wch++;
3f9c39
3f9c39
	if (wch < upper_bound)
3f9c39
		return (wch - str) * sizeof(wchar16_t);
3f9c39
	else
3f9c39
		return -1;
3f9c39
}
3f9c39
3f9c39
9c42df
static __inline__ wchar16_t pe_impl_utf16_char_to_lower(const wchar16_t c)
3f9c39
{
3f9c39
	return ((c >= 'A') && (c <= 'Z'))
3f9c39
		? c + 'a' - 'A'
3f9c39
		: c;
3f9c39
}