Page 1 of 1
Delphi XE2 x64 and TRY ... EXCEPT
Posted: Mon Oct 16, 2017 6:34 pm
by febob
If in a x64 application (Borland Delphi XE2) occurs exception in code in a block "try ... except", then instead of execution the code inside "except ... end" block shows message like "This code requires valid serial number to run. Program will be terminated." and application closes.
An error occurs in an non-encrypted part of the code, i.e. not inside code blocks of like "VMProtectBeginUltra ... VMProtectEnd;".
The serial do not loaded before. It is DEMO mode of application.
What to do? How to work with "try ... except ... end"?
---
Если в x64 приложении внутри блока try ... except происходит исключение, то вместо выполнения кода внутри блока except ... end, появляется сообщение вида "This code requires valid serial number to run. Program will be terminated." и приложение закрывается.
Ошибка происходит в незашищенном участке кода, т.е. не внутри блоков кода вида VMProtectBeginUltra ... VMProtectEnd;
Серийный номер не загружался перед этим. Это ДЕМО режим работы приложения.
Что делать? Как работать блоками "try ... except ... end"?
Re: Delphi XE2 x64 and TRY ... EXCEPT
Posted: Tue Oct 17, 2017 3:43 am
by Admin
У вас скорее всего проблема в другом:
Code: Select all
try
VMProtectBeginVirtualizationLockByKey('');
...
VMProtectEnd();
try
...
except
...
end
finally
...
end;
Обратите внимание, что блоки try/finally могут быть неявными (например когда компилятор уничтожает локальные String). Поэтому когда вы обрабатываете маркер, то туда же попадает и код между fynally/end, а после except/end управление попадает как раз на начало finally в результате чего показывается сообщение об отсутствии серийного номера.
Что делать? Как работать блоками "try ... except ... end"?
В данном случае уносить маркер в отдельную функцию.
Re: Delphi XE2 x64 and TRY ... EXCEPT
Posted: Wed Oct 18, 2017 7:52 am
by febob
Перефразирую вопрос.
Есть код вида:
Code: Select all
try
VMProtectBeginVirtualizationLockByKey('');
...
VMProtectEnd();
finally
...
end;
try
try
...
[код где происходит ошибка]
...
except
...
end;
finally
end;
В 32-х разрядном приложении, после наложении защиты VMProtect, все отрабатывает как и должно.
В х64 приложении, после наложении защиты VMProtect, после ошибки в коде появляется сообщение:
This code requires valid serial number to run.
Program will be terminated.
и приложение закрывается совсем.
Re: Delphi XE2 x64 and TRY ... EXCEPT
Posted: Wed Oct 18, 2017 11:31 am
by Admin
Перефразирую свой ответ - в код маркера попадает часть функции, которая выполняется после except/end (скорее всего это неявный finally, который вставляет компилятор):
Code: Select all
var S: String;
begin
try
// ваш код здесь и и вам не нужно вызывать деструктор S, потому что, компилятор делает это сам в собственном finally блоке
finally
S.Free();
end;
end;
Re: Delphi XE2 x64 and TRY ... EXCEPT
Posted: Wed Oct 18, 2017 1:54 pm
by febob
Вот пример:
Code: Select all
procedure TForm1.Button1Click(Sender: TObject);
var sList : TStringList;
begin
VMProtectBeginUltraLockByKey('Test.Protect');
VMProtectEnd;
try
sList[0] := 'Test string'; // тут будет AccessViolation
finally
ShowMessage('finally for s[0]');
end;
end;
Почему появляется сообщение "This code requires valid serial number to run. Program will be terminated." ?
Как сделать, чтобы было сообщение "finally for s[0]" ?
Re: Delphi XE2 x64 and TRY ... EXCEPT
Posted: Wed Oct 18, 2017 2:37 pm
by Admin
В дизассемблере весь код смотрели?
Re: Delphi XE2 x64 and TRY ... EXCEPT
Posted: Wed Oct 18, 2017 3:14 pm
by febob
Это примитивный тест. Весь код:
Code: Select all
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses VMProtectSDK;
procedure TForm1.Button1Click(Sender: TObject);
var sList : TStringList;
begin
VMProtectBeginUltraLockByKey('Test.Protect');
VMProtectEnd;
try
sList[0] := 'Test string';
finally
ShowMessage('finally for s[0]');
end;
end;
end.
И собственно проект:
Code: Select all
program Project1;
uses
Vcl.Forms,
Unit1 in 'Unit1.pas' {Form1},
VMProtectSDK in '..\..\..\Borland Studio Projects\Project\Common.VCL.VMProtect\VMProtectSDK.pas';
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
Зачем тут дизассемблер?
Re: Delphi XE2 x64 and TRY ... EXCEPT
Posted: Wed Oct 18, 2017 3:32 pm
by Admin
Зачем тут дизассемблер?
Затем что у вас FINALLY попал в маркер!
Re: Delphi XE2 x64 and TRY ... EXCEPT
Posted: Wed Oct 18, 2017 4:07 pm
by febob
Admin wrote:
Затем что у вас FINALLY попал в маркер!
Вот тут не понятно. Маркеры это же VMProtectBeginUltraLockByKey ... VMProtectEnd;
Или что понимается под маркерами? Где это описано?
Re: Delphi XE2 x64 and TRY ... EXCEPT
Posted: Sat Oct 21, 2017 6:46 am
by Admin
Присылайте простейший пример (оригинальный EXE+MAP+VMP файлы), на котором можно воспроизвести вашу проблему.
Re: Delphi XE2 x64 and TRY ... EXCEPT
Posted: Sat Oct 21, 2017 5:12 pm
by febob
Admin wrote:Присылайте простейший пример (оригинальный EXE+MAP+VMP файлы), на котором можно воспроизвести вашу проблему.
Мы вывели зашищенные блоки кода в отдельные процедуры и проблемы более нет.