Roadmap tool to compare binary structure (#479)

This commit is contained in:
MS
2024-01-22 10:15:12 -05:00
committed by GitHub
parent 05bc94f030
commit a65eb9a4e0
7 changed files with 320 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
import logging
import struct
from typing import List, Optional
from typing import List, Optional, Tuple
from dataclasses import dataclass
from collections import namedtuple
@@ -365,6 +365,14 @@ class Bin:
into an absolute vaddr."""
return self.get_section_offset_by_index(section) + offset
def get_relative_addr(self, addr: int) -> Tuple[int, int]:
"""Convert an absolute address back into a (section, offset) pair."""
for i, section in enumerate(self.sections):
if section.contains_vaddr(addr):
return (i + 1, addr - section.virtual_address)
return (0, 0)
def get_raw_addr(self, vaddr: int) -> int:
"""Returns the raw offset in the PE binary for the given virtual address."""
self._set_section_for_vaddr(vaddr)