Skip to content

Commit

Permalink
pe: Fix to use i64 for relocation calculation
Browse files Browse the repository at this point in the history
This commit fixes loading error reported in issue #73.

Signed-off-by: Akira Moroo <retrage01@gmail.com>
  • Loading branch information
retrage committed Jan 16, 2021
1 parent 1aa0750 commit 4c2696a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/pe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ impl<'a> Loader<'a> {
}
}

let base_diff = address as i64 - self.image_base as i64;

for section in sections {
if &section.name[0..6] == b".reloc" {
let section_size = core::cmp::min(section.raw_size, section.virt_size);
Expand All @@ -196,7 +198,7 @@ impl<'a> Loader<'a> {
if entry_type == 10 {
let location = u64::from(page_rva + u32::from(entry_offset));
let value = loaded_region.read_u64(location);
loaded_region.write_u64(location, value + (address - self.image_base));
loaded_region.write_u64(location, (value as i64 + base_diff) as u64);
}

block_offset += 2;
Expand Down

0 comments on commit 4c2696a

Please sign in to comment.