Pack Qiling's current state into an object and optionally dump it to a file. Specific components may be included or excluded from the save state. Args: reg : include all registers values mem : include memory layout and content hw
(self, reg=True, mem=True, hw=False, fd=False, cpu_context=False, os=False, loader=False, *, snapshot: Optional[str] = None)
| 607 | self.patch_lib.append((offset, data, target)) |
| 608 | |
| 609 | def save(self, reg=True, mem=True, hw=False, fd=False, cpu_context=False, os=False, loader=False, *, snapshot: Optional[str] = None): |
| 610 | """Pack Qiling's current state into an object and optionally dump it to a file. |
| 611 | Specific components may be included or excluded from the save state. |
| 612 | |
| 613 | Args: |
| 614 | reg : include all registers values |
| 615 | mem : include memory layout and content |
| 616 | hw : include hardware entities state (baremetal only) |
| 617 | fd : include OS file descriptors table, where supported |
| 618 | cpu_context : include underlying Unicorn state |
| 619 | os : include OS-related state |
| 620 | loader : include Loader-related state |
| 621 | snapshot : specify a filename to dump the state into (optional) |
| 622 | |
| 623 | Returns: a dictionary holding Qiling's current state |
| 624 | """ |
| 625 | |
| 626 | saved_states = {} |
| 627 | |
| 628 | if reg: |
| 629 | saved_states["reg"] = self.arch.regs.save() |
| 630 | |
| 631 | if self.arch.type in (QL_ARCH.ARM, QL_ARCH.ARM64): |
| 632 | saved_states["cpr"] = self.arch.cpr.save() |
| 633 | |
| 634 | if mem: |
| 635 | saved_states["mem"] = self.mem.save() |
| 636 | |
| 637 | if hw: |
| 638 | saved_states["hw"] = self.hw.save() |
| 639 | |
| 640 | if fd: |
| 641 | saved_states["fd"] = self.os.fd.save() |
| 642 | |
| 643 | if cpu_context: |
| 644 | saved_states["cpu_context"] = self.arch.save() |
| 645 | |
| 646 | if os: |
| 647 | saved_states["os"] = self.os.save() |
| 648 | |
| 649 | if loader: |
| 650 | saved_states["loader"] = self.loader.save() |
| 651 | |
| 652 | if snapshot is not None: |
| 653 | with open(snapshot, "wb") as save_state: |
| 654 | pickle.dump(saved_states, save_state) |
| 655 | |
| 656 | return saved_states |
| 657 | |
| 658 | def restore(self, saved_states: Mapping[str, Any] = {}, *, snapshot: Optional[str] = None): |
| 659 | """Unpack and apply a saved Qiling state. |