nmzik
nmzik

Reputation: 151

Convert binary to arm

How I can run x86 binaries (for example .exe file) on arm?As I see on Wikipedia,I need to convert binary data for the emulated platform into binary data suitable for execution on the targeted platform.but question is:How I can do it?I need to open file in hex editor and change?Or something else?

Upvotes: 7

Views: 13687

Answers (4)

Zibri
Zibri

Reputation: 9827

To run an ARM executable on an X86 machine all you need is qemu-user.

Example: you have busybox compiled for AARCH64 architecture (ARM64) and you want to run it on an X86_64 linux system:

Assuming a static compile, this runs arm64 code on x86 system:

$ qemu-aarch64-static ./busybox

And this runs X86 code on ARM system:

$ qemu-x86_64-static ./busybox

What I am curioous is if there is a way to embed both in a single program.

Upvotes: 1

Lan...
Lan...

Reputation: 103

read x86 binary file as utf-8,then copy from ELF to last character�.Then go to arm binary and delete as you copy with x86.Then copy x86 in clip-board to the head.i tried and it's working.

Upvotes: -3

artless-noise-bye-due2AI
artless-noise-bye-due2AI

Reputation: 22395

You can not do this with a binary;note1 here binary means an object with no symbol information like an elf file. Even with an elf file, this is difficult to impossible. The issue is determining code from data. If you resolve this issue, then you can make de-compilers and other tools.

Even if you haven an elf file, a compiler will insert constants used in the code in the text segment. You have to look at many op-codes and do a reverse basic block to figure out where a function starts and ends.

A better mechanism is to emulate the x86 on the ARM. Here, you can use JIT technology to do the translation as encountered, but you approximately double code space. Also, the code will execute horribly. The ARM has 16 registers and the x86 is register starved (usually it has hidden registers). A compilers big job is to allocate these registers. QEMU is one technology that does this. I am unsure if it goes in the x86 to ARM direction; and it will have a tough job as noted.

Note1: The x86 has an asymmetric op-code sizing. In order to recognize a function prologue and epilogue, you would have to scan an image multiple times. To do this, I think the problem would be something like O(n!) where n is the bytes of the image, and then you might have trouble with in-line assembler and library routines coded in assembler. It maybe possible, but it is extremely hard.

Upvotes: 3

PaulProgrammer
PaulProgrammer

Reputation: 17620

To successfully do this, you'd have to do two things.. one relatively easy, one very hard. Neither of which you want to do by hand in a hex editor.

  1. Convert the machine code from x86 to ARM. This is the easy one, because you should be able to map each x86 opcode to one or more ARM opcodes. There are different ways to do this, some more efficient than others, but it can be done with a pretty straightforward mapping.

  2. Remap function calls (and other jumps). This one is hard, because monkeying with the opcodes is going to change all the offsets for the jump and return points. If you have dynamically linked libraries (.so), and we assume that all the libraries are available at exactly the same version in both places (a sketchy assumption at best), you'd have to remap the loads.

It's essentially a machine->machine compiler and linker.

So, can you do it? Sure.

Is it easy? No.

There may be a commercial tool out there, but I'm not aware of it.

Upvotes: 7

Related Questions