-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
161 lines (158 loc) · 5.98 KB
/
Program.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
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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
namespace CMRev
{
internal static class Program
{
/// <summary>
/// Главная точка входа для приложения.
/// </summary>
[STAThread]
static void Main(string[] args)
{
try
{
if (args.Length == 0)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
else if (args.Length >= 1)
{
string configPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\CMRev.txt";
if (File.Exists(configPath))
{
string[] configData = File.ReadAllLines(configPath);
string IDA64path = configData[0];
string IDA32path = configData[1];
string dnSpy64path = configData[2];
string dnSpy32path = configData[3];
string DIEpath = configData[4];
bool DIErun = false;
if (configData[5] == "True")
{
DIErun = true;
}
string filePath = Environment.GetCommandLineArgs()[1];
byte[] fileBytes = File.ReadAllBytes(filePath);
string fileType = GetTypeFile(fileBytes);
filePath = $"\"{filePath}\"";
if (DIErun)
{
Process.Start(DIEpath, filePath);
}
switch (fileType)
{
case "ELF32":
Process.Start(IDA32path, filePath);
break;
case "ELF64":
Process.Start(IDA64path, filePath);
break;
case "PE64":
if (IsNET(Encoding.Default.GetString(fileBytes)))
{
Process.Start(dnSpy64path, filePath);
}
else
{
Process.Start(IDA64path, filePath);
}
break;
case "PE32":
if (IsNET(Encoding.Default.GetString(fileBytes)))
{
Process.Start(dnSpy32path, filePath);
}
else
{
Process.Start(IDA32path, filePath);
}
break;
default:
MessageBox.Show("Invalid file type", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
else
{
MessageBox.Show("Config file not found. Please run the program without arguments and configure", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
Process.GetCurrentProcess().Kill();
}
}
static private string GetTypeFile(byte[] data)
{
try
{
if (data[0] == 0x7F &&
data[1] == 0x45 &&
data[2] == 0x4C &&
data[3] == 0x46)
{
if (data[4] == 1)
{
return "ELF32";
}
else if (data[4] == 2)
{
return "ELF64";
}
}
if (data[0] == 'M' &&
data[1] == 'Z')
{
for (int i = 0; i < data.Length; i++)
{
if (data[i] == 'P' && data[i + 1] == 'E')
{
if (data[i + 4] == 'd')
{
return "PE64";
}
else if (data[i + 4] == 'L')
{
return "PE32";
}
}
}
}
return "invalid";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
Process.GetCurrentProcess().Kill();
return "null";
}
}
static private bool IsNET(string data)
{
try
{
int offsetPE = data.IndexOf("\0\0PE\0\0");
return Convert.ToChar(data[offsetPE + 238]) == 'H' && Convert.ToChar(data[offsetPE + 263]) == ' ';
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
Process.GetCurrentProcess().Kill();
return false;
}
}
}
}