[Moto G Q&A, Help & Troubleshooting] PuLKit4xd:
This script creates backup of partitions related to IMEI number. If you have not unlocked your boot-loader then you do not have to worry, you're safe. But read this in case you root someday!

DISCLAIMER:

I am not responsible for any damage caused to your device in any manner, you should be careful while doing anything. Before you proceed please read everything.

DESCRIPTION

The IMEI number is like an identifier to your cellphone for network operators. The phones will not be able to communicate in case IMEI is lost. The IMEI number is generally stored in PDS partition of the EMMC but the Moto g is an exception, there is no physical EFS partition so NV-Items are inaccessible for manipulation which means backing up PDS partition only will not make any sense.

The EFS is created on the fly: the modem reads HOB and DHOB partitions and after manipulations it creates a EFS file-system which is isolated from rest of the system. The modem finds the baseband, MEID, IMEI etc. and reports it to the OS.

The DHOB partition is encrypted and the key used is a PBKFD2 derived key for which the details like passkey, salt and iterations are unknown. HOB partition is XML-formatted and contains encrypted base64 text items. The secret is yet to be discovered.

Reference

http://xdaforums.com/moto-g/help/info-moto-g-imei0-t2925970/post62064474#post62064474

http://xdaforums.com/showthread.php?t=2640677

What does the script do?

This script simply creates the dumps of HOB, DHOB, FSC and PDS partition.

REQUIREMENTS:

A rooted phone is bare minimum and rest depends upon the method you choose. Download the archive one is for Linux and other is for Windows.

Choose any one.

FROM PHONE:-

1. Download and install any “Terminal Emulator” application from App store.

2. Type su and press enter to have superuser privileges.

3. Run these commands one-by-one.

su
mkdir /sdcard0/imei_backup
dd if=/dev/block/platform/msm_sdcc.1/by-name/hob" of=/sdcard0/imei_backup/hob.img
dd if=/dev/block/platform/msm_sdcc.1/by-name/dhob" of=/sdcard0/imei_backup/dhob.img
dd if=/dev/block/platform/msm_sdcc.1/by-name/fsc" of=/sdcard0/imei_backup/fsc.img
dd if=/dev/block/platform/msm_sdcc.1/by-name/pds" of=/sdcard0/imei_backup/pds.img

4. Copy imei_backup from the top folder of internal storage or SD-card.

FROM PC:-

1. Enable ROOT for both apps and adb from developer options.

2. Open cmd or terminal hange current location to folder imei_linux or imei_windows extracted from archive.

3. Run the below commands from cmd or terminal.

Windows

Make sure you have Motorola drivers installed (Motorola device manager).

imei_backup.bat

Linux

Superuser privileges are necessary.

sudo bash imei_backup.sh

or

su -C 'bash imei_backup.sh'

4. Once finished save imei_backup folder to someplace safe. The folder sits in the same folder the commands are run and in phone's internal storage or SD card.

FOR RESTORATION

1. Copy imei_backup folder to /sdcard (both internal or SD-Card in case you are not sure)

2. Open terminal emulator on phone and run these commands, all of them do not miss any. Run all of them twice to be sure.

dd if=/sdcard0/imei_backup/hob.img of=/dev/block/platform/msm_sdcc.1/by-name/hob"
dd if=/sdcard0/imei_backup/dhob.img of=/dev/block/platform/msm_sdcc.1/by-name/dhob"
dd if=/sdcard0/imei_backup/fsc.img of=/dev/block/platform/msm_sdcc.1/by-name/fsc"
dd if=/sdcard0/imei_backup/pds.img of=/dev/block/platform/msm_sdcc.1/by-name/pds"

4. Reboot your phone.

How to keep IMEI safe:

1. Do not use incompatible Roms or firmware.

2. Never run these commands.

Don't even try, I have screwed my phone already. Misspelled for safety.

Fast-boot erasee all (Don't)
Fast-boot erasee recovery (Don't)
Fast-boot erasee HOB (Don't)
Fast-boot erasee DHOB (Don't)[/COLOR]

Fast-boot erasee earth (Please Don't)

Run any of these commands and your phone turn into a tablet forever.

3. Create backup of the partitions i mentioned using one of the methods.

FAQS:-

Does it work on Dual-Sim or CDMA ?

Yes, it works. It just creates partition dumps, nothing more nothing less. It should work on Moto G (1st and 2nd gen) all variants and Moto E (1st and 2nd).

Is it safe to share my imei_backup folder if anyone asks?

Yes, the content is encrypted and there is no chance of manipulation of IMEI, the NV-ITEMS are written after verification. No two phones can have same IMEI. If it was possible then I wouldn't be so mad or worried or you would not be reading this. The best he could achieve is base-band change and signal but IMEI stays zero. No Cheating!

I have PDS partition backup, why should I care about this?

The PDS partition alone is no good for recovery, there are other partitions which help phone get a working cellular and valid IMEI number, those partition are HOB and DHOB. You can create backup through terminal emulator.

Why should I believe you?

I am a victim and did research on this for like 30 days. I do have a clear idea of what the problem really is. Please refer to mentioned threads for more information.

I have lost my IMEI because of “fast-boot erase all” command, can I get my IMEI back?

Sorry! But there is no working solution at the moment. All you can do right now is either buy a new motherboard or a spare phone to do work. The cure has not been found till now and hopes are really low unless some guy with good cryptography knowledge comes to rescue. So far i only know the problem :(