-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHashLookupForm.cs
More file actions
196 lines (179 loc) · 7.59 KB
/
Copy pathHashLookupForm.cs
File metadata and controls
196 lines (179 loc) · 7.59 KB
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.Globalization;
using System.IO;
namespace LVLTool
{
public partial class HashLookupForm : Form
{
public HashLookupForm()
{
InitializeComponent();
}
//protected override void OnHandleCreated(EventArgs e)
//{
// //https://stackoverflow.com/questions/57124243/winforms-dark-title-bar-on-windows-10 (thank you:)
// if (DwmSetWindowAttribute(this.Handle, 19, new[] { 1 }, 4) != 0)
// DwmSetWindowAttribute(this.Handle, 20, new[] { 1 }, 4);
// base.OnHandleCreated(e);
//}
//[System.Runtime.InteropServices.DllImport("DwmApi")] //System.Runtime.InteropServices
//private static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, int[] attrValue, int attrSize);
private void mInputTextBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
FindHashes();
}
}
private void mLookupButton_Click(object sender, EventArgs e)
{
FindHashes();
}
Regex mHexNumber = new Regex("0x([0-9a-fA-F]+)");
Regex mDecNumber = new Regex("([0-9]+)");
private void FindHashes()
{
uint current = 0;
String key = "";
MatchCollection mc = mHexNumber.Matches(txt_input.Text);
StringBuilder sb = new StringBuilder();
NumberStyles style = NumberStyles.AllowHexSpecifier;
if (mc.Count < 1)
{
mc = mDecNumber.Matches(txt_input.Text);
style = NumberStyles.Integer;
}
foreach (Match m in mc)
{
current = UInt32.Parse(m.Groups[1].ToString(), style);
key = HashHelper.ReverseLookup(current);
if (key == null)
key = "<No Match>";
if( style == NumberStyles.AllowHexSpecifier)
sb.Append(String.Format("0x{0:x}:{1}\r\n", current, key));
else
sb.Append(String.Format("{0}= 0x{0:x}:{1}\r\n", current, key));
}
txt_output.Text = sb.ToString();
}
internal void SetStyle(Form prevForm)
{
this.BackColor = prevForm.BackColor;
this.ForeColor = prevForm.ForeColor;
TextBox tb = null;
Button b = null;
foreach (Control tmp in prevForm.Controls)
{
if (tb == null)
tb = tmp as TextBox;
if (b == null)
b = tmp as Button;
if (tb != null && b != null)
break;
}
if (tb != null)
{
this.txt_hashMe.BackColor = this.txt_input.BackColor =
this.txt_output.BackColor = tb.BackColor;
this.txt_hashMe.ForeColor = this.txt_input.ForeColor =
this.txt_output.ForeColor = tb.ForeColor;
}
if (b != null)
{
btn_addStrings.BackColor = btn_lookup.BackColor = b.BackColor;
grp_hashMe.ForeColor =
btn_addStrings.ForeColor = btn_lookup.ForeColor = b.ForeColor;
}
}
private void mAddStringsButton_Click(object sender, EventArgs e)
{
//public static string ShowMessage(string title, string message, Icon icon, bool editable, bool showCancelButton)
string result = MessageForm.ShowMessage("Paste in strings to add", "", SystemIcons.Question, true, true);
if (result != null)
{
result = result.Replace("\r\n", "\n");
//public static string Replace(string input, string pattern, string replacement);
result = Regex.Replace(result, "[ ]+\n", "\n");
List<string> stringsToAdd = new List<string>( result.Split(new char[] {'\n'}));
int numberAdded = HashHelper.AddStringsToDictionary(stringsToAdd);
txt_output.Text = string.Format("Added {0} previously unknown strings\n", numberAdded);
if(numberAdded > 0)
HashHelper.WriteDictionary();
}
}
private void mHashMeTextBox_TextChanged(object sender, EventArgs e)
{
uint result = HashHelper.HashString(txt_hashMe.Text);
lbl_hashMe.Text = string.Format("0x{0:x}", result);
}
private void unmungeHashFinderToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
List<String> newStrings = CollectHashes(dlg.FileName);
if (newStrings != null)
{
MessageForm.ShowMessage("Found these", String.Join("\n", newStrings.ToArray()), SystemIcons.Information, false, false);
}
}
dlg.Dispose();
}
private List<String> CollectHashes(string fileName)
{
// unmunge 1.2.2
// swbf-unmunge.exe -platform pc -string_dict <my_dict> -gen_string_dict <new_dict> -folder <lvl_folder>
string current_dict = "dictionary.txt";
string gen_dict = "new_dict.txt";
string unmunge_1_2_2 = "unmunge_versions\\swbf-unmunge-v1.2.2\\swbf-unmunge.exe";
string unmunge_1_2_1 = "unmunge_versions\\swbf-unmunge-v1.2.1\\swbf-unmunge.exe";
string unmungeProgram = "";
string args = "";
if (File.Exists(unmunge_1_2_2))
{
unmungeProgram = unmunge_1_2_2;
FileInfo info = new FileInfo(fileName);
args = String.Format(
"-platform pc -string_dict {0} -gen_string_dict {1} -folder {2} ",
current_dict, gen_dict, info.Directory );
}
else if (File.Exists(unmunge_1_2_1))
{
unmungeProgram = unmunge_1_2_1;
args = String.Format(
"-platform pc -file {0} -string_dict {1} -gen_string_dict {2} ",
fileName, current_dict, gen_dict);
}
else
{
MessageBox.Show(String.Format("Could not find proper Unmunge program\n\n'{0}'\nor\n'{1}'\n",
unmunge_1_2_2, unmunge_1_2_1));
return null;
}
string output = Program.RunCommand(unmungeProgram, args, true);
// now figure out what we don't have
string[] found_strings = File.ReadAllText(gen_dict).Replace("\r\n","\n").Split("\n".ToCharArray());
List<string> retVal = new List<string>(200);
uint hashId = 0;
foreach (string str in found_strings)
{
if (!str.StartsWith("0x"))
{
hashId = HashHelper.HashString(str);
if (HashHelper.GetStringFromHash(hashId) == null)
retVal.Add(str);
}
}
retVal.Sort();
return retVal;
}
}
}