executable
Executable: management of the binary file in itself.
Executable
The executable class is used to interact with the binary file.
It handles access to the binary file itself (not the exported) for reads.
Note: The binary is read only once and stored in memory. This is done for performance purposes but does not cope well with low RAM systems and/or huge binaries.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Union[str, Path]
|
Path towards the executable file |
required |
endianness |
Endianness
|
How are stored the data |
required |
Attributes:
Name | Type | Description |
---|---|---|
exec_file |
Path
|
Path towards the executable file |
endianness |
Endianness
|
Binary endianness |
content |
bytes
|
Bytes of the binary |
Raises:
Type | Description |
---|---|
ValueError
|
If the file is not found |
Source code in quokka/executable.py
23 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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
|
__init__(path, endianness)
Constructor
Source code in quokka/executable.py
45 46 47 48 49 50 51 52 53 54 55 |
|
read(offset, size)
Read size
at offset
in the file.
This method should not be used directly and considered as part of a private API. The preferred method are read_bytes / read_string .
Parameters:
Name | Type | Description | Default |
---|---|---|---|
offset |
int
|
File offset |
required |
size |
int
|
Read size |
required |
Returns:
Type | Description |
---|---|
bytes
|
The content that has been read |
Raises:
Type | Description |
---|---|
ValueError
|
when the value is not in the file |
Source code in quokka/executable.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
read_bytes(offset, size)
Read one (or more) byte(s) in the file at offset
.
This is mostly used to read instructions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
offset |
int
|
File offset to read |
required |
size |
int
|
Number of bytes to read |
required |
Returns:
Type | Description |
---|---|
bytes
|
The bytes values |
Source code in quokka/executable.py
173 174 175 176 177 178 179 180 181 182 183 184 185 |
|
read_data(offset, data_type, size=None)
Read the data value.
If the size is not specified, it is inferred from the data type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
offset |
int
|
Data file offset |
required |
data_type |
DataType
|
Data type |
required |
size |
Optional[int]
|
Read size |
None
|
Returns:
Type | Description |
---|---|
Union[int, float, str]
|
The data value |
Source code in quokka/executable.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
|
read_string(offset, size=None)
Read a string in the file.
If the size is not given, Quokka will try to read the string until the first null byte. That works only for null-terminated strings.
If the string is null terminated, remove the trailing 0.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
offset |
int
|
String file offset |
required |
size |
Optional[int]
|
String size if known. |
None
|
Returns:
Type | Description |
---|---|
str
|
The decoded string |
Raises:
Type | Description |
---|---|
ValueError
|
If the string is not found nor decoded. |
Source code in quokka/executable.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
|