qemu-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Generate an LSB binary from my MSB binary (arm32)


From: Frederick Virchanza Gotham
Subject: Generate an LSB binary from my MSB binary (arm32)
Date: Sun, 13 Feb 2022 18:16:30 +0000


I have written a program called 'Dynamo', and I have built it as a 32-Bit Big Endian ARM executable binary. (The architecture codename for 32-Bit Big Endian ARM is "armeb").

When I run this 'armeb' binary on my x86_64 desktop PC, of course qemu interprets the ARM machine code, converts it to x86_64 machine code and then runs it on my x86_64 CPU.

However if I were to run my 'armeb' program inside qemu running on a 32-Bit Little Endian ARM computer, such as the Raspberry Pi, then the only processing that qemu would have to do is:
(1) At the very beginning of my program, execute the CPU instruction "setend be" to switch the CPU to big endian for the current process.
(2) Reverse bytes when my program interacts with the kernel (i.e. reverse the bytes in the general purpose registers before and after each 'syscall' CPU instruction).

I want qemu to process my 'armeb' binary, and to produce from it a 32-Bit ARM Little Endian binary. If I understand correctly, 'qemu' would only have to do 3 things here:
(1) Change the ELF header of the executable file so that the magic number says "little endian" instead of "big endian". Also reverse the bytes in the values of fields in the ELF header (for example reverse the bytes in the address of the entry point).
(2) Insert one instruction at the program's entry point: "setend be".
(3) Before and after each 'syscall', reverse the bytes in the general purpose registers.

Is it possible to get qemu to generate an LSB binary from a statically-linked MSB binary something like as follows?

    qemu-convert-armeb-to-arm --input-file=dynamo_big --output-file=dynamo_little

If there is no such command, then I'd like to ask how can I go about achieving what I'm trying to achieve here. I would need to capture the machine code from qemu that it uses to reverse the bytes before and after syscall. Could someone please point me even vaguely in the right direction?

Or could I even possibly get qemu to process the file "libc.so.6" to reverse the bytes before and after each syscall, and then rename it to something like "libc_reverse_kernel_bytes.so.6" so then I can get my Dynamo program to link with it? So then the only change I'd have to make to my Dynamo binary would be to convert the ELF header from MSB to LSB, and just insert one instruction at the program's entry point: 'setend be'.

Please give me any ideas that might be floating around your head on this.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]