block
Methods to use and deal with blocks in a binary.
Block
Bases: MutableMapping
Basic Block class
A basic block is a sequence of instructions without any (basic) incoming flows disrupting it (except calls returns).
While blocks may be serialized in the exported file, a new instance of this class is created for each block in the program (so they all have an unique address).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
block_idx
|
Index
|
Index in the protobuf file of the block |
required |
start_address
|
AddressT
|
Starting address of the block |
required |
function
|
Function
|
Parent function of the block. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
proto |
Protobuf object |
|
parent |
Function
|
A reference to the parent Function |
program |
Program
|
A reference to the parent Program |
start |
int
|
Start address |
type |
BlockType
|
Block type |
address_to_index |
dict[AddressT, Index]
|
A mapping of addresses to instruction indexes |
end |
int
|
End address |
comments |
dict[AddressT, str]
|
List of comments attached to the block |
Source code in bindings/python/quokka/block.py
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 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
address
property
Direct accessor of the block address
bytes
cached
property
Retrieve the block bytes
All bytes for the block are read at once in the file but the result is not cached.
constants
cached
property
Constants used by the block
end
property
Size of the block.
This number is the number of instruction * the size of an instruction for architecture with fixed length instructions (e.g. ARM).
instructions
property
Accessor of the block instructions
last_instruction
property
Direct accessor of the last instruction in the block
pcode_insts
cached
property
Generate PCode instructions for the block
This method will call the backend Pypcode and generate the instruction for the whole block, updating all the instruction inside the block as well.
However, all instructions will from now be attached to the block itself, and not the instructions so the list may differ after some optimizations (e.g. len(self.pcode_insts) != sum(len(inst.pcode_insts) for inst in block.values()) )
Returns:
| Type | Description |
|---|---|
list[PcodeOp]
|
A list of PCode instructions |
program
property
Return the parent program
strings
cached
property
Strings used by the block
__delitem__(v)
Remove an instruction from the mapping
Source code in bindings/python/quokka/block.py
121 122 123 | |
__getitem__(address)
Retrieve an instruction at address.
Source code in bindings/python/quokka/block.py
134 135 136 | |
__hash__()
Hash of the block.
The proto index is guaranteed to be unique so we can use it as an hash and forget about un-hashable types.
TODO(dm): Check this
Source code in bindings/python/quokka/block.py
184 185 186 187 188 189 190 191 192 193 | |
__init__(block_idx, start_address, function)
Constructor
Source code in bindings/python/quokka/block.py
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 | |
__iter__()
Return an iterator over the instruction list
Source code in bindings/python/quokka/block.py
142 143 144 | |
__len__()
Number of instruction in the block
Source code in bindings/python/quokka/block.py
138 139 140 | |
__repr__()
Block Representation
Source code in bindings/python/quokka/block.py
178 179 180 181 182 | |
__setitem__(k, ins)
Update the instructions mapping
Source code in bindings/python/quokka/block.py
117 118 119 | |
add_comment(addr, value)
Set the comment at addr.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
addr
|
AddressT
|
Comment address |
required |
value
|
str
|
Comment value |
required |
Source code in bindings/python/quokka/block.py
125 126 127 128 129 130 131 132 | |
predecessors()
(Addresses of) Predecessors of the current block
Source code in bindings/python/quokka/block.py
199 200 201 | |
successors()
(Addresses of the) Successors of the current block.
Source code in bindings/python/quokka/block.py
195 196 197 | |