EntryPoint.java 7.2 KB

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