28 #define FI_ARG_ACTION 2
29 #define FI_ARG_NATIVE 3
30 #define FI_ARG_PATTERN 4
31 #define FI_ARG_CASESENSITIVE 5
32 #define FI_ARG_OUTPUT 6
33 #define FI_ARG_FORCE 7
34 #define FI_ARG_LENGTH 8
55 static BOOLEAN NTAPI FiCommandLineCallback(
58 _In_opt_ PVOID Context
95 else if (!FiArgFileName)
108 L
"fiin action [-C] [-f] [-L length] [-N] [-o filename] [-p pattern] [filename]\n"
109 L
"\taction The action to be performed.\n"
110 L
"\t-C Specifies that file names are case-sensitive.\n"
111 L
"\t-f Forces the action to succeed by overwriting files.\n"
112 L
"\t-L length Specifies the length for an operation.\n"
113 L
"\t-N Specifies that file names are in native format.\n"
114 L
"\t-o filename Specifies the output file name, or the command line.\n"
115 L
"\t-p pattern A search pattern for listings.\n"
146 if (fullPath->
Length / 2 > MAX_PATH)
148 wprintf(L
"Warning: Detected long file name \"%s\".\n", fullPath->
Buffer);
173 wprintf(L
"Warning: Unable to convert the file name \"%s\" to a NT file name.\n", FileName->Buffer);
182 if (FileName->Length >= 2 * 2 && iswalpha(FileName->Buffer[0]) && FileName->Buffer[1] ==
':')
186 else if (FileName->Buffer[0] !=
'\\')
190 NtCurrentPeb()->ProcessParameters->CurrentDirectory.DosPath.Buffer,
202 _Out_ PHANDLE FileHandle,
203 _In_ ACCESS_MASK DesiredAccess,
205 _In_opt_ ULONG FileAttributes,
206 _In_ ULONG ShareAccess,
207 _In_ ULONG CreateDisposition,
208 _In_opt_ ULONG Options
219 FileAttributes = FILE_ATTRIBUTE_NORMAL;
277 wprintf(L
"Error creating/opening file: %s\n",
PhGetNtMessage(status)->Buffer);
281 *FileHandle = fileHandle;
288 _In_opt_ PVOID Context
292 SYSTEMTIME systemTime;
300 L
"%-10s %12s %c%c%c%c%c%c%c%c %11s %.*s\n",
303 (Information->FileAttributes & FILE_ATTRIBUTE_DIRECTORY) ?
'+' :
' ',
304 (Information->FileAttributes & FILE_ATTRIBUTE_HIDDEN) ?
'h' :
' ',
305 (Information->FileAttributes & FILE_ATTRIBUTE_SYSTEM) ?
's' :
' ',
306 (Information->FileAttributes & FILE_ATTRIBUTE_READONLY) ?
'r' :
' ',
307 (Information->FileAttributes & FILE_ATTRIBUTE_COMPRESSED) ?
'z' :
' ',
308 (Information->FileAttributes & FILE_ATTRIBUTE_ENCRYPTED) ?
'e' :
' ',
309 (Information->FileAttributes & FILE_ATTRIBUTE_SPARSE_FILE) ?
'%' :
' ',
310 (Information->FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) ?
'*' :
' ',
312 Information->FileNameLength / 2,
313 Information->FileName
320 if (Information->FileAttributes & FILE_ATTRIBUTE_DIRECTORY)
331 int __cdecl
main(
int argc,
char *argv[])
345 NTSTATUS status = STATUS_SUCCESS;
357 FiCommandLineCallback,
365 if (!FiArgFileName && (
380 WCHAR deviceNameBuffer[7] = L
"\\??\\ :";
382 WCHAR targetNameBuffer[0x100];
385 targetName.Buffer = targetNameBuffer;
388 for (i = 0; i < 26; i++)
394 deviceNameBuffer[4] = (WCHAR)(
'A' + i);
395 deviceName.Buffer = deviceNameBuffer;
396 deviceName.
Length = 6 *
sizeof(WCHAR);
418 wprintf(L
"%c: %.*s\n",
'A' + i, targetName.
Length / 2, targetName.Buffer);
425 else if (!FiArgFileName)
427 wprintf(L
"Error: file name missing.\n");
434 LARGE_INTEGER fileSize;
448 wprintf(L
"Invalid hash algorithm. Possibilities: md5, sha1, crc32\n");
457 FILE_SHARE_READ | FILE_SHARE_DELETE,
468 ULONG64 bytesRemaining;
470 bytesRemaining = fileSize.QuadPart;
485 while (bytesRemaining)
518 if (status == STATUS_END_OF_FILE)
519 status = STATUS_SUCCESS;
539 wprintf(L
"%08x", crc);
545 wprintf(L
"Warning: I/O error encountered: %s\n",
PhGetNtMessage(status)->Buffer);
563 FiArgOutput ? &FiArgOutput->
sr : NULL,
584 NtCurrentPeb()->ProcessParameters->CurrentDirectory.DosPath.Buffer,
602 DELETE | SYNCHRONIZE,
605 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
617 wprintf(L
"Error deleting file: %s\n",
PhGetNtMessage(status)->Buffer);
629 FILE_READ_ATTRIBUTES | SYNCHRONIZE,
632 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
646 FILE_READ_ATTRIBUTES | SYNCHRONIZE,
648 FILE_ATTRIBUTE_DIRECTORY,
649 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
664 wprintf(L
"Error: new file name missing.\n");
673 DELETE | SYNCHRONIZE,
676 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
682 ULONG renameInfoSize;
686 renameInfo = PhAllocate(renameInfoSize);
697 wprintf(L
"Error renaming file: %s\n",
PhGetNtMessage(status)->Buffer);
706 HANDLE outFileHandle;
707 LARGE_INTEGER fileSize;
712 wprintf(L
"Error: output file name missing.\n");
719 FILE_READ_ATTRIBUTES | FILE_READ_DATA | SYNCHRONIZE,
722 FILE_SHARE_READ | FILE_SHARE_DELETE,
727 FILE_WRITE_ATTRIBUTES | FILE_WRITE_DATA | SYNCHRONIZE,
730 FILE_SHARE_READ | FILE_SHARE_DELETE,
735 #define COPY_BUFFER_SIZE 0x10000
749 wprintf(L
"Error allocating buffer.\n");
767 if (status == STATUS_END_OF_FILE)
773 wprintf(L
"Error reading from file: %s\n",
PhGetNtMessage(status)->Buffer);
791 wprintf(L
"Error writing to output file: %s\n",
PhGetNtMessage(status)->Buffer);
819 NtClose(outFileHandle);
830 FILE_LIST_DIRECTORY | SYNCHRONIZE,
833 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
848 FiArgPattern ? &pattern : NULL,
858 L
"%12I64u file(s) %11s bytes\n"
859 L
"%12I64u dir(s) %11s bytes allocated\n",
878 FILE_READ_ATTRIBUTES | SYNCHRONIZE,
881 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
917 wprintf(L
"Error: invalid action \"%s\".\n", FiArgAction->
Buffer);