Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tatsh committed Oct 29, 2023
1 parent a417f63 commit 8c23103
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 15 deletions.
12 changes: 12 additions & 0 deletions CMakeSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@
"inheritEnvironments": ["msvc_x64_x64"],
"installRoot": "${projectDir}\\out\\install\\${name}",
"name": "x64-DebugNoVLD"
},
{
"buildCommandArgs": "",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"cmakeCommandArgs": "",
"configurationType": "RelWithDebInfo",
"ctestCommandArgs": "",
"generator": "Ninja",
"inheritEnvironments": ["msvc_x64_x64"],
"installRoot": "${projectDir}\\out\\install\\${name}",
"name": "x64-Release",
"variables": []
}
]
}
4 changes: 2 additions & 2 deletions native/arg.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ int main(int argc, char **argv) {
reverse = 1;
ARG_FLAG();
}
else if (ARG_LONG("input")) case 'i': {
else if (ARG_LONG("input")) case 'i' : {
input = ARG_VAL();
}
else if (ARG_LONG("output")) case 'o': {
else if (ARG_LONG("output")) case 'o' : {
output = ARG_VAL();
}
else if (ARG_LONG("help")) case 'h':
Expand Down
1 change: 1 addition & 0 deletions native/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#ifndef _MSC_VER
#include <stdbool.h>
#else
#include <windows.h>
#define bool BOOL
#define true TRUE
#define false FALSE
Expand Down
10 changes: 5 additions & 5 deletions native/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,21 @@ int wmain(int argc, wchar_t *argv[]) {
case 'K': {
deploy_key = ARG_VAL();
}
else if (ARG_LONG("commit")) case 'c': {
else if (ARG_LONG("commit")) case 'c' : {
commit = true;
ARG_FLAG();
}
else if (ARG_LONG("debug")) case 'd': {
else if (ARG_LONG("debug")) case 'd' : {
debug = true;
ARG_FLAG();
}
else if (ARG_LONG("output-file")) case 'f': {
else if (ARG_LONG("output-file")) case 'f' : {
output_file = ARG_VAL();
}
else if (ARG_LONG("output-dir")) case 'o': {
else if (ARG_LONG("output-dir")) case 'o' : {
output_dir = ARG_VAL();
}
else if (ARG_LONG("max-depth")) case 'm': {
else if (ARG_LONG("max-depth")) case 'm' : {
wchar_t *val = ARG_VAL();
size_t w_len = wcslen(val);
char *as_char = malloc(w_len + 1);
Expand Down
28 changes: 21 additions & 7 deletions native/reg_command.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ wchar_t *convert_data_for_reg(DWORD reg_type, const char *data, size_t data_len)
return out;
}
if (reg_type == REG_EXPAND_SZ || reg_type == REG_SZ || reg_type == REG_MULTI_SZ) {
wchar_t *s = escape_for_batch((wchar_t *)data, data_len == 0 ? 0 : (data_len / WL) - 1);
wchar_t *s = escape_for_batch((wchar_t *)data, data_len == 0 ? 0 : data_len / WL);
if (s == nullptr) {
return nullptr;
}
Expand All @@ -83,7 +83,7 @@ wchar_t *convert_data_for_reg(DWORD reg_type, const char *data, size_t data_len)
return out;
}
if (reg_type == REG_DWORD || reg_type == REG_QWORD) {
size_t s_size = 20;
size_t s_size = 128;
wchar_t *out = calloc(s_size, WL);
if (!out) {
return nullptr;
Expand Down Expand Up @@ -159,7 +159,14 @@ bool do_write_reg_command(HANDLE out_fp,
0,
NULL,
NULL);
char *mb_out = malloc(req_size);
if (req_size == 0) {
fwprintf(stdout, L"%ls\n", out);
}
char *mb_out = malloc(req_size + 3);
if (!mb_out) {
return false;
}
memset(mb_out, 0, req_size + 3);
WideCharToMultiByte(CP_UTF8,
IsWindowsVistaOrGreater() ? _WC_ERR_INVALID_CHARS : 0,
out,
Expand All @@ -168,10 +175,15 @@ bool do_write_reg_command(HANDLE out_fp,
(int)req_size,
NULL,
NULL);
mb_out[req_size - 1] = '\n';
DWORD written;
WriteFile(out_fp, mb_out, (DWORD)(req_size), &written, nullptr);
printf("%lld %s\n", req_size, mb_out);
mb_out[req_size - 1] = '\r';
mb_out[req_size] = '\n';
DWORD written = 0;
bool ret = WriteFile(out_fp, mb_out, (DWORD)(req_size), &written, nullptr);
free(mb_out);
if (!ret || written == 0) {
return false;
}
} else {
debug_print(L"%ls %ls: Skipping due to length of command.\n", full_path, prop);
}
Expand Down Expand Up @@ -207,6 +219,7 @@ bool do_write_reg_commands(HANDLE out_fp, HKEY hk, unsigned n_values, const wcha
for (i = 0; i < n_values; i++) {
data_len = sizeof(data);
wmemset(value, L'\0', MAX_VALUE_NAME);
memset(data, 0, 8192);
value_len = MAX_VALUE_NAME * WL;
reg_type = REG_NONE;
ret = RegEnumValue(
Expand Down Expand Up @@ -263,7 +276,8 @@ bool write_reg_commands(HKEY hk,
wcsstr(full_path, L"Explorer\\ComDlg32\\OpenSavePidlMRU") ||
wcsstr(full_path, L"IrisService\\Cache") ||
wcsstr(full_path, L"Microsoft\\Windows\\Shell\\Bags") ||
wcsstr(full_path, L"Windows\\Shell\\BagMRU")) {
wcsstr(full_path, L"Windows\\Shell\\BagMRU") ||
wcsstr(full_path, L"Windows\\Shell\\MuiCache")) {
debug_print(L"%ls: Skipping %ls due to filter.\n", prior_stem, stem);
free(full_path);
return true;
Expand Down
2 changes: 1 addition & 1 deletion native/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ wchar_t *escape_for_batch(const wchar_t *input, size_t n_chars) {
if (!out) {
return nullptr;
}
wmemset(out, L'\0', new_n_chars + 1);
if (n_chars == new_n_chars) {
wmemcpy(out, input, new_n_chars + 1);
return out;
}
wmemset(out, L'\0', new_n_chars + 1);
for (i = 0, j = 0; i < n_chars && j < new_n_chars; i++, j++) {
// This condition is to handle REG_MULTI_SZ string sets
if (input[i] == '\0' && i < (n_chars - 1) && j < (new_n_chars - 1)) {
Expand Down

0 comments on commit 8c23103

Please sign in to comment.