1
0
mirror of https://github.com/angr/angr synced 2026-06-08 13:09:39 +00:00
Files
angr-angr/tests/knowledge_plugins/test_variable_manager.py
T
2026-02-23 17:14:46 -07:00

45 lines
1.3 KiB
Python

#!/usr/bin/env python3
# pylint: disable=missing-class-docstring,no-self-use,line-too-long
from __future__ import annotations
__package__ = __package__ or "tests.knowledge_plugins" # pylint:disable=redefined-builtin
import os
import pickle
import unittest
import angr
from tests.common import bin_location
test_location = os.path.join(bin_location, "tests")
class TestVariableManager(unittest.TestCase):
def test_variable_manager_internal_pickle(self):
p = angr.Project(os.path.join(test_location, "x86_64", "fauxware"), auto_load_libs=False)
vm = p.kb.variables
# Create a VariableManagerInternal and generate some variable idents
vmi = vm.get_function_manager(0x400000)
ident0 = vmi.next_variable_ident("stack")
ident1 = vmi.next_variable_ident("stack")
ident2 = vmi.next_variable_ident("register")
assert ident0 == "is_0"
assert ident1 == "is_1"
assert ident2 == "ir_0"
# Pickle round-trip
data = pickle.dumps(vmi)
vmi2 = pickle.loads(data)
# The counters should continue from where they left off
ident3 = vmi2.next_variable_ident("stack")
ident4 = vmi2.next_variable_ident("register")
assert ident3 == "is_2"
assert ident4 == "ir_1"
if __name__ == "__main__":
unittest.main()