-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dump.cs
104 lines (88 loc) · 2.33 KB
/
Dump.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
using System;
using System.IO;
using DarkOps_Tool;
public class Dump
{
public byte[] mem;
private uint startAddress;
private uint endAddress;
private uint readCompletedAddress;
private int fileNumber;
public uint StartAddress => startAddress;
public uint EndAddress => endAddress;
public uint ReadCompletedAddress
{
get
{
return readCompletedAddress;
}
set
{
readCompletedAddress = value;
}
}
public Dump(uint theStartAddress, uint theEndAddress)
{
Construct(theStartAddress, theEndAddress, 0);
}
public Dump(uint theStartAddress, uint theEndAddress, int theFileNumber)
{
Construct(theStartAddress, theEndAddress, theFileNumber);
}
private void Construct(uint theStartAddress, uint theEndAddress, int theFileNumber)
{
startAddress = theStartAddress;
endAddress = theEndAddress;
readCompletedAddress = theStartAddress;
mem = new byte[endAddress - startAddress];
fileNumber = theFileNumber;
}
public uint ReadAddress32(uint addressToRead)
{
if (addressToRead < startAddress || addressToRead > endAddress - 4)
{
return 0u;
}
byte[] array = new byte[4];
Buffer.BlockCopy(mem, index(addressToRead), array, 0, 4);
return ByteSwap.Swap(BitConverter.ToUInt32(array, 0));
}
private int index(uint addressToRead)
{
return (int)(addressToRead - startAddress);
}
public uint ReadAddress(uint addressToRead, int numBytes)
{
if (addressToRead < startAddress || addressToRead > endAddress - numBytes)
{
return 0u;
}
byte[] array = new byte[4];
Buffer.BlockCopy(mem, index(addressToRead), array, 0, numBytes);
switch (numBytes)
{
case 2:
return ByteSwap.Swap(BitConverter.ToUInt16(array, 0));
case 4:
return ByteSwap.Swap(BitConverter.ToUInt32(array, 0));
default:
return array[0];
}
}
public void WriteStreamToDisk()
{
string text = Environment.CurrentDirectory + "\\searchdumps\\";
if (!Directory.Exists(text))
{
Directory.CreateDirectory(text);
}
WriteStreamToDisk(text + "dump" + fileNumber.ToString() + ".dmp");
}
public void WriteStreamToDisk(string filepath)
{
FileStream fileStream = new FileStream(filepath, FileMode.Create);
fileStream.Write(mem, 0, (int)(endAddress - startAddress));
fileStream.Close();
fileStream.Dispose();
}
}