Ejemplo n.º 1
0
//--------------------------------------------------------------------------
void idaapi cr16c_data(ea_t ea) 
{
   char obuf[256];
   init_output_buffer(obuf, sizeof(obuf));
   int col = 0;
   uint32 flags = get_flags_novalue(ea);
   if (isWord(flags)) {
      out_snprintf("%s %xh", ash.a_word ? ash.a_word : "", get_word(ea));
   }
   else if (isDwrd(flags)) {
      out_snprintf("%s %xh", ash.a_dword ? ash.a_dword : "", get_long(ea));
   }
   else { //if (isByte(flags)) {
      int val = get_byte(ea);
      char ch = ' ';
      if (val >= 0x20 && val <= 0x7E) {
         ch = val;
      }
      out_snprintf("%s %02xh   ; %c", ash.a_byte ? ash.a_byte : "", val, ch);
   }
   term_output_buffer();
   gl_comm = 1;
   MakeLine(obuf);
   return;
}
Ejemplo n.º 2
0
Archivo: out.c Proyecto: mpusz/nvml
/*
 * out_common -- common output code, all output goes through here
 */
#define	MAXPRINT 8192	/* maximum expected log line */
static void
out_common(const char *file, int line, const char *func, int level,
		const char *suffix, const char *fmt, va_list ap)
{
	int oerrno = errno;
	char buf[MAXPRINT];
	int cc = 0;
	const char *sep = "";
	const char *errstr = "";

	if (file)
		cc += out_snprintf(&buf[cc], MAXPRINT - cc,
				"<%s>: <%d> [%s:%d %s] ",
				Log_prefix, level, file, line, func);

	if (fmt) {
		if (*fmt == '!') {
			fmt++;
			sep = ": ";
			errstr = strerror(errno);
		}
		cc += Vsnprintf(&buf[cc], MAXPRINT - cc, fmt, ap);
	}

	out_snprintf(&buf[cc], MAXPRINT - cc, "%s%s%s", sep, errstr, suffix);

	Print(buf);
	errno = oerrno;
}
Ejemplo n.º 3
0
/*
 * out_common -- common output code, all output goes through here
 */
static void
out_common(const char *file, int line, const char *func, int level,
		const char *suffix, const char *fmt, va_list ap)
{
	int oerrno = errno;
	char buf[MAXPRINT];
	unsigned cc = 0;
	int ret;
	const char *sep = "";
	const char *errstr = "";

	if (file) {
		char *f = strrchr(file, '/');
		if (f)
			file = f + 1;
		ret = out_snprintf(&buf[cc], MAXPRINT - cc,
				"<%s>: <%d> [%s:%d %s] ",
				Log_prefix, level, file, line, func);
		if (ret < 0) {
			Print("out_snprintf failed");
			goto end;
		}
		cc += (unsigned)ret;
		if (cc < Log_alignment) {
			memset(buf + cc, ' ', Log_alignment - cc);
			cc = Log_alignment;
		}
	}

	if (fmt) {
		if (*fmt == '!') {
			fmt++;
			sep = ": ";
			errstr = strerror(errno);
		}
		ret = Vsnprintf(&buf[cc], MAXPRINT - cc, fmt, ap);
		if (ret < 0) {
			Print("Vsnprintf failed");
			goto end;
		}
		cc += (unsigned)ret;
	}

	out_snprintf(&buf[cc], MAXPRINT - cc, "%s%s%s", sep, errstr, suffix);

	Print(buf);

end:
	errno = oerrno;
}
Ejemplo n.º 4
0
//--------------------------------------------------------------------------
int out_commented(const char *p, color_t ntag)
{
  if ( ntag != _CURCOL) out_tagon(ntag );
  register int i = out_snprintf("%s %s", ash.cmnt, p);
  if ( ntag != _CURCOL) out_tagoff(ntag );
  return(i);
}
Ejemplo n.º 5
0
//----------------------------------------------------------------------
static void idaapi func_header(func_t *f) 
{
	char buf[256];
	char name[64];

   printf_line(0, "# =============== S U B R O U T I N E =======================================");
   printf_line(0, "");

	get_func_name(f->startEA, name, sizeof(name));
	init_output_buffer(buf, sizeof(buf));
	out_snprintf("def %s(", name);
	out_snprintf("...):");
	term_output_buffer();
	printf_line(0, "%s", buf);
	printf_line(0, "");

}
Ejemplo n.º 6
0
//--------------------------------------------------------------------------
// returns number of positions advanced
int out_commented(const char *p, color_t color)
{
  if ( color != COLOR_NONE )
    out_tagon(color);
  int npos = out_snprintf("%s %s", ash.cmnt, p);
  if ( color != COLOR_NONE )
    out_tagoff(color);
  return npos;
}
Ejemplo n.º 7
0
//----------------------------------------------------------------------
static void out_address(ea_t ea, op_t &x)
{
  segment_t *s = getseg(ea);
  ea_t value = s != NULL ? ea - get_segm_base(s) : ea;
  if ( !out_name_expr(x, ea, value) )
  {
    out_tagon(COLOR_ERROR);
    out_snprintf("%a", ea);
    out_tagoff(COLOR_ERROR);
    QueueSet(Q_noName, cmd.ea);
  }
}
Ejemplo n.º 8
0
Archivo: out.cpp Proyecto: nealey/vera
//----------------------------------------------------------------------
static void out_address(ea_t ea, op_t &x)
{

    if ( !out_name_expr(x, ea,/* ea */ BADADDR) )
    {
          out_tagon(COLOR_ERROR);
          OutValue(x, OOFW_IMM|OOF_ADDR|OOFW_16);
          out_snprintf(" (ea = %a)", ea);
          out_tagoff(COLOR_ERROR);
          QueueMark(Q_noName, cmd.ea);
    }

}
Ejemplo n.º 9
0
/*
 * out_error -- common error output code, all error messages go through here
 */
static void
out_error(const char *file, int line, const char *func,
		const char *suffix, const char *fmt, va_list ap)
{
	int oerrno = errno;
	unsigned cc = 0;
	int ret;
	const char *sep = "";
	const char *errstr = "";

	char *errormsg = (char *)out_get_errormsg();

	if (fmt) {
		if (*fmt == '!') {
			fmt++;
			sep = ": ";
			errstr = strerror(errno);
		}
		ret = Vsnprintf(&errormsg[cc], MAXPRINT, fmt, ap);
		if (ret < 0) {
			strcpy(errormsg, "Vsnprintf failed");
			goto end;
		}
		cc += (unsigned)ret;
		out_snprintf(&errormsg[cc], MAXPRINT - cc, "%s%s",
				sep, errstr);
	}

#ifdef DEBUG
	if (Log_level >= 1) {
		char buf[MAXPRINT];
		cc = 0;

		if (file) {
			char *f = strrchr(file, '/');
			if (f)
				file = f + 1;
			ret = out_snprintf(&buf[cc], MAXPRINT,
					"<%s>: <1> [%s:%d %s] ",
					Log_prefix, file, line, func);
			if (ret < 0) {
				Print("out_snprintf failed");
				goto end;
			}
			cc += (unsigned)ret;
			if (cc < Log_alignment) {
				memset(buf + cc, ' ', Log_alignment - cc);
				cc = Log_alignment;
			}
		}

		out_snprintf(&buf[cc], MAXPRINT - cc, "%s%s", errormsg,
				suffix);

		Print(buf);
	}
#endif

end:
	errno = oerrno;
}
Ejemplo n.º 10
0
//----------------------------------------------------------------------
inline void out_ip_rel(int displ)
{
  out_snprintf(COLSTR("%s+", SCOLOR_SYMBOL) COLSTR("%d", SCOLOR_NUMBER),
               ash.a_curip, displ);
}
Ejemplo n.º 11
0
int dline_add(dline_t * dl, ea_t ea, char options)
{
	char buf[256];
	char tmp[256];
	char dis[256];
	char addr[30];
	char * dll;
	int len;
	flags_t f;

	buf[0] = '\0';

	f = getFlags(ea);
	generate_disasm_line(ea, dis, sizeof(dis));

	decode_insn(ea);
	init_output_buffer(buf, sizeof(buf));

	// Adds block label
	if (has_dummy_name(f))
	{
		get_nice_colored_name(ea,tmp,sizeof(tmp),GNCN_NOSEG|GNCN_NOFUNC);
		out_snprintf("%s", tmp);
		out_line(":\n", COLOR_DATNAME);
	}

	if (options)
	{
		qsnprintf(addr, sizeof(addr), "%a", ea);
		out_snprintf("%s ", addr);
	}

	out_insert(get_output_ptr(), dis);
	term_output_buffer();

	len = strlen(buf);

	if (dl->available < (len+3))
	{
		dll = (char *)qrealloc(dl->lines, sizeof(char*) * (dl->num+len+256));
		if (!dll) return -1;

		dl->available = len+256;
		dl->lines = dll;
	}

	if (dl->num)
	{
		dl->lines[dl->num] = '\n';
		dl->num++;
	}

	memcpy(&dl->lines[dl->num], buf, len);

	dl->available -= len+1;
	dl->num += len;

	dl->lines[dl->num] = '\0';

	return 0;
}
Ejemplo n.º 12
0
bool idaapi outop(op_t& x)
{
  uchar warn = 0;

  switch ( x.type ) {
    case o_near:
      if ( x.ref ) ++warn;
      else {
        if ( outName(cmd.ea + x.offb, x.n, curSeg.startEA, x.addr, &warn) ) break;
        if ( warn ) goto badop;
      }
      if ( putVal(x, OOF_ADDR | OOF_NUMBER | OOFS_NOSIGN | OOFW_32, warn) ) break;
      //PASS THRU
    case o_void:
badop:
      return(false);

    case o_imm:
      if ( x.ref == 2 ) ++warn;
      if ( putVal(x, OOFW_IMM | OOF_NUMBER | (x.ref ? OOFS_NOSIGN : OOF_SIGNED ),
                warn)) break;
      goto badop;

    case o_mem:
      if ( jasmin() ) goto putVarNum;
      if ( x.ref ) {
putAddr:
        ++warn;
      } else {
        if ( outName(cmd.ea + x.offb, x.n, curSeg.DataBase, x.addr, &warn) ) break;
        if ( warn ) goto badop;
      }
putVarNum:
      if ( putVal(x, OOF_ADDR | OOF_NUMBER | OOFS_NOSIGN | OOFW_16, warn) ) break;
      goto badop;

    case o_cpool:
      if ( !x.cp_ind) OUT_KEYWORD("NULL" );
      else {
        if ( x.ref ) goto putAddr;
        if ( !OutConstant(x) ) goto badop;
      }
      break;

    case o_array:
      if ( !x.ref ) {
        int i = (uchar)x.cp_type - (T_BOOLEAN-1); // -1 - correct tp_decl
        if ( i < 0 || i > T_LONG - (T_BOOLEAN-1) || chkOutKeyword(tp_decl[i].str, tp_decl[i].size) )
          goto badop;
      } else {
        static const char tt_bogust[] = "BOGUST_TYPE-";

        if ( !checkLine(sizeof(tt_bogust) + 2) ) goto badop;
        out_tagon(COLOR_ERROR);
        outcnt += out_snprintf("%c%s%u", WARN_SYM, tt_bogust, (uchar)x.cp_type);
        out_tagoff(COLOR_ERROR);
      }
      break;

    default:
      warning("out: %a: bad optype %d", cmd.ip, x.type);
      break;
  }
  return(true);
}
Ejemplo n.º 13
0
//----------------------------------------------------------------------
void idaapi cr16c_out(void) 
{
	char str[MAXSTR];  //MAXSTR is an IDA define from pro.h
	init_output_buffer(str, sizeof(str));

	OutMnem(12);       //first we output the mnemonic

	switch(cmd.auxpref)
	{
		case ooType0:					//no operands
			break;

		case ooType1:					//4,0x444(r0)	->1,20
			out_one_operand(1);
			out_symbol(',');
			out_one_operand(2);
			out_one_operand(0);
			break;

		case ooType2:					//4				->0
			out_one_operand(0);
			break;

		case ooType3:					//6(r5), r1		->20,1
			out_one_operand(2);
			out_one_operand(0);
			out_symbol(',');
			out_one_operand(1);
			break;

		case ooType4:					//$4,0x444		->1,0
			out_one_operand(1);
			out_symbol(',');
			out_one_operand(0);
			break;

		case ooType5:					//0x66666, r5	->0,1
			out_one_operand(0);
			out_symbol(',');
			out_one_operand(1);
			break;

		case ooType6:					//$7, [r12]0x26666	->1,[2]0
			out_one_operand(1);
			out_symbol(',');
			out_symbol('[');
			out_one_operand(2);
			out_symbol(']');
			out_one_operand(0);
			break;

		case ooType7:					//$7, [r12]0x26666(r3,r2)
			out_one_operand(1);
			out_symbol(',');
			out_symbol('[');
			out_one_operand(3);
			out_symbol(']');
			out_one_operand(2);
			out_one_operand(0);
			break;

		case ooType8:					//[r12]0x26666(r3,r2), r0
			out_symbol('[');
			out_one_operand(3);
			out_symbol(']');
			out_one_operand(2);
			out_one_operand(0);
			out_symbol(',');
			out_one_operand(1);
			break;

		case ooType9:					//[r12]0x26666,R3	->[2]0,1
			out_symbol('[');
			out_one_operand(2);
			out_symbol(']');
			out_one_operand(0);
			out_symbol(',');
			out_one_operand(1);
			break;

		case ooType10:					//x,y,z			->0,1,2
			out_one_operand(0);
			out_symbol(',');
			out_one_operand(1);
			out_symbol(',');
			out_one_operand(2);
			break;

		case ooType11:					//4				->2
			out_one_operand(2);
			break;

		case ooType12:					//y,x{,z}		->1,0{,2}
			out_one_operand(1);
			out_symbol(',');
			out_one_operand(0);
			if(cmd.Op3.type != o_void) 
			{
				out_symbol(',');
				out_one_operand(2);
			}
			break;


		default:
			if(cmd.Op1.type != o_void) 
			{
				out_one_operand(0);
			}

			out_snprintf(" , ");

			if(cmd.Op2.type != o_void) 
			{  //then there is an argument to print
				out_one_operand(1);
			}

			out_snprintf(" , ");

			if(cmd.Op3.type != o_void) 
			{  //then there is an argument to print
				out_one_operand(2);
			}
	}




	term_output_buffer();
	gl_comm = 1;      //we want comments!
	MakeLine(str);    //output the line with default indentation
}