Skip to content

Commit 7ef4e49

Browse files
committed
f to follow a phdr offset in hex view
1 parent b35a860 commit 7ef4e49

2 files changed

Lines changed: 51 additions & 7 deletions

File tree

src/header/formats/elf/events.rs

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::io::Result;
22

33
use ratatui::crossterm::event::{KeyCode, KeyEvent};
44

5-
use crate::app::App;
5+
use crate::{app::App, editor::AppView};
66

77
const NUMBER_OF_TABS: usize = 4;
88

@@ -79,7 +79,7 @@ fn tab_program_headers_events(app: &mut App, key: KeyEvent) -> Result<bool> {
7979
app.header_view
8080
.elf_state
8181
.program_header_table_state
82-
.select_cell(Some((0, 1)));
82+
.select_cell(Some((0, 5)));
8383
} else {
8484
app.header_view
8585
.elf_state
@@ -107,8 +107,52 @@ fn tab_program_headers_events(app: &mut App, key: KeyEvent) -> Result<bool> {
107107
}
108108
}
109109
}
110-
KeyCode::Char('G') => {
111-
// goto
110+
KeyCode::Left | KeyCode::Char('h') => {
111+
if app
112+
.header_view
113+
.elf_state
114+
.program_header_table_state
115+
.selected()
116+
.is_none()
117+
{
118+
tab_prev(app);
119+
} else {
120+
app.header_view
121+
.elf_state
122+
.program_header_table_state
123+
.select_previous_column();
124+
}
125+
}
126+
KeyCode::Right | KeyCode::Char('l') => {
127+
if app
128+
.header_view
129+
.elf_state
130+
.program_header_table_state
131+
.selected()
132+
.is_none()
133+
{
134+
tab_next(app);
135+
} else {
136+
app.header_view
137+
.elf_state
138+
.program_header_table_state
139+
.select_next_column();
140+
}
141+
}
142+
// follow
143+
// TODO: follow only when a PhysAddr field is selected
144+
KeyCode::Char('f') => {
145+
let idx = app
146+
.header_view
147+
.elf_state
148+
.program_header_table_state
149+
.selected()
150+
.unwrap();
151+
let elf = app.header_view.elf.as_ref().unwrap();
152+
let phdr = elf.phdrs.get(idx).unwrap();
153+
let ofs = phdr.p_offset;
154+
app.goto(ofs as usize);
155+
app.editor_view = AppView::Hex;
112156
}
113157
_ => {}
114158
}
@@ -193,10 +237,10 @@ fn tab_symbols_events(app: &mut App, key: KeyEvent) -> Result<bool> {
193237

194238
pub fn view_header_elf_events(app: &mut App, key: KeyEvent) -> Result<bool> {
195239
match key.code {
196-
KeyCode::Tab | KeyCode::Right | KeyCode::Char('l') => {
240+
KeyCode::Tab => {
197241
tab_next(app);
198242
}
199-
KeyCode::BackTab | KeyCode::Left | KeyCode::Char('h') => {
243+
KeyCode::BackTab => {
200244
tab_prev(app);
201245
}
202246
_ => (),

src/hex/events.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub fn hex_mode_events(app: &mut App, key: KeyEvent) -> Result<bool> {
3737
if app.hex_view.search.mode == hex::search::SearchMode::Utf8
3838
&& !app.hex_view.search.input_text.value().is_empty()
3939
{
40-
let needle = app.hex_view.search.input_text.value().to_string();
40+
let needle = app.hex_view.search.input_text.value().to_string();
4141
ofs = hex::search::search(app, needle);
4242
} else if app.hex_view.search.mode == hex::search::SearchMode::Hex
4343
&& !app.hex_view.search.input_hex.value().is_empty()

0 commit comments

Comments
 (0)