int main(int argc, char **argv) { int rv; int fd = open(argv[1], O_RDWR); struct lead lead; pread(fd, &lead, sizeof(lead), 0); // First header struct header hdr; pread(fd, &hdr, sizeof(hdr), sizeof(lead)); hdr.nindex = be32toh(hdr.nindex); hdr.len = be32toh(hdr.len); long hdrofs = sizeof(struct lead); long idxofs = hdrofs + sizeof(struct header); long storeofs = idxofs + hdr.nindex * sizeof(struct idxentry); printf("== Signatures ==\nHeader offset: 0x%lx\nIndex offset: 0x%lx\n" "Store: 0x%lx - 0x%lx\nIndex entries (%u):\n", hdrofs, idxofs, storeofs, storeofs + hdr.len, hdr.nindex); int i; int64_t remsize = -1; for (i = 0; i < hdr.nindex; i++) { struct idxentry ent; pread(fd, &ent, sizeof(ent), idxofs + i * sizeof(struct idxentry)); ent.tag = be32toh(ent.tag); ent.type = be32toh(ent.type); ent.offset = storeofs + be32toh(ent.offset); ent.count = be32toh(ent.count); if (ent.tag == RPMSIGTAG_LONGSIZE) { assert(ent.type == RPM_INT64_TYPE); assert(ent.count == 1); pread(fd, &remsize, sizeof(remsize), ent.offset); remsize = be64toh(remsize); } else if (ent.tag == RPMSIGTAG_SIZE) { assert(ent.type == RPM_INT32_TYPE); assert(ent.count == 1); uint32_t remsize32 = 0; pread(fd, &remsize32, sizeof(remsize32), ent.offset); remsize = be32toh(remsize32); } const char *name = hdr_tag_name(ent.tag); if (name) printf(" %s: ", name); else printf(" %d: ", ent.tag); print_value(fd, &ent); printf("\n"); if (i == 0) { // Is this what "sealed" means? uint32_t tag = ent.tag; assert(TAG_IS_REGION(tag)); assert(ent.type == RPM_BIN_TYPE); assert(ent.count == 16); pread(fd, &ent, sizeof(ent), ent.offset); ent.tag = be32toh(ent.tag); ent.type = be32toh(ent.type); ent.offset = storeofs + be32toh(ent.offset); ent.count = be32toh(ent.count); assert(ent.tag == tag); assert(ent.type == RPM_BIN_TYPE); assert(ent.count == 16); assert(ent.offset == idxofs); } } printf("\n"); assert(remsize >= 0); // Pad to 8-byte alignment and seek past pad hdrofs = storeofs + hdr.len; hdrofs = ((hdrofs + 7) / 8) * 8; lseek(fd, hdrofs, SEEK_SET); // Second header pread(fd, &hdr, sizeof(hdr), hdrofs); hdr.nindex = be32toh(hdr.nindex); hdr.len = be32toh(hdr.len); idxofs = hdrofs + sizeof(struct header); storeofs = idxofs + hdr.nindex * sizeof(struct idxentry); printf("== Header ==\nTotal filesize: 0x%lx\nHeader offset: 0x%lx\n" "Index offset: 0x%lx\nStore: 0x%lx - 0x%lx\nIndex entries (%u):\n", hdrofs + remsize, hdrofs, idxofs, storeofs, storeofs + hdr.len, hdr.nindex); for (i = 0; i < hdr.nindex; i++) { struct idxentry ent; pread(fd, &ent, sizeof(ent), idxofs + i * sizeof(struct idxentry)); ent.tag = be32toh(ent.tag); ent.type = be32toh(ent.type); ent.offset = storeofs + be32toh(ent.offset); ent.count = be32toh(ent.count); const char *name = sig_tag_name(ent.tag); if (name) printf(" %s: ", name); else printf(" %d: ", ent.tag); print_value(fd, &ent); printf("\n"); } printf("\n"); close(fd); return 0; }
/* Render an array to text */ static char *print_array(cJSON * item, int depth, int fmt, printbuffer * p) { char **entries; char *out = 0, *ptr, *ret; int len = 5; cJSON *child = item->child; int numentries = 0, i = 0, fail = 0; size_t tmplen = 0; /* How many entries in the array? */ while (child) numentries++, child = child->next; /* Explicitly handle numentries==0 */ if (!numentries) { if (p) out = ensure(p, 3); else out = (char *) cJSON_malloc(3); if (out) strcpy(out, "[]"); return out; } if (p) { /* Compose the output array. */ i = p->offset; ptr = ensure(p, 1); if (!ptr) return 0; *ptr = '['; p->offset++; child = item->child; while (child && !fail) { print_value(child, depth + 1, fmt, p); p->offset = update(p); if (child->next) { len = fmt ? 2 : 1; ptr = ensure(p, len + 1); if (!ptr) return 0; *ptr++ = ','; if (fmt) *ptr++ = ' '; *ptr = 0; p->offset += len; } child = child->next; } ptr = ensure(p, 2); if (!ptr) return 0; *ptr++ = ']'; *ptr = 0; out = (p->buffer) + i; } else { /* Allocate an array to hold the values for each */ entries = (char **) cJSON_malloc(numentries * sizeof(char *)); if (!entries) return 0; memset(entries, 0, numentries * sizeof(char *)); /* Retrieve all the results: */ child = item->child; while (child && !fail) { ret = print_value(child, depth + 1, fmt, 0); entries[i++] = ret; if (ret) len += strlen(ret) + 2 + (fmt ? 1 : 0); else fail = 1; child = child->next; } /* If we didn't fail, try to malloc the output string */ if (!fail) out = (char *) cJSON_malloc(len); /* If that fails, we fail. */ if (!out) fail = 1; /* Handle failure. */ if (fail) { for (i = 0; i < numentries; i++) if (entries[i]) cJSON_free(entries[i]); cJSON_free(entries); return 0; } /* Compose the output array. */ *out = '['; ptr = out + 1; *ptr = 0; for (i = 0; i < numentries; i++) { tmplen = strlen(entries[i]); memcpy(ptr, entries[i], tmplen); ptr += tmplen; if (i != numentries - 1) { *ptr++ = ','; if (fmt) *ptr++ = ' '; *ptr = 0; } cJSON_free(entries[i]); } cJSON_free(entries); *ptr++ = ']'; *ptr++ = 0; } return out; }
/* Render a cJSON item/entity/structure to text. */ char *cJSON_Print(cJSON *item) {return print_value(item,0,1);}
void InstructionPrinter::do_InstanceOf(InstanceOf* x) { output()->print("instanceof("); print_value(x->obj()); output()->print(") "); print_klass(x->klass()); }
void InstructionPrinter::do_UnsafePutRaw(UnsafePutRaw* x) { print_unsafe_raw_op(x, "UnsafePutRaw"); output()->print(", value "); print_value(x->value()); output()->put(')'); }
void InstructionPrinter::do_Convert(Convert* x) { output()->print("%s(", Bytecodes::name(x->op())); print_value(x->value()); output()->put(')'); }
void InstructionPrinter::do_NewObjectArray(NewObjectArray* x) { output()->print("new object array ["); print_value(x->length()); output()->print("] "); print_klass(x->klass()); }
GLOBAL Int UMF_report_vector ( Int n, const double Xx [ ], const double Xz [ ], Int prl, Int user, Int scalar ) { Int n2, i ; if (user || prl >= 4) { PRINTF (("dense vector, n = "ID". ", n)) ; } if (user) { if (!Xx) { PRINTF (("ERROR: vector not present\n\n")) ; return (UMFPACK_ERROR_argument_missing) ; } if (n < 0) { PRINTF (("ERROR: length of vector is < 0\n\n")) ; return (UMFPACK_ERROR_n_nonpositive) ; } } if (user || prl >= 4) { PRINTF4 (("\n")) ; } if (prl == 4) { /* print level of 4 */ n2 = MIN (10, n) ; for (i = 0 ; i < n2 ; i++) { print_value (i, Xx, Xz, scalar) ; } if (n2 < n) { PRINTF ((" ...\n")) ; print_value (n-1, Xx, Xz, scalar) ; } } else if (prl > 4) { /* print level 4 or more */ for (i = 0 ; i < n ; i++) { print_value (i, Xx, Xz, scalar) ; } } PRINTF4 ((" dense vector ")) ; if (user || prl >= 4) { PRINTF (("OK\n\n")) ; } return (UMFPACK_OK) ; }
void InstructionPrinter::print_field(AccessField* field) { print_value(field->obj()); output()->print("._%d", field->offset()); }
/* Render an array to text */ static char *print_array(srjson_doc_t *doc, srjson_t *item, int depth, int fmt) { char **entries; char *out = 0, *ptr, *ret; int len = 5; srjson_t *child = item->child; int numentries = 0, i = 0, fail = 0; /* How many entries in the array? */ while (child) numentries++, child = child->next; /* Allocate an array to hold the values for each */ entries = (char **) doc->malloc_fn(numentries * sizeof(char *)); if (!entries) return 0; memset(entries, 0, numentries * sizeof(char *)); /* Retrieve all the results: */ child = item->child; while (child && !fail) { ret = print_value(doc, child, depth + 1, fmt); entries[i++] = ret; if (ret) len += strlen(ret) + 2 + (fmt ? 1 : 0); else fail = 1; child = child->next; } /* If we didn't fail, try to malloc the output string */ if (!fail) out = (char *) doc->malloc_fn(len); /* If that fails, we fail. */ if (!out) fail = 1; /* Handle failure. */ if (fail) { for (i = 0; i < numentries; i++) if (entries[i]) doc->free_fn(entries[i]); doc->free_fn(entries); return 0; } /* Compose the output array. */ *out = '['; ptr = out + 1; *ptr = 0; for (i = 0; i < numentries; i++) { strcpy(ptr, entries[i]); ptr += strlen(entries[i]); if (i != numentries - 1) { *ptr++ = ','; if (fmt) *ptr++ = ' '; *ptr = 0; } doc->free_fn(entries[i]); } doc->free_fn(entries); *ptr++ = ']'; *ptr++ = 0; return out; }
/* Render an object to text. */ static char *print_object(srjson_doc_t *doc, srjson_t *item, int depth, int fmt) { char **entries = 0, **names = 0; char *out = 0, *ptr, *ret, *str; int len = 7, i = 0, j; srjson_t *child = item->child; int numentries = 0, fail = 0; /* Count the number of entries. */ while (child) numentries++, child = child->next; /* Allocate space for the names and the objects */ entries = (char **) doc->malloc_fn(numentries * sizeof(char *)); if (!entries) return 0; names = (char **)doc->malloc_fn(numentries * sizeof(char *)); if (!names) { doc->free_fn(entries); return 0; } memset(entries, 0, sizeof(char *) * numentries); memset(names, 0, sizeof(char *) * numentries); /* Collect all the results into our arrays: */ child = item->child; depth++; if (fmt) len += depth; while (child) { names[i] = str = print_string_ptr(doc, child->string); entries[i++] = ret = print_value(doc, child, depth, fmt); if (str && ret) len += strlen(ret) + strlen(str) + 2 + (fmt ? 2 + depth : 0); else fail = 1; child = child->next; } /* Try to allocate the output string */ if (!fail) out = (char *) doc->malloc_fn(len); if (!out) fail = 1; /* Handle failure */ if (fail) { for (i = 0; i < numentries; i++) { if (names[i]) doc->free_fn(names[i]); if (entries[i]) doc->free_fn(entries[i]); } doc->free_fn(names); doc->free_fn(entries); return 0; } /* Compose the output: */ *out = '{'; ptr = out + 1; if (fmt) *ptr++ = '\n'; *ptr = 0; for (i = 0; i < numentries; i++) { if (fmt) for (j = 0; j < depth; j++) *ptr++ = '\t'; strcpy(ptr, names[i]); ptr += strlen(names[i]); *ptr++ = ':'; if (fmt) *ptr++ = '\t'; strcpy(ptr, entries[i]); ptr += strlen(entries[i]); if (i != numentries - 1) *ptr++ = ','; if (fmt) *ptr++ = '\n'; *ptr = 0; doc->free_fn(names[i]); doc->free_fn(entries[i]); } doc->free_fn(names); doc->free_fn(entries); if (fmt) for (i = 0; i < depth - 1; i++) *ptr++ = '\t'; *ptr++ = '}'; *ptr++ = 0; return out; }
char *srjson_PrintUnformatted(srjson_doc_t *doc, srjson_t *item) { return print_value(doc, item, 0, 0); }
/* Render a srjson item/entity/structure to text. */ char *srjson_Print(srjson_doc_t *doc, srjson_t *item) { return print_value(doc, item, 0, 1); }
static void print_stats(const gchar *filename, capture_info *cf_info) { const gchar *file_type_string, *file_encap_string; time_t start_time_t; time_t stop_time_t; /* Build printable strings for various stats */ file_type_string = wtap_file_type_string(cf_info->file_type); file_encap_string = wtap_encap_string(cf_info->file_encap); start_time_t = (time_t)cf_info->start_time; stop_time_t = (time_t)cf_info->stop_time; if (filename) printf ("File name: %s\n", filename); if (cap_file_type) printf ("File type: %s%s\n", file_type_string, cf_info->iscompressed ? " (gzip compressed)" : ""); if (cap_file_encap) printf ("File encapsulation: %s\n", file_encap_string); if (cap_file_encap && (cf_info->file_encap == WTAP_ENCAP_PER_PACKET)) { int i; for (i=0; i<WTAP_NUM_ENCAP_TYPES; i++) { if (cf_info->encap_counts[i] > 0) printf(" %s\n", wtap_encap_string(i)); } } if (cap_snaplen && cf_info->snap_set) printf ("Packet size limit: file hdr: %u bytes\n", cf_info->snaplen); else if(cap_snaplen && !cf_info->snap_set) printf ("Packet size limit: file hdr: (not set)\n"); if (cf_info->snaplen_max_inferred > 0) { if (cf_info->snaplen_min_inferred == cf_info->snaplen_max_inferred) printf ("Packet size limit: inferred: %u bytes\n", cf_info->snaplen_min_inferred); else printf ("Packet size limit: inferred: %u bytes - %u bytes (range)\n", cf_info->snaplen_min_inferred, cf_info->snaplen_max_inferred); } if (cap_packet_count) printf ("Number of packets: %u\n", cf_info->packet_count); if (cap_file_size) printf ("File size: %" G_GINT64_MODIFIER "d bytes\n", cf_info->filesize); if (cap_data_size) printf ("Data size: %" G_GINT64_MODIFIER "u bytes\n", cf_info->packet_bytes); if (cf_info->times_known) { if (cap_duration) print_value("Capture duration: ", 0, " seconds", cf_info->duration); if (cap_start_time) printf ("Start time: %s", time_string(start_time_t, cf_info, TRUE)); if (cap_end_time) printf ("End time: %s", time_string(stop_time_t, cf_info, TRUE)); if (cap_data_rate_byte) print_value("Data byte rate: ", 2, " bytes/sec", cf_info->data_rate); if (cap_data_rate_bit) print_value("Data bit rate: ", 2, " bits/sec", cf_info->data_rate*8); } if (cap_packet_size) printf ("Average packet size: %.2f bytes\n", cf_info->packet_size); if (cf_info->times_known) { if (cap_packet_rate) print_value("Average packet rate: ", 2, " packets/sec", cf_info->packet_rate); } #ifdef HAVE_LIBGCRYPT if (cap_file_hashes) { printf ("SHA1: %s\n", file_sha1); printf ("RIPEMD160: %s\n", file_rmd160); printf ("MD5: %s\n", file_md5); } #endif /* HAVE_LIBGCRYPT */ if (cap_order) printf ("Strict time order: %s\n", order_string(cf_info->order)); }
void InstructionPrinter::do_StoreIndexed(StoreIndexed* x) { print_indexed(x); output()->print(" := "); print_value(x->value()); output()->print(" (%c)", type2char(x->elt_type())); }
void InstructionPrinter::print_indexed(AccessIndexed* indexed) { print_value(indexed->array()); output()->put('['); print_value(indexed->index()); output()->put(']'); }
void InstructionPrinter::do_NegateOp(NegateOp* x) { output()->put('-'); print_value(x->x()); }
void InstructionPrinter::print_monitor(AccessMonitor* monitor) { output()->print("monitor[%d](", monitor->monitor_no()); print_value(monitor->obj()); output()->put(')'); }
void InstructionPrinter::do_NewTypeArray(NewTypeArray* x) { output()->print("new %s array [", basic_type_name(x->elt_type())); print_value(x->length()); output()->put(']'); }
void InstructionPrinter::print_op2(Op2* instr) { print_value(instr->x()); output()->print(" %s ", op_name(instr->op())); print_value(instr->y()); }
void InstructionPrinter::do_CheckCast(CheckCast* x) { output()->print("checkcast("); print_value(x->obj()); output()->print(") "); print_klass(x->klass()); }
void InstructionPrinter::print_unsafe_object_op(UnsafeObjectOp* op, const char* name) { print_unsafe_op(op, name); print_value(op->object()); output()->print(", "); print_value(op->offset()); }
void InstructionPrinter::do_Throw(Throw* x) { output()->print("throw "); print_value(x->exception()); }
void InstructionPrinter::print_alias(Value v) { if (v != v->subst()) { output()->print("alias "); print_value(v->subst()); } }
void InstructionPrinter::do_UnsafePutObject(UnsafePutObject* x) { print_unsafe_object_op(x, "UnsafePutObject"); output()->print(", value "); print_value(x->value()); output()->put(')'); }
void InstructionPrinter::do_StoreField(StoreField* x) { print_field(x); output()->print(" := "); print_value(x->value()); output()->print(" (%c)", type2char(x->field()->type()->basic_type())); }
/* Render an object to text. */ static char *print_object(cJSON * item, int depth, int fmt, printbuffer * p) { char **entries = 0, **names = 0; char *out = 0, *ptr, *ret, *str; int len = 7, i = 0, j; cJSON *child = item->child; int numentries = 0, fail = 0; size_t tmplen = 0; /* Count the number of entries. */ while (child) numentries++, child = child->next; /* Explicitly handle empty object case */ if (!numentries) { if (p) out = ensure(p, fmt ? depth + 4 : 3); else out = (char *) cJSON_malloc(fmt ? depth + 4 : 3); if (!out) return 0; ptr = out; *ptr++ = '{'; if (fmt) { *ptr++ = '\n'; for (i = 0; i < depth - 1; i++) *ptr++ = '\t'; } *ptr++ = '}'; *ptr++ = 0; return out; } if (p) { /* Compose the output: */ i = p->offset; len = fmt ? 2 : 1; ptr = ensure(p, len + 1); if (!ptr) return 0; *ptr++ = '{'; if (fmt) *ptr++ = '\n'; *ptr = 0; p->offset += len; child = item->child; depth++; while (child) { if (fmt) { ptr = ensure(p, depth); if (!ptr) return 0; for (j = 0; j < depth; j++) *ptr++ = '\t'; p->offset += depth; } print_string_ptr(child->string, p); p->offset = update(p); len = fmt ? 2 : 1; ptr = ensure(p, len); if (!ptr) return 0; *ptr++ = ':'; if (fmt) *ptr++ = '\t'; p->offset += len; print_value(child, depth, fmt, p); p->offset = update(p); len = (fmt ? 1 : 0) + (child->next ? 1 : 0); ptr = ensure(p, len + 1); if (!ptr) return 0; if (child->next) *ptr++ = ','; if (fmt) *ptr++ = '\n'; *ptr = 0; p->offset += len; child = child->next; } ptr = ensure(p, fmt ? (depth + 1) : 2); if (!ptr) return 0; if (fmt) for (i = 0; i < depth - 1; i++) *ptr++ = '\t'; *ptr++ = '}'; *ptr = 0; out = (p->buffer) + i; } else { /* Allocate space for the names and the objects */ entries = (char **) cJSON_malloc(numentries * sizeof(char *)); if (!entries) return 0; names = (char **) cJSON_malloc(numentries * sizeof(char *)); if (!names) { cJSON_free(entries); return 0; } memset(entries, 0, sizeof(char *) * numentries); memset(names, 0, sizeof(char *) * numentries); /* Collect all the results into our arrays: */ child = item->child; depth++; if (fmt) len += depth; while (child) { names[i] = str = print_string_ptr(child->string, 0); entries[i++] = ret = print_value(child, depth, fmt, 0); if (str && ret) len += strlen(ret) + strlen(str) + 2 + (fmt ? 2 + depth : 0); else fail = 1; child = child->next; } /* Try to allocate the output string */ if (!fail) out = (char *) cJSON_malloc(len); if (!out) fail = 1; /* Handle failure */ if (fail) { for (i = 0; i < numentries; i++) { if (names[i]) cJSON_free(names[i]); if (entries[i]) cJSON_free(entries[i]); } cJSON_free(names); cJSON_free(entries); return 0; } /* Compose the output: */ *out = '{'; ptr = out + 1; if (fmt) *ptr++ = '\n'; *ptr = 0; for (i = 0; i < numentries; i++) { if (fmt) for (j = 0; j < depth; j++) *ptr++ = '\t'; tmplen = strlen(names[i]); memcpy(ptr, names[i], tmplen); ptr += tmplen; *ptr++ = ':'; if (fmt) *ptr++ = '\t'; strcpy(ptr, entries[i]); ptr += strlen(entries[i]); if (i != numentries - 1) *ptr++ = ','; if (fmt) *ptr++ = '\n'; *ptr = 0; cJSON_free(names[i]); cJSON_free(entries[i]); } cJSON_free(names); cJSON_free(entries); if (fmt) for (i = 0; i < depth - 1; i++) *ptr++ = '\t'; *ptr++ = '}'; *ptr++ = 0; } return out; }
void InstructionPrinter::do_ArrayLength(ArrayLength* x) { print_value(x->array()); output()->print(".length"); }
char *cJSON_PrintUnformatted(cJSON *item) {return print_value(item,0,0);}
static int lowprobe_device(blkid_probe pr, const char *devname, int chain, char *show[], int output, uint64_t offset, uint64_t size) { const char *data; const char *name; int nvals = 0, n, num = 1; size_t len; int fd; int rc = 0; static int first = 1; fd = open(devname, O_RDONLY|O_CLOEXEC); if (fd < 0) { fprintf(stderr, "error: %s: %m\n", devname); return BLKID_EXIT_NOTFOUND; } if (blkid_probe_set_device(pr, fd, offset, size)) goto done; if (chain & LOWPROBE_TOPOLOGY) rc = lowprobe_topology(pr); if (rc >= 0 && (chain & LOWPROBE_SUPERBLOCKS)) rc = lowprobe_superblocks(pr); if (rc < 0) goto done; if (!rc) nvals = blkid_probe_numof_values(pr); if (nvals && !first && output & (OUTPUT_UDEV_LIST | OUTPUT_EXPORT_LIST)) /* add extra line between output from devices */ fputc('\n', stdout); if (nvals && (output & OUTPUT_DEVICE_ONLY)) { printf("%s\n", devname); goto done; } for (n = 0; n < nvals; n++) { if (blkid_probe_get_value(pr, n, &name, &data, &len)) continue; if (show[0] && !has_item(show, name)) continue; len = strnlen((char *) data, len); print_value(output, num++, devname, (char *) data, name, len); } if (first) first = 0; if (nvals >= 1 && !(output & (OUTPUT_VALUE_ONLY | OUTPUT_UDEV_LIST | OUTPUT_EXPORT_LIST))) printf("\n"); done: if (rc == -2) { if (output & OUTPUT_UDEV_LIST) print_udev_ambivalent(pr); else fprintf(stderr, "%s: ambivalent result (probably more " "filesystems on the device, use wipefs(8) " "to see more details)\n", devname); } close(fd); if (rc == -2) return BLKID_EXIT_AMBIVAL; /* ambivalent probing result */ if (!nvals) return BLKID_EXIT_NOTFOUND; /* nothing detected */ return 0; /* success */ }