( this article
) , FileName
.NET . , True, .NET, False, . 32-, 64- .
, Unicode Inno Setup. Inno Setup ANSI. ANSI , :
[Code]
function BufferToWord(const Buffer: string): Word;
begin
Result := Ord(Buffer[1]);
end;
function BufferToLongWord(const Buffer: string): LongWord;
begin
Result := (Ord(Buffer[2]) shl 16) + Ord(Buffer[1]);
end;
function ReadFromStream(Stream: TStream; Size: Integer): LongWord;
var
Buffer: string;
begin
SetLength(Buffer, Size div 2);
Stream.ReadBuffer(Buffer, Size);
case Size of
2: Result := BufferToWord(Buffer);
4: Result := BufferToLongWord(Buffer);
else
RaiseException('Unexpected byte size to be read.');
end;
end;
function IsDotNetAssembly(const FileName: string): Boolean;
var
FileStream: TFileStream;
PEOffset: LongWord;
MagicNumber: Word;
ComDescriptor: LongWord;
DataDirOffset: LongWord;
begin
Result := False;
FileStream := TFileStream.Create(FileName, fmOpenRead or fmShareDenyNone);
try
FileStream.Position := $3C;
PEOffset := ReadFromStream(FileStream, SizeOf(PEOffset));
FileStream.Position := PEOffset + $18;
MagicNumber := ReadFromStream(FileStream, SizeOf(MagicNumber));
case MagicNumber of
$010B: DataDirOffset := $60;
$020B: DataDirOffset := $70;
else
RaiseException('Invalid image format.');
end;
FileStream.Position := PEOffset + $18 + DataDirOffset + $70;
ComDescriptor := ReadFromStream(FileStream, SizeOf(ComDescriptor));
Result := ComDescriptor <> 0;
finally
FileStream.free;
end;
end;
ANSI Inno Setup, . , Inno Setup , char Unicode Inno Setup ANSI:
function BufferToWord(const Buffer: AnsiString): Word;
begin
Result := (Ord(Buffer[2]) shl 8) + Ord(Buffer[1]);
end;
function BufferToLongWord(const Buffer: AnsiString): LongWord;
begin
Result := (Ord(Buffer[4]) shl 24) + (Ord(Buffer[3]) shl 16) +
(Ord(Buffer[2]) shl 8) + Ord(Buffer[1]);
end;
function ReadFromStream(Stream: TStream; Size: Integer): LongWord;
var
Buffer: AnsiString;
begin
SetLength(Buffer, Size);
Stream.ReadBuffer(Buffer, Size);
case Size of
2: Result := BufferToWord(Buffer);
4: Result := BufferToLongWord(Buffer);
else
RaiseException('Unexpected byte size to be read.');
end;
end;
:
if IsDotNetAssembly('C:\Wherever\WhateverBinary.dll') then
MsgBox('The binary file is a .NET assembly!', mbInformation, MB_OK)
else
MsgBox('The binary file is not a .NET assembly!', mbInformation, MB_OK);