Skip to content

segment

Segment management

Segment

Segment

This class represents IDA segments.

Parameters:

Name Type Description Default
segment Segment

Segment protobuf information

required
program Program

Program back reference

required

Attributes:

Name Type Description
name str

Segment name

start AddressT

Segment starting address

permissions int

Segment permissions

size int

Segment size

type SegmentType

Segment type

program Program

Program reference

file_offset int

Segment offset in the file (if appropriate)

Source code in quokka/segment.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
73
74
75
76
77
78
79
80
81
class Segment:
    """Segment

    This class represents IDA segments.

    Arguments:
        segment: Segment protobuf information
        program: Program back reference

    Attributes:
        name: Segment name
        start: Segment starting address
        permissions: Segment permissions
        size: Segment size
        type: Segment type
        program: Program reference
        file_offset: Segment offset in the file (if appropriate)

    """

    def __init__(
        self,
        segment: "quokka.pb.Quokka.Segment",
        program: quokka.Program,
    ):
        """Constructor"""
        self.name: str = segment.name
        self.start: AddressT = segment.start_addr
        self.permissions: int = segment.permissions
        self.size: int = segment.size
        self.type: "SegmentType" = SegmentType.from_proto(segment.type)

        self.program: quokka.Program = program

        self.file_offset: int = -1
        if segment.no_offset is False:
            self.file_offset = segment.file_offset - self.start

    @property
    def end(self) -> AddressT:
        """End address of the segment"""
        return self.start + self.size

    def writable(self) -> bool:
        """Is the segment writable?"""
        return self.permissions & 0x2 > 0

    def executable(self) -> bool:
        """Is the segment executable?"""
        return self.permissions & 0x1 > 0

    def readable(self) -> bool:
        """Is the segment readable?"""
        return self.permissions & 0x4 > 0

    def in_segment(self, addr: int) -> bool:
        """Does `addr` belong to this segment ?"""
        return self.start <= addr < self.start + self.size

end: AddressT property

End address of the segment

__init__(segment, program)

Constructor

Source code in quokka/segment.py
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def __init__(
    self,
    segment: "quokka.pb.Quokka.Segment",
    program: quokka.Program,
):
    """Constructor"""
    self.name: str = segment.name
    self.start: AddressT = segment.start_addr
    self.permissions: int = segment.permissions
    self.size: int = segment.size
    self.type: "SegmentType" = SegmentType.from_proto(segment.type)

    self.program: quokka.Program = program

    self.file_offset: int = -1
    if segment.no_offset is False:
        self.file_offset = segment.file_offset - self.start

executable()

Is the segment executable?

Source code in quokka/segment.py
71
72
73
def executable(self) -> bool:
    """Is the segment executable?"""
    return self.permissions & 0x1 > 0

in_segment(addr)

Does addr belong to this segment ?

Source code in quokka/segment.py
79
80
81
def in_segment(self, addr: int) -> bool:
    """Does `addr` belong to this segment ?"""
    return self.start <= addr < self.start + self.size

readable()

Is the segment readable?

Source code in quokka/segment.py
75
76
77
def readable(self) -> bool:
    """Is the segment readable?"""
    return self.permissions & 0x4 > 0

writable()

Is the segment writable?

Source code in quokka/segment.py
67
68
69
def writable(self) -> bool:
    """Is the segment writable?"""
    return self.permissions & 0x2 > 0