yashsingh1/xdaforums huggingface dataset:
[Android Software/Hacking General [Developers Only]] HemanthJabalpuri:
I made my own simple and small signapk mod which can used to sign only with test keys and faster than zipsigner.

https://xdaforums.com/t/app-android-no-pc-sign-apk-zip-within-android.3835975/post-81324327

GitHub - omni-ten/android_packages_apps_OpenDelta: OpenDelta was written to provide automatic OTA updates for The OmniROM Project's nightly builds, making use of deltas when possible, to reduce the size of the download.

OpenDelta was written to provide automatic OTA updates for The OmniROM Project's nightly builds, making use of deltas when possible, to reduce the size of the download. - omni-ten/android_packa...

github.com

The source used to build signapk.jar in 2nd post Linux and Windows tools is https://android.googlesource.com/pl...2025cbe69649b426b5/tools/signapk/SignApk.java
[Android Software/Hacking General [Developers Only]] Nikhil:
Hi [MENTION=4544860]osm0sis[/MENTION],

I am working on building a package of apps using my tool.

The same package created with aroma installer works just fine. but the package which is created as a normal installer (without aroma) doesn't work.

while executing

package_extract_file "customize/gapps_91/Project_My Apps/Type_system_priv_app/Group_Priv Apps/Folder_Phonesky/Phonesky.apk" "/system/priv-app/Phonesky/Phonesky.apk"

i get below error in log.

unzip: short read

the same command works when I use with aroma installer.

Any Idea, why this could be happening?

I read this, but it is not making any sense since I am in same network and tried aroma/normal installer at the same time.

The zip file is readable, I am able to extract files and install the apk files manually.

can it be a recovery issue?
[Android Software/Hacking General [Developers Only]] osm0sis:
Hmm I've seen that before but I don't recall what the issue was.. maybe the spaces in the file names? Try using busybox unzip to extract manually in recovery.
[Android Software/Hacking General [Developers Only]] FriendlyNeighborhoodShane:
How do you zip the file?
[Android Software/Hacking General [Developers Only]] Nikhil:
I zip it using java commands. This is how.

I can upload the zip file. if you want to take a look at it.

with aroma installer, it works, with normal installation it doesn't. the commands are same in both type of operation. aroma installer just comes with an additional UI (aroma config) that's it.
[Android Software/Hacking General [Developers Only]] FriendlyNeighborhoodShane:
In AROMA, it won't matter how you zip it because the AROMA binary extracts it, but in shell scripting, it is extracted by the recovery unzip, which is quite commonly broken.

And yes, that is probably the cause, because java applets use some weird compression standard which everybody except recoveries can unzip. I've also seen this with the python zipfile module and most android apps.

You should use a proper zipper like info-zip or 7z, or use the ZArchiver app if on android.

---------- Post added at 11:30 AM ---------- Previous post was at 11:25 AM ----------

BTW [MENTION=4544860]osm0sis[/MENTION] did you try the MInstaller?

Any feedback?

I've made a tiny change after the uploaded version, i.e. it no longer seds the xml, just reads the directory from it and installs there (safer, I guess).

Still can't figure out the system app thing.
[Android Software/Hacking General [Developers Only]] osm0sis:
Nah, I took a look at the script but didn't really have a use for it personally.
[Android Software/Hacking General [Developers Only]] HemanthJabalpuri:
[MENTION=4544860]osm0sis[/MENTION]

I want to output the ui_print from the .sh file that is executed with normal updater-script run program command....

I have seen the Chainfire's thread link in op and tried that

#!/sbin/sh
OUTFD=$(ps | grep -v "grep" | grep -o -E "update_binary(.*)" | cut -d " " -f 3);

ui_print() {
if [ $OUTFD != "" ]; then
echo "ui_print ${1} " 1>&$OUTFD;
echo "ui_print " 1>&$OUTFD;
else
echo "${1}";
fi;
}

ui_print "--------------------";

But it is not outputting that in Message area of TWRP...

In recovery.log it shows fine... any error on my side?

or needs an update to that command?

also Where TWRP unzips the zip file of updater-script zip and shell script zip which is not provided the unzip directory by user...?

Also how Custom-Key of opengapps is verifying successfully in TWRP ?

I heard that TWRP only allows test-keys!

Thanks
[Android Software/Hacking General [Developers Only]] RebelLion_:
Is the use of wildcards permitted with set_perm_recursive? For example, if I want to set perms of all system apps i push and their respective folders, can I specify that with "/system/app/*"? Or do I need to write it out for each individual folder?

---------- Post added at 08:18 AM ---------- Previous post was at 07:52 AM ----------

Actually, reading through the functions again I think the nature of the function is that "dir_mode" applies the mode to all directories in the folder specified, and "file_mode" applies to the files within the directories, correct? So I would be okay just doing:

set_perm_recursive 0 0 0755 0644 /system/app/;

Please me correct me if I'm wrong
[Android Software/Hacking General [Developers Only]] _that:
TWRP extracts the update-binary to "updater", see here: https://xdaforums.com/showpost.php?p=51723819&postcount=16

TWRP extracts only update-binary, everything else is up to that program.
[Android Software/Hacking General [Developers Only]] HemanthJabalpuri:
Thanks sir...it is working..

Now we can use all the shell script from that right?

If no.. any other modifications are needed when we place whole shell script in that .sh file?

Another small thing is I tested a shell script

#!/sbin/sh
OUTFD=$2
ZIP=$3
ui_print() {
echo -n -e "ui_print $1\n" > /proc/self/fd/$OUTFD
echo -n -e "ui_print\n" > /proc/self/fd/$OUTFD
}
cd /tmp
unzip -o "$ZIP"
ui_print "Test.."
sh /tmp/script.sh $OUTFD

and that script.sh

#!/sbin/sh
OUTFD=$2$1

ui_print() {
echo -n -e "ui_print $1\n" > /proc/self/fd/$OUTFD
echo -n -e "ui_print\n" > /proc/self/fd/$OUTFD
}

ui_print "--------------------";
touch /sdcard/00test

ui_print from that .sh script is not appearing in TWRP message area..

And recovery.log shows something error(attached)

edit:- @osm0sis

Is there anyway to put 644 permission by default from package_extract_file shell command..?

Since it gives 666 as default...

edit2:- for fix see red colour.
[Android Software/Hacking General [Developers Only]] osm0sis:
That's not really a big deal.. You can just set_perm after, but yeah, super easy, just add chmod 644 "$2"; after the unzip command.
[Android Software/Hacking General [Developers Only]] HemanthJabalpuri:
Like this?

# package_extract_file <file> <destination_file>
package_extract_file() { mkdir -p "$(dirname "$2")"; unzip -o "$ZIPFILE" "$1" -p > "$2"; chmod 644 "$2"; }
[Android Software/Hacking General [Developers Only]] osm0sis:
Yuppers
[Android Software/Hacking General [Developers Only]] HemanthJabalpuri:
Very, very sorry for disturbing again

..

but when tried this without asking you ,,,

my device soft bricked aftet flashing...

# package_extract_dir <dir> <destination_dir>
package_extract_dir() {
local entry outfile;
for entry in $(unzip -l "$ZIPFILE" "$1/*" 2>/dev/null | tail -n+4 | grep -o " $1.*$" | cut -c2-); do
outfile="$(echo "$entry" | sed "s|${1}|${2}|")";
mkdir -p "$(dirname "$outfile")";
unzip -o "$ZIPFILE" "$entry" -p > "$outfile";
[Color="Red"]chmod 644 "$2";[/color]
done;
}

please correct it sir..

I am expecting 755 for dir and 644 for files in it when I extract...
[Android Software/Hacking General [Developers Only]] osm0sis:
In extract_dir it needs to be "$outfile", not "$2", clearly.. you need to read more about shell scripting in general before you go any further.
[Android Software/Hacking General [Developers Only]] alecxs:
I plan to make a flashable zip (first time). I can read and understand the code of your edify replacement functions. What i don't understand is, why edify language is required? This is the point i don't get.

for example, why not just use "echo" instead of "ui_print" - are there any restrictions in custom recovery i better should know about?
[Android Software/Hacking General [Developers Only]] osm0sis:
A lot of it is to make the transition easy. As for ui_print, etc., recovery screen output is different from stdout and stderr, so as you can see from the scripts you have to send specific commands to the recovery output fd to control the recovery display.
[Android Software/Hacking General [Developers Only]] HemanthJabalpuri:
[MENTION=4544860]osm0sis[/MENTION]

How Can i use assert function?

i tried

assert "getprop ro.build.product == serranods";

The actual thing I want to assert is below from edify..

assert(getprop("ro.product.device") == "serranods" || getprop("ro.build.product") == "serranods" ||
getprop("ro.product.device") == "serranodsdd" || getprop("ro.build.product") == "serranodsdd" ||
getprop("ro.product.device") == "serranodsub" || getprop("ro.build.product") == "serranodsub" ||
getprop("ro.product.device") == "serranodsxx" || getprop("ro.build.product") == "serranodsxx" ||
getprop("ro.product.device") == "GT-I9192" || getprop("ro.build.product") == "GT-I9192" ||
abort("This package is for device: serranods, GT-I9192; this device is " + getprop("ro.product.device") + "."););

and also I cant able to understand the logic of below lines from 925vmsettings

# lmk tweaks
minfree=6144,8192,12288,16384,24576,40960;
lmk=/sys/module/lowmemorykiller/parameters/minfree;
minboot=`cat $lmk`;
while sleep 1; do
if [ `cat $lmk` != $minboot ]; then
[ `cat $lmk` != $minfree ] && echo $minfree > $lmk || exit;
fi;
done&

When the above if condition will true?
[Android Software/Hacking General [Developers Only]] osm0sis:
Well in shell we just assert commands, and you can't do a comparison like that between two values.

See the assert function:

# assert "<command>" ["<command2>"]
assert() {
until [ ! "$1" ]; do
$1;
test $? != 0 && abort 'assert failed('"$1"')';
shift;
done;
}

Basically it runs the command and if it fails (exit code is non-zero) then it runs the abort function.

To do the test you want you'd need to do something like

assert 'test "$(getprop ro.build.product)" == "serranods"'

But you could also just cut out the middle man and do simply

test "$(getprop ro.build.product)" == "serranods" || abort "Device check failed!";

Or something. Shell can be far more simple, and more powerful than these functions. These functions are meant more as a way to simplify things for people trying to switch over to shell from edify for their zips, but really the more real shell you can learn to use, the better.

As for your question about my old script, (which probably belongs more in my Odds thread,) LMK doesn't initialize with the normal default values, they get set later. My testing on it is pretty well documented in my Odds thread "Knowledge Base", see the LMK timing link: https://xdaforums.com/showthread.php?p=53554719#post53554719
[Android Software/Hacking General [Developers Only]] HemanthJabalpuri:
Thanks for your quick and clear relpy....

How magisk uses updater-script as shell script?

Is that can be done with the following lines in update-binary?

package_extract_file META-INF/com/google/android/updater-script /tmp/updater-script
chmod 777 /tmp/updater-script
. /tmp/updater-script

also MiXplorer app will work for signing in android for those who dont have pc.. and have older android versions

Also how i can get compressed tar like twrp backups using busybox?

Thanks
[Android Software/Hacking General [Developers Only]] osm0sis:
Magisk is open source, have a look for yourself: https://github.com/topjohnwu/Magisk/blob/master/scripts/update_binary.sh

But there's no need to do this for most purposes, where update-binary can just already be a shell script and is being run.

As for your other questions, `busybox tar --help`

Also, while we're at it: https://en.m.wikipedia.org/wiki/Test_(Unix)

I'm not your excuse to not even try to Google or look up answers for yourself. Please put in some basic effort going forward.
[Android Software/Hacking General [Developers Only]] jcmm11:
Just an FYI.

Latest TWRP (at least on my Pixel 3 XL) no longer uses busybox. They've switched to using toybox. They're also now using the regular Android shell (mksh, Korn shell).

I don't know if they're going to do this with all newer versions or just new devices, although if I'm guessing it'll just be new devices. Just something you may want to be aware of.
[Android Software/Hacking General [Developers Only]] HemanthJabalpuri:
[MENTION=4544860]osm0sis[/MENTION]

When i learning some basic shell scripting through your awesome scripts.. i found the below in your edify replacement script:-

sha1check cut command needs quote for space

cut -d " "
[Android Software/Hacking General [Developers Only]] osm0sis:
Ah thanks! I had it escaped as:

sha1sum $1 | cut -d\ -f1

which works, but unfortunately a long-standing bug with XDA DevDB is that it eats a \ every time you edit the project.

In fact I have to remember to escape the \n in ui_print as \\n with every edit, but I guess I'd forgotten sha1check needed one too.

I've updated the OP with a better/shorter fix, which is to just grab the first 40 characters (the length of a sha1sum):

sha1sum $1 | cut -c-40
[Android Software/Hacking General [Developers Only]] HemanthJabalpuri:
Sir your edify replacement apply_patch_space function requires a correction in LIBRARY_PATH variable..

also executing unpackimg.sh through explorer(MiX in my case) gives error that unexpected & in line 34..

i.e., ampersand after pipe...

a small request is to extend your AIK with simg2img, raw2img, img2simg binaries to extract sparse imgs that are in Samsung firmwares....

I am using simg2img binary of Chainfire to extract sparse img...

And I have doubt is my firmware has NON-HLOS.bin i.e., modem.img....

I am not sure that it is modem.img..

Can I flash that NON-HLOS.bin by renaming it to modem.img?

Thanks
[Android Software/Hacking General [Developers Only]] osm0sis:
You remain in the wrong thread for most of these items. This is ongoing with you, so I will answer only the appropriate questions in the appropriate thread.

If you mean the LD_ was missing, then you're right! Thanks for catching that. Fixed now. :good:
[Android Software/Hacking General [Developers Only]] ale5000:
Hi,

what is the best way to detect the path of the "removable memory" in Android recovery and in booted Android? (I say removable because external is a confusing term inside Android).
[Android Software/Hacking General [Developers Only]] osm0sis:
Tricky. The exact name depends on the vendor/chipset/board I think. Lately most things end up in /mnt or /storage I believe though, so you should be able to find it there.
[Android Software/Hacking General [Developers Only]] alecxs:
figured out that keycheck code is borrowed from system/core/toolbox/getevent.c which means you can use pre-installed /system/bin/toolbox instead. i am currently working on a shell function for getevent, because i want to read KEY_POWER too
[Android Software/Hacking General [Developers Only]] osm0sis:
Interesting! And it still exists in Pie!

:/ $ getevent
could not add watch for /dev/input, Permission denied
1|:/ $ which getevent
/system/bin/getevent
:/ $ su -c ls -al $(which getevent)
lrwxrwxrwx 1 root root 7 1970-01-15 09:32 /system/bin/getevent -> toolbox
:/ $ toolbox
getevent getprop newfs_msdos toolbox
:/ $
[Android Software/Hacking General [Developers Only]] alecxs:
in my very first flashable zip there is a full dialog function we can copy for our scripts.

example usage:

get_file "entry 1" "entry 2" "entry 3" "exit"

will print a list

1: entry 1

2: entry 2

3: entry 3

4: exit

we can scroll up or down with Volume keys - it jumps back to top/bottom when reached first/last entry. the selection must confirmed with power key. unfortunately there is no timeout, and it can not detect if screen is on/off.

if someone know how to print escape characters (carriage return, clear screen, etc) this would be very helpful, i know how to do it in shell but not in recovery.

the function readkeys() in the middle is not really needed - i just used it for manipulating the variables from get_file() based on a whitelist (for example if vol_dn key should be ignored, send a whitelist: readkeys vol_up pwr)

get_file() - print the dialog on twrp screen

└─ readkeys() - send a whitelist of keys we want to listening and request a single read

└─ GetKeyEvent() - listening to phone and give back first key pressed (whatever it is)​
[Android Software/Hacking General [Developers Only]] kramer04:
Just one thing trying to understand when using your very nice update-binary or a "normal" update-binary is about command echo

using your update-binary and at the end i add just this to it

echo "run script , using echo" >tong.txt
ui_print "run script, using ui_print" >>tong.txt

echo command creates tong.txt as expected with "run script , using echo" inside but doesn't print on screen the text.

i've same issue with other update-binary and i don't understand why .

Very weird for me.

ui_print print on screen text but nothing in tong.txt .

first question why echo doesn't print on screen using your update-binary or any other and how to solve this ?

2nd question, how to do to pass text in my tong.txt using ui_print ?
[Android Software/Hacking General [Developers Only]] osm0sis:
ui_print is specifically for displaying on the recovery's screen. If you want to output something to file use

a regular echo.
[Android Software/Hacking General [Developers Only]] kramer04:
And why echo doesn't displays on recovery's screen even with your update-binary or another one ?

For me it's weird.

I was thinking echo can be read directly and displays on screen
[Android Software/Hacking General [Developers Only]] _that:
Not when stdout is redirected to a file, which is what TWRP does for the updater. It's similar to "script.sh > recovery.log".
[Android Software/Hacking General [Developers Only]] alecxs:
Just add a echo -e "$1" into ui_print() function, this gives you expected behavior
[Android Software/Hacking General [Developers Only]] kramer04:
at the end of update-binary just add this code as i want to test echo and ui_print

ui_print "================="
echo "run script , using echo"
ui_print "run script, using ui_print 1"
ui_print "================="
mount /system
package_extract_dir test tmp

set_perm 0 0 0755 /tmp/test.sh
/tmp/test.sh

and in test.sh this

#!/sbin/sh

echo "hello world !, using echo"
ui_print "run script, using ui_print 2"

from my test.sh file

echo doesn't displays anything but i see in log it works

ui_print give error 127 unknown command

how to displays text with echo ? very simple with linux , but i don't understand how it works in recovery and if we can use it to displays text

ui_print doesn't works if using with an other file sh ?
[Android Software/Hacking General [Developers Only]] jcmm11:
ui_print is an inline subroutine, so yes, you can't just call it from an external script. If you look at the code for ui_print you'll see that it actually uses echo. It writes to /proc/self/fd/1 which is (always) the terminal output for the process.

You could modify it with a tee statement to also write to a file.
[Android Software/Hacking General [Developers Only]] kramer04:
thanks for your answer.

so i modify like this my test.sh

#!/sbin/sh

echo "2 hello world !, using echo" | tee /tmp/tong.txt
echo "hello" | tee -a /tmp/tong.txt
echo "world" | tee -a /tmp/tong.txt
cat /tmp/tong.txt

and log is

Installing zip file '/external_sd/Custom Rom/new-update-binary.zip'
Checking for Digest file...
Skipping Digest check: no Digest file found
I:Update binary zip
Verifying package compatibility...
Package doesn't contain compatibility.zip entry
I:Zip does not contain SELinux file_contexts file in its root.
I:Legacy property environment not used in updater.
1 run script , using echo
=================
run script, using ui_print 1
=================
mount: mounting /dev/block/sda18 on /system failed: Device or resource busy
/tmp/updater: line 231: can't create tmp/: Is a directory
2 hello world !, using echo
hello
world
2 hello world !, using echo
hello
world
I:Updater process ended with RC=0
I:Install took 0 second(s).

So i see echo and cat work because they are in log

but don't display anything on screen

I don't understand that

Could you show me an example how to have echo displays message on screen
[Android Software/Hacking General [Developers Only]] jcmm11:
Like I said look at the code for ui_print

# ui_print "<message>" ["<message 2>" ...]
ui_print() {
until [ ! "$1" ]; do
echo -e "ui_print $1\nui_print" >> $OUTFD;
shift;
done;
}

I'll save you the trouble of figuring out what $OUTFD is. It's /proc/self/sd/1

ui_print already writes to the log as well to the terminal, so if you want to also write to a file try modifying it to something like this:

echo -e "ui_print $1\nui_print" |tee -a $OUTFD >>file.txt

(if that no longer writes to the log just drop the >> )

Note: I haven't tested any of this so you may well have to play around but it should point you in the right direction.
[Android Software/Hacking General [Developers Only]] kramer04:
finally ! after lot of time i found how to do it through a [MENTION=631273]Chainfire[/MENTION] script to display message on recovery screen when using a sh file.

#!/sbin/sh

OUTFD=1
readlink /proc/$$/fd/$OUTFD 2>/dev/null | grep /tmp >/dev/null
if [ "$?" -eq "0" ]; then
# rerouted to log file, we don't want our ui_print commands going there
OUTFD=0

# we are probably running in embedded mode, see if we can find the right fd
# we know the fd is a pipe and that the parent updater may have been started as
# 'update-binary 3 fd zipfile'
for FD in `ls /proc/$$/fd`; do
readlink /proc/$$/fd/$FD 2>/dev/null | grep pipe >/dev/null
if [ "$?" -eq "0" ]; then
ps | grep " 3 $FD " | grep -v grep >/dev/null
if [ "$?" -eq "0" ]; then
OUTFD=$FD
break
fi
fi
done
fi

ui_print() {
echo -n -e "ui_print $1\n" >> /proc/self/fd/$OUTFD
echo -n -e "ui_print\n" >> /proc/self/fd/$OUTFD
}

but I still don't know why echo doesn't display nothing on recovery screen.

Maybe we can't...
[Android Software/Hacking General [Developers Only]] alecxs:
ui_print() is required, you can not use echo unless you announce your message with keyword "ui_print" and redirect it to the right file descriptor - that is what ui_print() function does. its easier to use a function, please change your scripts and always use ui_print() instead of echo. If you don't want to declare ui_print() function in each of your scripts, you can source declarations from updater-binary instead. (See my flashable zip for example, send me pm for help)

echo -e "ui_print Hello World\nui_print" >> /proc/self/fd/1

ui_print "Hello World"

two examples for same result, but in first example you have to specify the right file descriptor (twrp always give it as positional parameter, sou you don't have to search for it)
[Android Software/Hacking General [Developers Only]] jcmm11:
Because 'normal' stdout/stderror output has been redirected to the log.
[Android Software/Hacking General [Developers Only]] HemanthJabalpuri:
[MENTION=4544860]osm0sis[/MENTION]

ln command for multiple links is not working ...(log attached)

symlink() {
local file="$1"
while [ "$2" ]; do
ln -sf "$file" "$2"
shift
done
}

will work....

pacakage_extract_dir needs 2>/dev/null after done of loop else it will show errors(log attached)

also sha1check needs ui_print instead of echo for displaying hash

restore_con() { line has a space at end...

Thanks