Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Library: Windows API / MS.NET Framework API (https://www.delphipraxis.net/20-library-windows-api-ms-net-framework-api/)
-   -   Delphi Geschützte Dateien (SFC) auflisten (https://www.delphipraxis.net/7787-geschuetzte-dateien-sfc-auflisten.html)

Assarbad 21. Aug 2003 13:45


Geschützte Dateien (SFC) auflisten
 
Hier ein kleines Programm um alle SFC-geschützten Dateien aufzulisten

Hier die Downloads:
http://assarbad.net/stuff/!export/getsfcfiles.ace
http://assarbad.net/stuff/!export/getsfcfiles.rar
http://assarbad.net/stuff/!export/getsfcfiles.zip

Da es Klagen gab, man wisse nicht, was SFC/WFP ist ... hier die Informationen zum Anklicken Bei Google suchenSFC WFP Windows 2000

... und ein kurzer Abriß :)
Winlogon.exe, also der Prozeß, der für die Verwaltung von Benutzeranmeldungen verantwortlich ist und von SMSS.exe (dem Sessionmanager) gestartet wird, lädt eine DLL SFC.DLL aus %SystemRoot%\System32\. Diese DLL implementiert verschiedene Schutz- und Prüfmechanismen um die Integrität der wichtigsten Systemdateien zu gewährleisten. Jeder hat es sicher schon einmal erlebt, daß er eine DLL oder andere Systemdatei aus dem System32-Verzeichnis gelöscht hat, und danach aufgefordert wurde sie wiederherzustellen. Das passiert, wenn die entsprechende Datei nicht als Sicherheitskopie in %SystemRoot%\System32\DllCache\ vorliegt. So wird man dann aufgefordert die Installations-CD einzulegen. SFC steht übrigens für System File Ceck(er). WFP für Windows File Protection. Beim Start von Windows wird also beim Start der GUI entsprechend diverser Einstellungen in der Registry ein Integritätscheck vorgenommen. Deshalb sind Änderungen, die man in der Rettungskonsole gemacht hat manchmal plötzlich weg ...

Mein kleines Proggy listet nun alle geschützten Dateien auf und sollte auch auf XP funktionieren.

Delphi-Quellcode:
(******************************************************************************
 ******************************************************************************
 ***                                                                        ***
 ***  Sample code for use of undocumented GetSfcFiles API from sfcfiles.dll ***
 ***   Version [1.00]                              {Last mod 2003-08-21}   ***
 ***                                                                        ***
 ******************************************************************************
 ******************************************************************************

                                 _\\|//_
                                (` * * ')
 ______________________________ooO_(_)_Ooo_____________________________________
 ******************************************************************************
 ******************************************************************************
 ***                                                                        ***
 ***                Copyright (c) 1995 - 2003 by -=Assarbad=-               ***
 ***                                                                        ***
 ***             ___                                                        ***
 ***            /   |                     ||              ||                ***
 ***           / _  |   ________ ___  ____||__    ___   __||                ***
 ***          / /_\ |  / __/ __//   |/  _/|   \  /   | /   |                ***
 ***         / ___  |__\\__\\  / /\ || |  | /\ \/ /\ |/ /\ | DOT NET       ***
 ***        /_/   \_/___/___/ /_____\|_|  |____/_____\\__/\|                ***
 ***       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~        ***
 ***              [[url]http://assarbad.net[/url] | [url]http://assarbad.org][/url]              ***
 ***                                                                        ***
 ***   Notes:                                                              ***
 ***   - my first name is Oliver, you may well use this in your e-mails    ***
 ***   - for questions and/or proposals drop me a mail or instant message  ***
 ***                                                                        ***
 ***~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~***
 ***              May the source be with you, stranger ... ;)              ***
 ***    Snizhok, eto ne tolko fruktovij kefir, snizhok, eto stil zhizn.    ***
 ***                     Vsem Privet iz Germanij                           ***
 ***                                                                        ***
 *** Greets from -=Assarbad=- fly to YOU =)                                ***
 *** Special greets fly 2 Nico, Casper, SA, Pizza, Navarion, Eugen, Zhenja, ***
 *** Xandros, Melkij, Strelok etc pp.                                      ***
 ***                                                                        ***
 *** Thanks to:                                                            ***
 *** W.A. Mozart, Vivaldi, Beethoven, Poeta Magica, Kurtzweyl, Manowar,    ***
 *** Blind Guardian, Weltenbrand, In Extremo, Wolfsheim, Carl Orff, Zemfira ***
 *** ... most of my work was done with their music in the background ;)    ***
 ***                                                                        ***
 ******************************************************************************
 ******************************************************************************

 LEGAL STUFF:
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 Copyright (c) 1995-2003, -=Assarbad=- ["copyright holder(s)"]
 All rights reserved.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are met:

 1. Redistributions of source code must retain the above copyright notice, this
    list of conditions and the following disclaimer.
 2. Redistributions in binary form must reproduce the above copyright notice,
    this list of conditions and the following disclaimer in the documentation
    and/or other materials provided with the distribution.
 3. The name(s) of the copyright holder(s) may not be used to endorse or
    promote products derived from this software without specific prior written
    permission.

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                             .oooO    Oooo.
 ____________________________(   )_____(   )___________________________________
                              \ (       ) /
                               \_)    (_/

 ******************************************************************************)

program GetSfcFiles_Sample;
{$APPTYPE CONSOLE}
uses
  Windows;


type
  TSfcList = record
    wcsFileNameInDllCache: PWideChar; // Name of the file in DllCache
    wcsFilePath: PWideChar; // Path of the protected file
    wcsWhatEverInfFile: PWideChar; // Name of some INF file ... unknown meaning
  end;
  TSfcListArray = array[0..0] of TSfcList;
  PSfcListArray = ^TSfcListArray;

function SfcGetFiles(
  var lpNamelist: PSfcListArray;
  var lpNumEntries: DWORD
  ): DWORD; stdcall; external 'sfcfiles.dll';
(* Call and then iterate through the array with wide strings NumEntries times. *)

var
  namelist:PSfcListArray;
  i, num:DWORD;
begin
{ This crappy example simply dumps all SFC protected files to the console }
  if SfcGetFiles(namelist, num)=ERROR_SUCCESS then
    for i:=0 to num-1 do
      Writeln(String(namelist^[i].wcsFilePath));
end.
[edit=Daniel B]Titel korrigiert. Mfg, Daniel B[/edit]
[edit=CalganX]Titel geändert, Klassizifierung korrigiert, Cache erneuert. Mfg, CalganX[/edit]

Luckie 21. Aug 2003 13:54

Re: Undokumentiert: SFC-geschützte Dateien auflisten (W2K+)
 
Was sind SFC geschützte Dateien? :shock:

Assarbad 21. Aug 2003 15:37

Re: Undokumentiert: SFC-geschützte Dateien auflisten (W2K+)
 
SFC sind Dateien, die wiederhergestellt werden sobald sie modifiziert wurden (und solange SFC angeschalten ist). Es ist dazu da um die Integrität von Systemdateien zu gewährleisten. Die Originale stecken in %SYSTEMROOT%\System32\DllCache\

[edit=Luckie]Sinnzusammenhang durch gelöschte Postings wieder hergestellt. Mfg, Luckie[/edit]

Assarbad 21. Aug 2003 21:14

Re: Undokumentiert: SFC - geschützte Dateien auflisten (W2K+
 
[...]
SFC/WFP ist eines der Hauptfeatures von Windows 2000. Es wurde vorher an die große Glocke gehangen ... und danach gab es diverse Rezepte WFP abzuschalten. Also kann ich zumindest normalerweise davon ausgehen, daß es Windows 2000 Benutzern bekannt ist ... dachte ich. Ich werde oben nochmal was einfügen ;)

[edit=Luckie]Sinnzusammenhang durch gelöschte Postings wiederhergestellt. Mfg, Luckie[/edit]

CalganX 1. Apr 2007 19:54

Re: Undokumentiert: SFC - geschützte Dateien auflisten (W2K+
 
Nachtrag von himitsu:

jetzt dokumentiert :angel:

MSDN-Library durchsuchenSfcGetNextProtectedFile > geschützte Dateien auflisten
MSDN-Library durchsuchenSfcIsFileProtected > prüfen ob eine Datei geschützt ist


Diese Funktionen sind mir zufällig über'n Weg gelaufen und vorm Posten hab'sch dann noch den Thread eines altbekannten DP-Users entdeckt. :shock:


hier mal die wichtigsten Funktionen aus der Sfc.dll.
Delphi-Quellcode:
Type PROTECTED_FILE_DATA = packed Record
    FileName: packed Array[0..MAX_PATH-1] of WideChar;
    FileNumber: LongWord;
  End;

Function SfcGetNextProtectedFile(RpcHandle: THandle; Var ProtFileData: PROTECTED_FILE_DATA): LongBool; StdCall;
  External 'Sfc.dll' name 'SfcGetNextProtectedFile';

Function SfcIsFileProtected(RpcHandle: THandle; ProtFileName: PWideChar): LongBool; StdCall;
  External 'Sfc.dll' name 'SfcIsFileProtected';



Var ProtFileData: PROTECTED_FILE_DATA;

Begin
  ProtFileData.FileNumber := 0;
  While SfcGetNextProtectedFile(0, ProtFileData) do
    Memo1.Lines.Add(IntToStr(ProtFileData.FileNumber) + ': ' + ProtFileData.FileName);
End;
Wer selber Dateien schützen, oder daran was ändern will, der kann sich ja in den unter MSDN-Library durchsuchenSfcGetNextProtectedFile weiterverlinkten Seiten zum Thema Installer umsehen...


Alle Zeitangaben in WEZ +1. Es ist jetzt 11:54 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz