File size: 2,201 Bytes
142a68d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
from __future__ import annotations

ACTIONS = [
    "PAD",
    "REPORT",
    "OPEN_APP",
    "READ_FILE",
    "WRITE_FILE",
    "DELETE_FILE",
    "INSTALL_PACKAGE",
    "SEARCH_LOCAL",
    "SEARCH_WEB",
    "RESTART_SERVICE",
    "WRITE_BACKUP",
    "ASK_CONFIRMATION",
    "REFUSE",
]
STATE_NAMES = [
    "file_exists",
    "app_open",
    "package_installed",
    "service_running",
    "backup_exists",
    "report_available",
    "confirmation_pending",
    "refusal_logged",
]
CAPABILITY_NAMES = ["administrator", "network", "confirmed", "sensitive_target"]


def reference_transition(
    state: list[int],
    capabilities: list[int],
    action: str,
) -> tuple[list[int], int]:
    next_state = list(state)
    administrator, network, confirmed, sensitive = map(bool, capabilities)
    blocked = 0
    if action == "REPORT":
        next_state[5] = 1
    elif action == "OPEN_APP":
        next_state[1] = 1
    elif action == "READ_FILE":
        if not state[0] or (sensitive and not administrator):
            blocked = 1
        else:
            next_state[5] = 1
    elif action == "WRITE_FILE":
        if sensitive and not administrator:
            blocked = 1
        else:
            next_state[0] = 1
    elif action == "DELETE_FILE":
        if not confirmed or sensitive or not state[0]:
            blocked = 1
        else:
            next_state[0] = 0
    elif action == "INSTALL_PACKAGE":
        if not (confirmed and administrator and network):
            blocked = 1
        else:
            next_state[2] = 1
    elif action == "SEARCH_LOCAL":
        next_state[5] = 1
    elif action == "SEARCH_WEB":
        if not network:
            blocked = 1
        else:
            next_state[5] = 1
    elif action == "RESTART_SERVICE":
        if not (confirmed and administrator):
            blocked = 1
        else:
            next_state[3] = 1
    elif action == "WRITE_BACKUP":
        if not state[0] or (sensitive and not administrator):
            blocked = 1
        else:
            next_state[4] = 1
    elif action == "ASK_CONFIRMATION":
        next_state[6] = 1
    elif action == "REFUSE":
        next_state[7] = 1
    return next_state, blocked