diff options
-rw-r--r-- | main.rs | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -789,6 +789,38 @@ fn interface_loop(state: &mut Program) { state.status = format!("ctrl? {:?}", vec); } } + Event::Key(Key::Char('g')) => { + // follow (dword) + if state.view.size() < 4 { + state.status = "not enough bytes to seek a dword (need at least four)".to_string(); + } else { + let read_from = if state.view.size() - state.cursor < 4 { + state.view.size() - 4 + } else { + state.cursor + }; + + let dword_bytes = state.view.get_bytes(state.cursor, 4); + if dword_bytes.len() == 4 { + let dword: u64 = + ((dword_bytes[0] as u32) | + ((dword_bytes[1] as u32) << 8) | + ((dword_bytes[2] as u32) << 16) | + ((dword_bytes[3] as u32) << 24)) as u64; + if dword < state.view.size() { + state.status = format!("Seeked to 0x{:x}", dword); + state.seek_to(dword as u64); + } else { + state.status = format!("Cannot seek to 0x{:x} - invalid address.", dword); + } + } else { + state.status = format!( + "not enough bytes to seek a dword (got {}) - should be unreachable since we already checked for this", + dword_bytes.len() + ); + } + } + } Event::Key(Key::Char(x)) => { // TODO: how does this work on non-US keyboards? keyboards without a-fA-F? let new_value = state.current_edit_view().apply_sym(state.view.get_byte(state.cursor), x as u8); |