diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c1c96da..4f70fa6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - java: [ '7.x', '8.x', '9.x', '10.x', '11.x', '12.x', '13.x' ] + java: [ '8.x', '9.x', '10.x', '11.x', '12.x', '13.x' ] steps: - uses: actions/checkout@v1 - name: Set up JDK ${{ matrix.java }} @@ -15,6 +15,4 @@ jobs: with: java-version: ${{ matrix.java }} - name: Build with Maven - run: | - mvn install:install-file -Dfile=lib/HexLib.jar -DgroupId=at.HexLib -DartifactId=HexLib -Dversion=0.0.0 -Dpackaging=jar -DlocalRepositoryPath=./lib - mvn -B package --file pom.xml + run: mvn -B package --file pom.xml diff --git a/README.md b/README.md index 32f6449..3ea7272 100644 --- a/README.md +++ b/README.md @@ -28,30 +28,12 @@ access to it in a nice, easy-to-comprehend API. ## Build Install java, maven and, if on windows, git-bash -First, install dependencies into local maven repository: - -```bash -mvn install:install-file -Dfile=lib/HexLib.jar -DgroupId=at.HexLib -DartifactId=HexLib -Dversion=0.0.0 -Dpackaging=jar -DlocalRepositoryPath=./lib -``` - -Then build project as usual: +Run in console: ```bash mvn install ``` -If you got error: -```bash -[WARNING] The POM for kaitai_struct_visualizer_java:HexLib:jar:0.0.0 is missing, no dependency information available -``` -it means, that you already tried to build project without success and maven cache -unsuccessful state of dependency resolution. Just add switch `-U` to maven invocation -to force maven re-check dependencies: - -```bash -$ mvn -U install -``` - ## Licensing This GUI vis tool project itself is copyright (C) 2016-2019 Kaitai @@ -77,4 +59,4 @@ Vis tool depends on the following libraries: * [kaitai_struct_compiler](https://github.com/kaitai_struct_compiler) — GPLv3+ license * [fastparse](http://www.lihaoyi.com/fastparse/) — MIT license * [snakeyaml](https://bitbucket.org/asomov/snakeyaml) — Apache 2.0 license -* [HexLib](http://hexedit-lib.sourceforge.net/) — FreeBSD license +* [JHexView](https://github.com/Mingun/JHexView) — LGPL-2.1 license diff --git a/pom.xml b/pom.xml index 68632bd..308231c 100644 --- a/pom.xml +++ b/pom.xml @@ -40,9 +40,9 @@ 0.8 - at.HexLib - HexLib - 0.0.0 + ru.mingun + JHexView + 2.1 com.github.olivergondza @@ -63,8 +63,8 @@ maven-compiler-plugin 3.8.1 - 1.7 - 1.7 + 1.8 + 1.8 @@ -112,8 +112,10 @@ - local-jars - file://${project.basedir}/lib + + bintray-mingun-maven + bintray + https://dl.bintray.com/mingun/maven diff --git a/src/main/java/io/kaitai/struct/visualizer/VisualizerPanel.java b/src/main/java/io/kaitai/struct/visualizer/VisualizerPanel.java index 01d6357..4b0cef6 100644 --- a/src/main/java/io/kaitai/struct/visualizer/VisualizerPanel.java +++ b/src/main/java/io/kaitai/struct/visualizer/VisualizerPanel.java @@ -1,6 +1,7 @@ package io.kaitai.struct.visualizer; -import java.awt.Point; +import java.awt.Color; +import java.awt.Font; import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.Method; @@ -9,9 +10,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import at.HexLib.library.HexLib; -import at.HexLib.library.HexLibSelectionModel; - import io.kaitai.struct.ByteBufferKaitaiStream; import io.kaitai.struct.CompileLog; import io.kaitai.struct.KaitaiStream; @@ -37,6 +35,9 @@ import javax.swing.JSplitPane; import javax.swing.JTree; +import tv.porst.jhexview.JHexView; +import tv.porst.jhexview.SimpleDataProvider; + public class VisualizerPanel extends JPanel { private static final String DEST_PACKAGE = "io.kaitai.struct.visualized"; /** @@ -51,9 +52,16 @@ public class VisualizerPanel extends JPanel { /** Regexp, used to get parameter names from the generated source. */ private static final Pattern PARAMETER_NAME = Pattern.compile(", \\S+ ([^,\\s]+)"); + /** Color of hex editor section headers. */ + private static final Color HEADER = new Color(0x0000c0); + /** Color of hex data in HEX and ASCII sections. */ + private static final Color UNMODIFIED = Color.BLACK; + /** Background color selected hex data in HEX and ASCII sections. */ + private static final Color SELECTION = new Color(0xc0c0c0); + private final JTree tree = new JTree(); private final DefaultTreeModel model = new DefaultTreeModel(null); - private final HexLib hexEditor = new HexLib(new byte[0]); + private final JHexView hexEditor = new JHexView(); private final JSplitPane splitPane; private KaitaiStruct struct; @@ -62,6 +70,24 @@ public VisualizerPanel() throws IOException { super(); JScrollPane treeScroll = new JScrollPane(tree); + hexEditor.setSeparatorsVisible(false); + hexEditor.setBytesPerColumn(1); + hexEditor.setColumnSpacing(8); + hexEditor.setHeaderFontStyle(Font.BOLD); + + hexEditor.setFontColorHeader(HEADER); + hexEditor.setFontColorOffsetView(HEADER); + + hexEditor.setFontColorHexView1(UNMODIFIED); + hexEditor.setFontColorHexView2(UNMODIFIED); + hexEditor.setFontColorAsciiView(UNMODIFIED); + + hexEditor.setSelectionColor(SELECTION); + + hexEditor.setBackgroundColorOffsetView(hexEditor.getBackground()); + hexEditor.setBackgroundColorHexView(hexEditor.getBackground()); + hexEditor.setBackgroundColorAsciiView(hexEditor.getBackground()); + splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, treeScroll, hexEditor); tree.setShowsRootHandles(true); @@ -79,7 +105,8 @@ public void loadAll(String dataFileName, String ksyFileName) throws Exception { private void loadStruct() throws IOException { struct._io().seek(0); byte[] buf = struct._io().readBytesFull(); - hexEditor.setByteContent(buf); + hexEditor.setData(new SimpleDataProvider(buf)); + hexEditor.setDefinitionStatus(JHexView.DefinitionStatus.DEFINED); final DataNode root = new DataNode(0, struct, "[root]"); model.setRoot(root); @@ -195,16 +222,17 @@ public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoExceptio @Override public void valueChanged(TreeSelectionEvent event) { - TreePath path = event.getPath(); - if (path.getLastPathComponent() instanceof DataNode) { - DataNode node = (DataNode) path.getLastPathComponent(); - if (node.posStart() == null || node.posEnd() == null) - return; - HexLibSelectionModel select = hexEditor.getSelectionModel(); - ArrayList intervals = new ArrayList<>(); - intervals.add(new Point(node.posStart(), node.posEnd())); - select.setSelectionIntervals(intervals); - System.out.println(node.posStart() + " - " + node.posEnd()); + hexEditor.getSelectionModel().clearSelection(); + for (final TreePath path : tree.getSelectionPaths()) { + final Object selected = path.getLastPathComponent(); + if (!(selected instanceof DataNode)) continue; + + final DataNode node = (DataNode)selected; + final Integer start = node.posStart(); + final Integer end = node.posEnd(); + if (start == null || end == null) continue; + // Selection in nibbles, so multiply by 2 + hexEditor.getSelectionModel().addSelectionInterval(2*start, 2*end-1); } } }