← Hex
Hex·Guide
All tools

The Hex tool

Any file as offsets, hex bytes and text, for files no other tool reads. Select with the mouse or Shift and the arrows; the inspector reads the bytes at the cursor as integers, floats, LEB128 and UTF-8; Find looks for text or byte patterns (?? matches any byte); Go to takes hex (1a2b), decimal (#6699) or a relative move (+10). Files up to 1 GB are held in memory.

Bytes are coloured by kind: zero, printable ASCII, whitespace, other control bytes, bytes ≥ 0x80 and 0xFF, so text, padding and compressed data stand out.

1The libraries

Three small JavaScript modules with no dependencies and no user interface. Each exports one class of static methods:

import { FileType } from "../lib/filetype.js";
import { DataInspector } from "../lib/data-inspector.js";
import { ByteSearch } from "../lib/search.js";

lib/filetype.js — FileType

MethodWhat it does
FileType.detect(bytes){ id, name } from the first bytes (ZIP, ELF, DEX, Mach-O, Hermes, Android binary XML and resources, binary plist, XML, PNG, JPEG, GIF, WebP, PDF, gzip, SQLite, Dart snapshot, DER, JSON), or null.
FileType.SIGNATURESThe signatures, in the order they are checked.

lib/data-inspector.js — DataInspector

MethodWhat it does
DataInspector.read(bytes, offset, littleEndian)[{ name, value, copy }]: offset, binary, (u)int8/16/32/64, float32/64, uleb128, sleb128 and the UTF-8 character at the offset; value is null when the bytes run out.
DataInspector.leb128(bytes, offset, signed){ value (BigInt), length }, or null.

lib/search.js — ByteSearch

MethodWhat it does
ByteSearch.compileSequence(query, mode)A pattern: "hex" byte pairs with ?? wildcards, or UTF-8 text ("text", or "texti" ignoring ASCII case).
ByteSearch.nextMatch(bytes, pattern, from, direction){ offset, wrapped }: the next match forwards (1) or backwards (-1), wrapping around; or null.
ByteSearch.compile(query, mode)A pattern for find: "text" (ASCII case ignored) or "case" as UTF-8 and UTF-16LE, "hex" bytes, or "regex" on the bytes read as UTF-8. Throws an Error with a readable message for a bad query.
ByteSearch.find(bytes, pattern, limit)[{ offset, length, label }], sorted by offset, at most limit per encoding (the archive pages' Search contents).
ByteSearch.context(bytes, offset, length)The text around a match, with the match's position in it.
<script type="module">
import { FileType } from "../lib/filetype.js";
import { DataInspector } from "../lib/data-inspector.js";
import { ByteSearch } from "../lib/search.js";

const pattern = ByteSearch.compileSequence("50 4b 03 04", "hex");
let match = ByteSearch.nextMatch(bytes, pattern, 0, 1);   // the first local ZIP header
console.log(FileType.detect(bytes), DataInspector.read(bytes, match.offset, true));
</script>