I am strictly talking about security. By not a valid license I don't mean an expired; a crafted one which is known to be not from the author.
As for code execution, it's not that easy. Of course if you are corrupting with (or you did not initialize your buffer, and it contains) the exact binary representation of a call to DeleteFile - it will work.
procedure TForm1.Button1Click(Sender: TObject);
Type
TProcedure = Procedure;
PProcedure = ^TProcedure;
Var
p: PProcedure;
buf: Pointer;
begin
GetMem(buf, 1024);
Try
p := buf;
p^;
Finally
FreeMem(buf);
End;
end;
Project Project1.exe raised exception class $C0000005 with message 'access violation at 0x00000000: read of address 0x00000000'. Execution denied.
Same, if you try to execute a differently allocated memory area:
procedure TForm1.Button2Click(Sender: TObject);
Type
TProcedure = Procedure;
PProcedure = ^TProcedure;
Var
p: PProcedure;
x: TObject;
begin
p := Addr(x);
p^;
end;
Project Project1.exe raised exception class $C0000005 with message 'access violation at 0x02f788b0: write of address 0x060904ec'. No luck.
Out-of-bounds?
procedure TForm1.Button3Click(Sender: TObject);
Type
TProcedure = Procedure;
PProcedure = ^TProcedure;
Var
p: PProcedure;
begin
p := Pointer($ABABABAB);
p^;
end;
Project Project1.exe raised exception class $C0000005 with message 'access violation at 0x005fd31b: read of address 0xabababab'.
The OS is attempting to take measures against this, and if it's possible (somewhat how iPhone / PS4 jailbreaks used to work until they patched their browsers) - you found an exploit.
With not invasive memory corruption you'll turn some output Chinese, or crash the application at a point. Do it carelessly, and you can face charges.