yashsingh1/xdaforums huggingface dataset:
[Nexus 5 Android Development] VoidRunner:
Patch the Executable, not the Linker

I've done successful patches for Lollipop 5.0/5.1 for Huawei and Samsung firmwares.

However I recently updated a Samsung device to Marshmallow 6.0.1 (LineageOS 13) and was very surprised to find out that the bionic files are slightly different - the text "error: only position independent executables (PIE) are supported" is no longer XREF-ered directly any more. It is called from an array. And the linker is passing this text as a parameter to libc external function.

That's the reason why we no longer can use the text to find the procedure which evaluates if PIE is supported.

However what I did found in the code is that the Library Files (Shared Objects or .so) needs to be relocatable.

And because of this fact, the linker checks whether the file is Library or Executable via this procedure (this is the linker from CM13, guess it's the same for others):

ElfW(Ehdr)* elf_hdr = reinterpret_cast<ElfW(Ehdr)*>(si->base);
if (elf_hdr->e_type != ET_DYN) {
__libc_format_fd(2, "error: only position independent executables (PIE) are supported.\n");
exit(EXIT_FAILURE);
}

The check elf_hdr->e_type != ET_DYN) basically looks for the e_type of the file we're executing, and since in Linux everything is a file, and could be executed if we've an execution bit set up, we could patch our executables to be recognised as a library by simply changing the e_type bit from ET_EXEC to ET_DYN. Here is the structure of an ELF header:

typedef struct {
unsigned char e_ident[EI_NIDENT];
Elf32_Half e_type;
Elf32_Half e_machine;
Elf32_Word e_version;
Elf32_Addr e_entry;
Elf32_Off e_phoff;
Elf32_Off e_shoff;
Elf32_Word e_flags;
Elf32_Half e_ehsize;
Elf32_Half e_phentsize;
Elf32_Half e_phnum;
Elf32_Half e_shentsize;
Elf32_Half e_shnum;
Elf32_Half e_shstrndx;
} Elf32_Ehdr;

If we open the compiled Executable/Shared object with HEX, the e_type bit is found on 0x10 address. Changing from 02 to 03 will "convert" the executable to a Shared Object and will bypass the exit(EXIT_FAILURE).

Proven and is working - tested sqlite3, dropbead and midnight commander.
[Nexus 5 Android Development] nachosz1:
Sorry, I'm noob, but I opened my linker and I went to 0x10, but it is already 03. I'm using android 7.1.2.
[Nexus 5 Android Development] VoidRunner:
Hm.. I ment 0x10 on the Executable that you want to run on with this version of the linker.

What is the Exec you need to run?
[Nexus 5 Android Development] nachosz1:
It's PIE. I don't know if it is an executable exactly. I get this error trying to run Reaver. Thanks!
[Nexus 5 Android Development] LockClock:
Could someone help me with my linker ? Device is Highscreen Boost 3 Pro.
[Nexus 5 Android Development] Mr.Rigan Johan:
how to use curl.zip

Android nougat
[Nexus 5 Android Development] RawSlugs:
can a more detailed guide be given I have moto g4 play that I would like to do this to
[Nexus 5 Android Development] m2jhulk:
help me plz

i have rooted redmi 4 indian version. miui 9. android 712. i want to connect ps3 controller with it. i have installed sixaxis controller app. i am getting error : only pie are supported. plz send me a msg i ll share my file. I can't post links here. im new here.
[Nexus 5 Android Development] mocarela:
You rock! :) Thanks!

BTW... I managed to patch the linker also on 6.0.1 (MM) of the stock Samsing Galaxy S5 mini, but on 7.1.2 I gave up - couldn't find the pattern.
[Nexus 5 Android Development] CLaudioman2009:
how can i fix my samsung note 4 PIE error? i try to use SIXAXIS and i get that error. what i have to do to fix this? i want to play with my sixaxis controller again !! ;_; :crying::crying:
[Nexus 5 Android Development] mocarela:
Follow VoidRunner's instuctions.

Find the corresponding executable and patch it at 0x10 from 02 to 03.
[Nexus 5 Android Development] CLaudioman2009:
How? i don´t understand anything. could you please tell me step by step?:confused:

---------- Post added at 02:52 PM ---------- Previous post was at 02:48 PM ----------

wich executable?? i want to use sixaxis controller and the sixaxis enabler app is the executable i need to modify??

please explain
[Nexus 5 Android Development] mocarela:
The procedure applies only to binary executables, not applications as apks.

Since I have never used this sixaxis controller, I don't know what it is about.

Going back to the original issue of "only position independent executables (PIE) are supported"... if you have such binary executable, take it somewhere and change its 16th byte from 02 to 03.

This is the simplest way I'm able to explain.
[Nexus 5 Android Development] lurky5:
Please help , anyone to patch my linker , I am running nougat 7.0 alcatel device. I also attached libpiex files if they can help.
[Nexus 5 Android Development] Sreehari Vikram:
I am using HTC Desire 828( Android 5.1), I tried using an apk(reaver), and encountered with this error: only pie are supported. Will i be able to bypass pie with flashing the zip files " bypass.zip & curl.zip"? If this doesnt satisfy my android version, can anyone tell me a solution?
[Nexus 5 Android Development] swat4samp:
Just flash zip from 13th post.
[Nexus 5 Android Development] alipingdante:
this patch greatly helps my battery drain issue
[Nexus 5 Android Development] meteora:
I flashed the attached zip for solving my VPN client not connecting to the servers, now it says it's connected to the servers BUT my internet traffic is not routed through the VPN and the VPN seems to be bypassed as well. Any recommendations?
[Nexus 5 Android Development] gr4ce:
Thanks, yes, I can confirm it works :)
[Nexus 5 Android Development] Megaflop666:
Worked like a charm! Thanks! :good:
[Nexus 5 Android Development] shinyquagsire23:
For those curious, the patch from the last developer build does in fact work on the latest L image. for the Nexus 5 (and maybe other builds, IDK). It seems all that was tweaked with the final version of Lollipop was Google Services and a few other tweaks, but not the particular binary which this fix used. Once again, to patch out PIE protection, just download the ZIP from the post I made prior and flash it using TWRP. After that all your apps which have yet to update their binaries for position independent execution should work again (ES File Explorer, SSHDroid, etc). I haven't found any bugs as of yet but if any *are* found then we might have to just build from sources and disable it there (which is preferable to what we have now).
[Nexus 5 Android Development] topgeardave:
Cheers mate :)
[Nexus 5 Android Development] Megaflop666:
I can verify its working on the latest nexus 7 build from [MENTION=426561]scrosler[/MENTION].
[Nexus 5 Android Development] thereal_bigjake:
Also working on stock 5.0 on the Nexus 7
[Nexus 5 Android Development] meangreenie:
This got lmt pie launcher working for me in lrx21o

thx
[Nexus 5 Android Development] Kimbaroth:
lol, not sure if you are trolling or what. xD
[Nexus 5 Android Development] Radagast82:
warning: stupid question here!

can i flash this patch on a completely stock N5 Lollipop + Root? Or do I need a custom recovery? :D
[Nexus 5 Android Development] thereal_bigjake:
You need to at least boot a custom recovery "fastboot boot recovery.img" to flash the zip.
[Nexus 5 Android Development] C5Longhorn:
Newb question, is this considered a temporary fix until the developers update their apps and then at that point you would reroot to accept the PIE functionality?

Thanks,

Rick
[Nexus 5 Android Development] steviemch:
Thought I was on to a winner finding this but still getting the PIE crap in Su logs.

Es file explorer , quickboot still not working with root. Cleared both apps data after flashing .

Nexus 7 2012, official image.
[Nexus 5 Android Development] payas0:
i should try this. this might solve the SixAxis Controller compatibility on my LRX210. because the log says something about PIE. will try and report back.
[Nexus 5 Android Development] sirbanger:
How would you go upon re-enabling pie check after flashing this?
[Nexus 5 Android Development] gpvecchi:
Noob on these things: I have this problem on AOSP Lollipops ROMs, it seems that some Google Apps can not be updated, nor by APK nor by Playstore: could this patch fix this issue? Thanks...
[Nexus 5 Android Development] bwomack:
Couldn't get it to work on nexus 7 2012. ES is still saying test failed after I grant su permissions.
[Nexus 5 Android Development] morpheusgt:
This has worked for me on a Nexus 4 with Stock Lollipop. Thanks!
[Nexus 5 Android Development] payas0:
broke my root on LRX210. :(
[Nexus 5 Android Development] VoSA:
I have the same experience, it's not working on NEXUS 7 2012.
[Nexus 5 Android Development] swallowingled:
Doesn't seem to work on Nexus 10. Applied patch and still can't get most of my root apps to work correctly even though my device is rooted.
[Nexus 5 Android Development] steviemch:
[MENTION=5293221]cernekee[/MENTION] [MENTION=4911634]shinyquagsire23[/MENTION] any idea what the problem could be for grouper?

Sent by Borg neural subspace transceiver node.
[Nexus 5 Android Development] ash_arani:
I too would love to know how to revert these changes.

For the record, this worked on N5 and N7-2013 (Wifi) running stock rooted Lollipop. Great work :)
[Nexus 5 Android Development] disconnecktie:
I didn't read the whole thread but to update you on some fixes from the patch in post 13.

Device: HTC One m7 (vzw)

ROM: CM12

Es file explorer

Flashify
[Nexus 5 Android Development] dechronic:
Thanks a lot for your work.

I just modified your zip file to create a PIE restore by replacing the modified linker file with the original for people who are testing apps to switch between the two.

I will share the file just in case anyone wants it:

http://d-h.st/Kzc
[Nexus 5 Android Development] jbowwow02:
So this will re-enable PIE, yes?

Sent from my Nexus 5
[Nexus 5 Android Development] dechronic:
Yes.

I created it that when an app is updated it can be tested with the new PIE security.

Such as ES File Explorer which updated recently, which now works.

So I manually reverted the file but I thought it would be easier for others to just flash it.

Android 5.0 Lollipop by Google

+

ElementalX Kernel by flar2

+

TWRP Recovery by TeamWin
[Nexus 5 Android Development] jbowwow02:
Thanks. I was looking for this. I downloaded the pie patch just for es, but since they updated it I wanted to revert the changes and re enable pie. Thank you.

Sent from my Nexus 5
[Nexus 5 Android Development] banesi:
Thanks but link seems down?
[Nexus 5 Android Development] dechronic:
No problem man.

Dev-Host entire server seems to be down?!?!?

I have attached it to this post.

EDIT: Made changes to the zip file as recommended by [MENTION=4056970]3DSammy[/MENTION] in post #55.
[Nexus 5 Android Development] ericwgarza1:
Can we get an update for the Nexus 6? I just got my unit and this seems to be the only outstanding mod that I'm looking for atm.
[Nexus 5 Android Development] 3DSammy:
First thanks for the two flash files. They helped with my upgrade to Lollipop on both my Nexus 5 and 10 as I use a non-PIE compliant proxy server (privoxy) which your patch allowed to function after the upgrade.

Just an FYI as everything worked on my Nexus 5 but for some reason the /system/bin/linker file would not get replaced when flashed on my Nexus 10. It took a bit of checking but I eventually realized that the way the flash file mounts /system made the flash file Nexus 5 specific. This answered an issue when people were using the flash file for the ES File Explorer fix (before it was updated) but it did not work on the N10.

I replaced your updater-script's first line:

mount("ext4", "EMMC", "/dev/block/platform/msm_sdcc.1/by-name/system", "/system");

and added:

#mount("ext4", "EMMC", "/dev/block/platform/msm_sdcc.1/by-name/system", "/system");
ui_print("Mounting System partition ...");
#Properly unmounting to avoid issues
run_program("/sbin/busybox", "umount", "/system");
run_program("/sbin/busybox", "mount", "/system");

After that change the flash file worked on the N10 and I suspect any other device. By the way I cannot take any credit for the fix as I ripped it directly off a flash file for installing Viper4Android which was intended for the Nexus 5 but worked on both devices. The comment "Properly unmount" is from that updater-script and definitely not added by me.

The same change will also be of value to your restore-pie flash file.

Thanks again for your contribution.
[Nexus 5 Android Development] dechronic:
I took my script from another zip too :)

EDIT: I used the original script from the orignal zip to patch pie.

I made the modification and will replace the one in the post.

Thanks.

Android 5.0 Lollipop by Google

+

ElementalX Kernel by flar2

+

TWRP Recovery by TeamWin
[Nexus 5 Android Development] mlewis:
It worked on my Nexus 5 but seemed to break WhatsApp.

On my 2012 Nexus 7 I had the same results as the other guys, no luck.
[Nexus 5 Android Development] jbowwow02:
You need to download the patch from post #13, that'll fix WhatsApp.
[Nexus 5 Android Development] victor0888:
this fix work in lg g3 lollipo?
[Nexus 5 Android Development] jbowwow02:
Technically it should.
[Nexus 5 Android Development] victor0888:
no working, i lose the root and try to install supersu but no working
[Nexus 5 Android Development] jbowwow02:
Did you flash the pie patch from post #13?

http://xdaforums.com/showthread.php?p=56123703
[Nexus 5 Android Development] franck1135:
The patch from post#13 it's ok for the lg g3.
[Nexus 5 Android Development] topp10:
Post #13 works on my OnePlus, cheers!
[Nexus 5 Android Development] 4tune:
Post #13 didn't work on my Nexus 10. I had to edit the updater script, also explained in this thread.
[Nexus 5 Android Development] colonel_lp:
Sorry for my ignorance, but how are you patching? with a hex editor? pre compiled or not? trying to do this to my cm12 version but cant find the values to change?
[Nexus 5 Android Development] shinyquagsire23:
Disassembly was done in IDA Pro because I had it and was familiar with it. Patching was done in a hex editor. This was done on the precompiled binary, so with CM12 it may be better to edit the sources directly.
[Nexus 5 Android Development] colonel_lp:
Thanks, don't have sources or ability to compile at the mo.

Downloaded ida, and this is what I find, but a bit stumped comparing it to what you have... A bit out of my depth I think!!

.text:00004176
.text:00004176 loc_4176 ; CODE XREF: .text:00003DA0j
.text:00004176 LDR R1, =(aErrorOnlyPosit - 0x417E)
.text:00004178 MOVS R0, #2
.text:0000417A ADD R1, PC ; "error: only position independent execut"...
.text:0000417C BL __dl___libc_format_fd
.text:00004180 MOV R0, R7
.text:00004182 BL __dl_exit
[Nexus 5 Android Development] RIPAciD:
Sirrr, thank you very much, just flashed it on my galaxy s5 and it works, I can use my old apps again. I'm using a custom ROM, XtreStoLite 2.0 LP, is there any difference?
[Nexus 5 Android Development] Khendrix:
Any risks flashing this patch?
[Nexus 5 Android Development] dechronic:
It disables the PIE security check so that older apps can run. The OP mentions the purpose of PIE. So yes it is a slight security risk as the SELinux update enforces the security to prevent someone exploiting an app. If you do not have an problems with any apps you do not need it.
[Nexus 5 Android Development] skyguy126:
Ok so the flashing and everything else went well but now the issue is the su binary stopped functioning. When I type su I get an error. Any idea on how to fix?

EDIT: Im running CM12 5.0.1 on a Moto G xt1032 falcon.
[Nexus 5 Android Development] ihsas:
my root not working now

I flash bypass now my root access not working what to do now

any solution thank you
[Nexus 5 Android Development] SgtWendigo:
confirmed working on OnePlus one on Feb14 nightly CM12. Many thanks mate!
[Nexus 5 Android Development] Kamil Mahmood:
I flashed pie patch now I am fine. Now I can use everything and with that I can use tcpdump which is an example of PIE
[Nexus 5 Android Development] Troubadour666:
thanks for your thread.

i have some trouble with ScreenCast app , SuperSu show me the error and i just take a binary "linker" form another rom that made work ScreenCast well on my I9100.

i have made a little review video about it and reference your thread there .

[YOUTUBE]Fi7ozJy3Dj0[/YOUTUBE]

really thanks for that.
[Nexus 5 Android Development] afraaa:
how to re enable ? and thank for work :)
[Nexus 5 Android Development] Megaflop666:
Enable the pie bypass? Flash the correct .zip from this thread on your custom recovery.
[Nexus 5 Android Development] kamild_:
I made the same thing as shinyquagsire23 and cernekee did but with the binary included in SlimLP. And guess what - it works!

Here's a .zip for anyone using SlimLP - tested on Slim-hammerhead-5.0.2.alpha.1.0-WEEKLY-8605, let me know when it stops working so I'll update it ;)

Mom, I did a thing!
[Nexus 5 Android Development] Kubino:
thanks, it works on my Nexus 4 with Android 5 Purity ROM ;).
[Nexus 5 Android Development] insigma28:
Working well on my nexus 4 using resurrection remix rom with unleashed kernel and [MENTION=5514152]Paget96[/MENTION] l speed mod thanks.
[Nexus 5 Android Development] Paget96:
Fstrim now workin???
[Nexus 5 Android Development] kamild_:
Here is the linker file patched for Android 5.1 :) Beware that the zip file I'm providing is not flashable - I'll make such a file later. For now you can copy the file using a file manager integrated in your recovery.

hf ;)
[Nexus 5 Android Development] TearsDontFalls:
Tried some zips, but didnt work for me. So patched 5.0.2 LRX22G Nexus 7 2013 Wifi and attached here :)
[Nexus 5 Android Development] thet1nman:
Linker file 5.1 works for me

The file worked on my Nexus 5 running xTraSmooth 4.0 LMY47D Android 5.1.

Just unzipped the file and replaced the linker file system/bin/linker

After that and a reboot I was able to use my ShareKM app again
[Nexus 5 Android Development] hasbrone:
Root Access

I have a Xperia Z Ultra with Lollipop 5.0.2 (LRX22G) and Root, but I have problems with root access on some Apps like Adaway and Root Explorer.

This patch/fix can help me?...

Thank You.
[Nexus 5 Android Development] asusgarb:
I tried flashing it on my Galaxy Tab WiFi 8.0, but it bootloops and then enters automatically in recovery.
[Nexus 5 Android Development] Paget96:
Hi guys, I think that you know who am I :D

I'm here to ask, is there possibility to make this PIE fix universal, to work on any device :D

We need PIE fix on L Speed mod for fstrim and haveged.

If someone can make fix, or just say me what I can do, I will credit him :)

Btw, this work on other phones too, but for someone cause bootloop or root loose.

Thanks ;)
[Nexus 5 Android Development] berryman13:
Universal support would be great. LG G2 user here
[Nexus 5 Android Development] Cr33D OrB:
Yeah i think too :good:
[Nexus 5 Android Development] berryman13:
So no progress on this?? I'm surprised

.. This benefits everybody
[Nexus 5 Android Development] opssemnik:
impossible
[Nexus 5 Android Development] berryman13:
...is what they all say until somebody actually achieves it.

Nothing in the world of computing is impossible, and even when keeping people's personal lives, work, etc, in consideration, this isn't even that hard comparative to some other things we now consider universal on android.

I don't know enough about this to say much more, but a one-word post doesn't help anybody.
[Nexus 5 Android Development] colonel_lp:
Recompile fstrim & haveged with pie flags enabled?
[Nexus 5 Android Development] Joeisgood99:
Hey [MENTION=4594947]TheReduxPL[/MENTION] , [MENTION=4275993]TearsDontFalls[/MENTION] and [MENTION=5293221]cernekee[/MENTION]

How did you patch the linker binary/module for your phone?

I would like to bypass PIE security on my HTC m7, Android 5.2, in order to get functionality back re init.d scripts like zip-align on boot etc. I have noticed a lot of custom roms for the m7 advertise such functions in there OP however a check of the log file for these scripts reveals that lots of error/ failed messages due to PIE.

Will post a link to m7 version of PIE bypass when complete.

Thanks in advance.
[Nexus 5 Android Development] tooandrew:
so, this doesnt seem to have helped at all on the nvidia shield tv. is there any chance you could make a zip for the shield tv, and if so, how might i be of assistance? i'm trying to use iwconfig binaries for wifi tx power so i can get better signals
[Nexus 5 Android Development] dechronic:
If you have the latest SuperSU installed you can use a simple script by flar2 that sets the selinux to permissive on boot.

https://www.androidfilehost.com/?fid=23991606952602503

---------- Post added at 08:22 AM ---------- Previous post was at 08:17 AM ----------

Oh in terms of init.d scripts the author of SuperSU suggests using the su.d directory as opposed to the init.d directory when running SuperSU without having to set your ROM as permissive. The script I mentioned above installs the script to that folder.
[Nexus 5 Android Development] luisflorit:
Not working for Galaxy Tab 8.4

I flashed the original ZIP to the Galaxy Tab 8.4 running cyanogenmod 12 (CY12, Android 5.0.2), and got a boot loop. I had to flash back the original CY12. Terminal IDE is completely broken by this PIE thing.

Does somebody knows how to fix this PIE with CY12?

Thanks!!

L.
[Nexus 5 Android Development] Andmoreagain:
Tried to install this fix on Galaxy Note 10.1 2014 edition. CM12.1, SELinux permissive... No bootloop here, but I'm sorry to say that Terminal IDE is still broken.

You could try compiling CM12 after applying this patch that was linked to in the first post and see if that does the trick: https://android.googlesource.com/platform/bionic/+/d81b3b275dff99561cbe5905ca63a1c72fa54a17
[Nexus 5 Android Development] shery butt:
i lost my root permissions with it what i do re root it again ? i tested ds on my lg g3 cloudyg3 2.5 rom
[Nexus 5 Android Development] Paget96:
Don't needed, just copy linker file from zip of ro. To /system/bin and set permissions to 777
[Nexus 5 Android Development] hunting_:
Not work for me I'm on nexus 5 LMY48G any help plz
[Nexus 5 Android Development] iRiKi:
I tried that linker binary on a Nexus 7 2012 with stock 5.1.1 and.. it didn't boot.

Luckily I had a backup of the original /system/bin/linker on the external storage, so I could boot again. How did you do it?

What I did:

1) copied the new linker file to external storage (while backing up the original one)

2) rebooted to recovery

3) copied the new linker over the original one in /system/bin

4) fixed permissions (chmod 755 linker) and group ownership (chgrp shell linker)

5) rebooted.

At this point the OS will no longer boot, dropping me again in the bootloader screen. Had to revert everything in order to boot again the OS.

If anyone has a linker that works in a Nexus 7 2012 with 5.1.1, please attach it, thanks.
[Nexus 5 Android Development] aziz07:
Cannot flash on x86 device. Manually copying linker result in bootloop into recovery. Any idea?

How can I edit the linker file? I know about hex editors but not android ...

Whats the code added to oem linker file, I uploaded my oem zenfone 2 x86 linker file.

p.s: You only need to replace back the original linker file in custom recovery to boot again.
[Nexus 5 Android Development] dechronic:
If you are using SuperSU you can use the following script that runs at boot from the su.d folder/directory (formerly init.d)

https://www.androidfilehost.com/?fid=23991606952602503

This should work for any ROM using SuperSU
[Nexus 5 Android Development] airjyp:
did you know autoproxy app? is this the reason why android L cant used it ? is it can be fixed with this ? thankss

anybody work? and i wanna try it but i scared it wouldnt boot :'( im using zenfone 4 lollipop 5.0
[Nexus 5 Android Development] airjyp:
pages not found :(
[Nexus 5 Android Development] shery butt:
this worked on my lg g3 :) thanks
[Nexus 5 Android Development] BattlestarSC2:
Flashed just the pie-bypass.zip to my Nexus 5.

Sadly, it is now in bootloop :(

However, I do have access to CWM recovery and the bootloader/download mode.

What do you guys suggest I do?