[GUIDE][HOW TO] Add toggle to bypass email exchange security

Search This thread

txr33

Senior Member
Jan 17, 2011
2,143
4,956
QLD
This is a how to add a toggle to bypass email exchange security. It has been tested and working on s3, s4, s5, s6, note 2, note 3 and note 4. And is basically the same for lollipop, kitkat and jelly bean.

This is a guide for people to add it themselves, not for people to upload their files and expect it done for them. It does require the ability to decompile and compile apks and is done with making a toggle for it in custom settings which can be found in this great thread here so it can be toggled on or off depending on what people want to use.

For this mod we will be modifying two apks. SecEmail (SecEmail_K for s5) and SecExchange. For s6 it requires SecEmailProvider and SecEmailSync.

This is a short and pretty straight forward change but decompile both apks and we will start with SecExchange or SecEmailSync.

Navigate and open the following smali

For S5: com/android/exchange/adapter/ProvisionParser

For S6: com/samsung/android/email/sync/exchange/adapter/ProvisionParser

now search for the following method.

Code:
.method public hasSupportablePolicySet()Z

and add this code to the start of it

For S5

Code:
const/4 v0, 0x1

    iput-boolean v0, p0, Lcom/android/exchange/adapter/ProvisionParser;->mIsSupportable:Z

For S6

Code:
const/4 v0, 0x1

    iput-boolean v0, p0, Lcom/samsung/android/email/sync/exchange/adapter/ProvisionParser;->mIsSupportable:Z

so it will look something like this

Before
.method public hasSupportablePolicySet()Z
.locals 1

.prologue
.line 89
iget-object v0, p0, Lcom/samsung/android/email/sync/exchange/adapter/ProvisionParser;->mPolicySet:Lcom/samsung/android/emailcommon/service/PolicySet;

if-eqz v0, :cond_0

iget-boolean v0, p0, Lcom/samsung/android/email/sync/exchange/adapter/ProvisionParser;->mIsSupportable:Z

if-eqz v0, :cond_0

const/4 v0, 0x1

:goto_0
return v0

:cond_0
const/4 v0, 0x0

goto :goto_0
.end method


After
Code:
.method public hasSupportablePolicySet()Z
    .locals 1

    .prologue
    .line 89
	const/4 v0, 0x1

    iput-boolean v0, p0, Lcom/samsung/android/email/sync/exchange/adapter/ProvisionParser;->mIsSupportable:Z

    iget-object v0, p0, Lcom/samsung/android/email/sync/exchange/adapter/ProvisionParser;->mPolicySet:Lcom/samsung/android/emailcommon/service/PolicySet;

    if-eqz v0, :cond_0

    iget-boolean v0, p0, Lcom/samsung/android/email/sync/exchange/adapter/ProvisionParser;->mIsSupportable:Z

    if-eqz v0, :cond_0

    const/4 v0, 0x1

    :goto_0
    return v0

    :cond_0
    const/4 v0, 0x0

    goto :goto_0
.end method

We are now done with that apk you can recompile it and move on to SecEmail_* or SecEmailProvider

Navigate to and open the following smali

S5: com/android/email/SecurityPolicy

S5: com/samsung/android/email/provider/SecurityPolicy

Look for the following method

S5
Code:
.method public isActive(Lcom/android/emailcommon/service/PolicySet;)Z

S6
Code:
.method public isActive(Lcom/samsung/android/emailcommon/service/PolicySet;)Z

Increase the locals from 4 to 7 marked in BLUE

Remove the code in RED

Add the code in GREEN

S5
Code:
.method public isActive(Lcom/android/emailcommon/service/PolicySet;)Z
    [COLOR="Blue"].locals 7[/COLOR]
    .param p1, "policies"    # Lcom/android/emailcommon/service/PolicySet;

    .prologue
    .line 734
    invoke-virtual {p0, p1}, Lcom/android/email/SecurityPolicy;->getInactiveReasons(Lcom/android/emailcommon/service/PolicySet;)I

    move-result v0

    .line 735
    .local v0, "reasons":I
    const-string v1, "SecurityPolicy"

    new-instance v2, Ljava/lang/StringBuilder;

    invoke-direct {v2}, Ljava/lang/StringBuilder;-><init>()V

    const-string v3, "getInactiveReasons returns : "

    invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2, v0}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v2

    invoke-static {v1, v2}, Lcom/android/email/Log;->e(Ljava/lang/String;Ljava/lang/String;)V

    .line 736
    if-nez v0, :cond_0

    const/4 v1, 0x1

    :goto_0
    return v1

    :cond_0
[COLOR="Red"]const/4 v1, 0x0[/COLOR]

   [COLOR="Lime"] invoke-static {}, Lcom/android/email/SecurityPolicy;->getContext()Landroid/content/Context;

    move-result-object v4

    invoke-virtual {v4}, Landroid/content/Context;->getContentResolver()Landroid/content/ContentResolver;

    move-result-object v4

    const-string v5, "email_security"

    const v6, 0x1

    invoke-static {v4, v5, v6}, Landroid/provider/Settings$System;->getInt(Landroid/content/ContentResolver;Ljava/lang/String;I)I

    move-result v1[/COLOR]

    goto :goto_0
.end method


S6

Code:
.method public isActive(Lcom/samsung/android/emailcommon/service/PolicySet;)Z
   [COLOR="blue"] .locals 7[/COLOR]
    .param p1, "policies"    # Lcom/samsung/android/emailcommon/service/PolicySet;

    .prologue
    .line 397
    invoke-virtual {p0, p1}, Lcom/samsung/android/email/provider/SecurityPolicy;->getInactiveReasons(Lcom/samsung/android/emailcommon/service/PolicySet;)I

    move-result v0

    .line 398
    .local v0, "reasons":I
    const-string v1, "SecurityPolicy"

    new-instance v2, Ljava/lang/StringBuilder;

    invoke-direct {v2}, Ljava/lang/StringBuilder;-><init>()V

    const-string v3, "getInactiveReasons - reasons : "

    invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2, v0}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v2

    invoke-static {v1, v2}, Lcom/samsung/android/emailcommon/utility/Log;->d(Ljava/lang/String;Ljava/lang/String;)V

    .line 399
    if-nez v0, :cond_0

    const/4 v1, 0x1

    :goto_0
    return v1

    :cond_0
[COLOR="Red"]const/4 v1, 0x0[/COLOR]

    [COLOR="Lime"]invoke-static {}, Lcom/samsung/android/email/provider/SecurityPolicy;->getContext()Landroid/content/Context;

    move-result-object v4

    invoke-virtual {v4}, Landroid/content/Context;->getContentResolver()Landroid/content/ContentResolver;

    move-result-object v4

    const-string v5, "email_security"

    const v6, 0x1

    invoke-static {v4, v5, v6}, Landroid/provider/Settings$System;->getInt(Landroid/content/ContentResolver;Ljava/lang/String;I)I

    move-result v1[/COLOR]

    goto :goto_0
.end method

That is it.

For the toggle add the following code to CustomSettings preferences and all done.

Code:
 <CheckBoxPreference android:title="Email Exchange Security" android:key="email_security" android:summaryOn="Disabled " android:summaryOff="Enabled" />
 

edgarf28

Senior Member
Nov 15, 2007
3,769
12,990
@txr33 Thanks for the guide!
Question: Can I also use this mod without an CustomSettings app in the ROM, to bypass the Exchange security at default (without an toggle)?
 

balla48801

Senior Member
Jul 29, 2008
429
314
This works great except for one thing when you have exchange bypass enabled and you have an active account going you still only have 2 options to set lockscreen either pin or password. You need to have your lockscreen security set to what you want before you activate your exchange account because after its set you cant change it. If you want to change lockscreen after you have to delete the administrator account which deletes your email account.
 
Last edited:

odurecu

Member
Feb 11, 2007
7
0
If anyone managed to modifying the APK as described, can you post the APKs in this thread (I am especially interested for Galaxy S6 ones) ?

It is not easy for everyone to decompile/mod/recompile an APK :-/
 

naoatsu

Member
Jul 27, 2007
32
5
Partial works

Great guide @txr33!!. Thank you for your work.
A couple of questions here:
I decompiled my 5.1.1 TW Mail apks (SecEmail_K and SecExchange) with apktool 2.0.1 and change the smali code as you said. No errors here. I compiled them and overwrite the original apks with the new ones (SecEmail_k.apk and SecExchange.apk) making a backup first. All works fine syncing emails without any problem but when you reboot (w and w/o d.cache wipe) you lose the mail App (it desappear)
¿What is going wrong?

EDIT: Solved (my fault): They must be Signed and Aligned. Customsettings code don't needed
 
Last edited:

EEKNEHC

New member
Feb 14, 2016
4
1
If anyone managed to modifying the APK as described, can you post the APKs in this thread (I am especially interested for Galaxy S6 ones) ?

It is not easy for everyone to decompile/mod/recompile an APK :-/



most people will consider it is not safe to use apk from unknown source.

but thanks txr33, this patch works on my N4/N5 today (before today I use Xposed + Outlook, bad experience also break device KONX warranty:crying: )

paste patched apk here in case someone really need it, from my note5 latest update, 5.1.1.
//I can not paste external link, mediafire.com+below download strings should works
/download/21ybalfp9d4dtpq/email-works.rar
signed and aligned,confirmed works on my device, but just provided as-is.
use RE to replace original one(system/pri-app/secxxxx/secxxxx.apk), change file permission, reboot

original unpatched apk also shared:
/download/4c5x59cqy9cc2ck/SecEmailSync.apk
/download/1sjoxqjgzehng7s/SecEmailProvider.apk

PS: if you want to patch by yourself, some variable may need to change, for example in txr33's patch some variable named v1, but in latest version, it may need to change to v2, v2 may need to v3, etc
 
Last edited:
  • Like
Reactions: guisof

newyankee

Member
Sep 24, 2013
8
0
PS: if you want to patch by yourself, some variable may need to change, for example in txr33's patch some variable named v1, but in latest version, it may need to change to v2, v2 may need to v3, etc

Could you post your revised source with the corrected variables, please?

Thanks
 

Top Liked Posts

  • There are no posts matching your filters.
  • 12
    This is a how to add a toggle to bypass email exchange security. It has been tested and working on s3, s4, s5, s6, note 2, note 3 and note 4. And is basically the same for lollipop, kitkat and jelly bean.

    This is a guide for people to add it themselves, not for people to upload their files and expect it done for them. It does require the ability to decompile and compile apks and is done with making a toggle for it in custom settings which can be found in this great thread here so it can be toggled on or off depending on what people want to use.

    For this mod we will be modifying two apks. SecEmail (SecEmail_K for s5) and SecExchange. For s6 it requires SecEmailProvider and SecEmailSync.

    This is a short and pretty straight forward change but decompile both apks and we will start with SecExchange or SecEmailSync.

    Navigate and open the following smali

    For S5: com/android/exchange/adapter/ProvisionParser

    For S6: com/samsung/android/email/sync/exchange/adapter/ProvisionParser

    now search for the following method.

    Code:
    .method public hasSupportablePolicySet()Z

    and add this code to the start of it

    For S5

    Code:
    const/4 v0, 0x1
    
        iput-boolean v0, p0, Lcom/android/exchange/adapter/ProvisionParser;->mIsSupportable:Z

    For S6

    Code:
    const/4 v0, 0x1
    
        iput-boolean v0, p0, Lcom/samsung/android/email/sync/exchange/adapter/ProvisionParser;->mIsSupportable:Z

    so it will look something like this

    Before
    .method public hasSupportablePolicySet()Z
    .locals 1

    .prologue
    .line 89
    iget-object v0, p0, Lcom/samsung/android/email/sync/exchange/adapter/ProvisionParser;->mPolicySet:Lcom/samsung/android/emailcommon/service/PolicySet;

    if-eqz v0, :cond_0

    iget-boolean v0, p0, Lcom/samsung/android/email/sync/exchange/adapter/ProvisionParser;->mIsSupportable:Z

    if-eqz v0, :cond_0

    const/4 v0, 0x1

    :goto_0
    return v0

    :cond_0
    const/4 v0, 0x0

    goto :goto_0
    .end method


    After
    Code:
    .method public hasSupportablePolicySet()Z
        .locals 1
    
        .prologue
        .line 89
    	const/4 v0, 0x1
    
        iput-boolean v0, p0, Lcom/samsung/android/email/sync/exchange/adapter/ProvisionParser;->mIsSupportable:Z
    
        iget-object v0, p0, Lcom/samsung/android/email/sync/exchange/adapter/ProvisionParser;->mPolicySet:Lcom/samsung/android/emailcommon/service/PolicySet;
    
        if-eqz v0, :cond_0
    
        iget-boolean v0, p0, Lcom/samsung/android/email/sync/exchange/adapter/ProvisionParser;->mIsSupportable:Z
    
        if-eqz v0, :cond_0
    
        const/4 v0, 0x1
    
        :goto_0
        return v0
    
        :cond_0
        const/4 v0, 0x0
    
        goto :goto_0
    .end method

    We are now done with that apk you can recompile it and move on to SecEmail_* or SecEmailProvider

    Navigate to and open the following smali

    S5: com/android/email/SecurityPolicy

    S5: com/samsung/android/email/provider/SecurityPolicy

    Look for the following method

    S5
    Code:
    .method public isActive(Lcom/android/emailcommon/service/PolicySet;)Z

    S6
    Code:
    .method public isActive(Lcom/samsung/android/emailcommon/service/PolicySet;)Z

    Increase the locals from 4 to 7 marked in BLUE

    Remove the code in RED

    Add the code in GREEN

    S5
    Code:
    .method public isActive(Lcom/android/emailcommon/service/PolicySet;)Z
        [COLOR="Blue"].locals 7[/COLOR]
        .param p1, "policies"    # Lcom/android/emailcommon/service/PolicySet;
    
        .prologue
        .line 734
        invoke-virtual {p0, p1}, Lcom/android/email/SecurityPolicy;->getInactiveReasons(Lcom/android/emailcommon/service/PolicySet;)I
    
        move-result v0
    
        .line 735
        .local v0, "reasons":I
        const-string v1, "SecurityPolicy"
    
        new-instance v2, Ljava/lang/StringBuilder;
    
        invoke-direct {v2}, Ljava/lang/StringBuilder;-><init>()V
    
        const-string v3, "getInactiveReasons returns : "
    
        invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
    
        move-result-object v2
    
        invoke-virtual {v2, v0}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;
    
        move-result-object v2
    
        invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
    
        move-result-object v2
    
        invoke-static {v1, v2}, Lcom/android/email/Log;->e(Ljava/lang/String;Ljava/lang/String;)V
    
        .line 736
        if-nez v0, :cond_0
    
        const/4 v1, 0x1
    
        :goto_0
        return v1
    
        :cond_0
    [COLOR="Red"]const/4 v1, 0x0[/COLOR]
    
       [COLOR="Lime"] invoke-static {}, Lcom/android/email/SecurityPolicy;->getContext()Landroid/content/Context;
    
        move-result-object v4
    
        invoke-virtual {v4}, Landroid/content/Context;->getContentResolver()Landroid/content/ContentResolver;
    
        move-result-object v4
    
        const-string v5, "email_security"
    
        const v6, 0x1
    
        invoke-static {v4, v5, v6}, Landroid/provider/Settings$System;->getInt(Landroid/content/ContentResolver;Ljava/lang/String;I)I
    
        move-result v1[/COLOR]
    
        goto :goto_0
    .end method


    S6

    Code:
    .method public isActive(Lcom/samsung/android/emailcommon/service/PolicySet;)Z
       [COLOR="blue"] .locals 7[/COLOR]
        .param p1, "policies"    # Lcom/samsung/android/emailcommon/service/PolicySet;
    
        .prologue
        .line 397
        invoke-virtual {p0, p1}, Lcom/samsung/android/email/provider/SecurityPolicy;->getInactiveReasons(Lcom/samsung/android/emailcommon/service/PolicySet;)I
    
        move-result v0
    
        .line 398
        .local v0, "reasons":I
        const-string v1, "SecurityPolicy"
    
        new-instance v2, Ljava/lang/StringBuilder;
    
        invoke-direct {v2}, Ljava/lang/StringBuilder;-><init>()V
    
        const-string v3, "getInactiveReasons - reasons : "
    
        invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
    
        move-result-object v2
    
        invoke-virtual {v2, v0}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;
    
        move-result-object v2
    
        invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
    
        move-result-object v2
    
        invoke-static {v1, v2}, Lcom/samsung/android/emailcommon/utility/Log;->d(Ljava/lang/String;Ljava/lang/String;)V
    
        .line 399
        if-nez v0, :cond_0
    
        const/4 v1, 0x1
    
        :goto_0
        return v1
    
        :cond_0
    [COLOR="Red"]const/4 v1, 0x0[/COLOR]
    
        [COLOR="Lime"]invoke-static {}, Lcom/samsung/android/email/provider/SecurityPolicy;->getContext()Landroid/content/Context;
    
        move-result-object v4
    
        invoke-virtual {v4}, Landroid/content/Context;->getContentResolver()Landroid/content/ContentResolver;
    
        move-result-object v4
    
        const-string v5, "email_security"
    
        const v6, 0x1
    
        invoke-static {v4, v5, v6}, Landroid/provider/Settings$System;->getInt(Landroid/content/ContentResolver;Ljava/lang/String;I)I
    
        move-result v1[/COLOR]
    
        goto :goto_0
    .end method

    That is it.

    For the toggle add the following code to CustomSettings preferences and all done.

    Code:
     <CheckBoxPreference android:title="Email Exchange Security" android:key="email_security" android:summaryOn="Disabled " android:summaryOff="Enabled" />
    1
    If anyone managed to modifying the APK as described, can you post the APKs in this thread (I am especially interested for Galaxy S6 ones) ?

    It is not easy for everyone to decompile/mod/recompile an APK :-/



    most people will consider it is not safe to use apk from unknown source.

    but thanks txr33, this patch works on my N4/N5 today (before today I use Xposed + Outlook, bad experience also break device KONX warranty:crying: )

    paste patched apk here in case someone really need it, from my note5 latest update, 5.1.1.
    //I can not paste external link, mediafire.com+below download strings should works
    /download/21ybalfp9d4dtpq/email-works.rar
    signed and aligned,confirmed works on my device, but just provided as-is.
    use RE to replace original one(system/pri-app/secxxxx/secxxxx.apk), change file permission, reboot

    original unpatched apk also shared:
    /download/4c5x59cqy9cc2ck/SecEmailSync.apk
    /download/1sjoxqjgzehng7s/SecEmailProvider.apk

    PS: if you want to patch by yourself, some variable may need to change, for example in txr33's patch some variable named v1, but in latest version, it may need to change to v2, v2 may need to v3, etc
Our Apps
Get our official app!
The best way to access XDA on your phone
Nav Gestures
Add swipe gestures to any Android
One Handed Mode
Eases uses one hand with your phone