Delphi Easily Encrypt And Compress Your System Information Data In Your Windows App With These Components

FireWind

Свой
Регистрация
2 Дек 2005
Сообщения
1,957
Реакции
1,199
Credits
4,009
Easily Encrypt And Compress Your System Information Data In Your Windows App With These Components
February 11, 2021 By Anbarasan

Do you need to collect system information which need to be encrypted and compressed to a file for later use in your Для просмотра ссылки Войди или Зарегистрируйся application. Для просмотра ссылки Войди или Зарегистрируйся System Information Management Suite helps to easily encrypt/decrypt the system information. In this blog post how to use the TMiTec_SystemInfo component’s TCodeStreamProcedure to Encrypt, Compress and save system information into a custom format file and load the same with the sample application.

Platforms: Windows.

Installation Steps:

You can easily install this Component Suite from GetIt Package Manager. The steps are as follows.
  1. Navigate In RAD Studio IDE->Tools->GetIt Package Manager->select Components in Categories->Components->Trail -MiTec system Information Component Suite 14.3 and click Install Button.
  2. Read the license and Click Agree All. An Information dialog saying ‘Requires a restart of RAD studio at the end of the process. Do you want to proceed? click yes and continue.
  3. It will download the plugin and installs it. Once installed Click Restart now.
How to run the Demo app:
  • Navigate to the System Information Management Suite trails setup, Demos folder which is installed during Get It installation e.g) C:UsersDocumentsEmbarcaderoStudio21.0CatalogRepositoryMiTeC-14.3DemosDelphi2
  • Open the SCPDemo project in RAD studio 10.4.1 compile and Run the application.
  • This Demo App shows how to access the system information like Machine, Memory, CPU, Graphics, OS, etc.
Components used in MSIC StreamCodeProcedure Demo App:
1613036462277.png
  • TMiTeC_SystemInfo: This component encapsulates most of MSICS components into one interface. Key properties are shown below. Using those properties we can easily get the respective component properties. e.g consider CPU property has its own properties such as CPU architecture, Brand, CPU count, etc. Using this simple component you can access the entire system information quickly. Alternatively, we can access these components individually.
  • TButton to open and save the system information to a file.
  • TListView, to populate the collected system information in a list view.
Implementation Details:
  • An instance is created SI of TMiTeC_SystemInfo. Using SI properties Machine, Memory, CPU, Graphics, OS, the respective values were added to the List view.
Код:
procedure TwndMain.FillList;
var
  c,i,idx: Integer;
begin
  List.Items.BeginUpdate;
  try
    List.Items.Clear;
    if SI.OS.DataAvailable and (SI.OS.OSName<>'') then begin
      with List.Items.Add do begin
        Caption:='Machine';
        if SI.Machine.BIOS.BIOSDataCount>0 then
          SubItems.Add(SI.Machine.BIOS.BIOSValue['SystemProductName'].Value)
        else
          SubItems.Add(SI.Machine.SMBIOS.SystemModel);
      end;
      with List.Items.Add do begin
        Caption:='CPU';
        SubItems.Add(Format('%d x %s - %d MHz',[SI.CPU.CPUPhysicalCount,SI.CPU.CPUName,SI.CPU.Frequency]));
      end;
      with List.Items.Add do begin
        Caption:='Memory';
        if SI.Machine.SMBIOS.MemoryDeviceCount>0 then begin
          c:=0;
          idx:=-1;
          for i:=0 to SI.Machine.SMBIOS.MemoryDeviceCount-1 do
            if SI.Machine.SMBIOS.MemoryDevice[i].Size>0 then begin
              Inc(c);
              if idx=-1 then
                idx:=i;
            end;
          SubItems.Add(Format('%d x %d MB %s',[c,
                                               SI.Machine.SMBIOS.MemoryDevice[idx].Size,
                                               MemoryDeviceTypes[SI.Machine.SMBIOS.MemoryDevice[idx].Device]]))
        end else
          SubItems.Add(Format('%d MB',[SI.Memory.PhysicalTotal shr 20]));
      end;
      for i:=0 to SI.Display.AdapterCount-1 do
        with List.Items.Add do begin
          Caption:='Graphics';
          if SI.Display.Adapter[i].Memory>0 then
            SubItems.Add(Format('%s - %d MB',[SI.Display.Adapter[i].Name,SI.Display.Adapter[i].Memory shr 20]))
          else
            SubItems.Add(SI.Display.Adapter[i].Name);
        end;
      with List.Items.Add do begin
        Caption:='OS';
        SubItems.Add(Format('%s %s',[SI.OS.OSName,SI.OS.OSEdition]));
      end;
    end else
      List.Items.Add.Caption:='No data available';
  finally
    List.Items.EndUpdate;
  end;
end;
  • Save the System information into a custom file format .cff by choosing the option Encrypt/Compress/Encrypt And Compress. The Stream is encrypted/Decrypted/Compressed/Decompressed using the following TCodeStreamProcedure type procedures. SaveToStorage is used to save the system information into the file.
Код:
procedure EncryptStream(InStream, OutStream: TStream);
begin
  CryptStream(InStream,OutStream,StringToBytes('password'),True,CALG_SHA1,CALG_RC4);
end;

procedure DecryptStream(InStream, OutStream: TStream);
begin
  CryptStream(InStream,OutStream,StringToBytes('password'),False,CALG_SHA1,CALG_RC4);
end;

procedure CompressStream(InStream, OutStream: TStream);
{$IF (CompilerVersion >= 21.0) or Defined(FPC)}
begin
  InStream.Position:=0;
  ZCompressStream(InStream, OutStream, zcMax);
{$ELSE}
var
  InpBuf, OutBuf: Pointer;
  InpBytes, OutBytes: Integer;
begin
  InpBuf:=nil;
  OutBuf:=nil;
  try
    GetMem(InpBuf,InStream.Size);
    InStream.Position:=0;
    InpBytes:=InStream.Read(InpBuf^,InStream.Size);
    CompressBuf(InpBuf, InpBytes,OutBuf,OutBytes);
    OutStream.Write(OutBuf^,OutBytes);
  finally
    if InpBuf<>nil then
      FreeMem(InpBuf);
    if OutBuf<>nil then
      FreeMem(OutBuf);
  end;
{$IFEND}
OutStream.Position:=0;
end;

procedure DecompressStream(InStream, OutStream: TStream);
{$IF (CompilerVersion >= 21.0) or Defined(FPC)}
begin
  InStream.Position:=0;
  ZDecompressStream(InStream, OutStream);
  OutStream.Position:=0;
{$ELSE}
var
  InpBuf, OutBuf: Pointer;
  OutBytes, Size: Integer;
begin
  InStream.Position:=0;
  InpBuf:=nil;
  OutBuf:=nil;
  Size:=InStream.Size-InStream.Position;
  if Size>0 then
    try
      GetMem(InpBuf,Size);
      InStream.Read(InpBuf^,Size);
      DecompressBuf(InpBuf,Size,0,OutBuf, OutBytes);
      OutStream.Write(OutBuf^,OutBytes);
    finally
      if InpBuf<>nil then
        FreeMem(InpBuf);
      if OutBuf<>nil then
        FreeMem(OutBuf);
    end;
  OutStream.Position:=0;
{$IFEND}
end;
  • Later it can be loaded from the file using LoadFromStorage procedure and populated using the load button. TMiTeC_SystemInfo also has events to Read/Write header to the custom file.
1613036550218.png
StreamCodeProcedure demo
Developers not required to spend many hours identifying low-level system APIs to collect system information and save securely to custom file format. Use this MiTeC component suite and get the job done quickly.

Head over and check out the full MiTec System Information Management Suite for Access System Information for Wndows in Delphi Applications