timelib_tzinfo *timelib_parse_tzfile(char *timezone, const timelib_tzdb *tzdb) { const unsigned char *tzf; timelib_tzinfo *tmp; int version; if (seek_to_tz_position(&tzf, timezone, tzdb)) { tmp = timelib_tzinfo_ctor(timezone); version = read_preamble(&tzf, tmp); read_header(&tzf, tmp); read_transistions(&tzf, tmp); read_types(&tzf, tmp); if (version == 2) { skip_64bit_preamble(&tzf, tmp); read_64bit_header(&tzf, tmp); skip_64bit_transistions(&tzf, tmp); skip_64bit_types(&tzf, tmp); skip_posix_string(&tzf, tmp); } read_location(&tzf, tmp); } else { tmp = NULL; } return tmp; }
/*************************************************************** * DMOGetTypes (MSDMO.@) */ HRESULT WINAPI DMOGetTypes(REFCLSID clsidDMO, ULONG ulInputTypesRequested, ULONG* pulInputTypesSupplied, DMO_PARTIAL_MEDIATYPE* pInputTypes, ULONG ulOutputTypesRequested, ULONG* pulOutputTypesSupplied, DMO_PARTIAL_MEDIATYPE* pOutputTypes) { HKEY root,hkey; HRESULT ret = S_OK; WCHAR szguid[64]; TRACE ("(%s,%u,%p,%p,%u,%p,%p)\n", debugstr_guid(clsidDMO), ulInputTypesRequested, pulInputTypesSupplied, pInputTypes, ulOutputTypesRequested, pulOutputTypesSupplied, pOutputTypes); if (ERROR_SUCCESS != RegOpenKeyExW(HKEY_CLASSES_ROOT, szDMORootKey, 0, KEY_READ, &root)) return E_FAIL; if (ERROR_SUCCESS != RegOpenKeyExW(root,GUIDToString(szguid,clsidDMO) , 0, KEY_READ, &hkey)) { RegCloseKey(root); return E_FAIL; } if (ulInputTypesRequested > 0) { ret = read_types(hkey, szDMOInputType, pulInputTypesSupplied, ulInputTypesRequested, pInputTypes ); } else *pulInputTypesSupplied = 0; if (ulOutputTypesRequested > 0) { HRESULT ret2; ret2 = read_types(hkey, szDMOOutputType, pulOutputTypesSupplied, ulOutputTypesRequested, pOutputTypes ); if (ret == S_OK) ret = ret2; } else *pulOutputTypesSupplied = 0; return ret; }
int initmalloc(void) { field_view *v; for (v = views_malloc; v->name != NULL; v++) add_view(v); read_buckets(); read_types(); return(0); }
/* Load all of the config filse */ gboolean load_remote_configs(tclient_c *tclient) { if(!read_types(tclient)) return FALSE; if(!read_connections(tclient)) return FALSE; if(!read_settings(tclient)) return FALSE; return TRUE; }
static char const * get_biff_opcode_name (unsigned opcode) { int lp; if (!biff_types) read_types (BIFF_TYPES_FILE, &biff_types); /* Count backwars to give preference to non-filtered record types */ for (lp=biff_types->len; --lp >= 0 ;) { GENERIC_TYPE *bt = g_ptr_array_index (biff_types, lp); if (bt->opcode == opcode) return bt->name; } return "Unknown"; }
timelib_tzinfo *timelib_parse_tzfile(char *timezone, const timelib_tzdb *tzdb) { const unsigned char *tzf; char *memmap = NULL; size_t maplen; timelib_tzinfo *tmp; if (seek_to_tz_position(&tzf, timezone, &memmap, &maplen, tzdb)) { tmp = timelib_tzinfo_ctor(timezone); read_preamble(&tzf, tmp); read_header(&tzf, tmp); read_transistions(&tzf, tmp); read_types(&tzf, tmp); #ifdef HAVE_SYSTEM_TZDATA if (memmap) { const struct location_info *li; /* TZif-style - grok the location info from the system database, * if possible. */ if ((li = find_zone_info(system_location_table, timezone)) != NULL) { tmp->location.comments = strdup(li->comment); strncpy(tmp->location.country_code, li->code, 2); tmp->location.longitude = li->longitude; tmp->location.latitude = li->latitude; tmp->bc = 1; } else { strcpy(tmp->location.country_code, "??"); tmp->bc = 0; tmp->location.comments = strdup(""); } /* Now done with the mmap segment - discard it. */ munmap(memmap, maplen); } else #endif { /* PHP-style - use the embedded info. */ read_location(&tzf, tmp); } } else { tmp = NULL; } return tmp; }
timelib_tzinfo *timelib_parse_tzfile(char *timezone, const timelib_tzdb *tzdb) { const unsigned char *tzf; timelib_tzinfo *tmp; if (seek_to_tz_position(&tzf, timezone, tzdb)) { tmp = timelib_tzinfo_ctor(timezone); read_header((char**) &tzf, tmp); read_transistions((char**) &tzf, tmp); read_types((char**) &tzf, tmp); } else { tmp = NULL; } return tmp; }
static struct classifier_config* read_config(FILE *input) { assert(input); struct file_range types_section, atoms_section; struct classifier_config *config = NULL; struct classifier_types *types = NULL; if (!(types = classifier_types_new()) || !(config = classifier_config_new()) || check_file(input, &types_section, &atoms_section) || read_types(types, input, types_section) || read_atoms(config, types, input, atoms_section) || config_copy_classes(config, types)) { classifier_config_free(config); config = NULL; } classifier_types_free(types); return config; }
/****************************************************************************** * IEnumDMO_fnNext */ static HRESULT WINAPI IEnumDMO_fnNext( IEnumDMO * iface, DWORD cItemsToFetch, CLSID * pCLSID, WCHAR ** Names, DWORD * pcItemsFetched) { HKEY hkey; WCHAR szNextKey[MAX_PATH]; WCHAR szGuidKey[64]; WCHAR szKey[MAX_PATH]; WCHAR szValue[MAX_PATH]; DWORD len; UINT count = 0; HRESULT hres = S_OK; LONG ret; IEnumDMOImpl *This = impl_from_IEnumDMO(iface); TRACE("(%p)->(%d %p %p %p)\n", This, cItemsToFetch, pCLSID, Names, pcItemsFetched); if (!pCLSID || !Names || !pcItemsFetched) return E_POINTER; while (count < cItemsToFetch) { This->index++; len = MAX_PATH; ret = RegEnumKeyExW(This->hkey, This->index, szNextKey, &len, NULL, NULL, NULL, NULL); if (ret != ERROR_SUCCESS) { hres = HRESULT_FROM_WIN32(ret); break; } TRACE("found %s\n", debugstr_w(szNextKey)); if (!(This->dwFlags & DMO_ENUMF_INCLUDE_KEYED)) { wsprintfW(szKey, szCat3Fmt, szDMORootKey, szNextKey, szDMOKeyed); ret = RegOpenKeyExW(HKEY_CLASSES_ROOT, szKey, 0, KEY_READ, &hkey); if (ERROR_SUCCESS == ret) { RegCloseKey(hkey); /* Skip Keyed entries */ continue; } } wsprintfW(szKey, szCat2Fmt, szDMORootKey, szNextKey); ret = RegOpenKeyExW(HKEY_CLASSES_ROOT, szKey, 0, KEY_READ, &hkey); TRACE("testing %s\n", debugstr_w(szKey)); if (This->pInTypes) { UINT i, j; DWORD cInTypes; DMO_PARTIAL_MEDIATYPE* pInTypes; hres = read_types(hkey, szDMOInputType, &cInTypes, sizeof(szValue)/sizeof(DMO_PARTIAL_MEDIATYPE), (DMO_PARTIAL_MEDIATYPE*)szValue); if (FAILED(hres)) { RegCloseKey(hkey); continue; } pInTypes = (DMO_PARTIAL_MEDIATYPE*) szValue; TRACE("read %d intypes for %s:\n", cInTypes, debugstr_w(szKey)); for (i = 0; i < cInTypes; i++) { TRACE("intype %d: type %s, subtype %s\n", i, debugstr_guid(&pInTypes[i].type), debugstr_guid(&pInTypes[i].subtype)); } for (i = 0; i < This->cInTypes; i++) { for (j = 0; j < cInTypes; j++) { if (IsMediaTypeEqual(&pInTypes[j], &This->pInTypes[i])) break; } if (j >= cInTypes) break; } if (i < This->cInTypes) { RegCloseKey(hkey); continue; } } if (This->pOutTypes) { UINT i, j; DWORD cOutTypes; DMO_PARTIAL_MEDIATYPE* pOutTypes; hres = read_types(hkey, szDMOOutputType, &cOutTypes, sizeof(szValue)/sizeof(DMO_PARTIAL_MEDIATYPE), (DMO_PARTIAL_MEDIATYPE*)szValue); if (FAILED(hres)) { RegCloseKey(hkey); continue; } pOutTypes = (DMO_PARTIAL_MEDIATYPE*) szValue; TRACE("read %d outtypes for %s:\n", cOutTypes, debugstr_w(szKey)); for (i = 0; i < cOutTypes; i++) { TRACE("outtype %d: type %s, subtype %s\n", i, debugstr_guid(&pOutTypes[i].type), debugstr_guid(&pOutTypes[i].subtype)); } for (i = 0; i < This->cOutTypes; i++) { for (j = 0; j < cOutTypes; j++) { if (IsMediaTypeEqual(&pOutTypes[j], &This->pOutTypes[i])) break; } if (j >= cOutTypes) break; } if (i < This->cOutTypes) { RegCloseKey(hkey); continue; } } /* Media object wasn't filtered so add it to return list */ Names[count] = NULL; len = MAX_PATH * sizeof(WCHAR); ret = RegQueryValueExW(hkey, NULL, NULL, NULL, (LPBYTE)szValue, &len); if (ERROR_SUCCESS == ret) { Names[count] = CoTaskMemAlloc((strlenW(szValue) + 1) * sizeof(WCHAR)); if (Names[count]) strcpyW(Names[count], szValue); } wsprintfW(szGuidKey,szToGuidFmt,szNextKey); CLSIDFromString(szGuidKey, &pCLSID[count]); TRACE("found match %s %s\n", debugstr_w(szValue), debugstr_w(szNextKey)); RegCloseKey(hkey); count++; } *pcItemsFetched = count; if (*pcItemsFetched < cItemsToFetch) hres = S_FALSE; TRACE("<-- %i found\n",count); return hres; }
/****************************************************************************** * IEnumDMO_fnNext */ static HRESULT WINAPI IEnumDMO_fnNext( IEnumDMO * iface, DWORD cItemsToFetch, CLSID * pCLSID, WCHAR ** Names, DWORD * pcItemsFetched) { FILETIME ft; HKEY hkey; WCHAR szNextKey[MAX_PATH]; WCHAR szGuidKey[64]; WCHAR szKey[MAX_PATH]; WCHAR szValue[MAX_PATH]; DWORD len; UINT count = 0; HRESULT hres = S_OK; IEnumDMOImpl *This = (IEnumDMOImpl *)iface; TRACE("--> (%p) %d %p %p %p\n", iface, cItemsToFetch, pCLSID, Names, pcItemsFetched); if (!pCLSID || !Names || !pcItemsFetched) return E_POINTER; while (count < cItemsToFetch) { This->index++; len = MAX_PATH; hres = RegEnumKeyExW(This->hkey, This->index, szNextKey, &len, NULL, NULL, NULL, &ft); if (hres != ERROR_SUCCESS) break; TRACE("found %s\n", debugstr_w(szNextKey)); if (!(This->dwFlags & DMO_ENUMF_INCLUDE_KEYED)) { wsprintfW(szKey, szCat3Fmt, szDMORootKey, szNextKey, szDMOKeyed); hres = RegOpenKeyExW(HKEY_CLASSES_ROOT, szKey, 0, KEY_READ, &hkey); if (ERROR_SUCCESS == hres) { RegCloseKey(hkey); /* Skip Keyed entries */ continue; } } wsprintfW(szKey, szCat2Fmt, szDMORootKey, szNextKey); hres = RegOpenKeyExW(HKEY_CLASSES_ROOT, szKey, 0, KEY_READ, &hkey); if (This->pInTypes) { UINT i, j; DWORD cInTypes; DMO_PARTIAL_MEDIATYPE* pInTypes; hres = read_types(hkey, szDMOInputType, &cInTypes, sizeof(szValue)/sizeof(DMO_PARTIAL_MEDIATYPE), (DMO_PARTIAL_MEDIATYPE*)szValue); if (ERROR_SUCCESS != hres) { RegCloseKey(hkey); continue; } pInTypes = (DMO_PARTIAL_MEDIATYPE*) szValue; for (i = 0; i < This->cInTypes; i++) { for (j = 0; j < cInTypes; j++) { if (IsMediaTypeEqual(&pInTypes[j], &This->pInTypes[i])) break; } if (j >= cInTypes) break; } if (i < This->cInTypes) { RegCloseKey(hkey); continue; } } if (This->pOutTypes) { UINT i, j; DWORD cOutTypes; DMO_PARTIAL_MEDIATYPE* pOutTypes; hres = read_types(hkey, szDMOOutputType, &cOutTypes, sizeof(szValue)/sizeof(DMO_PARTIAL_MEDIATYPE), (DMO_PARTIAL_MEDIATYPE*)szValue); if (ERROR_SUCCESS != hres) { RegCloseKey(hkey); continue; } pOutTypes = (DMO_PARTIAL_MEDIATYPE*) szValue; for (i = 0; i < This->cOutTypes; i++) { for (j = 0; j < cOutTypes; j++) { if (IsMediaTypeEqual(&pOutTypes[j], &This->pOutTypes[i])) break; } if (j >= cOutTypes) break; } if (i < This->cOutTypes) { RegCloseKey(hkey); continue; } } /* Media object wasn't filtered so add it to return list */ Names[count] = NULL; len = MAX_PATH * sizeof(WCHAR); hres = RegQueryValueExW(hkey, NULL, NULL, NULL, (LPBYTE) szValue, &len); if (ERROR_SUCCESS == hres) { Names[count] = HeapAlloc(GetProcessHeap(), 0, strlenW(szValue) + 1); if (Names[count]) strcmpW(Names[count], szValue); } wsprintfW(szGuidKey,szToGuidFmt,szNextKey); CLSIDFromString(szGuidKey, &pCLSID[count]); TRACE("found match %s %s\n", debugstr_w(szValue), debugstr_w(szNextKey)); RegCloseKey(hkey); count++; } *pcItemsFetched = count; if (*pcItemsFetched < cItemsToFetch) hres = S_FALSE; TRACE("<-- %i found\n",count); return hres; }
int main(int argc, char *argv[]) { const char *filename = NULL; const char *ufile = NULL; int error = 0; int c, fd, ufd; ctf_data_t cd; const ctf_preamble_t *pp; ctf_header_t *hp; Elf *elf; GElf_Ehdr ehdr; (void) elf_version(EV_CURRENT); for (opterr = 0; optind < argc; optind++) { while ((c = getopt(argc, argv, "dfhlsStu:")) != (int)EOF) { switch (c) { case 'd': flags |= F_DATA; break; case 'f': flags |= F_FUNC; break; case 'h': flags |= F_HDR; break; case 'l': flags |= F_LABEL; break; case 's': flags |= F_STR; break; case 'S': flags |= F_STATS; break; case 't': flags |= F_TYPES; break; case 'u': ufile = optarg; break; default: if (optopt == '?') return (print_usage(stdout, 1)); warn("illegal option -- %c\n", optopt); return (print_usage(stderr, 0)); } } if (optind < argc) { if (filename != NULL) return (print_usage(stderr, 0)); filename = argv[optind]; } } if (filename == NULL) return (print_usage(stderr, 0)); if (flags == 0 && ufile == NULL) flags = F_ALLMSK; if ((fd = open(filename, O_RDONLY)) == -1) die("failed to open %s", filename); if ((elf = elf_begin(fd, ELF_C_READ, NULL)) != NULL && gelf_getehdr(elf, &ehdr) != NULL) { Elf_Data *dp; Elf_Scn *ctfscn = findelfscn(elf, &ehdr, ".SUNW_ctf"); Elf_Scn *symscn; GElf_Shdr ctfshdr; if (ctfscn == NULL || (dp = elf_getdata(ctfscn, NULL)) == NULL) die("%s does not contain .SUNW_ctf data\n", filename); cd.cd_ctfdata = dp->d_buf; cd.cd_ctflen = dp->d_size; /* * If the sh_link field of the CTF section header is non-zero * it indicates which section contains the symbol table that * should be used. We default to the .symtab section if sh_link * is zero or if there's an error reading the section header. */ if (gelf_getshdr(ctfscn, &ctfshdr) != NULL && ctfshdr.sh_link != 0) { symscn = elf_getscn(elf, ctfshdr.sh_link); } else { symscn = findelfscn(elf, &ehdr, ".symtab"); } /* If we found a symbol table, find the corresponding strings */ if (symscn != NULL) { GElf_Shdr shdr; Elf_Scn *symstrscn; if (gelf_getshdr(symscn, &shdr) != NULL) { symstrscn = elf_getscn(elf, shdr.sh_link); cd.cd_nsyms = shdr.sh_size / shdr.sh_entsize; cd.cd_symdata = elf_getdata(symscn, NULL); cd.cd_strdata = elf_getdata(symstrscn, NULL); } } } else { struct stat st; if (fstat(fd, &st) == -1) die("failed to fstat %s", filename); cd.cd_ctflen = st.st_size; cd.cd_ctfdata = mmap(NULL, cd.cd_ctflen, PROT_READ, MAP_PRIVATE, fd, 0); if (cd.cd_ctfdata == MAP_FAILED) die("failed to mmap %s", filename); } /* * Get a pointer to the CTF data buffer and interpret the first portion * as a ctf_header_t. Validate the magic number and size. */ if (cd.cd_ctflen < sizeof (ctf_preamble_t)) die("%s does not contain a CTF preamble\n", filename); /* LINTED - pointer alignment */ pp = (const ctf_preamble_t *)cd.cd_ctfdata; if (pp->ctp_magic != CTF_MAGIC) die("%s does not appear to contain CTF data\n", filename); if (pp->ctp_version == CTF_VERSION) { /* LINTED - pointer alignment */ hp = (ctf_header_t *)cd.cd_ctfdata; cd.cd_ctfdata = (caddr_t)cd.cd_ctfdata + sizeof (ctf_header_t); if (cd.cd_ctflen < sizeof (ctf_header_t)) { die("%s does not contain a v%d CTF header\n", filename, CTF_VERSION); } } else { die("%s contains unsupported CTF version %d\n", filename, pp->ctp_version); } /* * If the data buffer is compressed, then malloc a buffer large enough * to hold the decompressed data, and use zlib to decompress it. */ if (hp->cth_flags & CTF_F_COMPRESS) { z_stream zstr; void *buf; int rc; if ((buf = malloc(hp->cth_stroff + hp->cth_strlen)) == NULL) die("failed to allocate decompression buffer"); bzero(&zstr, sizeof (z_stream)); zstr.next_in = (void *)cd.cd_ctfdata; zstr.avail_in = cd.cd_ctflen; zstr.next_out = buf; zstr.avail_out = hp->cth_stroff + hp->cth_strlen; if ((rc = inflateInit(&zstr)) != Z_OK) die("failed to initialize zlib: %s\n", zError(rc)); if ((rc = inflate(&zstr, Z_FINISH)) != Z_STREAM_END) die("failed to decompress CTF data: %s\n", zError(rc)); if ((rc = inflateEnd(&zstr)) != Z_OK) die("failed to finish decompression: %s\n", zError(rc)); if (zstr.total_out != hp->cth_stroff + hp->cth_strlen) die("CTF data is corrupt -- short decompression\n"); cd.cd_ctfdata = buf; cd.cd_ctflen = hp->cth_stroff + hp->cth_strlen; } if (flags & F_HDR) error |= print_header(hp, &cd); if (flags & (F_LABEL)) error |= print_labeltable(hp, &cd); if (flags & (F_DATA | F_STATS)) error |= read_data(hp, &cd); if (flags & (F_FUNC | F_STATS)) error |= read_funcs(hp, &cd); if (flags & (F_TYPES | F_STATS)) error |= read_types(hp, &cd); if (flags & (F_STR | F_STATS)) error |= read_strtab(hp, &cd); if (flags & F_STATS) error |= print_stats(); /* * If the -u option is specified, write the uncompressed CTF data to a * raw CTF file. CTF data can already be extracted compressed by * applying elfdump -w -N .SUNW_ctf to an ELF file, so we don't bother. */ if (ufile != NULL) { ctf_header_t h; bcopy(hp, &h, sizeof (h)); h.cth_flags &= ~CTF_F_COMPRESS; if ((ufd = open(ufile, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0 || write(ufd, &h, sizeof (h)) != sizeof (h) || write(ufd, cd.cd_ctfdata, cd.cd_ctflen) != cd.cd_ctflen) { warn("failed to write CTF data to '%s'", ufile); error |= E_ERROR; } (void) close(ufd); } if (elf != NULL) (void) elf_end(elf); (void) close(fd); return (error); }