yashsingh1/xdaforums huggingface dataset:
[Android Software/Hacking General [Developers Only]] osm0sis:
Well you obviously can't have the same app twice so it cleaned the extra copy up. I'd suggest looking at how Magisk's zip installs the Magisk Manager apk to /data, that should be up to date. SuperSU's would probably work too.
[Android Software/Hacking General [Developers Only]] Nikhil:
I thought I can have the same app twice with different numbers after -. That's the main reason why we have random alphabets in place. To distinguish them. Right?

Also, during Nougat days, I read about it and came to know that the number indicates a user id. So basically if a different user is added to system, he would have -2 for all the apps installed and apps with -1 would belong to original user.

Also, the screenshot was to explain the difference. Even when I don't have the same app installed, it deletes the folder on boot.

I went through the Magisk zip and SuperSU zip and observed that SuperSu pushes apk to system and Magisk pushes it to /data/adb/Magisk and installs it on boot.

I request you to please check Magisk zip once and let me know if my understanding is wrong.

Thank you very much for your time :)
[Android Software/Hacking General [Developers Only]] osm0sis:
Nope. -1 got used for the initial install, then -2 or even -3 would occasionally show up during app updates seemingly to avoid race conditions/conflicts, and -1 (any others, really) would get removed in the process. They don't have anything to do with the user, since the actual package lists for the device and which define the installed packages for each user are under /data/system/.

Anyway, sounds like starting with Oreo Android doesn't allow new APKs to be blindly installed by adding them to /data, which would explain why SuperSU and Magisk both now use `pm install` to handle it during boot.
[Android Software/Hacking General [Developers Only]] jcmm11:
Just use rm -r
[Android Software/Hacking General [Developers Only]] _that:
This is the "shell script as update-binary replacement" thread, which by definition requires busybox anyway.
[Android Software/Hacking General [Developers Only]] jcmm11:
Based on the where you're posting this I assumed you're using this script.

You asked about a flashable zip. That implies TWRP or similar. That already has busybox.

If both of the above are true you don't need run_program, just issue the command.

If you're doing this as a one off you don't even need a flashable zip (unless you're doing it for practice). Just use the built-in TWRP file manager.
[Android Software/Hacking General [Developers Only]] osm0sis:
Uploaded zipsigner-2.2.jar to the 2nd OP, fixing using custom signing keys. Thanks to [MENTION=4470081]topjohnwu[/MENTION] for taking some of his precious little free time away from his mandatory military service to track down, fix the issue and build us the new jar. :)
[Android Software/Hacking General [Developers Only]] FriendlyNeighborhoodShane:
Hey [MENTION=4544860]osm0sis[/MENTION]

Where is the magisk log stored, exactly, while the zip is processing? Something like /tmp/recovery.log, that can be catted at the end of a script into a log directory?

Thanks
[Android Software/Hacking General [Developers Only]] osm0sis:
It isn't automatic but any time a module is installed in Magisk Manager it gives you the option to "Save log". It's under /sdcard/MagiskManager/logs I believe.
[Android Software/Hacking General [Developers Only]] FriendlyNeighborhoodShane:
IK, Isn't there any way to make the script save the log?

Can redirecting STDOUT work?
[Android Software/Hacking General [Developers Only]] osm0sis:
And stderr, sure, but you'd break Magisk Manager's log showing and saving ability.
[Android Software/Hacking General [Developers Only]] Rebel7022:
I just downloaded this, but not sure what it does, will this make my wifi faster combined with ipvanish?
[Android Software/Hacking General [Developers Only]] osm0sis:
No you didn't. No. There aren't really any downloads here. You must be in the wrong thread.
[Android Software/Hacking General [Developers Only]] Ibuprophen:
He must be referring to the 3 downloads that's attached to the OP...

~~~~~~~~~~~~~~~

I DO NOT provide support via PM unless asked/requested by myself. PLEASE keep it in the threads where everyone can share.
[Android Software/Hacking General [Developers Only]] Rebel7022:
?. Sorry.. My question is I downloaded & installed the

DNS crypt -proxy 2 magisk module. I tried to find out what the benefits of this magisk module is, but I never could figure out what it does. Could you please give me a quick description of the benefits of this module. I really want to know.
[Android Software/Hacking General [Developers Only]] osm0sis:
Didn't make sense within the context of the question. A suspicion confirmed by his follow-up post; he didn't download what he thought he did here. ;)

That module has absolutely nothing to do with this thread. I didn't create it nor have I ever even heard of it. Go find the correct thread and post your questions there. :good:
[Android Software/Hacking General [Developers Only]] Ibuprophen:
I saw the response afterwards and I ASSumed wrong My Friend... LMAO! :eek:

~~~~~~~~~~~~~~~

I DO NOT provide support via PM unless asked/requested by myself. PLEASE keep it in the threads where everyone can share.
[Android Software/Hacking General [Developers Only]] Razor2:
[MENTION=4544860]osm0sis[/MENTION] Whats the correct way to use the function set_metadata in a shell script. An example would be nice.

Im using like this:

set_metadata "$dir$file" uid 0 gid 0 mode 0644 ... ;

But the script gets stuck here , no error msg or anything. I have to force reboot using power button.

Edit:

Not using updater-script, update-binary is the script

Also tried like this:

set_metadata "$dir$file" "uid 0 gid 0 mode 0644 ...";

This time script didn't get stuck but the metadata wasn't applied.
[Android Software/Hacking General [Developers Only]] osm0sis:
I think the issue might be that the function itself uses $file and you're trying to use that as well. I'll take a look at rewriting them all with local variables to be proper when I have some time. :good:

The correct format is as you had it first:

set_metadata "<file>" uid 0 gid 0 mode 644;

etc.
[Android Software/Hacking General [Developers Only]] Millan.SIS:
osm0sis you should check in func set_metadata and setmeta..recurs :

twrp setcap $2 "$file"

It should be:

twrp setcap "$file" $2
[Android Software/Hacking General [Developers Only]] Razor2:
checked the script thoroughly, changed the file variable, but no use, same problem. Meanwhile switched to updatebinary. Will wait for ur fixes, thx
[Android Software/Hacking General [Developers Only]] FriendlyNeighborhoodShane:
Try adding -x to your shebang

Like, change the first line of the script from

#!/sbin/sh

to

#!/sbin/sh -x

And get recovery logs.

That might shed more light on the problem'
[Android Software/Hacking General [Developers Only]] osm0sis:
OP updated with these fixes. All are local variables now within the functions so shouldn't have any effect on any variables used within the greater script, thanks [MENTION=4695508]Razor2[/MENTION] for the reminder I needed to fix that. Thanks [MENTION=4554340]Millan.SIS[/MENTION] for the setcap syntax fix, since it wasn't present in TWRP at the original time of my writing so I had based it on what I was told at the time. :highfive:

Last, I updated is_mounted to use grep instead of case since I recently discovered case can become overwhelmed if the list is too long (most notably when run booted with Magisk since all the bind mounts from Magisk makes for a gargantuan mount output). :good:
[Android Software/Hacking General [Developers Only]] _that:
By the way, also remember this limitation for twrp setcap (focus was on small code, not on usability):
[Android Software/Hacking General [Developers Only]] osm0sis:
I saw that. The original edify accepted hex like 0x0, so that's the same syntax and should be easily intuited by anyone using the script methinks. :)
[Android Software/Hacking General [Developers Only]] ale5000:
Hi,

is there the minified version of zipsigner 2.2?
[Android Software/Hacking General [Developers Only]] osm0sis:
[MENTION=4470081]topjohnwu[/MENTION] told me ProGuarding it breaks encryption formats other than the one used by the included standard testkeys, so best to leave it as the full version.
[Android Software/Hacking General [Developers Only]] ale5000:
Is it possible from a shell script to replace/remove a text already written with ui_print() or alternatively clear all written text?
[Android Software/Hacking General [Developers Only]] jcmm11:
If you're asking what I think you are try the "clear" command. That should clear everything in the current terminal. Not sure what it would do for the running display in TWRP since that's not really an active terminal.

You could print a bunch of blank lines to push existing content off the top of the display.
[Android Software/Hacking General [Developers Only]] ale5000:
Yes, but if every device have a different screen size how much blank lines I have to push?

Is there a way to detect this?
[Android Software/Hacking General [Developers Only]] osm0sis:
resize; then using $LINES should work.
[Android Software/Hacking General [Developers Only]] FriendlyNeighborhoodShane:
[MENTION=4544860]osm0sis[/MENTION],

Which part of your scipt makes it support A/B devices exactly?

Thanks.
[Android Software/Hacking General [Developers Only]] osm0sis:
Hmm? Nothing. You make it work for A/B by understanding how the filesystem works after you mount /system in recovery, if that's what you need.
[Android Software/Hacking General [Developers Only]] FriendlyNeighborhoodShane:
So your current mounting code will work for those devices, right?
[Android Software/Hacking General [Developers Only]] osm0sis:
# mount <partition> exists in shell

What mounting code? Please review the OP.

That said, yeah, busybox mount present in recovery can mount A/B just the same as as any other device.
[Android Software/Hacking General [Developers Only]] FriendlyNeighborhoodShane:
I was actually referring to the mounting snippet in your installer zips, sorry if I wasn't being clear...

if [ ! "$system" ]; then
suimg=$(ls /data/$adb/magisk_merge.img || ls /data/su.img || ls /cache/su.img || ls /data/$adb/magisk.img || ls /cache/magisk.img) 2>/dev/null;
mnt=$devtmp/$(basename $suimg .img);
fi;
if [ "$suimg" ]; then
umount $mnt;
test ! -e $mnt && mkdir -p $mnt;
mount -t ext4 -o rw,noatime $suimg $mnt;
for i in 0 1 2 3 4 5 6 7; do
test "$(mount | grep " $mnt ")" && break;
loop=/dev/block/loop$i;
if [ ! -f "$loop" -o ! -b "$loop" ]; then
mknod $loop b 7 $i;
fi;
losetup $loop $suimg && mount -t ext4 -o loop,noatime $loop $mnt;
done;
case $mnt in
*/magisk*) magisk=/$modname/system;;
esac;
if [ -d "$mnt$magisk/xbin" -o "$magisk" -a -d "$root/system/xbin" ]; then
target=$mnt$magisk/xbin;
else
target=$mnt$magisk/bin;
fi;
else
# SuperSU BINDSBIN support
mnt=$(dirname `find /data -name supersu_is_here | head -n1`);
if [ -e "$mnt" -a ! "$system" ]; then
target=$mnt/xbin;
else
mount -o rw,remount /system;
mount /system;
if -d [ "$root/system/xbin" ]; then
target=$root/system/xbin;
else
target=$root/system/bin;
fi;
fi;
fi;
[Android Software/Hacking General [Developers Only]] osm0sis:
Ah, thanks for clarifying. That has nothing to do with A/B /system mounts because that's all about systemless root mounting, which is on /data in a su.img, magisk.img and BINDSBIN SuperSU.

Edit: At the very end there, it uses $root when falling back to a /system target, and root=/system is set earlier in the script when /system/system/build.prop is found. So that handles system-as-root, but that's different from A/B of course.
[Android Software/Hacking General [Developers Only]] osm0sis:
I dexed it but it doesn't work. Android is likely missing some important Java stuff:

dalvikvm -Xbootclasspath:/system/framework/core-oj.jar:/system/framework/core-libart.jar:/system/framework/conscrypt.jar:/system/framework/bouncycastle.jar -Xnodex2oat -Xnoimage-dex2oat -cp zipsigner-3.0-dexed.jar test.zip test-signed.zip
Exception in thread "main" java.io.IOException: No such file or directory
at java.io.UnixFileSystem.createFileExclusively0(Native Method)
at java.io.UnixFileSystem.createFileExclusively(UnixFileSystem.java:281)
at java.io.File.createTempFile(File.java:2386)
at java.io.File.createTempFile(File.java:2432)
at com.topjohnwu.utils.SignAPK.sign(SignAPK.java:97)
at com.topjohnwu.utils.SignAPK.sign(SignAPK.java:82)
at com.topjohnwu.utils.SignAPK.sign(SignAPK.java:74)
at com.topjohnwu.utils.ZipSigner.main(ZipSigner.java:28)

I let [MENTION=4470081]topjohnwu[/MENTION] know, but not sure if he'll bother fixing it for Android use.

Edit: Ahh, figured it out, it's looking for /tmp, which booted Android doesn't have. I did `mount -o rw,remount -t auto /` and `mkdir /tmp` and then it executed perfectly for me. I'll pass this on to John as well to see if he can smooth out the issue. :)

It should definitely work in recovery with /system mounted so Dalvik can execute or as root, booted, with /tmp created and mounted rw as above.. at least on Oreo, since I know there were some things like Java IO File fixed.

Here it is if anyone wants to play around with it in the meantime.

[ Attachment removed since it's now in the OPs ]
[Android Software/Hacking General [Developers Only]] HemanthJabalpuri:
Sir I am a noob .....

How to use that .jar file sir?
[Android Software/Hacking General [Developers Only]] osm0sis:
The terminal command is in the post along with an explanation of the setup commands required...

Good news is I just worked out a workaround so that it doesn't need to be a root prompt while booted even.

Here's the only command now needed to run when booted:

dalvikvm -Djava.io.tmpdir=. -Xnodex2oat -Xnoimage-dex2oat -cp zipsigner-3.0-dexed.jar com.topjohnwu.utils.ZipSigner test.zip test-signed.zip

To run from recovery of course /system will just need to be mounted so dalvikvm can be executed.
[Android Software/Hacking General [Developers Only]] HemanthJabalpuri:
Sir I cant understand sir....

Sir is there any way to sign the zip by flashing zip file?
[Android Software/Hacking General [Developers Only]] osm0sis:
You want to flash a zip to sign a zip? Yeah you could, but that's ridiculous. Learn to use the command prompt.
[Android Software/Hacking General [Developers Only]] HemanthJabalpuri:
Sir I used the 1st post command in Terminal emulator app by putting zip*.jar and test.zip in /sdcard.....

It shows failed to initialize run time....
[Android Software/Hacking General [Developers Only]] osm0sis:
The new zipsigner-3.0.jar and zipsigner-3.0-dexed.jar are up.

Instructions are now added to the zip signing post in the OPs. Make sure you're using the latest command. Also, you're not posting logs or output or anything so I'm not sure how you expect anyone to help you.
[Android Software/Hacking General [Developers Only]] HemanthJabalpuri:
sir the output is

ZipSigner build.zip build-signed.zip <
Unrecognized option '-Xnodex2oat'

dalvikvm: [options] class [argument ...]
dalvikvm: [options] -jar file.jar [argument ...]

The following standard options are recognized:
-classpath classpath
-Dproperty=value
-verbose:tag ('gc', 'jni', or 'class')
-ea[:<package name>... |:<class name>]
-da[:<package name>... |:<class name>]
(-enableassertions, -disableassertions)
-esa
-dsa
(-enablesystemassertions, -disablesystemassertions)
-showversion
-help

The following extended options are recognized:
-Xrunjdwp:<options>
-Xbootclasspath:bootclasspath
-Xcheck:tag (e.g. 'jni')
-XmsN (min heap, must be multiple of 1K, >= 1MB)
-XmxN (max heap, must be multiple of 1K, >= 2MB)
-XssN (stack size, >= 1KB, <= 256KB)
-Xverify:{none,remote,all}
-Xrs
-Xint (extended to accept ':portable', ':fast' and ':jit')

These are unique to Dalvik:
-Xzygote
-Xdexopt:{none,verified,all,full}
-Xnoquithandler
-Xjniopts:{warnonly,forcecopy}
-Xjnitrace:substring (eg NativeClass or nativeMethod)
-Xstacktracefile:<filename>
-Xgc:[no]precise
-Xgc:[no]preverify
-Xgc:[no]postverify
-Xgc:[no]concurrent
-Xgc:[no]verifycardtable
-XX:+DisableExplicitGC
-X[no]genregmap
-Xverifyopt:[no]checkmon
-Xcheckdexsum
-Xincludeselectedop
-Xjitop:hexopvalue[-endvalue][,hexopvalue[-endvalue]]*
-Xincludeselectedmethod
-Xjitthreshold:decimalvalue
-Xjitcodecachesize:decimalvalueofkbytes
-Xjitblocking
-Xjitmethod:signature[,signature]* (eg Ljava/lang/String\;replace)
-Xjitclass:classname[,classname]*
-Xjitoffset:offset[,offset]
-Xjitconfig:filename
-Xjitcheckcg
-Xjitverbose
-Xjitprofile
-Xjitdisableopt
-Xjitsuspendpoll

Configured with: debugger profiler hprof jit(armv7-a-neon) smp show_exception=1

Failed to initialize runtime (check log for details)
1|u0_a45@serranods:/ $
[Android Software/Hacking General [Developers Only]] osm0sis:
You can try it without -Xnodex2oat, but it's not looking good for you; KitKat's DalvikVM is likely too old.
[Android Software/Hacking General [Developers Only]] HemanthJabalpuri:
Sir ok...i will try in 6.0 and report it sir....

Sir is my placing of files correct? i.e., in /sdcard/zip*.jar and /sdcard/build.zip?
[Android Software/Hacking General [Developers Only]] osm0sis:
Yeah, doesn't matter where it is now.

I also just tested it on my Galaxy Nexus running Marshmallow and it worked perfectly. :good:
[Android Software/Hacking General [Developers Only]] HemanthJabalpuri:
Sir I tested on cm13.... the result is

opjohnwu.utils.ZipSigner build.zip build-signed.zip <
Unable to locate class 'com/topjohnwu/utils/ZipSigner'
java.lang.ClassNotFoundException: Didn't find class "com.topjohnwu.utils.ZipSigner" on path: DexPathList[[],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
Suppressed: java.lang.ClassNotFoundException: com.topjohnwu.utils.ZipSigner
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 1 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace availablejava.lang.ClassNotFoundException: Didn't find class "com.topjohnwu.utils.ZipSigner" on path: DexPathList[[],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
Suppressed: java.lang.ClassNotFoundException: com.topjohnwu.utils.ZipSigner
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 1 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available1|u0_a61@serranodsdd:/ $
[Android Software/Hacking General [Developers Only]] osm0sis:
What's the full command you used? That looks like the output when you aren't using the dexed jar.
[Android Software/Hacking General [Developers Only]] HemanthJabalpuri:
I used the command that is in 2nd post.....

dalvikvm -Djava.io.tmpdir=. -Xnodex2oat -Xnoimage-dex2oat -cp zipsigner-3.0-dexed.jar com.topjohnwu.utils.ZipSigner build.zip build-signed.zip

I dont have the non - dexed jar file

I placed the zip-signer-3.0-dexed.jar in /sdcard...

Since the command is copied and pasted, it shows only end of the command.....
[Android Software/Hacking General [Developers Only]] osm0sis:
You realize you have to be in the same directory as the jar and the zip right?
[Android Software/Hacking General [Developers Only]] HemanthJabalpuri:
Yes sir... both are in same direcotory
[Android Software/Hacking General [Developers Only]] osm0sis:
No. YOU aren't in the right directory when you run the command. There aren't paths on the filenames in the command so unless you're in the same directory of course it can't find things. :rolleyes:

I've been running it in my tests from /sdcard/Download, so when I start Terminal Emulator I first type `cd /sdcard/Download` first, then I run that dalvikvm command.
[Android Software/Hacking General [Developers Only]] HemanthJabalpuri:
Sorry for Noob things... sir... First time i am using the commands...

I successfully signed the zip with your method....in cm13

the signature in twrp also verified successfully..

The process is:- First copy the dexed.jar and file to be signed and renamed to build.zip to /sdcard/Download folder and then open with any terminal app....

then the commands are

cd /sdcard/Download (then hit enter)
dalvikvm -Djava.io.tmpdir=. -Xnodex2oat -Xnoimage-dex2oat -cp zipsigner-3.0-dexed.jar com.topjohnwu.utils.ZipSigner build.zip build-signed.zip

after sometime it will placed signed build.zip depending on the size of the file to be signed....

Thanks for your support and clarifying my noob questions sir...

Note:- in my case signing 469mb took 50mins....
[Android Software/Hacking General [Developers Only]] osm0sis:
Yes the time it takes is only limited by the amount of memory and speed of the device you signed it on. Your SignAPK-based apps wouldn't have been able to sign a 469mb zip at all due to the memory constraint.

If someone wants to adapt it into an app it'll likely work on KitKat as well, though I don't believe you tried all my instructions to see if it was possible to get it working there. Anyway, if you want it in an app then you should get in touch with the authors of those apps and tell them about zipsigner. It's better than SignAPK in pretty much every way.
[Android Software/Hacking General [Developers Only]] HemanthJabalpuri:
Sir I have done all the process that above i posted....in kitkat too but fails...

The process is

copy the dexed.jar and file to be signed and renamed to build.zip to /sdcard/Download folder and then open with any terminal app....

then the commands are

cd /sdcard/Download (then hit enter)
dalvikvm -Djava.io.tmpdir=. -Xnodex2oat -Xnoimage-dex2oat -cp zipsigner-3.0-dexed.jar com.topjohnwu.utils.ZipSigner build.zip build-signed.zip
[Android Software/Hacking General [Developers Only]] osm0sis:
And I told you to try it without -Xnodex2oat
[Android Software/Hacking General [Developers Only]] HemanthJabalpuri:
Yes sir.. i tried but same result as when typing with that....
[Android Software/Hacking General [Developers Only]] osm0sis:
Can't be the same result because your result was about -Xnodex2oat, which is no longer there if you did it right.

Anyway, forget it. It's extremely tedious trying to get useful information out of you so that I can try to help you with your issues...
[Android Software/Hacking General [Developers Only]] osm0sis:
So remove -Xnoimage-dex2oat too!
[Android Software/Hacking General [Developers Only]] osm0sis:
Okay, so it's unable to read the dex file for some reason. That's pretty definitive, so sounds like the jar method won't work on KitKat or at least I don't know how to fix it. Thanks for helping to clear that up.
[Android Software/Hacking General [Developers Only]] HemanthJabalpuri:
Sir dont take my report as final one....

Since my device is very weird one...

It cant boot all custom roms that are made for my device...

It cant boot into stock recovery mode....

And many issues....

Thanks for helping sir....
[Android Software/Hacking General [Developers Only]] HemanthJabalpuri:
Sir I tested zipsigner-3.0-dexed in aicp-10 running on 5.1.1 .....

It works same as it works in 6.0....

Thanks sir