#ifndef __MALWARE_EXTRACTOR_H__
#define __MALWARE_EXTRACTOR_H__

#include "plugin.h"
#include <vector>

enum {
	ME_ERROR_NOERROR = 0,	// Everything is fine.
	ME_ERROR_NOTHREAD,		// No thread found.
	ME_ERROR_MEMALLOC,		// Memory allocation failed.
	ME_ERROR_MEMREAD,		// Memory read failed.
	ME_ERROR_OUTOFBOUNDS,	// Trying to access array out of its bounds.
	ME_ERROR_NOTFOUND		// Could not find something.
};


struct ME_MODULE_RANGE
{
	ulong base;				// Starting memory address.
	ulong size;				// Size of the memory region.
};

class MalwareExtractor
{
private:
	uchar *m_imagecopy;		// Copy of a whole executable image.
	int	m_running;			// Set to 1 if plugin is running.
	t_thread *m_thread;		//
	t_module *m_module;		//
	//
	std::vector<ME_MODULE_RANGE> m_module_ranges;
	int m_error_code;		// Error code of a last operation/function.

	ulong m_next_address;	// Address of the next CF changing instruction.

public:
	MalwareExtractor();
	~MalwareExtractor();

	int Initialize();
	void Reset();
	int FindNextAddress(ulong start);
	int IsRunning();
	int GetErrorCode();
private:
	void BackupModuleRanges();
};

#endif