|
@@ -108,6 +108,111 @@ public class FlashFSUnWiggler {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ public static void unpackCSRFS(File firmware, File outfolder)
|
|
|
+ {
|
|
|
+ try (RandomAccessFile f = new RandomAccessFile(firmware,"r")) {
|
|
|
+ byte[] javaisDipshit = new byte[4];
|
|
|
+ byte[] javaShorty = new byte[2];
|
|
|
+ int magic = f.readInt(); //ignored
|
|
|
+ f.read(javaisDipshit);
|
|
|
+ int sizeFile = Ints.fromBytes(javaisDipshit[0],javaisDipshit[1],javaisDipshit[2],javaisDipshit[3]);
|
|
|
+ //old shit calculates in words and not in bytes on sizes
|
|
|
+ if((sizeFile*2)>f.length())
|
|
|
+ {
|
|
|
+
|
|
|
+ System.out.println(sizeFile);
|
|
|
+ System.err.println("ZOINKS!!!, mismatch");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ f.read(javaisDipshit);
|
|
|
+ int countFileRecords = (Ints.fromBytes(javaisDipshit[2],javaisDipshit[3],javaisDipshit[0],javaisDipshit[1]) &0x00FFFFFF);
|
|
|
+ System.out.println(countFileRecords);
|
|
|
+ int countFileRecordsXXX = (Ints.fromBytes(javaisDipshit[1],javaisDipshit[0],javaisDipshit[3],javaisDipshit[2])&0x00FFFFFF);
|
|
|
+ System.out.println(countFileRecordsXXX);
|
|
|
+ f.seek(8);
|
|
|
+ FileMetadata[] files = new FileMetadata[countFileRecords];
|
|
|
+ for(int i=0;i<countFileRecords;i++)
|
|
|
+ {
|
|
|
+ FileMetadata fmd = new FileMetadata();
|
|
|
+ f.read(javaisDipshit);
|
|
|
+ int sizeAndFlags = Ints.fromBytes(javaisDipshit[2],javaisDipshit[3],javaisDipshit[0],javaisDipshit[1]);
|
|
|
+ int size = sizeAndFlags&0x00FFFFFF;
|
|
|
+ System.out.println(sizeAndFlags);
|
|
|
+ System.out.println(size);
|
|
|
+
|
|
|
+ fmd.offset_fname=size;
|
|
|
+ if((sizeAndFlags&0xFF000000)<0)
|
|
|
+ {
|
|
|
+ System.out.println("dir");
|
|
|
+ fmd.is_dir=true;
|
|
|
+ }
|
|
|
+ f.read(javaisDipshit);
|
|
|
+ fmd.offset=Ints.fromBytes(javaisDipshit[2],javaisDipshit[3],javaisDipshit[0],javaisDipshit[1]);
|
|
|
+ f.read(javaisDipshit);
|
|
|
+ fmd.length=Ints.fromBytes(javaisDipshit[2],javaisDipshit[3],javaisDipshit[0],javaisDipshit[1]);
|
|
|
+ files[i]=fmd;
|
|
|
+ }
|
|
|
+ for(int i=0;i<countFileRecords;i++)
|
|
|
+ {
|
|
|
+ FileMetadata fmd = files[i];
|
|
|
+ if(fmd.offset_fname==0)
|
|
|
+ {
|
|
|
+ fmd.filename="";
|
|
|
+ fmd.parentpath="";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ f.seek(fmd.offset_fname*2); //words again...
|
|
|
+ f.read(javaShorty);
|
|
|
+ short fnlength = Shorts.fromBytes(javaShorty[1],javaShorty[0]);
|
|
|
+ byte[] fname = new byte[fnlength*2];
|
|
|
+ f.read(fname);
|
|
|
+ byte[] fname_real = new byte[fnlength];
|
|
|
+ for(int fi=0;fi<fname_real.length;fi++)
|
|
|
+ {
|
|
|
+ fname_real[i]=fname[i*2+1]; //zapping each upper bit...
|
|
|
+ }
|
|
|
+
|
|
|
+ String s = File.separator+new String(fname);
|
|
|
+ fmd.filename=s;
|
|
|
+ }
|
|
|
+ if(fmd.is_dir)
|
|
|
+ {
|
|
|
+ new File(outfolder+fmd.parentpath+fmd.filename).mkdirs();
|
|
|
+
|
|
|
+ for(int j= 0;j< fmd.length;j++)
|
|
|
+ {
|
|
|
+ int subfiles = fmd.offset+j-1;
|
|
|
+ files[subfiles].parentpath=fmd.parentpath+fmd.filename;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ System.out.println("Reading:"+fmd.parentpath+fmd.filename+"("+fmd.length+")@"+fmd.offset);
|
|
|
+ byte[] filecontent = new byte[fmd.length*2];
|
|
|
+ if(fmd.length>0)
|
|
|
+ {
|
|
|
+ f.seek(fmd.offset*2);
|
|
|
+ f.read(filecontent);
|
|
|
+
|
|
|
+ RandomAccessFile out = new RandomAccessFile(outfolder+fmd.parentpath+fmd.filename,"rw");
|
|
|
+ out.write(filecontent);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
public static void unpackQCC512DFU(File firmware, File outfolder)
|
|
|
{
|
|
|
System.out.println("0x00!");
|