0

I have an assembler program and I try to understand it. (I'm actually profiling it). Is there a Linux tool/editor that would structurize it a little for me? Displaying where loops/jumps are would be enough. Handy description of what an instruction does would be great.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Łukasz Lew
  • 48,526
  • 41
  • 139
  • 208
  • You have the assembly source code, or are you using a disassembler on an executable? -- Do you know assembly? x86 (32-bit) processor? – mctylr Feb 24 '10 at 18:01
  • I have source dumped by oprofile. So I guess it is similar to objdump format. I have source as well but with heavy optimization oprofile (objdump?) can't find correspondence between ASM and C++ – Łukasz Lew Feb 24 '10 at 18:34
  • So you have the disassembly of an executable written in C++. This is sort of a different question than understanding a program originally written in assembly, because you want to make a connection between particular assembly instructions and the original C++ source. The first thing you can do, is ensure that the C++ compiler is run _with debugging enabled_, so extra debugging information is left in the executable for the disassembler to reference. Disassemblers only reverse the process back to assembly. There is also the process of decompiling. It tends to be harder and not very good results. – mctylr Feb 24 '10 at 21:23

6 Answers6

3

If you look for something that resembles OllyDbg but for linux, you might try edb.

Andras Vass
  • 11,478
  • 1
  • 37
  • 49
2

Since you are really reversing a high level language for profiling, you can do a couple things to help the process. First enable and preserve debugging information in the C++ compiler and linker (don't let it strip the executable). In g++ the -g command line flag does this. Second many C++ compilers have flags to output the immediate assembly source code, rather than emitting the object code (which is used by the linker). In g++ the -S flag enables this.

The assembly from the compiler can be compared to the assembly from the oprofile disassembly.

I'm not very familiar with decompilers, but two including one from another SO post are Boomerang and REC for C, rather than C++.

I hope that helps.

Community
  • 1
  • 1
mctylr
  • 5,159
  • 20
  • 32
0

Only, for PowerPC CPU The project Demono purpose to restore algorithms of binary code (currently, only for PPC) - and it's not fully decompiler. Project is under construction, but some examples are works. Site has Online service for generating C-like description of functions from assebler: online service for decompile PPC asm

For use it, you should perform following steps:

  1. Disassemble binary code(for PowerPC) to text of assembler (by IDA)
  2. Insert text of assebler to field "Ассемблер"
  3. Press button "Восстановить"
  4. Look to form "Восстановленный алгоритм"

For example, if your assembler has text:

funct(){
  0x00000002:  cmpw r3, r4    
  0x00000003:  ble label_1    
  0x00000004:  mr r6, r3      
  0x00000005:  b label_2      
  0x00000006:  label_1:       
  0x00000007:  mr r6, r4      
  0x00000008:  label_2:       
  0x00000009:  cmpw r6, r5    
  0x0000000A:  ble label_3    
  0x0000000B:  mr r7, r6      
  0x0000000C:  b label_4      
  0x0000000D:  label_3:       
  0x0000000E:  mr r7, r5      
  0x0000000F:  label_4:       
  0x00000010:  mr r3, r7      
  0x00000011:  blr            
}

Online service restore following function's algorithm description:

funct(arg_w_0, arg_w_1, arg_w_2){
  if(arg_w_0>arg_w_1?true?false){
    arg_w_0=arg_w_1;
  }else{
  }
  if(arg_w_0>arg_w_2?true?false){
    arg_w_0=arg_w_2;
  }else{
  }
  return (arg_w_0);
}

And, therefore, funct() derive max of three numbers - max3().

Possible, this service helps you understand how assembler instructions works..

Egg Head
  • 369
  • 3
  • 4
0

There's an Asm plugin for Eclipse you could use.

However, usually IDEs aren't employed for assembly programming. I'm not sure how much more understanding you will gain by easily spotting where the jumps and loops are - you have to read through everything anyway.

Eli Bendersky
  • 263,248
  • 89
  • 350
  • 412
0

Have a look at this...

http://sourceforge.net/projects/asmplugin/

It's a plugin for Eclipse...

Martin Milan
  • 6,346
  • 2
  • 32
  • 44
0

Not really, but you can always look at instruction references, use syntax highlighting (vim asm syntax) also you could step it through debugger if there's no limitation running it. For already assembled code this might be interesting: LIDA