Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ impl<'a> Elf<'a> {
header.e_shnum = self.nsections;
header.e_shstrndx = STRTAB_LINK;

file.iowrite_with(header, self.ctx)?;
file.iowrite_with(&header, self.ctx)?;
let after_header = file.seek(Current(0))?;
debug!("after_header {:#x}", after_header);
assert_eq!(after_header, Header::size(&self.ctx) as u64);
Expand Down Expand Up @@ -636,11 +636,11 @@ impl<'a> Elf<'a> {
// Strtab
/////////////////////////////////////
file.seek(Start(strtab_offset))?;
file.iowrite(0u8)?; // for the null value in the strtab;
file.iowrite(&0u8)?; // for the null value in the strtab;
for (_id, string) in self.strings.iter() {
debug!("String: {:?}", string);
file.write_all(string.as_bytes())?;
file.iowrite(0u8)?;
file.iowrite(&0u8)?;
}
let after_strtab = file.seek(Current(0))?;
debug!("after_strtab {:#x}", after_strtab);
Expand All @@ -651,15 +651,15 @@ impl<'a> Elf<'a> {
/////////////////////////////////////
for symbol in self.special_symbols.into_iter() {
debug!("Special Symbol: {:?}", symbol);
file.iowrite_with(symbol, self.ctx)?;
file.iowrite_with(&symbol, self.ctx)?;
}
for (_id, symbol) in self.section_symbols.into_iter() {
debug!("Section Symbol: {:?}", symbol);
file.iowrite_with(symbol, self.ctx)?;
file.iowrite_with(&symbol, self.ctx)?;
}
for (id, symbol) in self.symbols.into_iter() {
debug!("Symbol: {:?}", symbol);
file.iowrite_with(symbol, self.ctx)?;
file.iowrite_with(&symbol, self.ctx)?;
match self.sections.get(&id) {
Some(section) => {
section_headers.push(section.clone());
Expand All @@ -681,7 +681,7 @@ impl<'a> Elf<'a> {
section_headers.push(section);
for relocation in relocations.drain(..) {
debug!("Relocation: {:?}", relocation);
file.iowrite_with(relocation, (relocation.r_addend.is_some(), self.ctx))?;
file.iowrite_with(&relocation, (relocation.r_addend.is_some(), self.ctx))?;
}
}
let after_relocs = file.seek(Current(0))?;
Expand All @@ -703,7 +703,7 @@ impl<'a> Elf<'a> {
let shdr_size = section_headers.len() as u64 * Section::size(&self.ctx) as u64;
for shdr in section_headers {
debug!("Section: {:?}", shdr);
file.iowrite_with(shdr, self.ctx)?;
file.iowrite_with(&shdr, self.ctx)?;
}

let after_shdrs = file.seek(Current(0))?;
Expand Down
24 changes: 12 additions & 12 deletions src/mach.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ impl SectionBuilder {
/// Finalize and create the actual Mach-o section
pub fn create(self) -> Section {
let mut sectname = [0u8; 16];
sectname.pwrite(self.sectname, 0).unwrap();
sectname.pwrite(&self.sectname, 0).unwrap();
let mut segname = [0u8; 16];
segname.pwrite(self.segname, 0).unwrap();
segname.pwrite(&self.segname, 0).unwrap();
Section {
sectname,
segname,
Expand Down Expand Up @@ -494,7 +494,7 @@ impl<'a> Mach<'a> {
relocation_offset += nrelocs as u64 * SIZEOF_RELOCATION_INFO as u64;
}
debug!("Section: {:#?}", section);
raw_sections.iowrite_with(section, self.ctx)?;
raw_sections.iowrite_with(&section, self.ctx)?;
}
let raw_sections = raw_sections.into_inner();
debug!("Raw sections len: {} - Section start: {} Strtable size: {} - Segment size: {}", raw_sections.len(), first_section_offset, self.symtab.sizeof_strtable(), self.segment.size());
Expand All @@ -521,15 +521,15 @@ impl<'a> Mach<'a> {
//////////////////////////////
// write header
//////////////////////////////
file.iowrite_with(header, self.ctx)?;
file.iowrite_with(&header, self.ctx)?;
debug!("SEEK: after header: {}", file.seek(Current(0))?);

//////////////////////////////
// write load commands
//////////////////////////////
file.iowrite_with(segment_load_command, self.ctx)?;
file.iowrite_with(&segment_load_command, self.ctx)?;
file.write_all(&raw_sections)?;
file.iowrite_with(symtab_load_command, self.ctx.le)?;
file.iowrite_with(&symtab_load_command, self.ctx.le)?;
debug!("SEEK: after load commands: {}", file.seek(Current(0))?);

//////////////////////////////
Expand Down Expand Up @@ -562,21 +562,21 @@ impl<'a> Mach<'a> {
for (idx, symbol) in self.symtab.symbols.into_iter() {
let symbol = symbol.create();
debug!("{}: {:?}", idx, symbol);
file.iowrite_with(symbol, self.ctx)?;
file.iowrite_with(&symbol, self.ctx)?;
}
debug!("SEEK: after symtable: {}", file.seek(Current(0))?);

//////////////////////////////
// write strtable
//////////////////////////////
// we need to write first, empty element - but without an underscore
file.iowrite(0u8)?;
file.iowrite(&0u8)?;
for (idx, string) in self.symtab.strtable.into_iter().skip(1) {
debug!("{}: {:?}", idx, string);
// yup, an underscore
file.iowrite(0x5fu8)?;
file.iowrite(&0x5fu8)?;
file.write_all(string.as_bytes())?;
file.iowrite(0u8)?;
file.iowrite(&0u8)?;
}
debug!("SEEK: after strtable: {}", file.seek(Current(0))?);

Expand All @@ -587,12 +587,12 @@ impl<'a> Mach<'a> {
debug!("Relocations: {}", section_relocations.len());
for reloc in section_relocations.into_iter() {
debug!(" {:?}", reloc);
file.iowrite_with(reloc, self.ctx.le)?;
file.iowrite_with(&reloc, self.ctx.le)?;
}
}
debug!("SEEK: after relocations: {}", file.seek(Current(0))?);

file.iowrite(0u8)?;
file.iowrite(&0u8)?;

Ok(())
}
Expand Down