Monday, January 17, 2011

Reading the PlayStation 3 registry with PHP

Sony Brasil took way too long to release the PS3 console on my country (something around august 2010). A long time before that happened, many foreign versions of the console (mostly of them american) were already available all around the country. So when I bought mine, I had no choice but a DVD region 1 PS3.

Brazil and United States shares the same Blu-ray region, so I am fine on that matter. DVD playback wasn't an issue for me either as I used to play them on my MacBook. But I have recently replaced it with the new MacBook Air 11" which has no DVD drive built-in, and now I am left with only the PS3 to watch my DVD movies.

Even though Brazil is DVD region 4 and my console is region 1, most recent DVDs play fine on it - it seems that region lock has been removed from those discs on factory. But a recent purchase showed an exception: my 40 DVDs box of the complete series of "Friends" (from Warner) just won't play on my PS3. Now that is bothering me.

I have been searching for weeks on how to watch my original, and expensive, DVDs region 4 on my console region 1, bought on a region 4 country at a time when only region 1 console was available. I couldn't overcome that limitation, I couldn't even find a way to opt for a region change (like my old MacBook let me do). But still, I found out about a really interesting stuff: the PS3 has a registry file with all of its settings - including the DVD region.

The registry file is called xRegistry.sys and can not be obtained by normal ways - you have to jailbreak your console to have access to it. It is a binary file, but a few guys managed to reverse engineer it here and here.

A GUI editor is available at the last link above, but it is target on a platform I have no access to. So I wrote a small piece of PHP code to help me with the task of manually editing the registry file - based on the specifications on the PS3 wiki and also on the code by stoker25.



A sample output is:

Array
(
...
[3933] => Array
(
[0] => /setting/bddvd/mnrForDvdRom
[1] => Array
(
[flags] => 0
[xxx] => 27415
[length] => 4
[type] => 01
[data] => 0x00000000
)

)

[3966] => Array
(
[0] => /setting/bddvd/dvdRegionCode
[1] => Array
(
[flags] => 0
[xxx] => 35494
[length] => 4
[type] => 01
[data] => 0x00000001
)

)
...


Which tells me, for instance, that at the decimal offset 3966 (0xF7E) I have the setting /setting/bddvd/dvdRegionCode which holds a value of 0x1. With that information in hand I can open xRegistry.sys with my favorite HEX editor and change that value to 0x4, for instance, and then upload the file back to my PS3.

Note that the registry file is divided in two sections: settings and data. The outer array keys on the output above are offsets to the settings. The data section is located below the settings, and points directly (with a delta of 0x10) to its parent setting. So in the example above I would search for 0x0000076E (which is 0x7E - 0x10) and hopefully I would end up on the value of the dvdRegionCode setting. To make sure you are on the right place, check the other fields as well - flags, length, type and the unknown field "xxx".

For more information on the structure of the registry file, please check the PS3 wiki.

Note that I have successfully changed my dvdRegionCode setting from 0x1 to 0x4 using the method above, but it had no real effect. I still can not play region 4 DVDs. But other people reported it worked for them - perhaps my american console is doing hardware checks while other versions don't.

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.

Monday, June 22, 2009

PHP'n Rio 09

The PHP Local User Group of Rio de Janeiro - PHP Rio are pleased to announce their 1st PHP'n Rio conference. It will be held July 03rd at the
Infnet Institute, Rio de Janeiro. It is a one day mini conference, aimed on providing experienced developers and beginners a chance to learn more about PHP frameworks, web
applications built in PHP and testing code.

The keynote speaker is Jan Schneider that will talk about the Horde project. We will also have sessions about other frameworks and a PHP TestFest.

PHP'n Rio sessions goes from 6pm to 9pm. Then PHP TestFest follows up
to 10pm. No fees or subscription required. Participation is entirely
free !

Whether you live here or are around just enjoying the marvelous city,
come and join us :)

For more information please visit the official site (portuguese only).

We are looking for sponsors so we can bring even more speakers from
around the country while keeping a great conference for free. If you
see your company fits as our partner, please email Igor Feghali <ifeghali at phprio.org>

Saturday, March 7, 2009

PHP Test Fest 2009

What is it ?

The TestFest is an event that aims at improving the code coverage of the test suite for the PHP language itself. As part of this event, local User Groups (UG) are invited to join the TestFest. These UGs can meet physically or come together virtually.

When is it going to happen?

UGs are free to pick any timeframe in April - June 2009. Each local TestFest can last a day, a week or any other timeframe.

Where do I get more info?

At the official site of the event.

Scalable logo for advertising

I used Inkscape to vectorize the official logo designed by Vincent Pontier, so you can make smaller/bigger bitmaps while keeping the good quality.

Sunday, December 21, 2008

Compiling SQLite 2 on Mac OS X 10.5 Leopard (for x86_64)

Mac OS X 10.5 Leopard comes with SQLite v3 bundled. But many times having SQLite v2 can be handy, given that version 3 is not backwards compatible. The hardest step here is to find the download link for version 2 in the official SQLite site. Don't ask me how did I achieve that... I don't remember ;) Fortunately I wrote down the link so you don't have to bother digging the web again :)

So we start with:
$ wget http://www.sqlite.org/sqlite-2.8.17.tar.gz
$ tar -zxf sqlite-2.8.17.tar.gz


The next big problem comes with CFLAGS. The package we are about to install comes with a pre-made configure script that doesn't respects the CFLAGS environment variable when creating the dynamic library. It took me a while but I have the patch for you, too.

--- configure.old 2008-12-21 18:50:24.000000000 -0200
+++ configure 2008-12-21 18:57:11.000000000 -0200
@@ -8253,7 +8253,7 @@
;;
esac
output_verbose_link_cmd='echo'
- archive_cmds='$CC -dynamiclib $allow_undefined_flag -o $lib $libobjs $deplibs$compiler_flags -install_name $rpath/$soname $verstring'
+ archive_cmds='$CC '$CFLAGS' -dynamiclib $allow_undefined_flag -o $lib $libobjs $deplibs$compiler_flags -install_name $rpath/$soname $verstring'
module_cmds='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags'
# Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin ld's
archive_expsym_cmds='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -dynamiclib $allow_undefined_flag -o $lib $libobjs $deplibs$compiler_flags -install_name $rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'


After applying the patch to the configure file we can proceed as usual:

$ ./configure --prefix=/usr/local LDFLAGS="-arch i686 -arch x86_64" CFLAGS="-arch i686 -arch x86_64"
$ make


I like to take full advantage of my system so I like to have things working at 64 bits. Just for the case I ever need a tool that won't go 64, I keep a fat binary with both archs 32 and 64. At this point we should check our work:

$ file .libs/libsqlite.0.8.6.dylib
.libs/libsqlite.0.8.6.dylib: Mach-O universal binary with 2 architectures
.libs/libsqlite.0.8.6.dylib (for architecture i386): Mach-O dynamically linked shared library i386
.libs/libsqlite.0.8.6.dylib (for architecture x86_64): Mach-O 64-bit dynamically linked shared library x86_64


Everything seems fine. So we finally install it:

$ sudo make install

Monday, May 19, 2008

How to sync your Nokia 5200 with your Mac OS 10.5 Leopard

  1. Download the following plugin:
  2. Go to your Applications folder, look for iSync.
  3. Right click iSync, click "Show Package Contents"
  4. Navigate thru Contents\PlugIns\ApplePhoneConduit.syncdevice\Contents\PlugIns
  5. Extract here the zip you just got
  6. Enable bluetooth on your computer and phone
  7. Open iSync
  8. Press Command+N to configure your phone settings and you are done

Wednesday, May 7, 2008

How to record your Mac OS 10.5 Leopard screen to SWF

Sometimes when you want to demo an application or even create a step by step tutorial on something, there is nothing better then a live recording of the action. In those cases vnc2swf is a small and very handy python script able to help you on that job.

I am not very sure on what it depends, but you would need X11, Freetype 2, jpeg and Python Imaging Library (PIL) at least. Python of course, but Leopard already comes with version 2.5. I am not sure about GTK, I already had that on my system. If you don't, please take a look at Compiling GTK+ on Mac OS X 10.5 Leopard and get it to your system. That same post would help you setup all the dependencies but PIL, that we are going to cover now.

Download PIL source code to /usr/src. I assume all your own compiled libraries are installed to /usr/local and you used architecture i686.


cd /usr/src
wget http://effbot.org/downloads/Imaging-1.1.6.tar.gz
tar -zxf Imaging-1.1.6.tar.gz
cd Imaging-1.1.6


Now you need to hack setup.py accoding to that diff:


--- setup.py.orig 2006-12-03 09:37:29.000000000 -0200
+++ setup.py 2008-05-06 21:13:29.000000000 -0300
@@ -131,14 +131,10 @@

elif sys.platform == "darwin":
# attempt to make sure we pick freetype2 over other versions
- add_directory(include_dirs, "/sw/include/freetype2")
- add_directory(include_dirs, "/sw/lib/freetype2/include")
+ add_directory(include_dirs, "/usr/local/include/freetype2")
# fink installation directories
- add_directory(library_dirs, "/sw/lib")
- add_directory(include_dirs, "/sw/include")
- # darwin ports installation directories
- add_directory(library_dirs, "/opt/local/lib")
- add_directory(include_dirs, "/opt/local/include")
+ add_directory(library_dirs, "/usr/local/lib")http://www.blogger.com/img/gl.link.gif
+ add_directory(include_dirs, "/usr/local/include")

add_directory(library_dirs, "/usr/local/lib")
# FIXME: check /opt/stuff directories here?


Then you are done to build:


export ARCHFLAGS="-arch i686"
export CFLAGS="-arch i686"
python setup.py build
sudo python setup.py install


Now you would just unzip and go vnc2swf but I couldn't make it work with Leopard's built-in VNC server (Screen Sharing) so you first need OSXVnc. Download the disc image, mount it and copy Vine Server to your Applications folder. Run and start the server.



You are now ready to go vnc2swf:


cd /usr/src
wget http://www.unixuser.org/~euske/vnc2swf/pyvnc2swf-0.9.3.tar.gz
tar -zxf pyvnc2swf-0.9.3.tar.gz
cd pyvnc2swf-0.9.3/pyvnc2swf/
./vnc2swf.py -n -o /tmp/myMovie.swf