7

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?

4 Answers 4

7

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.

6
  • And I'm also assuming the OS is "similar" -- e.g. Linux x86 and Linux ARM. With windows -> linux, it goes out the window. Same for windows x86 to windows ARM, because they're the same in name only. Commented Apr 2, 2013 at 5:17
  • You might also be able to decompile/recompile, which might be easier than a machine->machine translation. Commented Apr 2, 2013 at 5:19
  • 2
    google terms like: static binary translation. First you need to write a disassembler, which for x86 is an advanced project. Then you convert each of those instructions into some other language. machine to machine works, but I think (based on personal experience) you will find converting to C or something like that a better choice, then compile that for whatever platform. Paul left out 3) emulate the x86 on the arm, since there are already so many of these out there is is the easiest choice.
    – old_timer
    Commented Apr 2, 2013 at 13:09
  • @dwelch Sorry, I missed your comment. I wouldn't have posted if so. Commented Apr 2, 2013 at 14:08
  • You can disassemble the file using a disassembler (en.wikibooks.org/wiki/X86_Disassembly/…) and inspect the code. You'd have to invent something to convert it. I tried to lay out the steps, but except as an academic exercise on a very simple program, this isn't a practical project. Commented Apr 3, 2013 at 14:44
3

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.

1

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.

2
  • I think OP's question was to run the other way - to run an x86 binary on ARM. Commented Jan 4, 2023 at 16:54
  • @PaulProgrammer you're right... added both cases.
    – Zibri
    Commented Jan 8, 2023 at 13:42
-3

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.

1
  • 1
    "Working" doesn't mean that it can actually run (unless its entry-point is polyglot machine code that can decode as both x86 or ARM machine code). Just changing the metadata will get file and readelf -a to tell you that it's now an ARM (or x86) binary executable. But the contents will still be the same, machine code for the original architecture, assuming it was normal compiler output. Commented Sep 27, 2022 at 19:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.