Compare commits

...

18 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
16 changed files with 654 additions and 585 deletions

View File

@@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 3.0)
cmake_minimum_required (VERSION 3.0...3.27)
project (hex VERSION 0.1.0 LANGUAGES C)
# Moar warnings
@@ -20,7 +20,6 @@ include (AddThreads)
find_package (Termo QUIET NO_MODULE)
option (USE_SYSTEM_TERMO
"Don't compile our own termo library, use the system one" ${Termo_FOUND})
if (USE_SYSTEM_TERMO)
if (NOT Termo_FOUND)
message (FATAL_ERROR "System termo library not found")
@@ -41,11 +40,10 @@ else ()
endif ()
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})
if (WITH_LUA)
if (NOT lua_FOUND)
message (FATAL_ERROR "Lua library not found")
@@ -54,28 +52,37 @@ if (WITH_LUA)
list (APPEND project_libraries ${lua_LIBRARIES})
include_directories (${lua_INCLUDE_DIRS})
link_directories (${lua_LIBRARY_DIRS})
endif ()
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")
pkg_check_modules (x11 x11 xrender xft fontconfig libpng)
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
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)
set (CMAKE_REQUIRED_LIBRARIES ${Ncursesw_LIBRARIES})
CHECK_FUNCTION_EXISTS ("resizeterm" HAVE_RESIZETERM)
# Generate a configuration file
set (HAVE_LUA "${WITH_LUA}")
configure_file (${PROJECT_SOURCE_DIR}/config.h.in
${PROJECT_BINARY_DIR}/config.h)
include_directories (${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR})
@@ -89,6 +96,30 @@ add_threads (${PROJECT_NAME})
include (GNUInstallDirs)
install (TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
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)
set (icon_base ${PROJECT_BINARY_DIR}/icons)
set (icon_png_list)
foreach (icon_size 16 32 48)
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)
@@ -137,7 +168,7 @@ foreach (page ${project_MAN_PAGES})
endforeach ()
# CPack
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "Hex viewer")
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "Interpreting hex viewer")
set (CPACK_PACKAGE_VENDOR "Premysl Eric Janouch")
set (CPACK_PACKAGE_CONTACT "Přemysl Eric Janouch <p@janouch.name>")
set (CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")

View File

@@ -1,4 +1,4 @@
Copyright (c) 2016 - 2017, Přemysl Eric 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
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
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.
@@ -11,8 +11,10 @@ image::hex.png[align="center"]
Packages
--------
Regular releases are sporadic. git master should be stable enough. You can get
a package with the latest development version from Archlinux's AUR.
Regular releases are sporadic. git master should be stable enough.
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
-------------
@@ -21,9 +23,11 @@ The rest of this README will concern itself with externalities.
Building and Running
--------------------
Build dependencies: CMake, pkg-config, awk, liberty (included),
termo (included), asciidoctor or asciidoc (recommended but optional) +
Runtime dependencies: ncursesw, libunistring, Lua >= 5.3 (for highlighting)
Build-only dependencies: CMake, pkg-config, awk, liberty (included),
termo (included), asciidoctor or asciidoc (recommended but optional),
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
$ mkdir hex/build

View File

@@ -5,7 +5,8 @@
#define PROGRAM_VERSION "${PROJECT_VERSION}"
#cmakedefine HAVE_RESIZETERM
#cmakedefine HAVE_LUA
#cmakedefine WITH_LUA
#cmakedefine WITH_X11
#endif // ! CONFIG_H

View File

@@ -38,6 +38,10 @@ _G_=1024M, and _GB_=1000M. The default value is 1G.
*-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.

1111
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: 34f86651f6...d8f785eae5

View File

@@ -18,7 +18,7 @@
-- See man 5 elf, /usr/include/elf.h and /usr/include/llvm/Support/ELF.h
local detect = function (c)
return c:read (4) == "\x7FELF"
return #c >= 4 and c:read (4) == "\x7FELF"
end
local ph_type_table = {
@@ -63,7 +63,7 @@ local decode_ph = function (elf, c)
ph.vaddr = elf.uwide (c, "virtual address: %#x")
ph.paddr = elf.uwide (c, "physical address: %#x")
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
ph.align = elf.uwide (c, "alignment: %d")
return ph

View File

@@ -16,7 +16,7 @@
--
local detect = function (c)
return c:read (2) == "\x1f\x8b"
return #c >= 2 and c:read (2) == "\x1f\x8b"
end
local function latin1_to_utf8 (s)

View File

@@ -16,11 +16,17 @@
--
local detect = function (c)
if #c < 4 then
return false
end
local magic = c:u32 ()
return magic == 0xa1b2c3d4 or magic == 0xd4c3b2a1
end
local detect_ng = function (c)
if #c < 8 then
return false
end
local magic = c (9):u32 ()
return c:u32 () == 0x0a0d0d0a
and (magic == 0x1a2b3c4d or magic == 0x4d3c2b1a)

View File

@@ -335,7 +335,7 @@ end
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
local detect = function (c)
return c:read (5) == "%PDF-"
return #c >= 5 and c:read (5) == "%PDF-"
end
local decode_xref_subsection = function (lex, start, count, result)

View File

@@ -16,6 +16,9 @@
--
local detect = function (c)
if #c < 68 then
return false
end
c.position = 65
return c:read (4) == "\x7F\x10\xDA\xBE"
end

View File

@@ -16,7 +16,7 @@
--
local detect = function (c)
return c:read (4) == "Xcur"
return #c >= 4 and c:read (4) == "Xcur"
end
-- https://www.x.org/releases/current/doc/man/man3/Xcursor.3.xhtml

2
termo

Submodule termo updated: 8265f075b1...f9a102456f