Secure PHP

Hide PHP version in http header: (X-Powered-By)

Edit php.ini

expose_php = off
Advertisements

Filesize function for Delphi

Erroneous filesize function: (Files bigger than 2GB are shown 2GB)

function FileSize(const aFilename: String): Int64;
var
 info: TWin32FileAttributeData;
begin
 result := -1;

if NOT GetFileAttributesEx(PWideChar(aFileName), GetFileExInfoStandard, @info) then
 EXIT;

result := Int64(info.nFileSizeLow) or Int64(info.nFileSizeHigh shl 32);
end;

Better filesize function: (sr.FindData is Platform specific warning)

function FileSize(const aFilename: String): Int64;
var
 sr : TSearchRec;
begin
 if FindFirst(aFilename, faAnyFile, sr ) = 0 then
 begin
 result := Int64(sr.FindData.nFileSizeHigh) shl Int64(32) + Int64(sr.FindData.nFileSizeLow);
 end else
 begin
 result := -1;
 end;
 FindClose(sr);
end;

Best way:

function FileSize(const aFilename: String): Int64;
var
 sr : TSearchRec;
begin
 if FindFirst(aFilename, faAnyFile, sr ) = 0 then
 begin
 Result:=Sr.Size;
 end else
 begin
 result := -1;
 end;
 FindClose(sr);
end;

Localization of MessageDlg in Delphi

Built-in MessageDlg function shows texts such as Yes, No, Confirmation only in English.

function MyMessageDlg(CONST Msg: string; DlgTypt: TmsgDlgType; button: TMsgDlgButtons;
 Caption: ARRAY OF string; dlgcaption: string): Integer;
var
 aMsgdlg: TForm;
 i: Integer;
 Dlgbutton: Tbutton;
 Captionindex: Integer;
begin
 aMsgdlg := createMessageDialog(Msg, DlgTypt, button);
 aMsgdlg.Caption := dlgcaption;
//aMsgdlg.BiDiMode := bdRightToLeft;
 Captionindex := 0;
 for i := 0 to aMsgdlg.componentcount - 1 Do
 begin
 if (aMsgdlg.components[i] is Tbutton) then
 Begin
 Dlgbutton := Tbutton(aMsgdlg.components[i]);
 if Captionindex <= High(Caption) then
 Dlgbutton.Caption := Caption[Captionindex];
 inc(Captionindex);
 end;
 end;
 Result := aMsgdlg.Showmodal;
end;

Get ShellExecute Error in Delphi

ExecuteResult:=ShellExecute(Handle, 'open', PChar(filename), nil, nil, SW_HIDE);

case ExecuteResult of
 0 : ShowMessage('Error ' + IntToStr(ExecuteResult) + ': The operating system is out of memory or resources.');
 2 : ShowMessage('Error ' + IntToStr(ExecuteResult) + ': The specified file was not found.');
 3 : ShowMessage('Error ' + IntToStr(ExecuteResult) + ': The specified path was not found.');
 5 : ShowMessage('Error ' + IntToStr(ExecuteResult) + ': Windows 95 only: The operating system denied access to the specified file.');
 8 : ShowMessage('Error ' + IntToStr(ExecuteResult) + ': Windows 95 only: There was not enough memory to complete the operation.');
 10 : ShowMessage('Error ' + IntToStr(ExecuteResult) + ': Wrong Windows version.');
 11 : ShowMessage('Error ' + IntToStr(ExecuteResult) + ': The .EXE file is invalid (non-Win32 .EXE or error in .EXE image).');
 12 : ShowMessage('Error ' + IntToStr(ExecuteResult) + ': Application was designed for a different operating system.');
 13 : ShowMessage('Error ' + IntToStr(ExecuteResult) + ': Application was designed for MS-DOS 4.0.');
 15 : ShowMessage('Error ' + IntToStr(ExecuteResult) + ': Attempt to load a real-mode program.');
 16 : ShowMessage('Error ' + IntToStr(ExecuteResult) + ': Attempt to load a second instance of an application with non-readonly data segments.');
 19 : ShowMessage('Error ' + IntToStr(ExecuteResult) + ': Attempt to load a compressed application file.');
 20 : ShowMessage('Error ' + IntToStr(ExecuteResult) + ': Dynamic-link library (DLL) file failure.');
 26 : ShowMessage('Error ' + IntToStr(ExecuteResult) + ': A sharing violation occurred.');
 27 : ShowMessage('Error ' + IntToStr(ExecuteResult) + ': The filename association is incomplete or invalid.');
 28 : ShowMessage('Error ' + IntToStr(ExecuteResult) + ': The DDE transaction could not be completed because the request timed out.');
 29 : ShowMessage('Error ' + IntToStr(ExecuteResult) + ': The DDE transaction failed.');
 30 : ShowMessage('Error ' + IntToStr(ExecuteResult) + ': The DDE transaction could not be completed because other DDE transactions were being processed.');
 31 : ShowMessage('Error ' + IntToStr(ExecuteResult) + ': There is no application associated with the given filename extension.');
 32 : ShowMessage('Error ' + IntToStr(ExecuteResult) + ': Windows 95 only: The specified dynamic-link library was not found.');
 end;

Inno Setup Languages

Name: "english"; MessagesFile: "compiler:Default.isl"
Name: "armenian"; MessagesFile: "compiler:Languages\Armenian.islu"
Name: "brazilianportuguese"; MessagesFile: "compiler:Languages\BrazilianPortuguese.isl"
Name: "catalan"; MessagesFile: "compiler:Languages\Catalan.isl"
Name: "corsican"; MessagesFile: "compiler:Languages\Corsican.isl"
Name: "czech"; MessagesFile: "compiler:Languages\Czech.isl"
Name: "danish"; MessagesFile: "compiler:Languages\Danish.isl"
Name: "dutch"; MessagesFile: "compiler:Languages\Dutch.isl"
Name: "finnish"; MessagesFile: "compiler:Languages\Finnish.isl"
Name: "french"; MessagesFile: "compiler:Languages\French.isl"
Name: "german"; MessagesFile: "compiler:Languages\German.isl"
Name: "greek"; MessagesFile: "compiler:Languages\Greek.isl"
Name: "hebrew"; MessagesFile: "compiler:Languages\Hebrew.isl"
Name: "hungarian"; MessagesFile: "compiler:Languages\Hungarian.isl"
Name: "italian"; MessagesFile: "compiler:Languages\Italian.isl"
Name: "japanese"; MessagesFile: "compiler:Languages\Japanese.isl"
Name: "nepali"; MessagesFile: "compiler:Languages\Nepali.islu"
Name: "norwegian"; MessagesFile: "compiler:Languages\Norwegian.isl"
Name: "polish"; MessagesFile: "compiler:Languages\Polish.isl"
Name: "portuguese"; MessagesFile: "compiler:Languages\Portuguese.isl"
Name: "russian"; MessagesFile: "compiler:Languages\Russian.isl"
Name: "scottishgaelic"; MessagesFile: "compiler:Languages\ScottishGaelic.isl"
Name: "serbiancyrillic"; MessagesFile: "compiler:Languages\SerbianCyrillic.isl"
Name: "serbianlatin"; MessagesFile: "compiler:Languages\SerbianLatin.isl"
Name: "slovenian"; MessagesFile: "compiler:Languages\Slovenian.isl"
Name: "spanish"; MessagesFile: "compiler:Languages\Spanish.isl"
Name: "turkish"; MessagesFile: "compiler:Languages\Turkish.isl"
Name: "ukrainian"; MessagesFile: "compiler:Languages\Ukrainian.isl"

Get Windows Language in English

function GetLocaleInformation(Flag: Integer): string;
var
 pcLCA: array [0..20] of Char;
begin
 if GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, Flag, pcLCA, 19) <= 0 then
 pcLCA[0] := #0;
 Result := pcLCA;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
 ShowMessage(GetLocaleInformation(LOCALE_SENGLANGUAGE));
end;

Result are like:

French

German

Japanese

kSign and Inno Setup Configuration

In Inno Setup:

Tools->Configure Sign Tools…

Add New:

Name: mysigntool

Value: “C:\Program Files (x86)\kSign\signtool.exe” sign /f “C:\Program Files (x86)\kSign\MyCertificate.pfx” /t http://timestamp.verisign.com/scripts/timstamp.dll $f

OR

Value: “C:\Program Files (x86)\kSign\signtool.exe” sign /f “C:\Program Files (x86)\kSign\MyCertificate.pfx” /p MYPASSWORD /t http://timestamp.verisign.com/scripts/timstamp.dll $f

[Setup]
SignTool=mysigntool