using System Windows Forms using System Data using System Drawing usin

  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
using System.Windows.Forms;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System;
using System.IO;
using System.Globalization;
using System.Threading;
using System.Collections;
using System.Collections.Generic;
class Pizda {
// Нужные утилиты
const string L2_ASM_PATH = "l2asm-disasm/l2asm.exe";
const string L2_DISASM_PATH = "l2asm-disasm/l2disasm.exe";
const string L2_ENCDEC = "l2encdec/l2encdec.exe";
const string L2_PROTOCOL = "413";
const string L2_DDF_FILE = "l2asm-disasm/DAT_defs/CT2_5en/systemmsg-e.ddf";
static bool L2_IS_ORIGINAL = false;
const string TEMP_PATH = "tmp/";
static string BASE_PATH = "";
public class DelaySpeed {
public string Name {get; set; }
public int Value {get; set; }
};
public static ArrayList delay_speeds = new ArrayList() {
new DelaySpeed() { Name = "Fast", Value = 0},
new DelaySpeed() { Name = "Slow", Value = 1},
new DelaySpeed() { Name = "Very slow", Value = 11}
};
public static void saveL2File(string file, string protocol, DataTable table) {
}
public static void parseL2File(string file, DataGridView table) {
string decoded_tmp_file = TEMP_PATH + "systemmsg_" + UnixTimeNow() + "_decoded.dat";
string cvs_tmp_file = TEMP_PATH + "systemmsg_" + UnixTimeNow() + "_cvs.dat";
Process p = null;
try {
// decrypt
p = exec(BASE_PATH + L2_ENCDEC, (L2_IS_ORIGINAL ? "-l " : "-d ") + EscapeCommandArg(file) + " " + EscapeCommandArg(decoded_tmp_file));
p.Start();
p.WaitForExit();
if (!File.Exists(decoded_tmp_file))
throw new Exception("File " + decoded_tmp_file + " not found! Can't decrypt!");
// disassemble to CVS
p = exec(BASE_PATH + L2_DISASM_PATH, "-q -f -d " + L2_DDF_FILE + " " + EscapeCommandArg(decoded_tmp_file) + " " + EscapeCommandArg(cvs_tmp_file));
p.Start();
p.WaitForExit();
if (!File.Exists(cvs_tmp_file))
throw new Exception("File " + cvs_tmp_file + " not found! Can't disassemble!");
StreamReader rd = new StreamReader(cvs_tmp_file);
table.Rows.Clear();
int i = 0;
while (!rd.EndOfStream) {
var splits = rd.ReadLine().Split('\t');
ushort a = Convert.ToUInt16(splits[7], 16);
ushort r = Convert.ToUInt16(splits[6], 16);
ushort g = Convert.ToUInt16(splits[5], 16);
ushort b = Convert.ToUInt16(splits[4], 16);
table.Rows.Add();
table.Rows[i].DefaultCellStyle.BackColor = Color.FromArgb(0xFF, 0, 0, 0);
table.Rows[i].DefaultCellStyle.ForeColor = Color.FromArgb(a, r, g, b);
table.Rows[i].Cells[0] = new DataGridViewTextBoxCell() { Value = Convert.ToInt32(splits[0]) };
var m = new DataGridViewTextBoxCell() { Value = splits[2] + "\r\nssss\r\nssssss\r\n" };
//m.DataGridViewCellStyle.WrapMode = DataGridViewTriState.True;\\, \t, \0, \r and \n.
table.Rows[i].Cells[1] = m;
table.Rows[i].Cells[2] = new DataGridViewTextBoxCell() { Value = splits[4] + splits[5] + splits[6] + splits[7] };
table.Rows[i].Cells[3] = new DataGridViewTextBoxCell() { Value = Convert.ToInt32(splits[10]) };
table.Rows[i].Cells[4] = new DataGridViewTextBoxCell() { Value = Convert.ToInt32(splits[12]) };
var c = new DataGridViewComboBoxCell();
int v = Convert.ToInt32(splits[13]);
foreach (DelaySpeed row in delay_speeds) {
c.Items.Add(row.Name);
if (row.Value == v) {
c.Value = row.Name;
}
}
table.Rows[i].Cells[5] = c;
table.Rows[i].Cells[6] = new DataGridViewCheckBoxCell() { Value = Convert.ToInt32(splits[14]) != 0 };
table.Rows[i].Cells[7] = new DataGridViewTextBoxCell() { Value = splits[15] };
++i;
}
rd.Close();
} catch (Exception e) {
Console.WriteLine(e);
}
File.Delete(cvs_tmp_file);
File.Delete(decoded_tmp_file);
}
public static void Main() {
BASE_PATH = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + "/";
Directory.SetCurrentDirectory(BASE_PATH);
// grid
DataGridView grid = new DataGridView();
grid.Columns.Add(new DataGridViewTextBoxColumn() {
HeaderText = "id",
MinimumWidth = 40
});
grid.Columns.Add(new DataGridViewTextBoxColumn() {
HeaderText = "message",
MinimumWidth = 50
});
grid.Columns.Add(new DataGridViewTextBoxColumn() {
HeaderText = "color",
MinimumWidth = 80
});
grid.Columns.Add(new DataGridViewTextBoxColumn() {
HeaderText = "position",
MinimumWidth = 10
});
grid.Columns.Add(new DataGridViewTextBoxColumn() {
HeaderText = "delay",
MinimumWidth = 10
});
var c = new DataGridViewComboBoxColumn() {
HeaderText = "delay_speed"
};
grid.Columns.Add(c);
grid.Columns.Add(new DataGridViewCheckBoxColumn() {
HeaderText = "border",
MinimumWidth = 10
});
grid.Columns.Add(new DataGridViewTextBoxColumn() {
HeaderText = "sub_msg",
MinimumWidth = 60
});
grid.AutoGenerateColumns = false;
parseL2File("H:/wine/drive_c/Program Files (x86)/averia.ws/system/systemmsg-ru.dat", grid);
grid.AllowUserToAddRows = false;
grid.AllowUserToDeleteRows = false;
//grid.AutoGenerateColumns = false;
grid.Width = 900;
grid.Height = 660;
grid.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
//grid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
//grid.DefaultView.AllowDelete();
//grid.ColumnHeadersBorderStyle = ProperColumnHeadersBorderStyle;
// form
Form form = new Form();
form.Controls.Add(grid);
form.Width = 1000;
form.Height = 700;
form.ShowDialog();
}
public static Process exec(string path, string args) {
return new Process {
StartInfo = new ProcessStartInfo {
FileName = path,
Arguments = args,
UseShellExecute = false,
// RedirectStandardOutput = true,
WorkingDirectory = BASE_PATH,
CreateNoWindow = true
}
};
}
public static long UnixTimeNow() {
var timeSpan = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0));
return (long)timeSpan.TotalSeconds;
}
private static string EscapeCommandArg(string arg) {
return "\"" + arg.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\"";
}
}