[PATCH/TESTING]: Avoiding mobile browser detection (EC05-ish)

Search This thread

Fnorder

Senior Member
Nov 8, 2008
153
327
Lake Vostok
Some of you may have noticed that, despite changing the User-Agent in the browser, you are still sent to a mobile website anyway. Gawker media (io9, lifehacker, gizmodo, etc) is especially obnoxious as there is no way to disable this, and the redirect fires when you hit the back button, keeping you trapped. Blogs hosted on wordpress.com have an option to view the full site, but you must select this for each blog.

These sites detect the UAProf (X-Wap-Profile) header, which android's web framework tacks onto every request. On the Epic - unlike other phones - there is no way to disable this using hiddenmenu; X-Wap-Profile: http://device.sprintpcs.com/Samsung/SPH-D700/EC05.rdf is hardcoded.

To further complicate matters, Google checkin, MMS, and Sprint Market purchasing all use webkit, and break if this header is suppressed.

Below are two smali patches that suppress the header in different ways. Only one is meant to be applied.

#1 is strict, and suppresses UAProf unless the User-Agent contains 'Android' or 'GoogleLog'. I have -not- tested this against the stock MMS client, but it works perfectly with AOSP provided you select the Android User-Agent.

#2 only suppresses UAProf if the User-Agent string contains 'Windows', which means it won't work for browsers that try to masquerade as a linux or mac browser in desktop mode.

I've tested patch#1 on SRF 1.1, with Dolphin Browser 4.x and AOSP MMS.

To apply:
$ adb pull /system/framework.jar .
$ apktool d framework.jar
$ unzip -p /somewhere/uaprof-patches.zip uaprof-1.diff.txt | patch -l -p0
-OR-
$ unzip -p /somewhere/uaprof-patches.zip uaprof-2.diff.txt | patch -l -p0
$ apktool b framework.jar.out
$ zip -ju framework.jar build/apk/classes.dex

I've thrown framework.jar directly back into /system/framework and rebooted without issue, but to play it safe you may wish to create an update.zip and backup before flashing in CWM.

Patch1:
Code:
diff -ur orig-framework.jar.out/smali/android/webkit/FrameLoader.smali framework.jar.out/smali/android/webkit/FrameLoader.smali
--- orig-framework.jar.out/smali/android/webkit/FrameLoader.smali       2011-10-01 15:09:02.000000000 +0000
+++ framework.jar.out/smali/android/webkit/FrameLoader.smali    2011-10-01 17:21:36.000000000 +0000
@@ -744,7 +744,7 @@
 .end method
 
 .method private populateStaticHeaders()V
-    .locals 8
+    .locals 10
 
     .prologue
     const-string v6, "Accept"
@@ -824,6 +824,16 @@
 
     move-result-object v6
 
+# UAProfMod
+  const-string v8, "Android"
+  invoke-virtual {v6, v8}, Ljava/lang/String;->contains(Ljava/lang/CharSequence;)Z
+  move-result v8
+  const-string v9, "GoogleLog"
+  invoke-virtual {v6, v9}, Ljava/lang/String;->contains(Ljava/lang/CharSequence;)Z
+  move-result v9
+  
+# /UAProfMod
+
     invoke-interface {v4, v5, v6}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
 
     .line 369
@@ -851,6 +861,12 @@
     .local v2, ver:Ljava/lang/String;
     iget-object v4, p0, Landroid/webkit/FrameLoader;->mHeaders:Ljava/util/Map;
 
+# UAProfMod
+  if-nez v9, :cond_4
+  if-eqz v8, :cond_3
+  :cond_4
+# /UaProfMod
+
     const-string v5, "X-Wap-Profile"
 
     new-instance v6, Ljava/lang/StringBuilder;
@@ -879,6 +895,10 @@
 
     invoke-interface {v4, v5, v6}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
 
+# UAProfMod
+  :cond_3
+# /UAProfMod
+
     .line 375
     return-void
 .end method

Patch2:
Code:
diff -ur orig-framework.jar.out/smali/android/webkit/FrameLoader.smali framework.jar.out/smali/android/webkit/FrameLoader.smali
--- orig-framework.jar.out/smali/android/webkit/FrameLoader.smali       2011-10-01 15:09:02.000000000 +0000
+++ framework.jar.out/smali/android/webkit/FrameLoader.smali    2011-10-01 17:19:06.000000000 +0000
@@ -744,7 +744,7 @@
 .end method
 
 .method private populateStaticHeaders()V
-    .locals 8
+    .locals 9
 
     .prologue
     const-string v6, "Accept"
@@ -824,6 +824,12 @@
 
     move-result-object v6
 
+# UAProfMod
+  const-string v8, "Windows"
+  invoke-virtual {v6, v8}, Ljava/lang/String;->contains(Ljava/lang/CharSequence;)Z
+  move-result v8
+# /UAProfMod
+
     invoke-interface {v4, v5, v6}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
 
     .line 369
@@ -851,6 +857,10 @@
     .local v2, ver:Ljava/lang/String;
     iget-object v4, p0, Landroid/webkit/FrameLoader;->mHeaders:Ljava/util/Map;
 
+# UAProfMod
+  if-nez v8, :cond_3
+# /UaProfMod
+
     const-string v5, "X-Wap-Profile"
 
     new-instance v6, Ljava/lang/StringBuilder;
@@ -879,6 +889,10 @@
 
     invoke-interface {v4, v5, v6}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
 
+# UAProfMod
+  :cond_3
+# /UAProfMod
+
     .line 375
     return-void
 .end method
 

Attachments

  • uaprof-patches.zip
    1.4 KB · Views: 50
Last edited:

Xhyperion

Senior Member
Oct 12, 2010
965
57
Miami
You did all this just for the hate of gawker? I understand but daaaammmn

Sent from my SPH-D700 using xda premium
 

styles420

Senior Member
Nov 12, 2010
2,379
1,390
Samsung Galaxy S21
Porn sites do the same ****

Sent from my SPH-D700 using xda premium

And there isn't a smali patch to get yourself a girlfriend, that still needs to be done the old fashioned way :)

Wait... I'm not saying knock her out and drag her home by the hair... Much easier, I would imagine, but a little TOO old fashioned... ;)

Sent from my SPH-D700 using XDA App
 

Ceelos09

Senior Member
Apr 18, 2011
1,025
289
Any way these patches could be put together into a CWM flashable zip?

Sent from my SPH-D700 using xda premium
 

Fnorder

Senior Member
Nov 8, 2008
153
327
Lake Vostok
Or you can just use skyfire...
I thought skyfire uses webkit? If so, it sends uaprof too.

Opera Mobile also has an option to set it as a desktop agent.
Opera and Firefox aren't affected by this issue. They just suffer from crappy UIs :p

Any way these patches could be put together into a CWM flashable zip?

For what rom? I could upload my framework.jar but I imagine it would only work on SRF 1.1.0 (ec05) and derivatives that don't modify framework.jar.
 

sephiroth009

Senior Member
Sep 5, 2011
151
18
Actually after trying out skyfire for a bit most websites didn't send me to the mobile version. Except for the occasional youtube page being m.youtube instead
 

lousou76

Senior Member
Mar 3, 2008
168
155
First of all THANK YOU for this great post.

I looked very hard finding where the wap profile code is located. I was searching in the wrong place thinking it was on the Browser's code not thinking of the framework.

Your diff patch is framework related. It would be nice if you would give instructions and code for any framework.

I added the following code on my Xperia Neo V .62 official Rom.
line 744 on file framework.jar.out\smali\android\webkit\FrameLoader.smali

change locals 5 to locals 7
Code:
.method private populateStaticHeaders()V
    .locals 5

line 839 on same file add the lines below ".line 371"
Code:
    .line 371

#patch remove this line after adding	 
iget-object v4, p0, Landroid/webkit/FrameLoader;->mSettings:Landroid/webkit/WebSettings;	
invoke-virtual {v4}, Landroid/webkit/WebSettings;->getUserAgentString()Ljava/lang/String;
move-result-object v4

const-string v3, "Android"
invoke-virtual {v4, v3}, Ljava/lang/String;->contains(Ljava/lang/CharSequence;)Z
move-result v5
const-string v3, "GoogleLog"
invoke-virtual {v4, v3}, Ljava/lang/String;->contains(Ljava/lang/CharSequence;)Z
move-result v6

if-nez v5, :cond_4
if-eqz v6, :cond_3
:cond_4
# patch ends here remove this line 

    iget-object v2, p0, Landroid/webkit/FrameLoader;->mHeaders:Ljava/util/Map;

    const-string/jumbo v3, "x-wap-profile"

In my post you will find the compiled framework.jar and an "all in one" batch script which can be used to install it on a rooted device with just one click!

Tested and works fine!

:)

This is for Xperia Neo V .62 official Rom ONLY
 

Attachments

  • mobile_browser_detect2.rar
    3.3 MB · Views: 45
Last edited:

Top Liked Posts

  • There are no posts matching your filters.
  • 5
    Some of you may have noticed that, despite changing the User-Agent in the browser, you are still sent to a mobile website anyway. Gawker media (io9, lifehacker, gizmodo, etc) is especially obnoxious as there is no way to disable this, and the redirect fires when you hit the back button, keeping you trapped. Blogs hosted on wordpress.com have an option to view the full site, but you must select this for each blog.

    These sites detect the UAProf (X-Wap-Profile) header, which android's web framework tacks onto every request. On the Epic - unlike other phones - there is no way to disable this using hiddenmenu; X-Wap-Profile: http://device.sprintpcs.com/Samsung/SPH-D700/EC05.rdf is hardcoded.

    To further complicate matters, Google checkin, MMS, and Sprint Market purchasing all use webkit, and break if this header is suppressed.

    Below are two smali patches that suppress the header in different ways. Only one is meant to be applied.

    #1 is strict, and suppresses UAProf unless the User-Agent contains 'Android' or 'GoogleLog'. I have -not- tested this against the stock MMS client, but it works perfectly with AOSP provided you select the Android User-Agent.

    #2 only suppresses UAProf if the User-Agent string contains 'Windows', which means it won't work for browsers that try to masquerade as a linux or mac browser in desktop mode.

    I've tested patch#1 on SRF 1.1, with Dolphin Browser 4.x and AOSP MMS.

    To apply:
    $ adb pull /system/framework.jar .
    $ apktool d framework.jar
    $ unzip -p /somewhere/uaprof-patches.zip uaprof-1.diff.txt | patch -l -p0
    -OR-
    $ unzip -p /somewhere/uaprof-patches.zip uaprof-2.diff.txt | patch -l -p0
    $ apktool b framework.jar.out
    $ zip -ju framework.jar build/apk/classes.dex

    I've thrown framework.jar directly back into /system/framework and rebooted without issue, but to play it safe you may wish to create an update.zip and backup before flashing in CWM.

    Patch1:
    Code:
    diff -ur orig-framework.jar.out/smali/android/webkit/FrameLoader.smali framework.jar.out/smali/android/webkit/FrameLoader.smali
    --- orig-framework.jar.out/smali/android/webkit/FrameLoader.smali       2011-10-01 15:09:02.000000000 +0000
    +++ framework.jar.out/smali/android/webkit/FrameLoader.smali    2011-10-01 17:21:36.000000000 +0000
    @@ -744,7 +744,7 @@
     .end method
     
     .method private populateStaticHeaders()V
    -    .locals 8
    +    .locals 10
     
         .prologue
         const-string v6, "Accept"
    @@ -824,6 +824,16 @@
     
         move-result-object v6
     
    +# UAProfMod
    +  const-string v8, "Android"
    +  invoke-virtual {v6, v8}, Ljava/lang/String;->contains(Ljava/lang/CharSequence;)Z
    +  move-result v8
    +  const-string v9, "GoogleLog"
    +  invoke-virtual {v6, v9}, Ljava/lang/String;->contains(Ljava/lang/CharSequence;)Z
    +  move-result v9
    +  
    +# /UAProfMod
    +
         invoke-interface {v4, v5, v6}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     
         .line 369
    @@ -851,6 +861,12 @@
         .local v2, ver:Ljava/lang/String;
         iget-object v4, p0, Landroid/webkit/FrameLoader;->mHeaders:Ljava/util/Map;
     
    +# UAProfMod
    +  if-nez v9, :cond_4
    +  if-eqz v8, :cond_3
    +  :cond_4
    +# /UaProfMod
    +
         const-string v5, "X-Wap-Profile"
     
         new-instance v6, Ljava/lang/StringBuilder;
    @@ -879,6 +895,10 @@
     
         invoke-interface {v4, v5, v6}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     
    +# UAProfMod
    +  :cond_3
    +# /UAProfMod
    +
         .line 375
         return-void
     .end method

    Patch2:
    Code:
    diff -ur orig-framework.jar.out/smali/android/webkit/FrameLoader.smali framework.jar.out/smali/android/webkit/FrameLoader.smali
    --- orig-framework.jar.out/smali/android/webkit/FrameLoader.smali       2011-10-01 15:09:02.000000000 +0000
    +++ framework.jar.out/smali/android/webkit/FrameLoader.smali    2011-10-01 17:19:06.000000000 +0000
    @@ -744,7 +744,7 @@
     .end method
     
     .method private populateStaticHeaders()V
    -    .locals 8
    +    .locals 9
     
         .prologue
         const-string v6, "Accept"
    @@ -824,6 +824,12 @@
     
         move-result-object v6
     
    +# UAProfMod
    +  const-string v8, "Windows"
    +  invoke-virtual {v6, v8}, Ljava/lang/String;->contains(Ljava/lang/CharSequence;)Z
    +  move-result v8
    +# /UAProfMod
    +
         invoke-interface {v4, v5, v6}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     
         .line 369
    @@ -851,6 +857,10 @@
         .local v2, ver:Ljava/lang/String;
         iget-object v4, p0, Landroid/webkit/FrameLoader;->mHeaders:Ljava/util/Map;
     
    +# UAProfMod
    +  if-nez v8, :cond_3
    +# /UaProfMod
    +
         const-string v5, "X-Wap-Profile"
     
         new-instance v6, Ljava/lang/StringBuilder;
    @@ -879,6 +889,10 @@
     
         invoke-interface {v4, v5, v6}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     
    +# UAProfMod
    +  :cond_3
    +# /UAProfMod
    +
         .line 375
         return-void
     .end method
    2
    Porn sites do the same ****

    Sent from my SPH-D700 using xda premium

    And there isn't a smali patch to get yourself a girlfriend, that still needs to be done the old fashioned way :)

    Wait... I'm not saying knock her out and drag her home by the hair... Much easier, I would imagine, but a little TOO old fashioned... ;)

    Sent from my SPH-D700 using XDA App
    1
    Porn sites do the same ****

    Sent from my SPH-D700 using xda premium