-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory.py
More file actions
31 lines (24 loc) · 973 Bytes
/
Copy pathmemory.py
File metadata and controls
31 lines (24 loc) · 973 Bytes
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
from config import *
class Memory:
NULL = b'\x00' * CACHE_LINE_SIZE
def __init__(self, counter):
self.counter = counter
line = ''.join(chr(i) for i in range(CACHE_LINE_SIZE)).encode(encoding="utf-8")
self.memory = [line] * (MEM_SIZE // CACHE_LINE_SIZE)
def C2_READ_LINE(self, tag: int):
# принятие кэш-линии за CACHE_LINE_SIZE / 2
self.counter += ceil(CACHE_LINE_SIZE / 2)
return self.get(tag)
def get(self, tag: int):
self.counter += 100
return self.memory[tag]
def C2_WRITE_LINE(self, tag: int, data: bytes):
# отправка кэш-линии за CACHE_LINE_SIZE / 2
self.counter += ceil(CACHE_LINE_SIZE / 2)
# принятие ответа за 1
self.counter += 1
return self.set(tag, data)
def set(self, tag: int, data: bytes):
self.counter += 100
self.memory[tag] = data
return b'\x01'