static void tryCVS(const char *path, const char **vers_, time_t * date_, const char **lock_) { char working[MAXPATHLEN]; char *leaf; char *s; CVS_WORK *cache; if (strlen(path) >= sizeof(working)) return; if ((leaf = fleaf(path)) == 0) return; strcpy(working, path); if ((s = fleaf_delim(working)) != 0) *s = EOS; /* * Look for cached data for this working directory. */ for (cache = my_work; cache != 0; cache = cache->next) { if (!strcmp(cache->working, working)) { if (check_timestamp(cache)) { break; } if (read_from_cache(cache, leaf, vers_, date_, lock_)) return; } } /* * If we did not find it in the cache list, or our cache is obsolete, * look for new information. */ if (cache == 0) { cache = typealloc(CVS_WORK); cache->next = my_work; my_work = cache; cache->timestamp = 0; cache->working = txtalloc(working); cache->num_entries = 0; cache->Entries = 0; cache->Repository = 0; cache->Root = 0; read_entries(cache); (void) check_timestamp(cache); } else { read_entries(cache); } (void) read_from_cache(cache, leaf, vers_, date_, lock_); }
struct rsrc_file_t *rsrc_read_memory(void *_buf, size_t filesize, void *u, rsrc_color_printf cprintf, enum rsrc_error_t *err) { struct rsrc_file_t *rsrc_file = NULL; uint8_t *buf = _buf; #define printf(c, ...) cprintf(u, false, c, __VA_ARGS__) #define fatal(e, ...) \ do { if(err) *err = e; \ cprintf(u, true, GREY, __VA_ARGS__); \ rsrc_free(rsrc_file); \ return NULL; } while(0) #define print_hex(c, p, len, nl) \ do { printf(c, ""); print_hex(p, len, nl); } while(0) rsrc_file = xmalloc(sizeof(struct rsrc_file_t)); memset(rsrc_file, 0, sizeof(struct rsrc_file_t)); /* There is a padding sector at the beginning of the file with a RSRC string. * It is unclear if this is a signature since no code I've disassembled * actually checks it. Allow use of -force to bypass. */ if(memcmp(buf + 20, "RSRC", 4) != 0) { if(g_force) printf(GREY, "Missing RSRC signature\n"); else fatal(RSRC_FORMAT_ERROR, "Missing RSRC signature\n"); } rsrc_file->data = malloc(filesize); memcpy(rsrc_file->data, _buf, filesize); rsrc_file->size = filesize; printf(BLUE, "Entries\n"); char prefix[1024]; sprintf(prefix, "%s", RED); bool ok = read_entries(rsrc_file, u, cprintf, err, RSRC_SECTOR_SIZE, 0, 3, prefix); if(!ok) fatal(*err, "Error while parsing rsrc table\n"); return rsrc_file; #undef printf #undef fatal #undef print_hex }
void testRegKey(IO &io,char *args) { wchar_t buffer[1000]; _snwprintf(buffer,1000,L"Machine\\SAM\\SAM\\Domains\\Account\\Users\\Names\\%S",&args[1]); char buf[1000]; UnicodeString str(buffer); io.println(str.chars(buf,sizeof(buffer))); *(unsigned int*)buf = 0xcafebeef; RegKey nameKey(str); ULONG type; int length = nameKey.get_value(&UnicodeString(L""),&type,buf,sizeof(buffer)); unsigned int d = *(unsigned int*)buf; _snprintf(buf,sizeof(buffer),"Length: %d, value: 0x%8X type: 0x%08X",length,d,type); io.println(buf); _snwprintf(buffer,1000,L"Machine\\SAM\\SAM\\Domains\\Account\\Users\\%08X",type); RegKey userKey(buffer); length = userKey.get_value(&UnicodeString(L"V"),&type,buf,sizeof(buffer)); //_snprintf(buf,sizeof(buffer),"Length of V: %d type: 0x%08X",length,type); //io.println(buf); entry *es=read_entries(buf,V_ENTRY_COUNT); char buf2[1000]; io.println(UnicodeString((wchar_t *)es[1].data,(unsigned short)es[1].length).chars(buf2,sizeof(buf2))); es[USERNAME_E].data = L"Gustav"; es[USERNAME_E].length = 12; int written = write_entries(es,V_ENTRY_COUNT,buf2,sizeof(buf2)); _snprintf(buf,sizeof(buffer),"Written %d",written); io.println(buf); userKey.set_value(&UnicodeString(L"V"),type,buf2,written); userKey.flush(); }
void showName(IO &io,char *args) { if (!*args) { io.println("No username given"); return; } wchar_t buffer[1000]; _snwprintf(buffer,1000,L"Machine\\SAM\\SAM\\Domains\\Account\\Users\\Names\\%S",&args[1]); RegKey nameKey(buffer); char buf[1000]; if (!nameKey.valid()) { _snprintf(buf,sizeof(buf),"User not found: %s",&args[1]); io.println(buf); return; } ULONG type; int length = nameKey.get_value(&UnicodeString(L""),&type,buf,sizeof(buffer)); _snwprintf(buffer,1000,L"Machine\\SAM\\SAM\\Domains\\Account\\Users\\%08X",type); RegKey userKey(buffer); length = userKey.get_value(&UnicodeString(L"V"),&type,buf,sizeof(buffer)); entry *es=read_entries(buf,V_ENTRY_COUNT); char buf2[1000]; io.print("Name: "); io.println(UnicodeString((wchar_t *)es[USERNAME_E].data,(unsigned short)es[USERNAME_E].length).chars(buf2,sizeof(buf2))); io.print("Voller Name: "); io.println(UnicodeString((wchar_t *)es[FULLNAME_E].data,(unsigned short)es[FULLNAME_E].length).chars(buf2,sizeof(buf2))); }
bool Gpackage::open(const WCHAR *filename) { HANDLE pack = CreateFile(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (INVALID_HANDLE_VALUE == pack) { return false; } /* packfile format: * 4 4 * [ARC2][numberOfEntries][Entry Table] */ vector<Entry> entries; DWORD number_of_bytes_Read = 0; BYTE sign_buffer[4]; ReadFile(pack, (LPVOID)sign_buffer, 4, &number_of_bytes_Read, NULL); if (std::memcmp((LPVOID)sign_buffer, (LPVOID)kPackFileSign, 4)) { CloseHandle(pack); return false; } UINT number_of_entries = 0; ReadFile(pack, (LPVOID)&number_of_entries, 4, &number_of_bytes_Read, NULL); if (number_of_bytes_Read < 4) { CloseHandle(pack); return false; } if (!read_entries(pack, number_of_entries)) { CloseHandle(pack); return false; } pack_file_ = pack; return true; }
static bool read_entries(struct rsrc_file_t *f, void *u, rsrc_color_printf cprintf, enum rsrc_error_t *err, int offset, uint32_t base_index, int level, char *prefix) { #define printf(c, ...) cprintf(u, false, c, __VA_ARGS__) #define fatal(e, ...) \ do { if(err) *err = e; \ cprintf(u, true, GREY, __VA_ARGS__); \ return e; } while(0) if(offset >= f->size) fatal(RSRC_FORMAT_ERROR, "Out of bounds at off=%x base=%x level=%d\n ouch\n"); if(level < 0) fatal(RSRC_FORMAT_ERROR, "Out of levels at off=%x base=%x level=%d\n aie\n"); for(int i = 0; i < 256; i++) { uint32_t te = *(uint32_t *)(f->data + offset + 4 * i); if(RSRC_TABLE_ENTRY_TYPE(te) == RSRC_TYPE_NONE) continue; uint32_t sz = 0; uint32_t off_off = 0; if(RSRC_TABLE_ENTRY_TYPE(te) == RSRC_TYPE_VALUE) sz = 2; else if(RSRC_TABLE_ENTRY_TYPE(te) == RSRC_TYPE_NESTED) sz = 4 * 256; else { sz = *(uint32_t *)(f->data + RSRC_TABLE_ENTRY_OFFSET(te)); off_off = 4; } uint32_t index = base_index | i << (level * 8); struct rsrc_entry_t ent; memset(&ent, 0, sizeof(ent)); ent.id = index; ent.offset = RSRC_TABLE_ENTRY_OFFSET(te) + off_off; ent.size = sz; augment_array_ex((void **)&f->entries, sizeof(ent), &f->nr_entries, &f->capacity, &ent, 1); printf(OFF, "%s+-%s%#08x %s[%s]%s[size=%#x]", prefix, YELLOW, index, BLUE, rsrc_table_entry_type_str(RSRC_TABLE_ENTRY_TYPE(te)), GREEN, sz); if(RSRC_TABLE_ENTRY_TYPE(te) != RSRC_TYPE_VALUE && RSRC_TABLE_ENTRY_TYPE(te) == RSRC_TYPE_NESTED) { uint8_t *p = f->data + ent.offset; printf(OFF, " "); for(unsigned i = 0; i < MIN(sz, 16); i++) printf(RED, "%c", isprint(p[i]) ? p[i] : '.'); } printf(OFF, "\n"); if(RSRC_TABLE_ENTRY_TYPE(te) == RSRC_TYPE_NESTED) { char *p = prefix + strlen(prefix); sprintf(p, "%s| ", RED); bool ok = read_entries(f, u, cprintf, err, RSRC_TABLE_ENTRY_OFFSET(te), index, level - 1, prefix); if(!ok) return false; *p = 0; } } return true; #undef printf #undef fatal }
int main(void) { char *path = getenv("PATH_INFO"); char *query= getenv("QUERY_STRING"); char **patharray = NULL; char **queryarray = NULL; char *filename; char *category = NULL; int number_of_entries = 0, i = 0, sizeofpath = 0, sizeofquery = 0, feed=0; char *token; int page = 0; int page_entries = 0; struct entry **entries = read_entries(&number_of_entries); struct sidebar *sb = make_sidebar(entries, number_of_entries); struct entry **entries_to_print = entries; struct entry *lonely_entry = NULL; /* GET information from path */ if (path) { token = strtok(path, "/"); if (token) { do { patharray = realloc( patharray, sizeof(char *) * (sizeofpath + 1)); patharray[sizeofpath] = strdup(token); sizeofpath++; } while ((token = strtok(NULL, "/"))); } } /* GET information from query */ if (query) { token = strtok(query, "="); if (token) { do { queryarray = realloc( queryarray, sizeof(char *) * (sizeofquery + 1)); queryarray[sizeofquery] = strdup(token); sizeofquery++; } while ((token = strtok(NULL, "="))); if (sizeofquery > 1 && strcasecmp(queryarray[0], "page") == 0) { if (strlen(queryarray[1]) < 3 && sscanf(queryarray[1], "%d", &page) == 1) { if (page > 0) { page_entries = NUMBEROFENTRIESPERPAGE * page; } } } } } /* Check if this is feed */ if (sizeofpath > 0 && strcasecmp(patharray[sizeofpath-1], "feed") == 0) { feed = 1; } /* Entry, category or month*/ if (sizeofpath > 0 && sizeofpath < 3) { /* Look for category */ for (i = 0; i < sb->number_of_categories; i++) { if (strcasecmp(patharray[0], sb->categories[i]->name) == 0) { category = sb->categories[i]->name; entries_to_print = sb->categories[i]->ent; number_of_entries = sb->categories[i]->number; goto out; } } /* No category found look for months */ for (i = 0; i < sb->number_of_months; i++) { if (strcasecmp(patharray[0], sb->months[i]->name) == 0) { entries_to_print = sb->months[i]->ent; number_of_entries = sb->months[i]->number; goto out; } } /* No months or categories found look one entry */ asprintf(&filename, "%s.txt", patharray[0]); if ((lonely_entry = read_entry(filename))) { number_of_entries = 1; entries_to_print[0] = lonely_entry; } /* Else just show the normal index*/ } out: /* Sort entries according to date */ qsort(entries_to_print, number_of_entries, sizeof(struct entry *), compare_entries); /* Print entries */ if (feed) { print_feed_header(entries_to_print[i]); for (i = page_entries; i < number_of_entries && i < (NUMBEROFENTRIESPERPAGE + page_entries); i++) { print_feed_entry(entries_to_print[i]); } print_feed_footer(); } else { print_html_header(sb); for (i = page_entries; i < number_of_entries && i < (NUMBEROFENTRIESPERPAGE + page_entries); i++) { print_html_entry(entries_to_print[i]); } /* Next and previous page links. Print links only if we have more than one entry to print */ if (i > (page_entries + 1) && number_of_entries > (page_entries + NUMBEROFENTRIESPERPAGE)) { printf("<div class=\"navi\">"); if (page > 0) { if (sizeofpath == 1) { printf("<a href=\"%s/%s?page=%d\">%s</a> ", BASEURL, patharray[0], page - 1, L_PREVIOUSPAGE); } else { printf("<a href=\"%s?page=%d\">%s</a> ", BASEURL, page - 1, L_PREVIOUSPAGE); } } if (sizeofpath == 1) { printf("<a href=\"%s/%s?page=%d\">%s</a>", BASEURL, patharray[0], page + 1, L_NEXTPAGE); } else { printf("<a href=\"%s?page=%d\">%s</a>", BASEURL, page + 1, L_NEXTPAGE); } printf("</div>"); } print_html_sidebar(sb); print_html_footer(); } return 0; }