-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
112 lines (100 loc) · 7.23 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
#define LOCK
#define AllowEmptyLock
using System;
using System.IO;
using System.Collections.Generic;
using System.Windows.Forms;
namespace OSM2SHP
{
static class Program
{
public static string[] exeargs = new string[0];
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
System.Windows.Forms.InputBox.pCancel_Text = "Îòìåíà";
if ((args != null) && (args.Length > 0))
{
if (args[1] == "genmid")
{
string Machine_ID;
string ccode = "OSM2SHPFastexConverter";
string HASH1 = Machine_ID = SYSID.GetSystemID(true, true, false, true, false);
string HASH2 = SYSID.Encrypt(HASH1, ccode);
SaveKeyFile(args[0], HASH2);
MessageBox.Show(String.Format("Machine {0} added", HASH1), "OSM2SHP");
return;
};
if (args[1] == "addmid")
{
string ccode = "OSM2SHPFastexConverter";
string HASH1 = args[2];
string HASH2 = SYSID.Encrypt(HASH1, ccode);
SaveKeyFile(args[0], HASH2);
MessageBox.Show(String.Format("Machine {0} added", HASH1), "OSM2SHP");
return;
};
};
#if LOCK
string MachineID = "";
bool mValid = true;
if (!validMachine(out MachineID)) mValid = false;
#endif
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MForm(exeargs = args, mValid, MachineID));
}
public static byte[] MACHINEID = new byte[] { 0x72, 0x65, 0x67, 0x62, 0x6b, 0x62, 0x64, 0x76, 0x66, 0x75, 0x66, 0x70, 0x62, 0x79, 0x74, 0x68, 0x74, 0x70, 0x62, 0x79, 0x6a, 0x64, 0x65, 0x2e, 0x70, 0x62, 0x79, 0x65, 0x3E, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x3C };
static bool validMachine(out string Machine_ID)
{
string ccode = "OSM2SHPFastexConverter";
string HASH1 = Machine_ID = SYSID.GetSystemID(true, true, false, true, false);
string HASH2 = SYSID.Encrypt(HASH1, ccode);
string HASH3 = "";
try
{
int sum = 0;
HASH3 = "";
int x = 0;
for (int i = 0; i < MACHINEID.Length; i++) if (MACHINEID[i] == 0) { x = i; break; };
#if AllowEmptyLock
for (int i = 30; i < MACHINEID.Length; i++) sum += MACHINEID[i];
if (sum == 120) return true; // 0x3C, 0x3C
#endif
HASH3 = System.Text.Encoding.ASCII.GetString(MACHINEID, 30, x - 30);
//return true;
}
catch { return false; };
string HASH4 = "";
try
{
HASH4 = SYSID.Decrypt(HASH3, ccode);
}
catch { };
return (HASH1 == HASH4);
}
private static byte[] PREFIX = new byte[] { 0x72, 0x65, 0x67, 0x62, 0x6b, 0x62, 0x64, 0x76, 0x66, 0x75, 0x66, 0x70, 0x62, 0x79, 0x74, 0x68, 0x74, 0x70, 0x62, 0x79, 0x6a, 0x64, 0x65, 0x2e, 0x70, 0x62, 0x79, 0x65 };
private static void SaveKeyFile(string fileName, string hash)
{
if (File.Exists(fileName)) File.Delete(fileName);
File.Copy(AppDomain.CurrentDomain.BaseDirectory + @"OSM2SHPFC.exe", fileName);
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite);
int i = 0;
int B = fs.ReadByte();
while (i < PREFIX.Length)
{
if (B != PREFIX[i++]) i = 0;
B = fs.ReadByte();
};
fs.Position++;
byte[] ba = System.Text.Encoding.ASCII.GetBytes(hash);
fs.Write(ba, 0, ba.Length);
ba = new byte[512 - ba.Length];
fs.Write(ba, 0, ba.Length);
fs.Close();
}
}
}