Compare commits

..

39 Commits

Author SHA1 Message Date
fe0381c762 Bump liberty and termo
All checks were successful
Alpine 3.21 Success
Arch Linux AUR Success
OpenBSD 7.6 Success
2025-06-04 22:09:41 +02:00
019c4302ad Handle tiny files gracefully
All checks were successful
Alpine 3.20 Success
Arch Linux AUR Success
OpenBSD 7.5 Success
Lua detection functions used to cause fatal errors on failure to read.

We could also reconsider treating detection errors as fatal.
2024-12-08 22:37:12 +01:00
189bf94034 Bump liberty
All checks were successful
Alpine 3.20 Success
Arch Linux AUR Success
OpenBSD 7.5 Success
2024-08-08 09:25:23 +02:00
3071db8e19 Be actually able to use a system Termo library
All checks were successful
Alpine 3.19 Success
Arch Linux AUR Success
OpenBSD 7.3 Success
2024-04-10 17:32:50 +02:00
0bbcbb7207 Fix build on Alpine
All checks were successful
Arch Linux AUR Success
Alpine 3.19 Success
2024-04-09 20:47:01 +02:00
d57db951aa Plugin load errors should not be fatal
All checks were successful
Arch Linux AUR Success
2024-02-26 23:54:05 +01:00
417115c3be Bump liberty 2024-02-10 12:51:05 +01:00
3c96448bcf Bump liberty, add an icon 2024-02-10 11:06:55 +01:00
92902a4f76 CMakeLists.txt: declare compatibility with 3.27
Sadly, the 3.5 deprecation warning doesn't go away after this.
2023-08-01 03:16:04 +02:00
43ef4805a5 Bump liberty 2023-07-04 06:55:15 +02:00
a29a785b20 README.adoc: update package information 2023-07-01 22:00:04 +02:00
accc095403 Bump liberty 2023-06-28 16:29:28 +02:00
b15ec36e38 CMakeLists.txt: fix build on BSD and macOS 2023-06-28 16:27:34 +02:00
b000f5eca7 README.adoc: add a missing line break 2023-06-28 01:10:31 +02:00
35cbb8647d CMakeLists.txt: actually install Lua plugins 2023-06-28 00:29:57 +02:00
f6d552766b g_ctx -> g
Because it's just plain noise.  But I still enjoy the indicator.
2023-06-19 13:20:28 +02:00
00d6c5ede9 Bump liberty, move the UI to liberty-xui.c
This deduplicates code between nncmpp and hex,
while adding functionality.
2023-06-19 13:19:48 +02:00
b87206bb93 elf.lua: fix a typo 2023-06-18 22:46:10 +02:00
62c6d43ca3 Add a real manual page 2023-06-15 22:32:02 +02:00
ccb3974895 Avoid ringing the bell on focus events 2023-06-05 20:00:06 +02:00
c7a6e9ec36 README.adoc: fix a dead link 2022-07-31 18:44:09 +02:00
c7448a72a2 README.adoc: mention fq 2022-03-11 20:43:45 +01:00
1cb069aa8b Fix second nibbles in the hex dump
Welp.
2021-12-01 05:03:41 +01:00
9489358c92 xcursor.lua: fix file version decoding
The Xcursor header file contains more documentation than there is
in the actual documentation.
2021-11-17 12:18:37 +01:00
a539a5510f Add an elementary decoder for Xcursor files 2021-11-17 11:48:10 +01:00
e5ddd6a6af Fix a compiler warning 2021-11-05 02:59:55 +01:00
8f7bcf7531 Bump liberty, termo 2021-11-05 02:59:35 +01:00
330e81fa89 Update .gitignore 2021-10-30 03:32:53 +02:00
84831a1492 Bind _/C-a/$/C-e to go to row start/end
Avoiding 0 because that's how you would write a zero in edit mode.
2021-10-30 02:59:09 +02:00
ada863925f Add clang-format configuration 2021-10-30 02:59:09 +02:00
28f36f6087 CMakeLists.txt: synchronize with sdtui 2021-10-30 01:36:48 +02:00
252e349e52 README.adoc: mention elfcat 2021-07-07 19:25:38 +02:00
a41d67432d Fix incomplete liberty bump 2021-01-16 16:43:00 +01:00
5e66f5402d Bump minimum CMake version to 3.0
A nice, round number.  This allows us to remove some boilerplate.
2020-10-27 11:53:49 +01:00
38694ea520 Bump liberty and termo 2020-10-27 11:53:03 +01:00
0304e4fcee README.adoc: update refs to similar software 2020-10-18 22:57:15 +02:00
b3f117a785 Name change 2020-09-28 05:10:27 +02:00
d87ae4bfba Bump liberty and termo 2020-09-28 05:09:20 +02:00
16e24195e7 Cleanup, add comment 2018-10-27 15:08:18 +02:00
21 changed files with 907 additions and 663 deletions

32
.clang-format Normal file
View File

@@ -0,0 +1,32 @@
# clang-format is fairly limited, and these rules are approximate:
# - array initializers can get terribly mangled with clang-format 12.0,
# - sometimes it still aligns with space characters,
# - struct name NL { NL ... NL } NL name; is unachievable.
BasedOnStyle: GNU
ColumnLimit: 80
IndentWidth: 4
TabWidth: 4
UseTab: ForContinuationAndIndentation
BreakBeforeBraces: Allman
SpaceAfterCStyleCast: true
AlignAfterOpenBracket: DontAlign
AlignOperands: DontAlign
AlignConsecutiveMacros: Consecutive
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
IndentGotoLabels: false
# IncludeCategories has some potential, but it may also break the build.
# Note that the documentation says the value should be "Never".
SortIncludes: false
# This is a compromise, it generally works out aesthetically better.
BinPackArguments: false
# Unfortunately, this can't be told to align to column 40 or so.
SpacesBeforeTrailingComments: 2
# liberty-specific macro body wrappers.
MacroBlockBegin: "BLOCK_START"
MacroBlockEnd: "BLOCK_END"
ForEachMacros: ["LIST_FOR_EACH"]

2
.gitignore vendored
View File

@@ -7,3 +7,5 @@
/hex.files /hex.files
/hex.creator* /hex.creator*
/hex.includes /hex.includes
/hex.cflags
/hex.cxxflags

View File

@@ -1,21 +1,12 @@
project (hex C) cmake_minimum_required (VERSION 3.0...3.27)
cmake_minimum_required (VERSION 2.8.5) project (hex VERSION 0.1.0 LANGUAGES C)
# Moar warnings # Moar warnings
if ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR CMAKE_COMPILER_IS_GNUCC) if ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR CMAKE_COMPILER_IS_GNUCC)
set (wdisabled "-Wno-unused-function -Wno-implicit-fallthrough") set (wdisabled "-Wno-unused-function")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wall -Wextra ${wdisabled}") set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wall -Wextra ${wdisabled}")
endif () endif ()
# Version
set (project_VERSION_MAJOR "0")
set (project_VERSION_MINOR "1")
set (project_VERSION_PATCH "0")
set (project_VERSION "${project_VERSION_MAJOR}")
set (project_VERSION "${project_VERSION}.${project_VERSION_MINOR}")
set (project_VERSION "${project_VERSION}.${project_VERSION_PATCH}")
# For custom modules # For custom modules
set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/liberty/cmake) set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/liberty/cmake)
@@ -29,29 +20,30 @@ include (AddThreads)
find_package (Termo QUIET NO_MODULE) find_package (Termo QUIET NO_MODULE)
option (USE_SYSTEM_TERMO option (USE_SYSTEM_TERMO
"Don't compile our own termo library, use the system one" ${Termo_FOUND}) "Don't compile our own termo library, use the system one" ${Termo_FOUND})
if (USE_SYSTEM_TERMO) if (USE_SYSTEM_TERMO)
if (NOT Termo_FOUND) if (NOT Termo_FOUND)
message (FATAL_ERROR "System termo library not found") message (FATAL_ERROR "System termo library not found")
endif (NOT Termo_FOUND) endif ()
else () else ()
# We don't want the library to install, but EXCLUDE_FROM_ALL ignores tests
add_subdirectory (termo EXCLUDE_FROM_ALL) add_subdirectory (termo EXCLUDE_FROM_ALL)
# We don't have many good choices when we don't want to install it and want file (WRITE ${PROJECT_BINARY_DIR}/CTestCustom.cmake
# to support older versions of CMake; this is a relatively clean approach "execute_process (COMMAND ${CMAKE_COMMAND} --build termo)")
# (other possibilities: setting a variable in the parent scope, using a
# cache variable, writing a special config file with build paths in it and # We don't have many good choices; this is a relatively clean approach
# including it here, or setting a custom property on the targets). # (other possibilities: setting a variable in the parent scope, using
# a cache variable, writing a special config file with build paths in it
# and including it here, or setting a custom property on the targets)
get_directory_property (Termo_INCLUDE_DIRS get_directory_property (Termo_INCLUDE_DIRS
DIRECTORY termo INCLUDE_DIRECTORIES) DIRECTORY termo INCLUDE_DIRECTORIES)
set (Termo_LIBRARIES termo-static) set (Termo_LIBRARIES termo-static)
endif () endif ()
set (project_libraries ${UNISTRING_LIBRARIES} set (project_libraries ${Unistring_LIBRARIES}
${NCURSESW_LIBRARIES} termo-static) ${Ncursesw_LIBRARIES} ${Termo_LIBRARIES})
pkg_search_module (lua lua53 lua5.3 lua-5.3 lua>=5.3) pkg_search_module (lua lua53 lua5.3 lua-5.3 lua54 lua5.4 lua-5.4 lua>=5.3)
option (WITH_LUA "Enable support for Lua plugins" ${lua_FOUND}) option (WITH_LUA "Enable support for Lua plugins" ${lua_FOUND})
if (WITH_LUA) if (WITH_LUA)
if (NOT lua_FOUND) if (NOT lua_FOUND)
message (FATAL_ERROR "Lua library not found") message (FATAL_ERROR "Lua library not found")
@@ -60,28 +52,37 @@ if (WITH_LUA)
list (APPEND project_libraries ${lua_LIBRARIES}) list (APPEND project_libraries ${lua_LIBRARIES})
include_directories (${lua_INCLUDE_DIRS}) include_directories (${lua_INCLUDE_DIRS})
link_directories (${lua_LIBRARY_DIRS}) link_directories (${lua_LIBRARY_DIRS})
include (CheckTypeSize)
set (CMAKE_REQUIRED_LIBRARIES ${lua_LIBRARIES})
set (CMAKE_REQUIRED_INCLUDES ${lua_INCLUDE_DIRS})
set (CMAKE_EXTRA_INCLUDE_FILES "lua.h")
CHECK_TYPE_SIZE (lua_Integer LUA_INTEGER)
if (NOT HAVE_LUA_INTEGER OR LUA_INTEGER LESS 8)
message (FATAL_ERROR "Lua must have at least 64-bit integers")
endif ()
endif () endif ()
include_directories (${UNISTRING_INCLUDE_DIRS} pkg_check_modules (x11 x11 xrender xft fontconfig libpng)
${NCURSESW_INCLUDE_DIRS} ${Termo_INCLUDE_DIRS}) option (WITH_X11 "Build with X11 support" ${x11_FOUND})
if (WITH_X11)
if (NOT x11_FOUND)
message (FATAL_ERROR "Some X11 libraries were not found")
endif ()
list (APPEND project_libraries ${x11_LIBRARIES})
include_directories (${x11_INCLUDE_DIRS})
link_directories (${x11_LIBRARY_DIRS})
endif ()
include_directories (${Unistring_INCLUDE_DIRS}
${Ncursesw_INCLUDE_DIRS} ${Termo_INCLUDE_DIRS})
# Configuration # Configuration
if ("${CMAKE_SYSTEM_NAME}" MATCHES "BSD")
# Need this for SIGWINCH in FreeBSD and OpenBSD respectively;
# our POSIX version macros make it undefined
add_definitions (-D__BSD_VISIBLE=1 -D_BSD_SOURCE=1)
elseif (APPLE)
add_definitions (-D_DARWIN_C_SOURCE)
endif ()
include (CheckFunctionExists) include (CheckFunctionExists)
set (CMAKE_REQUIRED_LIBRARIES ${NCURSESW_LIBRARIES}) set (CMAKE_REQUIRED_LIBRARIES ${Ncursesw_LIBRARIES})
CHECK_FUNCTION_EXISTS ("resizeterm" HAVE_RESIZETERM) CHECK_FUNCTION_EXISTS ("resizeterm" HAVE_RESIZETERM)
# Generate a configuration file # Generate a configuration file
set (HAVE_LUA "${WITH_LUA}")
configure_file (${PROJECT_SOURCE_DIR}/config.h.in configure_file (${PROJECT_SOURCE_DIR}/config.h.in
${PROJECT_BINARY_DIR}/config.h) ${PROJECT_BINARY_DIR}/config.h)
include_directories (${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR}) include_directories (${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR})
@@ -95,21 +96,67 @@ add_threads (${PROJECT_NAME})
include (GNUInstallDirs) include (GNUInstallDirs)
install (TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR}) install (TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
install (FILES LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR}) install (FILES LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR})
if (WITH_LUA)
install (DIRECTORY plugins
DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME})
endif ()
if (WITH_X11)
include (IconUtils)
# Generate documentation from program help set (icon_base ${PROJECT_BINARY_DIR}/icons)
find_program (HELP2MAN_EXECUTABLE help2man) set (icon_png_list)
if (NOT HELP2MAN_EXECUTABLE) foreach (icon_size 16 32 48)
message (FATAL_ERROR "help2man not found") icon_to_png (${PROJECT_NAME} ${PROJECT_SOURCE_DIR}/${PROJECT_NAME}.svg
${icon_size} ${icon_base} icon_png)
list (APPEND icon_png_list ${icon_png})
endforeach ()
add_custom_target (icons ALL DEPENDS ${icon_png_list})
install (FILES ${PROJECT_NAME}.svg
DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/scalable/apps)
install (DIRECTORY ${icon_base}
DESTINATION ${CMAKE_INSTALL_DATADIR})
install (FILES ${PROJECT_NAME}.desktop
DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
endif ()
# Generate documentation from text markup
find_program (ASCIIDOCTOR_EXECUTABLE asciidoctor)
find_program (A2X_EXECUTABLE a2x)
if (NOT ASCIIDOCTOR_EXECUTABLE AND NOT A2X_EXECUTABLE)
message (WARNING "Neither asciidoctor nor a2x were found, "
"falling back to a substandard manual page generator")
endif () endif ()
foreach (page ${PROJECT_NAME}) foreach (page ${PROJECT_NAME})
set (page_output "${PROJECT_BINARY_DIR}/${page}.1") set (page_output "${PROJECT_BINARY_DIR}/${page}.1")
list (APPEND project_MAN_PAGES "${page_output}") list (APPEND project_MAN_PAGES "${page_output}")
if (ASCIIDOCTOR_EXECUTABLE)
add_custom_command (OUTPUT ${page_output} add_custom_command (OUTPUT ${page_output}
COMMAND ${HELP2MAN_EXECUTABLE} -N COMMAND ${ASCIIDOCTOR_EXECUTABLE} -b manpage
"${PROJECT_BINARY_DIR}/${page}" -o ${page_output} -a release-version=${PROJECT_VERSION}
DEPENDS ${page} -o "${page_output}"
"${PROJECT_SOURCE_DIR}/${page}.adoc"
DEPENDS ${page}.adoc
COMMENT "Generating man page for ${page}" VERBATIM) COMMENT "Generating man page for ${page}" VERBATIM)
elseif (A2X_EXECUTABLE)
add_custom_command (OUTPUT ${page_output}
COMMAND ${A2X_EXECUTABLE} --doctype manpage --format manpage
-a release-version=${PROJECT_VERSION}
-D "${PROJECT_BINARY_DIR}"
"${PROJECT_SOURCE_DIR}/${page}.adoc"
DEPENDS ${page}.adoc
COMMENT "Generating man page for ${page}" VERBATIM)
else ()
set (ASCIIMAN ${PROJECT_SOURCE_DIR}/liberty/tools/asciiman.awk)
add_custom_command (OUTPUT ${page_output}
COMMAND env LC_ALL=C asciidoc-release-version=${PROJECT_VERSION}
awk -f ${ASCIIMAN} "${PROJECT_SOURCE_DIR}/${page}.adoc"
> ${page_output}
DEPENDS ${page}.adoc ${ASCIIMAN}
COMMENT "Generating man page for ${page}" VERBATIM)
endif ()
endforeach () endforeach ()
add_custom_target (docs ALL DEPENDS ${project_MAN_PAGES}) add_custom_target (docs ALL DEPENDS ${project_MAN_PAGES})
@@ -121,20 +168,17 @@ foreach (page ${project_MAN_PAGES})
endforeach () endforeach ()
# CPack # CPack
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "Hex viewer") set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "Interpreting hex viewer")
set (CPACK_PACKAGE_VENDOR "Premysl Janouch") set (CPACK_PACKAGE_VENDOR "Premysl Eric Janouch")
set (CPACK_PACKAGE_CONTACT "Přemysl Janouch <p@janouch.name>") set (CPACK_PACKAGE_CONTACT "Přemysl Eric Janouch <p@janouch.name>")
set (CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE") set (CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
set (CPACK_PACKAGE_VERSION_MAJOR ${project_VERSION_MAJOR})
set (CPACK_PACKAGE_VERSION_MINOR ${project_VERSION_MINOR})
set (CPACK_PACKAGE_VERSION_PATCH ${project_VERSION_PATCH})
set (CPACK_GENERATOR "TGZ;ZIP") set (CPACK_GENERATOR "TGZ;ZIP")
set (CPACK_PACKAGE_FILE_NAME set (CPACK_PACKAGE_FILE_NAME
"${PROJECT_NAME}-${project_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}") "${PROJECT_NAME}-${PROJECT_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
set (CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME}-${project_VERSION}") set (CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME}-${PROJECT_VERSION}")
set (CPACK_SOURCE_GENERATOR "TGZ;ZIP") set (CPACK_SOURCE_GENERATOR "TGZ;ZIP")
set (CPACK_SOURCE_IGNORE_FILES "/\\\\.git;/build;/CMakeLists.txt.user") set (CPACK_SOURCE_IGNORE_FILES "/\\\\.git;/build;/CMakeLists.txt.user")
set (CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${project_VERSION}") set (CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}")
set (CPACK_SET_DESTDIR TRUE) set (CPACK_SET_DESTDIR TRUE)
include (CPack) include (CPack)

View File

@@ -1,4 +1,4 @@
Copyright (c) 2016 - 2017, Přemysl Janouch <p@janouch.name> Copyright (c) 2016 - 2024, Přemysl Eric Janouch <p@janouch.name>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted. purpose with or without fee is hereby granted.

View File

@@ -3,7 +3,7 @@ hex
'hex' is yet another hex viewer. It automatically interprets fields within 'hex' is yet another hex viewer. It automatically interprets fields within
files using a set of Lua scripts, colorizing them and showing descriptions on files using a set of Lua scripts, colorizing them and showing descriptions on
the side. the side. It also runs equally well in the terminal, or as an X11 client.
At the moment there aren't that many features and we only have a few decoders. At the moment there aren't that many features and we only have a few decoders.
@@ -11,14 +11,23 @@ image::hex.png[align="center"]
Packages Packages
-------- --------
Regular releases are sporadic. git master should be stable enough. You can get Regular releases are sporadic. git master should be stable enough.
a package with the latest development version from Archlinux's AUR. You can get a package with the latest development version using Arch Linux's
https://aur.archlinux.org/packages/hex-git[AUR],
or as a https://git.janouch.name/p/nixexprs[Nix derivation].
Documentation
-------------
See the link:hex.adoc[man page] for information about usage.
The rest of this README will concern itself with externalities.
Building and Running Building and Running
-------------------- --------------------
Build dependencies: CMake, pkg-config, help2man, liberty (included), Build-only dependencies: CMake, pkg-config, awk, liberty (included),
termo (included) + termo (included), asciidoctor or asciidoc (recommended but optional),
Runtime dependencies: ncursesw, libunistring, Lua >= 5.3 (for highlighting) rsvg-convert (X11) +
Runtime dependencies: ncursesw, libunistring, Lua >= 5.3 (for highlighting) +
Optional runtime dependencies: x11 + xft + libpng (X11)
$ git clone --recursive https://git.janouch.name/p/hex.git $ git clone --recursive https://git.janouch.name/p/hex.git
$ mkdir hex/build $ mkdir hex/build
@@ -35,28 +44,9 @@ Or you can try telling CMake to make a package for you. For Debian it is:
$ cpack -G DEB $ cpack -G DEB
# dpkg -i hex-*.deb # dpkg -i hex-*.deb
Note that for versions of CMake before 2.8.9, you need to prefix `cpack` with
`fakeroot` or file ownership will end up wrong.
Having the program installed, optionally create a configuration file and run it Having the program installed, optionally create a configuration file and run it
on a file of your choice. on a file of your choice.
Configuration
-------------
Create _~/.config/hex/hex.conf_ with contents like the following:
....
colors = {
footer = ""
footer_hl = "bold"
bar = "reverse"
bar_hl = "reverse bold"
even = ""
odd = ""
selection = "reverse"
}
....
Terminal caveats Terminal caveats
---------------- ----------------
Terminals are somewhat tricky to get consistent results on, so be aware of the Terminals are somewhat tricky to get consistent results on, so be aware of the
@@ -73,9 +63,13 @@ Since we need Lua 5.3 features (64-bit integers), LuaJIT can't help us here.
Similar software Similar software
---------------- ----------------
* https://codisec.com/veles/ can also highlight files but it's not scriptable * https://ide.kaitai.io/ and https://codisec.com/veles/ are essentially what
* https://bitbucket.org/haypo/hachoir/wiki/Home seems to be strictly this project wanted to be but the description language is purely declarative
hierarchical, which may not work for file formats like ELF * https://github.com/wader/fq goes a step above, allowing transformations
of identified data
* https://hachoir.readthedocs.io/en/latest/ seems to be strictly hierarchical,
which may not work for file formats like ELF
* https://github.com/ruslashev/elfcat is a more interactive viewer for ELF
Contributing and Support Contributing and Support
------------------------ ------------------------

View File

@@ -1,11 +1,12 @@
#ifndef CONFIG_H #ifndef CONFIG_H
#define CONFIG_H #define CONFIG_H
#define PROGRAM_NAME "${CMAKE_PROJECT_NAME}" #define PROGRAM_NAME "${PROJECT_NAME}"
#define PROGRAM_VERSION "${project_VERSION}" #define PROGRAM_VERSION "${PROJECT_VERSION}"
#cmakedefine HAVE_RESIZETERM #cmakedefine HAVE_RESIZETERM
#cmakedefine HAVE_LUA #cmakedefine WITH_LUA
#cmakedefine WITH_X11
#endif // ! CONFIG_H #endif // ! CONFIG_H

85
hex.adoc Normal file
View File

@@ -0,0 +1,85 @@
hex(1)
======
:doctype: manpage
:manmanual: hex Manual
:mansource: hex {release-version}
Name
----
hex - Interpreting hex viewer
Synopsis
--------
*hex* [_OPTION_]... [_PATH_]
Description
-----------
*hex* is a hex viewer that uses Lua scripts to interpret fields within files,
colorizes them, and shows their descriptions on the side.
When run without arguments, it reads from its standard input stream.
Options
-------
*-o*, *--offset* _OFFSET_::
Byte offset into the file. All preceding data will be ignored.
*-s*, *--size* _SIZE_::
Size limit in bytes. Any following data will be ignored.
+
The _SIZE_ argument accepts similar suffixes as in *dd*(1): _c_=1,
_w_=2, _b_=512, _K_=1024, _KB_=1000, _M_=1024K, _MB_=1000KB,
_G_=1024M, and _GB_=1000M. The default value is 1G.
*-t*, *--type* _TYPE_::
Force interpretation as the given type, skipping autodetection.
Pass in "list" for a listing of all available decoders.
*-d*, *--debug*::
Run in debug mode.
*-x*, *--x11*::
Use an X11 interface even when run from a terminal.
Note that the application may be built with this feature disabled.
*-h*, *--help*::
Display a help message and exit.
*-V*, *--version*::
Output version information and exit.
Configuration
-------------
Create _~/.config/hex/hex.conf_ with contents like the following:
....
colors = {
footer = ""
footer_hl = "bold"
bar = "reverse"
bar_hl = "reverse bold"
even = ""
odd = ""
selection = "reverse"
}
....
Terminal attributes are accepted in a format similar to that of *git-config*(1),
only named colours aren't supported.
Files
-----
*hex* follows the XDG Base Directory Specification.
_~/.config/hex/hex.conf_::
The configuration file.
_~/.local/share/hex/plugins/_::
_/usr/local/share/hex/plugins/_::
_/usr/share/hex/plugins/_::
Plugins are loaded from these directories, in order.
Reporting bugs
--------------
Use https://git.janouch.name/p/hex to report bugs, request features,
or submit pull requests.

1139
hex.c

File diff suppressed because it is too large Load Diff

9
hex.desktop Normal file
View File

@@ -0,0 +1,9 @@
[Desktop Entry]
Type=Application
Name=hex
GenericName=Interpreting hex viewer
Icon=hex
Exec=hex %f
NoDisplay=true
StartupNotify=false
Categories=Utility;

10
hex.svg Normal file
View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg version="1.0" width="48" height="48" viewBox="0 0 48 48"
xmlns="http://www.w3.org/2000/svg">
<g transform="translate(24 24) scale(2 2)">
<path d="M 0 0 -10 0 -10 -10 0 -10 Z" stroke-width="0" fill="#c6ffd6" />
<path d="M 0 0 10 0 10 -10 0 -10 Z" stroke-width="0" fill="#ffd8d8" />
<path d="M 0 0 -10 0 -10 10 0 10 Z" stroke-width="0" fill="#d8d8ff" />
<path d="M 0 0 10 0 10 10 0 10 Z" stroke-width="0" fill="#ffffac" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 524 B

Submodule liberty updated: bb30c7d86e...d8f785eae5

View File

@@ -1,7 +1,7 @@
-- --
-- bencode.lua: BitTorrent data encoding -- bencode.lua: BitTorrent data encoding
-- --
-- Copyright (c) 2017, Přemysl Janouch <p@janouch.name> -- Copyright (c) 2017, Přemysl Eric Janouch <p@janouch.name>
-- --
-- Permission to use, copy, modify, and/or distribute this software for any -- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted. -- purpose with or without fee is hereby granted.

View File

@@ -1,7 +1,7 @@
-- --
-- elf.lua: Executable and Linkable Format -- elf.lua: Executable and Linkable Format
-- --
-- Copyright (c) 2017, Přemysl Janouch <p@janouch.name> -- Copyright (c) 2017, Přemysl Eric Janouch <p@janouch.name>
-- --
-- Permission to use, copy, modify, and/or distribute this software for any -- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted. -- purpose with or without fee is hereby granted.
@@ -18,7 +18,7 @@
-- See man 5 elf, /usr/include/elf.h and /usr/include/llvm/Support/ELF.h -- See man 5 elf, /usr/include/elf.h and /usr/include/llvm/Support/ELF.h
local detect = function (c) local detect = function (c)
return c:read (4) == "\x7FELF" return #c >= 4 and c:read (4) == "\x7FELF"
end end
local ph_type_table = { local ph_type_table = {
@@ -63,7 +63,7 @@ local decode_ph = function (elf, c)
ph.vaddr = elf.uwide (c, "virtual address: %#x") ph.vaddr = elf.uwide (c, "virtual address: %#x")
ph.paddr = elf.uwide (c, "physical address: %#x") ph.paddr = elf.uwide (c, "physical address: %#x")
ph.filesz = elf.uwide (c, "size in file: %d") ph.filesz = elf.uwide (c, "size in file: %d")
ph.memsz = elf.uwide (c, "sise in memory: %d") ph.memsz = elf.uwide (c, "size in memory: %d")
if elf.class == 1 then ph.flags = c:u32 ("flags: %s", xform_ph_flags) end if elf.class == 1 then ph.flags = c:u32 ("flags: %s", xform_ph_flags) end
ph.align = elf.uwide (c, "alignment: %d") ph.align = elf.uwide (c, "alignment: %d")
return ph return ph

View File

@@ -1,7 +1,7 @@
-- --
-- gzip.lua: GZIP File Format -- gzip.lua: GZIP File Format
-- --
-- Copyright (c) 2017, Přemysl Janouch <p@janouch.name> -- Copyright (c) 2017, Přemysl Eric Janouch <p@janouch.name>
-- --
-- Permission to use, copy, modify, and/or distribute this software for any -- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted. -- purpose with or without fee is hereby granted.
@@ -16,7 +16,7 @@
-- --
local detect = function (c) local detect = function (c)
return c:read (2) == "\x1f\x8b" return #c >= 2 and c:read (2) == "\x1f\x8b"
end end
local function latin1_to_utf8 (s) local function latin1_to_utf8 (s)

View File

@@ -1,7 +1,7 @@
-- --
-- pcap.lua: libpcap file format -- pcap.lua: libpcap file format
-- --
-- Copyright (c) 2017, Přemysl Janouch <p@janouch.name> -- Copyright (c) 2017, Přemysl Eric Janouch <p@janouch.name>
-- --
-- Permission to use, copy, modify, and/or distribute this software for any -- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted. -- purpose with or without fee is hereby granted.
@@ -16,11 +16,17 @@
-- --
local detect = function (c) local detect = function (c)
if #c < 4 then
return false
end
local magic = c:u32 () local magic = c:u32 ()
return magic == 0xa1b2c3d4 or magic == 0xd4c3b2a1 return magic == 0xa1b2c3d4 or magic == 0xd4c3b2a1
end end
local detect_ng = function (c) local detect_ng = function (c)
if #c < 8 then
return false
end
local magic = c (9):u32 () local magic = c (9):u32 ()
return c:u32 () == 0x0a0d0d0a return c:u32 () == 0x0a0d0d0a
and (magic == 0x1a2b3c4d or magic == 0x4d3c2b1a) and (magic == 0x1a2b3c4d or magic == 0x4d3c2b1a)

View File

@@ -5,7 +5,7 @@
-- In practice almost useless, I just wanted to learn about the file format. -- In practice almost useless, I just wanted to learn about the file format.
-- FIXME: it's also not very robust and doesn't support all documents. -- FIXME: it's also not very robust and doesn't support all documents.
-- --
-- Copyright (c) 2017, Přemysl Janouch <p@janouch.name> -- Copyright (c) 2017, Přemysl Eric Janouch <p@janouch.name>
-- --
-- Permission to use, copy, modify, and/or distribute this software for any -- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted. -- purpose with or without fee is hereby granted.
@@ -335,7 +335,7 @@ end
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
local detect = function (c) local detect = function (c)
return c:read (5) == "%PDF-" return #c >= 5 and c:read (5) == "%PDF-"
end end
local decode_xref_subsection = function (lex, start, count, result) local decode_xref_subsection = function (lex, start, count, result)

View File

@@ -1,7 +1,7 @@
-- --
-- vdi.lua: VirtualBox Disk Image -- vdi.lua: VirtualBox Disk Image
-- --
-- Copyright (c) 2017, Přemysl Janouch <p@janouch.name> -- Copyright (c) 2017, Přemysl Eric Janouch <p@janouch.name>
-- --
-- Permission to use, copy, modify, and/or distribute this software for any -- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted. -- purpose with or without fee is hereby granted.
@@ -16,6 +16,9 @@
-- --
local detect = function (c) local detect = function (c)
if #c < 68 then
return false
end
c.position = 65 c.position = 65
return c:read (4) == "\x7F\x10\xDA\xBE" return c:read (4) == "\x7F\x10\xDA\xBE"
end end

54
plugins/xcursor.lua Normal file
View File

@@ -0,0 +1,54 @@
--
-- xcursor.lua: X11 cursors
--
-- Copyright (c) 2021, Přemysl Eric Janouch <p@janouch.name>
--
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted.
--
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
-- SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
-- OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
-- CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
--
local detect = function (c)
return #c >= 4 and c:read (4) == "Xcur"
end
-- https://www.x.org/releases/current/doc/man/man3/Xcursor.3.xhtml
local decode = function (c)
if not detect (c) then error ("not an Xcursor file") end
-- libXcursor shows that they are always little-endian
c (1, 4):mark ("Xcursor magic")
c.endianity = "le"
local size = c:u32 ("header size: %d")
-- TODO: check the version, although it is essentially set in stone
-- as 1.0, with X.org being a nearly abandoned project
local version = c:u32 ("file version: %s", function (u32)
return "%d.%d", u32 >> 16, u32 & 0xffff
end)
local ntoc = c:u32 ("number of ToC entries: %d")
local i
for i = 1, ntoc do
local start = c.position
local type = c:u32 ("entry type: %s", function (u32)
if u32 == 0xfffe0001 then return "comment" end
if u32 == 0xfffd0002 then return "image" end
return "unknown: %d", u32
end)
local subtype = c:u32 ("entry subtype: %d")
local position = c:u32 ("chunk position: %d")
c (start, c.position - 1):mark (("ToC entry %d"):format (i))
end
-- TODO: decode all entries as well
end
hex.register { type="xcursor", detect=detect, decode=decode }

View File

@@ -1,7 +1,7 @@
-- --
-- zip.lua: ZIP archives -- zip.lua: ZIP archives
-- --
-- Copyright (c) 2017, Přemysl Janouch <p@janouch.name> -- Copyright (c) 2017, Přemysl Eric Janouch <p@janouch.name>
-- --
-- Permission to use, copy, modify, and/or distribute this software for any -- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted. -- purpose with or without fee is hereby granted.
@@ -42,6 +42,7 @@ local decode = function (c)
c (c.position, c.position + comment_len - 1):mark ("comment") c (c.position, c.position + comment_len - 1):mark ("comment")
-- TODO: decode the fields better -- TODO: decode the fields better
-- https://stackoverflow.com/a/30028491/76313
-- TODO: also mark actual file data if someone wants to put in the effort -- TODO: also mark actual file data if someone wants to put in the effort
c.position = cd_offset + 1 c.position = cd_offset + 1
for i = 1, cd_len do for i = 1, cd_len do

View File

@@ -1,7 +1,7 @@
-- --
-- zlib.lua: ZLIB Compressed Data Format -- zlib.lua: ZLIB Compressed Data Format
-- --
-- Copyright (c) 2017, Přemysl Janouch <p@janouch.name> -- Copyright (c) 2017, Přemysl Eric Janouch <p@janouch.name>
-- --
-- Permission to use, copy, modify, and/or distribute this software for any -- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted. -- purpose with or without fee is hereby granted.

2
termo

Submodule termo updated: 30e0eee1a8...f9a102456f