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"; }
private void uploadImage(InputStream fileinputstream, int buffer) throws X10FlashException { try { processHeader(fileinputstream); int readCount; do { if (buffer == 0x1000) readCount = fileinputstream.read(readarray4); else readCount = fileinputstream.read(readarray65); if (readCount > 0) if (buffer == 0x1000) cmd.send( Command.CMD06, BytesUtil.getReply(readarray4, readCount), (readCount == buffer)); else cmd.send( Command.CMD06, BytesUtil.getReply(readarray65, readCount), (readCount == buffer)); if (readCount != buffer) break; } while (true); fileinputstream.close(); if (USBFlash.getLastFlags() == 0) getLastError(); } catch (Exception e) { try { fileinputstream.close(); } catch (Exception cl) { } throw new X10FlashException(e.getMessage()); } }
public SinHashBlock(byte[] hashblock, int index) { this.spare = spare; byte[] offset = new byte[4]; byte[] length = new byte[4]; System.arraycopy(hashblock, 0, offset, 0, 4); System.arraycopy(hashblock, 4, length, 0, 4); boffset = BytesUtil.getLong(offset); blength = BytesUtil.getInt(length); hashsize = hashblock[8]; blockindex = index; }
/** the reverse of dictIdToString(), returns integer ID */ public static int stringToDictId(String str) { try { byte[] bytes = str.getBytes("ISO-8859-1"); return BytesUtil.readUnsigned(bytes, 0, bytes.length); } catch (UnsupportedEncodingException e) { // never happen return 0; } }
public static String encrypt(byte[] key, Map<String, Object> req) { String request = JsonUtil.toJson(req).toString(); byte[] hex = null; try { hex = DESUtil.ecbEncrypt(key, request.getBytes(), 2); } catch (GeneralSecurityException e) { logger.error(e.getMessage()); logger.error(e.getStackTrace().toString()); } return BytesUtil.bytesToHex(hex); }
public void print() { System.out.println( BytesUtil.getHexString(this.buffer) + "\n" + "-----------------------------------------------------------\n" + "I:" + position() + " L:" + length() + " C:" + capasity()); }
public String dumpProperty(int prnumber) throws IOException, X10FlashException { MyLogger.getLogger().info("Start Reading property"); MyLogger.getLogger() .debug((new StringBuilder("%%% read property id=")).append(prnumber).toString()); cmd.send(Command.CMD12, BytesUtil.getBytesWord(prnumber, 4), false); MyLogger.updateProgress(); String reply = cmd.getLastReplyHex(); reply = reply.replace("[", ""); reply = reply.replace("]", ""); reply = reply.replace(",", ""); MyLogger.getLogger().info("Reading property finished."); return reply; }
private void processHeader(InputStream fileinputstream) throws X10FlashException { try { byte abyte0[] = new byte[6]; int j = fileinputstream.read(abyte0); if (j != 6) { fileinputstream.close(); throw new X10FlashException("Error in processHeader"); } int k; byte abyte1[] = new byte[4]; System.arraycopy(abyte0, 2, abyte1, 0, 4); k = BytesUtil.getInt(abyte1); abyte1 = new byte[k - 6]; k = fileinputstream.read(abyte1); if (k != abyte1.length) { fileinputstream.close(); throw new X10FlashException("Error in processHeader"); } cmd.send(Command.CMD05, BytesUtil.concatAll(abyte0, abyte1), false); if (USBFlash.getLastFlags() == 0) getLastError(); } catch (IOException ioe) { throw new X10FlashException("Error in processHeader : " + ioe.getMessage()); } }
public void dumpProperties() throws IOException, X10FlashException { TextFile tazone = new TextFile("./tazone.ta", "ISO8859-1"); tazone.open(false); TextFile tazoneS = new TextFile("./tazoneString.ta", "ISO8859-1"); tazoneS.open(false); try { MyLogger.getLogger().info("Start Dumping properties"); MyLogger.initProgress(4920); for (int i = 0; i < 4920; i++) { MyLogger.getLogger() .debug((new StringBuilder("%%% read property id=")).append(i).toString()); cmd.send(Command.CMD12, BytesUtil.getBytesWord(i, 4), false); String reply = cmd.getLastReplyHex(); String replyS = cmd.getLastReplyString(); reply = reply.replace("[", ""); reply = reply.replace("]", ""); reply = reply.replace(",", ""); if (cmd.getLastReplyLength() > 0) { tazone.writeln( HexDump.toHex(i) + " " + HexDump.toHex(cmd.getLastReplyLength()) + " " + reply.trim()); tazoneS.writeln( HexDump.toHex(i) + " " + HexDump.toHex(cmd.getLastReplyLength()) + " " + replyS.trim()); } } MyLogger.initProgress(0); tazone.close(); tazoneS.close(); MyLogger.getLogger().info("Dumping properties finished."); DeviceChangedListener.pause(false); closeDevice(); } catch (Exception ioe) { tazone.close(); tazoneS.close(); MyLogger.initProgress(0); MyLogger.getLogger().error(ioe.getMessage()); MyLogger.getLogger().error("Error dumping properties. Aborted"); DeviceChangedListener.pause(false); closeDevice(); } }
public static byte[] crc(byte[] data, int start, int size) { long c = crc(0, data, start, size); return BytesUtil.int2bytes((int) c, false); }
public int getGptpLength() { return BytesUtil.getInt(gptplength); }
public int getMmcfLength() { return BytesUtil.getInt(mmcflength); }