Skip to content

Commit 07e7a52

Browse files
committed
stack trace translator
1 parent 02df1de commit 07e7a52

File tree

3 files changed

+194
-0
lines changed

3 files changed

+194
-0
lines changed

DeCraftLauncher/DeCraftLauncher.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
<Compile Include="UIControls\LauncherEntryPointFinding.xaml.cs">
129129
<DependentUpon>LauncherEntryPointFinding.xaml</DependentUpon>
130130
</Compile>
131+
<Compile Include="Utils\TinyV2Mapper.cs" />
131132
<Compile Include="WindowDeployMTP.xaml.cs">
132133
<DependentUpon>WindowDeployMTP.xaml</DependentUpon>
133134
</Compile>

DeCraftLauncher/Utils/TinyV2Mapper.cs

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
using System;
2+
using System.IO;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace DeCraftLauncher.Utils
9+
{
10+
public class TinyV2Mapper
11+
{
12+
public string nameFrom;
13+
public string nameTo;
14+
15+
public List<ClassMapping> remappedClasses = new List<ClassMapping>();
16+
17+
public class Mappable
18+
{
19+
public string from;
20+
public string to;
21+
}
22+
public class MethodParameterMapping
23+
{
24+
public int paramNumber;
25+
public string name;
26+
27+
public void Parse(string a)
28+
{
29+
string[] tabSplits = a.Split('\t');
30+
this.paramNumber = int.Parse(tabSplits[3]);
31+
this.name = tabSplits[5];
32+
}
33+
}
34+
public class MethodMapping : Mappable
35+
{
36+
public string descriptor;
37+
public List<MethodParameterMapping> methodParams = new List<MethodParameterMapping>();
38+
39+
public void Parse(string a)
40+
{
41+
string[] tabSplits = a.Split('\t');
42+
this.descriptor = tabSplits[2];
43+
this.from = tabSplits[3];
44+
this.to = tabSplits[4];
45+
}
46+
}
47+
public class FieldMapping : Mappable
48+
{
49+
public string type;
50+
51+
public void Parse(string a)
52+
{
53+
string[] tabSplits = a.Split('\t');
54+
this.type = tabSplits[2];
55+
this.from = tabSplits[3];
56+
this.to = tabSplits[4];
57+
}
58+
}
59+
public class ClassMapping : Mappable
60+
{
61+
public List<MethodMapping> remappedMethods = new List<MethodMapping>();
62+
public List<FieldMapping> remappedFields = new List<FieldMapping>();
63+
64+
public void Parse(string a)
65+
{
66+
string[] tabSplits = a.Split('\t');
67+
this.from = tabSplits[1];
68+
this.to = tabSplits[2];
69+
}
70+
}
71+
72+
public static TinyV2Mapper FromMappingsFile(string file)
73+
{
74+
TinyV2Mapper mapper = new TinyV2Mapper();
75+
76+
FileStream inFile = File.OpenRead(file);
77+
StreamReader fileReader = new StreamReader(inFile);
78+
string nLine = null;
79+
try
80+
{
81+
while ((nLine = fileReader.ReadLine()) != null)
82+
{
83+
if (nLine.StartsWith("tiny\t"))
84+
{
85+
string[] tabSplit = nLine.Split('\t');
86+
mapper.nameFrom = tabSplit[3];
87+
mapper.nameTo = tabSplit[4];
88+
}
89+
else if (nLine.StartsWith("c\t"))
90+
{
91+
ClassMapping nClass = new ClassMapping();
92+
nClass.Parse(nLine);
93+
mapper.remappedClasses.Add(nClass);
94+
}
95+
else if (nLine.StartsWith("\tm"))
96+
{
97+
MethodMapping nMethod = new MethodMapping();
98+
nMethod.Parse(nLine);
99+
mapper.remappedClasses.Last().remappedMethods.Add(nMethod);
100+
}
101+
else if (nLine.StartsWith("\tf"))
102+
{
103+
FieldMapping nField = new FieldMapping();
104+
nField.Parse(nLine);
105+
mapper.remappedClasses.Last().remappedFields.Add(nField);
106+
}
107+
else if (nLine.StartsWith("\t\tp"))
108+
{
109+
MethodParameterMapping nParam = new MethodParameterMapping();
110+
nParam.Parse(nLine);
111+
mapper.remappedClasses.Last().remappedMethods.Last().methodParams.Add(nParam);
112+
}
113+
}
114+
} catch (Exception ex)
115+
{
116+
Console.WriteLine(ex.Message);
117+
} finally
118+
{
119+
fileReader.Close();
120+
}
121+
122+
return mapper;
123+
}
124+
}
125+
}

DeCraftLauncher/WindowProcessLog.xaml.cs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Windows.Controls;
1313
using System.Windows.Data;
1414
using System.Windows.Documents;
15+
using System.Windows.Forms;
1516
using System.Windows.Input;
1617
using System.Windows.Media;
1718
using System.Windows.Media.Imaging;
@@ -233,5 +234,72 @@ private void proc_kill_Click(object sender, RoutedEventArgs e)
233234
}
234235
proc_kill.Visibility = Visibility.Hidden;
235236
}
237+
238+
public string ProcessLogTranslateString(string a, TinyV2Mapper tinyV2Mapper)
239+
{
240+
if (a.StartsWith("\tat "))
241+
{
242+
string classPathString = a.Substring(4).Split('(')[0];
243+
int l = classPathString.LastIndexOf('.');
244+
string classPath = classPathString.Substring(0, l);
245+
string methodName = classPathString.Substring(l+1);
246+
247+
var possibleClassPaths = (from x in tinyV2Mapper.remappedClasses
248+
where x.@from == classPath.Replace('.', '/')
249+
select x);
250+
if (!possibleClassPaths.Any())
251+
{
252+
possibleClassPaths = (from x in tinyV2Mapper.remappedClasses
253+
where x.to == classPath.Replace('.', '/')
254+
select x);
255+
}
256+
if (possibleClassPaths.Any())
257+
{
258+
TinyV2Mapper.ClassMapping fClassPath = possibleClassPaths.First();
259+
classPath = fClassPath.to.Replace('/', '.');
260+
try
261+
{
262+
var possibleMethodNames = (from x in fClassPath.remappedMethods
263+
where x.@from == methodName
264+
select x.to);
265+
if (possibleMethodNames.Count() == 1)
266+
{
267+
methodName = possibleMethodNames.First();
268+
}
269+
else if (possibleMethodNames.Count() > 1)
270+
{
271+
methodName = $"<multiple choices: {String.Join(",", possibleMethodNames)}>";
272+
}
273+
} catch (InvalidOperationException)
274+
{
275+
}
276+
}
277+
278+
return $"\tat {classPath}.{methodName}{a.Substring(a.LastIndexOf('('))}";
279+
280+
} else
281+
{
282+
return a;
283+
}
284+
}
285+
286+
protected override void OnKeyDown(System.Windows.Input.KeyEventArgs e)
287+
{
288+
//todo: make this a visible option
289+
if (e.Key == Key.Pause)
290+
{
291+
OpenFileDialog tinyV2MapDialog = new OpenFileDialog();
292+
tinyV2MapDialog.Filter = "TinyV2 Files|*.tiny";
293+
if (tinyV2MapDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
294+
{
295+
TinyV2Mapper tinyV2Mapper = TinyV2Mapper.FromMappingsFile(tinyV2MapDialog.FileName);
296+
Console.WriteLine("Read " + tinyV2Mapper.remappedClasses.Count + " remapped classes");
297+
string currentLogText = logtext.Text;
298+
logtext.Text = String.Join("\n", (from x in currentLogText.Split('\n')
299+
select ProcessLogTranslateString(x, tinyV2Mapper)));
300+
}
301+
}
302+
base.OnKeyDown(e);
303+
}
236304
}
237305
}

0 commit comments

Comments
 (0)