/*++ Copyright (c) 1998-1999 Microsoft Corporation Module Name: logdump.c Abstract: this file implements functrionality to read and dump the sr logs Author: Kanwaljit Marok (kmarok) 01-May-2000 Revision History: --*/ #include #include #include #include #include #include "logfmt.h" #include "srapi.h" struct _EVENT_STR_MAP { DWORD EventId; PCHAR pEventStr; } EventMap[ 13 ] = { {SrEventInvalid , "INVALID " }, {SrEventStreamChange, "FILE-MODIFY" }, {SrEventAclChange, "ACL-CHANGE " }, {SrEventAttribChange, "ATTR-CHANGE" }, {SrEventStreamOverwrite,"FILE-MODIFY" }, {SrEventFileDelete, "FILE-DELETE" }, {SrEventFileCreate, "FILE-CREATE" }, {SrEventFileRename, "FILE-RENAME" }, {SrEventDirectoryCreate,"DIR-CREATE " }, {SrEventDirectoryRename,"DIR-RENAME " }, {SrEventDirectoryDelete,"DIR-DELETE " }, {SrEventMountCreate, "MNT-CREATE " }, {SrEventMountDelete, "MNT-DELETE " } }; BYTE Buffer[4096]; PCHAR GetEventString( DWORD EventId ) { PCHAR pStr = NULL; static CHAR EventStringBuffer[8]; for( int i=0; iSubRecords); fprintf( stderr, "Header Size: %ld, Version: %ld, Tool Version: %ld\n%S\n", pLogHeader->Header.RecordSize, pLogHeader->LogVersion, SR_LOG_VERSION, (LPWSTR)(pLoc + sizeof(RECORD_HEADER)) ); if( pLogHeader->LogVersion != SR_LOG_VERSION || pLogHeader->MagicNum != SR_LOG_MAGIC_NUMBER ) { fprintf( stderr, "Invalid version or Corrupt log\n" ); CloseHandle(hFile); goto End; } dwSizeLow -= pLogHeader->Header.RecordSize; SetFilePointer (hFile, pLogHeader->Header.RecordSize, NULL, FILE_BEGIN); // // Start reading the log entries // while( dwSizeLow ) { PSR_LOG_ENTRY pLogEntry = (PSR_LOG_ENTRY)Buffer; ZeroMemory(pLogEntry, sizeof(Buffer)); // // Read the size of the entry // if ( !ReadFile( hFile, &pLogEntry->Header.RecordSize, sizeof(DWORD), &nRead, NULL ) ) { break; } cbSize = pLogEntry->Header.RecordSize; if (cbSize == 0 ) { // // Zero size indicates end of the log // break; } SetFilePointer( hFile, - (INT)sizeof(DWORD), NULL, FILE_CURRENT ); // // Read the rest of the entry // if ( !ReadFile( hFile, ((PBYTE)pLogEntry), cbSize, &nRead, NULL ) ) { break; } // // Check the magic number // if( pLogEntry->MagicNum != SR_LOG_MAGIC_NUMBER ) { fprintf(stderr, "Invalid Entry ( Magic num )\n"); break; } // // Read the entries in to the buffer // sprintf( szSerNo , "%05d" , dwEntries + 1); sprintf( szSize , "%04d" , pLogEntry->Header.RecordSize ); sprintf( szOperation, "%s" , GetEventString( pLogEntry->EntryType )); sprintf( szFlags , "%08x" , pLogEntry->EntryFlags ); sprintf( szSeqNo , "%010d" , pLogEntry->SequenceNum); sprintf( szAttr , "%08x" , pLogEntry->Attributes ); sprintf( szProcess , "%12.12s" , pLogEntry->ProcName ); // // get the first path // PBYTE pLoc = (PBYTE)&pLogEntry->SubRecords; sprintf( szPath1 , "%S" , pLoc + sizeof(RECORD_HEADER) ); if (pLogEntry->EntryFlags & ENTRYFLAGS_TEMPPATH) { pLoc += RECORD_SIZE(pLoc); sprintf( szTmpFile , "%S" , pLoc + sizeof(RECORD_HEADER) ); } else { sprintf( szTmpFile , "" ); } if (pLogEntry->EntryFlags & ENTRYFLAGS_SECONDPATH) { pLoc += RECORD_SIZE(pLoc); sprintf( szPath2 , "%S" , pLoc + sizeof(RECORD_HEADER) ); } else { sprintf( szPath2 , "" ); } if (pLogEntry->EntryFlags & ENTRYFLAGS_ACLINFO) { ULONG AclInfoSize; pLoc += RECORD_SIZE(pLoc); AclInfoSize = RECORD_SIZE(pLoc); sprintf( szAcl , "ACL(%04d)%" , AclInfoSize ); } else { sprintf( szAcl , "" ); } if (pLogEntry->EntryFlags & ENTRYFLAGS_DEBUGINFO) { bHaveDebugInfo = TRUE; pLoc += RECORD_SIZE(pLoc); sprintf( szProcess , "%12.12s", ((PSR_LOG_DEBUG_INFO)pLoc)->ProcessName ); sprintf( szProcessHandle,"0x%08X", ((PSR_LOG_DEBUG_INFO)pLoc)->ProcessId ); sprintf( szThreadHandle,"0x%08X", ((PSR_LOG_DEBUG_INFO)pLoc)->ThreadId ); } else { bHaveDebugInfo = FALSE; sprintf( szProcess , "" ); sprintf( szThreadHandle , "" ); sprintf( szProcessHandle , "" ); } if (pLogEntry->EntryFlags & ENTRYFLAGS_SHORTNAME) { pLoc += RECORD_SIZE(pLoc); sprintf( szShortName , "%S" , pLoc + sizeof(RECORD_HEADER) ); } else { sprintf( szShortName , "" ); } // // read the trailing record size // sprintf( szEndSize , "%04d", GET_END_SIZE(pLogEntry)); ProcessLogEntry( bPrintDebugInfo && bHaveDebugInfo, szSerNo, szSize, szEndSize, szSeqNo, szFlags, szProcess, szOperation, szAttr, szTmpFile, szPath1, szPath2, szAcl, szShortName, szProcessHandle, szThreadHandle); dwEntries++; dwSizeLow -= cbSize; cbSize = 0; } CloseHandle( hFile ); Status = TRUE; } else { fprintf( stderr, "Error opening LogFile %s\n", pszFileName ); } End: fprintf( stderr, "Number of entries read :%d\n", dwEntries ); if (szPath1 != NULL) LocalFree( szPath1 ); if (szPath2 != NULL) LocalFree( szPath2 ); return Status; } INT __cdecl main( int argc, char *argv[] ) { if( argc < 2 || argc > 3 ) { fprintf( stderr, "USAGE: %s [-d] \n\t -d : debug info\n", argv[0] ); } else { int i = 1; if ( argc == 3 && !strcmp( argv[i], "-d" ) ) { i++; ReadLogData(TRUE, argv[i] ); } else { ReadLogData(FALSE, argv[i] ); } } return 0; }