Showing posts with label iphone. Show all posts
Showing posts with label iphone. Show all posts

Monday, October 12, 2009

Mac OS X 10.6 Snow Leopard, iPhone USB Tethering and Bad Carriers

Since iPhone OS 3.0 it is possible to [officially] use your 3G internet connection right into your laptop. That works very well for the all new Snow Leopard, with one single drawback: it is not possible to set name resolution servers when tethering via USB.

You might think it is a small issue but I would say you can be wrong, sorry. Relying on carrier's default DNS can be very annoying when they are faulty. And thats exactly what happens with me all the time. My carrier DNS frequently stops resolving top hit domains such as google.com and many more.

Of course I can switch to bluetooth, in which case Snow Leopard "weirdly" allows you to set your own DNS. But keep in mind that sometimes the phone might have no battery for that. Again, I could just let the phone plugged in a power outlet and bring bluetooth up, but that would have any fun ! I like to have choices, and not being able to tether via USB is something that annoys me and challenged me for quite some time.

No more bla bla bla, I could fix my problem when I found about something called configd and scutil. You can find a bit of information about them here and here. Going straight to the point, I could manage to overwrite my default DNS (with the address for opendns) using scutil and a little of bash scripting. That is what I came up with:


#!/bin/sh
#
# Replaces current DNS with the one you want in Mac OS X
#
# Author: Igor Feghali 
# 

#DNS="208.67.222.222 208.67.220.220"
DNS="8.8.8.8 8.8.4.4"
STATE=`echo "list State:/Network/Service/[^/]+/DNS" | scutil | awk '{print $4}'`

(echo "d.init"; echo "d.add ServerAddresses * $DNS"; echo "set $STATE";) | sudo scutil


You can set the contents of the variable DNS in the above script to whichever you want. But don't get too excited. This solution will work only for a few moments. I guess that's because configd rebuilds the network configuration periodically.

A short visit to configd man page led me to the right place: /Library/Preferences/SystemConfiguration/preferences.plist stores the preferences for all the network interfaces. The first thing to do is to find out the HEX code of which one we want to modify.

That would be BB6EBCF-861B-4A73-94FE-E08F7EEEE5EE for me. Now open preferences.plist (in the above path) and look for the key string somewhere in the file between a <key> and a </key>. Now replace:


<key>EBB6EBCF-861B-4A73-94FE-E08F7EEEE5EE</key>
<dict>
<key>AppleTalk</key>
<dict/>
<key>DNS</key>
<dict/>

with:

<key>EBB6EBCF-861B-4A73-94FE-E08F7EEEE5EE</key>
<dict>
<key>AppleTalk</key>
<dict/>
<key>DNS</key>
<dict>
<key>ServerAddresses</key>
<array>
<string>208.67.222.222</string>
<string>208.67.220.220</string>
</array>
</dict>


Just be sure to edit the file as root ($sudo vim for instance), save and reboot. That should do the trick.

I couldn't manage to reload the system configuration without a reboot, just let me know if you do.

Friday, March 28, 2008

How to hack iphone locales

You may already seen out there some projects that translates the iPhone user interface to many different languages. Locale strings are stored in a totally different way though. Things like "Monday" and the Portuguese equivalent "Segunda-Feira" are stored in a ICU (International Components for Unicode) data file.

For 12 mondays I had to stand looking at "Segunda-Feira" being printed out of the bounds of iCal icon. Until today. I tried fgrep'ng the whole iPhone for the string "segunda" with no luck. Then I tried converting all the plists from binaries to XML and fgrep'ng again and still no luck. Doing some research I found that apple uses ICU on iPhone, which drove me to find our target: /usr/share/icu/icudt34l.dat. This is a 8.5MB file bundled with all the locales (timezones, region formats, etc.).

To start playing with it, the first thing we will need is obviously the file itself:
cd /tmp
ssh root@iPhone cp /usr/share/icu/icudt34l.dat /usr/share/icu/icudt34l.dat.bak
scp root@iPhone:/usr/share/icu/icudt34l.dat .
Now we need the ICU version 3.4 tools. Again, I don't like macports or fink so I had a bad time trying to compile it myself (remember I am on a Mac OS X Leopard). You have now the cake recipe:
cd /usr/src
wget ftp://ftp.software.ibm.com/software/globalization/icu/3.4.1/icu-3.4.1.tgz
tar -zxf icu-3.4.1.tgz
mv icu icu-3.4.1
cd icu-3.4.1/source
For some weird reason the configure script for darwin is broken, so I had to fix that with the following patch:
--- config/mh-darwin 2004-05-18 18:54:24.000000000 -0300
+++ config/mh-darwin.new 2008-03-27 23:48:45.000000000 -0300
@@ -58,6 +58,7 @@
@echo "generating dependency information for $<" @$(GEN_DEPS.c) $< > /dev/null
@mv $@ $@~
- @echo -n "$@ " > $@
@cat < $@~ >> $@
@-rm $@~

@@ -65,6 +66,7 @@
@echo "generating dependency information for $<" @$(GEN_DEPS.cc) $< >/dev/null
@mv $@ $@~
- @echo -n "$@ " > $@
@cat < $@~ >> $@
@-rm $@~
Now we can run configure:
./runConfigureICU MacOSX --disable-samples --disable-draft --disable-extras --disable-tracing --disable-tests
and make it:
make
sudo make install
I couldn't manage to get file from bin/ installed on my system, but anyway I wasn't really interested on going deeply on that. Heck, I want to get rid of that "Segunda-Feira" thing !

Lets extract our package now:
cd /tmp
/usr/src/icu-3.4.1/source/bin/decmn icudt34l.dat --pkgdata > out.lst
cd icudt34l
boom ! we got a lot of files... and look who is laying around:
-rw-r--r-- 1 igor wheel 51K Mar 28 00:14 pt.res
-rw-r--r-- 1 igor wheel 496B Mar 27 23:06 pt_BR.res
-rw-r--r-- 1 igor wheel 3.7K Mar 27 23:06 pt_PT.res
The file we want is pt.res, but its a binary file. I couldn't manage to convert it back to something readable but again I am more interested in the quickest solution possible. Just download the pt.txt here. Near to the end you will find the calendar day names. Edit accordingly. Important: remember to use UTF-8.

Now its time to generate our new resource:
/usr/src/icu-3.4.1/source/bin/genrb pt.txt
and re-package:
/usr/src/icu-3.4.1/source/bin/gencmn -v -n icudt34l 0 < ../out.lst
At this point you cross your fingers and hope this works... worked for me :)
scp icudt34l.dat root@iPhone:/usr/share/icu
reboot and you are all set.

If you can read Portuguese you might find this entry interesting as well. It describes the similar process of updating Mac OS X timezone. It makes use of `icupkg` though, that is not available on ICU version 3.4.