Skip to content
Snippets Groups Projects
SMPDBInterface.h 5.72 KiB
Newer Older
/*
 * SMPDBInterface.h - <see below>.
 *
 * Copyright (c) 2000, 2001, 2010 - University of Virginia 
 *
 * This file is part of the Memory Error Detection System (MEDS) infrastructure.
 * 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 the University 
 * of Virginia.
 *
 * 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: University of Virginia
 * e-mail: jwd@virginia.com
 * URL   : http://www.cs.virginia.edu/
 *
 * Additional copyrights 2010, 2011 by Zephyr Software LLC
 * e-mail: {clc,jwd}@zephyr-software.com
 * URL   : http://www.zephyr-software.com/
 *
 */

#ifndef SMPDBINTERFACE_H
#define SMPDBINTERFACE_H 1

// SMPDBInterface.h
//
// This header defines the interfaces needed for obtaining program information
//  from a disassembler or other program database, e.g. IDA Pro, the UVa IRDB,
//  another disassembler, etc.
//

#include <string>
#include <utility>
#include <list>
#include <vector>
#include <map>
#include <set>

#include <cstddef>

#include <pro.h>
#include <ida.hpp>
#include <ua.hpp>
#include <xref.hpp>

#ifndef STARS_IRDB_INTERFACE
#ifndef STARS_IDA_INTERFACE
#warning No INTERFACE symbol defined: defaulting to STARS_IDA_INTERFACE
#define STARS_IDA_INTERFACE
#endif
#endif

#ifdef STARS_IDA_INTERFACE
#ifdef STARS_IRDB_INTERFACE
#error Cannot define both STARS_IDA_INTERFACE and STARS_IRDB_INTERFACE
#endif
#else
#ifndef STARS_IRDB_INTERFACE
#error Must define either STARS_IDA_INTERFACE or STARS_IRDB_INTERFACE
#endif
#endif

bool SMPGetCmd(ea_t InstAddr, insn_t &SMPcmd, ulong &SMPfeatures);

// Need instruction xref info from IRDB

// Need redefinitions for:

// Need to deal with shared chunks


#ifdef STARS_IDA_INTERFACE


typedef ea_t STARS_ea_t;
#include <interfaces/idapro/all.h>

// Globals, typedefs and macros for STARS_IDA_INTERFACE only
#define SMP_getseg(addr)  (global_stars_interface->getseg(addr))
jdh8d's avatar
jdh8d committed
#define SMP_getnseg(index) (global_stars_interface->getnseg(index))
#define SMP_get_segm_qty() (global_stars_interface->get_segm_qty())

#define SMP_get_first_seg() (SMP_getnseg(1)) /* get the first segment a diff way */
#define SMP_get_next_seg(addr) (global_stars_interface->get_next_seg(addr))
#define SMP_get_segm_name(seg, name, size) (seg->GetSegmentName(name, size))

jdh8d's avatar
jdh8d committed
#define SMP_get_func_qty() (global_stars_interface->get_func_qty())
#define SMP_getn_func(index) (global_stars_interface->getn_func(index))
#define SMP_get_func(addr) (global_stars_interface->get_func(addr))
#define SMP_get_func_name(addr, NameBuf, NameBufSize) (SMP_get_func(addr)->GetFunctionName(NameBuf, NameBufSize));
#define SMP_get_spd(ptr_to_func, ea) (ptr_to_func->get_spd(ea))

#define SMP_get_item_end(addr) get_item_end(addr)
#define SMP_getFlags(addr) getFlags(addr)
#define SMP_msg(...) msg(__VA_ARGS__)
#define SMP_strncat(str1, str2, len) qstrncat(str1, str2, len)
#define SMP_strncpy(str1, str2, len) qstrncpy(str1, str2, len)
#define SMP_snprintf(...) qsnprintf(__VA_ARGS__)
#define SMP_fprintf(...) qfprintf(__VA_ARGS__)
clc5q's avatar
clc5q committed
#define SMP_fscanf(...) qfscanf(__VA_ARGS__)
#define SMP_fopen(name, mode) qfopen(name, mode)
#define SMP_feof(file) feof(file)
#define SMP_fclose(file) qfclose(file)
#define SMP_get_true_name(from, ea, buf, bufsize) get_true_name(from, ea, buf, bufsize)
#define SMP_next_head(ea, maxea) next_head(ea, maxea)
#define SMP_get_flags_novalue(ea) get_flags_novalue(ea)
jdh8d's avatar
jdh8d committed
#define SMP_get_frame(ptr_to_func_t) get_frame((func_t*)*dynamic_cast<STARS_IDA_Function_t*>(ptr_to_func_t))
#define SMP_get_member_name(mid, buf, bufsize) get_member_name(mid, buf, bufsize)
#define SMP_get_item_end(addr) get_item_end(addr)
#define SMP_getFlags(addr) getFlags(addr)
#define SMP_isHead(flags) isHead(flags)
#define SMP_isCode(flags) isCode(flags)
#define SMP_add_cref(from, to, type) add_cref(from, to, type)
#define SMP_generate_disasm_line(InstAddr, CharArray, CharArrayLimit)  generate_disasm_line(InstAddr, CharArray, CharArrayLimit)
#define SMP_tag_remove(InBuf, OutBuf, OutBufSize)  tag_remove(InBuf, OutBuf, OutBufSize)
	xrefblk_t CurrSMP_xref;
	ea_t GetFrom() { return CurrSMP_xref.from; };
	ea_t GetTo() { return CurrSMP_xref.to; };
	uchar GetIscode() { return CurrSMP_xref.iscode; };         // 1-is code reference; 0-is data reference
	uchar GetType() { return CurrSMP_xref.type; };           // type of the last retured reference (cref_t & dref_t)
	uchar GetUser() { return CurrSMP_xref.user; };           // 1-is used defined xref, 0-defined by ida
	bool SMP_first_from(ea_t from, int flags)   // get first reference from...
    { return xrefblk_t_first_from(&CurrSMP_xref, from, flags); }
	bool SMP_next_from(void)                   // get next reference from...
    { return xrefblk_t_next_from(&CurrSMP_xref); }
	bool SMP_first_to(ea_t to, int flags)      // get first reference to...
    { return xrefblk_t_first_to(&CurrSMP_xref, to, flags); }
	bool SMP_next_to(void)                     // get next reference to....
    { return xrefblk_t_next_to(&CurrSMP_xref); }
};

#else 
// Globals, typedefs and macros for STARS_IRDB_INTERFACE only
#define SMP_strncat(str1, str2, len) strncat(str1, str2, len)
#define SMP_strncpy(str1, str2, len) strncpy(str1, str2, len)
#define SMP_snprintf(...) snprintf(__VA_ARGS__)
#define SMP_fprintf(...) fprintf(__VA_ARGS__)
#define SMP_fopen(name, mode) fopen(name, mode)
#define SMP_feof(file) feof(file)
#define SMP_fclose(file) fclose(file)

extern FILE *SMPLogFile;
#define SMP_msg(...) fprintf(SMPLogFile, __VA_ARGS__)

#endif



#endif