yashsingh1/xdaforums huggingface dataset:
[Android Software/Hacking General [Developers Only]] osm0sis:
symlink(): thanks for finding that, you're right, it was an oversight, from confusion with ln's help back when I wrote this. Here's toybox and busybox currently:

:/ $ ln --help
usage: ln [-sfnv] [FROM...] TO

Create a link between FROM and TO.
With only one argument, create link in current directory.

-s Create a symbolic link
-f Force the creation of the link, even if TO already exists
-n Symlink at destination treated as file
-v Verbose

:/ $ busybox ln --help
BusyBox v1.30.1-osm0sis (2019-02-28 18:48:08 AST) multi-call binary.

Usage: ln [OPTIONS] TARGET... LINK|DIR

Create a link LINK or DIR/TARGET to the specified TARGET(s)

-s Make symlinks instead of hardlinks
-f Remove existing destinations
-n Don't dereference symlinks - treat like normal file -b Make a backup of the target (if exists) before link operation
-S suf Use suffix instead of ~ when making backup files
-T 2nd arg must be a DIR
-v Verbose
:/ $

So these actually work differently for any longer lists, with toybox wanting an output dir to dump them to and busybox appearing to daisy-chain the given targets together.

For the desired syntax of `symlink <file/dir> <link> [<link2> ...]` your version looks like it should work great! I'll add it to the OP.

package_extract_dir(): from a quick few tests to refresh myself it's coming from `unzip -l` listing directory entries as well as files, so, since we would ideally still like to know if there are any legitimate errors from unzip, the better solution to cleaner output (which I didn't care about at the time since it was just the recovery.log) is to filter out those entries from the list:

# 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 -v '/$' | grep -o " $1.*$" | cut -c2-); do
outfile="$(echo "$entry" | sed "s|${1}|${2}|")";
mkdir -p "$(dirname "$outfile")";
test ! -d "$outfile" && unzip -o "$ZIPFILE" "$entry" -p > "$outfile";
done;
}

I'll update it in the OP.

sha1check(): is not about ui_print, it's about output that can be used in an if statement or something (just as it was in EDIFY), so no, echo is correct.

restore_con(): you and I both know that's purely a cosmetic difference, and you're just being ridiculously knitpicky now. Fixed. :rolleyes:;)
[Android Software/Hacking General [Developers Only]] Xenos7:
I need a shell script to extract files from zip that it resides in.

This zip would have "META-INF" and "Dummy_file" in it's root. How can I extract the "Dummy_file" to ex. /system ?
[Android Software/Hacking General [Developers Only]] HemanthJabalpuri:
Copy and paste in code block of first post to META-INF/com/google/android/update-binary

Under that code add these lines

mount /system
package_extract_file Dummy_file /system/Dummy_file
set_perm 0 0 0644 /system/Dummy_file
unmount /system
exit 0

and flash it...
[Android Software/Hacking General [Developers Only]] osm0sis:
[MENTION=2869520]dontobi[/MENTION] I don't answer technical question PMs so I'll answer you here in the correct thread for your post.

You left brackets and commas in some of your package_extract_dir lines. Fix those and it looks fine. If you're still getting errors check recovery.log and it should be more specific and point you in the right direction.

Also, not a breaking issue but you could just use one delete_recursive command for all of yours, and/or switch it to rm -rf like you have at the bottom.
[Android Software/Hacking General [Developers Only]] :
Thanks for the hint. The last days I have revised my script. It works so far, but I get an ERROR 1 (TWRP). I have no idea why, maybe someone can help me. In the attachment I attached the recovery.log and my script.
[Android Software/Hacking General [Developers Only]] alecxs:
update busybox binary in your twrp. and what is /system/system does it exist?
[Android Software/Hacking General [Developers Only]] _that:
Shell scripts return the exit code of the last command if there is no explicit "exit" statement. Looks like your unmount_all fails, but you don't see why because you're redirecting its output to /dev/null.

By the way, reading error messages in the recovery.log generally helps. Only a few lines after the start I see this:

/tmp/updater: line 82: priv-app=/system/system/priv-app: not found

Shell variable names cannot contain "-"; you should fix that. There might be more errors, but I'm sure you can read the log file yourself. :)
[Android Software/Hacking General [Developers Only]] HemanthJabalpuri:
[MENTION=4544860]osm0sis[/MENTION]

zipsigner source is changed to https://github.com/topjohnwu/Magisk/tree/master/signing and link in 2nd post has to be changed.

and if we build from that we have to change the main-class path to com.topjohnwu.signing.ZipSigner, if we are explicitly mentioning class.
[Android Software/Hacking General [Developers Only]] osm0sis:
Thanks. Link updated. I'll update the instructions the next time there are tangible enough changes to zipsigner to require a new build, at the latest the next time it gets a version bump - it's currently still 3.0.
[Android Software/Hacking General [Developers Only]] Nikhil:
[MENTION=4544860]osm0sis[/MENTION] can you please help me out with the scripting flow that I am working on.

"My Package.zip" is the package which i am unzipping to /tmp/pkgContent folder using package_extract_file function from OP. Everything is okay till here. My Package.zip is extracted to /tmp/pkgContent.

Thereby I'm executing afzc (which is a shell script) passing below parameters where -op is just a case to identify the operation that needs to be performed in switch case statement.

/tmp/AFZCScripts/afzc "$2" "-op" "My Package.zip" "/tmp/pkgContent"

Now, the objective is to copy the files present in My Package.zip (which can have apk files and lib files) to appropriate system folder. I can have 10 (or more) My Package.zip (different files) in my original zip file. Instructions to perform this copy operation (of apk and lib files) is placed in installer.sh file present in My Package.zip. (I'm doing this since I can have 10 My Packages.zip and each package.zip will install itself using installer.sh present in the zip folder)

The code to achieve that is placed in afzc shell script which is below

case "$1" in
"-op")
unzip -o "/tmp/$1" -d "/tmp/$2"
ui_print "unzipping $1 into /tmp/$2"
ui_print $(ls) >> $OUTFD
cd $2
ui_print $(ls) >> $OUTFD #performing this operation to see if the file that I want to execute is present or not
chmod 755 installer.sh;
installer.sh;
;;
esac

However, installer.sh is not executing and below is what I see in the recovery.log. I'm really confused since the file is present in /tmp/$2 and even after chmod, it is not executing the file. rather saying file not found.

/tmp/AFZCScripts/afzc: line 46: installer.sh: not found

I've tried executing /tmp/$2/installer.sh thinking absolute path will be recognized but no luck.

Can you please help me out with this? Attaching the zip file and recovery.log if my explanation is confusing.

P.S. only sharing a part of whole code in post to narrow down the problem statement. Rest of the logic is working fine except installer.sh. I confirmed with ls command and installer.sh is present in the directory I am in.

Would appreciate your help on this. :)
[Android Software/Hacking General [Developers Only]] osm0sis:
Not found for a shell script can also happen if you've got a shebang at the top that isn't currently available, e.g. #!/system/bin/sh but /system isn't mounted.

I'd just suggest sourcing the installer.sh scripts with e.g. `. installer.sh` then you wouldn't have to worry about shebangs or permissions at all, plus use full path, then you don't have to cd either.
[Android Software/Hacking General [Developers Only]] Beakhole:
I don't know if I have signapk.jar. Where do I get it from? And which directory do I need to execute that from?
[Android Software/Hacking General [Developers Only]] osm0sis:
Google and download. That's what I did. :good:
[Android Software/Hacking General [Developers Only]] Beakhole:
Oh yeah, duh. Thanks for the tip.
[Android Software/Hacking General [Developers Only]] Beakhole:
Is it this one?
[Android Software/Hacking General [Developers Only]] osm0sis:
It's probably in there somewhere. Please try things before asking in the future.

Edit: Actually no, it's not in there. Somehow you found the one signapk that doesn't contain signapk.jar. Maybe try Googling the exact filename "signapk.jar" ...
[Android Software/Hacking General [Developers Only]] Beakhole:
Ok, will do. Also, I just solved my problem! I went here and saw this comment. It says to use ZipSigner to sign the apks. I've always used ZipSigner to sign my regular, edify flashable zips. Since your instructions say to use testkey, I decided to try to sign my zip using testkey in ZipSigner. I then rebooted to recovery and it flashed perfectly! I'm glad to know that I don't need to use my computer to sign these zips and can just do it on my phone like I've always done!! Thanks for your help! :laugh:
[Android Software/Hacking General [Developers Only]] osm0sis:
Are you sure you have zip verification enabled? It shouldn't both pass verification and unzip correctly without using Chainfire's tools unless something has changed.
[Android Software/Hacking General [Developers Only]] Beakhole:
You're right. I didn't have zip file signature verification enabled. Crap.
[Android Software/Hacking General [Developers Only]] osm0sis:
If you leave it disabled there's no point in signing. It's not necessary to the functioning of the zip.
[Android Software/Hacking General [Developers Only]] Beakhole:
Ok.
[Android Software/Hacking General [Developers Only]] 29y6145:
Good job
[Android Software/Hacking General [Developers Only]] Beakhole:
So I've found the signapk.jar file from here that's needed and did these steps per your instructions on my Ubuntu machine to sign the zip file: I did these steps:

7za a -tzip -r build-unsigned.zip .\build\*

java -jar signapk.jar test.certificate.x509.pem test.key.pk8 build-unsigned.zip build.zip

zipadjust build.zip build-fixed.zip

java -jar minsignapk.jar test.certificate.x509.pem test.key.pk8 build-fixed.zip build-signed.zip

It all comes out fine but when I go to flash the file with zip file signature verification enabled it says:

Verifying zip signature...
E:Zip signature verification failed: 1
Error flashing zip '/sdcard/Mods/Zips/Kernel-Gestures-signed.zip'

What did I do wrong?
[Android Software/Hacking General [Developers Only]] osm0sis:
Is that what your key and certificate are actually named? There weren't any errors there? I don't know man, I can't baby step you through all of this. You should be doing a lot more reading and experimenting and a lot less posting from what I've seen thus far.
[Android Software/Hacking General [Developers Only]] Beakhole:
Sorry for bothering you. I changed out the names of the cert and key files. I have been doing more research and less asking since you mentioned it yesterday. At this point I followed your instructions to the T but I'm not sure where I went wrong. Sorry.
[Android Software/Hacking General [Developers Only]] osm0sis:
Work has begun. Probably have the refresh ready by this time next week. :cowboy:
[Android Software/Hacking General [Developers Only]] osm0sis:
Refresh posted!

Changes:

- add less_than_int and greater_than_int because, what the hell

- place function usages in comments, in-line, to be less confusing for people

- add rename

- fix ch_con to support multiple files as per the documentation

- update ch_con, ch_con_recursive and restore_con based on [MENTION=631273]Chainfire[/MENTION]'s latest versions (they still only require the, e.g. "system_file" part of the label)

- add set_metadata and set_metadata_recursive (note "capabilities" currently isn't supported; I can't find any documentation on it or a shell counterpart)

- add apply_patch, apply_patch_check, and apply_patch_space by using the /system/bin/applypatch binary and the LD_LIBRARY_PATH hack to ensure the linking works (note: as with ch_con on some systems, make sure system is mounted before use)

- remove getprop's fallback reliance on the file_getprop function, implementing the /default.prop check directly

- remaining excluded functions updated to match current Android OTA documentation

Even though I've added set_metadata/set_metadata_recursive I have left set_perm/set_perm_recursive and ch_con/ch_con_recursive intact for those who prefer or need them (ch_con_recursive provides more granular control over the SELinux label). No function is reliant on another function so you may include only your preferred methods.
[Android Software/Hacking General [Developers Only]] Captain_Throwback:
So your shell getprop will only retrieve props that are stored in default.prop, not any/all props that are loaded by init like the standard getprop?
[Android Software/Hacking General [Developers Only]] osm0sis:
Fallback. It uses getprop from sbin and if that fails, uses what's in /default.prop since some older recoveries don't support getprop. Check out the function in the OP.
[Android Software/Hacking General [Developers Only]] Captain_Throwback:
Ah. I was looking at it and not understanding. Thanks.
[Android Software/Hacking General [Developers Only]] osm0sis:
Made a couple of fixes to the functions in the OP.

Also worth noting if your script is being embedded in a ROM zip install (ie. from a ROM kitchen), then there is a chunk of script you'll want to include: http://xdaforums.com/showpost.php?p=64929134&postcount=501

Thanks [MENTION=1162986]Captain_Throwback[/MENTION] and [MENTION=631273]Chainfire[/MENTION]
[Android Software/Hacking General [Developers Only]] HemanthJabalpuri:
line 46 should be

./installer.sh

implicit calling will only search in $PATH.
[Android Software/Hacking General [Developers Only]] Nikhil:
Thanks guys, it worked using below command and I didn't use cd $2 this time

. /tmp/pkgContent/installer.sh
[Android Software/Hacking General [Developers Only]] UTNT:
Error 255?
[Android Software/Hacking General [Developers Only]] osm0sis:
Super vague.
[Android Software/Hacking General [Developers Only]] UTNT:
Made the ZIP with the files (update-binary & updater-script), added this at the end:

ui_print "Test"
exit 0

Got an error 255 when attempting to flash.

I did create the directories "system" & "META-INF\com\google\android" and dropped the 2 files inside the 2nd directory.
[Android Software/Hacking General [Developers Only]] osm0sis:
What file editor did you use? Perhaps it was an issue with Linux line endings if you cut/paste into one that doesn't support them.
[Android Software/Hacking General [Developers Only]] ipdev:
Delete.
[Android Software/Hacking General [Developers Only]] FerryAr:
package_extract_dir function not working... :confused:

How to use the function ?

Like this

package_extract_dir system /system;

This

package_extract_dir "system" "/system";

This

package_extract_dir "system", "/system";

or this

package_extract_dir("system", "/system");

I have tried all above, but my files can't be extracted

Sorry for bad grammar, hope you understand.
[Android Software/Hacking General [Developers Only]] osm0sis:
The first or second ones should work. Is /system mounted read-write?
[Android Software/Hacking General [Developers Only]] FerryAr:
Yes, I've mounted /system to rw.

Here my update-binary script and recovery log, can you check it?
[Android Software/Hacking General [Developers Only]] jcmm11:
Hmm. What device? What version of Android? Stock or custom ROM?

Have you tried installing as a Magisk module instead?

What happens if you mount /system as rw in the TWRP terminal and try and write to it?
[Android Software/Hacking General [Developers Only]] FerryAr:
GT-S5282, Android 4.1.2, Running X-Pirates ROM

I'm a beginner, I haven't knowledge about magisk.

Device or resource busy.
[Android Software/Hacking General [Developers Only]] jcmm11:
Instead of

mount -o rw /system

Try

mount -o rw,remount /system

I do suggest you get familiar with Magisk. It would actually make things like this simpler in a lot of ways and, with new versions of Android, is a necessity if you want to modify /system.

With 4.1 it's not an issue - you should be able to mount system and do anything you want to it. Also true with a custom ROM, but Magisk, especially for simple changes, isn't difficult and adds flexibility. (I'm assuming that the phone is rooted using Magisk, which may not be true)
[Android Software/Hacking General [Developers Only]] AndDiSa:
[MENTION=4487388]jcmm11[/MENTION] shouldn't it be

mount -o remount,rw /system
[Android Software/Hacking General [Developers Only]] jcmm11:
Order of options shouldn't matter, although - especially on older Android versions - it may. So if one doesn't work try the other. Pretty sure I normally drop the remount at the end though.

Edit: you're correct that I forgot the -o though. Corrected.
[Android Software/Hacking General [Developers Only]] FerryAr:
I've try those command, but the result is same! But, when I use compiled update binary, its working!

I using

run_program("/sbin/mount", "/system");

command to mount.

I hate using compiled update binary because make the size of zip file bigger than before.

Magisk? Maybe later, cause I am a personal dev and not have device with new versions of android. Also I not have tester to test my work.

Sorry for bad grammar, hope you understand :p
[Android Software/Hacking General [Developers Only]] osm0sis:
I just looked at your update-binary script and you left out some important stuff from the OP, namely:

ZIPFILE="$3";

without which the package_extract_dir() function has no idea where the zip being flashed is located.

I also agree you should have something a bit more robust for mounting /system, since it may or may not be mounted before the zip is flashed. For your Android version I would normally do:

(mount /system;
mount -o rw -t auto /system;
mount -o rw,remount -t auto /system;) 2>/dev/null

and just for everyone's knowledge rw,remount is the correct order universally (toybox used to reject remount,rw when it was first introduced). Reference.

Feel free to throw a credit to me for the installer scripts somewhere too while you're at it. ;)
[Android Software/Hacking General [Developers Only]] alecxs:
[MENTION=6037748]Zackptg5[/MENTION] if you like use get_file() instead of keycheck. disadvantage: needs working /system mounted
[Android Software/Hacking General [Developers Only]] Zackptg5:
Good find! Sounds like getevent solution chainfire used. I've been sticking with static keycheck binaries since the contents of system/bin is strangely unreliable (like the issue I had with toybox on some devices) which still baffles me since toybox and toolbox should be consistent across all Android roms. I'll definitely keep this in mind though, thanks!
[Android Software/Hacking General [Developers Only]] osm0sis:
Just updated the OP functions with the following fixes:

- fix regression in ui_print when final character is \

- fix issue with package_extract_dir from non-busybox unzip (e.g. in mksh/toybox-based TWRP) not accepting wildcards

- mask stderr from set_metadata/_recursive selabel, ch_con/_recursive and restore_con /system attempts

Thanks to [MENTION=1162986]Captain_Throwback[/MENTION] for bringing them to my attention. :good:
[Android Software/Hacking General [Developers Only]] Nikhil:
Hi [MENTION=4544860]osm0sis[/MENTION],

Can I request you to add a function in OP to mount the partitions? Ever since SAR is introduced, mount <partition> is not good enough considering the dynamic nature of various devices. There are a lot of mods which follows the scripts you wrote in OP. It would be really helpful if you could write up the mounting mechanism in OP.

Best Regards,

Nikhil
[Android Software/Hacking General [Developers Only]] osm0sis:
Not sure how to simplify that for the OP. SAR in recovery is its own moving target.. People can grab my current implementation from the AK3 Backend if they like.
[Android Software/Hacking General [Developers Only]] kramer04:
Error 255

Hello

just want to make a test, but have

Updater process ended with Error 255

I've a Note9 with Samsung stock rom , rooted and Orange Fox recovery

I:operation_start: 'Flashing'
Installing ZIP file '/external_sd/Custom_Rom/test1.zip'
Checking for Digest file...
Skipping Digest check: no Digest file found
Unmounting System...
I:Update binary zip
Bypassing Treble compatibility check ...
Detecting Current Package
I:Zip does not contain SELinux file_contexts file in its root.
I:Legacy property environment not used in updater.
E:Can't execute '/tmp/updater': Exec format error
Updater process ended with ERROR: 255
I:eek:rangeFox: installed standard zip: /external_sd/Custom_Rom/test1.zip
I:flash_zip: installer code = 0
Error installing ZIP file '/external_sd/Custom_Rom/test1.zip'
Updating partition details...
I:Data backup size is 5561MB, free: 106694MB.
I:Unable to mount '/usb-otg'
I:Actual block device: '', current file system: 'vfat'
...done
I:Set page: 'flash_done'
I:operation_end - status=1
I:TWFunc::Set_Brightness: Setting brightness control to 5
I:TWFunc::Set_Brightness: Setting brightness control to 0
I:TWFunc::Set_Brightness: Setting brightness control to 10200
I:Set overlay: ''
I:Set page: 'clear_vars'
I:Set page: 'filemanagerlist'
I:Set page: 'advanced'
I:Set page: 'confirm_action'
I:Set page: 'action_page'
I:operation_start: 'Copy Log'
[Android Software/Hacking General [Developers Only]] osm0sis:
You've got a space before your shebang, so probably that.

If not then something else formatting-wise, most likely; make sure you're using LF line endings, trying to ui_print an empty variable might not work, etc.
[Android Software/Hacking General [Developers Only]] kramer04:
I'm trying to understand how to correctly use is_mounted()

is this code correct ?

sys="/system_root"
if is_mounted $sys; then
ui_print "Mounted System = $sys";
syspath="/system";
else
ui_print "$sys not mounted";
fi

if is_mounted /data; then
ui_print "/data is already mounted";
else
mount /data;
ui_print "/data is mounted";
fi
[Android Software/Hacking General [Developers Only]] osm0sis:
The examples here echo 1 or 0, not return, to leave it closer to the EDIFY they're based on, so you'd want to e.g. `test "$(is_mounted /data)" == 1` instead.

If you're borrowing the mount code from my AnyKernel3 project then your way would be correct: https://github.com/osm0sis/AnyKernel3/blob/master/META-INF/com/google/android/update-binary
[Android Software/Hacking General [Developers Only]] Nikhil:
[MENTION=4544860]osm0sis[/MENTION] is it logical to write system apps to inactive slot while being in active slot such that after ota update is complete, the system apps are present?

I'm aware of your twrp retention mechanism, wondering if that's seems logical with system apps on devices with A/B slot!
[Android Software/Hacking General [Developers Only]] osm0sis:
Not sure what you're referring to script-wise, but obviously A/B and A-only devices both exist and are being produced nowadays, so one should try to accommodate both.
[Android Software/Hacking General [Developers Only]] Nikhil:
What I mean to say is,

if I flash a custom rom on slot b,

my gapps on slot b,

When an update is arrived, through ota, the rom is installed in inactive slot (in this case slot a).

Upon reboot, slot a becomes active, we get the updated version of custom rom but the gapps are gone (naturally since they were never flashed on slot a).

Thus my question is, before reboot, when we're still in slot b, can we copy the google apps to inactive slot (through a retention script that can be flashed via magisk manager) so that after reboot, the gapps are present.
[Android Software/Hacking General [Developers Only]] osm0sis:
That's why addon.d exists, and in the case of A/B devices, addon.d-v2. Open GApps has a pretty comprehensive addon.d/addon.d-v2 script, check it out. :good:
[Android Software/Hacking General [Developers Only]] alecxs:
[MENTION=4867515]Nikhil[/MENTION] OTA will fail on modified system