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

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

问题描述

我一派,我看到的轻率答复一个令人惊奇量在提问者笑基本上为这么问。

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

Microchip的免费提供部分源$ C ​​$ C(我不想在这里发布的情况下,这是一个禁忌。基本上,谷歌AN937,单击第一个链接,并有一个链接,源$ C ​​$ c和它的一个压缩文件)。它在ASM,当我看着它,我开始去斗眼。我想将其转换为类似的东西一个C类型的语言,这样我可以跟着。因为线,如:

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.

必须有一些自动化的ASM到C翻译在那里,但我能看到的是人们说的是不可能的。坦率地说,它不可能为它是不可能的。这两种语言有结构和结构肯定可以翻译。

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.

感谢您。

推荐答案

您可以绝对让从汇编的C程序。问题是,它可能不会像你在想什么,或者它会的。我的PIC是生锈的,但使用另一汇编,说你有

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

在C可以说成为

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;

长和拉出,但很显然,MEM [0×12] = MEM [0×12] + MEM [0x13];

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

这些存储位置是不会跳周围像编译C code代表处理器与一群寄存器可能的变量。该图片可能更容易找出变量,然后做一个搜索和替换在整个文件的名字。

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.

你所寻找的被称为静态二进制翻译,不一定是一个二进制到另一个(一个处理器到另一个),一个翻译,但在这种情况下,从图片二进制C.翻译理想情况下,你会希望采取汇编在应用笔记给出以及使用Microchip的工具装配到一个程序,然后做翻译。你可以做动态二进制翻译很好,但你更不可能发现其中的一个,它通常犯规导致C,但一个二进制到另一个。有没有想过如何在沃尔玛与PAC-男子和Galaga游戏工作的$ 15个操纵杆?从街机的ROM使用静态二进制翻译转换,优化和清理,C或任何中间语言编译在手持框中输入新的目标处理器。我想不是所有人都是这样做的方式,但我pretty肯定有些人。

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.

百万美元的问题,你可以找到一个图片的静态二进制翻译?谁知道,你可能要自己写一个。猜猜这是什么意思,你写一个反汇编,并且而不是在本机汇编语法拆卸一个指令像添加R0,R1你有你的反汇编打印输出R0 = R0 + R1;到时候你完成这项反汇编虽然你会知道图片汇编语言这么好,你不会需要汇编到C翻译。你有一个鸡和蛋的问题。

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天全站免登陆