EntryPoint.java 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. package de.nplusc.izc.senabitwiggler;
  2. import java.io.*;
  3. import org.yaml.snakeyaml.Yaml;
  4. import picocli.CommandLine;
  5. import picocli.CommandLine.Command;
  6. import picocli.CommandLine.Option;
  7. import picocli.CommandLine.Parameters;
  8. @Command(mixinStandardHelpOptions = true, version = "Sena Firmware Hacking Utiility")
  9. public class EntryPoint implements Runnable
  10. {
  11. @Parameters(index = "0", description = "Mode for the Program. Valid values: ${COMPLETION-CANDIDATES}")
  12. private Modes mode;
  13. @Parameters(index = "1", description = "Firmware File to dissect/reassemble")
  14. private File input;
  15. @Parameters(index = "2", description = "Disassembled Data Folder")
  16. private File output;
  17. @Parameters(index = "3", arity = "0..1", description = "Headset ID. Any value if not in the Prompt unpacking mode.")
  18. private String headset;
  19. @Option(names = { "-d", "--deep" }, description = "Deep Dissect. Splits everything down and reassembles from those low-level modules. Also yields a partial disassembly.")
  20. private boolean weNeedToGoDeeper;
  21. @Option(names = { "-v", "--verbose" }, description = "Snitch enabling")
  22. public static boolean verbose;
  23. public static String SoxPath = "";
  24. public static String BlueLabPath = "";
  25. public static final String APPDIR = new File(EntryPoint.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getParentFile().getParent();
  26. public static void main(String[] args)
  27. {
  28. Yaml y = new Yaml();
  29. File cfg = new File(APPDIR+File.separator+"config.yml");
  30. if(cfg.exists())
  31. {
  32. try {
  33. Configuration config = y.loadAs(new FileReader(cfg),Configuration.class);
  34. SoxPath=config.getSoxPath();
  35. BlueLabPath=config.getBlueLabPath();
  36. } catch (FileNotFoundException e) {
  37. System.err.println("Hurz");
  38. e.printStackTrace();
  39. }
  40. }
  41. else
  42. {
  43. Configuration config = new Configuration();
  44. config.setBlueLabPath("C:\\ADK_CSR867x.WIN4.3.1.5\\tools\\bin\\");
  45. config.setSoxPath("sox");
  46. try {
  47. y.dump(config, new FileWriter(cfg));
  48. System.err.println("Configuration needed. Check the generated config.yml");
  49. } catch (IOException e) {
  50. System.err.println("Failed to initialize config");
  51. e.printStackTrace();
  52. }
  53. System.exit(0);
  54. }
  55. CommandLine cl = new CommandLine(new EntryPoint());
  56. cl.setCaseInsensitiveEnumValuesAllowed(true);
  57. cl.execute(args);
  58. }
  59. @Override
  60. public void run() {
  61. //TODO check and init config file
  62. switch(mode)
  63. {
  64. case ExtractSenaBin:
  65. try {
  66. Utils.makeSureThatOutFolderIsCreated(output.getPath());
  67. FirmwareWrapperExtraction.extractFirmwareLong(input,output.getPath());
  68. } catch (InputInvalidException e) {
  69. System.out.println("Zarf! File was bad");
  70. e.printStackTrace();
  71. }
  72. break;
  73. case ImportSenaBin:
  74. FirmwareWrapperExtraction.assembleFirmware(input,output.getPath());
  75. break;
  76. case ExtractVMImage:
  77. VmAppFIleExtraction.extractVmImage(input,output.getPath());
  78. break;
  79. case ImportVMImage:
  80. throw new UnsupportedOperationException("Not Implemented yet");
  81. //break;
  82. case DisassembleXAP:
  83. XAPDisAsm.Disassemble(input.getPath(),output.getPath());
  84. break;
  85. case ExtractForPrompts:
  86. try {
  87. PromptHandlerSuite.handlePrompts(input,output,headset,weNeedToGoDeeper);
  88. } catch (InputInvalidException e) {
  89. e.printStackTrace();
  90. }
  91. break;
  92. case ReassembleForPrompts:
  93. try {
  94. PromptHandlerSuite.assembleWithNewPrompts(input,output,headset);
  95. } catch (InputInvalidException e) {
  96. e.printStackTrace();
  97. }
  98. break;
  99. case Jailbreak:
  100. Jailbreaker.jailbreak();
  101. break;
  102. case DumpFlashes:
  103. Jailbreaker.dumpFlash(input.getName(),output);
  104. break;
  105. case ResignDFU:
  106. Jailbreaker.resignDFU(input.getPath(),output);
  107. break;
  108. case FlashFS512x:
  109. FlashFSUnWiggler.unpackFSQCC512x(input,output);
  110. break;
  111. case FlashFSCSR86xx:
  112. FlashFSUnWiggler.unpackCSRFS(input,output);
  113. break;
  114. case DfuS512x:
  115. FlashFSUnWiggler.unpackQCC512DFU(input,output);
  116. break;
  117. case ScanForSenaFirmware:
  118. FirmwareAutoDumper.pullFirmwares(input,output,weNeedToGoDeeper);
  119. break;
  120. }
  121. }
  122. }
  123. enum Modes
  124. {
  125. ExtractSenaBin,
  126. ImportSenaBin,
  127. ExtractVMImage,
  128. ImportVMImage,
  129. DisassembleXAP,
  130. ExtractForPrompts,
  131. ReassembleForPrompts,
  132. Jailbreak,
  133. DumpFlashes,
  134. ResignDFU,
  135. FlashFS512x,
  136. FlashFSCSR86xx,
  137. DfuS512x,
  138. ScanForSenaFirmware
  139. }
  140. // http://www.tinyosshop.com/download/ADK_CSR867x.WIN4.3.1.5.zip für die tools
  141. // C:\ADK_CSR867x.WIN4.3.1.5\tools\bin\XUV2BIN.exe -e vp.bin vp.xuv
  142. //C:\ADK_CSR867x.WIN4.3.1.5\tools\bin\ unpackfile.exe vp.xuv out
  143. // resultat: out mit prm-dateien. bei SRL2 sind das raw-PCMs, Mono, 16bit 8khz. leider keine header zum rumverzinken....
  144. // C:\ADK_CSR867x.WIN4.3.1.5\tools\bin\packfile.exe out vp2.xuv
  145. // C:\ADK_CSR867x.WIN4.3.1.5\tools\bin\XUV2BIN.exe -d vp2.xuv vp2.bin
  146. // danach die vp.bin mit vp2.bin austauschen und repacken
  147. // für raw pcm: for f in *.prm; do sox -t raw -r 8000 -c 1 -e signed-integer -b 16 $f -e signed-integer -b 16 out2.$f.wav; done
  148. // für ima adpcm: for f in *.prm; do sox -t ima -r 8000 -c 1 -e ima-adpcm -b 4 $f -e signed-integer -b 16 out.$f.wav; done