forked from forth32/huaweicalc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_cmd.cpp
216 lines (183 loc) · 4.45 KB
/
main_cmd.cpp
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#include "encrypt.h"
#include <ctype.h>
#ifndef _MSC_VER
#include <unistd.h>
#else
#include "vcgetopt.h"
#endif
#ifdef WIN32
#include <windows.h>
#include "w32res.h"
#endif
char imeibuf[17];
char codebuf[40];
void helptxt(char* exename) {
printf( "\n\n *** SIM unlock code calculator for HUAWEI ***\n\n\
%s [-f123] IMEI\n\n\
-r - reverse IMEI\n\
-f - generate flash-code\n\
-1 - generate code v1\n\
-2 - generate code v2\n\
-3 - generate code v201\n\n",exename);
}
#ifdef WIN32
BOOL CALLBACK HuaweiDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_INITDIALOG:
SetWindowPos(hwnd,
HWND_TOP,
300,
200,
0, 0, // Ignores size arguments.
SWP_NOSIZE);
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
case IDCANCEL:
EndDialog(hwnd, IDCANCEL);
break;
case IDB_CALC:
imeibuf[16] = '\0';
SetDlgItemTextA(hwnd, IDT_FLASHCODE, "");
SetDlgItemTextA(hwnd, IDT_V1CODE, "");
SetDlgItemTextA(hwnd, IDT_V2CODE, "");
SetDlgItemTextA(hwnd, IDT_V201CODE, "");
GetDlgItemTextA(hwnd, IDT_IMEI, imeibuf, 16);
if (strlen(imeibuf) != 15) {
MessageBox(hwnd, "Incorrect IMEI Length", "Error", MB_ICONEXCLAMATION);
return FALSE;
}
for(int i=0;i<15;i++) {
if (!isdigit (imeibuf[i])) {
MessageBox(hwnd, "Invalid IMEI", "Error", MB_ICONEXCLAMATION);
return FALSE;
}
}
encrypt_v1(imeibuf,codebuf,"e630upgrade");
SetDlgItemTextA(hwnd, IDT_FLASHCODE, codebuf);
encrypt_v1(imeibuf,codebuf,"hwe620datacard");
SetDlgItemTextA(hwnd, IDT_V1CODE, codebuf);
calc2(imeibuf,codebuf);
SetDlgItemTextA(hwnd, IDT_V2CODE, codebuf);
calc201(imeibuf,codebuf);
SetDlgItemTextA(hwnd, IDT_V201CODE, codebuf);
break;
case IDB_REVERSE:
{
char c;
GetDlgItemTextA(hwnd, IDT_IMEI, imeibuf, 16);
if (strlen(imeibuf) != 15) {
MessageBox(hwnd, "Incorrect IMEI Length", "Error", MB_ICONEXCLAMATION);
return FALSE;
}
for (int i=0;i<7;i++) {
c=imeibuf[i];
imeibuf[i]=imeibuf[14-i];
imeibuf[14-i]=c;
}
SetDlgItemTextA(hwnd, IDT_IMEI, imeibuf);
}
break;
}
break;
default:
return FALSE;
}
return TRUE;
}
#endif
int main(int argc, char* argv[]) {
char c;
int opt;
int ff=0; // флаг ключей команды
int rf=0; // флаг reverse
int i;
// Если аргументов нет - запускаем графическую морду
if (argc == 1) {
#ifndef WIN32
helptxt(argv[0]);
#else
FreeConsole();
DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_HUAWEICALC), GetDesktopWindow(), HuaweiDlgProc);
#endif
return 0;
}
// аргументы есть - работаем в консольном режиме
while ((opt = getopt(argc, argv, "rRfF123hH")) != -1) {
switch (opt) {
case 'h':
case 'H':
helptxt(argv[0]);
return 0;
case 'f':
case 'F':
ff=1;
break;
case '1':
ff=2;
break;
case '2':
ff=3;
break;
case '3':
ff=4;
break;
case 'r':
case 'R':
rf=1;
break;
}
}
if (optind >= argc) {
printf("\n No IMEI specified\n\n");
return 0;
}
strcpy(imeibuf,argv[optind]);
// Разворот imei, если надо
if (rf != 0)
for (i=0;i<7;i++) {
c=imeibuf[i];
imeibuf[i]=imeibuf[14-i];
imeibuf[14-i]=c;
}
if (strlen(imeibuf) != 15) {
printf("\n Incorrect IMEI Length\n");
return 0;
}
switch (ff) {
case 0: {
// режим без ключей - вывдим форматирванный результат
encrypt_v1(imeibuf,codebuf,"e630upgrade");
printf("\n Flash code = %s",codebuf);
encrypt_v1(imeibuf,codebuf,"hwe620datacard");
printf("\n Encrypt_v1 code = %s",codebuf);
calc2(imeibuf,codebuf);
printf("\n Encrypt_v2 code = %s",codebuf);
calc201(imeibuf,codebuf);
printf("\n Encrypt_v201 code = %s\n\n",codebuf);
return 0;
}
// режим с ключами - вывди только отдельные цифры
case 1: {
encrypt_v1(imeibuf,codebuf,"e630upgrade");
break;
}
case 2: {
encrypt_v1(imeibuf,codebuf,"hwe620datacard");
break;
}
case 3: {
calc2(imeibuf,codebuf);
break;
}
case 4: {
calc201(imeibuf,codebuf);
break;
}
}
printf("%s\n",codebuf);
}