-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.dpr
213 lines (184 loc) · 6.09 KB
/
main.dpr
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
{
Autodesk License Manager Installer Automation
Autor: Linces Marques
Data : 14/11/2024
}
uses
ShellAPI, Windows, SysUtils, Classes, Registry, WinSock, Nb30;
const
NCBRESET = $32; // Constante para resetar o NCB - valor HEX que representa o comando de reset
NCBASTAT = $33; // Constante para obter o status do NCB
NRC_GOODRET = 0; // Retorno de sucesso do Netbios (geralmente 0)
function GetHostName: string;
var
Buffer: array [0 .. 255] of AnsiChar;
begin
if WinSock.GetHostName(@Buffer[0], SizeOf(Buffer)) = 0 then
Result := string(Buffer)
else
raise Exception.Create('Erro ao obter o nome do host');
end;
//function GetMACAddress: string;
//var
// NCB: TNCB;
// Adapter: TAdapterStatus;
// i: Integer;
// MAC: string;
//begin
// FillChar(NCB, SizeOf(NCB), 0);
// NCB.ncb_command := AnsiChar(NCBRESET);
// NCB.ncb_lana_num := AnsiChar(0);
//
// if Netbios(@NCB) <> NRC_GOODRET then
// raise Exception.Create('Erro ao resetar o NetBIOS');
//
// FillChar(NCB, SizeOf(NCB), 0);
// NCB.ncb_command := AnsiChar(NCBASTAT);
// NCB.ncb_lana_num := 0;
// StrPCopy(NCB.ncb_callname, '* '); // 16 espaços
//
// if Netbios(@NCB) <> NRC_GOODRET then
// raise Exception.Create('Erro ao obter o status do adaptador');
//
// Move(NCB.ncb_buffer, Adapter, SizeOf(Adapter));
//
// MAC := '';
// for i := 0 to 5 do
// MAC := MAC + IntToHex(Adapter.adapter_address[i], 2);
// Result := MAC;
//end;
function GetMACAddress: string;
var
NCB: TNCB;
Adapter: TAdapterStatus;
i: Integer;
MAC: string;
begin
// Inicializa a estrutura NCB
FillChar(NCB, SizeOf(NCB), 0);
NCB.ncb_command := AnsiChar(NCBRESET);
NCB.ncb_lana_num := AnsiChar(0);
// if Netbios(@NCB) <> NRC_GOODRET then
if Netbios(@NCB) <> AnsiChar(Byte(NRC_GOODRET)) then
raise Exception.Create('Erro ao resetar o NetBIOS');
FillChar(NCB, SizeOf(NCB), 0);
NCB.ncb_command := AnsiChar(NCBASTAT);
NCB.ncb_lana_num := AnsiChar(0);
StrPCopy(NCB.ncb_callname, '* ');
if Netbios(@NCB) <> AnsiChar(Byte(NRC_GOODRET)) then
raise Exception.Create('Erro ao obter o status do adaptador');
Move(NCB.ncb_buffer, Adapter, SizeOf(Adapter));
MAC := '';
for i := 0 to 5 do
MAC := MAC + IntToHex(Byte(Adapter.adapter_address[i]), 2); // Conversão explícita para Byte
Result := MAC;
end;
procedure InstallApplication(const AppPath: string);
begin
if ShellExecute(0, 'open', PChar(AppPath), nil, nil, SW_SHOWNORMAL) <= 32 then
raise Exception.Create('Erro ao instalar a aplicação');
end;
procedure InstallNLM(const NLMPath: string);
begin
if ShellExecute(0, 'open', PChar(NLMPath), nil, nil, SW_SHOWNORMAL) <= 32 then
raise Exception.Create('Erro ao instalar o Network License Manager');
end;
procedure StopProcesses;
begin
ShellExecute(0, 'open', 'taskkill', '/F /IM lmgrd.exe', nil, SW_HIDE);
ShellExecute(0, 'open', 'taskkill', '/F /IM adskflex.exe', nil, SW_HIDE);
end;
procedure ReplaceFile(const Source, Dest: string);
begin
if not CopyFile(PChar(Source), PChar(Dest), False) then
raise Exception.CreateFmt('Erro ao substituir arquivo: %s', [SysErrorMessage(GetLastError)]);
end;
procedure ConfigureLicFile(const LicFilePath, HostName, MACAddress: string);
var
LicFile: TStringList;
begin
LicFile := TStringList.Create;
try
LicFile.LoadFromFile(LicFilePath);
LicFile.Text := StringReplace(LicFile.Text, '<HOSTNAME>', HostName, [rfReplaceAll]);
LicFile.Text := StringReplace(LicFile.Text, '<MAC>', MACAddress, [rfReplaceAll]);
LicFile.SaveToFile(LicFilePath);
finally
LicFile.Free;
end;
end;
procedure CreateService;
var
reg: TRegistry;
begin
reg := TRegistry.Create(KEY_WRITE);
try
reg.RootKey := HKEY_LOCAL_MACHINE;
if reg.OpenKey('\SYSTEM\CurrentControlSet\Services\Autodesk', True) then
begin
reg.WriteString('DisplayName', 'Autodesk License Service');
reg.WriteString('ImagePath', '"C:\Autodesk\Network License Manager\lmgrd.exe" -c "C:\Autodesk\Network License Manager\lic.dat" -z');
reg.WriteString('Description', 'Serviço de licença da Autodesk');
reg.WriteInteger('Start', 2); // Define o serviço para iniciar automaticamente
reg.CloseKey;
end;
finally
reg.Free;
end;
end;
procedure StartLicenseServer;
begin
if ShellExecute(0, 'open', 'C:\Autodesk\Network License Manager\lmgrd.exe', '-c "C:\Autodesk\Network License Manager\lic.dat" -z', nil, SW_HIDE) <= 32 then
raise Exception.Create('Erro ao iniciar o servidor de licença');
end;
procedure InitializeLMTools(const LMToolsPath: string);
begin
if ShellExecute(0, 'open', PChar(LMToolsPath), nil, nil, SW_SHOWNORMAL) <= 32 then
raise Exception.Create('Erro ao inicializar o LMTools');
end;
procedure StartAutodeskApp(const AppPath: string);
begin
if ShellExecute(0, 'open', PChar(AppPath), nil, nil, SW_SHOWNORMAL) <= 32 then
raise Exception.Create('Erro ao iniciar o aplicativo Autodesk');
end;
procedure Main;
var
HostName, MACAddress: string;
begin
try
const
AppInstallerPath = 'C:\path_to_autodesk_installer.exe';
const
NLMInstallerPath = 'C:\path_to_crack\NLM.msi';
const
CrackedAdskflex = 'C:\path_to_crack\adskflex.exe';
const
DestAdskflex = 'C:\Autodesk\Network License Manager\adskflex.exe';
const
CrackedNetapi32 = 'C:\path_to_crack\netapi32.dll';
const
DestNetapi32 = 'C:\Program Files (x86)\Common Files\Autodesk Shared\AdskLicensing\Current\AdskLicensingAgent\netapi32.dll';
const
LicFilePath = 'C:\Autodesk\Network License Manager\lic.dat';
const
LMToolsPath = 'C:\Autodesk\Network License Manager\lmtools.exe';
InstallApplication(AppInstallerPath);
InstallNLM(NLMInstallerPath);
StopProcesses;
ReplaceFile(CrackedAdskflex, DestAdskflex);
ReplaceFile(CrackedNetapi32, DestNetapi32);
HostName := GetHostName;
MACAddress := GetMACAddress;
ConfigureLicFile(LicFilePath, HostName, MACAddress);
CreateService;
StartLicenseServer;
InitializeLMTools(LMToolsPath);
StartAutodeskApp(AppInstallerPath);
except
on E: Exception do
Writeln('Ocorreu um erro: ', E.Message);
end;
end;
begin
Main;
end.