Do you need to collect system information which needs to be encrypted and compressed to a file for later use in your Delphi application. MiTec’s 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.
- 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.
- 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.
- 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:
- 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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
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.
Developers are not required to spend many hours identifying low-level system APIs to collect system information and save it securely to custom file format. Use this MiTeC component suite and get the job done quickly.
With the use of a Windows IDE, you can easily encrypt and compress your system information data in your Windows apps with a component suite. Try your Free Trial here.
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition