program
Program
This is the main class of Quokka. It deals with the most common abstraction, the Program.
Program
Bases: dict
Program
The program is quokka
main abstraction.
It represents the full binary and is in itself a mapping of functions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
export_file |
Union[Path, str]
|
Path towards the export file (e.g. .quokka) |
required |
exec_path |
Union[Path, str]
|
Path towards the binary file |
required |
Attributes:
Name | Type | Description |
---|---|---|
proto |
Quokka
|
Contains the protobuf data. This should not be used directly. However, if you don't find another way of accessing some information, feel free to open an issue. |
export_file |
Path
|
The path to the export file (e.g. the .quokka) |
mode |
ExporterMode
|
Export mode (LIGHT, NORMAL or FULL) |
base_address |
AddressT
|
Program base address |
addresser |
Utility to convert the program offsets into file-offsets |
|
isa |
ArchEnum
|
Instruction set |
address_size |
int
|
Default pointer size |
arch |
Type[QuokkaArch]
|
Program architecture |
endianness |
Endianness
|
Program endianness |
chunks |
Dict[int, Union[Chunk, SuperChunk]]
|
A mapping of chunks |
executable |
An object to manage the binary file |
|
references |
The reference manager |
|
data_holder |
The data manager |
|
fun_names |
Dict[str, Function]
|
A mapping of function names to functions |
Raises:
Type | Description |
---|---|
QuokkaError
|
If the loading is not successful. |
Source code in quokka/program.py
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 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 |
|
call_graph: networkx.DiGraph
cached
property
Compute the Call Graph of the binary
Every node in the call graph is a chunk (and not a function).
:return: A Call Graph (a networkx DiGraph)
capstone: capstone.Cs
cached
property
Compute a capstone context
func_chunk_index: Dict[Index, List[quokka.Function]]
cached
property
Returns the list of functions attached to a chunk.
This method allows to find all the functions using a specific chunk.
However, it is mostly an internal method and should not be directly used by a
user. Instead, use get_function_by_chunk
.
Returns:
Type | Description |
---|---|
Dict[Index, List[Function]]
|
A mapping of ChunkIndex to a list of Function. |
hash: str
property
Returns the hash value of the binary (either sha256 or MD5).
name: str
property
Returns the underlying binary name
pypcode: pypcode.Context
cached
property
Generate the Pypcode context.
segments: List[quokka.Segment]
cached
property
Returns the list of segments defined in the program.
strings: Iterable[str]
property
Program strings
Retrieves all the strings used in the program.
Returns:
Type | Description |
---|---|
Iterable[str]
|
A list of strings. |
structures: List[quokka.Structure]
cached
property
Structures accessor
Allows to retrieve the different structures of a program (as defined by the disassembler).
Returns:
Type | Description |
---|---|
List[Structure]
|
A list of structures |
__hash__()
Hash of the Program (use the hash from the exported file)
Source code in quokka/program.py
170 171 172 |
|
__init__(export_file, exec_path)
Constructor
Source code in quokka/program.py
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 |
|
__repr__()
Program representation
Source code in quokka/program.py
474 475 476 |
|
__str__()
Program representation
Source code in quokka/program.py
478 479 480 |
|
from_binary(exec_path, output_file=None, database_file=None, debug=False, timeout=600)
staticmethod
Generate an export file directly from the binary.
This methods will export exec_path
directly using Quokka IDA's plugin if
installed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exec_path |
Union[Path, str]
|
Binary to export. |
required |
output_file |
Optional[Union[Path, str]]
|
Where to store the result (by default: near the executable) |
None
|
database_file |
Optional[Union[Path, str]]
|
Where to store IDA database (by default: near the executable) |
None
|
timeout |
Optional[int]
|
How long should we wait for the export to finish (default: 10 min) |
600
|
debug |
bool
|
Activate the debug output |
False
|
Returns:
Type | Description |
---|---|
Optional[Program]
|
A | |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the executable is not found |
Source code in quokka/program.py
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 |
|
get_chunk(chunk_index, block_index=None)
Get a Chunk
If the candidate Chunk is a SuperChunk, this method will resolve it to find the appropriate chunk (given a block index).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
chunk_index |
Index
|
Chunk index |
required |
block_index |
Optional[Index]
|
Used to resolve SuperChunks |
None
|
Returns:
Type | Description |
---|---|
Chunk
|
A Chunk matching the criteria |
Raises:
Type | Description |
---|---|
ChunkMissingError
|
When no chunk has been found |
Source code in quokka/program.py
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 |
|
get_data(address)
Get data by address
Parameters:
Name | Type | Description | Default |
---|---|---|---|
address |
AddressT
|
Address to query |
required |
Returns:
Type | Description |
---|---|
Data
|
A data at the address |
Source code in quokka/program.py
463 464 465 466 467 468 469 470 471 472 |
|
get_first_function_by_chunk(chunk)
Return the first function found when searching for a chunk.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
chunk |
Chunk
|
Chunk belonging to the function |
required |
Returns:
Type | Description |
---|---|
Optional[Function]
|
A function in which |
Raises:
Type | Description |
---|---|
FunctionMissingError
|
No function has been found for the chunk |
Source code in quokka/program.py
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 |
|
get_function(name, approximative=True, normal=False)
Find a function in a program by its name
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
Function name |
required |
approximative |
bool
|
Should the name exactly match or allow partial matches? |
True
|
normal |
bool
|
Return only FunctionType.NORMAL functions |
False
|
Returns:
Type | Description |
---|---|
Function
|
A function matching the research criteria |
Raises:
Type | Description |
---|---|
ValueError
|
When no function is found |
Source code in quokka/program.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
|
get_function_by_chunk(chunk)
Retrieves all the functions where chunk
belongs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
chunk |
Chunk
|
Chunk to search for |
required |
Returns:
Type | Description |
---|---|
List[Function]
|
A list of corresponding functions |
Raises:
Type | Description |
---|---|
IndexError
|
When no function is found for the chunk. |
Source code in quokka/program.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
|
get_instruction(address)
Get an instruction by its address
Note: the address must be the head of the instruction.
TODO(dm): Improve the algorithm because the chunks are sorted (use bisect)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
address |
AddressT
|
AddressT: Address to query |
required |
Returns:
Type | Description |
---|---|
Instruction
|
A |
Raises:
Type | Description |
---|---|
IndexError
|
When no instruction is found at this address |
Source code in quokka/program.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
|
get_segment(address)
Get a Segment
by an address
The address must be in [segment.start, segment.end) to be found.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
address |
AddressT
|
Segment's address |
required |
Returns:
Type | Description |
---|---|
Segment
|
The corresponding Segment |
Raises:
Type | Description |
---|---|
KeyError
|
When the segment is not found |
Source code in quokka/program.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
|
iter_chunk(chunk_types=None)
Iterate over all the chunks in the program.
If a SuperChunk
is found, it will split it and return individual chunks.
By default, it iterates over all the chunks, even extern functions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
chunk_types |
Optional[List[FunctionType]]
|
Allow list of chunk types. By default, it retrieves every chunk. |
None
|
Yields:
Type | Description |
---|---|
Chunk
|
All the chunks in the program. |
Source code in quokka/program.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 |
|
read_bytes(v_addr, size)
Read raw bytes from a virtual address
Parameters:
Name | Type | Description | Default |
---|---|---|---|
v_addr |
AddressT
|
Virtual address of the data to read |
required |
size |
int
|
Size of the data to read |
required |
Returns:
Type | Description |
---|---|
bytes
|
The raw data at the specified address |
Source code in quokka/program.py
448 449 450 451 452 453 454 455 456 457 458 459 460 461 |
|