5,598,657 Members 39,620 Now Online
XDA Developers Android and Mobile Development Forum

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

Tip us?
 
Fnorder
Old
(Last edited by Fnorder; 1st October 2011 at 06:58 PM.)
#1  
Senior Member - OP
Thanks Meter 316
Posts: 152
Join Date: Nov 2008
Location: Lake Vostok
Lightbulb [PATCH/TESTING]: Avoiding mobile browser detection (EC05-ish)

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
Attached Files
File Type: zip uaprof-patches.zip - [Click for QR Code] (1.4 KB, 22 views)
The Following 5 Users Say Thank You to Fnorder For This Useful Post: [ Click to Expand ]
 
Fnorder
Old
#2  
Senior Member - OP
Thanks Meter 316
Posts: 152
Join Date: Nov 2008
Location: Lake Vostok
One final note; gawker websites are -horribly- coded and try to pre-cache all sorts of junk. They actually -need- the mobile site, and will run like molassis unless you block
the following:
||dyn-cache.io9.com^
||dyn-cache.lifehacker.com^
||dyn-cache.gizmodo.com^
http://hyperion.gawker.com^
http://fastcache.gawkerassets.com/as.../*/*/*/xsmall_
http://fastcache.gawkerassets.com/as...s/*/*/*/micro_
 
Xhyperion
Old
#3  
Xhyperion's Avatar
Senior Member
Thanks Meter 55
Posts: 945
Join Date: Oct 2010
Location: Miami

 
DONATE TO ME
You did all this just for the hate of gawker? I understand but daaaammmn

Sent from my SPH-D700 using xda premium
Did I help you? Please donate to 1Kc4EvLjXuGdVz9bi6hjyAD9zw3Z7zgCew
 
Fnorder
Old
#4  
Senior Member - OP
Thanks Meter 316
Posts: 152
Join Date: Nov 2008
Location: Lake Vostok
Actually it was one too many wordpress.com blogs that did it. Their idea of 'mobile-friendly' is rather minimalist.
 
nerdtaco
Old
#5  
nerdtaco's Avatar
Senior Member
Thanks Meter 27
Posts: 219
Join Date: Sep 2008
Location: Lexington Park
Porn sites do the same ****

Sent from my SPH-D700 using xda premium
Look, nothing here!
The Following User Says Thank You to nerdtaco For This Useful Post: [ Click to Expand ]
 
styles420
Old
#6  
Senior Member
Thanks Meter 1235
Posts: 2,145
Join Date: Nov 2010
Quote:
Originally Posted by nerdtaco View Post
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
"What is this?! When does this happen in the movie?!"

"Now, sir. You're looking at now - everything that's happening now, is happening now."
The Following 2 Users Say Thank You to styles420 For This Useful Post: [ Click to Expand ]
 
Mama Luigi
Old
#7  
Senior Member
Thanks Meter 11
Posts: 128
Join Date: Aug 2010
Quote:
Originally Posted by nerdtaco View Post
Porn sites do the same ****

Sent from my SPH-D700 using xda premium
lol

10chars
 
Ceelos09
Old
#8  
Ceelos09's Avatar
Senior Member
Thanks Meter 284
Posts: 1,003
Join Date: Apr 2011
Any way these patches could be put together into a CWM flashable zip?

Sent from my SPH-D700 using xda premium
DEVICE: Samsung Galaxy S3
ROM: MOAR v5.01
Kernel: Stock Optimized Kernel
BOOTANIMATION: stock
Theme: My own personal creation
______________________________
DEVICE: Samsung Epic 4G
ROM: CyanogenMod 10.1
KERNEL: Stock CM10
BOOTANIMATION: Stock CM
THEME: ICS Glow
______________________________
DEVICE: Galaxy Tab 7 Plus
______________________________

DEVICE: Galaxy Tab 2 7"
ROM: Stock 4.1.2 JB
KERNEL: Stock
BOOTANIMATION: Stock
THEME: Stock
 
ugothakd
Old
#9  
Senior Member
Thanks Meter 404
Posts: 1,485
Join Date: Jun 2011
Location: O 'Fallon, MO
Quote:
Originally Posted by Ceelos09 View Post
Any way these patches could be put together into a CWM flashable zip?

Sent from my SPH-D700 using xda premium
Nope. Well, possibly. But it'd kinda be like a theme. Build-specific.

sent from my miui-ified epic
 
lafronz
Old
#10  
lafronz's Avatar
Senior Member
Thanks Meter 13
Posts: 131
Join Date: Sep 2010
Location: Fort Gordon

 
DONATE TO ME
Or you can just use skyfire...

Sent from my SPH-D700 using Tapatalk
Quote:
Originally Posted by jbadboy2007 View Post
Guess no one else realizes this but when the 3g or wifi icon change to a color that is when google is accessing your phone.

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


XDA PORTAL POSTS

Say Goodbye to Holo Blue Once and for All

When Google released Android 4.4 KitKat back in October of last year, they changed quite a bit … more

Sony Z Ultra Google Play Edition Receives Bluetooth Certification for Android 4.4.3

You may recall that a few days ago, Sprint jumped the gun … more

Easily Configure Xposed Module Projects in Eclipse

XDA Recognized Developer rovo89‘s innovative and versatile Xposed Framework allows … more

Android Control Center Becomes Quick Control Panel, Brings Host of New Features

You may recall that back in August of last year, we talked … more