Explorar el Código

Deeper Mode added

LH hace 3 años
padre
commit
738f164b80

+ 9 - 2
SenaBitWiggler/src/main/java/de/nplusc/izc/senabitwiggler/EntryPoint.java

@@ -20,9 +20,16 @@ public class EntryPoint implements Runnable
     @Parameters(index = "2", description = "Disassembled Data Folder")
     @Parameters(index = "2", description = "Disassembled Data Folder")
     private File output;
     private File output;
 
 
-    @Parameters(index = "3", description = "Head")
+    @Parameters(index = "3", arity = "0..1", description = "Headset ID. Any value if not in the Prompt unpacking mode")
     private String headset;
     private String headset;
 
 
+    @Option(names = { "-d", "--deep" }, description = "Deep Dissect. Splits everything down and reassembles from those low-level modules. Also yields a partial disassembly.")
+    private boolean weNeedToGoDeeper;
+    @Option(names = { "-v", "--verbose" }, description = "Snitch enabling")
+    public static boolean verbose;
+
+
+
     public static String SoxPath = "";
     public static String SoxPath = "";
     public static String BlueLabPath = "";
     public static String BlueLabPath = "";
 
 
@@ -110,7 +117,7 @@ public class EntryPoint implements Runnable
                 break;
                 break;
             case ExtractForPrompts:
             case ExtractForPrompts:
                 try {
                 try {
-                    PromptHandlerSuite.handlePrompts(input,output,headset);
+                    PromptHandlerSuite.handlePrompts(input,output,headset,weNeedToGoDeeper);
                 } catch (InputInvalidException e) {
                 } catch (InputInvalidException e) {
                     e.printStackTrace();
                     e.printStackTrace();
                 }
                 }

+ 34 - 4
SenaBitWiggler/src/main/java/de/nplusc/izc/senabitwiggler/PromptHandlerSuite.java

@@ -12,7 +12,7 @@ import java.nio.file.Paths;
 import java.util.*;
 import java.util.*;
 
 
 public class PromptHandlerSuite {
 public class PromptHandlerSuite {
-    public static void handlePrompts(File firmware, File outfolder, String headsetid) throws InputInvalidException {
+    public static void handlePrompts(File firmware, File outfolder, String headsetid,boolean deep) throws InputInvalidException {
         URL rsrc = EntryPoint.class.getResource("/PromptConfigs/"+headsetid+".prompts.yml");
         URL rsrc = EntryPoint.class.getResource("/PromptConfigs/"+headsetid+".prompts.yml");
         if(rsrc==null)
         if(rsrc==null)
         {
         {
@@ -43,11 +43,15 @@ public class PromptHandlerSuite {
         }
         }
         File scratch = new File(outfolder,"internal");
         File scratch = new File(outfolder,"internal");
         File prompts = new File(outfolder,"prompts");
         File prompts = new File(outfolder,"prompts");
+        File firmwaredir = new File(outfolder,"firmware");
+        File exe = new File(outfolder,"exe");
         scratch.mkdirs();
         scratch.mkdirs();
         prompts.mkdirs();
         prompts.mkdirs();
+        firmwaredir.mkdirs();
+        exe.mkdirs();
         File SenaUnwrap = new File(scratch,"senatransport");
         File SenaUnwrap = new File(scratch,"senatransport");
-        File DFUUnwrap = new File(scratch,"dfuunwrap"); //Needed for some not yet supported variants
-        File PromptsInPrm = new File(scratch,"prm"); //Needed for some not yet supported variants
+        File DFUUnwrap = new File(scratch,"dfuunwrap");
+        File PromptsInPrm = new File(scratch,"prm");
         SenaUnwrap.mkdirs();
         SenaUnwrap.mkdirs();
         DFUUnwrap.mkdirs();
         DFUUnwrap.mkdirs();
         PromptsInPrm.mkdirs();
         PromptsInPrm.mkdirs();
@@ -66,6 +70,24 @@ public class PromptHandlerSuite {
             String unpacker = EntryPoint.BlueLabPath+"unpackfile";
             String unpacker = EntryPoint.BlueLabPath+"unpackfile";
             runTool(xuv2bin,"-e", xuvin.getPath(), xuvout.getPath());
             runTool(xuv2bin,"-e", xuvin.getPath(), xuvout.getPath());
             runTool(unpacker, xuvout.getPath(), PromptsInPrm.getPath());
             runTool(unpacker, xuvout.getPath(), PromptsInPrm.getPath());
+
+            if(deep)
+            {
+                //TODO array for multiples!!
+                File dfu = new File(SenaUnwrap,config.get("maincpu"));
+                runTool(DFUUnwrap,EntryPoint.BlueLabPath+"dfuunbuild","-v","-f", dfu.getAbsolutePath(), "-o", "unwrap");
+                runTool(EntryPoint.BlueLabPath+"unpackfile", new File(DFUUnwrap,"unwrap0000.fs").getPath(),firmwaredir.getPath());
+                File fwXuv = new File(firmwaredir,"vm.app");
+                File fwUnXuv = new File(scratch,"exe.unxuv");
+                runTool(xuv2bin,"-d", fwXuv.getPath(), fwUnXuv.getPath());
+
+                VmAppFIleExtraction.extractVmImage(fwUnXuv, exe.getPath());
+
+
+                XAPDisAsm.Disassemble(new File(exe,"code.bin").getPath(),new File(exe,"app.disasm").getPath());
+            }
+
+
             File[] fileprompts = PromptsInPrm.listFiles();
             File[] fileprompts = PromptsInPrm.listFiles();
             for(File f : fileprompts)
             for(File f : fileprompts)
             {
             {
@@ -212,12 +234,20 @@ public class PromptHandlerSuite {
     }
     }
 
 
 
 
+    private static void runTool(String... args) throws IOException {
 
 
+        runTool(null,args);
+    }
 
 
 
 
-    private static void runTool(String... args) throws IOException {
+
+    private static void runTool(File workdir, String... args) throws IOException {
         ProcessBuilder pb = new ProcessBuilder();
         ProcessBuilder pb = new ProcessBuilder();
         pb.command(args);
         pb.command(args);
+        if(workdir !=null&&workdir.isDirectory())
+        {
+            pb.directory(workdir);
+        }
         pb.inheritIO();
         pb.inheritIO();
         Process runme = pb.start();
         Process runme = pb.start();
         try {
         try {

+ 2 - 1
SenaBitWiggler/src/main/java/de/nplusc/izc/senabitwiggler/VmAppFIleExtraction.java

@@ -29,7 +29,8 @@ public class VmAppFIleExtraction {
             }
             }
             if(Utils.xorsum(checksumarray)!=0)
             if(Utils.xorsum(checksumarray)!=0)
             {
             {
-                System.out.println("Smells like Dead Beef, the data seems to be corrupt");
+                System.err.println("Smells like Dead Beef, the data seems to be corrupt");
+                System.exit(1);
             }
             }
             f.seek(0);
             f.seek(0);
 
 

+ 13 - 13
SenaBitWiggler/src/main/java/de/nplusc/izc/senabitwiggler/XAPDisAsm.java

@@ -49,12 +49,12 @@ public class XAPDisAsm {
                 for(int i=0;i<opcode.length;i++)
                 for(int i=0;i<opcode.length;i++)
                 {
                 {
                     byte[] opcodeWord = Shorts.toByteArray(opcode[i]);
                     byte[] opcodeWord = Shorts.toByteArray(opcode[i]);
-                    System.out.println(opcodeWord[0]);
+                    if(EntryPoint.verbose)System.out.println(opcodeWord[0]);
                     opcodeValues[i]=opcodeWord[0];
                     opcodeValues[i]=opcodeWord[0];
                     opcodeReal=(opcodeWord[1]); //stompy stomp, only keeps the last
                     opcodeReal=(opcodeWord[1]); //stompy stomp, only keeps the last
                 }
                 }
                 String rawValue = Utils.bytesToHex(opcodeValues);
                 String rawValue = Utils.bytesToHex(opcodeValues);
-                System.out.println(rawValue);
+                if(EntryPoint.verbose)System.out.println(rawValue);
 
 
                 int valueUnsigned = XAPDisAsmGeneratedCode.unsignedCounts.get(rawValue);
                 int valueUnsigned = XAPDisAsmGeneratedCode.unsignedCounts.get(rawValue);
                 int valueSigned =XAPDisAsmGeneratedCode.signedCounts.get(rawValue);
                 int valueSigned =XAPDisAsmGeneratedCode.signedCounts.get(rawValue);
@@ -156,7 +156,7 @@ public class XAPDisAsm {
                     opcodeReal=(opcodeWord[1]); //stompy stomp, only keeps the last
                     opcodeReal=(opcodeWord[1]); //stompy stomp, only keeps the last
                 }
                 }
                 String rawVal = Utils.bytesToHex(opcodeValues);
                 String rawVal = Utils.bytesToHex(opcodeValues);
-                System.out.println(rawVal);
+                if(EntryPoint.verbose)System.out.println(rawVal);
                 int valueUnsigned = XAPDisAsmGeneratedCode.unsignedCounts.get(rawVal);
                 int valueUnsigned = XAPDisAsmGeneratedCode.unsignedCounts.get(rawVal);
                 int valueSigned =XAPDisAsmGeneratedCode.signedCounts.get(Utils.bytesToHex(opcodeValues));
                 int valueSigned =XAPDisAsmGeneratedCode.signedCounts.get(Utils.bytesToHex(opcodeValues));
                 String register = "";
                 String register = "";
@@ -813,15 +813,15 @@ public class XAPDisAsm {
     private static int untwiddleOpcodeParamBra(byte[] opcode,int opcodelocation)
     private static int untwiddleOpcodeParamBra(byte[] opcode,int opcodelocation)
     {
     {
         int out = opcode[0];
         int out = opcode[0];
-        System.out.println(out);
-        System.out.println(String.format("0x%08X", out));
+        if(EntryPoint.verbose)System.out.println(out);
+        if(EntryPoint.verbose)System.out.println(String.format("0x%08X", out));
         for(int i=1;i<opcode.length;i++)
         for(int i=1;i<opcode.length;i++)
         {
         {
             out=out<<8;
             out=out<<8;
             out+=opcode[i];
             out+=opcode[i];
-            System.out.println(out);
-            System.out.println(opcode[i]);
-            System.out.println(String.format("0x%08X", out));
+            if(EntryPoint.verbose)System.out.println(out);
+            if(EntryPoint.verbose)System.out.println(opcode[i]);
+            if(EntryPoint.verbose)System.out.println(String.format("0x%08X", out));
         }
         }
         out=out+opcodelocation;
         out=out+opcodelocation;
         out = out &0x00FFFFFF;
         out = out &0x00FFFFFF;
@@ -918,9 +918,9 @@ public class XAPDisAsm {
             for(int i=0;i<assemblyLength;i++)
             for(int i=0;i<assemblyLength;i++)
             {
             {
                 Short word = f.readShort();
                 Short word = f.readShort();
-                System.out.println("READ:"+ (word&0xff));
-                System.out.println(addressToString(i));
-                System.out.println(addressToString(baseAddressLastOpcode));
+                if(EntryPoint.verbose)System.out.println("READ:"+ (word&0xff));
+                if(EntryPoint.verbose)System.out.println(addressToString(i));
+                if(EntryPoint.verbose)System.out.println(addressToString(baseAddressLastOpcode));
                 opcodeHoldingBay.add(word);
                 opcodeHoldingBay.add(word);
                 if(word==(short)0xfe09) //specialcasing one specific opcode
                 if(word==(short)0xfe09) //specialcasing one specific opcode
                 {
                 {
@@ -951,7 +951,7 @@ public class XAPDisAsm {
                                 opcode[j]=opcodeHoldingBay.get(j);
                                 opcode[j]=opcodeHoldingBay.get(j);
                             }
                             }
                         }
                         }
-                        System.out.println("Mangling Opcode with length"+opcode.length);
+                        if(EntryPoint.verbose)System.out.println("Mangling Opcode with length"+opcode.length);
                         try{
                         try{
                             disassembled.println(manglers[word&0xff].mangleOpCode(modifier,opcode,baseAddressLastOpcode));
                             disassembled.println(manglers[word&0xff].mangleOpCode(modifier,opcode,baseAddressLastOpcode));
                         }
                         }
@@ -974,7 +974,7 @@ public class XAPDisAsm {
                         opcodeHoldingBay.clear();
                         opcodeHoldingBay.clear();
                         baseAddressLastOpcode++;
                         baseAddressLastOpcode++;
                     }
                     }
-                    System.out.println("VALUE");
+                    if(EntryPoint.verbose)System.out.println("VALUE");
                     //opcodeHoldingBay.add(word);
                     //opcodeHoldingBay.add(word);
                 }
                 }
 
 

+ 2 - 1
SenaBitWiggler/src/main/resources/PromptConfigs/10S.prompts.yml

@@ -17,4 +17,5 @@ ALL: "PCM"
 "32": "IMA"
 "32": "IMA"
 "52": "IMA"
 "52": "IMA"
 "53": "IMA"
 "53": "IMA"
-"58": "IMA"
+"58": "IMA"
+maincpu: "10S.img"

+ 2 - 1
SenaBitWiggler/src/main/resources/PromptConfigs/SRL2.prompts.yml

@@ -1,2 +1,3 @@
 ALL: "PCM"
 ALL: "PCM"
-file: "vp.bin"
+file: "vp.bin"
+maincpu: "SRL2_M0.img"