generated from amosproj/amos202Xss0Y-projname
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored code, correctly handled result values
Signed-off-by: Benedikt Zinn <[email protected]>
- Loading branch information
1 parent
75d4794
commit 9cff386
Showing
5 changed files
with
106 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use std::path::PathBuf; | ||
use tokio::process::Command; | ||
use std::fs::File; | ||
use object::{Object, ObjectSymbol, ReadCache}; | ||
use std::io::Error; | ||
use crate::constants::OATDUMP_PATH; | ||
use crate::symbols_stuff::SymbolError; | ||
|
||
pub async fn generate_json_oatdump(path: &PathBuf) -> Result<(), SymbolError> { | ||
let _oatdump_status = Command::new("oatdump") | ||
.args(vec![ | ||
format!("--output={}", OATDUMP_PATH).as_str(), | ||
"--dump-method-and-offset-as-json", | ||
format!("--oat-file={}", path.to_str().unwrap().to_string()).as_str(), | ||
]) | ||
.spawn()? | ||
.wait() | ||
.await?; | ||
// TODO: Check for status [robin] | ||
// do we even need the status -> if yes for what? [benedikt] | ||
Ok(()) | ||
} | ||
|
||
pub async fn get_section_address(oat_path: &PathBuf) -> Result<u64, Error> { | ||
tokio::task::spawn_blocking({ | ||
let path = oat_path.clone(); | ||
move || get_symbol_address_from_oat(&path, "oatdata") | ||
}) | ||
.await? | ||
} | ||
|
||
fn get_symbol_address_from_oat(path: &PathBuf, symbol_name: &str) -> Result<u64, Error> { | ||
let file = File::open(path)?; | ||
let file_cache = ReadCache::new(file); | ||
let obj = object::File::parse(&file_cache).unwrap(); | ||
|
||
let section = obj | ||
.dynamic_symbols() | ||
.find(|s| s.name() == Ok(symbol_name)) | ||
.unwrap(); | ||
|
||
Ok(section.address()) | ||
} |