-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreference_monitor_ra3108.r2py
More file actions
112 lines (94 loc) · 3.18 KB
/
reference_monitor_ra3108.r2py
File metadata and controls
112 lines (94 loc) · 3.18 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
TYPE="type"
ARGS="args"
RETURN="return"
EXCP="exceptions"
TARGET="target"
FUNC="func"
OBJC="objc"
class ABFile():
def __init__(self,filename,create):
# globals
mycontext['debug'] = False
# local (per object) reference to the underlying file
if '_' in filename:
exitall()
self.Afn = filename+'.a'
self.Bfn = filename+'.b'
flag = False
if self.Afn not in listfiles() and self.Bfn not in listfiles() and create == False:
exitall()
if self.Afn not in listfiles() and create == True:
if self.Bfn in listfiles():
removefile(self.Bfn)
flag = True
try:
self.Afile = openfile(self.Afn,create)
self.Bfile = openfile(self.Bfn,create)
except:
exitall();
self.lock = createlock()
self.Bfile.lock = createlock()
self.Afile.lock = createlock()
if flag:
self.Afile.writeat('SE',0)
#self.Afile = openfile(self.Afn,False)
#self.Bfile = openfile(self.Bfn,True)
#content = self.Afile.readat(None,0)
#self.Bfile.writeat(content,0)
def writeat(self,data,offset):
self.lock.acquire(True)
if(offset < 0 or offset > len(self.Bfile.readat(None,0))):
exitall()
self.Bfile.lock.acquire(True)
self.Bfile.writeat(data,offset)
self.Bfile.lock.release()
self.lock.release()
def readat(self,bytes,offset):
self.lock.acquire(True)
if(offset < 0):
exitall()
self.Bfile.lock.acquire(True)
value = self.Afile.readat(bytes,offset)
self.Bfile.lock.release()
self.lock.release()
return value
def close(self):
self.lock.acquire(True)
conlist = []
acontent = self.Afile.readat(None,0)
bcontent = self.Bfile.readat(None,0)
#log(len(bcontent))
if (len(bcontent) <=1):
exitall()
conlist = list(bcontent)
try:
if (conlist[0] == 'S'and conlist[-1] == 'E'):
self.Afile.close()
removefile(self.Afn)
self.Afile = openfile(self.Afn,True)
self.Afile.writeat(bcontent,0)
#log(self.Afile.readat(None,0))
else:
self.Bfile.close()
removefile(self.Bfn)
self.Bfile = openfile(self.Bfn,True)
self.Bfile.writeat(acontent,0)
except:
pass
self.Afile.close()
self.Bfile.close()
#removefile(self.Bfn)
self.lock.release()
def ABopenfile(filename, create):
return ABFile(filename,create)
# The code here sets up type checking and variable hiding for you. You
# should not need to change anything below here.
sec_file_def = {"obj-type":ABFile,
"name":"ABFile",
"writeat":{"type":"func","args":(str,(int,long)),"exceptions":Exception,"return":(int,type(None)),"target":ABFile.writeat},
"readat":{"type":"func","args":((int,long,type(None)),(int,long)),"exceptions":Exception,"return":str,"target":ABFile.readat},
"close":{"type":"func","args":None,"exceptions":None,"return":(bool,type(None)),"target":ABFile.close}
}
CHILD_CONTEXT_DEF["ABopenfile"] = {TYPE:OBJC,ARGS:(str,bool),EXCP:Exception,RETURN:sec_file_def,TARGET:ABopenfile}
# Execute the user code
secure_dispatch_module()