-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMainWindow.xaml.cs
129 lines (104 loc) · 4.09 KB
/
MainWindow.xaml.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
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.AvalonEdit.Highlighting.Xshd;
using PS2Disassembler.ViewModel;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Text;
using System.Windows;
using System.Xml;
using Microsoft.Win32;
using PS2Disassembler.Core;
namespace PS2Disassembler
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private readonly MainViewVM _vm;
public MainWindow()
{
InitializeComponent();
var assembly = this.GetType().Assembly;
using (var stream = assembly.GetManifestResourceStream(assembly.GetName().Name + ".MIPSSyntax.xshd"))
{
using (var reader = new XmlTextReader(stream))
{
AssemblyEditor.SyntaxHighlighting = HighlightingLoader.Load(reader, HighlightingManager.Instance);
}
}
_vm = new MainViewVM();
this.DataContext = _vm;
}
protected override void OnInitialized(EventArgs e)
{
base.OnInitialized(e);
}
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
var openFileDialog = new OpenFileDialog();
var parsedBuffers = new List<byte[]>();
var disassembler = new Disassembler();
var outputBuilder = new StringBuilder();
var stopWatch = new Stopwatch();
if (openFileDialog.ShowDialog() == true)
{
stopWatch.Start();
var fileName = openFileDialog.FileName;
var fInfo = new FileInfo(openFileDialog.FileName);
using var fileStream = fInfo.OpenRead();
//bool success = GC.TryStartNoGCRegion(110000000);
var buffer = new byte[41 * 2048];
var parsedBuffer = new byte[32 * 2048];
do
{
var inputLength = 0;
var bufferDataLength = FillBuffer(fileStream, buffer);
if (bufferDataLength == 0)
break;
for (int i = 0, pI = 0; i < bufferDataLength; i += 41)
{
for (int j = i; j < i + 40; j += 10, pI += 8)
{
if (j + 8 < buffer.Length)
{
parsedBuffer[pI] = buffer[j + 7];
parsedBuffer[pI + 1] = buffer[j + 8];
parsedBuffer[pI + 2] = buffer[j + 5];
parsedBuffer[pI + 3] = buffer[j + 6];
parsedBuffer[pI + 4] = buffer[j + 2];
parsedBuffer[pI + 5] = buffer[j + 3];
parsedBuffer[pI + 6] = buffer[j];
parsedBuffer[pI + 7] = buffer[j + 1];
inputLength += 8;
}
}
}
disassembler.DisassembleByteArray(parsedBuffer, inputLength, ref outputBuilder);
//parsedBuffers.Add(parsedBuffer);
} while (true);
}
stopWatch.Stop();
_vm.StatusText = stopWatch.Elapsed.ToString();
//GC.EndNoGCRegion();
_vm.Output.BeginUpdate();
_vm.Output.Replace(0, _vm.Output.TextLength, outputBuilder.ToString());
_vm.Output.EndUpdate();
//_vm.DisassembleByteArrays(parsedBuffers);
}
private static int FillBuffer(Stream stream, byte[] buffer)
{
int read;
int totalRead = 0;
do
{
read = stream.Read(buffer, totalRead, buffer.Length - totalRead);
totalRead += read;
} while (read > 0 && totalRead < buffer.Length);
return totalRead;
}
}
}