Author Topic: JXD A1000 Firmware Unpacker/Packer in PHP  (Read 1302 times)

kurtbilisim (OP)

JXD A1000 Firmware Unpacker/Packer in PHP
« on: October 27, 2015, 03:07:29 pm »
So I got this device but I don't like emulators stretching the image across the screen. There's a video aspect ratio setting but it doesn't seem to work.

Hoping for a solution I got the firmware here http://www.jxdofficial.com/firmware (A1000_20130531) It is looking like the same firmware when the device came but for some reason the camera doesn't work now.

Hoping maybe I can modify the firmware, I coded this PHP script for unpacking/packing. I can change the images but don't have any idea about IMG or RAP files. I'm sharing this incase someone can come up with a solution.

I'd like emulators to show 1x size centered on screen and without smooth effect. It would be nice if you could fix the camera as well. Then I also noticed files related to radio, unlocked the menu for it but it also doesn't work (despite headphones inserted) so maybe that can be fixed as well.

You can install EasyPHP for this. Put "A1000EN-UOA-BTR-YB20120406-8110C-100C-CG0307-NOFM.img" file from the firmware archive near this script. Uncomment "//imgExtract();" line and run it. It should create a DATA folder with all files inside. There's a folder named "0" in it. Keep that as backup, copy and rename the new one "HOME". Now you can modify files in HOME and repack. I suggest deleting "thumbs.db" files inside, they are probably unnecessary.

When you want to pack, comment that line back and then uncomment "//imgPack();" line and run the script. This should produce a "+A1000EN-UOA-BTR-YB20120406-8110C-100C-CG0307-NOFM.img" file in the same folder (Notice + in front).

!Warning: If you hadn't changed your firmware before, don't do this since the camera becomes broken.!

I hope someone can make use of this and solve my problems. There are a few bytes I don't know the meanings but packed firmware seems to work regardless. I'm guessing they are timestamps or something.

Code: [Select]
<html><head><style>body {font-family:sans-serif; font-size:12px; }</style></head><body><?php

set_time_limit
(3000);
ini_set('memory_limit','300M');

//imgExtract();
//imgPack();

function imgExtract(){
    if(!
file_exists('DATA')) mkdir('DATA');
    
$content file_get_contents('A1000EN-UOA-BTR-YB20120406-8110C-100C-CG0307-NOFM.img');
    
    
// u1=time?
    
$header unpack('Vu1/Vfiles/Vsize/Vversion/Z16name',$content);
    
print_r($header);
    
    
$files = array();
    
    
$pos 32;
    for(
$n=0,$m=$header['files']; $n<$m$n++,$pos+=32){
        
// u1=permission?(always 7) u2=subfolder+2(. & ..)? u3=always 26280336
        
array_push($files,unpack('vtype/vu1/Vu2/Vu3/Vsize/Vtime/Vstart/Z8id',substr($content,$pos,32)));
        
$files[$n]['path'] = 'DATA/'.$n;
    }
    
    for(
$n=0,$m=count($files); $n<$m$n++){
        if(
$files[$n]['type']=="1"){
            
mkdir($files[$n]['path']);
        } else if(
$files[$n]['type']=="8"){
            
$data substr($content,$files[$n]['start'],$files[$n]['size']);
            
file_put_contents($files[$n]['path'],$data);
        } else {
            exit(
'Unknown File Type!');
        }
    }
    
    for(
$n=0,$m=count($files); $n<$m$n++){
        if(
$files[$n]['type']=="1"){
            
$list substr($content,$files[$n]['start'],$files[$n]['size']);
            
$pos 0;
            while(
$pos<strlen($list)){
                
$data unpack('Vid/Vend',substr($list,$pos,8));
                
$data unpack('Vid/Vend/Z'.($data['end']-($pos+8)).'name',substr($list,$pos,$data['end']-$pos));
                echo 
'<br/>'.$data['id'].' - '.($data['end']-($pos+8)).' - '.$data['name'];
                if(
$data['name']!='.' && $data['name']!='..'){
                    
rename($files[$data['id']]['path'],$files[$n]['path'].'/'.$data['name']);
                    
$files[$data['id']]['path'] = $files[$n]['path'].'/'.$data['name'];
                }
                
$pos $data['end'];
            }
        }
    }
}


function 
imgPack(){
    
$files = array();
    
$files[0] = array( 'type'=>1'parent'=>0'name'=>'HOME''path'=>'DATA/HOME''folders'=>1);
    
    
$f=0;
    while(
$f<count($files)){
        if(
$files[$f]['type']==1){
            
$files[$f]['folders']++;
            
$folder scandir($files[$f]['path']);
            for(
$n=0,$m=count($folder); $n<$m$n++){
                if(
$folder[$n]!='.' && $folder[$n]!='..'){
                    if(
is_dir($files[$f]['path'].'/'.$folder[$n])) {
                        
$type 1;
                        
$files[$f]['folders']++;
                    } else {
                        
$type 8;
                    }
                    
array_push($files,array( 'type'=>$type'parent'=>$f'name'=>$folder[$n], 'path'=>$files[$f]['path'].'/'.$folder[$n], 'folders'=>1));
                }
            }
        }
        
$f++;
    }
    
    
$newH '';
    
$newC '';
    
$pos 32 + (count($files)*32);
    for(
$n=0,$m=count($files); $n<$m$n++){
        if(
$files[$n]['type']==1){
            
$size 64;
            
$newC .= pack('VVZ24VVZ24'$n32'.'$files[$n]['parent'], 64'..');
            for(
$a=0,$b=count($files); $a<$b$a++){
                if(
$files[$a]['parent']==$n && $files[$a]['type']==&& $a!=$n){
                    
$length strlen($files[$n]['name']);
                    if(
$length<24$length=24; else if($length<56$length=56;
                    
$size += ($length 8);
                    
$newC .= pack('VVZ'.$length$a$size$files[$a]['name']);
                }
            }
            for(
$a=0,$b=count($files); $a<$b$a++){
                if(
$files[$a]['parent']==$n && $files[$a]['type']!=&& $a!=$n){
                    
$length strlen($files[$n]['name']);
                    if(
$length<24$length=24; else if($length<56$length=56;
                    
$size += ($length 8);
                    
$newC .= pack('VVZ'.$length$a$size$files[$a]['name']);
                }
            }
        } else {
            
$size filesize($files[$n]['path']);
            
$newC .= file_get_contents($files[$n]['path']);
        }
        
$id '<'.str_pad($n6' 'STR_PAD_LEFT).'>';
        
$newH .= pack('vvVVVVV'$files[$n]['type'], 7$files[$n]['folders'], 26280336$size0$pos) . $id;
        
$pos += $size;
        if(
$size%32>0) for($x=$size%32;$x<32;$x++){
            
$newC .= "\x00";
            
$pos ++;
        }
    }
    
    
$new pack("VVVVZ16"1383034158count($files), 32 strlen($newH) + strlen($newC), 67507472'EN-YB0406') . $newH $newC;
    
file_put_contents('+A1000EN-UOA-BTR-YB20120406-8110C-100C-CG0307-NOFM.img',$new);
}

echo 
'<br/><br/>DONE!';
exit(
0);

zhongtiao1

Re: JXD A1000 Firmware Unpacker/Packer in PHP
« Reply #1 on: October 28, 2015, 02:33:19 pm »
Have you tried using 7zip to unpack the IMG/rap files as a test?

kurtbilisim (OP)

Re: JXD A1000 Firmware Unpacker/Packer in PHP
« Reply #2 on: October 28, 2015, 02:41:40 pm »
Have you tried using 7zip to unpack the IMG/rap files as a test?

Rar or 7z don't seem to recognise their format.

Btw, the firmware updating software had a 2nd tab and I found out that could be used for packing. I'll read some articles on this page to see if I learn anything I can make use of. http://openschemes.com/2010/01/30/building-spmp8k-os-images/2/

zhongtiao1

Re: JXD A1000 Firmware Unpacker/Packer in PHP
« Reply #3 on: October 28, 2015, 03:49:36 pm »
Have you tried using 7zip to unpack the IMG/rap files as a test?

Rar or 7z don't seem to recognise their format.

Btw, the firmware updating software had a 2nd tab and I found out that could be used for packing. I'll read some articles on this page to see if I learn anything I can make use of. http://openschemes.com/2010/01/30/building-spmp8k-os-images/2/
Did you try renaming the files? It may just be a different file, but with a different extension

kurtbilisim (OP)

Re: JXD A1000 Firmware Unpacker/Packer in PHP
« Reply #4 on: October 28, 2015, 03:57:22 pm »
Did you try renaming the files? It may just be a different file, but with a different extension

Yeah, doesn't help. I looked in them with a hex editor and they start with "MMP" letters. Multiple MMPs can be seen throughout the file so maybe that's some kind of chunk identifier. Is anyone familiar with it?

 

Post a new topic
Post a new topic