{"record":{"id":"f3c3939a7cd4e888","repo":"tonhowtf/omniget","slug":"hex-inv-lido","errorCode":null,"errorMessage":"hex inválido: {}","messagePattern":"hex inválido: (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/ctf/xor.rs","lineNumber":149,"sourceCode":"}\n\nfn default_mode() -> String {\n    \"single\".into()\n}\nfn default_max() -> usize {\n    16\n}\n\n#[derive(Debug, Clone, Serialize)]\npub struct XorResult {\n    pub candidates: Vec<XorCandidate>,\n    pub key_sizes: Vec<(usize, f64)>,\n}\n\npub fn run(opts: &XorOptions) -> anyhow::Result<XorResult> {\n    let data = if opts.input_hex {\n        hex::decode(opts.input.trim().replace([' ', '\\n', ':'], \"\"))\n            .map_err(|e| anyhow::anyhow!(\"hex inválido: {}\", e))?\n    } else {\n        opts.input.as_bytes().to_vec()\n    };\n    Ok(match opts.mode.as_str() {\n        \"apply\" => {\n            let key = if opts.key_hex {\n                hex::decode(opts.key.trim()).map_err(|e| anyhow::anyhow!(\"chave hex: {}\", e))?\n            } else {\n                opts.key.as_bytes().to_vec()\n            };\n            let out = xor(&data, &key);\n            XorResult {\n                candidates: vec![XorCandidate {\n                    key: opts.key.clone(),\n                    key_hex: hex::encode(&key),\n                    text: String::from_utf8_lossy(&out).to_string(),\n                    score: 0.0,\n                }],","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/ctf/xor.rs#L131-L167","documentation":"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>'.","triggerScenarios":"Calling XorOptions { input_hex: true, .. } with input containing characters outside 0-9a-fA-F after whitespace/colon stripping, or an odd-length hex string.","commonSituations":"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 ';'.","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"],"exampleFix":"// before\nlet opts = XorOptions { input_hex: true, input: \"0x48 std\".into(), .. }; // invalid\n// after\nlet opts = XorOptions { input_hex: true, input: \"48 65 6c 6c 6f\".into(), .. };","handlingStrategy":"validation","validationCode":"fn is_hex(s: &str) -> bool {\n    let cleaned: String = s.chars().filter(|c| !c.is_whitespace() && *c != ':').collect();\n    cleaned.len() % 2 == 0 && cleaned.chars().all(|c| c.is_ascii_hexdigit())\n}\nif opts.input_hex && !is_hex(&opts.input) { anyhow::bail!(\"input is not valid hex\"); }","typeGuard":"fn valid_hex_input(opts: &XorOptions) -> bool {\n    !opts.input_hex || (opts.input.trim().replace([' ', '\\n', ':'], \"\").len() % 2 == 0\n        && opts.input.chars().all(|c| c.is_whitespace() || c == ':' || c.is_ascii_hexdigit()))\n}","tryCatchPattern":null,"preventionTips":["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"],"tags":["hex","xor","ctf","rust","decoding"],"backgroundTag":"invalid-argument-format","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}