|
@@ -1,437 +1,68 @@
|
|
package de.nplusc.izc.senabitwiggler;
|
|
package de.nplusc.izc.senabitwiggler;
|
|
|
|
|
|
-import com.google.common.base.Charsets;
|
|
|
|
-import com.google.common.base.Strings;
|
|
|
|
-import com.google.common.primitives.Ints;
|
|
|
|
-import com.google.common.primitives.Longs;
|
|
|
|
-import com.google.common.primitives.Shorts;
|
|
|
|
-import org.yaml.snakeyaml.Yaml;
|
|
|
|
-
|
|
|
|
import java.io.*;
|
|
import java.io.*;
|
|
-import java.lang.reflect.Field;
|
|
|
|
-import java.nio.ByteBuffer;
|
|
|
|
-import java.nio.charset.Charset;
|
|
|
|
-import java.security.MessageDigest;
|
|
|
|
-import java.security.NoSuchAlgorithmException;
|
|
|
|
-import java.util.Arrays;
|
|
|
|
-import java.util.Locale;
|
|
|
|
-
|
|
|
|
-public class EntryPoint
|
|
|
|
-{
|
|
|
|
- public static void main(String[] args)
|
|
|
|
- {
|
|
|
|
- if(args.length!=4)
|
|
|
|
- {
|
|
|
|
- printUsage();
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- boolean extract = args[0].equalsIgnoreCase("extract");
|
|
|
|
- boolean immport = args[0].equalsIgnoreCase("import");
|
|
|
|
-
|
|
|
|
- boolean regularfuckery = extract||immport;
|
|
|
|
-
|
|
|
|
- boolean vmexport = args[0].equalsIgnoreCase("extractvm");
|
|
|
|
- boolean importvm = args[0].equalsIgnoreCase("importvm");
|
|
|
|
|
|
|
|
- boolean vmfuckery = vmexport||importvm;
|
|
|
|
-
|
|
|
|
- boolean disasm = args[0].equalsIgnoreCase("disasm");
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- boolean incoming = immport|importvm;
|
|
|
|
|
|
+import org.yaml.snakeyaml.Yaml;
|
|
|
|
+import picocli.CommandLine;
|
|
|
|
+import picocli.CommandLine.Command;
|
|
|
|
+import picocli.CommandLine.Option;
|
|
|
|
+import picocli.CommandLine.Parameters;
|
|
|
|
|
|
- boolean outgoing = extract||vmexport||disasm;
|
|
|
|
|
|
+public class EntryPoint implements Runnable
|
|
|
|
+{
|
|
|
|
+ @Parameters(index = "0", description = "The file whose checksum to calculate.")
|
|
|
|
+ private Modes mode;
|
|
|
|
|
|
- if(!(extract||immport||vmexport||importvm||disasm))
|
|
|
|
- {
|
|
|
|
- printUsage();
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
|
|
- boolean shorty = args[1].equalsIgnoreCase("short");
|
|
|
|
- boolean longy = args[1].equalsIgnoreCase("long");
|
|
|
|
|
|
+ @Parameters(index = "1", description = "Firmware File to dissect/reassemble")
|
|
|
|
+ private File input;
|
|
|
|
|
|
- if(!(shorty||longy)&®ularfuckery)
|
|
|
|
- {
|
|
|
|
- printUsage();
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- else if(vmfuckery||disasm)
|
|
|
|
- {
|
|
|
|
- shorty = false;
|
|
|
|
- longy = false;
|
|
|
|
- }
|
|
|
|
|
|
+ @Parameters(index = "2", description = "Disassembled Data Folder")
|
|
|
|
+ private File output;
|
|
|
|
|
|
- if(shorty)
|
|
|
|
- {
|
|
|
|
- System.out.println("Need to debug the format more first. Aborting now");
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+ @Parameters(index = "3", description = "Head")
|
|
|
|
+ private String headset;
|
|
|
|
|
|
- File input = new File(args[2]);
|
|
|
|
- if(incoming&&input.exists())
|
|
|
|
- {
|
|
|
|
- System.out.println("Refusing to overwrite a existing firmware archive. Use a fresh name instead");
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- if(outgoing&&!input.exists())
|
|
|
|
- {
|
|
|
|
- System.out.println("Can't extract thin air. Give a file please");
|
|
|
|
- }
|
|
|
|
|
|
+ public static String SoxPath = "";
|
|
|
|
+ public static String BlueLabPath = "";
|
|
|
|
|
|
- if(outgoing&&!disasm)
|
|
|
|
- {
|
|
|
|
- makeSureThatOutFolderIsCreated(args[3]);
|
|
|
|
- }
|
|
|
|
|
|
+ public static final String APPDIR = new File(EntryPoint.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getParentFile().getParent();
|
|
|
|
|
|
- if(extract)
|
|
|
|
|
|
+ public static void main(String[] args)
|
|
|
|
+ {
|
|
|
|
+ Yaml y = new Yaml();
|
|
|
|
+ File cfg = new File(APPDIR+File.separator+"config.yml");
|
|
|
|
+ if(cfg.exists())
|
|
{
|
|
{
|
|
- if(longy)
|
|
|
|
- {
|
|
|
|
- try {
|
|
|
|
- extractFirmwareLong(input,args[3]);
|
|
|
|
- } catch (InputInvalidException e) {
|
|
|
|
- System.out.println("Zarf! File was bad");
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
|
|
+ try {
|
|
|
|
+ Configuration config = y.loadAs(new FileReader(cfg),Configuration.class);
|
|
|
|
+ SoxPath=config.getSoxPath();
|
|
|
|
+ BlueLabPath=config.getBlueLabPath();
|
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
|
+ System.err.println("Hurz");
|
|
|
|
+ e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- else if(immport)
|
|
|
|
|
|
+ else
|
|
{
|
|
{
|
|
- if(longy)
|
|
|
|
- {
|
|
|
|
- assembleFirmware(input,args[3]);
|
|
|
|
|
|
+ Configuration config = new Configuration();
|
|
|
|
+ config.setBlueLabPath("C:\\ADK_CSR867x.WIN4.3.1.5\\tools\\bin\\");
|
|
|
|
+ config.setSoxPath("sox.exe");
|
|
|
|
+ try {
|
|
|
|
+ y.dump(config, new FileWriter(cfg));
|
|
|
|
+ System.err.println("Configuration needed. Check the generated config.yml");
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ System.err.println("Failed to initialize config");
|
|
|
|
+ e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
+ System.exit(0);
|
|
}
|
|
}
|
|
- else if(vmexport)
|
|
|
|
- {
|
|
|
|
- extractVmImage(input,args[3]);
|
|
|
|
- }
|
|
|
|
- else if(disasm)
|
|
|
|
- {
|
|
|
|
- XAPDisAsm.Disassemble(args[2],args[3]);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private static void assembleFirmware(File output, String inputfolder)
|
|
|
|
- {
|
|
|
|
- Yaml y = new Yaml();
|
|
|
|
- try {
|
|
|
|
- LongHeader h = y.loadAs(new FileReader(new File(inputfolder+File.separator+"header.yml")),LongHeader.class);
|
|
|
|
- RandomAccessFile f = new RandomAccessFile(output,"rw");
|
|
|
|
- f.write(h.getVersion_raw());
|
|
|
|
- f.write(LongToRawBytes(h.getMagicShit()));
|
|
|
|
- f.write(LongToRawBytes(h.getRandom_id()));
|
|
|
|
- HeaderRecord[] records = h.getHeaderRecords();
|
|
|
|
- int count = records.length;
|
|
|
|
- f.write(LongToRawBytes(count));
|
|
|
|
- long offset = records[0].getOffset();
|
|
|
|
- for(int i=0;i<count;i++)
|
|
|
|
- {
|
|
|
|
- HeaderRecord r = records[i];
|
|
|
|
- File handle = new File(inputfolder+File.separator+r.getFilename());
|
|
|
|
- r.setLength(handle.length());
|
|
|
|
- r.setOffset(offset+0);
|
|
|
|
- offset+=handle.length();
|
|
|
|
-
|
|
|
|
- RandomAccessFile file = new RandomAccessFile(handle,"r");
|
|
|
|
- byte[] bfr = new byte[(int)handle.length()];
|
|
|
|
- file.read(bfr);
|
|
|
|
- byte[] newmd5 = MessageDigest.getInstance("MD5").digest(bfr);
|
|
|
|
- r.setMd5sum(newmd5);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- for(int i=0;i<count;i++)
|
|
|
|
- {
|
|
|
|
- HeaderRecord r = records[i];
|
|
|
|
- f.write(LongToRawBytes(r.getShortflag_1()));
|
|
|
|
- f.write(LongToRawBytes(r.getShortflag_2()));
|
|
|
|
- f.write(LongToRawBytes(r.getOffset()));
|
|
|
|
- f.write(LongToRawBytes(r.getLength()));
|
|
|
|
- f.write(r.getMd5sum());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- for(int i=0;i<count;i++)
|
|
|
|
- {
|
|
|
|
- HeaderRecord r = records[i];
|
|
|
|
- f.write(LongToRawBytes(r.getShortflag_1()));
|
|
|
|
- f.write(LongToRawBytes(r.getShortflag_2()));
|
|
|
|
- f.write(LongToRawBytes(r.getOffset()));
|
|
|
|
- f.write(LongToRawBytes(r.getLength()));
|
|
|
|
- f.write(LongToRawBytes(r.getFlag_1()));
|
|
|
|
- f.write(LongToRawBytes(r.getFlag_2()));
|
|
|
|
- f.write(LongToRawBytes(r.getFlag_3()));
|
|
|
|
- f.write(LongToRawBytes(r.getFlag_4()));
|
|
|
|
- f.write(LongToRawBytes(r.getFlag_5()));
|
|
|
|
- f.write(LongToRawBytes(r.getUnknown_id()));
|
|
|
|
- f.write(r.getPadding());
|
|
|
|
-
|
|
|
|
- byte[] filenamebytes = r.getFilename().getBytes(Charsets.US_ASCII);
|
|
|
|
- byte[] filename = new byte[128];
|
|
|
|
- for(int j=0;j<128;j++)
|
|
|
|
- {
|
|
|
|
- if(j<filenamebytes.length)
|
|
|
|
- {
|
|
|
|
- filename[j]=filenamebytes[j];
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- filename[j]=0;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- f.write(filename);
|
|
|
|
- f.write(r.getMd5sum());
|
|
|
|
- }
|
|
|
|
|
|
|
|
- for(int i=0;i<count;i++)
|
|
|
|
- {
|
|
|
|
- HeaderRecord r = records[i];
|
|
|
|
- File handle = new File(inputfolder+File.separator+r.getFilename());
|
|
|
|
- RandomAccessFile file = new RandomAccessFile(handle,"r");
|
|
|
|
- byte[] bfr = new byte[(int)handle.length()];
|
|
|
|
- file.read(bfr);
|
|
|
|
- f.write(bfr);
|
|
|
|
- }
|
|
|
|
- f.close();
|
|
|
|
-
|
|
|
|
- } catch (FileNotFoundException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- } catch (NoSuchAlgorithmException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
|
|
+ CommandLine cl = new CommandLine(new EntryPoint());
|
|
|
|
+ cl.setCaseInsensitiveEnumValuesAllowed(true);
|
|
|
|
+ cl.execute(args);
|
|
}
|
|
}
|
|
|
|
|
|
- private static void extractFirmwareLong(File input, String output) throws InputInvalidException {
|
|
|
|
- byte filler = 0x00;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- try (RandomAccessFile f = new RandomAccessFile(input,"r")) {
|
|
|
|
- LongHeader hdr = new LongHeader();
|
|
|
|
- byte[] headermagic = new byte[24];
|
|
|
|
- f.read(headermagic);
|
|
|
|
- String versionName = new String(headermagic, Charsets.US_ASCII).split("\0")[0]; //hack, can be done since strings are shorty. https://stackoverflow.com/a/8843313/1405227
|
|
|
|
- hdr.setVersion_raw(headermagic);
|
|
|
|
- hdr.setVersion(versionName);
|
|
|
|
- //12 more bytes
|
|
|
|
- byte[] magic = new byte[4];
|
|
|
|
- f.read(magic);
|
|
|
|
-
|
|
|
|
- hdr.setMagicShit(Longs.fromBytes(filler,filler,filler,filler,magic[3],magic[2],magic[1],magic[0]));
|
|
|
|
-
|
|
|
|
- byte[] unknown_id = new byte[4];
|
|
|
|
-
|
|
|
|
- f.read(unknown_id);
|
|
|
|
-
|
|
|
|
- hdr.setRandom_id(Longs.fromBytes(filler,filler,filler,filler,unknown_id[3],unknown_id[2],unknown_id[1],unknown_id[0]));
|
|
|
|
-
|
|
|
|
- byte[] count_raw = new byte[4];
|
|
|
|
- f.read(count_raw);
|
|
|
|
-
|
|
|
|
- long count_l = (Longs.fromBytes(filler,filler,filler,filler,count_raw[3],count_raw[2],count_raw[1],count_raw[0]));
|
|
|
|
-
|
|
|
|
- if(count_l>Integer.MAX_VALUE)
|
|
|
|
- {
|
|
|
|
- throw new InputInvalidException();
|
|
|
|
- }
|
|
|
|
- int count = (int)count_l;
|
|
|
|
- HeaderRecord[] records = new HeaderRecord[count];
|
|
|
|
- byte[] skip = new byte[count*32]; /*skipping over shorty header, repeats content with long one*/
|
|
|
|
- f.read(skip);
|
|
|
|
- for(int i=0;i<count;i++)
|
|
|
|
- {
|
|
|
|
- HeaderRecord record = new HeaderRecord();
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- byte[] flags1 = new byte[4];
|
|
|
|
- f.read(flags1);
|
|
|
|
-
|
|
|
|
- record.setShortflag_1(Longs.fromBytes(filler,filler,filler,filler,flags1[3],flags1[2],flags1[1],flags1[0]));
|
|
|
|
-
|
|
|
|
- byte[] flags2 = new byte[4];
|
|
|
|
- f.read(flags2);
|
|
|
|
-
|
|
|
|
- record.setShortflag_2(Longs.fromBytes(filler,filler,filler,filler,flags2[3],flags2[2],flags2[1],flags2[0]));
|
|
|
|
-
|
|
|
|
- byte[] offset = new byte[4];
|
|
|
|
- f.read(offset);
|
|
|
|
-
|
|
|
|
- record.setOffset(Longs.fromBytes(filler,filler,filler,filler,offset[3],offset[2],offset[1],offset[0]));
|
|
|
|
-
|
|
|
|
- byte[] length = new byte[4];
|
|
|
|
- f.read(length);
|
|
|
|
-
|
|
|
|
- record.setLength(Longs.fromBytes(filler,filler,filler,filler,length[3],length[2],length[1],length[0]));
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- long[] flags = new long[5];
|
|
|
|
- for(int j=0;j<5;j++)
|
|
|
|
- {
|
|
|
|
- byte[] flags_raw = new byte[4];
|
|
|
|
- f.read(flags_raw);
|
|
|
|
-
|
|
|
|
- flags[j] = (Longs.fromBytes(filler,filler,filler,filler,flags_raw[3],flags_raw[2],flags_raw[1],flags_raw[0]));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- record.setFlag_1(flags[0]);
|
|
|
|
- record.setFlag_2(flags[1]);
|
|
|
|
- record.setFlag_3(flags[2]);
|
|
|
|
- record.setFlag_4(flags[3]);
|
|
|
|
- record.setFlag_5(flags[4]);
|
|
|
|
-
|
|
|
|
- byte[] unknown = new byte[4];
|
|
|
|
- f.read(unknown);
|
|
|
|
-
|
|
|
|
- record.setUnknown_id(Longs.fromBytes(filler,filler,filler,filler,unknown[3],unknown[2],unknown[1],unknown[0]));
|
|
|
|
-
|
|
|
|
- byte[] padding = new byte[128];
|
|
|
|
-
|
|
|
|
- f.read(padding);
|
|
|
|
-
|
|
|
|
- record.setPadding(padding);
|
|
|
|
-
|
|
|
|
- byte[] filename_raw = new byte[128];
|
|
|
|
-
|
|
|
|
- f.read(filename_raw);
|
|
|
|
-
|
|
|
|
- String filename = new String(filename_raw, Charsets.US_ASCII).split("\0")[0]; //hack, can be done since strings are shorty. https://stackoverflow.com/a/8843313/1405227
|
|
|
|
- record.setFilename(filename);
|
|
|
|
-
|
|
|
|
- byte[] md5 = new byte[16];
|
|
|
|
-
|
|
|
|
- f.read(md5);
|
|
|
|
-
|
|
|
|
- record.setMd5sum(md5);
|
|
|
|
-
|
|
|
|
- records[i]=record;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- hdr.setHeaderRecords(records);
|
|
|
|
- Yaml y = new Yaml();
|
|
|
|
-
|
|
|
|
- y.dump(hdr, new FileWriter(new File(output+File.separator+"header.yml")));
|
|
|
|
-
|
|
|
|
- for(int i=0;i<records.length;i++)
|
|
|
|
- {
|
|
|
|
- HeaderRecord r = records[i];
|
|
|
|
- String target = output+File.separator+r.getFilename();
|
|
|
|
- long offset = r.getOffset();
|
|
|
|
- int len = (int)r.getLength();
|
|
|
|
- byte[] file = new byte[len];
|
|
|
|
- f.seek(offset);
|
|
|
|
- f.read(file);
|
|
|
|
- RandomAccessFile out = new RandomAccessFile(target,"rw");
|
|
|
|
- out.write(file);
|
|
|
|
- out.close();
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- } catch (FileNotFoundException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private static void extractVmImage(File input, String output)
|
|
|
|
- {
|
|
|
|
- byte filler = 0x00;
|
|
|
|
- try (RandomAccessFile f = new RandomAccessFile(input,"r")) {
|
|
|
|
- VMImageHeader h = new VMImageHeader();
|
|
|
|
-
|
|
|
|
- long len = f.length()/2;
|
|
|
|
- if(len>Integer.MAX_VALUE)
|
|
|
|
- {
|
|
|
|
- System.out.println("Ugggh, File too big");
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- short[] checksumarray = new short[(int)len];
|
|
|
|
-
|
|
|
|
- for(int i=0;i<len;i++)
|
|
|
|
- {
|
|
|
|
- checksumarray[i]=f.readShort();
|
|
|
|
- }
|
|
|
|
- if(xorsum(checksumarray)!=0)
|
|
|
|
- {
|
|
|
|
- System.out.println("Smells like Dead Beef, the data seems to be corrupt");
|
|
|
|
- }
|
|
|
|
- f.seek(0);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- byte[] magic = new byte[8];
|
|
|
|
- f.read(magic);
|
|
|
|
-
|
|
|
|
- h.setHeader(magic);
|
|
|
|
-
|
|
|
|
- byte[] shortPants = new byte[2];
|
|
|
|
- byte[] integer = new byte[4];
|
|
|
|
- f.read(shortPants);
|
|
|
|
- h.setUnknownMagic(Ints.fromBytes(filler,filler,shortPants[0],shortPants[1]));
|
|
|
|
-
|
|
|
|
- f.read(integer);
|
|
|
|
- h.setSizeCodeInWords(Longs.fromBytes(filler,filler,filler,filler,integer[0],integer[1],integer[2],integer[3]));
|
|
|
|
- f.read(shortPants);
|
|
|
|
- h.setSzConstantsInWords(Ints.fromBytes(filler,filler,shortPants[0],shortPants[1]));
|
|
|
|
- f.read(shortPants);
|
|
|
|
- h.setSzGlobalsInWords(Ints.fromBytes(filler,filler,shortPants[0],shortPants[1]));
|
|
|
|
- f.read(shortPants);
|
|
|
|
- h.setSzStack(Ints.fromBytes(filler,filler,shortPants[0],shortPants[1]));
|
|
|
|
- f.read(shortPants);
|
|
|
|
- h.setAddressMain(Ints.fromBytes(filler,filler,shortPants[0],shortPants[1]));
|
|
|
|
- f.read(shortPants);
|
|
|
|
- h.setUnknownFlag(Shorts.fromBytes(shortPants[0],shortPants[1]));
|
|
|
|
- f.read(shortPants);
|
|
|
|
- h.setSyscallCompatId(Ints.fromBytes(filler,filler,shortPants[0],shortPants[1]));
|
|
|
|
- byte[] trapsets = new byte[8];
|
|
|
|
- f.read(trapsets);
|
|
|
|
- h.setTrapSet(trapsets);
|
|
|
|
- h.setTrapSetStringlied(bytesToHex(trapsets));
|
|
|
|
- f.read(integer);
|
|
|
|
- h.setSizeFileInWords(Longs.fromBytes(filler,filler,filler,filler,integer[0],integer[1],integer[2],integer[3]));
|
|
|
|
- f.read(shortPants);
|
|
|
|
- h.setChksum(Shorts.fromBytes(shortPants[0],shortPants[1]));
|
|
|
|
- f.read(shortPants);
|
|
|
|
- h.setUnknown_parameter_b(Shorts.fromBytes(shortPants[0],shortPants[1]));
|
|
|
|
- f.read(integer);
|
|
|
|
- h.setEtcetcaddress(Longs.fromBytes(filler,filler,filler,filler,integer[0],integer[1],integer[2],integer[3]));
|
|
|
|
-
|
|
|
|
- f.read(shortPants);
|
|
|
|
- h.setUnknown_twiddled_bits(Shorts.fromBytes(shortPants[0],shortPants[1]));
|
|
|
|
-
|
|
|
|
- Yaml y = new Yaml();
|
|
|
|
-
|
|
|
|
- y.dump(h, new FileWriter(new File(output+File.separator+"header.yml")));
|
|
|
|
-
|
|
|
|
- f.seek(0);
|
|
|
|
-
|
|
|
|
- RandomAccessFile hdrRaw = new RandomAccessFile(output+File.separator+"header.bin","rw");
|
|
|
|
- byte[] header = new byte[0x30];
|
|
|
|
- f.read(header);
|
|
|
|
- hdrRaw.write(header);
|
|
|
|
- byte[] code = new byte[(int)h.getSizeCodeInWords()*2];
|
|
|
|
- f.read(code);
|
|
|
|
- RandomAccessFile codeRaw = new RandomAccessFile(output+File.separator+"code.bin","rw");
|
|
|
|
- codeRaw.write(code);
|
|
|
|
-
|
|
|
|
- byte[] constants = new byte[h.getSzConstantsInWords()*2];
|
|
|
|
- f.read(constants);
|
|
|
|
- RandomAccessFile dataRaw = new RandomAccessFile(output+File.separator+"data.bin","rw");
|
|
|
|
- dataRaw.write(constants);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- } catch (FileNotFoundException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -451,51 +82,60 @@ public class EntryPoint
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- private static byte[] LongToRawBytes(long l)
|
|
|
|
- {
|
|
|
|
- byte[] tmp = Longs.toByteArray(l);
|
|
|
|
- return new byte[]{tmp[7],tmp[6],tmp[5],tmp[4]};
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private static final char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();
|
|
|
|
- public static String bytesToHex(byte[] bytes) {
|
|
|
|
- char[] hexChars = new char[bytes.length * 2];
|
|
|
|
- for (int j = 0; j < bytes.length; j++) {
|
|
|
|
- int v = bytes[j] & 0xFF;
|
|
|
|
- hexChars[j * 2] = HEX_ARRAY[v >>> 4];
|
|
|
|
- hexChars[j * 2 + 1] = HEX_ARRAY[v & 0x0F];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- String hexxit = new String(hexChars).toLowerCase(Locale.ROOT);
|
|
|
|
- //hexxit = hexxit.replaceAll("^0+", "");
|
|
|
|
- return hexxit;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private static void makeSureThatOutFolderIsCreated(String output)
|
|
|
|
- {
|
|
|
|
- File od = (new File(output));
|
|
|
|
- if(!(od.exists()&&od.isDirectory()))
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ //TODO check and init config file
|
|
|
|
+ switch(mode)
|
|
{
|
|
{
|
|
- if(!od.mkdirs())
|
|
|
|
- {
|
|
|
|
- System.err.println("WTF! somethint ate shit");
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public static short xorsum(short[] filewords)
|
|
|
|
- {
|
|
|
|
- short xorsum = 0;
|
|
|
|
- for(int i=0;i<filewords.length;i++)
|
|
|
|
- {
|
|
|
|
- xorsum ^= filewords[i];
|
|
|
|
|
|
+ case ExtractSenaBin:
|
|
|
|
+ try {
|
|
|
|
+ Utils.makeSureThatOutFolderIsCreated(output.getPath());
|
|
|
|
+ FirmwareWrapperExtraction.extractFirmwareLong(input,output.getPath());
|
|
|
|
+ } catch (InputInvalidException e) {
|
|
|
|
+ System.out.println("Zarf! File was bad");
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case ImportSenaBin:
|
|
|
|
+ FirmwareWrapperExtraction.assembleFirmware(input,output.getPath());
|
|
|
|
+ break;
|
|
|
|
+ case ExtractVMImage:
|
|
|
|
+ VmAppFIleExtraction.extractVmImage(input,output.getPath());
|
|
|
|
+ break;
|
|
|
|
+ case ImportVMImage:
|
|
|
|
+ throw new UnsupportedOperationException("Not Implemented yet");
|
|
|
|
+ //break;
|
|
|
|
+ case DisassembleXAP:
|
|
|
|
+ XAPDisAsm.Disassemble(input.getPath(),output.getPath());
|
|
|
|
+ break;
|
|
|
|
+ case ExtractForPrompts:
|
|
|
|
+ try {
|
|
|
|
+ PromptHandlerSuite.handlePrompts(input,output,headset);
|
|
|
|
+ } catch (InputInvalidException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case ReassembleForPrompts:
|
|
|
|
+ try {
|
|
|
|
+ PromptHandlerSuite.assembleWithNewPrompts(input,output,headset);
|
|
|
|
+ } catch (InputInvalidException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
- return xorsum;
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+enum Modes
|
|
|
|
+{
|
|
|
|
+ ExtractSenaBin,
|
|
|
|
+ ImportSenaBin,
|
|
|
|
+ ExtractVMImage,
|
|
|
|
+ ImportVMImage,
|
|
|
|
+ DisassembleXAP,
|
|
|
|
+ ExtractForPrompts,
|
|
|
|
+ ReassembleForPrompts
|
|
|
|
+}
|
|
|
|
|
|
// http://www.tinyosshop.com/download/ADK_CSR867x.WIN4.3.1.5.zip für die tools
|
|
// http://www.tinyosshop.com/download/ADK_CSR867x.WIN4.3.1.5.zip für die tools
|
|
|
|
|