static bool test_str_regtype(struct torture_context *ctx) { torture_assert_str_equal(ctx, str_regtype(1), "REG_SZ", "REG_SZ failed"); torture_assert_str_equal(ctx, str_regtype(4), "REG_DWORD", "REG_DWORD failed"); return true; }
static WERROR cmd_ls(struct regshell_context *ctx, int argc, char **argv) { unsigned int i; WERROR error; uint32_t valuetype; DATA_BLOB valuedata; const char *name = NULL; for (i = 0; W_ERROR_IS_OK(error = reg_key_get_subkey_by_index(ctx, ctx->current, i, &name, NULL, NULL)); i++) { printf("K %s\n", name); } if (!W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS)) { fprintf(stderr, "Error occurred while browsing through keys: %s\n", win_errstr(error)); return error; } for (i = 0; W_ERROR_IS_OK(error = reg_key_get_value_by_index(ctx, ctx->current, i, &name, &valuetype, &valuedata)); i++) printf("V \"%s\" %s %s\n", name, str_regtype(valuetype), reg_val_data_string(ctx, valuetype, valuedata)); return WERR_OK; }
/** Generate a string that describes a registry value */ _PUBLIC_ char *reg_val_description(TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *iconv_convenience, const char *name, uint32_t data_type, const DATA_BLOB data) { return talloc_asprintf(mem_ctx, "%s = %s : %s", name?name:"<No Name>", str_regtype(data_type), reg_val_data_string(mem_ctx, iconv_convenience, data_type, data)); }
static const char *vl_get_item_label(const void *row, unsigned col) { const struct value_item *value = row; SMB_ASSERT(value != NULL); SMB_ASSERT(value->value_name != NULL); switch (col) { case 0: return value->value_name; case 1: return str_regtype(value->type); case 2: if (value->value) { return value->value; } return ""; } return "???"; }
static WERROR cmd_print(struct regshell_context *ctx, int argc, char **argv) { uint32_t value_type; DATA_BLOB value_data; WERROR error; if (argc != 2) { fprintf(stderr, "Usage: print <valuename>\n"); return WERR_INVALID_PARAM; } error = reg_key_get_value_by_name(ctx, ctx->current, argv[1], &value_type, &value_data); if (!W_ERROR_IS_OK(error)) { fprintf(stderr, "No such value '%s'\n", argv[1]); return error; } printf("%s\n%s\n", str_regtype(value_type), reg_val_data_string(ctx, value_type, value_data)); return WERR_OK; }
void dump_reg_val(int lvl, const char *direction, const char *key, const char *subkey, struct registry_value *val) { int i = 0; const char *type_str = NULL; if (!val) { DEBUG(lvl,("no val!\n")); return; } type_str = str_regtype(val->type); DEBUG(lvl,("\tdump_reg_val:\t%s '%s'\n\t\t\t'%s' %s: ", direction, key, subkey, type_str)); switch (val->type) { case REG_DWORD: { uint32_t v; if (val->data.length < 4) { break; } v = IVAL(val->data.data, 0); DEBUG(lvl,("%d (0x%08x)\n", (int)v, v)); break; } case REG_QWORD: { uint64_t v; if (val->data.length < 8) { break; } v = BVAL(val->data.data, 0); DEBUG(lvl,("%d (0x%016llx)\n", (int)v, (unsigned long long)v)); break; } case REG_SZ: { const char *s; if (!pull_reg_sz(talloc_tos(), &val->data, &s)) { break; } DEBUG(lvl,("%s (length: %d)\n", s, (int)strlen_m(s))); break; } case REG_MULTI_SZ: { const char **a; if (!pull_reg_multi_sz(talloc_tos(), &val->data, &a)) { break; } for (i=0; a[i] != NULL; i++) { ;; } DEBUG(lvl,("(num_strings: %d)\n", i)); for (i=0; a[i] != NULL; i++) { DEBUGADD(lvl,("\t%s\n", a[i])); } break; } case REG_NONE: DEBUG(lvl,("\n")); break; case REG_BINARY: dump_data(lvl, val->data.data, val->data.length); break; default: DEBUG(lvl,("unsupported type: %d\n", val->type)); break; } }
void print_registry_value(const struct registry_value *valvalue, bool raw) { if (!raw) { d_printf(_("Type = %s\n"), str_regtype(valvalue->type)); } switch(valvalue->type) { case REG_DWORD: { uint32_t v = 0; if (valvalue->data.length >= 4) { v = IVAL(valvalue->data.data, 0); } if (!raw) { d_printf(_("Value = ")); } d_printf("%d\n", v); break; } case REG_SZ: case REG_EXPAND_SZ: { const char *s; if (!pull_reg_sz(talloc_tos(), &valvalue->data, &s)) { break; } if (!raw) { d_printf(_("Value = \"")); } d_printf("%s", s); if (!raw) { d_printf("\""); } d_printf("\n"); break; } case REG_MULTI_SZ: { uint32 j; const char **a; if (!pull_reg_multi_sz(talloc_tos(), &valvalue->data, &a)) { break; } for (j = 0; a[j] != NULL; j++) { if (!raw) { d_printf(_("Value[%3.3d] = \""), j); } d_printf("%s", a[j]); if (!raw) { d_printf("\""); } d_printf("\n"); } break; } case REG_BINARY: if (!raw) { d_printf(_("Value = ")); } d_printf(_("%d bytes\n"), (int)valvalue->data.length); break; default: if (!raw) { d_printf(_("Value = ")); } d_printf(_("<unprintable>\n")); break; } }