Created
May 4, 2017 12:10
-
-
Save mitsuhiko/0b56a3b9cd9b5ad36e849fc5fe0de1e2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
error: `rv` does not live long enough | |
--> src/read.rs:143:43 | |
| | |
143 | extract_variants(&mut rv, file); | |
| ^^ does not live long enough | |
... | |
194 | } | |
| - borrowed value only lives until here | |
| | |
note: borrowed value must be valid for the lifetime 'a as defined on the body at 137:62... | |
--> src/read.rs:137:63 | |
| | |
137 | pub fn get_variants(&'a self) -> Result<Vec<Variant<'a>>> { | |
| ^ | |
error: `rv` does not live long enough | |
--> src/read.rs:147:39 | |
| | |
147 | extract_variants(&mut rv, &self.ofile); | |
| ^^ does not live long enough | |
... | |
194 | } | |
| - borrowed value only lives until here | |
| | |
note: borrowed value must be valid for the lifetime 'a as defined on the body at 137:62... | |
--> src/read.rs:137:63 | |
| | |
137 | pub fn get_variants(&'a self) -> Result<Vec<Variant<'a>>> { | |
| ^ | |
error: aborting due to 2 previous errors |
This file contains hidden or 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
pub fn get_variants(&'a self) -> Result<Vec<Variant<'a>>> { | |
let mut rv = vec![]; | |
match self.ofile { | |
OFile::FatFile { ref files, .. } => { | |
for &(_, ref file) in files { | |
extract_variants(&mut rv, file); | |
} | |
} | |
OFile::MachFile { .. } => { | |
extract_variants(&mut rv, &self.ofile); | |
} | |
_ => {} | |
} | |
return Ok(rv); | |
fn extract_variants<'a>(rv: &'a mut Vec<Variant<'a>>, file: &'a OFile) { | |
if let &OFile::MachFile { ref header, ref commands, .. } = file { | |
let mut variant_uuid = Uuid::nil(); | |
let mut variant_name = "<unknown>"; | |
let mut variant_vmaddr = 0; | |
let mut variant_vmsize = 0; | |
for &MachCommand(ref load_cmd, _) in commands { | |
match load_cmd { | |
&LoadCommand::Uuid(uuid) => { | |
variant_uuid = uuid; | |
}, | |
&LoadCommand::IdDyLib(DyLib { ref name, .. }) => { | |
variant_name = &name.1; | |
} | |
&LoadCommand::Segment { ref segname, vmaddr, vmsize, .. } => { | |
if segname == "__TEXT" { | |
variant_vmaddr = vmaddr as u64; | |
variant_vmsize = vmsize as u64; | |
} | |
} | |
&LoadCommand::Segment64 { ref segname, vmaddr, vmsize, .. } => { | |
if segname == "__TEXT" { | |
variant_vmaddr = vmaddr as u64; | |
variant_vmsize = vmsize as u64; | |
} | |
} | |
_ => {} | |
} | |
} | |
rv.push(Variant { | |
cpu_name: get_arch_name_from_types(header.cputype, | |
header.cpusubtype) | |
.unwrap_or("<unknown>"), | |
uuid: variant_uuid, | |
name: variant_name, | |
vmaddr: variant_vmaddr, | |
vmsize: variant_vmsize, | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment