Monday, September 26, 2011

Subtle compiler error due to circular dependency


Spent 2 hours debugging a compiler error. It keeps complaining about
error: expected ';' before '{' token
error: expected specifier-qualifier-list before 'type_name'
Turns out it's due to a circular dependency in header files, even with include guards...

foo.h
#include "bar.h"
bar.h
#include "foo.h"
 Fix is easy, just move the shared dependency out into a new header file.

foo.h
#include "shared.h"
bar.h
#include "shared.h"
shared.h
//Shared definition here

Saturday, September 3, 2011

Fix Chinese characters issue in Map for iPhone/iPad sold in China

As discussed in this post: chinese-iphone-4-serious-map-issues

  • Street names in the build-in Map app are in Chinese characters for all countries.
  • Changing the region/language in settings does not affect that.
The root cause is that the map data has been hardcoded to serve from ditu.google.cn instead of the general Google Map server at maps.google.com

The following is a fix from here, but that did NOT work for me and a few people I have seen in the aforementioned post.
Go to /System/Library/Caches/com.apple.dyld/ and copy dyld_shared_cache_armv7 to your pc
Use a hex editor (i use hex editor neo for windows) to make the following changes:
- search for ditu, and replace ditu with maps (only 1 reference)
- search for google.cn and replace cn with fr (only 1 reference)
Save file
Rename original file on iPhone_OLD
Copy over edited file to iPhone
Reboot
Voila - Maps in English
I ended up getting stuck at the white Apple logo during boot, and had to restore my iPad :(

After playing around that dyld_shared_cache_armv7 file, I found that the MD5 checksum was different when I did two copies via WinSCP. It is possibly the file is always changing, or it is just corrupted during the transfer, which causes the crash during boot. To overcome this, I decide to edit the file in place with the basic unix toolchain.

So here is my fix for the fix. (Tested with iPad + iOS 4.3.3 + Jailbreak by Jailbreak.me 3.0)

1. Install OpenSSH from Cydia
2. Create a file "patch.sh" with this content:
printf '\x6d\x61\x70\x73' | dd conv=notrunc of=/System/Library/Caches/com.apple.dyld/dyld_shared_cache_armv7 bs=1 seek=37841376 
printf '\x75\x73' | dd conv=notrunc of=/System/Library/Caches/com.apple.dyld/dyld_shared_cache_armv7 bs=1 seek=101924630
#The 1st line replaces "ditu" with "maps", while the 2nd line replaces "cn" with "us".
#37841376 and 101924630 are the corresponding HEX address in Decimal. You may want to verify them with a hex editor as in the original fix.
3. Copy over the file to iOS, e.g. /var/root
4. Run ./patch.sh
5. Reboot
6. No more Apple logo and Chinese in Map!


Update 1:
An anonymous commenter shared some more detailed steps that were not clear in my tutorial. I'll quote them here, but credit goes to him/her. Thank you!
Using Winscp, create a file >Files>new>file...
Name it patch.sh and paste the code 
printf '\x6d\x61\x70\x73' | dd conv=notrunc of=/System/Library/Caches/com.apple.dyld/dyld_shared_cache_armv7 bs=1 seek=XXXXXXXXX 
printf '\x75\x73' | dd conv=notrunc of=/System/Library/Caches/com.apple.dyld/dyld_shared_cache_armv7 bs=1 seek=XXXXXXXXX
Replace de XXXXXX after seek= with the number you get when using HxD hex editor, >search>find>search for - google.us select only the us and copy the number you see on the bottom left for me was offset:13654496 for ditu to maps and 66989846 for cn to us.
Then back to WinSCP right click on the dyld_shared_cache_armv7 and propieties, then change the octas to 0777, before running the command (right click on patch.sh, custom commands and execute) after you get an error change the Octas back from 0777 to 0644 default.

Update 2:
After installing the new iOS 5 GM, I found that this issue no longer existed. Maybe it will reappear in the final release. For those who don't need jailbreak/unlock, upgrading to iOS 5 might be a good option.

Update 3:
Some non-Chinese iPhone is having this problem after upgrading to iOS5. Now the map seems to be bound to SIM card, not where it is sold. Since I'm currently using an T-mobile SIM card, I have no such issue. I have jailbreak and a Chinese SIM card lying around, so I'll report back when I have more results.











Friday, September 2, 2011

BlahBear's Hive Meta

This is not BlahBear's Home. This is a sweet spot where BlahBear drops by for honey. Hence the name.

Thursday, September 1, 2011

Fix hard-coded Safari search to Google.cn for iPhone sold in China

If you buy iPhone in a Chinese Apple Store, the default search in Safari is hard-coded to use Google.cn. Unlike iPhone sold in other countries, changing region settings does not affect the search engine redirect. Now that Google has left China, searching from Google.cn will give a notice to ask you to use Google Hong Kong instead, which is annoying.


Here is the fix (jailbreak required):

  1. Locate and backup this file /var/mobile/Library/Safari/SearchEngines.plist
  2. Use your favorite text editor, e.g. iFile, to change "www.google.cn/search" to  "www.google.{topLevelDomain}/search"
  3. Restart Safari if it's in background mode.