@@ -11,6 +11,7 @@ public class MemoryBuffer
11
11
public RemoteProcess Process { get ; set ; }
12
12
13
13
private byte [ ] data ;
14
+ private byte [ ] historyData ;
14
15
15
16
public int Size
16
17
{
@@ -23,6 +24,7 @@ public int Size
23
24
if ( value != data . Length )
24
25
{
25
26
data = new byte [ value ] ;
27
+ historyData = new byte [ value ] ;
26
28
}
27
29
}
28
30
}
@@ -33,21 +35,26 @@ public int Size
33
35
private void ObjectInvariants ( )
34
36
{
35
37
Contract . Invariant ( data != null ) ;
38
+ Contract . Invariant ( historyData != null ) ;
36
39
}
37
40
38
41
public MemoryBuffer ( )
39
42
{
40
43
Contract . Ensures ( data != null ) ;
44
+ Contract . Ensures ( historyData != null ) ;
41
45
42
46
data = new byte [ 0 ] ;
47
+ historyData = new byte [ 0 ] ;
43
48
}
44
49
45
50
public MemoryBuffer ( MemoryBuffer other )
46
51
{
47
52
Contract . Requires ( other != null ) ;
48
53
Contract . Ensures ( data != null ) ;
54
+ Contract . Ensures ( historyData != null ) ;
49
55
50
56
data = other . data ;
57
+ historyData = other . historyData ;
51
58
}
52
59
53
60
public MemoryBuffer Clone ( )
@@ -62,9 +69,19 @@ public MemoryBuffer Clone()
62
69
}
63
70
64
71
public void Update ( IntPtr address )
72
+ {
73
+ Update ( address , true ) ;
74
+ }
75
+
76
+ public void Update ( IntPtr address , bool setHistory )
65
77
{
66
78
Contract . Requires ( Process != null ) ;
67
79
80
+ if ( setHistory )
81
+ {
82
+ Array . Copy ( data , historyData , data . Length ) ;
83
+ }
84
+
68
85
Process . ReadRemoteMemoryIntoBuffer ( address , ref data ) ;
69
86
}
70
87
@@ -92,15 +109,31 @@ public byte[] ReadBytes(int offset, int length)
92
109
Contract . Requires ( offset >= 0 ) ;
93
110
Contract . Requires ( length >= 0 ) ;
94
111
95
- var bytes = new byte [ length ] ;
112
+ var buffer = new byte [ length ] ;
96
113
97
- if ( Offset + offset + length > data . Length )
114
+ ReadBytes ( offset , buffer ) ;
115
+
116
+ return buffer ;
117
+ }
118
+
119
+ public void ReadBytes ( IntPtr offset , byte [ ] buffer )
120
+ {
121
+ Contract . Requires ( buffer != null ) ;
122
+
123
+ ReadBytes ( offset . ToInt32 ( ) , buffer ) ;
124
+ }
125
+
126
+ public void ReadBytes ( int offset , byte [ ] buffer )
127
+ {
128
+ Contract . Requires ( offset >= 0 ) ;
129
+ Contract . Requires ( buffer != null ) ;
130
+
131
+ if ( Offset + offset + buffer . Length > data . Length )
98
132
{
99
- return bytes ;
133
+ return ;
100
134
}
101
135
102
- Array . Copy ( data , Offset + offset , bytes , 0 , length ) ;
103
- return bytes ;
136
+ Array . Copy ( data , Offset + offset , buffer , 0 , buffer . Length ) ;
104
137
}
105
138
106
139
public T ReadObject < T > ( IntPtr offset ) where T : struct
@@ -213,5 +246,30 @@ public string ReadUTF32String(IntPtr offset, int length)
213
246
214
247
return ReadString ( Encoding . UTF32 , offset . ToInt32 ( ) , length ) ;
215
248
}
249
+
250
+ public bool HasChanged ( IntPtr offset , int length )
251
+ {
252
+ return HasChanged ( offset . ToInt32 ( ) , length ) ;
253
+ }
254
+
255
+ public bool HasChanged ( int offset , int length )
256
+ {
257
+ if ( Offset + offset + length > data . Length )
258
+ {
259
+ return false ;
260
+ }
261
+
262
+ var end = Offset + offset + length ;
263
+
264
+ for ( var i = Offset + offset ; i < end ; ++ i )
265
+ {
266
+ if ( data [ i ] != historyData [ i ] )
267
+ {
268
+ return true ;
269
+ }
270
+ }
271
+
272
+ return false ;
273
+ }
216
274
}
217
275
}
0 commit comments