Friday 27 September 2013

How to execute ELF file compiled for MIPS architecture on x86_64 Windows?

In order to execute MIPS binary we will need to emulate architecture that it was compiled for. A good solution to accomplish this is using the QEMU emulator.


If you have a *nix you may need to install qemu as a package or compile it from source code. I will use precompiled QEMU for Windows. You can find it here . (More sources to get QEMU can be found on the official qemu wiki here) I've downloaded QEMU 1.6.0 Win32 binary . Then you have to unpack it. You can use Universal Extractor for this purpose or another extractor that is capable of extracting files from lzma.

Then you will need to install or use preinstalled system distributive. We will use Debian for this purposes. There is a site that describes how to do this and provides preinstalled Debian distributives. To use a working emulated Debian faster we will use a preinstalled variant.

Let's download preinstalled system disk drive and kernel from here. I've downloaded little-endian variant (See P.P.S. for big-endian):

debian_squeeze_mipsel_standard.qcow2 
vmlinux-2.6.32-5-4kc-malta

Then all you have to do is run your MIPS system. You can do this with a following command (You will need to specify full path to the qemu-system-mipsel which is located in the place where you've extracted archive or append location folder to the PATH System Environment variable):
qemu-system-mipsel -m 256 -M malta -kernel vmlinux-2.6.32-5-4kc-malta -hda debian_squeeze_mipsel_standard.qcow2 -append "root=/dev/sda1 console=tty0" -nographic
If all went right you will see such output:
Login with root/root or user/user credentials and use your fresh system. In my case I had network working so I've uploaded binary to execute from host system to network file share and downloaded it from guest(Debian qemu) system using wget . Probably there are more convenient ways to get a file from the host system but I will leave this research to you.

P.S. You may experience missing bios warning. There is a solution.  However system will probably work without it. You may need dd for windows, which is available in the Internet or you may create zeroed 128 Kb file another way. Probably even size doesn't matter.

P.P.S You may need to run big-endian MIPS. This can be done with qemu-system-mips insted of qemu-system-mipsel and downloading another versions of disk image and kernel from here.

No comments:

Post a Comment