4void test_powershell_null_escaped_reg_key(
void **state) {
5 DWORD *test_val = malloc(
sizeof(DWORD));
7 bool ret = do_write_powershell_reg_code(
nullptr,
10 (
const char *)test_val,
17void test_powershell_dword(
void **state) {
21 L
"if (!(Test-Path 'HKEY_CURRENT_USER:\\Control Panel\\Desktop')) { New-Item -Path "
22 L
"'HKEY_CURRENT_USER:\\Control Panel\\Desktop' -Force | Out-Null } "
23 L
"New-ItemProperty -LiteralPath 'HKEY_CURRENT_USER:\\Control Panel\\Desktop' -Name "
24 L
"'DoubleClickHeight' -PropertyType DWord -Force -Value 4",
26 will_return(__wrap_write_output,
true);
27 DWORD *test_val = malloc(
sizeof(DWORD));
29 bool ret = do_write_powershell_reg_code(
nullptr,
30 L
"HKEY_CURRENT_USER\\Control Panel\\Desktop",
32 (
const char *)test_val,
39void test_powershell_qword(
void **state) {
43 L
"if (!(Test-Path 'HKEY_CURRENT_USER:\\Control Panel\\Desktop')) { New-Item -Path "
44 L
"'HKEY_CURRENT_USER:\\Control Panel\\Desktop' -Force | Out-Null } "
45 L
"New-ItemProperty -LiteralPath 'HKEY_CURRENT_USER:\\Control Panel\\Desktop' -Name "
46 L
"'DoubleClickHeight' -PropertyType QWord -Force -Value 4",
48 will_return(__wrap_write_output,
true);
49 QWORD *test_val = malloc(
sizeof(QWORD));
51 bool ret = do_write_powershell_reg_code(
nullptr,
52 L
"HKEY_CURRENT_USER\\Control Panel\\Desktop",
54 (
const char *)test_val,
61void test_powershell_sz(
void **state) {
62 expect_memory(__wrap_write_output,
64 L
"if (!(Test-Path 'HKEY_CURRENT_USER:\\Environment')) { New-Item -Path "
65 L
"'HKEY_CURRENT_USER:\\Environment' -Force | Out-Null } "
66 L
"New-ItemProperty -LiteralPath 'HKEY_CURRENT_USER:\\Environment' -Name "
67 L
"'TEMP' -PropertyType String -Force -Value 'a midsummer night''s dream'",
69 will_return(__wrap_write_output,
true);
70 bool ret = do_write_powershell_reg_code(
nullptr,
71 L
"HKEY_CURRENT_USER\\Environment",
73 (
const char *)L
"a midsummer night's dream",
79void test_powershell_expand_sz(
void **state) {
80 expect_memory(__wrap_write_output,
82 L
"if (!(Test-Path 'HKEY_CURRENT_USER:\\Environment')) { New-Item -Path "
83 L
"'HKEY_CURRENT_USER:\\Environment' -Force | Out-Null } "
84 L
"New-ItemProperty -LiteralPath 'HKEY_CURRENT_USER:\\Environment' -Name "
85 L
"'TEMP' -PropertyType ExpandString -Force -Value 'a midsummer night''s %dream%'",
87 will_return(__wrap_write_output,
true);
88 bool ret = do_write_powershell_reg_code(
nullptr,
89 L
"HKEY_CURRENT_USER\\Environment",
91 (
const char *)L
"a midsummer night's %dream%",
97const wchar_t *MULTI_SZ_TEST_DATA = L
"a midsummer night's dream\0test2\0";
99void test_powershell_multi_sz(
void **state) {
103 L
"if (!(Test-Path 'HKEY_CURRENT_USER:\\Environment')) { New-Item -Path "
104 L
"'HKEY_CURRENT_USER:\\Environment' -Force | Out-Null } "
105 L
"New-ItemProperty -LiteralPath 'HKEY_CURRENT_USER:\\Environment' -Name "
106 L
"'TEMP' -PropertyType String -Force -Value @\"\na midsummer night''s dream\ntest2\n)\n\"@",
107 50 *
sizeof(
wchar_t));
108 will_return(__wrap_write_output,
true);
109 bool ret = do_write_powershell_reg_code(
nullptr,
110 L
"HKEY_CURRENT_USER\\Environment",
112 (
const char *)MULTI_SZ_TEST_DATA,
113 33 *
sizeof(
wchar_t),
118void test_powershell_none(
void **state) {
119 expect_memory(__wrap_write_output,
121 L
"if (!(Test-Path 'HKEY_CURRENT_USER:\\Environment')) { New-Item -Path "
122 L
"'HKEY_CURRENT_USER:\\Environment' -Force | Out-Null } "
123 L
"New-ItemProperty -LiteralPath 'HKEY_CURRENT_USER:\\Environment' -Name "
124 L
"'TEMP' -PropertyType None -Force -Value $null",
126 will_return(__wrap_write_output,
true);
127 bool ret = do_write_powershell_reg_code(
nullptr,
128 L
"HKEY_CURRENT_USER\\Environment",
130 (
const char *)MULTI_SZ_TEST_DATA,
136const int BINARY_TEST_DATA[] = {0x30, 0, 0x02, 0x80, 0x12, 0, 0, 0};
138void test_powershell_binary(
void **state) {
142 L
"if (!(Test-Path 'HKEY_CURRENT_USER:\\Control Panel\\Desktop')) { New-Item -Path "
143 L
"'HKEY_CURRENT_USER:\\Control Panel\\Desktop' -Force | Out-Null } New-ItemProperty "
144 L
"-LiteralPath 'HKEY_CURRENT_USER:\\Control Panel\\Desktop' -Name 'UserPreferencesMask' "
145 L
"-PropertyType Binary -Force -Value "
146 L
"(byte[]](0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x80,0x00,0x00,0x00,"
147 L
"0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0)",
149 will_return(__wrap_write_output,
true);
150 bool ret = do_write_powershell_reg_code(
nullptr,
151 L
"HKEY_CURRENT_USER\\Control Panel\\Desktop",
152 L
"UserPreferencesMask",
153 (
const char *)BINARY_TEST_DATA,
154 sizeof(BINARY_TEST_DATA),
159void test_powershell_skip_too_big(
void **state) {
160 wchar_t *buf = calloc(POWERSHELL_MAX_COMMAND_LENGTH + 500,
sizeof(
wchar_t));
161 wmemset(buf, L
'a', POWERSHELL_MAX_COMMAND_LENGTH + 500);
162 bool ret = do_write_powershell_reg_code(
nullptr,
163 L
"HKEY_CURRENT_USER\\Control Panel\\Desktop",
164 L
"UserPreferencesMask",
166 POWERSHELL_MAX_COMMAND_LENGTH + 500,
172const unsigned char MULTI_SZ_TEST_DATA_INVALID[] = {
'e', 0,
'n', 0,
'-', 0,
'U', 0,
'S'};
174void test_powershell_multi_sz_invalid(
void **state) {
175 bool ret = do_write_powershell_reg_code(
nullptr,
176 L
"HKEY_USERS\\Environment",
178 (
const char *)MULTI_SZ_TEST_DATA_INVALID,
184const struct CMUnitTest powershell_tests[] = {
185 cmocka_unit_test(test_powershell_binary),
186 cmocka_unit_test(test_powershell_dword),
187 cmocka_unit_test(test_powershell_expand_sz),
188 cmocka_unit_test(test_powershell_multi_sz),
190 cmocka_unit_test(test_powershell_multi_sz_invalid),
192 cmocka_unit_test(test_powershell_none),
193 cmocka_unit_test(test_powershell_null_escaped_reg_key),
194 cmocka_unit_test(test_powershell_qword),
195 cmocka_unit_test(test_powershell_skip_too_big),
196 cmocka_unit_test(test_powershell_sz),
199int main(
int argc,
char *argv[]) {
200 return cmocka_run_group_tests(powershell_tests,
nullptr,
nullptr);