Unpack and apply a saved Qiling state. Only saved components will be restored; the rest remains intact. Args: saved_states : a saved state dictionary originally created by the `save` method snapshot : path of a snapshot file containing a dumped saved stat
(self, saved_states: Mapping[str, Any] = {}, *, snapshot: Optional[str] = None)
| 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. |
| 660 | Only saved components will be restored; the rest remains intact. |
| 661 | |
| 662 | Args: |
| 663 | saved_states : a saved state dictionary originally created by the `save` method |
| 664 | snapshot : path of a snapshot file containing a dumped saved state. |
| 665 | |
| 666 | Notes: |
| 667 | Only restore a saved state provided by a trusted entity. |
| 668 | In case both arguments are provided, snapshot file will be ignored |
| 669 | """ |
| 670 | |
| 671 | # snapshot will be ignored if saved_states is set |
| 672 | if (not saved_states) and (snapshot is not None): |
| 673 | with open(snapshot, "rb") as load_state: |
| 674 | saved_states = pickle.load(load_state) |
| 675 | |
| 676 | if "mem" in saved_states: |
| 677 | self.mem.restore(saved_states["mem"]) |
| 678 | |
| 679 | if "cpu_context" in saved_states: |
| 680 | self.arch.restore(saved_states["cpu_context"]) |
| 681 | |
| 682 | if "reg" in saved_states: |
| 683 | self.arch.regs.restore(saved_states["reg"]) |
| 684 | |
| 685 | if self.arch.type in (QL_ARCH.ARM, QL_ARCH.ARM64): |
| 686 | self.arch.cpr.restore(saved_states["cpr"]) |
| 687 | |
| 688 | if "hw" in saved_states: |
| 689 | self.hw.restore(saved_states['hw']) |
| 690 | |
| 691 | if "fd" in saved_states: |
| 692 | self.os.fd.restore(saved_states["fd"]) |
| 693 | |
| 694 | if "os" in saved_states: |
| 695 | self.os.restore(saved_states["os"]) |
| 696 | |
| 697 | if "loader" in saved_states: |
| 698 | self.loader.restore(saved_states["loader"]) |
| 699 | |
| 700 | # Map "ql_path" to any objects which implements QlFsMappedObject. |
| 701 | def add_fs_mapper(self, ql_path: Union["PathLike", str], real_dest): |