简体   繁体   中英

How to convert Atmel AVR Assembler code into a code in C language

Is it possible to convert AVR Assembler code into original code written in C language?

If yes, what is the name of the software to use?

Well, this task is quite AI-complete. This is basically the point of reverse engineering: given some disassembled code, understand what it does, and possibly represent it in a high-level programming language. There are tools that attempt to automate this process , but generally it's not quite easy, sometimes not even possible.

So your best bet is to read the assembly, understand what it does and write the equivalent C code by hand. Not going to be easy if you're not an experienced reverse engineer.

I believe IDAPro supports AVR assembler and there is a HexRay decompiler which converts ASM to kind-of C code.

However, HexRay is really expensive.

One of the working options to decompile AVR hex binaries into C is Ghidra . But you may find the result kind of sad:(

This code:

int n=5;

int main(void) {
    if(n>=10) {
        n=15;
    }
    else {
        n=20;
    }

}

will be decompiled into this code:

int FUN_code_004f(void)

{
  int iVar1;
  
  W = CONCAT11(DAT_mem_0101,DAT_mem_0100);
  iVar1 = W;
  W = W + -10;
  if ((bool)(W < 0 ^ SBORROW2(iVar1,10))) {
    W._0_1_ = 0x14;
  }
  else {
    W._0_1_ = 0xf;
  }
  R1 = 0;
  W = 0;
  DAT_mem_0100 = (undefined)W;
  DAT_mem_0101 = 0;
  return W;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM