1
0

PWNaFirmwareGrabScriptGenerator.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package QuickVerifyCrap;
  2. import java.io.*;
  3. import java.util.ArrayList;
  4. import java.util.HashSet;
  5. import java.util.List;
  6. public class PWNaFirmwareGrabScriptGenerator {
  7. public static void main(String[] args){
  8. try{
  9. BufferedReader br = new BufferedReader(new FileReader("Q:\\LOA\\000013\\S30-FW\\firmware2.dat"));
  10. String fwline = br.readLine();
  11. BufferedWriter w = new BufferedWriter(new FileWriter("Q:\\LOA\\000013\\S30-FW\\firmwarehunt-reloaded.txt"));
  12. w.write("#!/bin/bash\n");
  13. HashSet<String> linesAdded = new HashSet<>();
  14. while(fwline!=null)
  15. {
  16. System.out.println(fwline);
  17. if(fwline.contains(":"))
  18. {
  19. if(fwline.contains(".img"))
  20. {
  21. var line = fwline.split(":");
  22. String filename = line[line.length-1];
  23. String[] magic = filename.split("-v");
  24. boolean fuckingoddity = false;
  25. if(magic.length==1)
  26. {
  27. fuckingoddity = true;
  28. magic = filename.split("_v");
  29. }
  30. String version = magic[1];
  31. String[] vsplit = version.split("\\.");
  32. String suffix = "";
  33. int major=0,minor=0,patch=0;
  34. major=Integer.valueOf(vsplit[0]);
  35. if(vsplit.length==4)
  36. {
  37. minor = Integer.valueOf(vsplit[1]);
  38. patch = Integer.valueOf(vsplit[2].substring(0,1));
  39. if(vsplit[2].length()>1)
  40. {
  41. suffix = vsplit[2].substring(1)+"."+vsplit[3];
  42. }
  43. else
  44. {
  45. suffix = "."+vsplit[3];
  46. }
  47. }
  48. else
  49. {
  50. if(vsplit[1].length()>1)
  51. {
  52. minor = Integer.valueOf(vsplit[1].substring(0,1));
  53. suffix = vsplit[1].substring(1)+"."+vsplit[2];
  54. }
  55. else
  56. {
  57. minor = Integer.valueOf(vsplit[1].substring(0,1));
  58. suffix = "."+vsplit[2];
  59. }
  60. }
  61. String[] synthesized = synthesizeVersionNumbers(major,minor,patch,fuckingoddity?"_v":"-v");
  62. for (String innerline:synthesized)
  63. {
  64. String newline = "wget -nc https://firmware.sena.com/senabluetoothmanager/"+magic[0]+innerline+suffix;
  65. if(!linesAdded.contains(newline))
  66. {
  67. w.write(newline+"\n");
  68. linesAdded.add(newline);
  69. }
  70. }
  71. }
  72. }
  73. fwline = br.readLine();
  74. }
  75. w.close();
  76. }
  77. catch (Exception e)
  78. {
  79. e.printStackTrace();
  80. }
  81. }
  82. private static String[] synthesizeVersionNumbers(int major,int minor, int patch,String prefix)
  83. {
  84. System.out.println(major+"--"+minor+"--"+patch);
  85. List<String> temp = new ArrayList<>();
  86. //temp.add(prefix+(major+1)+".0.0"); // poking for next major
  87. //temp.add(prefix+(major+1)+".0"); // poking for next major
  88. //temp.add(prefix+(major)+"."+(minor+1)+".0"); // poking for next minor
  89. temp.add(prefix+(major)+"."+(minor+1)); // poking for next minor
  90. //temp.add(prefix+(major)+"."+minor+"."+(patch+1)); // poking for next patch
  91. System.out.println(major+"--"+minor+"--"+patch);
  92. /*
  93. while(major>0&&minor>=0&&patch>=0)
  94. {
  95. temp.add(prefix+(major)+"."+minor+"."+(patch));
  96. if(patch==0)
  97. {
  98. temp.add(prefix+(major)+"."+minor); // specialcase to probe for unset patch version versions
  99. }
  100. patch--;
  101. if(patch<0)
  102. {
  103. patch=9;
  104. minor--;
  105. }
  106. if(minor<0)
  107. {
  108. minor=9;
  109. major--;
  110. }
  111. }/**/
  112. return temp.toArray(new String[]{});
  113. }
  114. }