Skip to content

addresser

Addresser : handle addresses management

Addresser

Class for managing addresses.

Parameters:

Name Type Description Default
program Program

A backref to the program

required
base_address AddressT

Program's base address

required

Attributes:

Name Type Description
logger

A logger instance

program Program

Program reference

base_address AddressT

Program base address

Source code in quokka/addresser.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
class Addresser:
    """Class for managing addresses.

    Arguments:
        program: A backref to the program
        base_address: Program's base address

    Attributes:
        logger: A logger instance
        program: Program reference
        base_address: Program base address

    """

    def __init__(self, program: quokka.Program, base_address: AddressT):
        """Constructor"""
        self.logger = logging.getLogger(__name__)
        self.program: quokka.Program = program
        self.base_address: AddressT = base_address

    def absolute(self, offset: int) -> AddressT:
        """Converts an offset in the file to an absolute address

        Arguments:
            offset: Offset in the file

        Returns:
            An absolute address
        """
        return self.base_address + offset

    def file(self, offset: int) -> int:
        """Converts a program offset to a file offset.

        Arguments:
            offset: A virtual address

        Returns:
            A file offset
        """
        try:
            segment = self.program.get_segment(offset)
        except KeyError as exc:
            raise quokka.NotInFileError("Unable to find the segment") from exc

        if segment.file_offset != -1:
            return offset + segment.file_offset

        raise quokka.NotInFileError("Unable to find the offset in the file")

__init__(program, base_address)

Constructor

Source code in quokka/addresser.py
38
39
40
41
42
def __init__(self, program: quokka.Program, base_address: AddressT):
    """Constructor"""
    self.logger = logging.getLogger(__name__)
    self.program: quokka.Program = program
    self.base_address: AddressT = base_address

absolute(offset)

Converts an offset in the file to an absolute address

Parameters:

Name Type Description Default
offset int

Offset in the file

required

Returns:

Type Description
AddressT

An absolute address

Source code in quokka/addresser.py
44
45
46
47
48
49
50
51
52
53
def absolute(self, offset: int) -> AddressT:
    """Converts an offset in the file to an absolute address

    Arguments:
        offset: Offset in the file

    Returns:
        An absolute address
    """
    return self.base_address + offset

file(offset)

Converts a program offset to a file offset.

Parameters:

Name Type Description Default
offset int

A virtual address

required

Returns:

Type Description
int

A file offset

Source code in quokka/addresser.py
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
def file(self, offset: int) -> int:
    """Converts a program offset to a file offset.

    Arguments:
        offset: A virtual address

    Returns:
        A file offset
    """
    try:
        segment = self.program.get_segment(offset)
    except KeyError as exc:
        raise quokka.NotInFileError("Unable to find the segment") from exc

    if segment.file_offset != -1:
        return offset + segment.file_offset

    raise quokka.NotInFileError("Unable to find the offset in the file")