- int fd;
- int i;
- unsigned int len;
- if(regs)
- {
- printf("Multiple open_registry(>\n");
- return;
- }
- fd = open(localregpathname, O_RDONLY);
- if (fd == -1)
- {
- printf("Creating new registry\n");
- create_registry();
- return;
- }
- read(fd, ®_size, 4);
- regs=(struct reg_value*)malloc(reg_size*sizeof(struct reg_value));
- head = 0;
- for(i=0; i<reg_size; i++)
- {
- read(fd,®s[i].type,4);
- read(fd,&len,4);
- regs[i].name=(char*)malloc(len+1);
- if(regs[i].name==0)
- {
- reg_size=i+1;
- goto error;
- }
- read(fd, regs[i].name, len);
- regs[i].name[len]=0;
- read(fd,®s[i].len,4);
- regs[i].value=(char*)malloc(regs[i].len+1);
- if(regs[i].value==0)
- {
- free(regs[i].name);
- reg_size=i+1;
- goto error;
- }
- read(fd, regs[i].value, regs[i].len);
- regs[i].value[regs[i].len]=0;
- }
+ int fd;
+ int i;
+ unsigned int len;
+ if(regs)
+ {
+ printf("Multiple open_registry(>\n");
+ return;
+ }
+ fd = open(localregpathname, O_RDONLY);
+ if (fd == -1)
+ {
+ printf("Creating new registry\n");
+ create_registry();
+ return;
+ }
+ read(fd, ®_size, 4);
+ regs=(struct reg_value*)malloc(reg_size*sizeof(struct reg_value));
+ head = 0;
+ for(i=0; i<reg_size; i++)
+ {
+ read(fd,®s[i].type,4);
+ read(fd,&len,4);
+ regs[i].name=(char*)malloc(len+1);
+ if(regs[i].name==0)
+ {
+ reg_size=i+1;
+ goto error;
+ }
+ read(fd, regs[i].name, len);
+ regs[i].name[len]=0;
+ read(fd,®s[i].len,4);
+ regs[i].value=(char*)malloc(regs[i].len+1);
+ if(regs[i].value==0)
+ {
+ free(regs[i].name);
+ reg_size=i+1;
+ goto error;
+ }
+ read(fd, regs[i].value, regs[i].len);
+ regs[i].value[regs[i].len]=0;
+ }
- int fd, i;
- if (!regs)
- init_registry();
- fd = open(localregpathname, O_WRONLY | O_CREAT, 00666);
- if (fd == -1)
- {
- printf("Failed to open registry file '%s' for writing.\n",
- localregpathname);
- return;
- }
- write(fd, ®_size, 4);
- for(i=0; i<reg_size; i++)
- {
- unsigned len=strlen(regs[i].name);
- write(fd, ®s[i].type, 4);
- write(fd, &len, 4);
- write(fd, regs[i].name, len);
- write(fd, ®s[i].len, 4);
- write(fd, regs[i].value, regs[i].len);
- }
- close(fd);
+ int fd, i;
+ if (!regs)
+ init_registry();
+ fd = open(localregpathname, O_WRONLY | O_CREAT, 00666);
+ if (fd == -1)
+ {
+ printf("Failed to open registry file '%s' for writing.\n",
+ localregpathname);
+ return;
+ }
+ write(fd, ®_size, 4);
+ for(i=0; i<reg_size; i++)
+ {
+ unsigned len=strlen(regs[i].name);
+ write(fd, ®s[i].type, 4);
+ write(fd, &len, 4);
+ write(fd, regs[i].name, len);
+ write(fd, ®s[i].len, 4);
+ write(fd, regs[i].value, regs[i].len);
+ }
+ close(fd);
- reg_handle_t* t;
- for(t=head; t; t=t->prev)
- {
- if(!strcmp(t->name, name))
- {
- return t;
- }
- }
- return 0;
+ reg_handle_t* t;
+ for(t=head; t; t=t->prev)
+ {
+ if(!strcmp(t->name, name))
+ {
+ return t;
+ }
+ }
+ return 0;
- int i;
- for(i=0; i<reg_size; i++)
- if(!strcmp(regs[i].name, name))
- return regs+i;
- return 0;
+ int i;
+ for(i=0; i<reg_size; i++)
+ if(!strcmp(regs[i].name, name))
+ return regs+i;
+ return 0;
- char* full_name;
- reg_handle_t* t;
- if((t=find_handle(key))==0)
- {
- TRACE("Invalid key\n");
- return NULL;
- }
- if(subkey==NULL)
- subkey="<default>";
- full_name=(char*)malloc(strlen(t->name)+strlen(subkey)+10);
- strcpy(full_name, t->name);
- strcat(full_name, "\\");
- strcat(full_name, subkey);
- return full_name;
+ char* full_name;
+ reg_handle_t* t;
+ if((t=find_handle(key))==0)
+ {
+ TRACE("Invalid key\n");
+ return NULL;
+ }
+ if(subkey==NULL)
+ subkey="<default>";
+ full_name=(char*)malloc(strlen(t->name)+strlen(subkey)+10);
+ strcpy(full_name, t->name);
+ strcat(full_name, "\\");
+ strcat(full_name, subkey);
+ return full_name;
}
static struct reg_value* insert_reg_value(int handle, const char* name, int type, const void* value, int len)
{
}
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)
- {
- 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=(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);
- }
- TRACE("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);
+ reg_handle_t* t;
+ 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=(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);
+ }
+ TRACE("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);
- TRACE("Initializing registry\n");
- // can't be free-ed - it's static and probably thread
- // unsafe structure which is stored in glibc
+ TRACE("Initializing registry\n");
+ // can't be free-ed - it's static and probably thread
+ // unsafe structure which is stored in glibc
- // registry.c is holding its own internal pointer
- // localregpathname - which is being allocate/deallocated
+ // registry.c is holding its own internal pointer
+ // localregpathname - which is being allocate/deallocated
- localregpathname = (char*)malloc(strlen(pthn)+20);
- strcpy(localregpathname, pthn);
- strcat(localregpathname, "/.registry");
- }
+ localregpathname = (char*)malloc(strlen(pthn)+20);
+ strcpy(localregpathname, pthn);
+ strcat(localregpathname, "/.registry");
+ }
- open_registry();
- insert_handle(HKEY_LOCAL_MACHINE, "HKLM");
- insert_handle(HKEY_CURRENT_USER, "HKCU");
+ open_registry();
+ insert_handle(HKEY_LOCAL_MACHINE, "HKLM");
+ insert_handle(HKEY_CURRENT_USER, "HKCU");
- char* full_name;
- reg_handle_t* t;
- if((t=find_handle(key))==0)
- {
- TRACE("Invalid key\n");
- return (reg_handle_t*)-1;
- }
- if(subkey==NULL)
- return t;
- full_name=(char*)malloc(strlen(t->name)+strlen(subkey)+10);
- strcpy(full_name, t->name);
- strcat(full_name, "\\");
- strcat(full_name, subkey);
- t=find_handle_by_name(full_name);
- free(full_name);
- return t;
+ char* full_name;
+ reg_handle_t* t;
+ if((t=find_handle(key))==0)
+ {
+ TRACE("Invalid key\n");
+ return (reg_handle_t*)-1;
+ }
+ if(subkey==NULL)
+ return t;
+ full_name=(char*)malloc(strlen(t->name)+strlen(subkey)+10);
+ strcpy(full_name, t->name);
+ strcat(full_name, "\\");
+ strcat(full_name, subkey);
+ t=find_handle_by_name(full_name);
+ free(full_name);
+ return t;
}
long __stdcall RegOpenKeyExA(long key, const char* subkey, long reserved, long access, int* newkey)
}
long __stdcall RegOpenKeyExA(long key, const char* subkey, long reserved, long access, int* newkey)
- memcpy(data, t->value, (t->len<*count)?t->len:*count);
- TRACE("returning %d bytes: %d\n", t->len, *(int*)data);
+ memcpy(data, t->value, (t->len<*count)?t->len:*count);
+ TRACE("returning %d bytes: %d\n", t->len, *(int*)data);
}
return 0;
}
long __stdcall RegCreateKeyExA(long key, const char* name, long reserved,
}
return 0;
}
long __stdcall RegCreateKeyExA(long key, const char* name, long reserved,
- void* classs, long options, long security,
- void* sec_attr, int* newkey, int* status)
+ void* classs, long options, long security,
+ void* sec_attr, int* newkey, int* status)
TRACE("Creating/Opening key %s\n", fullname);
v=find_value_by_name(fullname);
if(v==0)
{
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;
+ int qw=45708;
+ v=insert_reg_value(key, name, DIR, &qw, 4);
+ if (status) *status=REG_CREATED_NEW_KEY;
+ // return 0;
*/
long __stdcall RegEnumValueA(HKEY hkey, DWORD index, LPSTR value, LPDWORD val_count,
*/
long __stdcall RegEnumValueA(HKEY hkey, DWORD index, LPSTR value, LPDWORD val_count,
- LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count)
+ LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count)
{
// currenly just made to support MSZH & ZLIB
//printf("Reg Enum 0x%x %d %s %d data: %p %d %d >%s<\n", hkey, index,
{
// currenly just made to support MSZH & ZLIB
//printf("Reg Enum 0x%x %d %s %d data: %p %d %d >%s<\n", hkey, index,
- struct reg_value* v=find_value_by_name(t->name);
- if (v)
- {
- memcpy(data, v->value, (v->len < *count) ? v->len : *count);
- if(*count < v->len)
- *count = v->len;
- if (type)
- *type = v->type;
- //printf("Found handle %s\n", v->name);
- return 0;
- }
+ struct reg_value* v=find_value_by_name(t->name);
+ if (v)
+ {
+ memcpy(data, v->value, (v->len < *count) ? v->len : *count);
+ if(*count < v->len)
+ *count = v->len;
+ if (type)
+ *type = v->type;
+ //printf("Found handle %s\n", v->name);
+ return 0;
+ }
insert_reg_value(key, name, v2, data, size);
free(c);
return 0;
}
long __stdcall RegEnumKeyExA(HKEY hKey, DWORD dwIndex, LPSTR lpName, LPDWORD lpcbName,
insert_reg_value(key, name, v2, data, size);
free(c);
return 0;
}
long __stdcall RegEnumKeyExA(HKEY hKey, DWORD dwIndex, LPSTR lpName, LPDWORD lpcbName,
- LPDWORD lpReserved, LPSTR lpClass, LPDWORD lpcbClass,
- LPFILETIME lpftLastWriteTime)
+ LPDWORD lpReserved, LPSTR lpClass, LPDWORD lpcbClass,
+ LPFILETIME lpftLastWriteTime)