Tutorial: Make a simple Minecraft PE mod - zhuowei/MinecraftPEModWiki GitHub Wiki
-
Download the Android NDK from http://developer.android.com/sdk/ndk/index.html and extract it to a folder.
-
Extract libminecraftpe.so from the lib/armeabi-v7a folder of a Minecraft PE .apk. Place it in a good place; you'll be using it later. Personally, I would put it in the android-ndk-r7b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/ folder, as then you only have to type the name. I am going to assume that you did this.
-
Open a command prompt or Terminal and navigate to the android-ndk-r7b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/ folder extracted from the download.
-
Run objdump to get a disassembled version of libminecraftpe.
For Windows:
C:\android-ndk-r7b\toolchains\arm-linux-androideabi-4.4.3\prebuilt\windows\bin\arm-linux-androideabi-objdump -dRC libminecraftpe.so >mpedump.txt
I've also made a batch file . Place the disasm.bat file extracted from the .zip and libminecraftpe.so in the android-ndk-r7b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/ folder, then double click the batch file to launch objdump with the correct parameters.
For Linux and Mac OS X:
zhuowei@zhuowei-desktop:~/Documents/winprogress/ndk/linux-x86/bin$ ./arm-linux-androideabi-objdump -dRC libminecraftpe.so >mpedump.txt
This is based on the instructions at The Objdump tutorial at MultimediaWiki.
- Open mpedump.txt using any plain text editor. (I do not recommend Notepad, though - It's 15MB, too big for Notepad. )
The file produced is a disassembly of the file - It uses assembly language to describe what the program does. A tutorial for assembler is at http://www.heyrick.co.uk/assembler/ .
Method names are not obfuscated like Desktop edition, so you can look through it straight away.
The following assumes that you are using a libminecraftpe.so file from 0.2.1 Pocket Edition Demo.
Hmm... Interesting method name - I wonder if it sets up the number of slots displayed?
000989f0 Gui::getNumSlots(): 989f0: f8d0 0a28 ldr.w r0, [r0, #2600] ; 0xa28 989f4: 4770 bx lr 989f6: bf00 nop
The first line loads a value from inside the Gui object and then returns it. What if we made it load a constant number instead? Looking through the code, I noticed that loading a constant value is done in methods like this:
000e1358 Chicken::getEntityTypeId() const: e1358: 200a movs r0, #10 e135a: 4770 bx lr
So I guess we could just that instruction in to change the number of slots! Open up your hex editor and navigate to 989f0, the location indicated by the number on the left hand of the instruction that we want to change.
000989B0 04 46 48 46 B5 F0 34 EF D0 E7 04 46 28 46 B5 F0 .FHF..4....F(F.. 000989C0 30 EF CB E7 04 46 C9 E7 FC E7 0C A9 0B 91 21 E7 0....F........!. 000989D0 F8 E7 F2 E7 F6 E7 00 BF 28 6B 0F 00 F4 64 0C 00 ........(k...d.. 000989E0 C8 64 0C 00 38 09 00 00 EE 6D 0C 00 E8 6D 0C 00 .d..8....m...m.. 000989F0 D0 F8 28 0A 70 47 00 BF 70 B5 2D ED 02 8B D0 F8 ..(.pG..p.-..... --- moreslots.so --0x989F0/0x3F0B38-------------------------------------
You can see that the instruction is actually reversed. We'll replace that with:
000989C0 30 EF CB E7 04 46 C9 E7 FC E7 0C A9 0B 91 21 E7 0....F........!. 000989D0 F8 E7 F2 E7 F6 E7 00 BF 28 6B 0F 00 F4 64 0C 00 ........(k...d.. 000989E0 C8 64 0C 00 38 09 00 00 EE 6D 0C 00 E8 6D 0C 00 .d..8....m...m.. 000989F0 09 20 00 BF 70 47 00 BF 70 B5 2D ED 02 8B D0 F8 . ..pG..p.-..... -** moreslots.so --0x989F4/0x3F0B38-------------------------------------
The 09 20 part forms a movs r0, #9 instruction , which signifies 8 slots plus one slot for the block selection button, while the 00 bf part forms a nop, or "do nothing" instruction, as the new instruction is shorter than the original.
Copy your new libminecraftpe.so into the .apk and sign it using Marc's method.
Remove your existing copy of Minecraft PE, install the modified copy, and start it up.
If the bottom of the screen shows 8 slots, you win!
Now that you have a mod, share it with other people by creating a patch.