Skip to content
Snippets Groups Projects
scfi_instr.hpp 1.86 KiB
Newer Older
an7s's avatar
an7s committed
/*
 * Copyright (c) 2014-2015 - Zephyr Software LLC
 *
 * This file may be used and modified for non-commercial purposes as long as
 * all copyright, permission, and nonwarranty notices are preserved.
 * Redistribution is prohibited without prior written consent from Zephyr
 * Software.
 *
 * Please contact the authors for restrictions applying to commercial use.
 *
 * THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 * Author: Zephyr Software
 * e-mail: jwd@zephyr-software.com
 * URL   : http://www.zephyr-software.com/
 *
 */

jdh8d's avatar
jdh8d committed
#ifndef scfi_instrument_hpp
#define scfi_instrument_hpp

#include <libIRDB-core.hpp>
jdh8d's avatar
jdh8d committed
#include "color_map.hpp"
jdh8d's avatar
jdh8d committed



class SCFI_Instrument
{
	public:
jdh8d's avatar
jdh8d committed
		SCFI_Instrument(libIRDB::FileIR_t *the_firp, bool p_do_coloring=true) 
			: firp(the_firp), do_coloring(p_do_coloring), color_map(NULL) {}
jdh8d's avatar
jdh8d committed
		bool execute();

	private:


		// find instrumentation points.
		bool mark_targets();
		bool instrument_jumps();

		// helper
		libIRDB::Relocation_t* create_reloc(libIRDB::Instruction_t* insn);
jdh8d's avatar
jdh8d committed
		libIRDB::Relocation_t* FindRelocation(libIRDB::Instruction_t* insn, std::string type);
jdh8d's avatar
jdh8d committed

		// add instrumentation
		bool add_scfi_instrumentation(libIRDB::Instruction_t* insn);
		bool needs_scfi_instrumentation(libIRDB::Instruction_t* insn);
jdh8d's avatar
jdh8d committed

		// return instrumentation
jdh8d's avatar
jdh8d committed
		void  AddReturnCFI(libIRDB::Instruction_t* insn, ColoredSlotValue_t *v=NULL);
jdh8d's avatar
jdh8d committed
		// jump instrumentation
		void AddJumpCFI(libIRDB::Instruction_t* insn);
jdh8d's avatar
jdh8d committed


		// Nonce Manipulation.
jdh8d's avatar
jdh8d committed
		NonceValueType_t GetNonce(libIRDB::Instruction_t* insn);
jdh8d's avatar
jdh8d committed
		unsigned int GetNonceSize(libIRDB::Instruction_t* insn);
jdh8d's avatar
jdh8d committed
		unsigned int GetNonceOffset(libIRDB::Instruction_t*);
jdh8d's avatar
jdh8d committed

jdh8d's avatar
jdh8d committed


jdh8d's avatar
jdh8d committed
	
		libIRDB::FileIR_t* firp;
jdh8d's avatar
jdh8d committed
		bool do_coloring;
		ColoredInstructionNonces_t *color_map;