Skip to content

Commit 61d3e72

Browse files
retragerbradford
authored andcommitted
pe: Fix to use i64 for relocation calculation
This commit fixes loading error reported in issue #73. Signed-off-by: Akira Moroo <[email protected]>
1 parent c6ed75c commit 61d3e72

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/pe.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ impl<'a> Loader<'a> {
172172
}
173173
}
174174

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

202204
block_offset += 2;

0 commit comments

Comments
 (0)