forked from obaby/winrar-keygen
-
Notifications
You must be signed in to change notification settings - Fork 1
/
_tmain.cpp
94 lines (84 loc) · 2.54 KB
/
_tmain.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
#ifdef _WIN32
#include <tchar.h>
#include <windows.h>
#ifdef __GNUC__
#define MINGW_HAS_SECURE_API
#include <sec_api/stdio_s.h>
#define _tprintf_s printf_s
#endif
#define HS "hs"
#else
#define PTSTR char*
#define _putts puts
#define _tprintf_s printf
#define TEXT(s) s
#define HS "s"
#endif
#include <stdio.h>
#include <locale.h>
#include "WinRarConfig.hpp"
#include "WinRarKeygen.hpp"
#include <system_error>
void Help() {
_putts(TEXT("Usage:"));
_putts(TEXT(" winrar-keygen.exe <your name> <license type>"));
_putts(TEXT(""));
_putts(TEXT("Example:"));
_putts(TEXT(""));
_putts(TEXT(" winrar-keygen.exe \"Rebecca Morrison\" \"Single PC usage license\""));
_putts(TEXT(" or:"));
_putts(TEXT(" winrar-keygen.exe \"Rebecca Morrison\" \"Single PC usage license\" > rarreg.key\n"));
}
void PrintRegisterInfo(const WinRarKeygen<WinRarConfig>::RegisterInfo& Info) {
_tprintf_s(TEXT("%" HS "\n"), "RAR registration data");
_tprintf_s(TEXT("%" HS "\n"), Info.UserName.c_str());
_tprintf_s(TEXT("%" HS "\n"), Info.LicenseType.c_str());
_tprintf_s(TEXT("UID=%" HS "\n"), Info.UID.c_str());
for (size_t i = 0; i < Info.HexData.length(); i += 54) {
_tprintf_s(TEXT("%.54" HS "\n"), Info.HexData.c_str() + i);
}
}
#ifdef _WIN32
std::string ToACP(PCWSTR lpszUnicodeString) {
int len;
len = WideCharToMultiByte(CP_ACP, 0, lpszUnicodeString, -1, NULL, 0, NULL, NULL);
if (len == 0) {
auto err = GetLastError();
throw std::system_error(err, std::system_category());
}
std::string Result(len, '\x00');
len = WideCharToMultiByte(CP_ACP, 0, lpszUnicodeString, -1, Result.data(), static_cast<int>(Result.length()), NULL, NULL);
if (len == 0) {
auto err = GetLastError();
throw std::system_error(err, std::system_category());
}
while (Result.back() == '\x00') {
Result.pop_back();
}
return Result;
}
#endif
#ifdef WIN32
int _tmain(int argc, PTSTR argv[]) {
#else
int main(int argc, PTSTR argv[]) {
#endif
setlocale(LC_ALL, "");
if (argc == 3) {
try {
PrintRegisterInfo(
#if defined(_UNICODE) || defined(UNICODE)
WinRarKeygen<WinRarConfig>::GenerateRegisterInfo(ToACP(argv[1]).c_str(), ToACP(argv[2]).c_str())
#else
WinRarKeygen<WinRarConfig>::GenerateRegisterInfo(argv[1], argv[2])
#endif
);
} catch (std::exception& e) {
_tprintf_s(TEXT("%" HS "\n"), e.what());
return -1;
}
} else {
Help();
}
return 0;
}