function
Functions and chunk management
Chunk
Bases: MutableMapping
, Iterable
Chunk object
A chunk is an IDA specific item that is used for code reuse across functions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
chunk_idx |
Index
|
Index of the chunk in the protobuf |
required |
program |
Program
|
Backref to the program |
required |
accepted_addresses |
List[AddressT]
|
A list of address for blocks heads. Used only for fake chunks. |
None
|
Attributes:
Name | Type | Description |
---|---|---|
program |
Program
|
Program reference |
proto_index |
Index
|
Index inside the protobuf |
start |
AddressT
|
Start address |
fake |
bool
|
Is the chunk fake? |
index_to_address |
Dict[int, int]
|
Mapping from index to block starting address |
chunk_type |
FunctionType
|
Chunk type |
chunk |
Proto information |
Source code in quokka/function.py
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 |
|
block_ranges: List[Tuple[AddressT, AddressT]]
property
Returns the sorted list of block ranges.
A block range is a tuple (block.start, block.end).
callers: List[Chunk]
property
Return the list of callers of this chunk.
calls: List[quokka.Chunk]
property
Return the list of calls made by this chunk.
Note: The list is not deduplicated so a target may occur multiple time.
constants: List[int]
cached
property
Return the constants used in the chunk
data_references: List[quokka.Data]
property
Returns the data reference in the chunk
end: AddressT
cached
property
Compute the end address of a chunk
graph: 'networkx.DiGraph'
cached
property
Return the CFG of the chunk as DiGraph object
in_degree: int
cached
property
Compute the chunk in degree
Get the in-degree of a chunk. This is the number of distinct incoming edges.
Returns:
Type | Description |
---|---|
int
|
Chunk in-degree |
instructions: Generator
property
Iterator over instructions in the chunk
name: str
cached
property
Chunk name.
The chunk name is the one of its parent if it exists or is empty otherwise.
Returns:
Type | Description |
---|---|
str
|
Chunk name |
out_degree: int
cached
property
Compute the chunk out degree
Get the out degree of a chunk (e.g. the number of distinct chunks called by this one).
Returns:
Type | Description |
---|---|
int
|
Number of distinct out edges |
size: int
cached
property
Return the size of a chunk
strings: List[str]
cached
property
Return the strings used in the chunk
__delitem__(k)
Remove a block
Source code in quokka/function.py
201 202 203 |
|
__getitem__(address)
Lazy loader for blocks
Source code in quokka/function.py
205 206 207 208 |
|
__hash__()
Override hash method to return an unique index
Source code in quokka/function.py
375 376 377 |
|
__init__(chunk_idx, program, accepted_addresses=None)
Constructor
Source code in quokka/function.py
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 |
|
__iter__()
Iterator over the blocks
Source code in quokka/function.py
193 194 195 |
|
__len__()
Number of blocks in the chunk
Source code in quokka/function.py
189 190 191 |
|
__setitem__(k, v)
Set block
Source code in quokka/function.py
197 198 199 |
|
__str__()
Chunk representation
Source code in quokka/function.py
210 211 212 |
|
get_block(address)
Get the block at address
Source code in quokka/function.py
371 372 373 |
|
get_instruction(address)
Get the instruction at address
Source code in quokka/function.py
360 361 362 363 364 365 366 367 368 369 |
|
in_chunk(address)
Check if an address belongs to the chunk.
Source code in quokka/function.py
346 347 348 349 350 351 352 353 354 355 356 357 358 |
|
Function
Bases: dict
Function object
This class represents a binary function within the Program.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func |
'quokka.pb.Quokka.Function'
|
Protobuf data |
required |
program |
Program
|
Program reference |
required |
Attributes:
Name | Type | Description |
---|---|---|
start |
int
|
Start address |
name |
str
|
Function name |
mangled_name |
str
|
Function mangled name (it might be equal to the function name) |
program |
Program
|
Program reference |
type |
'FunctionType'
|
Function type |
index_to_address |
Dict[int, int]
|
Mapping of Chunks to Protobuf indexes |
func |
Protobuf data |
Source code in quokka/function.py
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 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 |
|
blocks: dict[AddressT, quokka.Block]
property
Returns a dictionary which is used to reference all basic blocks by their address. Calling this function will also load the CFG.
callers: List[Chunk]
property
Retrieve the function callers (the ones calling this function)
calls: List[Chunk]
property
Retrieve the function calls (the ones called by the function)
constants: List[int]
cached
property
Lists constants used in the function
data_references
property
Lists data references used in the function
end: int
cached
property
Get the last address of the function
graph: 'networkx.DiGraph'
cached
property
Compute the Control Flow Graph for the function
in_degree: int
cached
property
Function in degree
instructions
property
Yields the function instruction
out_degree: int
cached
property
Function out degree
strings: List[str]
cached
property
Return the list of strings used in the function
__hash__()
Hash value
Source code in quokka/function.py
721 722 723 |
|
__init__(func, program)
Constructor
Source code in quokka/function.py
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 |
|
__repr__()
Function representation
Source code in quokka/function.py
729 730 731 |
|
__str__()
Function representation
Source code in quokka/function.py
725 726 727 |
|
get_block(address)
Get the block at address
Source code in quokka/function.py
596 597 598 599 600 601 602 603 604 |
|
get_instruction(address)
Get the instruction at address
Source code in quokka/function.py
606 607 608 609 610 611 612 |
|
in_func(address)
Check if the address
belongs to this function.
Source code in quokka/function.py
695 696 697 698 699 700 701 |
|
SuperChunk
Bases: MutableMapping
SuperChunk: fake functions
A SuperChunk is an abstract construction that has no other meaning that serve as a candidate (or fake) function.
Indeed, super chunks are created when a chunk (or a fake chunk) have multiple non-connected components.
A superchunk keeps a mapping of chunk index to chunk instance and implements most of a function interface.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
initial_chunk |
Chunk
|
The chunk to split |
required |
components |
Generator
|
The various non-connected components |
required |
Attributes:
Name | Type | Description |
---|---|---|
proto_idx |
Index
|
Initial chunk proto index |
addresses |
Dict[AddressT, int]
|
All addresses belonging to the chunk with the instruction index |
chunks |
Dict[Index, Chunk]
|
Mapping of chunks within the SuperChunk |
starts |
Dict[AddressT, Chunk]
|
Mapping of chunk starts to chunks |
Source code in quokka/function.py
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 |
|
__delitem__(v)
Delete a chunk
Source code in quokka/function.py
443 444 445 |
|
__getitem__(k)
Get a chunk
Source code in quokka/function.py
447 448 449 |
|
__init__(initial_chunk, components)
Init method
Parameters:
Name | Type | Description | Default |
---|---|---|---|
initial_chunk |
Chunk
|
Original chunk to split |
required |
components |
Generator
|
A generator of sets for each component of the graph |
required |
Source code in quokka/function.py
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 |
|
__iter__()
Iterator over chunk
Source code in quokka/function.py
455 456 457 |
|
__len__()
Number of chunk
Source code in quokka/function.py
451 452 453 |
|
__setitem__(k, v)
Set a chunk
Source code in quokka/function.py
439 440 441 |
|
__str__()
SuperChunk representation
Source code in quokka/function.py
459 460 461 |
|
get_chunk(address)
Return a chunk by an address.
To resolve an address and retrieve the appropriate chunk, we enumerate the chunks and look within the blocks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
address |
AddressT
|
Address to query |
required |
Raises:
Type | Description |
---|---|
IndexError
|
When no chunk is found |
Source code in quokka/function.py
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 |
|
get_chunk_by_index(chunk_index, block_index)
Return a chunk by its index
This must be reimplemented because the chunk_index is unique for the proto but there are multiple chunks existing with the same index because of a SuperChunk.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
chunk_index |
Index
|
Chunk index |
required |
block_index |
Index
|
Block index |
required |
Raises:
Type | Description |
---|---|
ChunkMissingError
|
if the chunk is not found |
Source code in quokka/function.py
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 |
|
get_instruction(address)
Get the instruction at address
Source code in quokka/function.py
530 531 532 533 534 535 536 |
|
in_chunk(address)
Check if address belongs to this SuperChunk
Source code in quokka/function.py
519 520 521 522 523 524 525 526 527 528 |
|
dereference_thunk(item, caller=False)
Dereference a thunk
This method is used to resolve a thunk calls / callers. As thunk function only have 1 relation : FUNC (call x) -> THUNK X -> X , it disrupts the call graph and heuristics based on graph degrees.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
item |
Union[Function, Chunk]
|
Either a function or a chunk |
required |
caller |
bool
|
True if we want to find the callers (e.g. the functions that call item) False if we want to find the callee (e.g. function that are called by item) |
False
|
Raises:
Type | Description |
---|---|
ThunkMissingError
|
When no thunk has been found |
FunctionMissingError
|
When no function has been found |
Source code in quokka/function.py
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 |
|
get_degrees(item)
Compute the {in, out} degrees of an item (Function/Chunk)
Source code in quokka/function.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
|