diff --git a/modules/rosapps/applications/CMakeLists.txt b/modules/rosapps/applications/CMakeLists.txt index e42ab38721..2365bec861 100644 --- a/modules/rosapps/applications/CMakeLists.txt +++ b/modules/rosapps/applications/CMakeLists.txt @@ -1,5 +1,6 @@ add_subdirectory(cmdutils) add_subdirectory(devutils) +add_subdirectory(diskcat) add_subdirectory(explorer-old) add_subdirectory(fraginator) add_subdirectory(imagesoft) diff --git a/modules/rosapps/applications/diskcat/CMakeLists.txt b/modules/rosapps/applications/diskcat/CMakeLists.txt new file mode 100644 index 0000000000..5649ba836f --- /dev/null +++ b/modules/rosapps/applications/diskcat/CMakeLists.txt @@ -0,0 +1,4 @@ +add_executable(diskcat diskcat.c) +set_module_type(diskcat win32cui UNICODE) +add_importlibs(diskcat msvcrt kernel32) +add_cd_file(TARGET diskcat DESTINATION reactos/system32 FOR all) \ No newline at end of file diff --git a/modules/rosapps/applications/diskcat/diskcat.c b/modules/rosapps/applications/diskcat/diskcat.c new file mode 100644 index 0000000000..3d59d0ec3f --- /dev/null +++ b/modules/rosapps/applications/diskcat/diskcat.c @@ -0,0 +1,113 @@ + +#include +#include +#include + +#define PARTONE 446 +#define PARTTYPE 4 +#define PARTLBA 8 + +const WCHAR args[5][3]= { L"/?", L"-?", L"-h", L"/m", L"/c" }; +const WCHAR yesno[3][4]= { L"No\0", L"Yes", L"???" }; + +unsigned int ReadMBR(const char* diskObject, unsigned char* buffer); +void HackString(char* name, unsigned char number); + +int wmain(int argc, char* argv[]) +{ + unsigned char firstsector[512]; + char diskname[20] = "\\\\.\\PhysicalDrive0"; // for up to 99 - should be enough + + int disknum, partnum, active, type; + unsigned int lba, alignment = 64; + + printf("Diskcat alignment check v0.5\n"); + + if (argc >= 2) + { + if ((wcscmp((wchar_t*)argv[1],args[0]) == 0) ||(wcscmp((wchar_t*)argv[1],args[1]) == 0) || (wcscmp((wchar_t*)argv[1],args[2]) == 0)) + { + printf("released as Public Domain by whatevar (2018)\n\nCommandline arguments:\n /m Alignment to 1 Megabyte (2048)\n /c 2048 Alignment to custom value (here: 2048 [* 512b])\n"); + return 0; + } + else if (wcscmp((wchar_t*)argv[1],args[3]) == 0) + { + alignment = 2048; + } + else if ((wcscmp((wchar_t*)argv[1],args[4]) == 0)&&(argc > 2)) + { + alignment = (unsigned int) strtoul(argv[2],NULL,10); + + } + } + + if (alignment == 0) alignment = 64; + + printf("Alignment set to: %d\n\n", alignment); + + printf("Object Path\t\tPart#\tActive\tType\tMisalignment\tLBA\n--------------------------------------------------------------------------------\n"); + + for (disknum = 0; disknum < 10; disknum++) + { + HackString(diskname,disknum); + + if (ReadMBR((const char*)diskname,firstsector) == 0) continue; + + //Check the primary partitions + + for (partnum = 0; partnum < 4; partnum++) + { + if (firstsector[PARTONE + (partnum*16) + PARTTYPE] == 0) continue; + + active = firstsector[PARTONE + (partnum*16)]; + + active = active > 127 ? 1 : active > 0 ? 2 : 0; + + type = firstsector[PARTONE + (partnum*16) + PARTTYPE]; + lba = *((unsigned int*)&firstsector[PARTONE + (partnum*16) + PARTLBA]); + printf("%s\t%d\t%S\t%d\t%d\t\t%d\n",diskname,partnum,yesno[active],type,(alignment - (lba%alignment))%alignment,lba); + } + + } + return 0; +} + +void HackString(char* name, unsigned char number) +{ + if (number < 10) + { + name[17] = '0' + number; + name[18] = 0; + name[19] = 0; + } else if (number < 100) + { + name[17] = '0' + number /10; + name[18] = '0' + number % 10; + name[19] = 0; + } else + { + name[0] = 0; + printf("Not today, Sir!\n"); + } +} + +//unsigned int ReadMBR(const char* diskObject, unsigned char* buffer) +unsigned int ReadMBR(const char* diskObject, unsigned char* buffer) +{ + DWORD count = 0; + HANDLE disk = INVALID_HANDLE_VALUE; + + disk = CreateFileA(diskObject, GENERIC_READ, FILE_SHARE_VALID_FLAGS, 0, OPEN_EXISTING, 0, 0); + if (disk == INVALID_HANDLE_VALUE) + { + if (GetLastError() == 5) printf("%s\t%s\n",diskObject,"Access denied!"); + CloseHandle(disk); + return 0; + } + + ReadFile(disk, buffer, 512, &count, 0); // read sector + + CloseHandle(disk); + + return (unsigned int)count; +}