📄 decoder.java
字号:
}
catch (StringIndexOutOfBoundsException strerr) {
return theAttrib;
}
}
/** Converts all the hex values that are classified as a string into an
actual string format */
private String ProcessString(String HexString, boolean Attrib) {
String TextString = "";
int theNumber = 0;
char value;
int StartofSpecialStrings = ConversionFile.indexOf("&");
String StringSection = ConversionFile.substring(StartofSpecialStrings);
int Endpos = 0;
int Startpos = 0;
boolean SpecialString = false;
for (int x = 0; x < HexString.length(); x = x + 3) {
// Procedure for special strings
if (HexString.substring(x, x + 2).compareTo("C2") == 0)
SpecialString = true;
if (SpecialString) {
SpecialString = false;
x = x + 3;
theNumber = HextoInt(HexString.substring(x, x + 2));
// Look number up in conversion file by going first to & section
// then look for the number
Endpos = StringSection.indexOf(String.valueOf(theNumber)) - 3;
// Then look for its string translation by searching backwards for \n
Startpos = SearchBackwards(Endpos, "\n", StringSection);
TextString = TextString + StringSection.substring(Startpos, Endpos);
}
else {
theNumber = HextoInt(HexString.substring(x, x + 2));
value = (char)theNumber;
TextString = TextString + String.valueOf(value);
}
}
if (Attrib) {
TextString = "=\"" + TextString + "\"";
}
return TextString;
}
/** This method reads the data file and stores the data in a string in hex format
A small portion of this algorithm was taken from Sun Microsystems */
private String ReadFile(String fileName) {
FileInputStream fis = null;
String str = "";
String tmp = "";
char hexDigit[] = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
};
byte b;
try {
fis = new FileInputStream (fileName);
int size = fis.available ();
byte[] bytes = new byte [size];
fis.read (bytes);
for (int x = 0; x < size; x++) {
b = bytes[x];
char[] array = { hexDigit[(b >> 4) & 0x0f], hexDigit[b & 0x0f] };
tmp = new String(array);
str = str + tmp + " ";
}
}
catch (IOException e) {
//System.out.println("error, cannot read from file");
ErrorMessage = ErrorMessage + e.getMessage() + "\n";
}
try {
fis.close ();
}
catch (IOException e) {
//System.out.println("cannot close file");
ErrorMessage = ErrorMessage + e.getMessage() + "\n";
}
return str;
}
/** Reads text files such as the conversion files and the header files */
private String ReadaFile(String fileName) {
FileInputStream fis = null;
String str = null;
//System.out.println(fileName);
try {
fis = new FileInputStream (fileName);
int size = fis.available ();
byte[] bytes = new byte [size];
fis.read (bytes);
str = new String (bytes);
}
catch (IOException e) {
ErrorMessage = ErrorMessage + e.getMessage() + "\n";
}
try {
fis.close ();
}
catch (IOException e) {
ErrorMessage = ErrorMessage + e.getMessage() + "\n";
}
return str;
}
/** Write the final output to a file with the same name and
the appropriate extension as the hex file */
private void WriteFile(String fileName, String fileData) {
FileOutputStream fos = null;
String str = fileData;
// need to be sure no file is overwriten without warning
try {
File f = new File(fileName);
boolean fexists = f.createNewFile();
if (!fexists) {
// need to display some type of dialog
int selOption = JOptionPane.showConfirmDialog(null, "File Exists, do you wish to overwrite the file", "Warning", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
switch (selOption) {
case JOptionPane.YES_OPTION:
FileName = fileName;
FileOutputStream DataOut = new FileOutputStream(fileName);
DataOut.write(str.getBytes());
DataOut.close();
break;
case JOptionPane.NO_OPTION:
// display a file rename dialog box
String[] filters = {"wml", "wmls", "si", "sl"};
Designer.Filter filter = new Designer.Filter(filters, "WAP Files");
JFileChooser fc = new JFileChooser();
fc.addChoosableFileFilter(filter);
fc.setCurrentDirectory(new File(fileName));
fc.setSelectedFile(new File(fileName));
fc.setDialogTitle("Rename File As");
fc.setApproveButtonText("Rename");
fc.setApproveButtonToolTipText("Rename the file");
int retVal = fc.showDialog(null, "Rename");
if (retVal == fc.APPROVE_OPTION) {
// Get the path & the file name
String path = fc.getSelectedFile().getParent() + File.separator;
String fname = fc.getSelectedFile().getPath().substring(path.length());
FileName = path + fname;
WriteFile(FileName, str);
}
else
FileName = "";
break;
case JOptionPane.CANCEL_OPTION:
FileName = "";
break;
}
}
else {
FileName = fileName;
FileOutputStream DataOut = new FileOutputStream(fileName);
DataOut.write(str.getBytes());
DataOut.close();
}
}
catch (IOException e) {
ErrorMessage = ErrorMessage + e.getMessage() + "\n";
}
}
/** Used to get the integer(decimal) equivelants of the hex strings */
private int HextoInt(String hexValue) {
String hexDigit = "0123456789ABCDEF";
int HextoIntValue = (hexDigit.indexOf(hexValue.substring(0,1)) * 16) + hexDigit.indexOf(hexValue.substring(1,2));
return HextoIntValue;
}
/** Searches for a certain string before the actual start position */
private int SearchBackwards(int pos, String Criteria, String Section) {
int newPos = pos - 1;
int thePos = 0;
String SearchString;
try {
do { // Loop backwards 1 character at a time
SearchString = Section.substring(newPos, pos);
thePos = SearchString.indexOf(Criteria);
newPos--;
}
while (thePos == -1);
return newPos + Criteria.length() + 1;
}
catch (StringIndexOutOfBoundsException e) {
return 0;
}
}
/** Inserts tabs into the text to provide the proper programmatic alignment.
In short, used for esthetics in the final text output */
private String InsertTabs(int level) {
String s = "";
for (int x = 0; x < level; x++)
s = s + "\t";
return s;
}
/** A helper method to determine what file to call */
private String getConversionFileName(String data) {
String fname = "";
//locate !DOCTYPE
int startPos = data.indexOf("!DOCTYPE");
if (startPos > -1) {
int endPos = data.indexOf(">", startPos);
if (endPos > 0) {
String type = data.substring(startPos, endPos);
String loc = "http://www.wapforum.org/DTD/";
startPos = type.indexOf(loc);
if (startPos > -1) {
// need to change this to look for xml 1st and then dtd
endPos = type.indexOf(".xml", startPos + loc.length());
if (endPos > -1)
fname = type.substring(startPos + loc.length(), endPos);
else {
endPos = type.indexOf(".dtd", startPos + loc.length());
if (endPos > -1)
fname = type.substring(startPos + loc.length(), endPos);
}
}
}
}
return fname;
}
/** Reads the whole string from a given position in the string table */
private String GetStringFromTable(int pos, String DataFile) {
int StartTable = 12;
int EndTable = StartTable + HextoInt(DataFile.substring(9, 11)) * 3 - 1;
String Table = DataFile.substring(StartTable, EndTable);
String theString = Table.substring(pos * 3, Table.indexOf((" 00"), pos * 3));
return theString;
}
/** Returns any errors that may have occured in the execution of this code */
public String GetErrorMessage() {
return ErrorMessage;
}
/** Returns the file name of the decompiled file */
public String GetFileName() {
return FileName;
}
/**
* @param args the command line arguments
*/
public static void main (String args[]) {
Decoder WapDecoder = new Decoder(args[0]);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -