Code Painters The Art of Coding

20Nov/1055

Android emulator patch for configurable IMEI, IMSI and SIM card serial number

My post about hacking the emulator's IMEI number gained a lot of interest, hence I've decided to prepare a patch which makes IMEI, IMSI and SIM card serial configurable on a per-AVD basis. It's necessary to recompile the emulator with the patch applied, so setup your build environment as a first step. I suggest using Ubuntu 10.10 and following the Android compilation hints.

Patching the emulator

The next step is to fetch the Android source code tree as described on the Getting the Source page and apply the emulator patch (most likely you'd want to use froyo branch, but the patch should work with the master branch too):

czajnik@czajnik:~/froyo$ patch -p1 -d external/qemu/ < froyo_qemu_imei_patch_20101119.diff
patching file android/avd/hardware-properties.ini
patching file android/avd/hw-config-defs.h
patching file android/avd/info.c
patching file android/utils/ini.c
patching file android/utils/ini.h
patching file telephony/android_modem.c
patching file telephony/sim_card.c

Now we can rebuild the patched emulator for Linux:

czajnik@czajnik:~/froyo$ make emulator

When the compilation completes, copy the emulator binary into your SDK tools directory (I have SDK installed under /opt/android-sdk-linux_x86/), replacing existing file (you may want to backup it first):

czajnik@czajnik:~/froyo$ cp out/host/linux-x86/bin/emulator /opt/android-sdk-linux_x86/tools/

You may also want to compile the emulator for Windows:

czajnik@czajnik:~/froyo$ USE_MINGW=1 make emulator

When the build completes, look for out/host/windows-x86/bin/emulator.exe. Copy it to the tools directory, replacing existing emulator.exe.

How to use

Now you can customize IMEI, IMSI and SIM serial number by editing the AVD's config.ini file. The following new properties can now be used:

  • hw.gsmModem.imei - string of up to 15 digits
  • hw.gsmModem.imsi - string of up to 15 digits
  • hw.gsmModem.simSerial - string of up to 20 digits

Here's a sample file:

czajnik@czajnik:~$ more ~/.android/avd/A15i.avd/config.ini
skin.name=QVGA-L
image.sysdir.1=platforms/android-3/images/
skin.path=platforms/android-3/skins/QVGA-L
hw.gsmModem.imei=123451234512345
hw.gsmModem.imsi=543215432154321
hw.gsmModem.simSerial=11223344556677889900

Testing

To test the new settings you can build and run this sample application (see the screenshot below). Enjoy!


Update (Jan 22nd, 2011): I've received complaints about the patch failing to apply properly with the newer versions of the Android emulator (indeed, the emulator seems to be a moving target). Find the updated versions of the patch below:

The commit signatures refer to external/qemu project, of course.

Update (Jan 23rd, 2011): One more update of the patch, for the Donut release:

Update (June 1st, 2012): Upon request, here's a version for ICS:

Remember, that you need to build emulator-arm and emulator-x86 targets!

Share:
  • Facebook
  • Digg
  • del.icio.us
  • Twitter
  • LinkedIn
  • Google Bookmarks
  • Reddit
  • StumbleUpon
Comments (55) Trackbacks (0)
  1. You are attempting to build on a 32-bit system.
    build/core/main.mk:78: Only 64-bit build environments are supported beyond froyo/2.2.

    please tell me this is not true!!!!!!

    • I’m afraid it is true :), take a look at this thread. Personally I don’t agree with the technical reasons outlined there, I believe that it was just an arbitrary decision made by Google to unify the build environment internally.

      Search the mailing list archives, there are some patches available if you want to build on 32-bit system!

  2. patching file android/avd/hardware-properties.ini
    Hunk #1 FAILED at 150.
    1 out of 1 hunk FAILED — saving rejects to file android/avd/hardware-properties.ini.rej
    patching file android/avd/hw-config-defs.h
    Hunk #1 succeeded at 143 with fuzz 2 (offset -7 lines).
    patching file android/avd/info.c
    Hunk #1 succeeded at 253 (offset -6 lines).
    Hunk #2 succeeded at 316 (offset -6 lines).
    Hunk #3 succeeded at 951 (offset -6 lines).
    Hunk #4 succeeded at 1054 (offset -6 lines).
    patching file android/utils/ini.c
    patching file android/utils/ini.h
    Hunk #1 succeeded at 89 (offset 30 lines).
    Hunk #2 succeeded at 104 (offset 30 lines).
    patching file telephony/android_modem.c
    patching file telephony/sim_card.c

    could you give me an idea of the problem. I followed, everything you have suggested

    • Take a look at the post again – I’ve updated the patch for the new Android releases.

      • http://blog.codepainters.com/2010/10/27/compiling-android-sdk-on-ubuntu-10-10-maverick-meerkat/

        I followed the intructions for ubuntu 10.10 right down to a Tee.

        I am unsure which version your commands get but that is what I did, could you suggest a mod. Cause I am kind of desperate.

        • Well, I can just suggest you try the new patches I uploaded today. It is the patching step that fails for you, and not the compilation, so you should:
          * start with a fresh checkout
          * use the patch for the master branch that I published today
          If that fails, send me an e-mail.

          • Okay all the patches did not work for me again with this error.
            Could you tell me what the contents of this file should be I could try to do it manually.

            sudo patch -p1 -d external/qemu/ < android_imei_patch_tools_r8_20110122.diff
            patching file android/avd/hardware-properties.ini
            Hunk #1 FAILED at 150.
            1 out of 1 hunk FAILED — saving rejects to file android/avd/hardware-properties.ini.rej
            patching file android/avd/hw-config-defs.h
            Hunk #1 succeeded at 227 with fuzz 2 (offset 77 lines).
            patching file android/avd/info.c

            This is the reply I got for all three the other file patching seem to work.

          • I’m slightly lost about which version you’re using – if you don’t mind, what exact command did you use to checkout the repo?

          • This is the patch command I tried all versions above
            ———————————
            sudo patch -p1 -d external/qemu/ < android_imei_patch_tools_r8_20110122.diff

            repo commands used
            —————————
            sudo time repo sync

            this is the android command
            ————————————-
            sudo -s repo init -u git://android.git.kernel.org/platform/manifest.git -bdonut

          • Now it’s clear – you’re using Donut branch, i.e. Android 1.6, while my patches are for Froyo (Android 2.2) and higher. I can backport the patch, but.. just my curiosity – why do you need such an old version?

          • Ah, that post was from 2009, its’ pretty much outdated now. I guess I should at least add a link to a newer post there :)

            How’s the patch? Did it work for you eventually?

          • Also where is there a list of versions you can get, I can not find froyo. is it -bfroyo
            or just -froyo.
            I have not been able to get froyo release or any release yet, I cannot build android. This shit has taken me a week just to test serial numbers. I am never programming for mobiles after this program. I can not believe they would make it so difficult to do so little.

          • Well, Android development is moving forward very quickly, sometimes at the cost of code quality (I’ve seen a lot of hacks inside Android code). The documentation cries for improvements as well.

            I hope you’ve seen that page already?
            http://source.android.com/source/download.html

            I can send you exact steps to do, but I suggest you rather contact me via email (I’ve sent you an email, so you have my address), I don’t want to continue this topic in blog comments endlessly.

  3. The path imformation was a great help. But when the IMSI’s MCC or MNC is change from 310260, the emulator doesn’t have network access.

    Any idea how to change these and still have network access?

  4. How can I modify the model (android.os.Build.MODEL)

  5. The patch doesn’t work if you want to use a MEID value, as those start with a hex digit, and in reference-ril.c, it uses at_send_command_numeric() to retrieve the value instead of at_send_command_singleline().

  6. Hi, meets from Spain.
    Ive tried do this, but this post its seem to be obsolete..
    Sometimes Im traveling and Id like to have a clone of my Samsung Galaxy SII or my HTC Desire for use without roaming (whatsapp,grindr,badoo, etc)(on my PC) so I need change IMSI, IMEI, Number of the emulator, but I have 2.3.3 , your DIFF doesn’t work with this version. I have the SDK downloaded this weekend, could you help me please?.
    Thanks in advance.

  7. Hi admin .. tnx a lot for your job… i successfully build an emulator with your froyo patch.
    but I have a problem… internet connection didn’t work on emulator. Is there a way to make the emulator connect to the web with your patch? or can you tell me what file I have to modify manually in order to change imsi and sim?
    regards ;)

    • Hi! Thanks for pointing the issue, I’ve just reproduced it. I’m a bit surprised, as I’ve created this patch to test my application, which uses TCP connections a lot – and it was working just fine! It was several months ago, however, something might have changed since then.

      There’s a good news however: it seems that if you only change IMEI and do not enforce IMSI/SIM serial, network appears to work fine! To be exact, it seems everything works just fine if IMSI starts with 310260 !

      I hope this helps you!

      • tnx admin! yes I tried and it works just fine, also with hw.gsmModem.imsi=310995000000000

        now I have another question 4 U : is there a way to change the read-only variable ro.kernel.qemu=1 to =0 ? I want to change this value to bypass the emulator check that some android apps do to know if you are using an emulator or a real device :D it is possibile to do that?
        tnx again

        • Well, it is possible for sure, yet depends on how particular application checks for the emulator. Are you sure ro.kernel.qemu has anything to do with it? What is the application you want to cheat? ;)

          • realy? :) wow! I tried to change imei, IMSI, simSerial, android_ID … but nothing. with the emulator I can’t play on this app (Gowar)
            can I have your mail please ? :)

      • Android Emulator Network work fine after changing IMSI

        setprop gsm.defaultpdpcontext.active true
        setprop net.dns1 10.0.2.3
        setprop net.dnschange 1

  8. Hi,

    Thx for the patch it really work well for Froyo.
    Did you try this on ICS ?

    Thx a lot

  9. I’m an idiot and I cannot seem to figure this out… I’ve figured out how to build an ICS emulator, I just cannot figure out how to apply the damn patch.

    I’m a noob to ubuntu, I’ve had the opportunity to use it… lots, just never any need to.. I’ve built android emulator in windows before and played around with coding, but this is the first real time I’ve messed with linux.

    so could you write it out in plain english the command I need to type to apply this patch to my sdk and then what to compile it

    thanks… it’s late and it took me all damn day to get the SDK downloaded and all the prereqs installed.

    • for some reason now the android list command isn’t working I get an error saying android isn’t a command. I’ve gone into the android-sdks/tools folder… it was working, I restarted my laptop and now it’s not.

      god this is frustrating, I know it’s something stupid simple I’m doing that’s not working… something really simple I’m overlooking.

      I’ve even created an avd THROUGH eclipse and played with it, I just can’t find it anywhere…. I know I should’ve used linux years ago when I started using litestep and playing with kernels in windows 98.

      • Well, how come you managed to actually *build* the emulator having problems with SDK configuration?

        • I didn’t build the emulator through the terminal I built it inside eclipse the same way I would with windows.

          I’ve found where the files are kept, I just can’t figure out how to apply the patches. I downloaded the entire source tree it was close to 20 gigs I’ve found some of the files I just cannnot apply the patch cause apparently I’m an idiot.

          • I guess what you mean is creating AVD instance and not actual emulator compilation? As of patching, well… http://linux.die.net/man/1/patch

          • this is the problem I’m getting now, I’ve got the entire source downloaded to home/source-dl/

            nicholas@ubuntu:~/Desktop$ patch -p1 < android_imei_patch_4_0_4.diff
            can't find file to patch at input line 5
            Perhaps you used the wrong -p or –strip option?
            The text leading up to this was:
            ————————–
            |diff –git a/android/avd/hardware-properties.ini b/android/avd/hardware-properties.ini
            |index a2b05df..10ede3c 100644
            |— a/android/avd/hardware-properties.ini
            |+++ b/android/avd/hardware-properties.ini
            ————————–
            File to patch: a
            a: No such file or directory
            Skip this patch? [y] y
            Skipping patch.
            1 out of 1 hunk ignored
            can't find file to patch at input line 37
            Perhaps you used the wrong -p or –strip option?
            The text leading up to this was:
            ————————–
            |diff –git a/telephony/android_modem.c b/telephony/android_modem.c
            |index 437035d..f88a817 100644
            |— a/telephony/android_modem.c
            |+++ b/telephony/android_modem.c
            ————————–
            File to patch: y
            y: No such file or directory
            Skip this patch? [y] y
            Skipping patch.
            7 out of 7 hunks ignored
            can't find file to patch at input line 134
            Perhaps you used the wrong -p or –strip option?
            The text leading up to this was:
            ————————–
            |diff –git a/telephony/sim_card.c b/telephony/sim_card.c
            |index b172deb..a65f23e 100644
            |— a/telephony/sim_card.c
            |+++ b/telephony/sim_card.c
            ————————–
            File to patch: y
            y: No such file or directory
            Skip this patch? [y] y
            Skipping patch.
            5 out of 5 hunks ignored

  10. Dear admin, have you even researched how to change the phone number in the emulator.exe ?

    Does the SIM Card Series have relationship to the phone number ?

    I am looking forward to your reply, Thank you!

    • No, I’ve never tried hacking the phone number. Actually, the phone logs into the network with IMEI and IMSI, and this is the network side that assigns/maps the phone number (known as MSISDN) to/from particular IMSI. Many phones don’t even know their own number.

      That said, I’m not sure about Android – never needed it for anything.

      • Thanks First.

        But i find that whatever how many emulators you created, they have the same phone number.

        So , i wonder if the source code of the emulator contains the phone number

        If this if true , theoretically, we can use hex editor to find it and change it

  11. Hello Dear Admin
    I have sucessfully modded the Phone Number.
    If you want,i can share it to the community of your site,if there is still someone who needs this.
    Contact me if you still doing research on this topic. If not,you may delete this post.
    Best Regards
    Ilia

  12. i need urgent help…..can you please post a complete tutorial or all codes that can give a demo of android application that displays imei number of a device (emulator or android device)

  13. Great article and thanks for your hard work.

    Are you or anyone able to provide a downloadable of the newly compiled emulator?

    I have tried in vain and seem to come across issues. I am a novice at this stuff.

  14. Hi,i want to change the processor ,would u tell me how to do it?and i find all u website,i cann’t find u email address.becasuse i need to change the processor to test my app ;

  15. i am trying to compile 4.1.6 android src code, but when i made the modificaitons and gave make emulator, it just created 2 files inside /out/host/linux-x86/bin thats acp, and emulator .. Now when i copy these files inside adt/sdk/tools folder and then launch the avd, the avd never comes :( please let me know if i am doing somthing wrong

  16. Any Idea about change IMEI on bluestack? Please help me my skype:daotuanlinh
    I can change IMEI by change registry on Windows but Bluestack generate IMEI not true (check sum not true). How can we change it on bluestack VM. Thank you!


Add Comment Register



Leave a comment

No trackbacks yet.