unlock your iphone 3G or 3GS

There are many articles in internet about unlocking iphone 3G/3GS. many folks are trying various methods and corrupting their iphones. here is the method you can follow.


1 . Download iPhone OS 3.1.2 firmware (3G / 3GS) and save it into a folder.


Note: Make sure you download the correct firmware for your iPhone model. Otherwise, you can’t upgrade the iPhone OS.
2. Connect your iPhone via USB and launch iTunes


Note: I suggest not to use the docking for the jailbreak. Connect the USB cable directly with your iPhone.
3. Restore your iPhone with iPhone OS 3.1.2. For Windows, hold SHIFT key and click on the “Restore” button and select the firmware file (with .ipsw extension) you have just downloaded. For Mac, hold option key and click on the “Restore” button and select the firmware file (with .ipsw extension) to restore.
jailbreak-312-step1
4. If you’re not using official sim, your iPhone will not be recognized by iTunes after restoration. Don’t worry. It’s normal. You can then close iTunes and continues with the next step.

Jailbreaking with blackra1n

5. Go to blackra1n.com and download blackra1n. Both Windows and Mac versions are available. So, you should download the correct version that matches your OS.
6. After downloading, unzip the blackra1n.zip an copy to
C:\Program Files\Common Files\Apple\Apple Application Support.
7. Make sure your iPhone is still connected with your computer via USB. Launch blackra1n.

Note: if you get error "Cannot find ASL.dll" . download ASL.dll from http://download.155384.com/english/asl.dll.html and copy to C:\Program Files\Common Files\Apple\Apple Application Support
blackra1n-icon
8. Click “make it ra1n” to start the jailbreak.
blackra1n-make-it-ra1n
9. Once you click the button, the jailbreak process starts and it’ll take around 30 seconds to complete.
Blackra1n - Jailbreaking in Progress
10. Wait until you see the following message and your iPhone should be jailbroken after reboot.
blackra1n-complete
your iPhone should have been activated and jailbroken. Now lets Unlock it . 

Installing Cydia

Tip: Before proceeding, if you have WiFi connection, I suggest you to first enable it before continuing. This should speed up the download process of cydia.
11. Next, you’ll have to install Cydia. connect to WIFI and Tap on the “blackra1n” icon.
blackra1n-app-iphone
12. Tap on “Cydia” and then “Install” button to install Cydia. Just wait until the download and installation to complete.
blackra1n-cydia-3g

Unlocking iPhone 3G/3GS with Blacksn0w

Okay, with cydia installed, the whole jailbreak process is complete. But if you need to unlock your iPhone 3G/3GS to work with unofficial sim, launch blackra1n app again. Simply tap “sn0w” and then select “install” to kick off the unlocking process. Wait for a moment and your iPhone will be automatically unlocked.

Note: Jailbreaking and unlocking iphone will make warranty void, pls try this at  your risk .

Memory leaks - Linux , Windows , Solaris

Dtrace to find memory leaks - Solaris 10

The dbx and libumem utilities are pretty slow in finding leaks. in my experience I didnt get callstacks for memory  leaks.  so I used Dtrace tool which can print malloc/free callstacks and size to outputfile. From the output file we can extract malloc addresses which are not present in free ptr address. these addresses and callstacks will be memory leaked ones.

Step 1 ) use this dtrace script to print malloc/free statistics . usage is ./memleak.d pid  > output.txt

#!/usr/sbin/dtrace -s
#echo " usage ./memleak.d pid "
pid$1:libc.so.1:malloc:entry
{
        self->trace = 1;
        self->size = arg0;
}
pid$1:libc.so.1:malloc:return
/self->trace == 1/
{
        printf("Ptr=0x%p Size=%d", arg1, self->size);
        ustack();
        self->trace = 0;
        self->size = 0;
}

pid$1:libc.so.1:free:entry
{
        printf("Ptr=0x%p ", arg0);
}

for example if the process id is 1234 then
/memleak.d  1234 > output.txt

 step 2 )
copy this python script to showleaks.py and run  python ./showleaks.py output.txt 6 > leaks.txt 
output.txt is the output file  you got from dtrace 
6 is the depth of callstack. make sure your output.txt has minimum of callstack depth 6. 

#showleaks.py


import sys
import re

if (len(sys.argv) > 1 ):
    allocsfile = open(sys.argv[1],'r')
    allocs_lines=list(allocsfile.readlines())
    linenums=len(allocs_lines)
    i=0
    poin_size=" "
    ''' str1='12  66201                    malloc:return Ptr=0x10244cb30 Size=73' '''
    allocs_map={}
    stacks_map={}
    final_map={}
    depth=int(sys.argv[2])

    malloc_set=set(" ")
    free_set=set(" ")
    while i < linenums:
   
        malloc_match=re.search(r"malloc:return Ptr=\b0[xX][0-9a-fA-F]+\b Size=[0-9]*", allocs_lines[i])
        free_match=re.search(r"free:entry Ptr=\b0[xX][0-9a-fA-F]+\b",allocs_lines[i])
        if malloc_match:
            malloc_line=str(malloc_match.group())
            pos_ptr=malloc_line.find('=')
            ptr_address=str(malloc_line[pos_ptr+1:pos_ptr+12])
            malloc_set.add(ptr_address)
            allocs_map[ptr_address]=i # store ptr addr and line number
        elif free_match:
            free_line=str(free_match.group())
            pos_ptr=free_line.find('=')
            freeptr_address=str(free_line[pos_ptr+1::])  
            free_set.add(freeptr_address)
        i=i+1
else:
    print("usage: ./showleaks.py ")

leak_set=malloc_set - free_set


for i in leak_set:
        j=allocs_map[i]
        formatstr="malloc:return Ptr=%s Size=[0-9]*" % i
        malloc_match=re.search(formatstr,allocs_lines[j])
        if malloc_match:
            malloc_line=str(malloc_match.group())
            pos_ptr=malloc_line.find('=')
            rest_of_line=str(malloc_line[pos_ptr+1::])
            pos_Size=rest_of_line.find('=')
            Size = int(rest_of_line[pos_Size+1::])
            callstack=str(allocs_lines[j+1:j+depth])

            if callstack in stacks_map:
                value=stacks_map[callstack]
                stacks_map[callstack] = value + Size
            else:
                stacks_map[callstack] = Size

keys=stacks_map.keys()

for k in keys:
    print("leaked bytes: %d" %stacks_map[k])
    stacks=str(k)
    stacks1=stacks.split(r'\n')
    for sts in stacks1:
        print(sts)
   
print("\n DONE ")
   
   
   

for any queries, pls do post here. I will respond to it .