Logo Search packages:      
Sourcecode: eresi version File versions  Download package

u_int revm_instr_display ( int  fd,
u_int  index,
eresi_Addr  vaddr,
u_int  foffset,
u_int  size,
char *  name,
u_int  nindex,
char *  buff 
)

Display An instruction. Runtime compatible

Parameters:
fd 
index 
vaddr 
foffset 
size 
name 
nindex 
buff 

Definition at line 192 of file disasm.c.

References asm_display_instr_att(), asm_instr_len(), asm_read_instr(), buf, elfsh_get_arch(), and revm_output().

Referenced by revm_object_display().

{
  char            *s;
  char            buf[256];
  u_int           idx_bytes;
  u_int           ret;
  asm_instr ptr;
  char            base[16] = "0123456789ABCDEF";
  char            logbuf[BUFSIZ];
  char            c1[2];
  char            c2[2];
  u_int           strsz;
  elfsh_Half      machine;

  PROFILER_IN(__FILE__, __FUNCTION__, __LINE__);

  if (!buff)
    PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, 
                  "Invalid argument", (-1));    

  /* Init proc */               
  if (!world.curjob->proc) 
    {
      switch (machine = elfsh_get_arch(world.curjob->curfile->hdr))
      {
      case EM_386:
        world.curjob->proc = &world.proc;
        break;
      case EM_SPARC:
      case EM_SPARC32PLUS:
      case EM_SPARCV9:
        world.curjob->proc = &world.proc_sparc;
        break;
      case EM_MIPS:
      case EM_MIPS_RS3_LE:
      case EM_MIPS_X:
        world.curjob->proc = &world.proc_mips;
        break;
      default:
        snprintf(logbuf, sizeof (logbuf) - 1, 
               "Architecture %s not supported. No disassembly available\n",
               elfsh_get_machine_string(machine));
        revm_output(logbuf);
        PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, 0);
      }
    }

  /* Print the instr. itself : vaddr and relative symbol resolution */
  ret = asm_read_instr(&ptr, (u_char *)buff + index, size - index + 10, 
                   world.curjob->proc);
  if (ret == -1)
    PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, "asm_read_instruction faild (-1)", (ret));

  s = (!ret ? "(bad)" : asm_display_instr_att(&ptr, (vaddr ? vaddr + index : 0)));

  /* Libasm test */
  if (fd == -1)
    {

      /* Are we in quiet mode ? */
      if (world.state.revm_quiet)
      {
        snprintf(buf, sizeof(buf), " %s %s + %s", 
               revm_coloraddress(XFMT, vaddr + index), 
               revm_colorstr(name),
               revm_colornumber("%u", nindex));
        size = snprintf(logbuf, BUFSIZ, "%-40s %-30s ", 
                    buf, revm_colorinstr(s));
      }
      else
      {
        size = snprintf(buf, sizeof(buf), " %s [%s %s] %s + %s", 
                    revm_coloraddress(XFMT, vaddr + index), 
                    revm_colorfieldstr("foff:"), 
                    revm_colornumber("%u", foffset + index), 
                    revm_colorstr(name), 
                    revm_colornumber("%u", nindex));
        strsz = strlen(s);
        size = snprintf(logbuf, BUFSIZ, "%-*s %-*s ", 
                    (size > 95 ? 125 : 
                     size > 87 ? 100 : 
                     size > 75 ? 108 : 
                     size > 50 ? 88 : 55),
                    buf,
                    (strsz > 95 ? 125 : 
                     strsz > 87 ? 100 : 
                     strsz > 75 ? 108 : 
                     strsz > 50 ? 88 : 55),
                    revm_colorinstr(s));
      }
      
      /* Print bytes in hexa for this instruction */
      ret = asm_instr_len(&ptr);
      if (!ret)
      ret++;

      if (!world.state.revm_quiet)
      for (idx_bytes = 0; idx_bytes < ret; idx_bytes++)
        {
          c1[0] = base[(buff[index + idx_bytes] >> 4) & 0x0F];
          c2[0] = base[buff[index + idx_bytes] & 0x0F];
          c1[1] = c2[1] = 0x00;
          size += snprintf(logbuf + size, sizeof(logbuf) - size, "%s%s ", 
                       revm_colorfieldstr(c1), 
                       revm_colorfieldstr(c2));
        }

      if (!world.curjob->curcmd || !world.curjob->curcmd->use_regx[1] || 
        !regexec(&second->name, logbuf, 0, 0, 0))
      {
        revm_output(logbuf);
        revm_output("\n");
      }
      revm_endline();
    }
  else
    write(fd, s, strlen(s));
  PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, (ret));
}


Generated by  Doxygen 1.6.0   Back to index