private void addLineBreaksToHexDump(byte[] id, byte[] data) { // add linefeeds to the dump int lnCount = _hexDumpArea.getText().length() / 48; int rest = _hexDumpArea.getText().length() % 48; for (int i = 1; i <= lnCount; i++) { int pos = i * 67 - 20; try { int idx = i - 1; String ansci = idx == 0 ? (Util.toAnsci(id, 0, id.length) + Util.toAnsci(data, 0, 16 - id.length)) : Util.toAnsci(data, idx * 16 - id.length, idx * 16 + 16 - id.length); _hexStyledDoc.replace(pos, 1, " " + ansci + "\n", _hexStyledDoc.getStyle("base")); // _hexStyledDoc.remove(pos,1); // _hexStyledDoc.insertString(pos, "\n", _hexStyledDoc.getStyle("base")); } catch (BadLocationException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } // rest if (rest != 0) { try { int pos = lnCount * 67 + rest; String space = ""; int spaceCount = 48 - rest; while (spaceCount-- > 0) space += " "; String ansci = lnCount == 0 ? (Util.toAnsci(id, 0, id.length) + Util.toAnsci(data, 0, data.length - id.length)) : Util.toAnsci(data, lnCount * 16 - id.length, data.length - id.length); _hexStyledDoc.insertString(pos, space + " " + ansci, _hexStyledDoc.getStyle("base")); } catch (BadLocationException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }
public void updateCurrentPacket(boolean forced) { if (!forced && _currentSelectedPacket == _packetTable.getSelectedRow()) return; /*try { DataStructure gp = _gameSessionViewer.getPacket(_currentSelectedPacket); if(gp!= null) gp.setViewed(false); } catch (IndexOutOfBoundsException e) { }*/ _currentSelectedPacket = _packetTable.getSelectedRow(); // reset the selected part as we selected another packet _currentSelectedPart = null; DataPacket gp = _gameSessionViewer.getPacket(_currentSelectedPacket); // gp.setViewed(true); // System.out.println("Selected row/packet: "+_table.getSelectedRow()); _hexDumpArea.setText(""); if (gp.getPacketFormat() != null && gp.isValid()) { _packetFormat.setText(gp.getPacketFormat().getPartsStr()); // colorfull hex dump :P // opcode if (gp.getPacketId() != null) { for (IdPart part : gp.getPacketId().getParts()) { int bytes = part.getType().getTypeByteNumber(); for (int i2 = 0; i2 < bytes; i2++) { addStyledText( Util.zeropad(Long.toHexString(part.getValue() << (8 * i2) & 0xff), 2).toUpperCase(), "op"); if (i2 < bytes - 1) addStyledText(" ", "op"); } addStyledText(" ", "base"); } } // chksum if (gp.getProtocol().getChecksumSize() > 0) { int size = gp.getProtocol().getChecksumSize(); for (int i = 1; i < size + 1; i++) { addStyledText( Util.zeropad(Integer.toHexString(gp.getIdData()[i] & 0xff), 2).toUpperCase(), "chk"); if (i < size) addStyledText(" ", "chk"); } addStyledText(" ", "base"); } // parsed packet parts for (ValuePart part : gp.getValuePartList()) { addStyledText(Util.rawHexDump(part.getBytes()), part.getType().getName(), true); addStyledText(" ", "base"); } // unparsed data (if any) addStyledText(Util.rawHexDump(gp.getUnparsedData()), "base"); this.addLineBreaksToHexDump(gp.getIdData(), gp.getByteBuffer().array()); int opSize = 0; for (PartType pt : gp.getPacketFormat().getIdParts()) { opSize += pt.getTypeByteNumber() * 3; } DataPartNode root = new DataPartNode(gp.getRootNode(), opSize + gp.getProtocol().getChecksumSize() * 3); _packetViewTableModel.setRoot(root); _packetViewTable.revalidate(); _packetViewTable.expandAll(); } else { // clear the format _packetFormat.setText(""); // dump everything _hexDumpArea.setText(""); // if we know the opcode but the format was invalid still show the opcode if (gp.getFormat() != null) { for (IdPart part : gp.getPacketId().getParts()) { int bytes = part.getType().getTypeByteNumber(); for (int i2 = 0; i2 < bytes; i2++) { addStyledText( Util.zeropad(Long.toHexString(part.getValue() << (8 * i2) & 0xff), 2).toUpperCase(), "op"); if (i2 < bytes - 1) addStyledText(" ", "op"); } addStyledText(" ", "base"); } } ViewPane.this.addStyledText(Util.rawHexDump(gp.getData()), "base"); this.addLineBreaksToHexDump(gp.getIdData(), gp.getByteBuffer().array()); // no part for u _packetViewTableModel.setRoot(null); } }