Skip to content

Commit

Permalink
[CHKREG] WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoB99 committed Nov 11, 2023
1 parent 03edefb commit bac35a8
Show file tree
Hide file tree
Showing 9 changed files with 785 additions and 0 deletions.
1 change: 1 addition & 0 deletions sdk/tools/CMakeLists.txt
Expand Up @@ -29,6 +29,7 @@ add_host_tool(utf16le utf16le/utf16le.cpp)

add_subdirectory(asmpp)
add_subdirectory(cabman)
add_subdirectory(chkreg)
add_subdirectory(fatten)
add_subdirectory(hhpcomp)
add_subdirectory(hpp)
Expand Down
17 changes: 17 additions & 0 deletions sdk/tools/chkreg/CMakeLists.txt
@@ -0,0 +1,17 @@

list(APPEND SOURCE
chkreg.c
hivinit.c
hivchk.c
hivio.c
hivmem.c
rtl.c)

add_host_tool(chkreg ${SOURCE})
target_include_directories(chkreg PRIVATE ${REACTOS_SOURCE_DIR}/sdk/lib/rtl)
target_compile_definitions(chkreg PRIVATE CHKREG_HOST)
if(NOT MSVC)
target_compile_options(chkreg PRIVATE "-fshort-wchar")
endif()

target_link_libraries(chkreg PRIVATE host_includes unicode cmlibhost)
132 changes: 132 additions & 0 deletions sdk/tools/chkreg/chkreg.c
@@ -0,0 +1,132 @@
/*
* PROJECT: ReactOS Tools
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: Check Registry Utility
* COPYRIGHT: Copyright 2023 George Bișoc <george.bisoc@reactos.org>
*/

/* INCLUDES *****************************************************************/

#include "chkreg.h"

/* FUNCTIONS ****************************************************************/

static
void
ChkRegShowUsage(
void)
{
printf("Usage: chkreg /h /a /r /v HIVE_FILE LOG_FILE\n\n"
" /a HIVE_FILE - Analyze a registry hive.\n"
" /r HIVE_FILE LOG_FILE - Recover a damaged hive with a log (currently it's not implemented yet).\n"
" /h - Show help.\n"
" /v - Verbose mode (currently it's not implemented yet).\n");
}

static
void
ChkRegBuildFilePath(
IN OUT char *Destination,
IN char *Source)
{
INT i;

i = 0;
while (Source[i] != 0)
{
#ifdef _WIN32
if (Source[i] == '/')
{
Destination[i] = '\\';
}
#else
if (Source[i] == '\\')
{
Destination[i] = '/';
}
#endif
else
{
Destination[i] = Source[i];
}

i++;
}

Destination[i] = 0;
}

int
main(int argc, char *argv[])
{
BOOLEAN Success;
INT i;
BOOLEAN AnalyzeHive = FALSE;
CHAR HiveName[260] = "";

/* Display the usage description if the user only typed the program name */
if (argc < 2)
{
ChkRegShowUsage();
return -1;
}

/* Parse the arguments from the command line */
for (i = 1; i < argc && *argv[i] == '/'; i++)
{
/* Display the usage description */
if (argv[i][1] == 'h' && argv[i][2] == 0)
{
ChkRegShowUsage();
return -1;
}

/* The user wants to analyze its registry hive */
if (argv[i][1] == 'a')
{
/* Grab the hive name */
AnalyzeHive = TRUE;
ChkRegBuildFilePath(HiveName, argv[i] + 3);
break;
}
/* The user wants to repair its hive with a log */
else if (argv[i][1] == 'r')
{
printf("Repair mode with a hive log is not implemented yet!\n");
return -1;
}
/* The user wants verbose mode whilst analyzing its hive */
else if (argv[i][1] == 'v')
{
printf("Verbose mode is not implemented yet!\n");
return -1;
}
else
{
fprintf(stderr, "Unrecognized command option: %s\n", argv[i]);
return -1;
}
}

/* The user asked to analyze its hive, ensure he submitted a hive file name */
if (AnalyzeHive)
{
if (!*HiveName)
{
fprintf(stderr, "The hive name is missing!\n");
return -1;
}

/* Analyze it now */
Success = ChkRegAnalyzeHive(HiveName);
if (!Success)
{
fprintf(stderr, "Hive analization finished, the hive has damaged parts!\n");
return -1;
}
}

return 0;
}

/* EOF */
102 changes: 102 additions & 0 deletions sdk/tools/chkreg/chkreg.h
@@ -0,0 +1,102 @@
/*
* PROJECT: ReactOS Tools
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: Check Registry Utility main header
* COPYRIGHT: Copyright 2023 George Bișoc <george.bisoc@reactos.org>
*/

#pragma once

/* INCLUDES *****************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <typedefs.h>

#define CMLIB_HOST
#include <cmlib.h>

/* GLOBALS *******************************************************************/

extern BOOLEAN FixBrokenHive;

/* DEFINES *******************************************************************/

// Definitions copied from <ntstatus.h>
// We only want to include host headers, so we define them manually
#define STATUS_SUCCESS ((NTSTATUS)0x00000000)
#define STATUS_UNSUCCESSFUL ((NTSTATUS)0xC0000001)
#define STATUS_NO_MEMORY ((NTSTATUS)0xC0000017)
#define STATUS_REGISTRY_CORRUPT ((NTSTATUS)0xC000014C)

/* FUNCTION PROTOTYPES *******************************************************/

/* hivchk.c */
BOOLEAN
ChkRegAnalyzeHive(
IN PCSTR HiveName);

/* hivio.c */
BOOLEAN
NTAPI
CmpFileRead(
IN PHHIVE RegistryHive,
IN ULONG FileType,
IN PULONG FileOffset,
OUT PVOID Buffer,
IN SIZE_T BufferLength);

BOOLEAN
NTAPI
CmpFileWrite(
IN PHHIVE RegistryHive,
IN ULONG FileType,
IN PULONG FileOffset,
IN PVOID Buffer,
IN SIZE_T BufferLength);

BOOLEAN
NTAPI
CmpFileSetSize(
IN PHHIVE RegistryHive,
IN ULONG FileType,
IN ULONG FileSize,
IN ULONG OldFileSize);

BOOLEAN
NTAPI
CmpFileFlush(
IN PHHIVE RegistryHive,
IN ULONG FileType,
PLARGE_INTEGER FileOffset,
ULONG Length);

BOOLEAN
ChkRegOpenHive(
IN PCSTR HiveName,
IN BOOLEAN WriteToHive,
OUT PVOID *HiveData);

/* hivmem.c */
PVOID
NTAPI
CmpAllocate(
IN SIZE_T Size,
IN BOOLEAN Paged,
IN ULONG Tag);

VOID
NTAPI
CmpFree(
IN PVOID Ptr,
IN ULONG Quota);

/* hivinit.c */
NTSTATUS
ChkRegInitializeHive(
IN OUT PHHIVE RegistryHive,
IN PVOID HiveData);

/* EOF */

0 comments on commit bac35a8

Please sign in to comment.