예제 #1
0
long __stdcall RegCreateKeyExA(long key, const char* name, long reserved,
		     void* classs, long options, long security,
		     void* sec_attr, int* newkey, int* status)
{
    reg_handle_t* t;
    char* fullname;
    struct reg_value* v;
    //        TRACE("Creating/Opening key %s\n", name);
    if(!regs)
	init_registry();

    fullname=build_keyname(key, name);
    if (!fullname)
	return 1;
    TRACE("Creating/Opening key %s\n", fullname);
    v=find_value_by_name(fullname);
    if(v==0)
    {
	int qw=45708;
	v=insert_reg_value(key, name, DIR, &qw, 4);
	if (status) *status=REG_CREATED_NEW_KEY;
	//		return 0;
    }

    t=insert_handle(generate_handle(), fullname);
    *newkey=t->handle;
    free(fullname);
    return 0;
}
예제 #2
0
long __stdcall RegOpenKeyExA(long key, const char* subkey, long reserved, long access, int* newkey)
{
    char* full_name;
    reg_handle_t* t;
    struct reg_value* v;
    TRACE("Opening key %s\n", subkey);

    if(!regs)
        init_registry()
;
/*	t=find_handle_2(key, subkey);

	if(t==0)
		return -1;

	if(t==(reg_handle_t*)-1)
		return -1;
*/
    full_name=build_keyname(key, subkey);
    if(!full_name)
        return -1;
    TRACE("Opening key Fullname %s\n", full_name);
    v=find_value_by_name(full_name);

    t=insert_handle(generate_handle(), full_name);
    *newkey=t->handle;
    free(full_name);

    return 0;
}
예제 #3
0
long __stdcall RegQueryValueExA(long key, const char* value, int* reserved, int* type, int* data, int* count)
{
    struct reg_value* t;
    char* c;
    TRACE("Querying value %s\n", value);
    if(!regs)
	init_registry();

    c=build_keyname(key, value);
    if (!c)
	return 1;
    t=find_value_by_name(c);
    free(c);
    if (t==0)
	return 2;
    if (type)
	*type=t->type;
    if (data)
    {
	memcpy(data, t->value, (t->len<*count)?t->len:*count);
	TRACE("returning %d bytes: %d\n", t->len, *(int*)data);
    }
    if(*count<t->len)
    {
	*count=t->len;
	return ERROR_MORE_DATA;
    }
    else
    {
	*count=t->len;
    }
    return 0;
}
예제 #4
0
static struct reg_value* insert_reg_value(int handle, const char* name, int type, const void* value, int len)
{
  // reg_handle_t* t;
  struct reg_value* v;
  char* fullname;
  if((fullname=build_keyname(handle, name))==NULL)
  {
    OutputDebugString("Registery:Invalid handle\n");
    return NULL;
  }

  if((v=find_value_by_name(fullname))==0)
    //creating new value in registry
  {
    regs=(struct reg_value*)realloc(regs, sizeof(struct reg_value)*(reg_size+1));
    //regs=(struct reg_value*)my_realloc(regs, sizeof(struct reg_value)*(reg_size+1));
    v=regs+reg_size;
    reg_size++;
  }
  else
    //replacing old one
  {
    free(v->value);
    free(v->name);
  }
  //mp_msg(0,0,"RegInsert '%s' %p v:%d len:%d\n", name, value, *(int*)value, len);
  v->type=type;
  v->len=len;
  v->value=(char*)malloc(len);
  memcpy(v->value, value, len);
  v->name=(char*)malloc(strlen(fullname)+1);
  strcpy(v->name, fullname);
  free(fullname);
  return v;
}
예제 #5
0
LONG WINAPI dllRegCreateKeyExA (HKEY key, LPCSTR name, DWORD reserved,
                                LPTSTR classs, DWORD options, REGSAM security,
                                LPSECURITY_ATTRIBUTES sec_attr,
                                PHKEY newkey, LPDWORD status)
{
  reg_handle_t* t;
  char* fullname;
  struct reg_value* v;
  // mp_msg(0,0,"Creating/Opening key %s\n", name);
  if(!regs)
    init_registry
    ();

  fullname=build_keyname((long)key, name);
  if (!fullname)
    return 1;
  //mp_msg(0,0,"Creating/Opening key %s\n", fullname);
  v=find_value_by_name(fullname);
  if(v==0)
  {
    int qw=45708;
    v=insert_reg_value((int)key, name, DIR, &qw, 4);
    if (status)
      *status=REG_CREATED_NEW_KEY;
    // return 0;
  }

  t=insert_handle(generate_handle(), fullname);
  *newkey=(HKEY)t->handle;
  free(fullname);
  return 0;
}
예제 #6
0
LONG WINAPI dllRegOpenKeyExA(HKEY key, LPCSTR subkey, DWORD reserved, REGSAM access, PHKEY newkey)
{
  char* full_name;
  reg_handle_t* t;
  struct reg_value* v;

  if(!regs)
    init_registry();

  full_name=build_keyname((long)key, subkey);
  if(!full_name)
    return -1;

  dbgprintf("RegOpenKeyExA(key 0x%x, subkey %s, reserved %d, access 0x%x, pnewkey 0x%x) => 0\n",
    key, subkey, reserved, access, newkey);

  if(newkey)
  {
    v=find_value_by_name(full_name);
    t=insert_handle(generate_handle(), full_name);
    *newkey=(HKEY)t->handle;
    dbgprintf(" New key: 0x%x\n", *newkey);
  }
  free(full_name);

  return 0;
}
예제 #7
0
long __stdcall RegQueryValueExA(long key, const char* value, int* reserved, int* type, int* data, int* count)
{
    struct reg_value* t;
    char* c;
    TRACE("Querying value %s\n", value);
    if(!regs)
	init_registry();

    c=build_keyname(key, value);
    if (!c)
	return 1;
    t=find_value_by_name(c);
    if (t==0) {
        // Hacks for CineForm.
        if (strcmp(c, "HKCU\\SOFTWARE\\CineForm\\DecoderProperties\\Resolution") == 0) {
            if (data)
                *data = 1000;
            if (type)
                *type = REG_DWORD;
            if (count)
                *count = sizeof(DWORD);
            free(c);
            return ERROR_SUCCESS;
        }
        if (strcmp(c, "HKCU\\SOFTWARE\\CineForm\\DecoderProperties\\PixelFormats") == 0) {
            if (data)
                *data = 0xffff;
            if (type)
                *type = REG_DWORD;
            if (count)
                *count = sizeof(DWORD);
            free(c);
            return ERROR_SUCCESS;
        }
        free(c);
        return ERROR_FILE_NOT_FOUND;
    }
    free(c);
    if (type)
	*type=t->type;
    if (data)
    {
	memcpy(data, t->value, (t->len<*count)?t->len:*count);
	TRACE("returning %d bytes: %d\n", t->len, *(int*)data);
    }
    if(*count<t->len)
    {
	*count=t->len;
	return ERROR_MORE_DATA;
    }
    else
    {
	*count=t->len;
    }
    return ERROR_SUCCESS;
}
예제 #8
0
long __stdcall RegSetValueExA(long key, const char* name, long v1, long v2, const void* data, long size)
{
    char* c;
    TRACE("Request to set value %s %d\n", name, *(const int*)data);
    if(!regs)
	init_registry();

    c=build_keyname(key, name);
    if(c==NULL)
	return 1;
    insert_reg_value(key, name, v2, data, size);
    free(c);
    return 0;
}
예제 #9
0
LONG WINAPI dllRegQueryValueExA (HKEY key, LPCSTR value, LPDWORD reserved,
                                 LPDWORD type, LPBYTE data, LPDWORD count)
{
  struct reg_value* t;
  char* c;

  if(!regs)
    init_registry();

  c=build_keyname((long)key, value);


  if (!c)
    return 1;
  t=find_value_by_name(c);
  free(c);
  if (t==0){
    dbgprintf("RegQueryValueExA(key 0x%x, value %s, reserved 0x%x, data 0x%x, count 0x%x)"
      " => 0x%x\n", key, value, reserved, data, count, 2);
    memset(data, 0, *count);
    return 2;
  }
  if (type)
    *type=t->type;
  if (data)
  {
    memcpy(data, t->value, (t->len<(int)*count)?t->len:(int)*count);
    //mp_msg(0,0,"returning %d bytes: %d\n", t->len, *(int*)data);
  }
  if((int)*count<t->len)
  {
    *count=t->len;
    dbgprintf("RegQueryValueExA(key 0x%x, value %s, reserved 0x%x, data 0x%x, count 0x%x)"
      " => 0x%x\n", key, value, reserved, data, count, ERROR_MORE_DATA);
    if(data && count)dbgprintf(" read %d bytes: '%s'\n", *count, data);

    return ERROR_MORE_DATA;
  }
  else
  {
    *count=t->len;
  }

  dbgprintf("RegQueryValueExA(key 0x%x, value %s, reserved 0x%x, data 0x%x, count 0x%x)"
    " => 0x%x\n", key, value, reserved, data, count, 0);
  if(data && count)dbgprintf(" read %d bytes: '%s'\n", *count, data);

  return 0;
}
예제 #10
0
파일: registry.c 프로젝트: Jheengut/gmerlin
long RegSetValueExA(long key, const char* name, long v1, long v2, const void* data, long size)
{
    /* struct reg_value* t; -- unused */
    char* c;
    TRACE("Request to set value %s\n", name);
    if(!regs)
	init_registry();

    c=build_keyname(key, name);
    if(c==NULL)
	return 1;
    insert_reg_value(key, name, v2, data, size);
    free(c);
    return 0;
}
예제 #11
0
LONG WINAPI dllRegSetValueExA(HKEY key, LPCTSTR name, DWORD v1,
                              DWORD v2, const BYTE * data, DWORD size)
{
  // struct reg_value* t;
  char* c;
  //mp_msg(0,0,"Request to set value %s %d\n", name, *(const int*)data);
  if(!regs)
    init_registry
    ();

  c=build_keyname((long)key, name);
  if(c==NULL)
    return 1;
  insert_reg_value((int)key, name, v2, data, size);
  free(c);
  return 0;
}
예제 #12
0
static void remove_key(long handle, const char* name) {
    int i, len;
    char *fullname;

    fullname = build_keyname(handle, name);
    len = strlen(fullname);
    for (i=0; i < reg_size;) {
        if (!strncmp(regs[i].name, fullname, len)) {
            free(regs[i].value);
            free(regs[i].name);
            memmove(&regs[i], &regs[i+1], --reg_size*sizeof(struct reg_value));
        } else {
            i++;
        }
    }
    free(fullname);
    save_registry();
}
예제 #13
0
static struct reg_value* insert_reg_value(int handle, const char* name, int type, const void* value, int len)
{
	struct reg_value* v;
	char* fullname;
	if((fullname=build_keyname(handle, name))==NULL)
	{
		TRACE("Invalid handle\n");
		return NULL;
	}

	if((v=find_value_by_name(fullname))==0)
	//creating new value in registry
	{
		if(regs==0)
		    create_registry();
		regs = realloc(regs, sizeof(struct reg_value) * (reg_size +1 ));
		//regs=(struct reg_value*)my_realloc(regs, sizeof(struct reg_value)*(reg_size+1));
		v=regs+reg_size;
		reg_size++;
	}
	else
	//replacing old one
	{
	    free(v->value);
	    free(v->name);
	}
	TRACE("RegInsert '%s'  %p  v:%d  len:%d\n", name, value, *(int*)value, len);
	v->type=type;
	v->len=len;
	v->value=malloc(len);
	memcpy(v->value, value, len);
	v->name=malloc(strlen(fullname)+1);
	strcpy(v->name, fullname);
        free(fullname);
	save_registry();
	return v;
}
예제 #14
0
static bool load_registry_key(long handle, TiXmlElement *key)
{
  if(!key)
    return false;

  const char* path = key->Attribute("path");
  if(!path)
  {
    reg_handle_t* t = find_handle(handle);
    CLog::Log(LOGERROR, __FUNCTION__" - key element is missing path, parent %s", t ? t->name : "");
    return false;
  }

  if(!handle)
  {
    int span = strcspn(path, "\\");
    if(strncmp(path, "HKCU",span) == 0 || strncmp(path, "HKEY_CURRENT_USER", span) == 0)
    {
      handle = (long)HKEY_CURRENT_USER;
      path+=span;
    }
    else if(strncmp(path, "HKLM",span) == 0 || strncmp(path, "HKEY_LOCAL_MACHINE", span) == 0)
    {
      handle = (long)HKEY_LOCAL_MACHINE;
      path+=span;
    }
    else
    {
      CLog::Log(LOGERROR, __FUNCTION__" - invalid root element %s", path);
      return false;
    }
  }

  char * fullname = build_keyname(handle, path);
  reg_handle_t *t = insert_handle(generate_handle(), fullname);
  free(fullname);

  TiXmlNode *node = NULL;
  while(node = key->IterateChildren(node))
  {
    TiXmlElement *element = node->ToElement();
    if(!element)
      continue;

    if(strcmp("value", element->Value()) == 0)
    {
      const char* type = element->Attribute("type");
      const char* id = element->Attribute("id");

      if(!type) type = "string";
      if(!id || !id[0]) id = "<default>";
      
      if(strcmp(type, "string") == 0)
      {
        const char* str = element->GetText();
        if(!str) 
          continue;
        insert_reg_value(t->handle, id, REG_SZ, str, strlen(str)+1);
      }
      else if(strcmp(type, "dword") == 0)
      {
        DWORD val = atol(element->GetText());
        insert_reg_value(t->handle, id, REG_DWORD, &val, sizeof(DWORD));
      }
      else
        CLog::Log(LOGERROR, __FUNCTION__" - Unsupported value type");
    }
    else if(strcmp("key", element->Value()) == 0)
      load_registry_key(t->handle, element);
  }
  remove_handle(t);

  return true;
}