/*********************************************************************** * DosDateTimeToFileTime (KERNEL32.@) */ BOOL WINAPI DosDateTimeToFileTime( WORD fatdate, WORD fattime, LPFILETIME ft) { struct tm newtm; #ifndef HAVE_TIMEGM struct tm *gtm; time_t time1, time2; #endif newtm.tm_sec = (fattime & 0x1f) * 2; newtm.tm_min = (fattime >> 5) & 0x3f; newtm.tm_hour = (fattime >> 11); newtm.tm_mday = (fatdate & 0x1f); newtm.tm_mon = ((fatdate >> 5) & 0x0f) - 1; newtm.tm_year = (fatdate >> 9) + 80; newtm.tm_isdst = -1; #ifdef HAVE_TIMEGM RtlSecondsSince1970ToTime( timegm(&newtm), (LARGE_INTEGER *)ft ); #else time1 = mktime(&newtm); gtm = gmtime(&time1); time2 = mktime(gtm); RtlSecondsSince1970ToTime( 2*time1-time2, (LARGE_INTEGER *)ft ); #endif return TRUE; }
/* TODO: * - set file deletion time * - set original file location */ HRESULT TRASH_GetDetails(const char *trash_path, const char *name, WIN32_FIND_DATAW *data) { static int once; int trash_path_length = lstrlenA(trash_path); int name_length = lstrlenA(name); char *path = SHAlloc(trash_path_length+1+name_length+1); struct stat stats; int ret; if(!once++) FIXME("semi-stub\n"); if(!path) return E_OUTOFMEMORY; memcpy(path, trash_path, trash_path_length); path[trash_path_length] = '/'; memcpy(path+trash_path_length+1, name, name_length+1); ret = lstat(path, &stats); heap_free(path); if(ret == -1) return S_FALSE; memset(data, 0, sizeof(*data)); data->nFileSizeHigh = stats.st_size>>32; data->nFileSizeLow = stats.st_size & 0xffffffff; RtlSecondsSince1970ToTime(stats.st_mtime, (LARGE_INTEGER*)&data->ftLastWriteTime); if(!MultiByteToWideChar(CP_UNIXCP, 0, name, -1, data->cFileName, MAX_PATH)) return S_FALSE; return S_OK; }
VOID ShowLatestVersionDialog( _In_ PPH_UPDATER_CONTEXT Context ) { TASKDIALOGCONFIG config; LARGE_INTEGER time; SYSTEMTIME systemTime = { 0 }; PIMAGE_DOS_HEADER imageDosHeader; PIMAGE_NT_HEADERS imageNtHeader; memset(&config, 0, sizeof(TASKDIALOGCONFIG)); config.cbSize = sizeof(TASKDIALOGCONFIG); config.dwFlags = TDF_USE_HICON_MAIN | TDF_ALLOW_DIALOG_CANCELLATION | TDF_CAN_BE_MINIMIZED | TDF_ENABLE_HYPERLINKS | TDF_EXPAND_FOOTER_AREA; config.dwCommonButtons = TDCBF_CLOSE_BUTTON; config.hMainIcon = Context->IconLargeHandle; config.cxWidth = 200; config.pfCallback = FinalTaskDialogCallbackProc; config.lpCallbackData = (LONG_PTR)Context; // HACK imageDosHeader = (PIMAGE_DOS_HEADER)NtCurrentPeb()->ImageBaseAddress; imageNtHeader = (PIMAGE_NT_HEADERS)PTR_ADD_OFFSET(imageDosHeader, imageDosHeader->e_lfanew); RtlSecondsSince1970ToTime(imageNtHeader->FileHeader.TimeDateStamp, &time); PhLargeIntegerToLocalSystemTime(&systemTime, &time); config.pszWindowTitle = L"Process Hacker - Updater"; config.pszMainInstruction = L"You're running the latest version."; config.pszContent = PhaFormatString( L"Version: v%s\r\nCompiled: %s\r\n\r\n<A HREF=\"changelog.txt\">View Changelog</A>", PhGetStringOrEmpty(Context->CurrentVersionString), PhaFormatDateTime(&systemTime)->Buffer )->Buffer; TaskDialogNavigatePage(Context->DialogHandle, &config); }
static VOID PrintDateTime(DWORD dwSeconds) { LARGE_INTEGER Time; FILETIME FileTime; SYSTEMTIME SystemTime; WCHAR DateBuffer[80]; WCHAR TimeBuffer[80]; RtlSecondsSince1970ToTime(dwSeconds, &Time); FileTime.dwLowDateTime = Time.u.LowPart; FileTime.dwHighDateTime = Time.u.HighPart; FileTimeToLocalFileTime(&FileTime, &FileTime); FileTimeToSystemTime(&FileTime, &SystemTime); GetDateFormatW(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &SystemTime, NULL, DateBuffer, 80); GetTimeFormatW(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &SystemTime, NULL, TimeBuffer, 80); ConPrintf(StdOut, L"%s %s", DateBuffer, TimeBuffer); }
/* * @implemented */ BOOLEAN NTAPI HalQueryRealTimeClock(IN PTIME_FIELDS Time) { LARGE_INTEGER LargeTime; ULONG Seconds; /* Query the RTC value */ Seconds = READ_REGISTER_ULONG(RTC_DATA); /* Convert to time */ RtlSecondsSince1970ToTime(Seconds, &LargeTime); /* Convert to time-fields */ RtlTimeToTimeFields(&LargeTime, Time); return TRUE; }
VOID NetpSecondsSince1970ToFileTime( IN DWORD SecondsSince1970, OUT LPFILETIME FileTime ) { LARGE_INTEGER LargeInteger; // // BUGBUG: This assumes that FILETIME and LARGE_INTEGER have same // precision. Is this guaranteed? // NetpAssert( sizeof(LARGE_INTEGER) == sizeof(FILETIME) ); RtlSecondsSince1970ToTime ( (ULONG) SecondsSince1970, // input: secs since 1970 &LargeInteger ); // output: 64-bits FileTime->dwHighDateTime = LargeInteger.HighPart; FileTime->dwLowDateTime = LargeInteger.LowPart; } // NetpSecondsSince1970ToFileTime
int main( int argc, char *argv[] ) { ULONG i; // // We're starting the test // DbgPrint("Start Time Test\n"); // // Start by initializing some constants and making sure they // are correct // Zero.QuadPart = 0; OneSecond.QuadPart = 10000000; OneMinute.QuadPart = OneSecond.QuadPart * 60; OneHour.QuadPart = OneMinute.QuadPart * 60; OneDay.QuadPart = OneHour.QuadPart * 24; OneWeek.QuadPart = OneDay.QuadPart * 7; OneNormalYear.QuadPart = OneDay.QuadPart * 365; OneLeapYear.QuadPart = OneDay.QuadPart * 366; OneCentury.QuadPart = (OneNormalYear.QuadPart * 76) + (OneLeapYear.QuadPart * 24); TwoCenturies.QuadPart = OneCentury.QuadPart * 2; ThreeCenturies.QuadPart = OneCentury.QuadPart * 3; FourCenturies.QuadPart = (OneCentury.QuadPart * 4) + OneDay.QuadPart; Sum.QuadPart = Zero.QuadPart + OneSecond.QuadPart + OneMinute.QuadPart + OneHour.QuadPart + OneDay.QuadPart + OneWeek.QuadPart + OneNormalYear.QuadPart + ThreeCenturies.QuadPart; RtlTimeToTimeFields( (PLARGE_INTEGER)&Zero, &TimeFields ); DbgPrint("StartOf1601 = "); PrintTimeFields( &TimeFields ); DbgPrint("\n"); if (!RtlTimeFieldsToTime( &TimeFields, &Time )) { DbgPrint("****ERROR converting TimeFields back to Zero\n"); } if ((Time.LowPart != Zero.LowPart) || (Time.HighPart != Zero.HighPart)) { DbgPrint("****ERROR Time != Zero\n"); } RtlTimeToTimeFields( (PLARGE_INTEGER)&OneSecond, &TimeFields ); DbgPrint(" + 1 Second = "); PrintTimeFields( &TimeFields ); DbgPrint("\n"); if (!RtlTimeFieldsToTime( &TimeFields, &Time )) { DbgPrint("****ERROR converting TimeFields back to OneSecond\n"); } if ((Time.LowPart != OneSecond.LowPart) || (Time.HighPart != OneSecond.HighPart)) { DbgPrint("****ERROR Time != OneSecond\n"); } RtlTimeToTimeFields( (PLARGE_INTEGER)&OneMinute, &TimeFields ); DbgPrint(" + 1 Minute = "); PrintTimeFields( &TimeFields ); DbgPrint("\n"); if (!RtlTimeFieldsToTime( &TimeFields, &Time )) { DbgPrint("****ERROR converting TimeFields back to OneMinute\n"); } if ((Time.LowPart != OneMinute.LowPart) || (Time.HighPart != OneMinute.HighPart)) { DbgPrint("****ERROR Time != OneMinute\n"); } RtlTimeToTimeFields( (PLARGE_INTEGER)&OneHour, &TimeFields ); DbgPrint(" + 1 Hour = "); PrintTimeFields( &TimeFields ); DbgPrint("\n"); if (!RtlTimeFieldsToTime( &TimeFields, &Time )) { DbgPrint("****ERROR converting TimeFields back to OneHour\n"); } if ((Time.LowPart != OneHour.LowPart) || (Time.HighPart != OneHour.HighPart)) { DbgPrint("****ERROR Time != OneHour\n"); } RtlTimeToTimeFields( (PLARGE_INTEGER)&OneDay, &TimeFields ); DbgPrint(" + 1 Day = "); PrintTimeFields( &TimeFields ); DbgPrint("\n"); if (!RtlTimeFieldsToTime( &TimeFields, &Time )) { DbgPrint("****ERROR converting TimeFields back to OneDay\n"); } if ((Time.LowPart != OneDay.LowPart) || (Time.HighPart != OneDay.HighPart)) { DbgPrint("****ERROR Time != OneDay\n"); } RtlTimeToTimeFields( (PLARGE_INTEGER)&OneWeek, &TimeFields ); DbgPrint(" + 1 Week = "); PrintTimeFields( &TimeFields ); DbgPrint("\n"); if (!RtlTimeFieldsToTime( &TimeFields, &Time )) { DbgPrint("****ERROR converting TimeFields back to OneWeek\n"); } if ((Time.LowPart != OneWeek.LowPart) || (Time.HighPart != OneWeek.HighPart)) { DbgPrint("****ERROR Time != OneWeek\n"); } RtlTimeToTimeFields( (PLARGE_INTEGER)&OneNormalYear, &TimeFields ); DbgPrint(" + 1 NormalYear = "); PrintTimeFields( &TimeFields ); DbgPrint("\n"); if (!RtlTimeFieldsToTime( &TimeFields, &Time )) { DbgPrint("****ERROR converting TimeFields back to OneNormalYear\n"); } if ((Time.LowPart != OneNormalYear.LowPart) || (Time.HighPart != OneNormalYear.HighPart)) { DbgPrint("****ERROR Time != OneNormalYear\n"); } RtlTimeToTimeFields( (PLARGE_INTEGER)&OneLeapYear, &TimeFields ); DbgPrint(" + 1 LeapYear = "); PrintTimeFields( &TimeFields ); DbgPrint("\n"); if (!RtlTimeFieldsToTime( &TimeFields, &Time )) { DbgPrint("****ERROR converting TimeFields back to OneLeapYear\n"); } if ((Time.LowPart != OneLeapYear.LowPart) || (Time.HighPart != OneLeapYear.HighPart)) { DbgPrint("****ERROR Time != OneLeapYear\n"); } RtlTimeToTimeFields( (PLARGE_INTEGER)&OneCentury, &TimeFields ); DbgPrint(" + 1 Century = "); PrintTimeFields( &TimeFields ); DbgPrint("\n"); if (!RtlTimeFieldsToTime( &TimeFields, &Time )) { DbgPrint("****ERROR converting TimeFields back to OneCentury\n"); } if ((Time.LowPart != OneCentury.LowPart) || (Time.HighPart != OneCentury.HighPart)) { DbgPrint("****ERROR Time != OneCentury\n"); } RtlTimeToTimeFields( (PLARGE_INTEGER)&TwoCenturies, &TimeFields ); DbgPrint(" + 2 Centuries = "); PrintTimeFields( &TimeFields ); DbgPrint("\n"); if (!RtlTimeFieldsToTime( &TimeFields, &Time )) { DbgPrint("****ERROR converting TimeFields back to TwoCenturies\n"); } if ((Time.LowPart != TwoCenturies.LowPart) || (Time.HighPart != TwoCenturies.HighPart)) { DbgPrint("****ERROR Time != TwoCenturies\n"); } RtlTimeToTimeFields( (PLARGE_INTEGER)&ThreeCenturies, &TimeFields ); DbgPrint(" + 3 Centuries = "); PrintTimeFields( &TimeFields ); DbgPrint("\n"); if (!RtlTimeFieldsToTime( &TimeFields, &Time )) { DbgPrint("****ERROR converting TimeFields back to ThreeCenturies\n"); } if ((Time.LowPart != ThreeCenturies.LowPart) || (Time.HighPart != ThreeCenturies.HighPart)) { DbgPrint("****ERROR Time != ThreeCenturies\n"); } RtlTimeToTimeFields( (PLARGE_INTEGER)&FourCenturies, &TimeFields ); DbgPrint(" + 4 Centuries = "); PrintTimeFields( &TimeFields ); DbgPrint("\n"); if (!RtlTimeFieldsToTime( &TimeFields, &Time )) { DbgPrint("****ERROR converting TimeFields back to FourCenturies\n"); } if ((Time.LowPart != FourCenturies.LowPart) || (Time.HighPart != FourCenturies.HighPart)) { DbgPrint("****ERROR Time != FourCenturies\n"); } RtlTimeToTimeFields( (PLARGE_INTEGER)&Sum, &TimeFields ); DbgPrint(" + sum = "); PrintTimeFields( &TimeFields ); DbgPrint("\n"); if (!RtlTimeFieldsToTime( &TimeFields, &Time )) { DbgPrint("****ERROR converting TimeFields back to Sum\n"); } if ((Time.LowPart != Sum.LowPart) || (Time.HighPart != Sum.HighPart)) { DbgPrint("****ERROR Time != Sum\n"); } DbgPrint("\n"); // // Setup and test the start 1970 time // RtlSecondsSince1970ToTime( 0, &StartOf1970 ); RtlTimeToTimeFields( &StartOf1970, &TimeFields ); DbgPrint(" Start of 1970 = "); PrintTimeFields( &TimeFields ); DbgPrint("\n"); if (!RtlTimeFieldsToTime( &TimeFields, &Time )) { DbgPrint("****ERROR converting TimeFields back to start of 1970\n"); } if ((Time.LowPart != StartOf1970.LowPart) || (Time.HighPart != StartOf1970.HighPart)) { DbgPrint("****ERROR Time != StartOf1970\n"); } if (!RtlTimeToSecondsSince1970( &StartOf1970, &i )) { DbgPrint("****ERROR converting time to seconds since 1970\n"); } if (i != 0) { DbgPrint("****ERROR seconds since 1970 != 0\n"); } // // Setup and test the start 1980 time // RtlSecondsSince1980ToTime( 0, &StartOf1980 ); RtlTimeToTimeFields( &StartOf1980, &TimeFields ); DbgPrint(" Start of 1980 = "); PrintTimeFields( &TimeFields ); DbgPrint("\n"); if (!RtlTimeFieldsToTime( &TimeFields, &Time )) { DbgPrint("****ERROR converting TimeFields back to start of 1980\n"); } if ((Time.LowPart != StartOf1980.LowPart) || (Time.HighPart != StartOf1980.HighPart)) { DbgPrint("****ERROR Time != StartOf1980\n"); } if (!RtlTimeToSecondsSince1980( &StartOf1980, &i )) { DbgPrint("****ERROR converting time to seconds since 1980\n"); } if (i != 0) { DbgPrint("****ERROR seconds since 1980 != 0\n"); } // // Lets try to print the Christmas when Santa arrives for 1901 to 2001 // every 10 years // TimeFields.Month = 12; TimeFields.Day = 25; TimeFields.Hour = 3; TimeFields.Minute = 30; TimeFields.Second = 15; TimeFields.Milliseconds = 250; for (i = 1901; i < 2002; i += 10) { TimeFields.Year = i; if (!RtlTimeFieldsToTime( &TimeFields, &Time )) { DbgPrint("****ERROR converting TimeFields to Christmas %4d\n", TimeFields.Year); } RtlTimeToTimeFields( &Time, &TimeFields ); DbgPrint(" Christmas %4d = ", i); PrintTimeFields( &TimeFields ); DbgPrint("\n"); } // // Let's see how old I really am, when I turn 10, 20, 30, ... // TimeFields.Month = 12; TimeFields.Day = 5; TimeFields.Hour = 3; TimeFields.Minute = 14; TimeFields.Second = 0; TimeFields.Milliseconds = 0; for (i = 1956; i <= 1956+60; i += 10) { TimeFields.Year = i; if (!RtlTimeFieldsToTime( &TimeFields, &Time )) { DbgPrint("****ERROR converting TimeFields to DOB %4d\n", TimeFields.Year); } RtlTimeToTimeFields( &Time, &TimeFields ); DbgPrint(" DOB + %4d = ", i-1956); PrintTimeFields( &TimeFields ); DbgPrint("\n"); } DbgPrint("End Time Test\n"); return TRUE; }
static HRESULT TRASH_GetDetails(const TRASH_BUCKET *bucket, LPCSTR filename, WIN32_FIND_DATAW *data) { LPSTR path = NULL; XDG_PARSED_FILE *parsed = NULL; char *original_file_name = NULL; char *deletion_date = NULL; int fd = -1; struct stat stats; HRESULT ret = S_FALSE; LPWSTR original_dos_name; int suffix_length = lstrlenA(trashinfo_suffix); int filename_length = lstrlenA(filename); int files_length = lstrlenA(bucket->files_dir); int path_length = max(lstrlenA(bucket->info_dir), files_length); path = SHAlloc(path_length + filename_length + 1); if (path == NULL) return E_OUTOFMEMORY; wsprintfA(path, "%s%s", bucket->files_dir, filename); path[path_length + filename_length - suffix_length] = 0; /* remove the '.trashinfo' */ if (lstat(path, &stats) == -1) { ERR("Error accessing data file for trashinfo %s (errno=%d)\n", filename, errno); goto failed; } wsprintfA(path, "%s%s", bucket->info_dir, filename); fd = open(path, O_RDONLY); if (fd == -1) { ERR("Couldn't open trashinfo file %s (errno=%d)\n", path, errno); goto failed; } parsed = XDG_ParseDesktopFile(fd); if (parsed == NULL) { ERR("Parse error in trashinfo file %s\n", path); goto failed; } original_file_name = XDG_GetStringValue(parsed, trashinfo_group, "Path", XDG_URLENCODE); if (original_file_name == NULL) { ERR("No 'Path' entry in trashinfo file\n"); goto failed; } ZeroMemory(data, sizeof(*data)); data->nFileSizeHigh = (DWORD)((LONGLONG)stats.st_size>>32); data->nFileSizeLow = stats.st_size & 0xffffffff; RtlSecondsSince1970ToTime(stats.st_mtime, (LARGE_INTEGER *)&data->ftLastWriteTime); original_dos_name = wine_get_dos_file_name(original_file_name); if (original_dos_name != NULL) { lstrcpynW(data->cFileName, original_dos_name, MAX_PATH); SHFree(original_dos_name); } else { /* show only the file name */ char *file = strrchr(original_file_name, '/'); if (file == NULL) file = original_file_name; MultiByteToWideChar(CP_UNIXCP, 0, file, -1, data->cFileName, MAX_PATH); } deletion_date = XDG_GetStringValue(parsed, trashinfo_group, "DeletionDate", 0); if (deletion_date) { struct tm del_time; time_t del_secs; sscanf(deletion_date, "%d-%d-%dT%d:%d:%d", &del_time.tm_year, &del_time.tm_mon, &del_time.tm_mday, &del_time.tm_hour, &del_time.tm_min, &del_time.tm_sec); del_time.tm_year -= 1900; del_time.tm_mon--; del_time.tm_isdst = -1; del_secs = mktime(&del_time); RtlSecondsSince1970ToTime(del_secs, (LARGE_INTEGER *)&data->ftLastAccessTime); } ret = S_OK; failed: SHFree(path); SHFree(original_file_name); SHFree(deletion_date); if (fd != -1) close(fd); XDG_FreeParsedFile(parsed); return ret; }
BOOLEAN EtpRefreshUnloadedDlls( __in HWND hwndDlg, __in PUNLOADED_DLLS_CONTEXT Context ) { NTSTATUS status; PULONG elementSize; PULONG elementCount; PVOID eventTrace; HANDLE processHandle = NULL; ULONG eventTraceSize; ULONG capturedElementSize; ULONG capturedElementCount; PVOID capturedEventTracePointer; PVOID capturedEventTrace = NULL; ULONG i; PVOID currentEvent; HWND lvHandle; lvHandle = GetDlgItem(hwndDlg, IDC_LIST); ListView_DeleteAllItems(lvHandle); RtlGetUnloadEventTraceEx(&elementSize, &elementCount, &eventTrace); if (!NT_SUCCESS(status = PhOpenProcess(&processHandle, PROCESS_VM_READ, Context->ProcessItem->ProcessId))) goto CleanupExit; // We have the pointers for the unload event trace information. // Since ntdll is loaded at the same base address across all processes, // we can read the information in. if (!NT_SUCCESS(status = PhReadVirtualMemory( processHandle, elementSize, &capturedElementSize, sizeof(ULONG), NULL ))) goto CleanupExit; if (!NT_SUCCESS(status = PhReadVirtualMemory( processHandle, elementCount, &capturedElementCount, sizeof(ULONG), NULL ))) goto CleanupExit; if (!NT_SUCCESS(status = PhReadVirtualMemory( processHandle, eventTrace, &capturedEventTracePointer, sizeof(PVOID), NULL ))) goto CleanupExit; if (!capturedEventTracePointer) goto CleanupExit; // no events if (capturedElementCount > 0x4000) capturedElementCount = 0x4000; eventTraceSize = capturedElementSize * capturedElementCount; capturedEventTrace = PhAllocateSafe(eventTraceSize); if (!capturedEventTrace) { status = STATUS_NO_MEMORY; goto CleanupExit; } if (!NT_SUCCESS(status = PhReadVirtualMemory( processHandle, capturedEventTracePointer, capturedEventTrace, eventTraceSize, NULL ))) goto CleanupExit; currentEvent = capturedEventTrace; ExtendedListView_SetRedraw(lvHandle, FALSE); for (i = 0; i < capturedElementCount; i++) { PRTL_UNLOAD_EVENT_TRACE rtlEvent = currentEvent; INT lvItemIndex; WCHAR buffer[128]; PPH_STRING string; LARGE_INTEGER time; SYSTEMTIME systemTime; if (!rtlEvent->BaseAddress) break; PhPrintUInt32(buffer, rtlEvent->Sequence); lvItemIndex = PhAddListViewItem(lvHandle, MAXINT, buffer, rtlEvent); // Name if (PhCopyUnicodeStringZ(rtlEvent->ImageName, sizeof(rtlEvent->ImageName) / sizeof(WCHAR), buffer, sizeof(buffer) / sizeof(WCHAR), NULL)) { PhSetListViewSubItem(lvHandle, lvItemIndex, 1, buffer); } // Base Address PhPrintPointer(buffer, rtlEvent->BaseAddress); PhSetListViewSubItem(lvHandle, lvItemIndex, 2, buffer); // Size string = PhFormatSize(rtlEvent->SizeOfImage, -1); PhSetListViewSubItem(lvHandle, lvItemIndex, 3, string->Buffer); PhDereferenceObject(string); // Time Stamp RtlSecondsSince1970ToTime(rtlEvent->TimeDateStamp, &time); PhLargeIntegerToLocalSystemTime(&systemTime, &time); string = PhFormatDateTime(&systemTime); PhSetListViewSubItem(lvHandle, lvItemIndex, 4, string->Buffer); PhDereferenceObject(string); // Checksum PhPrintPointer(buffer, UlongToPtr(rtlEvent->CheckSum)); PhSetListViewSubItem(lvHandle, lvItemIndex, 5, buffer); currentEvent = PTR_ADD_OFFSET(currentEvent, capturedElementSize); } ExtendedListView_SortItems(lvHandle); ExtendedListView_SetRedraw(lvHandle, TRUE); if (Context->CapturedEventTrace) PhFree(Context->CapturedEventTrace); Context->CapturedEventTrace = capturedEventTrace; CleanupExit: if (processHandle) NtClose(processHandle); if (NT_SUCCESS(status)) { return TRUE; } else { PhShowStatus(hwndDlg, L"Unable to retrieve unload event trace information", status, 0); return FALSE; } }
static INT DisplayWorkstationStatistics(VOID) { PWKSTA_INFO_100 WorkstationInfo = NULL; PSTAT_WORKSTATION_0 StatisticsInfo = NULL; LARGE_INTEGER LargeValue; FILETIME FileTime, LocalFileTime; SYSTEMTIME SystemTime; WORD wHour; INT nPaddedLength = 47; NET_API_STATUS Status; Status = NetWkstaGetInfo(NULL, 100, (PBYTE*)&WorkstationInfo); if (Status != NERR_Success) goto done; Status = NetStatisticsGet(NULL, SERVICE_SERVER, 0, 0, (LPBYTE*)&StatisticsInfo); if (Status != NERR_Success) goto done; PrintMessageStringV(4623, WorkstationInfo->wki100_computername); ConPrintf(StdOut, L"\n\n"); RtlSecondsSince1970ToTime(StatisticsInfo->StatisticsStartTime.u.LowPart, &LargeValue); FileTime.dwLowDateTime = LargeValue.u.LowPart; FileTime.dwHighDateTime = LargeValue.u.HighPart; FileTimeToLocalFileTime(&FileTime, &LocalFileTime); FileTimeToSystemTime(&LocalFileTime, &SystemTime); wHour = SystemTime.wHour; if (wHour == 0) { wHour = 12; } else if (wHour > 12) { wHour = wHour - 12; } PrintMessageString(4600); ConPrintf(StdOut, L" %d/%d/%d %d:%02d %s\n\n\n", SystemTime.wMonth, SystemTime.wDay, SystemTime.wYear, wHour, SystemTime.wMinute, (SystemTime.wHour >= 1 && SystemTime.wHour < 13) ? L"AM" : L"PM"); PrintPaddedMessageString(4630, nPaddedLength); ConPrintf(StdOut, L"%I64u\n", StatisticsInfo->BytesReceived.QuadPart); PrintPaddedMessageString(4631, nPaddedLength); ConPrintf(StdOut, L"%I64u\n", StatisticsInfo->SmbsReceived.QuadPart); PrintPaddedMessageString(4632, nPaddedLength); ConPrintf(StdOut, L"%I64u\n", StatisticsInfo->BytesTransmitted.QuadPart); PrintPaddedMessageString(4633, nPaddedLength); ConPrintf(StdOut, L"%I64u\n", StatisticsInfo->SmbsTransmitted.QuadPart); PrintPaddedMessageString(4634, nPaddedLength); ConPrintf(StdOut, L"%lu\n", StatisticsInfo->ReadOperations); PrintPaddedMessageString(4635, nPaddedLength); ConPrintf(StdOut, L"%lu\n", StatisticsInfo->WriteOperations); PrintPaddedMessageString(4636, nPaddedLength); ConPrintf(StdOut, L"%lu\n", StatisticsInfo->RawReadsDenied); PrintPaddedMessageString(4637, nPaddedLength); ConPrintf(StdOut, L"%lu\n\n", StatisticsInfo->RawWritesDenied); PrintPaddedMessageString(4638, nPaddedLength); ConPrintf(StdOut, L"%lu\n", StatisticsInfo->NetworkErrors); PrintPaddedMessageString(4639, nPaddedLength); ConPrintf(StdOut, L"%lu\n", StatisticsInfo->CoreConnects + StatisticsInfo->Lanman20Connects + StatisticsInfo->Lanman21Connects + StatisticsInfo->LanmanNtConnects); PrintPaddedMessageString(4640, nPaddedLength); ConPrintf(StdOut, L"%lu\n", StatisticsInfo->Reconnects); PrintPaddedMessageString(4641, nPaddedLength); ConPrintf(StdOut, L"%lu\n\n", StatisticsInfo->ServerDisconnects); PrintPaddedMessageString(4642, nPaddedLength); ConPrintf(StdOut, L"%lu\n", StatisticsInfo->Sessions); PrintPaddedMessageString(4643, nPaddedLength); ConPrintf(StdOut, L"%lu\n", StatisticsInfo->HungSessions); PrintPaddedMessageString(4644, nPaddedLength); ConPrintf(StdOut, L"%lu\n", StatisticsInfo->FailedSessions); PrintPaddedMessageString(4645, nPaddedLength); ConPrintf(StdOut, L"%lu\n", StatisticsInfo->InitiallyFailedOperations + StatisticsInfo->FailedCompletionOperations); PrintPaddedMessageString(4646, nPaddedLength); ConPrintf(StdOut, L"%lu\n", StatisticsInfo->UseCount); PrintPaddedMessageString(4647, nPaddedLength); ConPrintf(StdOut, L"%lu\n\n", StatisticsInfo->FailedUseCount); done: if (StatisticsInfo != NULL) NetApiBufferFree(StatisticsInfo); if (WorkstationInfo != NULL) NetApiBufferFree(WorkstationInfo); return 0; }
static INT DisplayServerStatistics(VOID) { PSERVER_INFO_100 ServerInfo = NULL; PSTAT_SERVER_0 StatisticsInfo = NULL; LARGE_INTEGER LargeValue; FILETIME FileTime, LocalFileTime; SYSTEMTIME SystemTime; WORD wHour; INT nPaddedLength = 35; NET_API_STATUS Status; Status = NetServerGetInfo(NULL, 100, (PBYTE*)&ServerInfo); if (Status != NERR_Success) goto done; Status = NetStatisticsGet(NULL, SERVICE_SERVER, 0, 0, (LPBYTE*)&StatisticsInfo); if (Status != NERR_Success) goto done; PrintMessageStringV(4624, ServerInfo->sv100_name); ConPrintf(StdOut, L"\n\n"); RtlSecondsSince1970ToTime(StatisticsInfo->sts0_start, &LargeValue); FileTime.dwLowDateTime = LargeValue.u.LowPart; FileTime.dwHighDateTime = LargeValue.u.HighPart; FileTimeToLocalFileTime(&FileTime, &LocalFileTime); FileTimeToSystemTime(&LocalFileTime, &SystemTime); wHour = SystemTime.wHour; if (wHour == 0) { wHour = 12; } else if (wHour > 12) { wHour = wHour - 12; } PrintMessageString(4600); ConPrintf(StdOut, L" %d/%d/%d %d:%02d %s\n\n\n", SystemTime.wMonth, SystemTime.wDay, SystemTime.wYear, wHour, SystemTime.wMinute, (SystemTime.wHour >= 1 && SystemTime.wHour < 13) ? L"AM" : L"PM"); PrintPaddedMessageString(4601, nPaddedLength); ConPrintf(StdOut, L"%lu\n", StatisticsInfo->sts0_sopens); PrintPaddedMessageString(4602, nPaddedLength); ConPrintf(StdOut, L"%lu\n", StatisticsInfo->sts0_stimedout); PrintPaddedMessageString(4603, nPaddedLength); ConPrintf(StdOut, L"%lu\n\n", StatisticsInfo->sts0_serrorout); LargeValue.u.LowPart = StatisticsInfo->sts0_bytessent_low; LargeValue.u.HighPart = StatisticsInfo->sts0_bytessent_high; PrintPaddedMessageString(4604, nPaddedLength); ConPrintf(StdOut, L"%I64u\n", LargeValue.QuadPart / 1024); LargeValue.u.LowPart = StatisticsInfo->sts0_bytesrcvd_low; LargeValue.u.HighPart = StatisticsInfo->sts0_bytesrcvd_high; PrintPaddedMessageString(4605, nPaddedLength); ConPrintf(StdOut, L"%I64u\n", LargeValue.QuadPart / 1024); PrintPaddedMessageString(4606, nPaddedLength); ConPrintf(StdOut, L"%lu\n\n", StatisticsInfo->sts0_avresponse); PrintPaddedMessageString(4610, nPaddedLength); ConPrintf(StdOut, L"%lu\n", StatisticsInfo->sts0_syserrors); PrintPaddedMessageString(4612, nPaddedLength); ConPrintf(StdOut, L"%lu\n", StatisticsInfo->sts0_permerrors); PrintPaddedMessageString(4611, nPaddedLength); ConPrintf(StdOut, L"%lu\n\n", StatisticsInfo->sts0_pwerrors); PrintPaddedMessageString(4608, nPaddedLength); ConPrintf(StdOut, L"%lu\n", StatisticsInfo->sts0_fopens); PrintPaddedMessageString(4613, nPaddedLength); ConPrintf(StdOut, L"%lu\n", StatisticsInfo->sts0_devopens); PrintPaddedMessageString(4609, nPaddedLength); ConPrintf(StdOut, L"%lu\n\n", StatisticsInfo->sts0_jobsqueued); PrintMessageString(4620); ConPrintf(StdOut, L"\n"); ConPrintf(StdOut, L" "); PrintPaddedMessageString(4621, nPaddedLength - 2); ConPrintf(StdOut, L"%lu\n", StatisticsInfo->sts0_bigbufneed); ConPrintf(StdOut, L" "); PrintPaddedMessageString(4622, nPaddedLength - 2); ConPrintf(StdOut, L"%lu\n\n", StatisticsInfo->sts0_reqbufneed); done: if (StatisticsInfo != NULL) NetApiBufferFree(StatisticsInfo); if (ServerInfo != NULL) NetApiBufferFree(ServerInfo); return 0; }