shakalaca/MagiskOnEmulator

Busybox and x86_64?

HypervisorXY opened this issue · 2 comments

First of all, thanks so much for making and maintaining this project, most appreciated.

This is less of a bug report as I'm unsure of the intended behavior, and more of a question regarding whether this project is supposed to support running on x86_64 based emulator guests as well as the resolution that worked for me.

If I try replacing magisk_emu.zip with the magisk.zip from the 21.4 release, after installing plugins I will end up with errors in magisk manager's debug log area regarding Exec format error (8) which I eventually determined was likely because it seemed like the busybox being installed from the update-binary file was an x86 version of busybox. The installed plugins of course fail to run with one exec format error occurring per plugin installed.

It looked like there might have been some logic in update-binary to detect whether its running on an x86 or 64 bit emulator by trying to run the x86 version extracted with dd first to see if there's any error and overwrite it with what I'm guessing was a 64 bit version if there was an error, but I'm guessing that this logic failed to produce the expected result when android translates the x86 code on the fly during the execution of update-binary on at least Android 11 (API 30) x86_64 which is what I was working with.

After replacing the x86 chunk in update-binary with a copy of busybox-86_64 from github.com/Magisk-Modules-Repo/busybox-ndk, adding 0 padding to the end of the nearest 1024 size block, and updating the offset for X86_CNT it seemed to resolve all my issues and I could install and use all the plugins I wanted without the exec format errors in Magisk Manager.

Rather than chase down the logic and confirm my suspicions regarding the logic in update-binary I figured I'd just post this here to let you know. You can see the relevant changes I made in my fork of your repo should you be interested.

Thanks again for this project, I was quite pleased to be able to get a copy of magisk running with the frida plugin etc goin in the android emulator!

The busybox in the 'update-binary' was taken from older Magisk.zip (canary version 20307 I believe) and according to John he only packed 32bit version (both arm and x86) for various reason. In the latest commit of this project, the busybox from update-binary is only used for operations during install, and the one installed on emulator comes from Magisk itself because that would be 'newer' and 'less buggy'. (unfortunately there's still no 64bit version)

Providing both x86 and x86_64 binaries is possible but it would add complexity to this project and most people are not comfortable with blobs. :(

Hi, please check the latest commit ! :)