Support running/profiling ISX files
This commit is contained in:
@@ -14,7 +14,7 @@ pub struct GameInfo {
|
||||
}
|
||||
|
||||
impl GameInfo {
|
||||
pub fn new(file_path: &Path, input: &[u8]) -> Result<Self> {
|
||||
pub fn from_elf(file_path: &Path, input: &[u8]) -> Result<Self> {
|
||||
let file = object::File::parse(input)?;
|
||||
|
||||
let (name, path) = name_and_path(file_path);
|
||||
@@ -52,6 +52,26 @@ impl GameInfo {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn from_isx(file_path: &Path, input: &[u8]) -> Self {
|
||||
let (name, path) = name_and_path(file_path);
|
||||
let symbols = extract_isx_symbols(input);
|
||||
let library_info = LibraryInfo {
|
||||
name: name.clone(),
|
||||
debug_name: name,
|
||||
path: path.clone(),
|
||||
debug_path: path,
|
||||
debug_id: DebugId::default(),
|
||||
code_id: None,
|
||||
arch: None,
|
||||
symbol_table: symbols.map(|syms| Arc::new(SymbolTable::new(syms))),
|
||||
};
|
||||
let inline_stack_map = InlineStackMap::empty();
|
||||
Self {
|
||||
library_info,
|
||||
inline_stack_map,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn empty(file_path: &Path) -> Self {
|
||||
let (name, path) = name_and_path(file_path);
|
||||
let library_info = LibraryInfo {
|
||||
@@ -115,6 +135,66 @@ fn build_inline_stack_map(file: object::File) -> Result<InlineStackMap> {
|
||||
Ok(frames.build())
|
||||
}
|
||||
|
||||
fn extract_isx_symbols(input: &[u8]) -> Option<Vec<Symbol>> {
|
||||
let mut syms = vec![];
|
||||
let (_, mut buf) = input.split_at_checked(32)?;
|
||||
while !buf.is_empty() {
|
||||
let typ;
|
||||
(typ, buf) = buf.split_first()?;
|
||||
match typ {
|
||||
0x11 => {
|
||||
// Code (Virtual Boy)
|
||||
(_, buf) = buf.split_at_checked(4)?;
|
||||
let len_bytes;
|
||||
(len_bytes, buf) = buf.split_first_chunk()?;
|
||||
let len = u32::from_le_bytes(*len_bytes);
|
||||
(_, buf) = buf.split_at_checked(len as usize)?;
|
||||
}
|
||||
0x13 => {
|
||||
// Range (Virtual Boy)
|
||||
let count_bytes;
|
||||
(count_bytes, buf) = buf.split_first_chunk()?;
|
||||
let count = u16::from_le_bytes(*count_bytes) + 1;
|
||||
(_, buf) = buf.split_at_checked(count as usize * 9)?;
|
||||
}
|
||||
0x14 => {
|
||||
// Symbol (Virtual Boy)
|
||||
let count_bytes;
|
||||
(count_bytes, buf) = buf.split_first_chunk()?;
|
||||
let count = u16::from_le_bytes(*count_bytes) + 1;
|
||||
for _ in 0..count {
|
||||
let name_len;
|
||||
(name_len, buf) = buf.split_first()?;
|
||||
let name_bytes;
|
||||
(name_bytes, buf) = buf.split_at_checked(*name_len as usize)?;
|
||||
(_, buf) = buf.split_at_checked(2)?;
|
||||
let address_bytes;
|
||||
(address_bytes, buf) = buf.split_first_chunk()?;
|
||||
|
||||
let name_str = String::from_utf8_lossy(name_bytes);
|
||||
let address = u32::from_le_bytes(*address_bytes);
|
||||
syms.push(Symbol {
|
||||
address,
|
||||
size: Some(4),
|
||||
name: demangle_any(&name_str),
|
||||
});
|
||||
}
|
||||
}
|
||||
0x20 | 0x21 | 0x22 => {
|
||||
// System (undocumented)
|
||||
let length_bytes;
|
||||
(length_bytes, buf) = buf.split_first_chunk()?;
|
||||
let length = u32::from_le_bytes(*length_bytes);
|
||||
(_, buf) = buf.split_at_checked(length as usize)?;
|
||||
}
|
||||
_ => {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(syms)
|
||||
}
|
||||
|
||||
type Reader<'a> = gimli::EndianSlice<'a, gimli::RunTimeEndian>;
|
||||
|
||||
struct ParseContext<'a> {
|
||||
|
||||
Reference in New Issue
Block a user