MRobe.org
http://www.mrobe.org/forum/

Image updating script for m:robe 500i = READY!
http://www.mrobe.org/forum/viewtopic.php?f=6&t=1274
Page 1 of 11

Author:  shirour [ Fri Apr 28, 2006 10:52 pm ]
Post subject:  Image updating script for m:robe 500i = READY!

EDIT: THIS MESSAGE IS OUT DATE.
visit
http://mrobe.fan.googlepages.com/
for the latest version.

hi all,
a script that does everything for you!
it decrypts the file,
gets images by their number from m:robe, (then
you can change them).
use the updateimage function to upload them back. use CorrectCRC to render the new CRC, and Encrypt to create the final file.

use at your own risk!

(it works, i've managed to change some pictures, very cool).

if anyone has a good site where we can put this file let me know. meanwhile, you can just copy/paste this
python script, which does everything for you !

have fun,

shirour

mrobe500script.py:
------------------
Code:
#           m:robe 500i image updater script - Ver 0.95 BETA
# -------------------------------------------------------------------
# Created by: shirour                                        29/04/06
# Usage:
#
#   DISCLAIMER: USE THIS SCRIPT AT YOUR OWN RISK!
#    
# DecryptFile(inputfile,outputfile)
#    default inputfile  = "N5002-BD.BIN"
#    default outputfile = "N5002-BD.DEC"
#
#   Decrypts the original firmware file (inverse it and reorder the bits)
#
# CorrectCRC(inputfile,outputfile):
#
#   default inputfile  = "N5002-BD.DEC"
#   default outputfile = "N5002-BD.DEC"
#
#   Updates the CRC according to the updated _DECRYPTED_(!) file.
#
# EncryptFile(inputfile,outputfile)
#    default inputfile  = "N5002-BD.BIN"
#    default outputfile = "N5002-BD.DEC"
#
#   Encrypts the updated firmware file (inverse it and reorder the bits)
#
# GetImage(imagenum,inputfile,offset):
#   default inputfile = "N5002-BD.DEC"
#   default offset = 0x100000-0x18        DO NOT CHANGE THIS VALUE!
#
#   Reads the $imagenum$ (a number 0-389) from the decrypted
#   firmware and saves it to a file named "imagenum.ext"
#   (where the extension comes from the file type.
#
# UpdateImage(imagenum,imagefile,inputfile,outputfile,offset=0x100000-0x18):
#   default inputfile = "N5002-BD.DEC"
#   default outputfile = "N5002-BD.DEC"
#   default offset = 0x100000-0x18        DO NOT CHANGE THIS VALUE!
#
#   Updates the $imagenum$ image to $imagefile$.
#
#   Normal usage scenario:
#   put N5002-BD.BIN in the same directory as the script file.
#   run DecryptFile()
#   run GetImage(0)   where here you can choose whatever image number you
#            want, and do that as many times as you'd like...
#            change the images, as long as their sizes don't grow.
#   run CorrectCRC()
#   run EncryptFile()
#
#       have fun.
#
#

import binascii;
import array;

dec_dic = {
    0:3,
    1:2,
    2:1,
    3:0,
    4:5,
    5:6,
    6:4,
    7:7,
    8:9,
    9:11,
    10:8,
    11:10,
    12:14,
    13:12,
    14:15,
    15:13,
    };

enc_dic = {}
for i in dec_dic:
    enc_dic[dec_dic[i]] = i;
   
image_type_dic = {
    '0x3E8L':'jpg',
    '0x3E9L':'png',
    };

def DecryptFile(inputfile="N5002-BD.BIN",outputfile="N5002-BD.DEC"):
    ModifyFile(inputfile,outputfile,dec_dic);

def EncryptFile(inputfile="N5002-BD.DEC",outputfile="N5002-BD-NEW.BIN"):
    ModifyFile(inputfile,outputfile,enc_dic);
   
def CorrectCRC(inputfile="N5002-BD.DEC",outputfile="N5002-BD.DEC"):
    print "Opening file", inputfile;
    inpfile = file(inputfile,"r+b",1000);
    filearr = array.array('L', inpfile.read()).tolist()   # make integer list       

    print "Computing the CRC..."    #Note - the real file begins at 0x18 -> +5
    CRC = reduce(lambda x,y:x+filearr[y+5],range(0,len(filearr)-5-1));
    CRC = hex(CRC)[-9:-1];
    print "The updated CRC value is:", CRC
    inpfile.seek(0,0);
    filearr = inpfile.read();
   
    inpfile.close;
    del inpfile;
   
    print "Writing CRC to the file",outputfile
   
    outfile = file(outputfile,"w+b",1000);     
   
    filearr=filearr[:-4];
    for i in map(lambda x: dec_dic.get(x)-12,range(12,16)):
        filearr = filearr+ chr(eval('0x'+CRC[2*i]+CRC[2*i+1]) ^ 0xFF);

    outfile.write(filearr);
    filearr = "";
   
    outfile.close;
    del outfile;
    print "Done."
    return CRC;

def ModifyFile(inputfile,outputfile,thedic):
    print "Opening file", inputfile;
    inpfile = file(inputfile,"r+b",1000);
    filearr = array.array('B', inpfile.read()).tolist()   # make integer list       
    tmplist = (len(filearr)/16+1)*range(0,16);

    print "Reordering the file..."
    filearr = map(lambda x:filearr[thedic[tmplist[x]]+(x/16)*16]^0xFF,range(0,len(filearr)));

    print "Making output file",outputfile
    outfile = file(outputfile,"w+b",1000);   
    filearr = map(lambda x:chr(x),filearr);
    filearr = "".join(filearr);
    outfile.write(filearr);

    outfile.close;
    inpfile.close;
     
    tmplist = "";
    print "Done."
    return filearr;


def GetImage(imagenum,inputfile="N5002-BD.DEC",offset=0x100000-0x18):
    if (imagenum > 389) or (imagenum <0> 389) or (imagenum < 0):
        print "Wrong image number (0-389)";
        return -1;
    print "Reading input image file:",imagefile;
    imgfile = file(imagefile,"r+b",1000);
    imagestr = imgfile.read();
    imgfile.close();
    print "Reading input file:",inputfile;
    inpfile = file(inputfile,"r+b",1000);
    print "Extracting image details...";
    adr_table = 0x50d84c;
    inpfile.seek(adr_table+(imagenum)*4)
    image_adr = array.array('L', inpfile.read(4)).tolist()[0];
    inpfile.seek(image_adr-offset,0);
    image_type = image_type_dic[hex(array.array('L', inpfile.read(8)).tolist()[0])];
    image_max_size = array.array('L', inpfile.read(4)).tolist()[0];
    image_adr = array.array('L', inpfile.read(4)).tolist()[0] - offset;
    print "Checking image...";
    if image_max_size < len(imagestr):
        print "max image size:",image_max_size;
        return -1;
    imagestr = imagestr + (image_max_size-len(imagestr))*'\x00';    # add 00 if needed
    inpfile.seek(0,0);
    first_part = inpfile.read(image_adr);
    inpfile.seek(image_adr+image_max_size,0);
    second_part = inpfile.read();
    final_file = first_part+imagestr+second_part;
    inpfile.close();
    print "Writing image file."
    outfile = file(outputfile,"w+b",1000);   
    outfile.write(final_file);
    outfile.close;
    print "Done."
    return image_adr;
   
[/code]

Author:  dacarlson [ Fri Apr 28, 2006 11:09 pm ]
Post subject: 

I don't have the brain power to add something like this to my m:robe, can we expect a user friendly way to modify our m:robes?

Author:  sarason [ Sat Apr 29, 2006 1:00 am ]
Post subject: 

If you read the post, youd know that thats the program code that does it for you.

Author:  Pocker09 [ Sat Apr 29, 2006 1:25 am ]
Post subject: 

yo sh if you make it liek a file that is hopfuly an exe i can put it on the server!! which is

http://tdnet.ath.cx/mrobe/

or you you can just ftp it your self or like i said i can but the password is mrobe and so is the user name

but i can do it if you email me at: BigDan32509@gmail.com

Author:  Pocker09 [ Sat Apr 29, 2006 1:55 am ]
Post subject: 

but yea dood i dont do python so if you could compile and send to me like i said ill put it on our serve that i posted earlyer but yea thx yea dood plz compile the py script as a .exe and email to me or just ftp the server adn put it up there

Author:  robeslicker [ Sat Apr 29, 2006 2:58 am ]
Post subject: 

what am i doing wrong?

i installed pythong 2.4.3 for windows. saved the script to mrobe500script.py and placed that in the same folder as N5002-BD.BIN. ive run it both by double-clicking and on commandline. nothing happens.

Author:  RK [ Sat Apr 29, 2006 4:59 am ]
Post subject: 

The script makes little sense to me, but I like it :D , I'll try to put it into action later... By the way if you need to host something, I can help you out with that, just email me the zipped files and I would PM you with the direct link. No problems at all, especially when it's for such a good cause.

Author:  shirour [ Sat Apr 29, 2006 3:16 pm ]
Post subject: 

OK - i've made an exe file... now everyone
can change the firmware easily. take a look:

http://mrobe.fan.googlepages.com/

Image

Author:  insert username here [ Sat Apr 29, 2006 3:19 pm ]
Post subject: 

this is cool. it better make front page news. there hasnt been an update in over 2 months. :cry:

Author:  robeslicker [ Sat Apr 29, 2006 4:49 pm ]
Post subject: 

the exe works great though i havnt tried updating the firmware on my 500i.

good work

Author:  Zero82z [ Sat Apr 29, 2006 5:12 pm ]
Post subject: 

Stickied. I'll PM Howie about putting it on the front page.

Author:  jamelikat [ Sat Apr 29, 2006 6:08 pm ]
Post subject:  Well done shirour!

Don't have a 500i, yet...but well done shirour. Like many others, marvelling at how you guys do this sort of thing. I guess some of you do this sort of thing for a living. I know I'll be tempted to use your script/exe if and when I get the 500. Scary, as in bricking the robe if I do something wrong, but irresistible still. Glad you put 'Do It At Your Own Risk' in your guide.

Applause to you.

jamelikat

Author:  Musjunk22 [ Sun Apr 30, 2006 5:48 am ]
Post subject: 

I followed the guide about 4-5 times doing something different each time but I still can't get it to decrypt. Any way you can make the guide any clearer or am i just plain ignorant and am not seeing something?

BTW Thank so incredibly much! What a great job you've done!

Author:  Zero82z [ Sun Apr 30, 2006 6:03 am ]
Post subject: 

Howie's put the guide up on the front page.

Author:  rick [ Sun Apr 30, 2006 6:34 am ]
Post subject: 

I want a 500 and I want it NOW!

(good work mate)

Page 1 of 11 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/