Posts
17
Comments
28
Trackbacks
1
July 2008 Entries
Windows Vista and Disaster Recovery

Windows Vista is a great operating system. In fact, it's the best full-featured client operating system I've seen (after working with different versions of Windows, Linux, and Mac OS X for my day to day tasks). I believe Leopard is a better general purpose (read: for dumb people, aka users) OS but if you need to do something serious, nothing comes close to Vista. What I don't get is how people compare it to XP. In my opinion Vista is a MUCH better operating system than XP. I can't stand working with XP at all. It seems even slower if you have more than 2GB of RAM. Vista is a nice OS, though it has its own problems and I should admit it's far less than expectations.

I didn't want to continue OS wars here in this post. I want to talk about the nice system recovery features in Windows Vista which is really great if you run into disasters. My desktop PC is powered by a Core 2 Quad Q6600 processor, 4GB of RAM, and 2x500GB hard disks configured as a 2x400GB RAID 0 and 2x100GB RAID 1 volumes. It runs Windows Vista x64 on the RAID 0 volume.

To improve performance, I had activated the advanced write back caching on the system drive.

In the past few weeks, we've experienced lots of power outages (one more reason get out of Iran as soon as possible). Once, I turned my PC on after a power failure and an unfriendly black screen told me that your registry file is corrupted. The system couldn't boot anymore.

A nice less advertised feature of Windows Vista came to help, I inserted the DVD and booted into it. Got into recovery options and it automatically started startup repair. Apparently, it issued a chkdsk command, checked the filesystem and replayed the journal. It rebooted, the same error popped up again. I booted into the DVD once more and it gave me the option to use system restore to recover the system. I restored to the latest restore point available and after a few minutes, the system booted happily. It saved lots of hassles.

Windows Vista is really improved in the area of system recovery. In fact the shadow copy feature has saved my data several times. Once it was 10GB of data on an external HDD which I had just shift-deleted! It's really a great and useful feature. Unlike the well advertised Time Machine on Leopard which is nothing more than a very simple backup application with a fancy, useless user interface, that is kinda just a demo of CoreAnimation framework, previous versions is a real new feature that really works. I'm not the kind of person that has enough hard disks to do all my backups. Previous versions give me exactly what I want at no extra cost and it's one of the features I can't live happily without. As a friendly advice, turn it on all drives. It'll help you when you least expect it!

posted @ Friday, July 25, 2008 2:12 PM | Feedback (0)
Google Bomb against University of Tehran

I, as a very frustrated student of the University of Tehran and stupid instructors there, had to figure out a way to express my feelings. Since there are many other guys and gals around who have more or less equivalent feelings, I came up with the idea of a blog (named UT-Haters, after Linux hater's blog and UNIX haters handbook) and initiating a Google bomb on phrase "University of Tehran" to reference that blog. I'm pretty sure it's gonna be a litttle fun!

posted @ Friday, July 25, 2008 1:21 PM | Feedback (0)
How to run unsigned apps on your jailbroken iPhone OS 2.0

UPDATE 2: Don't use this guide, my "ldid" version was old and it didn't work. You can also use this nice article to enable build and go support in Xcode, just like you've had an official development cert!

UPDATE: It's been said that this method breaks unsecured WiFi connections. I've not tried it since I'm on WPA2 (tell me if it does or not). Do it on your own anyway. In fact, there's a better method using "ldid" (apt-get install ldid) that generates executable hashes or something and allows it to run correctly. You should run "ldid -S executable". I couldn't make it work though. It always pops out an error message for me.

You can run unsigned apps you develop using Xcode on your jailbroken iPhone OS 2.0 device. You'll need SSH installed and running on your iPhone.

This technique relies on disabling signature check by means of altering a kernel config with sysctl (Note that I don't deserve any credit for the job, all the credit goes to saurik, I just came up with a LaunchDaemon for it).

To be able to run unsigned apps, you should run this command as root on your iPhone:

sysctl -w security.mac.proc_enforce=0 security.mac.vnode_enforce=0

The parameters will be reset after a reboot, therefore we'll make up a launch daemon to set the parameters at every boot:

To do so:

nano /Library/LaunchDaemons/com.mehrdadafshari.iphone.autostart.plist

Paste the following:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">

<dict>
    <key>Label</key>
    <string>com.mehrdadafshari.iphone.autostart</string>

    <key>RunAtLoad</key>
    <true/>

    <key>ProgramArguments</key>
    <array>
        <string>/etc/rc.local</string>
    </array>
</dict>
</plist>

Save and exit (Ctrl+X,Y,Enter).

nano /etc/rc.local

Paste the following:

#!/bin/sh

/usr/sbin/sysctl -w security.mac.proc_enforce=0 security.mac.vnode_enforce=0

Save and exit (Ctrl+X,Y,Enter).

chmod +x /etc/rc.local

reboot

You're done! Copy your app developed using Device profile in Xcode (build/Debug-iphoneos/AppName.app or Release-iphoneos/AppName.app) to /Applications with SSH and run it, you have to kill SpringBoard to make it show up on the iPhone.

scp -r MyApp.app root@iphone.local:/Applications

ssh root@iphone.local 'killall SpringBoard'

I think you can put them as custom build actions in the Xcode tools and make them run everytime you build!

Have fun developing iPhone apps and keeping your $99!

posted @ Sunday, July 20, 2008 1:39 PM | Feedback (1)
Intel Launched "Centrino 2" Mobile Technology

Intel launched the new revision of its Centrino mobile platform! It's built on Intel 4 Series Express chipset and supports WiFi-n and WiMAX wireless technologies. It is said that a new wireless adapter supporting WiMAX and WiFi will be available in the second half of this year. A key technology in the new chipset series is the addition of something similar to what we've seen in some laptops such as "Sony VAIO SZ" series which Sony calls hybrid graphics system. It allows laptops to have a dedicated graphics processor while being able to switch to an integrated graphics chip to conserve power. Intel has also announced a new line of faster, more power-efficient processors, the fastest of which is X9100 chip which is running at 3.06GHz clock speed and has a 45W TDP. The greatest thing is the availability of the first mobile quad-core processor in the next 90 days!

Intel is a very innovative company. They make really great products! Go on Intel!

posted @ Tuesday, July 15, 2008 7:09 AM | Feedback (0)
Free US iTunes Store Account

Following the release of iTunes 7.7 software and the long-awaited AppStore for iPhones and iPod touches, I decided to download some apps to get prepared for iPhone OS 2.0 update. The first app I decided to download was the Apple provided "Remote" application which allows you to control iTunes on your systems remotely over WiFi using your iPhone or iPod touch and it even supports AirTunes! When I clicked Get App, I found out that just like music tracks, you should have an iTunes account to be able to download the apps, even free ones. So I decided to figure out how to open an iTunes account. The problem is when you want to open an account in iTunes, it requires you to provide billing information (valid credit card or paypal) to successfully register, therefore, it's necessary to have a credit card registered in the store's country (which I did not have). The trick is to fool the iTunes store using a redemption code. If you have an iTunes gift card and provide it at the time of registration, it will allow you skip the credit card part. Since buying a gift card is not the best solution, you should find a free redemption code and use it instead. I found one at www.tunecore.com/freealbum. Just enter this code at the registration page of the US iTunes Store and select None as the payment method. Just fill in the info (I think you should make sure ZIP code and state match) and you're done!

Enjoy downloading apps from the App Store and weekly freebies!

posted @ Friday, July 11, 2008 3:40 PM | Feedback (4)
Mac OS X (Darwin) x86_64 System Call Convention

I was looking everywhere around the net for an article or sample code describing how to issue system calls on x86-64 architecture on Mac OS X Leopard but I couldn't find anything.

So, I decided to find it out myself. I spent yesterday night digging around XNU kernel, FreeBSD kernel and Mac OS X Libc source code and disassembling and debugging to find it out.

I want to sum it up and write down what I found along with Linux syscall convention.

OK, let's get started. We'll use "yasm" with Intel syntax as our assembler.

Linux

x86 32-bit convention with "int 0x80": System call number is stored in eax. Parameters are passed using registers ebx, ecx, edx, esi, edi, ebp. Return value is stored in eax, edx. Stack is not used. System call numbers can be found in "unistd_32.h".

Example:

SECTION .data
     hello db 'Hello world!', 10
     hellolen equ $ - hello
SECTION .text
     global _start
_start:
     mov eax, 4 ; SYS_write
     mov ebx, 1 ; stdout
     mov ecx, hello ; string
     mov edx, hellolen ; string length
     int 0x80 ; issue system call
     mov eax, 1 ; SYS_exit 
     xor ebx, ebx ; exit code
     int 0x80 ; issue system call

Test: yasm -f elf a.asm; ld a.o; ./a.out

x86 32-bit convention with "sysenter": It's possible in newer releases of Linux kernel to use Intel architecture's fast system call facility by means of "sysenter" and "sysexit" instructions. I managed to use it successfully, but I'm not very sure how it should be used. It has something to do with stack and requires more prepration in userspace before system call as "sysenter" doesn't do much itself. Since I'm not sure about it, I won't talk about it here.

UPDATE: I figured out why the kernel doesn't use the rcx register to pass forth parameter of the system call like a function call. The reason is, as documented in the Intel manual, the fact that syscall instruction puts lower 32 bit of RFLAGS in R11 and also saves RIP value to RCX. Therefore, previous RCX value is discarded and it can't be used as a syscall parameter. As a result, both Darwin and Linux use R10 to pass the forth parameter.

amd64 64-bit convention with "syscall": There's a new instruction supported by Intel 64 architecture CPUs running in long mode used to issue system calls. Notice that system call numbers are changed in this mode and are specified in "unistd_64.h". In this mode, you store the system call number in rax register, and parameters are passed just like you were calling a C function (rdi, rsi, rdx, r10, r8, r9) except forth parameter which is passed via r10 instead of rcx. Return value will be placed in rax, rdx. Again stack is not used.

Example:

SECTION .data
     hello db 'Hello world!', 10
     hellolen equ $ - hello
SECTION .text
     global _start
_start:
     mov rax, 1 ; SYS_write
     mov rdi, 1 ; stdout
     mov rsi, hello ; string
     mov rdx, hellolen ; string length
     syscall ; issue system call
     mov rax, 60 ; SYS_exit 
     xor rdi, rdi ; exit code
     syscall ; issue system call

Test: yasm -f elf64 a.asm; ld a.o; ./a.out

Mac OS X

Darwin is a Mach and BSD based operating system. Therefore, its kernel, XNU, supports BSD and Mach system calls. In 32-bit x86 architecture, it seems that there are different interrupts for different system calls (e.g. int 0x80 is for BSD syscalls and int 0x81 seems to be for Mach syscalls). I'll stick to BSD syscalls in this article. By the way, 32-bit mode seems to support sysenter/sysexit too, but I haven't tried.

x86 32-bit convention with "int 0x80": Just like other BSD based operating systems, such as FreeBSD, parameters are passed on the stack. Just note that it requires a 4 byte empty space on the stack. This can be achieved by manually adjusting the stack, pushing a dword or by wrapping int 0x80 instruction in a separate function and calling the function instead. Return value will be stored in eax, and the caller has the responsibility of removing the parameters from the stack. You have to push parameters in the reverse order to allow the kernel to retrieve them in the correct order. System call numbers are in "sys/syscall.h".

Example:

SECTION .data
     hello db 'Hello world!', 10
     hellolen equ $ - hello
SECTION .text
     global start
start:
     push dword hellolen ; string length
     push dword hello ; string
     push dword 1 ; stdout
     mov eax, 4 ; SYS_write
     sub esp, 4 ; 4 bytes scratch space
     int 0x80 ; issue system call
     add esp, 16 ; clean up the stack
     mov eax, 1 ; SYS_exit
     push dword 0 ; exit code
     sub esp, 4 ; 4 bytes scratch space
     int 0x80 ; issue system call

Test: yasm -f macho a.asm; ld a.o; ./a.out

x86_64 64-bit convention with "syscall": This is the thing I was searching for in the source code. It's basically similar to Linux amd64 system call convention. Unfortunately, I had trouble testing this method since kernel panics (see last post) made me reboot the system anytime I did something wrong. The key difference between Mac OS X and Linux in this syscall method is system call numbers. Since Mac OS X has to handle more than just BSD syscalls (It should be able to handle Mach calls too) and unlike interrupts, there's only one syscall instruction, it had to somehow differentiate between them. To do so, it uses the highest byte of the eax. Therefore, first 32 bits of rax remain unused, the next 8 bit (highest byte of eax) will show what kind of system call you're going to use (2 for BSD, 1 for Mach, for instance). The next 24 bits (low 3 bytes of rax) will indicate syscall number, which you'll find in "sys/syscall.h".

This code snippet is from XNU source code, "osfmk/mach/i386/syscall_sw.h":
#define SYSCALL_CLASS_NONE 0 /* Invalid */
#define SYSCALL_CLASS_MACH 1 /* Mach */
#define SYSCALL_CLASS_UNIX 2 /* Unix/BSD */
#define SYSCALL_CLASS_MDEP 3 /* Machine-dependent */
#define SYSCALL_CLASS_DIAG 4 /* Diagnostics */

Example: (essentially the same as Linux with a different syscall number)

SECTION .data
     hello db 'Hello world!', 10
     hellolen equ $ - hello
SECTION .text
     global start
start:
     mov rax, 0x2000004 ;(SYSCALL_CLASS_UNIX<<24)|SYS_write
     mov rdi, 1 ; stdout
     mov rsi, qword hello ; string
     mov rdx, hellolen ; string length
     syscall ; issue system call
     mov rax, 0x2000001 ;(SYSCALL_CLASS_UNIX<<24)|SYS_exit
     xor rdi, rdi ; exit code
     syscall ; issue system call

Test: yasm -f macho64 a.asm; ld a.o; ./a.out

The interesting thing I noticed when using yasm is that in Mac OS X, when I run a yasm-assembled program with empty .data section or without a .data section at all and used the syscall instruction, dyld prints out an error message and the program exits. I've no idea why a dynamic linker should interfere with such a small independent program. I don't know much about Mach-O file format but it seems to be the reason dyld complains.

posted @ Friday, July 04, 2008 4:47 AM | Feedback (4)