将ASM转换为C(不是逆向工程师) [英] convert ASM to C (not reverse engineer)

查看:208
本文介绍了将ASM转换为C(不是逆向工程师)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



Microchip提供了一些免费的源代码(I don不要在这里发布,以防万一这是一个no-no。基本上,谷歌AN937,点击第一个链接,并有一个链接源代码及其压缩文件)。它在ASM中,当我看着它时,我开始越过眼睛。我想把它转换成类似于c语言的东西,以便我可以跟随。因为行如:

  GLOBAL _24_bit_sub 
movf BARGB2,w
subwf AARGB2,f

可能很简单,但对我来说意味着什么。



必须有一些自动化的ASM到C翻译器,但我可以找到的是人们说不可能的。坦白说,它不可能是不可能的。两种语言都有结构,而且结构肯定可以翻译。



谢谢。

解决方案

您可以绝对地从汇编程序中获取ac程序。问题是它可能看起来不像你在想,或者也许会这样。我的PIC是生锈的,但使用另一个汇编器,比方说你有

 添加r1,r2 

在C中,我们说这成为

  r1 = r1 + r2; 

可能更可读。您可能会失去任何变量名称的感觉,因为值从内存跳转到寄存器并返回,并且寄存器被重用。如果您正在谈论有两个寄存器和其他寄存器的旧图片,那么实际上可能更容易,因为变量大部分都在内存中,您可以查看地址,如

  q = mem [0x12]; 
e = q;
q = mem [0x13];
e = e + q;
mem [0x12] = e;

很长时间,但很明显,mem [0x12] = mem [0x12] + mem [ 0x13];



这些内存位置很可能不会像编译的C代码那样跳转到具有一堆寄存器的处理器上。 pic可能会更容易找出变量,然后进行搜索和替换,以便在文件中命名它们。



您要查找的内容称为静态二进制翻译,不一定是从一个二进制转换为另一个(一个处理器到另一个处理器)的翻译,但在这种情况下,从pic二进制转换为C.理想情况下,您将需要使用应用笔记中给出的汇编程序,并使用微芯片工具,然后做翻译。您也可以进行动态二进制翻译,但是您甚至不太可能找到其中的一个,它通常不会导致C但是另一个二进制文件。有没有想过如何在沃尔玛与pac-man和galaga的15美元左右的操纵杆工作?来自商场的rom使用静态二进制转换,优化和清理以及C或任何为手持盒中的新目标处理器编译的中间语言进行转换。我想,并不是所有这些都是这样做的,但我相当确定一些。



百万美元的问题,你能找到一个静态二进制翻译器的图片吗?谁知道,你可能必须自己写一个。并且猜测这是什么意思,你编写一个反汇编程序,而不是像本地汇编语法(如r0,r1)中的指令反汇编,你的反汇编程序打印出来r0 = r0 + r1;当你完成这个反汇编程序,虽然你会知道图形汇编语言这么好,你不需要asm到C翻译器。你有鸡蛋问题。


I googled and I see a suprising amount of flippant responses basically laughing at the asker for asking such a question.

Microchip provides some source code for free (I don't want to post it here in case that's a no-no. Basically, google AN937, click the first link and there's a link for "source code" and its a zipped file). Its in ASM and when I look at it I start to go cross-eyed. I'd like to convert it to something resembling a c type language so that I can follow along. Because lines such as:

GLOBAL  _24_bit_sub
movf    BARGB2,w
subwf   AARGB2,f

are probably very simple but they mean nothing to me.

There must be some automated ASM to C translator out there but all I can find are people saying its impossible. Frankly, its impossible for it to be impossible. Both languages have structure and that structure surely can be translated.

thank you.

解决方案

You can absolutely make a c program from assembler. The problem is it may not look like what you are thinking, or maybe it will. My PIC is rusty but using another assembler, say you had

add r1,r2

In C lets say that becomes

r1 = r1 + r2;

Possibly more readable. You lose any sense of variable names perhaps as values are jumping from memory to registers and back and the registers are being reused. If you are talking about the older pics that had what two registers an accumulator and another, well it actually might be easier because variables were in memory for the most part, you look at the address, something like

q = mem[0x12];
e = q;
q = mem[0x13];
e = e + q;
mem[0x12] = e;

Long and drawn out but it is clear that mem[0x12] = mem[0x12] + mem[0x13];

These memory locations are likely variables that will not jump around like compiled C code for a processor with a bunch of registers. The pic might make it easier to figure out the variables and then do a search and replace to name them across the file.

What you are looking for is called a static binary translation, not necessarily a translation from one binary to another (one processor to another) but in this case a translation from pic binary to C. Ideally you would want to take the assembler given in the app note and assemble it to a binary using the microchip tools, then do the translation. You can do dynamic binary translation as well but you are even less likely to find one of those and it doesnt normally result in C but one binary to another. Ever wonder how those $15 joysticks at wal-mart with pac-man and galaga work? The rom from the arcade was converted using static binary translation, optimized and cleaned up and the C or whatever intermediate language compiled for the new target processor in the handheld box. I imagine not all of them were done this way but am pretty sure some were.

The million dollar question, can you find a static binary translator for a pic? Who knows, you probably have to write one yourself. And guess what that means, you write a disassembler, and instead of disassembling to an instruction in the native assembler syntax like add r0,r1 you have your disassembler print out r0=r0+r1; By the time you finish this disassembler though you will know the pic assembly language so well that you wont need the asm to C translator. You have a chicken and egg problem.

这篇关于将ASM转换为C(不是逆向工程师)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆