-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathStructures.cs
168 lines (135 loc) · 3.41 KB
/
Structures.cs
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
using System;
using System.ComponentModel;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
namespace Com.Xenthrax
{
public partial class DllInjector : IDisposable
{
[StructLayout(LayoutKind.Sequential)]
public struct RemPtr : ISerializable
{
public const RemPtr Zero = new RemPtr(0);
public RemPtr(int value)
{
this.Value = value;
}
public RemPtr(long value)
{
this.Value = value;
}
public RemPtr(IntPtr value)
{
this.Value = value.ToInt64();
}
public unsafe RemPtr(void* value)
{
this.Value = (long)value;
}
private RemPtr(SerializationInfo info, StreamingContext context)
{
long num = info.GetInt64("value");
//if ((Size == 4) && ((num > 0x7fffffffL) || (num < -2147483648L)))
// throw new ArgumentException(Environment.GetResourceString("Serialization_InvalidPtrValue"));
this.Value = num;
}
private long Value;
private unsafe void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
if (info == null)
throw new ArgumentNullException("info");
info.AddValue("value", this.Value);
}
public override bool Equals(object obj)
{
if (obj is RemPtr)
{
RemPtr ptr = (RemPtr)obj;
return (this.Value == ptr.Value);
}
return false;
}
public override int GetHashCode()
{
return (int)this.Value;
}
public int ToInt32()
{
return (int)this.Value;
}
public long ToInt64()
{
return this.Value;
}
public IntPtr ToIntPtr()
{
return (IntPtr)this.Value;
}
public unsafe void* ToPointer()
{
return (void*)this.Value;
}
public override string ToString()
{
return this.Value.ToString(CultureInfo.InvariantCulture);
}
public string ToString(string format)
{
return this.Value.ToString(format, CultureInfo.InvariantCulture);
}
public static explicit operator RemPtr(int value)
{
return new RemPtr(value);
}
public static explicit operator RemPtr(long value)
{
return new RemPtr(value);
}
public static explicit operator RemPtr(IntPtr value)
{
return new RemPtr(value);
}
public static unsafe explicit operator RemPtr(void* value)
{
return new RemPtr(value);
}
public static unsafe explicit operator void*(RemPtr value)
{
return value.ToPointer();
}
public static explicit operator int(RemPtr value)
{
return (int)value.Value;
}
public static explicit operator long(RemPtr value)
{
return value.Value;
}
public static unsafe bool operator ==(RemPtr value1, RemPtr value2)
{
return value1.Value == value2.Value;
}
public static unsafe bool operator !=(RemPtr value1, RemPtr value2)
{
return value1.Value != value2.Value;
}
public static RemPtr Add(RemPtr pointer, int offset)
{
return pointer + offset;
}
public static RemPtr operator +(RemPtr pointer, int offset)
{
return new RemPtr(pointer.ToInt64() + offset);
}
public static RemPtr Subtract(RemPtr pointer, int offset)
{
return pointer - offset;
}
public static RemPtr operator -(RemPtr pointer, int offset)
{
return new RemPtr(pointer.ToInt64() - offset);
}
}
}
}