/*----------------------------------------------------------------------------- * Dump library file *----------------------------------------------------------------------------*/ void dump_library( FILE *fp, char *filename ) { long lib_start = ftell(fp) - 8; /* before signature */ long next_ptr = lib_start + 8; long obj_start, obj_len; enum file_type type; do { fseek( fp, next_ptr, SEEK_SET ); /* next block */ obj_start = next_ptr + 8; next_ptr = xfread_long( fp, filename ); obj_len = xfread_long( fp, filename ); type = read_signature( fp, filename ); if ( type != is_object ) die("File %s: contains non-object file\n", filename ); if ( obj_len == 0 ) printf(" Deleted...\n"); dump_object( fp, filename ); } while ( next_ptr >= 0 ); }
int get_original_signature(const void *offset, const void *new_sig, void *&org_sig) { unsigned int sign_len; if(!offset) return 0; sign_len = ((unsigned char *)new_sig)[SIGN_LEN_BYTE]; org_sig = malloc(sign_len + SIGN_HEADER_LEN); memcpy(org_sig, new_sig, SIGN_HEADER_LEN); return read_signature(offset, org_sig); }
/*----------------------------------------------------------------------------- * Main *----------------------------------------------------------------------------*/ int main(int argc, char *argv[]) { char *filename; FILE *fp; int flags = 0; int opt; while ((opt = getopt(argc,argv,"hleca")) != -1 ) { switch (opt ) { case 'l': opt_showlocal = 1; break; case 'e': opt_showexpr = 1; break; case 'c': opt_dump_code = 1; break; case 'a': opt_showlocal = opt_showexpr = opt_dump_code = 1; break; default: usage(argv[0]); } } if ( optind == argc ) usage(argv[0]); while ( optind < argc ) { filename = argv[optind++]; fp = xfopen( filename, "rb" ); switch ( read_signature( fp, filename ) ) { case is_library: dump_library( fp, filename ); break; case is_object: dump_object( fp, filename ); break; default: assert(0); } fclose( fp ); } return 0; }
int main(int argc, char **argv) { struct rsa_public_key key; struct sha1_ctx hash; mpz_t s; if (argc != 3) { werror("Usage: rsa-verify PUBLIC-KEY SIGNATURE-FILE < FILE\n"); return EXIT_FAILURE; } rsa_public_key_init(&key); if (!read_rsa_key(argv[1], &key, NULL)) { werror("Invalid key\n"); return EXIT_FAILURE; } mpz_init(s); if (!read_signature(argv[2], s)) { werror("Failed to read signature file `%s'\n", argv[2]); return EXIT_FAILURE; } sha1_init(&hash); if (!hash_file(&nettle_sha1, &hash, stdin)) { werror("Failed reading stdin: %s\n", strerror(errno)); return 0; } if (!rsa_sha1_verify(&key, &hash, s)) { werror("Invalid signature!\n"); return EXIT_FAILURE; } mpz_clear(s); rsa_public_key_clear(&key); return EXIT_SUCCESS; }
static Externalclosure read_assmodes( FILE * infile, char * language) { char *signature = GetSignature( language); Externalclosure result = emptyclosure; assem_infile = infile; if( signature != NULL ) { Transformer *nulltprocs = MakeNullTransformer(objtable, objtable); Assemreader *assemreader = read_signature( get_char, signature); if( assemreader != NULL) { result = read_closure( assemreader, nulltprocs); } free( assemreader ); } return( result ); }
/** * Given the file name of a signed boot image, verifies the signature * @param image_file Name of the boot image file */ static int verify(const char *image_file) { BootSignature *bs = NULL; int fd = -1; int rc = 1; off64_t offset = 0; if (!image_file) { return rc; } if ((fd = open(image_file, O_RDONLY | O_LARGEFILE)) == -1) { return rc; } if (get_signature_offset(fd, &offset) == -1) { goto out; } if (read_signature(fd, offset, &bs) == -1) { goto out; } if (validate_signature_block(bs, offset) == -1) { goto out; } if (verify_signature(fd, offset, bs) == -1) { goto out; } printf("Signature is VALID\n"); rc = 0; out: if (bs) { BootSignature_free(bs); } if (fd != -1) { close(fd); } return rc; }
void Manifold::load(const char* filename) { ifstream f; f.open(filename, ios::in | ios::binary); if (f.fail()) ibex_error("[manifold]: cannot open input file.\n"); read_signature(f); if (read_int(f)!=n) ibex_error("[manifold]: bad input file (number of variables does not match)."); if (read_int(f)!=m) ibex_error("[manifold]: bad input file (number of equalities does not match)."); if (read_int(f)!=nb_ineq) ibex_error("[manifold]: bad input file (number of inequalities does not match)."); read_int(f); // status int nb_inner = read_int(f); int nb_boundary = read_int(f); int nb_unknown = read_int(f); int nb_pending = read_int(f); int nb_sols = nb_inner + nb_boundary + nb_unknown + nb_pending; time = read_double(f); nb_cells = read_int(f); IntervalVector box(n); for (int i=0; i<nb_sols; i++) { SolverOutputBox sol = read_output_box(f); switch(sol.status) { case 0: inner.push_back(sol); break; case 1: boundary.push_back(sol); break; case 2: unknown.push_back(sol); break; case 3: pending.push_back(sol); break; } } }
/** * cdk_pkt_read: * @inp: the input stream * @pkt: allocated packet handle to store the packet * * Parse the next packet on the @inp stream and return its contents in @pkt. **/ cdk_error_t cdk_pkt_read (cdk_stream_t inp, cdk_packet_t pkt) { int ctb, is_newctb; int pkttype; size_t pktlen = 0, pktsize = 0, is_partial = 0; cdk_error_t rc; if (!inp || !pkt) return CDK_Inv_Value; ctb = cdk_stream_getc (inp); if (cdk_stream_eof (inp) || ctb == EOF) return CDK_EOF; else if (!ctb) return CDK_Inv_Packet; pktsize++; if (!(ctb & 0x80)) { _cdk_log_info ("cdk_pkt_read: no openpgp data found. " "(ctb=%02X; fpos=%02X)\n", ctb, cdk_stream_tell (inp)); return CDK_Inv_Packet; } if (ctb & 0x40) /* RFC2440 packet format. */ { pkttype = ctb & 0x3f; is_newctb = 1; } else /* the old RFC1991 packet format. */ { pkttype = ctb & 0x3f; pkttype >>= 2; is_newctb = 0; } if (pkttype > 63) { _cdk_log_info ("cdk_pkt_read: unknown type %d\n", pkttype); return CDK_Inv_Packet; } if (is_newctb) read_new_length (inp, &pktlen, &pktsize, &is_partial); else read_old_length (inp, ctb, &pktlen, &pktsize); pkt->pkttype = pkttype; pkt->pktlen = pktlen; pkt->pktsize = pktsize + pktlen; pkt->old_ctb = is_newctb ? 0 : 1; rc = 0; switch (pkt->pkttype) { case CDK_PKT_ATTRIBUTE: pkt->pkt.user_id = cdk_calloc (1, sizeof *pkt->pkt.user_id + pkt->pktlen + 16 + 1); if (!pkt->pkt.user_id) return CDK_Out_Of_Core; pkt->pkt.user_id->name = (char*)pkt->pkt.user_id + sizeof(*pkt->pkt.user_id); rc = read_attribute (inp, pktlen, pkt->pkt.user_id); pkt->pkttype = CDK_PKT_ATTRIBUTE; break; case CDK_PKT_USER_ID: pkt->pkt.user_id = cdk_calloc (1, sizeof *pkt->pkt.user_id + pkt->pktlen + 1); if (!pkt->pkt.user_id) return CDK_Out_Of_Core; pkt->pkt.user_id->name = (char*)pkt->pkt.user_id + sizeof(*pkt->pkt.user_id); rc = read_user_id (inp, pktlen, pkt->pkt.user_id); break; case CDK_PKT_PUBLIC_KEY: pkt->pkt.public_key = cdk_calloc (1, sizeof *pkt->pkt.public_key); if (!pkt->pkt.public_key) return CDK_Out_Of_Core; rc = read_public_key (inp, pktlen, pkt->pkt.public_key); break; case CDK_PKT_PUBLIC_SUBKEY: pkt->pkt.public_key = cdk_calloc (1, sizeof *pkt->pkt.public_key); if (!pkt->pkt.public_key) return CDK_Out_Of_Core; rc = read_public_subkey (inp, pktlen, pkt->pkt.public_key); break; case CDK_PKT_SECRET_KEY: pkt->pkt.secret_key = cdk_calloc (1, sizeof *pkt->pkt.secret_key); if (!pkt->pkt.secret_key) return CDK_Out_Of_Core; pkt->pkt.secret_key->pk = cdk_calloc (1, sizeof *pkt->pkt.secret_key->pk); if (!pkt->pkt.secret_key->pk) return CDK_Out_Of_Core; rc = read_secret_key (inp, pktlen, pkt->pkt.secret_key); break; case CDK_PKT_SECRET_SUBKEY: pkt->pkt.secret_key = cdk_calloc (1, sizeof *pkt->pkt.secret_key); if (!pkt->pkt.secret_key) return CDK_Out_Of_Core; pkt->pkt.secret_key->pk = cdk_calloc (1, sizeof *pkt->pkt.secret_key->pk); if (!pkt->pkt.secret_key->pk) return CDK_Out_Of_Core; rc = read_secret_subkey (inp, pktlen, pkt->pkt.secret_key); break; case CDK_PKT_LITERAL: pkt->pkt.literal = cdk_calloc (1, sizeof *pkt->pkt.literal); if (!pkt->pkt.literal) return CDK_Out_Of_Core; rc = read_literal (inp, pktlen, &pkt->pkt.literal, is_partial); break; case CDK_PKT_ONEPASS_SIG: pkt->pkt.onepass_sig = cdk_calloc (1, sizeof *pkt->pkt.onepass_sig); if (!pkt->pkt.onepass_sig) return CDK_Out_Of_Core; rc = read_onepass_sig (inp, pktlen, pkt->pkt.onepass_sig); break; case CDK_PKT_SIGNATURE: pkt->pkt.signature = cdk_calloc (1, sizeof *pkt->pkt.signature); if (!pkt->pkt.signature) return CDK_Out_Of_Core; rc = read_signature (inp, pktlen, pkt->pkt.signature); break; case CDK_PKT_PUBKEY_ENC: pkt->pkt.pubkey_enc = cdk_calloc (1, sizeof *pkt->pkt.pubkey_enc); if (!pkt->pkt.pubkey_enc) return CDK_Out_Of_Core; rc = read_pubkey_enc (inp, pktlen, pkt->pkt.pubkey_enc); break; case CDK_PKT_COMPRESSED: pkt->pkt.compressed = cdk_calloc (1, sizeof *pkt->pkt.compressed); if (!pkt->pkt.compressed) return CDK_Out_Of_Core; rc = read_compressed (inp, pktlen, pkt->pkt.compressed); break; case CDK_PKT_MDC: pkt->pkt.mdc = cdk_calloc (1, sizeof *pkt->pkt.mdc); if (!pkt->pkt.mdc) return CDK_Out_Of_Core; rc = read_mdc (inp, pkt->pkt.mdc); break; default: /* Skip all packets we don't understand */ skip_packet (inp, pktlen); break; } return rc; }
GByteArray *JarFile::get_next_file_contents() { guint8 *bytes; GByteArray *gba = g_byte_array_new(); read_signature(); //get compressed size bytes = (guint8 *)g_malloc(sizeof(guint8) * 30); if (!read(bytes+4, 26)) { g_free(bytes); return NULL; } guint32 compressed_size = UNPACK_UB4(bytes, LOC_CSIZE); guint16 filename_length = UNPACK_UB2(bytes, LOC_FNLEN); guint16 eflen = UNPACK_UB2(bytes, LOC_EFLEN); guint16 flags = UNPACK_UB2(bytes, LOC_EXTRA); guint16 method = UNPACK_UB2(bytes, LOC_COMP); if (filename_length == 0) { g_byte_array_free(gba, TRUE); if (_last_filename != NULL) g_free(_last_filename); _last_filename = NULL; g_free(bytes); return NULL; } #ifdef DEBUG std::printf("Compressed size is %u\n", compressed_size); std::printf("Filename length is %hu\n", filename_length); std::printf("Extra field length is %hu\n", eflen); std::printf("Flags are %#hx\n", flags); std::printf("Compression method is %#hx\n", method); #endif guint32 crc = get_crc(bytes, flags); gchar *filename = (gchar *)read_filename(filename_length); g_free(bytes); if (filename == NULL) return NULL; if (_last_filename != NULL) g_free(_last_filename); _last_filename = filename; //check if this is a directory and skip char *c_ptr; if ((c_ptr = std::strrchr(filename, '/')) != NULL) { if (*(++c_ptr) == '\0') { return NULL; } } if (!check_compression_method(method, flags)) { std::fprintf(stderr, "error in jar file\n"); return NULL; } if (method == 8 || flags & 0x0008) { unsigned int file_length = 0;//uncompressed file length lseek(fd, eflen, SEEK_CUR); guint8 *file_data = get_compressed_file(compressed_size, file_length, crc, flags); if (file_data == NULL) { g_byte_array_free(gba, FALSE); return NULL; } g_byte_array_append(gba, file_data, file_length); } else if (method == 0) { guint8 *file_data = get_uncompressed_file(compressed_size, crc, eflen, flags); if (file_data == NULL) { g_byte_array_free(gba, TRUE); return NULL; } g_byte_array_append(gba, file_data, compressed_size); } else { lseek(fd, compressed_size+eflen, SEEK_CUR); g_byte_array_free(gba, FALSE); return NULL; } return gba; }
void avrisp(int ReceivedByte){ // is pmode active? if (ram.isp.pmode) LEDs_TurnOnLEDs(LEDS_PMODE); else LEDs_TurnOffLEDs(LEDS_PMODE); // is there an error? if (ram.isp.error) LEDs_TurnOnLEDs(LEDS_ERR); else LEDs_TurnOffLEDs(LEDS_ERR); // read in bytes from the CDC interface if (!(ReceivedByte < 0)){ switch (ReceivedByte) { case STK_GET_SYNC: ram.isp.error = 0; replyOK(); break; case STK_GET_SIGNON: if (getch() == CRC_EOP) { sendCDCbyte(STK_INSYNC); sendCDCbyte('A'); sendCDCbyte('V'); sendCDCbyte('R'); sendCDCbyte(' '); sendCDCbyte('I'); sendCDCbyte('S'); sendCDCbyte('P'); sendCDCbyte(STK_OK); } break; case STK_GET_PARM: get_parameters(getch()); break; case STK_SET_PARM: set_parameters(); replyOK(); break; case STK_SET_PARM_EXT: // extended parameters - ignore for now fill(5); replyOK(); break; case STK_PMODE_START: start_pmode(); replyOK(); break; case STK_SET_ADDR: ram.isp._addr = getch(); ram.isp._addr += 256 * getch(); replyOK(); break; case STK_PROG_FLASH: //uint8_t low = getch(); getch(); //uint8_t high = getch(); getch(); replyOK(); break; case STK_PROG_DATA: //uint8_t data = getch(); getch(); replyOK(); break; case STK_PROG_PAGE: program_page(); break; case STK_READ_PAGE: read_page(); break; case STK_UNIVERSAL: universal(); break; case STK_PMODE_END: ram.isp.error = 0; end_pmode(); replyOK(); break; case STK_READ_SIGN: read_signature(); break; // expecting a command, not CRC_EOP // this is how we can get back in sync case CRC_EOP: ram.isp.error++; sendCDCbyte(STK_NOSYNC); break; // anything else we will return STK_UNKNOWN default: ram.isp.error++; if (CRC_EOP == getch()) sendCDCbyte(STK_UNKNOWN); else sendCDCbyte(STK_NOSYNC); } } }