AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi Gelöst: Vierten Zeitstempel ermitteln

Gelöst: Vierten Zeitstempel ermitteln

Ein Thema von Garfield · begonnen am 25. Mai 2008 · letzter Beitrag vom 1. Jun 2008
Antwort Antwort
Seite 1 von 2  1 2   
Benutzerbild von Garfield
Garfield

Registriert seit: 9. Jul 2004
Ort: Aken (Anhalt-Bitterfeld)
1.334 Beiträge
 
Delphi XE5 Professional
 
#1

Gelöst: Vierten Zeitstempel ermitteln

  Alt 25. Mai 2008, 20:26
Die Zeitstempel für Erstellung, letzte Änderung und letzten Zugriff kennt wohl jeder. Wie man diese ermittelt, ist mir auch klar. Unter NTFS gibt es noch einen vierten Zeitstempel - "Entry modified" bzw "MFT last modified" -, welcher die letzte Änderung des MFT Eintrags angibt.

Weiß jemand, wie man diesen ermitteln kann?

http://www.forensicswiki.org/index.php?title=NTFS
http://www.forensicswiki.org/wiki/Timestomp


[edit=Matze]Auf Wunsch des Autors ein "Gelöst" in den Titel eingefügt. MfG, Matze[/edit]
Gruss Garfield
Ubuntu 22.04: Laz2.2.2/FPC3.2.2 - VirtBox6.1+W10: D7PE, DXE5Prof
  Mit Zitat antworten Zitat
Benutzerbild von Garfield
Garfield

Registriert seit: 9. Jul 2004
Ort: Aken (Anhalt-Bitterfeld)
1.334 Beiträge
 
Delphi XE5 Professional
 
#2

Re: Vierten Zeitstempel ermitteln

  Alt 26. Mai 2008, 08:32
Hab gerade das gefunden, aber noch nicht weiter angesehen.
Gruss Garfield
Ubuntu 22.04: Laz2.2.2/FPC3.2.2 - VirtBox6.1+W10: D7PE, DXE5Prof
  Mit Zitat antworten Zitat
Benutzerbild von Garfield
Garfield

Registriert seit: 9. Jul 2004
Ort: Aken (Anhalt-Bitterfeld)
1.334 Beiträge
 
Delphi XE5 Professional
 
#3

Re: Vierten Zeitstempel ermitteln

  Alt 26. Mai 2008, 19:46
Code:
typedef struct _FILE_BASIC_INFORMATION {

LARGE_INTEGER CreationTime;
LARGE_INTEGER LastAccessTime;
LARGE_INTEGER LastWriteTime;
LARGE_INTEGER ChangeTime;
ULONG FileAttributes;

} FILE_BASIC_INFORMATION, *PFILE_BASIC_INFORMATION;
Code:
typedef struct _FILE_BOTH_DIR_INFORMATION {

ULONG NextEntryOffset;
ULONG FileIndex;
LARGE_INTEGER CreationTime;
LARGE_INTEGER LastAccessTime;
LARGE_INTEGER LastWriteTime;
LARGE_INTEGER ChangeTime;
LARGE_INTEGER EndOfFile;
LARGE_INTEGER AllocationSize;
ULONG FileAttributes;
ULONG FileNameLength;
ULONG EaSize;
BYTE ShortNameLength;
WCHAR ShortName[12];
WCHAR FileName[1];

} FILE_BOTH_DIR_INFORMATION, *PFILE_BOTH_DIR_INFORMATION;
Code:
NtQueryInformationFile(

IN HANDLE FileHandle,
OUT PIO_STATUS_BLOCK IoStatusBlock,
OUT PVOID FileInformation,
IN ULONG Length,
IN FILE_INFORMATION_CLASS FileInformationClass );
http://undocumented.ntinternals.net/

[edit=SirThornberry]quote-tags zu c-tags geändert - Bitte künftig die entsprechenden Tags verwenden - Mfg, SirThornberry[/edit]
Gruss Garfield
Ubuntu 22.04: Laz2.2.2/FPC3.2.2 - VirtBox6.1+W10: D7PE, DXE5Prof
  Mit Zitat antworten Zitat
Benutzerbild von Garfield
Garfield

Registriert seit: 9. Jul 2004
Ort: Aken (Anhalt-Bitterfeld)
1.334 Beiträge
 
Delphi XE5 Professional
 
#4

Re: Vierten Zeitstempel ermitteln

  Alt 28. Mai 2008, 22:02
Nun bin ich soweit:
Delphi-Quellcode:
function NtQueryAttributesFile(ObjectAttributes: POBJECT_ATTRIBUTES;
                               FileInformation: PFILE_BASIC_INFORMATION): NTSTATUS;
                               stdcall; external ntdll name 'NtQueryAttributesFile';

function NT_SUCCESS(Status: NTSTATUS): WordBool;
begin
  Result := Status >= 0;
end;

procedure InitObjectAttributes(var p: _OBJECT_ATTRIBUTES; n: PUNICODE_STRING; a: ULONG; r: THandle; s: POINTER);
begin
  p.Length := SizeOf(OBJECT_ATTRIBUTES);
  p.RootDirectory := r;
  p.Attributes := a;
  p.ObjectName := n;
  p.SecurityDescriptor := s;
  p.SecurityQualityOfService := nil;
end;

function GetNTTime(fn: String; var FILE_BASIC_INFORMATION): Boolean;
var
  Status : NTSTATUS;
  ObjName : UNICODE_STRING;
  ObjectAttributes : OBJECT_ATTRIBUTES;
  FileInformation : _FILE_BASIC_INFORMATION;
  Buffer : array of WideChar;
begin
  Result := False;

  try
    SetLength(Buffer, Length(fn));

    FillChar(ObjectAttributes, SizeOf(OBJECT_ATTRIBUTES), 0);
    FillChar(FileInformation, SizeOf(_FILE_BASIC_INFORMATION), 0);

    MultiByteToWideChar(CP_UTF8, 0, @fn[1], Length(fn), PWideChar(Buffer), Length(Buffer));
    ObjName.Buffer := @Buffer[0];
    ObjName.Length := Length(fn) * SizeOf(WideChar);

    InitObjectAttributes(ObjectAttributes, @ObjName, OBJ_CASE_INSENSITIVE, 0, nil);

    Status := NtQueryAttributesFile(@ObjectAttributes, @FileInformation);

    Result := NT_SUCCESS(Status);
  finally
    //
  end;
end;
Es gibt keine Fehlermeldungen der Status ist dennoch FALSE. Ich suche seit Stunden und finde im Prinzip immer nur die gleichen Typdeklarationen aber keine Beispiele, die mich weiterbringen. Vielleicht hat hier jemand eine Idee, was falsch sein könnte oder was fehlt.
Angehängte Dateien
Dateityp: 7z filetime_796.7z (4,0 KB, 6x aufgerufen)
Gruss Garfield
Ubuntu 22.04: Laz2.2.2/FPC3.2.2 - VirtBox6.1+W10: D7PE, DXE5Prof
  Mit Zitat antworten Zitat
Benutzerbild von Garfield
Garfield

Registriert seit: 9. Jul 2004
Ort: Aken (Anhalt-Bitterfeld)
1.334 Beiträge
 
Delphi XE5 Professional
 
#5

Re: Vierten Zeitstempel ermitteln

  Alt 30. Mai 2008, 15:15
Delphi-Quellcode:
function GetNTTime(fn: String; var FileInformation: FILE_BASIC_INFORMATION): Boolean;
var
  dosfn : String;
  szNtDeviceName : array[0..MAX_PATH] of Char;
  Status : NTSTATUS;
  ObjName : UNICODE_STRING;
  ObjectAttributes : OBJECT_ATTRIBUTES;
  Buffer : array of WideChar;
begin
  Result := False;

  QueryDosDevice (PAnsiChar(ExtractFileDrive(fn)), szNtDeviceName, MAX_PATH);
  dosfn := Format('%s\%s', [szNtDeviceName, copy(fn, 4, Length(fn) - 3)]);

  try
    SetLength(Buffer, Length(dosfn));

    FillChar(ObjectAttributes, SizeOf(OBJECT_ATTRIBUTES), 0);
    FillChar(FileInformation, SizeOf(FILE_BASIC_INFORMATION), 0);

    MultiByteToWideChar(CP_UTF8, 0, @dosfn[1], Length(dosfn), PWideChar(Buffer), Length(Buffer));
    ObjName.Buffer := @Buffer[0];
    ObjName.Length := Length(dosfn) * SizeOf(WideChar);

    InitializeObjectAttributes(@ObjectAttributes, @ObjName, OBJ_CASE_INSENSITIVE, 0, nil);

    Status := NtQueryAttributesFile(@ObjectAttributes, @FileInformation);

    Result := NT_SUCCESS(Status);
  finally
    //
  end;
end;
Ich denke, der Fehler liegt bei ObjName. Es funktioniert weder mit dem Dateinamen noch dem Devicenamen. Also zum Beispiel:

D:\Garfield\Beispiel.txt
\Device\HarddiskVolume2\Garfield\Beispiel.txt

Wie müsste ein Objectname aussehen?
Gruss Garfield
Ubuntu 22.04: Laz2.2.2/FPC3.2.2 - VirtBox6.1+W10: D7PE, DXE5Prof
  Mit Zitat antworten Zitat
Benutzerbild von nicodex
nicodex

Registriert seit: 2. Jan 2008
Ort: Darmstadt
286 Beiträge
 
Delphi 2007 Professional
 
#6

Re: Vierten Zeitstempel ermitteln

  Alt 30. Mai 2008, 15:22
Du setzt beim TNtUnicodeString (UNICODE_STRING) nur die Länge der Daten, aber nicht die Maximale Länge.
  Mit Zitat antworten Zitat
Benutzerbild von Garfield
Garfield

Registriert seit: 9. Jul 2004
Ort: Aken (Anhalt-Bitterfeld)
1.334 Beiträge
 
Delphi XE5 Professional
 
#7

Re: Vierten Zeitstempel ermitteln

  Alt 30. Mai 2008, 15:45
Wenn ich die maximale Länge nicht setze, steht dort der Wert 17394.

Nachdem ich jetzt meine Function um
Delphi-Quellcode:
var
  ...
  doserr : DWORD;
  Error : PChar;
begin
  ...
    doserr := RtlNtStatusToDosError(Status);
    SetLastError (doserr);
    GetMem (Error, 255);
    FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER or
                   FORMAT_MESSAGE_FROM_SYSTEM,
                   nil,
                   GetLastError,
                   0,
                   @Error,
                   255,
                   nil);
    ShowMessage(Trim(Error));
  finally
  ...
ergänzt habe, bekomme ich als Fehler:
Zitat:
---------------------------
Filetime
---------------------------
Unzulässiger Zugriff auf einen Speicherbereich.
---------------------------
OK
---------------------------
Gruss Garfield
Ubuntu 22.04: Laz2.2.2/FPC3.2.2 - VirtBox6.1+W10: D7PE, DXE5Prof
  Mit Zitat antworten Zitat
Benutzerbild von nicodex
nicodex

Registriert seit: 2. Jan 2008
Ort: Darmstadt
286 Beiträge
 
Delphi 2007 Professional
 
#8

Re: Vierten Zeitstempel ermitteln

  Alt 30. Mai 2008, 15:52
Zitat von Garfield:
Wenn ich die maximale Länge nicht setze, steht dort der Wert 17394.
Öhm, ja, schön, aber dein Buffer ist nicht so groß.
  Mit Zitat antworten Zitat
Benutzerbild von nicodex
nicodex

Registriert seit: 2. Jan 2008
Ort: Darmstadt
286 Beiträge
 
Delphi 2007 Professional
 
#9

Re: Vierten Zeitstempel ermitteln

  Alt 30. Mai 2008, 16:39
Deine Definition von TFileBasicInformation ist falsch (es fehlt die implizite Ausrichtung, die Struktur ist nicht packed!)

Delphi-Quellcode:
{$ALIGN 8}
{$MINENUMSIZE 4}

const
  NtApiLib = 'ntdll.dll';

type
  TNtStatus = type LongInt;
  UIntPtr = Cardinal;

type
  PIoStatusBlock = ^TIoStatusBlock;
  TIoStatusBlock = record
    u: record
      case Integer of
        0: (
          Status: TNtStatus);
        1: (
          Pointer: Pointer);
    end;
    Information: UIntPtr;
  end;

type
  PFileInformationClass = ^TFileInformationClass;
  TFileInformationClass = (
    FileInvalidInformation,
    FileDirectoryInformation, // 1
    FileFullDirectoryInformation, // 2
    FileBothDirectoryInformation, // 3
    FileBasicInformation, // 4
    FileStandardInformation, // 5
    FileInternalInformation, // 6
    FileEaInformation, // 7
    FileAccessInformation, // 8
    FileNameInformation, // 9
    FileRenameInformation, // 10
    FileLinkInformation, // 11
    FileNamesInformation, // 12
    FileDispositionInformation, // 13
    FilePositionInformation, // 14
    FileFullEaInformation, // 15
    FileModeInformation, // 16
    FileAlignmentInformation, // 17
    FileAllInformation, // 18
    FileAllocationInformation, // 19
    FileEndOfFileInformation, // 20
    FileAlternateNameInformation, // 21
    FileStreamInformation, // 22
    FilePipeInformation, // 23
    FilePipeLocalInformation, // 24
    FilePipeRemoteInformation, // 25
    FileMailslotQueryInformation, // 26
    FileMailslotSetInformation, // 27
    FileCompressionInformation, // 28
    FileObjectIdInformation, // 29
    FileCompletionInformation, // 30
    FileMoveClusterInformation, // 31
    FileQuotaInformation, // 32
    FileReparsePointInformation, // 33
    FileNetworkOpenInformation, // 34
    FileAttributeTagInformation, // 35
    FileTrackingInformation, // 36
    FileIdBothDirectoryInformation, // 37
    FileIdFullDirectoryInformation, // 38
    FileValidDataLengthInformation, // 39
    FileShortNameInformation, // 40
    FileIoCompletionNotificationInformation, // 41
    FileIoStatusBlockRangeInformation, // 42
    FileIoPriorityHintInformation, // 43
    FileSfioReserveInformation, // 44
    FileSfioVolumeInformation, // 45
    FileHardLinkInformation, // 46
    FileProcessIdsUsingFileInformation, // 47
    FileNormalizedNameInformation, // 48
    FileNetworkPhysicalNameInformation, // 49
    FileIdGlobalTxDirectoryInformation, // 50
    FileMaximumInformation
  );

function NtQueryInformationFile(AFileHandle: THandle;
  out AIoStatusBlock: TIoStatusBlock; out AFileInformation; ALength: ULONG;
  AFileInformationClass: TFileInformationClass): TNtStatus; stdcall;
  external NtApiLib;

type
  PFileBasicInformation = ^TFileBasicInformation;
  TFileBasicInformation = record
    CreationTime : TLargeInteger; // 00
    LastAccessTime: TLargeInteger; // 08
    LastWriteTime : TLargeInteger; // 10
    ChangeTime : TLargeInteger; // 18
    FileAttributes: ULONG; // 20
  //Reserved : ULONG; // 24
  end; //(28)

procedure Foobar();
const
  FILE_READ_ATTRIBUTES = $0080;
var
  FileNameLength: DWORD;
  FileName: array [0..MAX_PATH - 1] of WideChar;
  FileHandle: THandle;
  IoStatusBlock: TIoStatusBlock;
  FileInformation: TFileBasicInformation;
  Status: TNtStatus;
begin
  FileNameLength := GetModuleFileNameW(0, FileName, Length(FileName));
  if (FileNameLength > 0) and (FileNameLength < DWORD(Length(FileName))) then
  begin
    FileHandle := CreateFileW(FileName, FILE_READ_ATTRIBUTES,
      FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
    if FileHandle <> INVALID_HANDLE_VALUE then
    try
      FillChar(IoStatusBlock, SizeOf(IoStatusBlock), 0);
      FillChar(FileInformation, SizeOf(FileInformation), 0);
      Status := NtQueryInformationFile(FileHandle, IoStatusBlock,
        FileInformation, SizeOf(FileInformation), FileBasicInformation);
      if (Status >= 0) and (IoStatusBlock.u.Status >= 0) and
        (IoStatusBlock.Information = SizeOf(FileInformation)) then
        with FileInformation do
          ShowMessage(
            'CreationTime: $' + IntToHex(CreationTime, 16) + #13#10 +
            'LastAccessTime: $' + IntToHex(LastAccessTime, 16) + #13#10 +
            'LastWriteTime: $' + IntToHex(LastWriteTime, 16) + #13#10 +
            'ChangeTime: $' + IntToHex(ChangeTime, 16) + #13#10 +
            'FileAttributes: $' + IntToHex(FileAttributes, 8))
      else
        ShowMessage(
          'Status: $' + IntToHex(Status, 8) + #13#10 +
          'IoStatus: $' + IntToHex(IoStatusBlock.u.Status, 8) + #13#10 +
          'IoInformation: $' + IntToHex(IoStatusBlock.Information, 8));
    finally
      CloseHandle(FileHandle);
    end;
  end;
end;
  Mit Zitat antworten Zitat
Benutzerbild von Garfield
Garfield

Registriert seit: 9. Jul 2004
Ort: Aken (Anhalt-Bitterfeld)
1.334 Beiträge
 
Delphi XE5 Professional
 
#10

Re: Vierten Zeitstempel ermitteln

  Alt 30. Mai 2008, 17:44
Zitat von nicodex:
Öhm, ja, schön, aber dein Buffer ist nicht so groß.
Stimmt.

Delphi-Quellcode:
function GetNTTime(fn: String; var FileInformation: FILE_BASIC_INFORMATION): Boolean;
var
  dosfn : ANSI_STRING;
  szNtDeviceName : array[0..MAX_PATH] of Char;
  ObjName : UNICODE_STRING;
  ObjectAttributes : OBJECT_ATTRIBUTES;
  Buffer : array of WideChar;
  Status : NTSTATUS;
  DosErr : DWORD;
  Error : PChar;
begin
  Result := False;

  FillChar(dosfn, SizeOf(ANSI_STRING), 0);
  FillChar(ObjName, SizeOf(UNICODE_STRING), 0);
  FillChar(ObjectAttributes, SizeOf(OBJECT_ATTRIBUTES), 0);
  FillChar(FileInformation, SizeOf(FILE_BASIC_INFORMATION), 0);

  QueryDosDevice(PAnsiChar(ExtractFileDrive(fn)), szNtDeviceName, MAX_PATH);
  RtlInitAnsiString(@dosfn, PAnsiChar(Format('%s\%s', [szNtDeviceName, copy(fn, 4, Length(fn) - 3)])));
  RtlAnsiStringToUnicodeString(@ObjName, @dosfn, True);

  InitializeObjectAttributes(@ObjectAttributes, @ObjName, OBJ_CASE_INSENSITIVE, 0, nil);

  Status := NtQueryAttributesFile(@ObjectAttributes, @FileInformation);

  Result := NT_SUCCESS(Status);

  if not Result
  then begin
    doserr := RtlNtStatusToDosError(Status);
    SetLastError(DosErr);
    GetMem(Error, 255);
    FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER or FORMAT_MESSAGE_FROM_SYSTEM, nil, GetLastError, 0, @Error, 255, nil);
    ShowMessage(Trim(Error));
  end;
end;
Damit sehen die Buffergrößen schon besser aus. Der Fehler ist damit leider nicht behoben.

Zitat von nicodex:
Deine Definition von TFileBasicInformation ist falsch (es fehlt die implizite Ausrichtung, die Struktur ist nicht packed!
Die Deklarationen habe ich von dort:
http://www.koders.com/delphi/fid50A5...6A08E3B70.aspx
http://www.koders.com/delphi/fidFFCC...D78A4039C.aspx

Dein Code funktioniert, aber meinem ist die Deklaration egal.
Angehängte Dateien
Dateityp: 7z filetime_100.7z (5,5 KB, 8x aufgerufen)
Gruss Garfield
Ubuntu 22.04: Laz2.2.2/FPC3.2.2 - VirtBox6.1+W10: D7PE, DXE5Prof
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 2  1 2   

Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 23:01 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