Delphi - Byte 관련 Tip

Programming/Delphi 2013.03.05 17:05 Posted by 파란크리스마스

Delphi - Byte 관련 Tip

function BytesToHex(aSource: TBytes): string;
begin
  SetLength(Result, Length(aSource) * 2);
  if Length(aSource) > 0 then
    BinToHex(aSource[0], PChar(Result), Length(aSource));
end;

procedure TForm1.Button1Click(Sender: TObject);
const
  SetupLdrExeHeaderOffset = $01d204;
  A: Array[0..3] of Byte = ($EF, $BE, $AD, $DE);
var
  HInstance: THandle;
  filename: String;
  FileStream: TFileStream;
  ArrayBytesHeader, ArrayBytesHeaderStr : TBytes;
  HeaderStr : String;
begin
  // AbZipper1.FileName := 'C:\AAPlus4PC_server\ALZip861.exe';
  filename := 'C:\AAPlus4PC_server\ALZip861.exe';

  FileStream := TFileStream.Create(filename, fmOpenRead);
  try

    FileStream.Seek( SetupLdrExeHeaderOffset , soBeginning);

    SetLength( ArrayBytesHeader, 16 );
    FileStream.ReadBuffer(ArrayBytesHeader, 16);

    if (CompareMem(ArrayBytesHeader, @A, 4)) then begin
      SetLength(ArrayBytesHeaderStr, 12);
      CopyMemory( ArrayBytesHeaderStr, @ArrayBytesHeader[4], 12  );

      HeaderStr := TEncoding.ASCII.GetString(ArrayBytesHeaderStr);
      //Memo1.Lines.Add( BytesToHex(ArrayBytesHeader) );
      //Memo1.Lines.Add( BytesToHex(ArrayBytesHeaderStr) + '/' + HeaderStr );

      if HeaderStr='NullsoftInst' then begin
        Memo1.Lines.Add( 'ooooo' );
      end else begin
        Memo1.Lines.Add( 'xxxxx - 2' );
      end;

    end else begin
      Memo1.Lines.Add( 'xxxxx - 1' );
    end;
  finally
    SetLength(ArrayBytesHeader, 0);
    SetLength(ArrayBytesHeaderStr, 0);
    FileStream.Free;
  end;
end;
신고


 

티스토리 툴바