Skip to content

Commit 562e3d7

Browse files
committed
Add lazy helper
1 parent f41bd26 commit 562e3d7

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

jingle_sleigh/src/context/image/gimli.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ use crate::context::image::{ImageProvider, ImageSection, ImageSectionIterator, P
22
use crate::{JingleSleighError, VarNode};
33
use object::{Architecture, Endianness, File, Object, ObjectSection, Section, SectionKind};
44
use std::cmp::{max, min};
5+
use std::fmt::Debug;
6+
use std::fs;
7+
use std::path::Path;
8+
use crate::context::loaded::LoadedSleighContext;
9+
use crate::context::SleighContextBuilder;
510

611
#[derive(Debug, PartialEq, Eq)]
712
pub struct OwnedSection {
@@ -183,3 +188,13 @@ fn map_sec_kind(kind: &SectionKind) -> Perms {
183188
_ => Perms::NONE,
184189
}
185190
}
191+
192+
pub fn load_with_gimli<'a, P: AsRef<Path>, P2: AsRef<Path> + Debug>(p: P, ghidra_path: P2) -> Result<LoadedSleighContext<'a>, JingleSleighError>{
193+
let data = fs::read(p.as_ref()).map_err(|_| JingleSleighError::ImageLoadError)?;
194+
let f = object::File::parse(data.as_slice()).map_err(|_| JingleSleighError::ImageLoadError)?;
195+
let owned = OwnedFile::new(&f)?;
196+
let arch = map_gimli_architecture(&f).ok_or(JingleSleighError::InvalidLanguageId)?;
197+
let sleigh = SleighContextBuilder::load_ghidra_installation(ghidra_path)?.build(arch)?;
198+
let loaded = sleigh.initialize_with_image(owned)?;
199+
Ok(loaded)
200+
}

0 commit comments

Comments
 (0)