📚 OpenRCE is preserved as a read-only archive. Launched at RECon Montreal in 2005. Registration and posting are disabled.








Flag: Tornado! Hurricane!

 Forums >>  IDA Pro  >>  how to get the disassm operands value size?

Topic created on: January 10, 2011 05:35 CST by llm .

hi all,

im try to get the commands operands size info out of my disassembled code - im using an idc-script and IDA 5 Freeware
(the script is at the end of the post, just as an reference)

my script produces following information:

dissasm: sub     sp, 12h
code: 0x83
mnem: sub
operand 0: register 00000004 sp
operand 1: immediate 00000012 12h

dissasm: push    di
code: 0x57
mnem: push
operand 0: register 00000007 di

dissasm: mov     word_44CEE, dx
code: 0x89
mnem: mov
operand 0: memref 0000957e word_44CEE
operand 1: register 00000002 dx

dissasm: push    [bp+arg_2]
code: 0xff
mnem: push
operand 0: base+index+disp 00000008 [bp+arg_2]

dissasm: mov     word ptr dword_438E8+2, dx
code: 0x89
mnem: mov
operand 0: memref 0000817a word ptr dword_438E8+2
operand 1: register 00000002 dx
....

now my question is: how can get the size of the operands (its easy when registers are used nr=>register=>size), but
what about the immediate and the memory-access operand size?

to produce something like

sub sp,12h --> sub reg:sp(word), immediate:12h(byte)
push di --> push reg:di(word)
mov word_44CEE,dx --> mov mem:word_44CEE(word), reg:dx(word)
push [bp+arg_2] --> push mem:bp+arg_2(word)
mov word ptr dword_438E+2,dx --> mov mem:dword_438E+2(word),reg:dx(word)
...

i saw a op_t struct in my ida book but there seems to be no way of using this or DecodeInstruction inside
of my idc

any ideas how can i solve this problem - do i need to use the SDK?


the script:

#include <idc.idc>

static showoperands(f,ea)
{
  auto i;
  for (i=0 ; GetOpType(ea, i) ; i++)
  {
    fprintf(f,"operand %d: %s %08lx %s\n", i, OpTypeString(GetOpType(ea, i)), GetOperandValue(ea, i), GetOpnd(ea, i));
  }
}

static OpTypeString(t)
{
  if (t==1) return "register";
  if (t==2) return "memref";
  if (t==3) return "base+index";
  if (t==4) return "base+index+disp";
  if (t==5) return "immediate";
  if (t==6) return "immfar";
  if (t==7) return "immnear";
}

static main()
{
  auto addr;
  auto disass;
  auto mnem;
  auto f;
  auto f_mnem;
  auto op_type;
  auto op_str;
  auto op_nr;
  auto i;
  auto first_byte;
  auto cmd;
  auto prefix;

  f = fopen("c:\\temp\\dis.txt", "w+");
  f_mnem = fopen("c:\\temp\\dis.mnem.txt", "w+");

  addr = 0;
  for(;;)
  {
    addr = FindCode(addr,SEARCH_DOWN);
    if(addr == BADADDR) break;

    mnem = GetMnem(addr);
    disass = GetDisasm(addr);

    first_byte = Byte(addr);

    fprintf(f,"dissasm: %s\n", disass);
    fprintf(f,"code: 0x%02x\n",first_byte);
    fprintf(f,"dis: %s\n",disass);
    fprintf(f,"mnem: %s\n",mnem);

    fprintf(f_mnem,"%s\t0x%02x\t%s\n",mnem,first_byte,prefix);

    showoperands( f, addr );

    fprintf(f,"\n");
  }
}

No posts found under this topic.
Note: Registration is required to post to the forums.

There are 31,328 total registered users.


Recently Created Topics
[help] Unpacking VMP...
Mar/12
Reverse Engineering ...
Jul/06
let 'IDAPython' impo...
Sep/24
set 'IDAPython' as t...
Sep/24
GuessType return une...
Sep/20
About retrieving the...
Sep/07
How to find specific...
Aug/15
How to get data depe...
Jul/07
Identify RVA data in...
May/06
Question about memor...
Dec/12


Recent Forum Posts
Finding the procedur...
rolEYder
Question about debbu...
rolEYder
Identify RVA data in...
sohlow
let 'IDAPython' impo...
sohlow
How to find specific...
hackgreti
Problem with ollydbg
sh3dow
How can I write olly...
sh3dow
New LoadMAP plugin v...
mefisto...
Intel pin in loaded ...
djnemo
OOP_RE tool available?
Bl4ckm4n


Recent Blog Entries
halsten
Mar/14
Breaking IonCUBE VM

oleavr
Oct/24
Anatomy of a code tracer

hasherezade
Sep/24
IAT Patcher - new tool for ...

oleavr
Aug/27
CryptoShark: code tracer ba...

oleavr
Jun/25
Build a debugger in 5 minutes

More ...


Recent Blog Comments
nieo on:
Mar/22
IAT Patcher - new tool for ...

djnemo on:
Nov/17
Kernel debugger vs user mod...

acel on:
Nov/14
Kernel debugger vs user mod...

pedram on:
Dec/21
frida.github.io: scriptable...

capadleman on:
Jun/19
Using NtCreateThreadEx for ...

More ...


Imagery
SoySauce Blueprint
Jun 6, 2008

[+] expand

View Gallery (11) / Submit