yashsingh1/xdaforums huggingface dataset:
[Android Software Development] osm0sis:
Android Image Kitchen - UnpackImg Script
by osm0sis @ xda-developers

Supplied image: boot-k900.img

Setting up work folders...

Image type: OSIP

Splitting image to "split_img/"...
header size 512
sig size 480
bootstub size 4096
kernel size 5474880
ramdisk size 1397203

Unpacking ramdisk to "ramdisk/"...

Compression used: gzip
7977 blocks

Done!

Android Image Kitchen - UnpackImg Script
by osm0sis @ xda-developers

Supplied image: boot-z00d.img

Removing old work folders and files...

Setting up work folders...

Image type: OSIP

Splitting image to "split_img/"...
header size 512
sig size 480
bootstub size 8192
kernel size 5251072
ramdisk size 3739648

Unpacking ramdisk to "ramdisk/"...

Compression used: gzip
18211 blocks

Done!

All of the boot/recovery files in your .tgz (including droidboot.img, boot.bin and pos.bin) unpack fine here on my arm64 cross-compile and my Cygwin compile. I'll test my Linux and macOS cross-compiles probably tomorrow.

You can use my mboot.py in the meantime: https://github.com/osm0sis/mboot_py
[Android Software Development] osm0sis:
Question to Windows users: how many of you are getting false positives from my sudo.exe? I see it pop up in Windows Defender once in awhile but then it's usually gone again with the next definitions update. I'm thinking about adding in a little .js drop to elevate instead, but there's always the potential this will trigger heuristics also, so I'd like to know how big a problem the current implementation is generally.

Any thoughts on this [MENTION=5787964]SuperR.[/MENTION]? Have your users had any issues with this?
[Android Software Development] zainifame:
what command exactly you use to compile the project? and is that any other dependency required?... i'm trying to compile on linux... just wanna try standalone tool.
[Android Software Development] osm0sis:
`make` ;)

But all kidding aside, binaries from cross-compiles to Linux and macOS weren't working, seems to be because isalnum() doesn't behave the same on different platforms, so I've just reimplemented a custom version to make it uniform, and it seems good now! :good::cowboy:
[Android Software Development] SuperR.:
Only one user has mentioned it so far. I have not personally had any issues with it, but I only run a Windows VM for testing.
[Android Software Development] zainifame:
hoora for OSIP :silly:
[Android Software Development] arraki:
Hello,I have a smartphone Xiaomi MiMax3(android9)Tried a lot of programs for disassembly/Assembly .All doing fine,but after flashing the phone hangs on bootanimation.Like found the decision.When I remove these lines

"if [ -f split_img/*-sigtype ]; then

sigtype=`cat split_img/*-sigtype`;

if [ -f split_img/*-avbtype ]; then

avbtype=`cat split_img/*-avbtype`;

fi;

if [ -f split_img/*-blobtype ]; then

blobtype=`cat split_img/*-blobtype`;

fi;

echo "Signing new image...\n";

echo "Using signature: $sigtype $avbtype$avbtxt$blobtype\n";

test ! "$avbkey" && avbkey="$rel/avb/verity";

case $sigtype in

AVB) dalvikvm -Xbootclasspath:/system/framework/core-oj.jar:/system/framework/core-libart.jar:/system/framework/conscrypt.jar:/system/framework/bouncycastle.jar -Xnodex2oat -Xnoimage-dex2oat -cp $bin/BootSignature_Android.jar com.android.verity.BootSignature /$avbtype unsigned-new.img "$avbkey.pk8" "$avbkey.x509."* image-new.img 2>/dev/null;;

BLOB)

$bb printf '-SIGNED-BY-SIGNBLOB-\00\00\00\00\00\00\00\00' > image-new.img;

$bin/blobpack tempblob $blobtype unsigned-new.img >/dev/null;

cat tempblob >> image-new.img;

rm -rf tempblob;

;;

CHROMEOS) $bin/futility vbutil_kernel --pack image-new.img --keyblock $rel/chromeos/kernel.keyblock --signprivate $rel/chromeos/kernel_data_key.vbprivk --version 1 --vmlinuz unsigned-new.img --bootloader $rel/chromeos/empty --config $rel/chromeos/empty --arch arm --flags 0x1;;

DHTB)

$bin/dhtbsign -i unsigned-new.img -o image-new.img >/dev/null;

rm -rf split_img/*-tailtype 2>/dev/null;

;;

NOOK*) cat split_img/*-master_boot.key unsigned-new.img > image-new.img;;

esac;

if [ $? != "0" ]; then

abort;

return 1;

fi;

fi;"

from the build script,the phone loads normally,but the wifi does not work.Can this be fixed
[Android Software Development] osm0sis:
So in effect you're not signing the resulting image? The whole point of AIK is giving access to the image parameters as the big pile of files in split_img rather than hack around in a script/command-line. You could just go there and delete the -sigtype file.

As always, upload the untouched image you're working with or I can't help.
[Android Software Development] arraki:
https://yadi.sk/d/1Te-bolVA0vyyQ
[Android Software Development] osm0sis:
Does `repackimg.sh --original` create a working image?
[Android Software Development] arraki:
I'm sorry,I'm from Russia,I do not quite understand.This boot.img one's from the firmware "Xiaomi.eu".I didn't do anything to him.
[Android Software Development] osm0sis:
Right, but you're trying to unpack it with AIK right?

Do `./unpackimg.sh boot.img` then `./repackimg.sh --original` and tell me if the image-new.img boots.
[Android Software Development] arraki:
Yes,I this boot.img also collected the program with original "repackimg.sh" and the firmware did not start And then already began to modify "repackimg.sh"

I just thought I'd give you the original boot.img,so I wrote that I had nothing to do with him.
[Android Software Development] osm0sis:
Okay, I think you are telling me that even the image-new.img created by `repackimg.sh --original` does not boot. This image is 100% identical to the original boot.img EXCEPT for the AVBv1 signature. The original boot.img probably has Xaomi's signature, but we can't recreate that, so AIK signs with the public AOSP "verity" signature.

For some reason I guess your bootloader/ROM does not like any other signature. Maybe you have verity enabled still? You could try rooting the boot.img with Magisk Manager before attempting to unpack it. It might work better.

You could also try `./unpackimg.sh boot.img` with the untouched boot.img, then `rm split_img/*-sigtype split_img/*-avbtype` and then `./repackimg.sh --original`; This one should boot since it will not be signed, but tell me if the wifi is still broken.

Either way, I don't think this is a problem with AIK, more just you figuring out how to use it and what your device needs. :good:
[Android Software Development] arraki:
I tried repackaging booth after magisk, the effect is the same.

The latter did not understand,to try to remove these lines from "unpackimg.sh"?
[Android Software Development] osm0sis:
No.

Do not change the scripts.

I am talking about files.

Look in split_img after unpack.

Delete *-sigtype and *-avbtype.

Then try `repackimg.sh --original`.

I do not think I can help you more.
[Android Software Development] arraki:
But exactly where to look,in to split_img i don't see
[Android Software Development] ashyx:
Some serious hand holding happening here. :rolleyes:

Split_image contains a bunch of text files labelled with relevance to what they contain.

Just edit in any text editor.
[Android Software Development] osm0sis:
Just noticed the signature is from xiaomi.eu themselves and has [MENTION=3854189]ingbrzy[/MENTION]'s name and everything. So I doubt bootloader or ROM would be enforcing that, but still the only difference with a --original repack is the signature, so it's gotta be verity related or something. I can safely conclude it's not a fault of AIK I think.

Also, the reason he's not seeing those files is probably because he's still using the version he hacked the scripts in.. sigtype and avbtype are present after unpack on my device with AIK-mobile v3.5 and his uploaded boot.img. :rolleyes:
[Android Software Development] osm0sis:
Just noticed the signature is from xiaomi.eu themselves and has [MENTION=3854189]ingbrzy[/MENTION]'s name and everything. So I doubt bootloader or ROM would be enforcing that, but still the only difference with a --original repack is the signature, so it's gotta be verity related or something. I can safely conclude it's not a fault of AIK I think.
[Android Software Development] jcmm11:
I suspect there's also some language difficulties going on. Basic, clear, English + Google translate may help.
[Android Software Development] arraki:
Yeah,something weird is going on.Took a backup boot from twrp,sorted,in it there are these files,deleted them,collected a boot and stitched,the firmware was loaded,wifi is work:)
[Android Software Development] muminrky:
Hi,

Thanks for your support this issue.

I have a problem. I did can unpack my boot.img. But I didnt can repack.

Orginal Boot.img memory 9802kb.. New boot.img memory 9794kb. (I didnt edit orjinal boot.img, I repacked orjinal boot.img)

My devices Asus Memopad 8 me181cx k011
[Android Software Development] osm0sis:
You say you can't repack then say the size of the repack is different. What's the actual problem? Does the new image not boot up when flashed?

Upload the untouched boot.img you're trying to work with and I'll take a look. I can't magically help you with the next to nothing you've provided.
[Android Software Development] muminrky:
boot.img

I flashed new boot.img, but Devices dont boot.

You have a point.

I added original boot.img

yadi.sk/d/kQU8Wga0Gmo3Yg

Thanks your answer
[Android Software Development] osm0sis:
Does `repackimg.sh --original` make a working image-new.img for your device? It should.

From what I understand some Intel OSIP devices may not accept changed signed images (since we're not actually resigning them properly), and some others might not accept unsigned or changed images at all. Mileage will definitely vary on these devices.

You could try deleting *-sig from split_img then `repackimg.sh --original`, if that works try with deleting *-sig and `repackimg.sh` with no changes, and then if that works then try changing something. Good luck!
[Android Software Development] muminrky:
I tried your advice. And SUCCESS.

Thank you for support.

ASUS MEMOPET K011 ME181CX - after charge device plug in, boot

1-Remove the following from init.rc

service charger /charger

class charger

group log

seclabel u:r:healthd:s0

2-Write the following in init.rc

on property:ro.bootmode=charger

class_start sec-charger

service playlpm /system/bin/reboot

class sec-charger

critical
[Android Software Development] ipdev:
I stumbled into an error repacking a boot image the other night.

I was tired and copied the wrong boot image to my AIK directory.

Generating MTK headers...

Using ramdisk type: rootfs

Building image...

Using format: AOSP

Signing new image...

Using signature: AVB boot

Error!

Tonight I had some time to test, so I grabbed one of the older boot images I had for that device and gave it a test.

The boot image is dd partition copy/dump but, I was able to unpack and repack it before on macOS without error.

Straight up test. Just unpack and repack, no modifications.

AIK-Linux on linux worked.

AIK-Mobile worked.

AIK-Linux on macOS gave error.

AIK for Windows gave error.

Tested on:

Laptop (Primarily macOS - Windows only when needed.)

Dual boot macOS 10.13.6 High Sierra and Windows 7 Pro

Desktop (Now primarily linux - macOS only when needed.)

Dual boot macOS 10.13.6 High Sierra and Linux Mint 19.1 Cinnamon

Android (Nexus 7 2013 WiFI)

Unofficial AEX - Pie

Boot image a shell text are uploaded here. gDrive - Link

Might just be a user error.

Normally the obvious hides quite well from me. :o

If anyone can double check, unpacking and repacking the linked boot image on macOS or Windows, please let me know.

Thank you.

Cheers. :)
[Android Software Development] osm0sis:
I just tried your .img on my Windows PC and it re-signed fine, and when I was doing regression testing on macOS and Linux I definitely unpacked and repacked a few AVBv1 signed images without issue.

Are you sure Java is installed and up to date on the platforms you are seeing the issue on in your household? It needs to be correctly in the %PATH% in Windows, and it uses the /Library/Internet Plug-Ins/JavaAppletPlugin on macOS (since it's more likely to be up to date than the included system one). In all desktop platform cases it needs to be JRE 8 or higher.
[Android Software Development] HemanthJabalpuri:
[MENTION=4544860]osm0sis[/MENTION]

my friend has a device called Meizu Mx4 pro https://github.com/meizuosc/m462

There is no ramdisk in boot.img...!

There are two partitions in by-name kernel and ramdisk but none of them have ramdisk....
[Android Software Development] osm0sis:
Ooh a more recent U-Boot device. Interesting!

The kernel partition dump looks like raw uncompressed kernel. The ramdisk partition is U-Boot but only containing ramdisk, which I haven't seen on Android before.

AIK assumes a single part U-Boot only has a zImage/Image.gz (kernel), so I'll have to add detection for this setup for AIK 3.6. :good:

As is it splits out the ramdisk, just incorrectly names it -zImage and doesn't know to unpack it. Looks like gzip ramdisk, so you could unpack that yourself pretty easily if you need.

Edit: For now, here are the needed changes for AIK-mobile to support U-Boot RAMDisk images.

In unpackimg.sh change:

if [ "$(cat "$file-type")" == "Multi" ]; then
$bin/dumpimage -p 1 -o "$file-ramdisk.cpio.gz" "$img";
else
touch "$file-ramdisk.cpio.gz";
fi;

To:

case $(cat "$file-type") in
Multi) $bin/dumpimage -p 1 -o "$file-ramdisk.cpio.gz" "$img";;
RAMDisk) $bb mv -f "$file-zImage" "$file-ramdisk.cpio.gz";;
*) touch "$file-ramdisk.cpio.gz";;
esac;

In repackimg.sh change:

if [ "$imgtype" != "KRNL" ]; then

To:

if [ "$imgtype" != "KRNL" -a -f *-zImage ]; then

And change:

U-Boot)
test "$type" == "Multi" && uramdisk=(:"$ramdisk");
$bin/mkimage -A $arch -O $os -T $type -C $comp -a $addr -e $ep -n "$name" -d "$kernel""${uramdisk[@]}" $outname >/dev/null;
;;

To:

U-Boot)
part0="$kernel";
case $type in
Multi) part1=(:"$ramdisk");;
RAMDisk) part0="$ramdisk";;
esac;
$bin/mkimage -A $arch -O $os -T $type -C $comp -a $addr -e $ep -n "$name" -d "$part0""${part1[@]}" $outname >/dev/null;
;;
[Android Software Development] ipdev:
It was a problem with java for me. I checked this afternoon when I got home.

After testing a few things in macOS (on my laptop) and making the problem worse.

I rebooted my laptop into Windows and found I never installed java. (?)

Installed java and AIK for Windows worked perfectly.

So back to figuring out my macOS issues.

laptop is running java 11 when booted into macOS.

bash-3.2# java -version

java version "11.0.1" 2018-10-16 LTS

Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)

Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)

After trying a few more things and walking away a few times.

After rereading your message again, I realized what I could do to find out.

Small addition to repack.sh

rm -rf split_img/.temp;

##

java -verbose

##

if [ -f split_img/*-sigtype ]; then

Building image...

Using format: AOSP

./repackimg.sh: line 30: /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java: No such file or directory
Signing new image...

Using signature: AVB boot

Error!
bash-3.2#

BINGO!!!!!!

Then it all came together. I just simply comment out that line, and I get.

Signing new image...

Using signature: AVB boot

Done!

Actually I got the whole works after the script hit the java -verbose line. Including java --help. Probably should have sent -verbose to a file instead.

My setup, java is in /Library/Java

/Library/Java/JavaVirtualMachines/

total 0

drwxr-xr-x 5 root wheel 160 Oct 27 2018 .

drwxr-xr-x 4 root wheel 128 Dec 1 2017 ..

drwxr-xr-x 3 root wheel 96 Oct 27 2018 jdk-11.0.1.jdk

drwxr-xr-x 3 root wheel 96 Dec 1 2017 jdk-9.0.1.jdk

drwxr-xr-x 3 root wheel 96 Jul 9 2018 jdk1.8.0_171.jdk

/Library/Internet\ Plug-Ins/

total 0

drwxr-xr-x 4 root wheel 128 Oct 27 2018 .

drwxr-xr-x+ 62 root wheel 1984 Nov 25 14:44 ..

drwxr-xr-x 4 root wheel 128 Jul 20 2017 Disabled Plug-Ins

drwxrwxrwx 3 ip staff 96 Jan 18 2016 WebVideoPlugin.plugin

I haven't checked macOS on my desktop yet but since it's a very basic install, I assume I never updated java. If I did, I probably installed it the same as my laptop.

Thank you for helping me figure it out. :D

Cheers.
[Android Software Development] osm0sis:
So you need to install the Java JRE web plugin. By commenting it out your final image isn't properly signed. ;)
[Android Software Development] ipdev:
:confused:

Actually for me it seemed to work fine.

Not saying it will work or should be done by other users.

My setup is usually different than most so, I got use to adapting things to make it work.

For me java is installed in a different directory and is available when called in shell.

So setting java to a specific directory in the repack script that I did not have, is what was breaking it for me on macOS.

Installing another/different version into /Library/Internet Plug-Ins/ may crate another headache down the road.

I suppose I could use a symlink.

I uploaded the repacked images along with java-verbose.txt gDrive - Link

If you have a little extra spare time, can you check and see if the repacked signed boot image looks correct?

Thank you.

PS.

I forgot the -verbose option displays everything including --help.

I should not have mentioned it in my last post. :o

I added java -verbose >java-verbose.txt to top of the repack script.
[Android Software Development] osm0sis:
Ah you must have commented out where it gets set to use the plugin version, and your system version happens to be current enough; It is indeed signed correctly!

The system version is usually what comes with macOS, but I suppose could also be what is installed from the JDK, which most won't have. The plugin is what most people will have since it's what you would get from the Oracle website as the JRE for macOS, so really you should have it too. :p

Java 8 Update 211 is the current release as of April 16, 2019.

Anyway. Definitely a peculiarity in your setup. Glad you got it working! Not sure if there's anything to be done on my side... I guess I could try to add a version check and use the system one by default if it's current enough to work.

Maybe a dependency check for Java but I have made a point of avoiding those thus far, so I don't think I'll start.
[Android Software Development] HemanthJabalpuri:
Done and working...

Does Magisk supports U-Boot unpacking...?

Since when flashing magisk it quits with error "Unsupported/Unknown image format"
[Android Software Development] osm0sis:
Haha no, no. The mkimage and dumpimage U-Boot utils are a nightmare to cross-compile so only I do. Open an issue on the Magisk GitHub and include your kernel and ramdisk partition dumps for topjohnwu to maybe take a look at adding support. In the meantime you could probably manually root it using AIK-mobile.
[Android Software Development] martyfender:
It looks like [MENTION=4470081]topjohnwu[/MENTION] rejected supporting this device under issues on his github site:

I don't own one of these devices, but can you think of any good reason a manufacturer would do something like this? From my view it appears to be pretty stupid on their part, or are they just trying to be different and difficult, for no good reason?
[Android Software Development] osm0sis:
Pretty much. It's obstructionist. I've only seen 2 examples of devices that use U-Boot. The LG Optimus 3D from 2011 (using full U-Boot Multi-part for kernel and ramdisk in one partition), and now this Meizu MX4 Pro from 2014 (using U-Boot for separate boot and recovery ramdisk-only partitions, like a weird Huawei Treble-like setup). There doesn't seem to be any real good reason for it.

I Magisk-patched his ramdisk partition dump for fun, but it doesn't actually sound like it can be used though, since the device is apparently locked down tight: https://xdaforums.com/android/help/flashing-ramdisk-using-dd-locked-t3925945

Edit: ..Or not? I guess they've got SuperSU somehow.
[Android Software Development] osm0sis:
So I looked into it on my fiancee's MacBook Pro (2011) which is running untouched High Sierra and it's a very different setup from yours.

`which -a java` shows only /usr/bin/java

`ls -al /usr/bin/java` shows it's a symlink of /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java

`java -version` shows java version "1.7.0_09" (so Java 7)

`ls /Library/Java/JavaVirtualMachines/` shows only jdk1.7.0_09.jdk

`/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java -version` shows java version "1.8.0_181" (so Java 8)

I have no idea what "jdk-9" or "jdk-11" are on your setup, or why they take precedence. Are they some preview versions or something you've installed in addition to the default system one? Official release is only Java 8, and the versioning scheme is still 1.x.0 where x is the Java #.

Edit: Okay, [MENTION=7280276]ipdev[/MENTION], try this out for me.

In repackimg.sh change:

java() { "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java" "$@"; }
lzop() { DYLD_LIBRARY_PATH="$bin/$arch" "$bin/$arch/lzop" "$@"; }
xz() { DYLD_LIBRARY_PATH="$bin/$arch" "$bin/$arch/xz" "$@"; }

To:

lzop() { DYLD_LIBRARY_PATH="$bin/$arch" "$bin/$arch/lzop" "$@"; }
xz() { DYLD_LIBRARY_PATH="$bin/$arch" "$bin/$arch/xz" "$@"; }

javaver=$(java -version 2>&1 | head -n1 | cut -d\" -f2);
javamaj=$(echo $javaver | cut -d. -f1);
javamin=$(echo $javaver | cut -d. -f2);
if [ "$javamaj" -lt 9 ] && [ "$javamaj" -eq 1 -a "$javamin" -lt 8 ]; then
java() { "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java" "$@"; }
fi;
[Android Software Development] ipdev:
Sorry for the delay.

I got home a little late. Then got sidetracked by trying to figure out my java setup.

The edit/change worked just fine.

Tested on my laptop with the boot.img and 2 recovery images. All seemed to repack fine. Just to be safe, I also tried the edited repack.sh in linux on my desktop, no problem there either. - I know it should not have made a difference but, it's always good to double check.

I did switch to using the JDK builds for some reason. Link

I was probably trying something, or maybe still have something installed that needed it.

I double checked and I have the same here.

/usr/bin/java

/usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java

I still have to look into my configuration and settings some more.

I'm not sure/remember where or when this gets set or overridden on macOS.

Maybe it's time I clean flash my laptop. :)

I have a late 2010 MacBook Air, been meaning to clean it up for awhile.

Sorry again for the delay. I didn't realize I got sidetracked for three hours. :o

Thank you again for looking into this. :D

Edit:

Part of my configuration that was confusing me.

mb:ip ip$ which java
/usr/bin/java
mb:ip ip$ ls -la /usr/bin/java
lrwxr-xr-x 1 root wheel 74 Nov 30 2017 /usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
mb:ip ip$
mb:ip ip$ java --version
java 9.0.1
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)
mb:ip ip$
mb:ip ip$ sudo which java
Password:
/usr/bin/java
mb:ip ip$ sudo ls -la /usr/bin/java
lrwxr-xr-x 1 root wheel 74 Nov 30 2017 /usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
mb:ip ip$ sudo java --version
java 11.0.1 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)
mb:ip ip$
[Android Software Development] ahhl:
i tried on S4 and it works. now i want to try on Redmi6a. how to know whether the repack work. beside flashing back stock img.
[Android Software Development] osm0sis:
:confused:

... If it boots it works. You could add a small change, like create an empty file named "test" in the ramdisk which you can then check for while booted, if you for some reason need further confirmation.