<commit_before>/*

elfutil.h

Wrapper for elfio

shygoo 2017
License: MIT

*/

#ifndef ELFUTIL_H
#define ELFUTIL_H

#include <elfio/elfio.hpp>
#include "mipsrel.h"

using namespace ELFIO;

typedef struct
{
	std::string name;
	Elf64_Addr value;
	Elf_Xword size;
	unsigned char bind;
	unsigned char type;
	Elf_Half section_index;
	unsigned char other;
} ELF_SYMBOL;

typedef struct
{
	uint32_t offset;
	uint16_t unk;
	uint8_t symbol_index;
	uint8_t type;
} ELF_RELOCATION;

class CElfObject
{
private:

	elfio m_Elf;

	section* m_SymTabSec;
	section* m_TextSec;
	section* m_RelTextSec;

	const char* m_TextData;
	int m_TextSize;
	bool m_bTextEmpty;

	const char* m_RelTextData;
	int m_RelTextSize;
	int m_nRelTextEntries;

	symbol_section_accessor* m_SymbolAccessor;
	int m_nSymbols;

public:

	static CElfObject* Create(std::istream& stream, std::streampos start_pos = 0)
	{
		return new CElfObject(stream, start_pos);
	}

	static CElfObject* Create(const char* path)
	{
        std::ifstream stream;
        stream.open(path, std::ios::in | std::ios::binary);

        if(stream == NULL)
		{
            return NULL;
        }

		return new CElfObject(stream, 0);
	}

private:

	CElfObject(std::istream& stream, std::streampos start_pos = 0 ) :
		m_SymTabSec(NULL),
		m_TextSec(NULL),
		m_RelTextSec(NULL),
		m_SymbolAccessor(NULL),
		m_nSymbols(0),
		m_TextData(NULL),
		m_TextSize(0),
		m_bTextEmpty(true),
		m_RelTextData(NULL),
		m_RelTextSize(0),
		m_nRelTextEntries(0)
	{
		m_Elf.load(stream, start_pos);
		Init();
	}

public:

	~CElfObject()
	{<commit_msg>Fix stream check in CElfObject::Create<commit_after>/*

elfutil.h

Wrapper for elfio

shygoo 2017
License: MIT

*/

#ifndef ELFUTIL_H
#define ELFUTIL_H

#include <elfio/elfio.hpp>
#include "mipsrel.h"

using namespace ELFIO;

typedef struct
{
	std::string name;
	Elf64_Addr value;
	Elf_Xword size;
	unsigned char bind;
	unsigned char type;
	Elf_Half section_index;
	unsigned char other;
} ELF_SYMBOL;

typedef struct
{
	uint32_t offset;
	uint16_t unk;
	uint8_t symbol_index;
	uint8_t type;
} ELF_RELOCATION;

class CElfObject
{
private:

	elfio m_Elf;

	section* m_SymTabSec;
	section* m_TextSec;
	section* m_RelTextSec;

	const char* m_TextData;
	int m_TextSize;
	bool m_bTextEmpty;

	const char* m_RelTextData;
	int m_RelTextSize;
	int m_nRelTextEntries;

	symbol_section_accessor* m_SymbolAccessor;
	int m_nSymbols;

public:

	static CElfObject* Create(std::istream& stream, std::streampos start_pos = 0)
	{
		return new CElfObject(stream, start_pos);
	}

	static CElfObject* Create(const char* path)
	{
		std::ifstream stream;
		stream.open(path, std::ios::in | std::ios::binary);

		if((stream.rdstate() & std::ifstream::failbit) != 0)
		{
			return NULL;
		}

		return new CElfObject(stream, 0);
	}

private:

	CElfObject(std::istream& stream, std::streampos start_pos = 0 ) :
		m_SymTabSec(NULL),
		m_TextSec(NULL),
		m_RelTextSec(NULL),
		m_SymbolAccessor(NULL),
		m_nSymbols(0),
		m_TextData(NULL),
		m_TextSize(0),
		m_bTextEmpty(true),
		m_RelTextData(NULL),
		m_RelTextSize(0),
		m_nRelTextEntries(0)
	{
		m_Elf.load(stream, start_pos);
		Init();
	}

public:

	~CElfObject()
	{
{'fraction_non_alphanumeric': 0.11104060913705584, 'fraction_numerical': 0.012373096446700508, 'mean_word_length': 4.600355239786857, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2693445', 'n_tokens_mistral': 1398, 'n_tokens_neox': 1287, 'n_words': 269}