Blame src/internal/perk_reader_impl.h

e2e2c2
/***************************************************************/
e2e2c2
/*  perk: PE Resource Kit                                      */
425fb8
/*  Copyright (C) 2015--2021  SysDeer Technologies, LLC        */
e2e2c2
/*  Released under GPLv2 and GPLv3; see COPYING.PERK.          */
e2e2c2
/***************************************************************/
e2e2c2
61bf9c
#ifndef PERK_READER_IMPL_H
61bf9c
#define PERK_READER_IMPL_H
c0fbae
c0fbae
#include <stdint.h>
8216f9
#include "perk_endian_impl.h"
c0fbae
b5f7f5
static inline uint16_t pe_read_short(const unsigned char * raw)
c0fbae
{
8216f9
	if (PERK_LITTLE_ENDIAN) {
8216f9
		return *(uint16_t *)raw;
8216f9
	} else {
8216f9
		uint16_t x = *(uint16_t *)raw;
8216f9
		return x<<8 | x>>8;
8216f9
	}
c0fbae
}
c0fbae
c0fbae
static inline uint32_t pe_swap_long(uint32_t x)
c0fbae
{
7255ef
	return x<<24 | ((x<<8) & 0xff0000) | ((x>>8) & 0xff00) | x>>24;
c0fbae
}
c0fbae
b5f7f5
static inline uint32_t pe_read_long(const unsigned char * raw)
c0fbae
{
8216f9
	if (PERK_LITTLE_ENDIAN)
8216f9
		return *(uint32_t *)raw;
8216f9
	else
8216f9
		return pe_swap_long(*(uint32_t *)raw);
c0fbae
}
c0fbae
b5f7f5
static inline uint64_t pe_read_quad(const unsigned char * raw)
c0fbae
{
8216f9
	if (PERK_LITTLE_ENDIAN) {
8216f9
		return *(uint64_t *)raw;
8216f9
	} else {
8216f9
		uint64_t x = *(uint64_t *)raw;
8216f9
		return ((uint64_t)pe_swap_long(x)<<32) | pe_swap_long(x>>32);
8216f9
	}
c0fbae
}
c0fbae
c0fbae
#endif