tonhowtf/omniget · error · anyhow::Error
hex inválido
Error message
hex inválido: {} What it means
In ctf/xor, when opts.input_hex is true the tool decodes opts.input from hexadecimal (after stripping spaces, newlines and colons). Any value rejected by the hex crate — odd number of digits or non-hex characters — produces 'hex inválido: <hex error>'.
Solutions
- Fix the input so it is valid hex: even number of characters, only 0-9a-fA-F (optionally separated by spaces/newlines/colons)
- Remove '0x' prefixes before passing the value
- If the data is actually text/binary, set input_hex to false so it is treated as raw bytes
Example fix
// before
let opts = XorOptions { input_hex: true, input: "0x48 std".into(), .. }; // invalid
// after
let opts = XorOptions { input_hex: true, input: "48 65 6c 6c 6f".into(), .. }; Defensive patterns
Strategy: validation
Validate before calling
fn is_hex(s: &str) -> bool {
let cleaned: String = s.chars().filter(|c| !c.is_whitespace() && *c != ':').collect();
cleaned.len() % 2 == 0 && cleaned.chars().all(|c| c.is_ascii_hexdigit())
}
if opts.input_hex && !is_hex(&opts.input) { anyhow::bail!("input is not valid hex"); } Type guard
fn valid_hex_input(opts: &XorOptions) -> bool {
!opts.input_hex || (opts.input.trim().replace([' ', '\n', ':'], "").len() % 2 == 0
&& opts.input.chars().all(|c| c.is_whitespace() || c == ':' || c.is_ascii_hexdigit()))
} Prevention
- Strip '0x' prefixes and validate hex at the input boundary (CLI flag parsing, UI field)
- Decide explicitly between hex and raw-bytes mode; do not leave input_hex from a previous run
- Normalize whitespace handling consistently between input and key fields
When it happens
Trigger: Calling XorOptions { input_hex: true, .. } with input containing characters outside 0-9a-fA-F after whitespace/colon stripping, or an odd-length hex string.
Common situations: Pasting base64 or raw binary text instead of hex; leaving a '0x' prefix in the string; odd digit count from manual transcription; trailing punctuation like '.' or ';'.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- chave hex
- a API do TikTok devolveu resposta vazia — normalmente é a…
- a API do TikTok respondeu HTTP
- a capa não é PNG, JPEG, GIF ou BMP
- a chave local do SponsorBlock está corrompida
AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12).
Data as JSON: /api/errors/f3c3939a7cd4e888.
Report an issue: GitHub.
Appendix: source
Thrown at src-tauri/omniget-core/src/core/tools/ctf/xor.rs:149
}
fn default_mode() -> String {
"single".into()
}
fn default_max() -> usize {
16
}
#[derive(Debug, Clone, Serialize)]
pub struct XorResult {
pub candidates: Vec<XorCandidate>,
pub key_sizes: Vec<(usize, f64)>,
}
pub fn run(opts: &XorOptions) -> anyhow::Result<XorResult> {
let data = if opts.input_hex {
hex::decode(opts.input.trim().replace([' ', '\n', ':'], ""))
.map_err(|e| anyhow::anyhow!("hex inválido: {}", e))?
} else {
opts.input.as_bytes().to_vec()
};
Ok(match opts.mode.as_str() {
"apply" => {
let key = if opts.key_hex {
hex::decode(opts.key.trim()).map_err(|e| anyhow::anyhow!("chave hex: {}", e))?
} else {
opts.key.as_bytes().to_vec()
};
let out = xor(&data, &key);
XorResult {
candidates: vec![XorCandidate {
key: opts.key.clone(),
key_hex: hex::encode(&key),
text: String::from_utf8_lossy(&out).to_string(),
score: 0.0,
}],View on GitHub (pinned to 8600b91f42)