public static String getStreamMD5(String filePath) { String hash = null; byte[] buffer = new byte[4096]; BufferedInputStream in = null; try { MessageDigest md5 = MessageDigest.getInstance("MD5"); in = new BufferedInputStream(new FileInputStream(filePath)); int numRead = 0; while ((numRead = in.read(buffer)) > 0) { md5.update(buffer, 0, numRead); } in.close(); hash = HexDump.toHex(md5.digest()); } catch (Exception e) { e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (Exception ex) { ex.printStackTrace(); } } } return hash; }
public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append("[SERIESTEXT]\n"); buffer .append(" .id = ") .append("0x") .append(HexDump.toHex(getId())) .append(" (") .append(getId()) .append(" )"); buffer.append(System.getProperty("line.separator")); buffer .append(" .textLength = ") .append("0x") .append(HexDump.toHex(getTextLength())) .append(" (") .append(getTextLength()) .append(" )"); buffer.append(System.getProperty("line.separator")); buffer .append(" .undocumented = ") .append("0x") .append(HexDump.toHex(getUndocumented())) .append(" (") .append(getUndocumented()) .append(" )"); buffer.append(System.getProperty("line.separator")); buffer.append(" .text = ").append(" (").append(getText()).append(" )"); buffer.append(System.getProperty("line.separator")); buffer.append("[/SERIESTEXT]\n"); return buffer.toString(); }
public void validate(byte[] data) throws Exception { if (hash.length == 32) { if (!HexDump.toHex(hash).equals(OS.getSHA256(data))) throw new Exception("Bad data"); } else { if (hash.length == 20) { if (!HexDump.toHex(hash).equals(OS.getSHA1(data))) throw new Exception("Bad data"); } else throw new Exception("Cannot determine digest"); } }
public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append("[AI]\n"); buffer .append(" .linkType = ") .append("0x") .append(HexDump.toHex(getLinkType())) .append(" (") .append(getLinkType()) .append(" )"); buffer.append(System.getProperty("line.separator")); buffer .append(" .referenceType = ") .append("0x") .append(HexDump.toHex(getReferenceType())) .append(" (") .append(getReferenceType()) .append(" )"); buffer.append(System.getProperty("line.separator")); buffer .append(" .options = ") .append("0x") .append(HexDump.toHex(getOptions())) .append(" (") .append(getOptions()) .append(" )"); buffer.append(System.getProperty("line.separator")); buffer .append(" .customNumberFormat = ") .append(isCustomNumberFormat()) .append('\n'); buffer .append(" .indexNumberFmtRecord = ") .append("0x") .append(HexDump.toHex(getIndexNumberFmtRecord())) .append(" (") .append(getIndexNumberFmtRecord()) .append(" )"); buffer.append(System.getProperty("line.separator")); buffer .append(" .formulaOfLink = ") .append(" (") .append(getFormulaOfLink()) .append(" )"); buffer.append(System.getProperty("line.separator")); buffer.append("[/AI]\n"); return buffer.toString(); }
public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append("[FBI]\n"); buffer .append(" .xBasis = ") .append("0x") .append(HexDump.toHex(getXBasis())) .append(" (") .append(getXBasis()) .append(" )"); buffer.append(System.getProperty("line.separator")); buffer .append(" .yBasis = ") .append("0x") .append(HexDump.toHex(getYBasis())) .append(" (") .append(getYBasis()) .append(" )"); buffer.append(System.getProperty("line.separator")); buffer .append(" .heightBasis = ") .append("0x") .append(HexDump.toHex(getHeightBasis())) .append(" (") .append(getHeightBasis()) .append(" )"); buffer.append(System.getProperty("line.separator")); buffer .append(" .scale = ") .append("0x") .append(HexDump.toHex(getScale())) .append(" (") .append(getScale()) .append(" )"); buffer.append(System.getProperty("line.separator")); buffer .append(" .indexToFontTable = ") .append("0x") .append(HexDump.toHex(getIndexToFontTable())) .append(" (") .append(getIndexToFontTable()) .append(" )"); buffer.append(System.getProperty("line.separator")); buffer.append("[/FBI]\n"); return buffer.toString(); }
public String computeDataSizeAndType(RandomAccessFile fin) throws IOException { SinAddr a = map.get(0); byte[] res = new byte[(int) a.getDataLength()]; fin.seek(getDataHeaderSize() + map.getSize() + a.getSrcOffset()); fin.read(res); byte[] magic = new byte[4]; int pos = 0; while (res[pos] == 0) pos++; int startpos = pos; pos = 0; System.arraycopy(res, startpos + pos, magic, 0, magic.length); if (new String(magic).contains("ELF")) return "elf"; while (!HexDump.toHex(magic).startsWith("[FF, FF, 53, EF")) { pos++; try { System.arraycopy(res, startpos + pos, magic, 0, magic.length); } catch (Exception e) { return "unknown"; } if (new String(magic).contains("ELF")) return "elf"; } // if (pos>=500) return "unknown"; pos = pos - 54; byte[] header = new byte[58]; System.arraycopy(res, startpos + pos, header, 0, header.length); byte[] bcount = new byte[4]; System.arraycopy(header, 4, bcount, 0, bcount.length); BytesUtil.revert(bcount); long blockcount = BytesUtil.getInt(bcount); outputsize = blockcount * 4L * 1024L; return "ext4"; }
public static String getMD5(byte[] source) { try { MessageDigest md5 = MessageDigest.getInstance("MD5"); return HexDump.toHex(md5.digest(source)); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } }
public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append("[CHART]\n"); buffer .append(" .x = ") .append("0x") .append(HexDump.toHex(getX())) .append(" (") .append(getX()) .append(" )"); buffer.append(System.getProperty("line.separator")); buffer .append(" .y = ") .append("0x") .append(HexDump.toHex(getY())) .append(" (") .append(getY()) .append(" )"); buffer.append(System.getProperty("line.separator")); buffer .append(" .width = ") .append("0x") .append(HexDump.toHex(getWidth())) .append(" (") .append(getWidth()) .append(" )"); buffer.append(System.getProperty("line.separator")); buffer .append(" .height = ") .append("0x") .append(HexDump.toHex(getHeight())) .append(" (") .append(getHeight()) .append(" )"); buffer.append(System.getProperty("line.separator")); buffer.append("[/CHART]\n"); return buffer.toString(); }
public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append("[AREA]\n"); buffer .append(" .formatFlags = ") .append("0x") .append(HexDump.toHex(getFormatFlags())) .append(" (") .append(getFormatFlags()) .append(" )"); buffer.append(System.getProperty("line.separator")); buffer.append(" .stacked = ").append(isStacked()).append('\n'); buffer .append(" .displayAsPercentage = ") .append(isDisplayAsPercentage()) .append('\n'); buffer.append(" .shadow = ").append(isShadow()).append('\n'); buffer.append("[/AREA]\n"); return buffer.toString(); }
/** * @param tab - each children must be a right of his parent * @return xml representation of this record */ public String toXml(String tab) { StringBuilder builder = new StringBuilder(); builder .append(tab) .append("<") .append(getClass().getSimpleName()) .append(">\n") .append(tab) .append("\t") .append("<RecordId>0x") .append(HexDump.toHex(_recordId)) .append("</RecordId>\n") .append(tab) .append("\t") .append("<Options>") .append(_options) .append("</Options>\n") .append(tab) .append("</") .append(getClass().getSimpleName()) .append(">\n"); return builder.toString(); }
public void testDump() throws IOException { final byte[] testArray = new byte[256]; for (int j = 0; j < 256; j++) { testArray[j] = (byte) j; } ByteArrayOutputStream stream = new ByteArrayOutputStream(); HexDump.dump(testArray, 0, stream, 0); byte[] outputArray = new byte[16 * (73 + HexDump.EOL.length())]; for (int j = 0; j < 16; j++) { int offset = (73 + HexDump.EOL.length()) * j; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) toHex(j); outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) ' '; for (int k = 0; k < 16; k++) { outputArray[offset++] = (byte) toHex(j); outputArray[offset++] = (byte) toHex(k); outputArray[offset++] = (byte) ' '; } for (int k = 0; k < 16; k++) { outputArray[offset++] = (byte) toAscii((j * 16) + k); } System.arraycopy( HexDump.EOL.getBytes(), 0, outputArray, offset, HexDump.EOL.getBytes().length); } byte[] actualOutput = stream.toByteArray(); assertEquals("array size mismatch", outputArray.length, actualOutput.length); for (int j = 0; j < outputArray.length; j++) { assertEquals("array[ " + j + "] mismatch", outputArray[j], actualOutput[j]); } // verify proper behavior with non-zero offset stream = new ByteArrayOutputStream(); HexDump.dump(testArray, 0x10000000, stream, 0); outputArray = new byte[16 * (73 + HexDump.EOL.length())]; for (int j = 0; j < 16; j++) { int offset = (73 + HexDump.EOL.length()) * j; outputArray[offset++] = (byte) '1'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) toHex(j); outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) ' '; for (int k = 0; k < 16; k++) { outputArray[offset++] = (byte) toHex(j); outputArray[offset++] = (byte) toHex(k); outputArray[offset++] = (byte) ' '; } for (int k = 0; k < 16; k++) { outputArray[offset++] = (byte) toAscii((j * 16) + k); } System.arraycopy( HexDump.EOL.getBytes(), 0, outputArray, offset, HexDump.EOL.getBytes().length); } actualOutput = stream.toByteArray(); assertEquals("array size mismatch", outputArray.length, actualOutput.length); for (int j = 0; j < outputArray.length; j++) { assertEquals("array[ " + j + "] mismatch", outputArray[j], actualOutput[j]); } // verify proper behavior with negative offset stream = new ByteArrayOutputStream(); HexDump.dump(testArray, 0xFF000000, stream, 0); outputArray = new byte[16 * (73 + HexDump.EOL.length())]; for (int j = 0; j < 16; j++) { int offset = (73 + HexDump.EOL.length()) * j; outputArray[offset++] = (byte) 'F'; outputArray[offset++] = (byte) 'F'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) toHex(j); outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) ' '; for (int k = 0; k < 16; k++) { outputArray[offset++] = (byte) toHex(j); outputArray[offset++] = (byte) toHex(k); outputArray[offset++] = (byte) ' '; } for (int k = 0; k < 16; k++) { outputArray[offset++] = (byte) toAscii((j * 16) + k); } System.arraycopy( HexDump.EOL.getBytes(), 0, outputArray, offset, HexDump.EOL.getBytes().length); } actualOutput = stream.toByteArray(); assertEquals("array size mismatch", outputArray.length, actualOutput.length); for (int j = 0; j < outputArray.length; j++) { assertEquals("array[ " + j + "] mismatch", outputArray[j], actualOutput[j]); } // verify proper behavior with non-zero index stream = new ByteArrayOutputStream(); HexDump.dump(testArray, 0x10000000, stream, 0x81); outputArray = new byte[(8 * (73 + HexDump.EOL.length())) - 1]; for (int j = 0; j < 8; j++) { int offset = (73 + HexDump.EOL.length()) * j; outputArray[offset++] = (byte) '1'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) toHex(j + 8); outputArray[offset++] = (byte) '1'; outputArray[offset++] = (byte) ' '; for (int k = 0; k < 16; k++) { final int index = 0x81 + (j * 16) + k; if (index < 0x100) { outputArray[offset++] = (byte) toHex(index / 16); outputArray[offset++] = (byte) toHex(index); } else { outputArray[offset++] = (byte) ' '; outputArray[offset++] = (byte) ' '; } outputArray[offset++] = (byte) ' '; } for (int k = 0; k < 16; k++) { final int index = 0x81 + (j * 16) + k; if (index < 0x100) { outputArray[offset++] = (byte) toAscii(index); } } System.arraycopy( HexDump.EOL.getBytes(), 0, outputArray, offset, HexDump.EOL.getBytes().length); } actualOutput = stream.toByteArray(); assertEquals("array size mismatch", outputArray.length, actualOutput.length); for (int j = 0; j < outputArray.length; j++) { assertEquals("array[ " + j + "] mismatch", outputArray[j], actualOutput[j]); } // verify proper behavior with negative index try { HexDump.dump(testArray, 0x10000000, new ByteArrayOutputStream(), -1); fail("should have caught ArrayIndexOutOfBoundsException on negative index"); } catch (final ArrayIndexOutOfBoundsException ignored_exception) { // as expected } // verify proper behavior with index that is too large try { HexDump.dump(testArray, 0x10000000, new ByteArrayOutputStream(), testArray.length); fail("should have caught ArrayIndexOutOfBoundsException on large index"); } catch (final ArrayIndexOutOfBoundsException ignored_exception) { // as expected } // verify proper behavior with null stream try { HexDump.dump(testArray, 0x10000000, null, 0); fail("should have caught IllegalArgumentException on negative index"); } catch (final IllegalArgumentException ignored_exception) { // as expected } }
public static void decrypt(String sinfile) { byte[] buf = new byte[1024]; try { String folder = new File((new File(sinfile)).getParent()).getAbsolutePath(); FileInputStream f = new FileInputStream(sinfile); // DecodeInputStream in = new DecodeInputStream(f); RC4DecryptingInputStream in = new RC4DecryptingInputStream(f); String basefile = sinfile + "_dek"; OutputStream out = new FileOutputStream(basefile + ".zip.gz"); int len; while ((len = in.read(buf)) >= 0) { out.write(buf, 0, len); } out.flush(); out.close(); in.close(); byte[] magic = new byte[2]; FileInputStream fload = new FileInputStream(new File(basefile + ".zip.gz")); fload.read(magic); fload.close(); if (HexDump.toHex(magic).equals("[1F, 8B]")) { File fxml = new File(folder + "\\update.xml"); if (fxml.isFile()) fxml.renameTo(new File(folder + "\\update1.xml")); try { if (OS.getName().equals("windows")) { ProcessBuilderWrapper run = new ProcessBuilderWrapper( new String[] {OS.get7z(), "e", "-y", basefile + ".zip.gz", "-o" + folder}, false); } else { ProcessBuilderWrapper run = new ProcessBuilderWrapper(new String[] {"gunzip", basefile + ".zip.gz"}, false); } } catch (Exception e) { } fload = new FileInputStream(new File(basefile + ".zip")); fload.read(magic); fload.close(); if (HexDump.toHex(magic).equals("[50, 4B]")) { try { if (OS.getName().equals("windows")) { ProcessBuilderWrapper run1 = new ProcessBuilderWrapper( new String[] {OS.get7z(), "e", "-y", basefile + ".zip", "-o" + folder}, false); } else { ProcessBuilderWrapper run1 = new ProcessBuilderWrapper( new String[] {"unzip", "-o", basefile + ".zip", "-d", folder}, false); } } catch (Exception e1) { } } else if (HexDump.toHex(magic).equals("[2F, 2F]")) { File fl = new File(basefile + ".zip"); fl.renameTo(new File(folder + "/preset1.ta")); } else { File fl = new File(basefile + ".zip"); fl.renameTo(new File(folder + "/loader.sin")); } } File fdek = new File(basefile + ".zip.gz"); fdek.delete(); File ftar = new File(basefile + ".zip"); ftar.delete(); if (new File(folder + File.separator + "boot.zip").exists()) { OS.ZipExplode(folder + File.separator + "boot.zip"); new File(folder + File.separator + "boot.zip").delete(); } } catch (IOException e) { e.printStackTrace(); } }