|
@@ -5,6 +5,7 @@ import com.google.common.primitives.Shorts;
|
|
|
|
|
|
import java.io.*;
|
|
import java.io.*;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
+import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
interface OpCodeMangler
|
|
interface OpCodeMangler
|
|
@@ -13,6 +14,9 @@ interface OpCodeMangler
|
|
}
|
|
}
|
|
|
|
|
|
public class XAPDisAsm {
|
|
public class XAPDisAsm {
|
|
|
|
+
|
|
|
|
+ private static HashMap<String,String> labels = new HashMap<>();
|
|
|
|
+
|
|
private static OpCodeMangler brxl = (modifier,opcode,address)->{
|
|
private static OpCodeMangler brxl = (modifier,opcode,address)->{
|
|
return OpcodeAddressRangeToString(address,1)+": brxl";
|
|
return OpcodeAddressRangeToString(address,1)+": brxl";
|
|
};
|
|
};
|
|
@@ -679,7 +683,7 @@ public class XAPDisAsm {
|
|
{
|
|
{
|
|
case 0x00:
|
|
case 0x00:
|
|
register="AH";
|
|
register="AH";
|
|
- value = ParamManglerConstAddr(untwiddleOpcodeParamBra(opcodeValues,address));
|
|
|
|
|
|
+ value = ParamManglerConstAddr(untwiddleOpcodeParamBra(opcodeValues,address+opcode.length-1));
|
|
break;
|
|
break;
|
|
case 0x01:
|
|
case 0x01:
|
|
register="AH";
|
|
register="AH";
|
|
@@ -827,18 +831,26 @@ public class XAPDisAsm {
|
|
|
|
|
|
private static String addressToString(int address)
|
|
private static String addressToString(int address)
|
|
{
|
|
{
|
|
- return "0x"+(EntryPoint.bytesToHex(Ints.toByteArray(address)));
|
|
|
|
|
|
+ //return "0x"+(EntryPoint.bytesToHex(Ints.toByteArray(address)));
|
|
|
|
+ return String.format("0x%08X", address);
|
|
}
|
|
}
|
|
|
|
|
|
private static String OpcodeAddressRangeToString(int address,int opcodelen)
|
|
private static String OpcodeAddressRangeToString(int address,int opcodelen)
|
|
{
|
|
{
|
|
|
|
+ String startaddr = addressToString(address);
|
|
|
|
+ if(labels.containsKey(startaddr))
|
|
|
|
+ {
|
|
|
|
+ startaddr = labels.get(startaddr)+":\n"+startaddr;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
if(opcodelen>1)
|
|
if(opcodelen>1)
|
|
{
|
|
{
|
|
- return addressToString(address)+
|
|
|
|
|
|
+ return startaddr+
|
|
"---"+
|
|
"---"+
|
|
addressToString(address+(opcodelen-1));
|
|
addressToString(address+(opcodelen-1));
|
|
}
|
|
}
|
|
- else return addressToString(address);
|
|
|
|
|
|
+ else return startaddr;
|
|
}
|
|
}
|
|
|
|
|
|
private static String ParamManglerImmediate(int number)
|
|
private static String ParamManglerImmediate(int number)
|
|
@@ -848,7 +860,12 @@ public class XAPDisAsm {
|
|
|
|
|
|
private static String ParamManglerConstAddr(int number)
|
|
private static String ParamManglerConstAddr(int number)
|
|
{
|
|
{
|
|
- return String.format("0x%08X", number);
|
|
|
|
|
|
+ String addr = addressToString(number);
|
|
|
|
+ if(labels.containsKey(addr))
|
|
|
|
+ {
|
|
|
|
+ addr = addr+"("+labels.get(addr)+")";
|
|
|
|
+ }
|
|
|
|
+ return addr;
|
|
}
|
|
}
|
|
|
|
|
|
private static String ParamManglerAddress(int number)
|
|
private static String ParamManglerAddress(int number)
|
|
@@ -874,6 +891,25 @@ public class XAPDisAsm {
|
|
RandomAccessFile f = new RandomAccessFile(in,"r");
|
|
RandomAccessFile f = new RandomAccessFile(in,"r");
|
|
PrintStream disassembled = new PrintStream(new FileOutputStream(out));
|
|
PrintStream disassembled = new PrintStream(new FileOutputStream(out));
|
|
|
|
|
|
|
|
+ String mapfilepath = in+".sbwmap";
|
|
|
|
+ if(new File(mapfilepath).exists())
|
|
|
|
+ {
|
|
|
|
+ RandomAccessFile mapfile = new RandomAccessFile(mapfilepath,"r");
|
|
|
|
+ String line = mapfile.readLine();
|
|
|
|
+ while(line !=null)
|
|
|
|
+ {
|
|
|
|
+ if(line.equals(""))
|
|
|
|
+ {
|
|
|
|
+ line = mapfile.readLine();
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ String[] entry = line.split(":");
|
|
|
|
+ labels.put(entry[0].toLowerCase(),entry[1]);
|
|
|
|
+ line = mapfile.readLine();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
long assemblyLength = f.length()/2;
|
|
long assemblyLength = f.length()/2;
|
|
|
|
|
|
int baseAddressLastOpcode=0;
|
|
int baseAddressLastOpcode=0;
|