int getHeight(char *src){ FILE * pFile; if((pFile = fopen(src, "rb")) == NULL){ puts("Error: wrong source.\n"); return 0; } BITMAPFILEHEADER header __attribute__((unused)); header.bfType = read_u16(pFile); header.bfSize = read_u32(pFile); header.bfReserved1 = read_u16(pFile); header.bfReserved2 = read_u16(pFile); header.bfOffBits = read_u32(pFile); // считываем заголовок изображения BITMAPINFOHEADER bmiHeader; bmiHeader.biSize = read_u32(pFile); bmiHeader.biWidth = read_s32(pFile); bmiHeader.biHeight = read_s32(pFile); fclose(pFile); return bmiHeader.biHeight; }
RtcRecord::RtcRecord(const Source &source, const unsigned char *payload, int payload_len) { if (payload_len != 13) { throw ParseError("In RTYPE_RTC payload starting at byte %d, incorrect length (should be 13, is %d)", source.pos(payload), payload_len); } const unsigned char *ptr=payload; tick_count = read_u32(ptr); long long seconds_since_1970 = read_s40(ptr); unsigned int nanoseconds = read_u32(ptr); nanoseconds_since_1970 = seconds_since_1970 * 1000000000LL + nanoseconds; }
static int protocol_client_vencrypt_auth(VncState *vs, uint8_t *data, size_t len) { int auth = read_u32(data, 0); if (auth != vs->vd->subauth) { VNC_DEBUG("Rejecting auth %d\n", auth); vnc_write_u8(vs, 0); /* Reject auth */ vnc_flush(vs); vnc_client_error(vs); } else { VNC_DEBUG("Accepting auth %d, setting up TLS for handshake\n", auth); vnc_write_u8(vs, 1); /* Accept auth */ vnc_flush(vs); if (vnc_tls_client_setup(vs, NEED_X509_AUTH(vs)) < 0) { VNC_DEBUG("Failed to setup TLS\n"); return 0; } VNC_DEBUG("Start TLS VeNCrypt handshake process\n"); if (vnc_start_vencrypt_handshake(vs) < 0) { VNC_DEBUG("Failed to start TLS handshake\n"); return 0; } } return 0; }
static int chunk_decode(struct wav_chunk *chunk, FILE *f) { if (1 != fread(chunk->id, sizeof(chunk->id), 1, f)) return ferror(f); return read_u32(f, &chunk->size); }
// Return TRUE if all was read. FALSE if a problem occured: // If a bitstream syntax problem occured the bitstream will // point to after the problem, in case we run out of data the bitstream // will point to where we want to restart after getting more. static int read_pic_data(struct bitstream *esstream) { dbg_print(DMT_VERBOSE, "Read PIC Data\n"); uint8_t startcode = next_start_code(esstream); // Possibly the last call to this function ended with the last // bit of the slice? I.e. in_pic_data is still true, but we are // seeing the next start code. // We only get here after seeing that start code if (startcode < 0x01 || startcode > 0xAF) { dbg_print(DMT_VERBOSE, "Read Pic Data - processed0\n"); return 1; } // If we get here esstream points to the start of a slice_start_code // should we run out of data in esstream this is where we want to restart // after getting more. unsigned char *slice_start = esstream->pos; do { startcode = next_start_code(esstream); // Syntax check if (startcode == 0xB4) { if (esstream->bitsleft < 0) init_bitstream(esstream, slice_start, esstream->end); if ( esstream->error ) dbg_print(DMT_VERBOSE, "read_pic_data: syntax problem.\n"); else dbg_print(DMT_VERBOSE, "read_pic_data: reached end of bitstream.\n"); return 0; } slice_start = esstream->pos; // No need to come back if ( startcode >= 0x01 && startcode <= 0xAF ) { read_u32(esstream); // Advance bitstream search_start_code(esstream); // Skip this slice } } while(startcode >= 0x01 && startcode <= 0xAF); if (esstream->bitsleft < 0) { init_bitstream(esstream, slice_start, esstream->end); return 0; } dbg_print(DMT_VERBOSE, "Read Pic Data - processed\n"); return 1; }
void threadRdyChr() { #if DEBUG kprintf("thread rdy\r\n"); #endif if(thread.waiting==0) return; q_elem *cur = thread.waiting; while(cur->next != 0 && cur->tcb.status!=thread_waiting_putChr) cur = cur->next; if(cur!=0 && cur->tcb.status==thread_waiting_putChr) { if(putChar(read_u32(cur->tcb.regs[0]))) { cur->tcb.status = thread_ready; queueOut(cur, &thread.waiting); if(insertAtElem(cur, thread.current)) { #if DEBUG kprintf("error putting into list\r\n"); #endif } if(thread.threads_ready==1 || thread.current->priority==0) force_reschedule = 1; thread.threads_ready++; } } }
/* decompress a section of an open file. Call fatal() on error return the number of bytes that have been retrieved */ static int runzip_chunk(int fd_in, int fd_out, int fd_hist, int out_is_pipe, int in_is_pipe) { uchar head; int len; struct stat st; void *ss; off_t ofs; int total = 0; uint32 good_cksum, cksum = 0; int eof; if(!in_is_pipe) { ofs = lseek(fd_in, 0, SEEK_CUR); if (ofs == (off_t)-1) { fatal("Failed to seek input file in runzip_fd\n"); } if (fstat(fd_in, &st) != 0 || st.st_size-ofs == 0) { return 0; } } ss = open_stream_in(fd_in, NUM_STREAMS, in_is_pipe, &eof); if (!ss) { if(eof) return 0; fatal(NULL); } while ((len = read_header(ss, &head)) || head) { switch (head) { case 0: total += unzip_literal(ss, len, fd_out, &cksum, out_is_pipe); break; default: total += unzip_match(ss, len, fd_out, fd_hist, &cksum, out_is_pipe); break; } } good_cksum = read_u32(ss, 0); if (good_cksum != cksum) { fatal("Bad checksum 0x%08x - expected 0x%08x\n", cksum, good_cksum); } if (close_stream_in(ss) != 0) { fatal("Failed to close stream!\n"); } if(out_is_pipe) { if(lseek(fd_out,0,SEEK_SET)==-1 || lseek(fd_hist,0,SEEK_SET)==-1 || ftruncate(fd_out,0)==-1) fatal("cannot truncate temporary file\n"); } return total; }
static void do_test_libeprom24x(void) { int value; do { print_menu(); printf("Enter choice : "); scanf("%d",&value); switch(value) { case 1: get_prod_info(); break; case 2: get_last_error(); break; case 3: initialize(); break; case 4: finalize(); break; case 5: read_u8(); break; case 6: read_u16(); break; case 7: read_u32(); break; case 8: read_to_buffer(); break; case 9: write_u8(); break; case 10: write_u16(); break; case 11: write_u32(); break; case 12: write_from_buffer(); break; case 13: erase_chip(); break; case 100: /* Exit */ break; default: printf("Illegal choice!\n"); } } while (value != 100); return; }
void MetroHash128::Finalize(uint8_t * const hash) { // finalize bulk loop, if used if (bytes >= 32) { state.v[2] ^= rotate_right(((state.v[0] + state.v[3]) * k0) + state.v[1], 21) * k1; state.v[3] ^= rotate_right(((state.v[1] + state.v[2]) * k1) + state.v[0], 21) * k0; state.v[0] ^= rotate_right(((state.v[0] + state.v[2]) * k0) + state.v[3], 21) * k1; state.v[1] ^= rotate_right(((state.v[1] + state.v[3]) * k1) + state.v[2], 21) * k0; } // process any bytes remaining in the input buffer const uint8_t * ptr = reinterpret_cast<const uint8_t*>(input.b); const uint8_t * const end = ptr + (bytes % 32); if ((end - ptr) >= 16) { state.v[0] += read_u64(ptr) * k2; ptr += 8; state.v[0] = rotate_right(state.v[0],33) * k3; state.v[1] += read_u64(ptr) * k2; ptr += 8; state.v[1] = rotate_right(state.v[1],33) * k3; state.v[0] ^= rotate_right((state.v[0] * k2) + state.v[1], 45) * k1; state.v[1] ^= rotate_right((state.v[1] * k3) + state.v[0], 45) * k0; } if ((end - ptr) >= 8) { state.v[0] += read_u64(ptr) * k2; ptr += 8; state.v[0] = rotate_right(state.v[0],33) * k3; state.v[0] ^= rotate_right((state.v[0] * k2) + state.v[1], 27) * k1; } if ((end - ptr) >= 4) { state.v[1] += read_u32(ptr) * k2; ptr += 4; state.v[1] = rotate_right(state.v[1],33) * k3; state.v[1] ^= rotate_right((state.v[1] * k3) + state.v[0], 46) * k0; } if ((end - ptr) >= 2) { state.v[0] += read_u16(ptr) * k2; ptr += 2; state.v[0] = rotate_right(state.v[0],33) * k3; state.v[0] ^= rotate_right((state.v[0] * k2) + state.v[1], 22) * k1; } if ((end - ptr) >= 1) { state.v[1] += read_u8 (ptr) * k2; state.v[1] = rotate_right(state.v[1],33) * k3; state.v[1] ^= rotate_right((state.v[1] * k3) + state.v[0], 58) * k0; } state.v[0] += rotate_right((state.v[0] * k0) + state.v[1], 13); state.v[1] += rotate_right((state.v[1] * k1) + state.v[0], 37); state.v[0] += rotate_right((state.v[0] * k2) + state.v[1], 13); state.v[1] += rotate_right((state.v[1] * k3) + state.v[0], 37); bytes = 0; // do any endian conversion here memcpy(hash, state.v, 16); }
static void read_u32_func(void** state) { uint32_t comp_buf = 0; uint32_t idx = 0; for(uint32_t i = 0; i < CHAR_SIZE - 2; i += 4) { comp_buf = (('a' + i) << 24) | (('b' + i) << 16) | (('c' + i) << 8) | ('d' + i); assert_int_equal(read_u32(buffer, &idx), comp_buf); } }
unsigned int* read_bmp(char* src){ FILE * pFile; if((pFile = fopen(src, "rb")) == NULL){ puts("Error: wrong source.\n"); return 0; } puts("read_bmp 1"); // считываем заголовок файла BITMAPFILEHEADER header __attribute__((unused)); header.bfType = read_u16(pFile); header.bfSize = read_u32(pFile); header.bfReserved1 = read_u16(pFile); header.bfReserved2 = read_u16(pFile); header.bfOffBits = read_u32(pFile); // считываем заголовок изображения BITMAPINFOHEADER bmiHeader; bmiHeader.biSize = read_u32(pFile); bmiHeader.biWidth = read_s32(pFile); bmiHeader.biHeight = read_s32(pFile); bmiHeader.biPlanes = read_u16(pFile); bmiHeader.biBitCount = read_u16(pFile); bmiHeader.biCompression = read_u32(pFile); bmiHeader.biSizeImage = read_u32(pFile); bmiHeader.biXPelsPerMeter = read_s32(pFile); bmiHeader.biYPelsPerMeter = read_s32(pFile); bmiHeader.biClrUsed = read_u32(pFile); bmiHeader.biClrImportant = read_u32(pFile); // unsigned int *img = new unsigned int[bmiHeader.biWidth*bmiHeader.biHeight]; unsigned int *img = malloc(sizeof(unsigned int)*bmiHeader.biWidth*bmiHeader.biHeight); puts("read_bmp 2"); int i, j, k; for (i = 0; i < bmiHeader.biHeight; ++i) { for (j = 0; j < bmiHeader.biWidth; ++j) { for (k = 0; k < 3; ++k) { img[i*bmiHeader.biWidth + j] |= !getc(pFile) << (8*k); } } for (j = 0; j < bmiHeader.biWidth%4; ++j) { getc(pFile); } } puts("read_bmp 3"); fclose(pFile); return img; }
void test32(){ int fd = open_file(); u32 * myu32 = malloc(sizeof(u32)); read_u32(fd,myu32); assertTrue_hexa("U32 Reader ",*myu32,0x49443303); close(fd); }
u32 xbinary_reader::read(u32 & b) { if (_can_read(len_, cursor_, sizeof(b))) { xbyte const* ptr = buffer_ + cursor_; cursor_ += sizeof(b); b = read_u32(ptr); return sizeof(b); } return 0; }
PeriodicDataRecord::PeriodicDataRecord(const Source &source, const unsigned char *payload, int payload_len, const StartOfFileRecord *sofr) : start_of_file_record(sofr) { try { const unsigned char *ptr=payload, *end=payload+payload_len; first_sample_short_tick = read_u32(ptr); sample_period = read_u32(ptr); number_of_samples = read_u32(ptr); char *cdef_begin = (char*)ptr; char *cdef_end; for (cdef_end = cdef_begin; cdef_end < (char*)end && *cdef_end; cdef_end++) {} if (cdef_end >= (char*)end) throw ParseError("At byte %d: DEVICE_PARAMS don't end with NUL", source.pos(end-1)); char *cptr = (char*) cdef_begin; channel_signature = std::string(cdef_begin, cdef_end-1); while (cptr < cdef_end) { char *keyptr = cptr; cptr = strchr(cptr, '\t'); if (!cptr) throw ParseError("At byte %d: DEVICE_PARAMS missing tab", source.pos(keyptr)); std::string key(keyptr, cptr); cptr++; // skip tab char *valueptr = cptr; cptr = strchr(cptr, '\n'); if (!cptr) throw ParseError("At byte %d: DEVICE_PARAMS missing newline", source.pos(valueptr)); std::string value(valueptr, cptr); cptr++; // skip int nbits = atoi(value.c_str()); if (verbose) log_f("parse_bt_file: '%s'=%d", key.c_str(), nbits); channel_definitions.push_back(std::pair<std::string, int>(key, nbits)); } ptr = (unsigned char*)cdef_end+1; data = std::vector<unsigned char>(ptr, end); } catch (ParseError &e) { throw ParseError("In RTYPE_START_OF_FILE payload starting at byte %d: %s", source.pos(payload), e.what()); } }
TimeRecord::TimeRecord(const Source &source, const unsigned char *&ptr) { type = *(ptr++); switch (type) { case TIME_DOUBLE: time_double = read_float64(ptr); break; case TIME_TICKS32: time_ticks32 = read_u32(ptr); break; default: throw ParseError("At byte %d: Unknown TimeRecord type 0x%02x", source.pos(ptr-1), type); } }
// Return TRUE if the data parsing finished, FALSE otherwise. // estream->pos is advanced. Data is only processed if esstream->error // is FALSE, parsing can set esstream->error to TRUE. static int pic_coding_ext(struct bitstream *esstream) { dbg_print(DMT_VERBOSE, "Picture coding extension %lld\n", esstream->bitsleft); if (esstream->error || esstream->bitsleft <= 0) return 0; // Syntax check if (next_start_code(esstream) != 0xB5) { dbg_print(DMT_VERBOSE, "pic_coding_ext: syntax problem.\n"); return 0; } read_u32(esstream); // Advance // Read extension_start_code_identifier unsigned extension_id = (unsigned int) read_bits(esstream, 4); if (extension_id != 0x8) // Picture Coding Extension ID { if (esstream->bitsleft >= 0) // When bits left, this is wrong esstream->error = 1; if (esstream->error) dbg_print(DMT_VERBOSE, "pic_coding_ext: syntax problem.\n"); return 0; } // Discard some information skip_bits(esstream, 4*4+2); picture_structure = (unsigned int) read_bits(esstream, 2); top_field_first = (unsigned int) read_bits(esstream, 1); skip_bits(esstream, 5*1); repeat_first_field = (unsigned int) read_bits(esstream, 1); skip_bits(esstream, 1); // chroma progressive_frame = (unsigned int) read_bits(esstream, 1); unsigned composite_display = (unsigned int) read_bits(esstream,1); if (composite_display) skip_bits(esstream, 1+3+1+7+8); if (esstream->bitsleft < 0) return 0; dbg_print(DMT_VERBOSE, "Picture coding extension - processed\n"); // Read complete return 1; }
static int protocol_client_vencrypt_auth(VncState *vs, uint8_t *data, size_t len) { int auth = read_u32(data, 0); trace_vnc_auth_vencrypt_subauth(vs, auth); if (auth != vs->subauth) { trace_vnc_auth_fail(vs, vs->auth, "Unsupported sub-auth version", ""); vnc_write_u8(vs, 0); /* Reject auth */ vnc_flush(vs); vnc_client_error(vs); } else { Error *err = NULL; QIOChannelTLS *tls; vnc_write_u8(vs, 1); /* Accept auth */ vnc_flush(vs); if (vs->ioc_tag) { g_source_remove(vs->ioc_tag); vs->ioc_tag = 0; } tls = qio_channel_tls_new_server( vs->ioc, vs->vd->tlscreds, vs->vd->tlsauthzid, &err); if (!tls) { trace_vnc_auth_fail(vs, vs->auth, "TLS setup failed", error_get_pretty(err)); error_free(err); vnc_client_error(vs); return 0; } qio_channel_set_name(QIO_CHANNEL(tls), "vnc-server-tls"); object_unref(OBJECT(vs->ioc)); vs->ioc = QIO_CHANNEL(tls); trace_vnc_client_io_wrap(vs, vs->ioc, "tls"); vs->tls = qio_channel_tls_get_session(tls); qio_channel_tls_handshake(tls, vnc_tls_handshake_done, vs, NULL, NULL); } return 0; }
static int protocol_client_auth_sasl_start_len(VncState *vs, uint8_t *data, size_t len) { uint32_t startlen = read_u32(data, 0); VNC_DEBUG("Got client start len %d\n", startlen); if (startlen > SASL_DATA_MAX_LEN) { VNC_DEBUG("Too much SASL data %d\n", startlen); vnc_client_error(vs); return -1; } if (startlen == 0) return protocol_client_auth_sasl_start(vs, NULL, 0); vnc_read_when(vs, protocol_client_auth_sasl_start, startlen); return 0; }
void main(){ //ouverture int fd ; fd = open("/home/marms/Documents/ASR/C/TP5/x.mp3", O_CREAT | O_RDONLY, 0666 ); if( fd == -1 ){ printf("erreur ouverture\n"); exit(15); } printf("\n====ESSAIS PERMUTE======\n"); u16 *x= (u16*)malloc(sizeof(u16)); *x=0x4244;//BD affiche_u16(x); permut2(x); //DB affiche_u16(x); printf("x, %0x\n",*x); u32* g= (u32*)malloc(sizeof(u32)); *g=0x10203040; permut4(g); printf("g, %0x\n",*g); printf("\n======FIN PERMUTE=======\n"); u8* a = (u8*) malloc(sizeof(u8)); if(! read_u8(fd,a)){ printf("echec3\n");} affiche_u8(a); u16* e = (u16*) malloc(sizeof(u16)); if(! read_u16(fd,e)){ printf("echec3\n");} affiche_u16(e); u32* f = (u32*) malloc(sizeof(u32)); if(! read_u32(fd,f)){ printf("echec4\n");} affiche_u32(f); *h = 0x6d776e6e ; affiche_u32(h); aff_bin((u8*)h); printf("\n"); *h= convert_size(*h); aff_bin((u8*)h); printf("\n"); //fermeture close(fd); }
// Return TRUE if the data parsing finished, FALSE otherwise. // estream->pos is advanced. Data is only processed if esstream->error // is FALSE, parsing can set esstream->error to TRUE. static int sequence_ext(struct bitstream *esstream) { dbg_print(DMT_VERBOSE, "Sequence extension\n"); if (esstream->error || esstream->bitsleft <= 0) return 0; // Syntax check if (next_start_code(esstream) != 0xB5) { dbg_print(DMT_VERBOSE, "sequence_ext: syntax problem.\n"); return 0; } read_u32(esstream); // Advance // Read extension_start_code_identifier unsigned extension_id = (unsigned) read_bits(esstream, 4); if (extension_id != 0x1) // Sequence Extension ID { if (esstream->bitsleft >= 0) // When bits left, this is wrong esstream->error = 1; if (esstream->error) dbg_print(DMT_VERBOSE, "sequence_ext: syntax problem.\n"); return 0; } // Discard some information skip_bits(esstream, 8); unsigned progressive_sequence = (unsigned) read_bits(esstream,1); if (progressive_sequence!=current_progressive_sequence) { current_progressive_sequence = progressive_sequence; mprint(" [progressive: %s]\n\n", (progressive_sequence ? "yes" : "no")); } skip_bits(esstream, 2+2+2+12+1+8+1+2+5); if (esstream->bitsleft < 0) return 0; // Read complete return 1; }
static int protocol_client_auth_sasl_mechname_len(VncState *vs, uint8_t *data, size_t len) { uint32_t mechlen = read_u32(data, 0); VNC_DEBUG("Got client mechname len %d\n", mechlen); if (mechlen > 100) { VNC_DEBUG("Too long SASL mechname data %d\n", mechlen); vnc_client_error(vs); return -1; } if (mechlen < 1) { VNC_DEBUG("Too short SASL mechname %d\n", mechlen); vnc_client_error(vs); return -1; } vnc_read_when(vs, protocol_client_auth_sasl_mechname,mechlen); return 0; }
// Return TRUE if the data parsing finished, FALSE otherwise. // estream->pos is advanced. Data is only processed if esstream->error // is FALSE, parsing can set esstream->error to TRUE. static int pic_header(struct lib_cc_decode *ctx, struct bitstream *esstream) { debug("PIC header\n"); if (esstream->error || esstream->bitsleft <= 0) return 0; // We only get here after seeing that start code if (read_u32(esstream) != 0x00010000) // LSB first (0x00000100) fatal(CCX_COMMON_EXIT_BUG_BUG, "In pic_header: read_u32(esstream) != 0x00010000. Please file a bug report in GitHub.\n"); ctx->temporal_reference = (int) read_bits(esstream,10); ctx->picture_coding_type = (enum ccx_frame_type) read_bits(esstream,3); // Discard vbv_delay skip_bits(esstream, 16); // Discard some information if (ctx->picture_coding_type == 2 || ctx->picture_coding_type == 3) skip_bits(esstream, 4); if (ctx->picture_coding_type == 3) skip_bits(esstream, 4); // extra_information while( read_bits(esstream,1) == 1 ) { skip_bits(esstream, 8); } if (esstream->bitsleft < 0) return 0; if ( !(ctx->picture_coding_type==CCX_FRAME_TYPE_I_FRAME || ctx->picture_coding_type==CCX_FRAME_TYPE_P_FRAME || ctx->picture_coding_type==CCX_FRAME_TYPE_B_FRAME)) { if (esstream->bitsleft >= 0) // When bits left, this is wrong esstream->error = 1; if (esstream->error) debug("pic_header: syntax problem.\n"); return 0; } return 1; }
static int unzip_match(void *ss, int len, int fd_out, int fd_hist, uint32 *cksum, int out_is_pipe) { unsigned offset; int n, total=0; off_t cur_pos = lseek(fd_out, 0, SEEK_CUR); offset = read_u32(ss, 0); ssize_t w,r; if (lseek(fd_hist, cur_pos-offset, SEEK_SET) == (off_t)-1) { fatal("Seek failed by %d from %d on history file in unzip_match - %s\n", offset, cur_pos, strerror(errno)); } while (len) { uchar *buf; n = MIN(len, offset); buf = malloc(n); if (!buf) { fatal("Failed to allocate %d bytes in unzip_match\n", n); } if (read(fd_hist, buf, n) != n) { fatal("Failed to read %d bytes in unzip_match\n", n); } if (write(fd_out, buf, n) != n) { fatal("Failed to write %d bytes in unzip_match\n", n); } if (out_is_pipe) { w=0; while(w<n && (r=write(STDOUT_FILENO, buf+w, n-w))>0) w+=r; if(r<0) fatal("Failed to write literal buffer of size %d\n", len); } *cksum = crc32_buffer(buf, n, *cksum); len -= n; free(buf); total += n; } return total; }
// Return TRUE if the data parsing finished, FALSE otherwise. // estream->pos is advanced. Data is only processed if esstream->error // is FALSE, parsing can set esstream->error to TRUE. static int pic_header(struct bitstream *esstream) { dbg_print(DMT_VERBOSE, "PIC header\n"); if (esstream->error || esstream->bitsleft <= 0) return 0; // We only get here after seeing that start code if (read_u32(esstream) != 0x00010000) // LSB first (0x00000100) fatal(EXIT_BUG_BUG, "Impossible!"); temporal_reference = (int) read_bits(esstream,10); picture_coding_type = (unsigned int) read_bits(esstream,3); // Discard vbv_delay skip_bits(esstream, 16); // Discard some information if (picture_coding_type == 2 || picture_coding_type == 3) skip_bits(esstream, 4); if (picture_coding_type == 3) skip_bits(esstream, 4); // extra_information while( read_bits(esstream,1) == 1 ) { skip_bits(esstream, 8); } if (esstream->bitsleft < 0) return 0; if ( !(picture_coding_type==I_FRAME || picture_coding_type==P_FRAME || picture_coding_type==B_FRAME)) { if (esstream->bitsleft >= 0) // When bits left, this is wrong esstream->error = 1; if (esstream->error) dbg_print(DMT_VERBOSE, "pic_header: syntax problem.\n"); return 0; } return 1; }
void read_header(FILE *infile, Header *header) { header->signature = read_u32(infile); if ((header->signature & 0xffff) != 0x4b50) { puts("ERROR: Invalid zip format."); exit(1); } if (IS_LOCAL_FILE_HEADER(header->signature)) { read_local_file_header(infile, header); } else if (IS_CENTRAL_DIRECTORY_FILE_HEADER(header->signature)) { read_central_directory_file_header(infile, header); } else if (IS_END_RECORD(header->signature)) { read_end_record(infile, header); } }
static int protocol_client_vencrypt_auth(VncState *vs, uint8_t *data, size_t len) { int auth = read_u32(data, 0); if (auth != vs->subauth) { VNC_DEBUG("Rejecting auth %d\n", auth); vnc_write_u8(vs, 0); /* Reject auth */ vnc_flush(vs); vnc_client_error(vs); } else { Error *err = NULL; QIOChannelTLS *tls; VNC_DEBUG("Accepting auth %d, setting up TLS for handshake\n", auth); vnc_write_u8(vs, 1); /* Accept auth */ vnc_flush(vs); if (vs->ioc_tag) { g_source_remove(vs->ioc_tag); vs->ioc_tag = 0; } tls = qio_channel_tls_new_server( vs->ioc, vs->vd->tlscreds, vs->vd->tlsaclname, &err); if (!tls) { VNC_DEBUG("Failed to setup TLS %s\n", error_get_pretty(err)); error_free(err); vnc_client_error(vs); return 0; } VNC_DEBUG("Start TLS VeNCrypt handshake process\n"); object_unref(OBJECT(vs->ioc)); vs->ioc = QIO_CHANNEL(tls); vs->tls = qio_channel_tls_get_session(tls); qio_channel_tls_handshake(tls, vnc_tls_handshake_done, vs, NULL); } return 0; }
int tag_read_id3_header(int fd, id3v2_header_t *header) { if(strcmp("ID3", read_string(fd, header->ID3, 3, 0))) return -1; if(!read_u16(fd, &(header->version))) return -1; // version valide if(header->version > 0x0300) return -1; if(!read_u8(fd, &(header->flags))) return -1; if(!read_u32(fd, &(header->size))) return -1; header->size = convert_size(header->size); return 0; }
/** * Reads a frame, stores data into the structure * * @param fd file descriptor * @param frame structure pointer * * @return -1 on error, 0 otherwise */ int tag_read_one_frame(int fd, id3v2_frame_t *frame) { u8 encoding; int i = 0; if(read_string(fd, frame->id, ID3V2_FRAME_ID_LENGTH, 0) == NULL) return -1; if(!read_u32(fd, &(frame->size))) return -1; if(!read_u16(fd, &(frame->flags))) return -1; if(frame->id[0] != 'T' || !strcmp(frame->id, "TXXX")) { lseek(fd, frame->size, SEEK_CUR); frame->text = NULL; return -1; } for(i = 0 ; i < ID3V2_FRAME_ID_LENGTH ; i++) { if(!isupper(frame->id[i]) && !isdigit(frame->id[i])) { lseek(fd, frame->size, SEEK_CUR); frame->text = NULL; return -1; } } if(!read_u8(fd, &(encoding))) return -1; frame->text = read_string(fd, NULL, frame->size - 1, (int) encoding); if(frame->text == NULL) return -1; return 0; }
int tag_read_id3_header(int fd, id3v2_header_t *header) { if(strcmp("ID3", read_string(fd, header->ID3, 3, 0)) != 0) { printf("titi1"); return -1; } if(!read_u16(fd, &(header->version))) { printf("titi2"); return -1; } // version valide if(header->version > 0x0300) { printf("titi3"); return -1; } if(!read_u8(fd, &(header->flags))) { printf("titi4"); return -1; } if(!read_u32(fd, &(header->size))) { printf("titi5"); return -1; } header->size = convert_size(header->size); return 0; }
int blob_decode_t::output(int &n,char ** &s_arr,int *&len_arr) { int parser_pos=0; if(parser_pos+(int)sizeof(u32_t)>current_len) {mylog(log_info,"failed 0\n");return -1;} n=(int)read_u32(input_buf+parser_pos); if(n>max_blob_packet_num) {mylog(log_info,"failed 1\n");return -1;} s_arr=output_buf; len_arr=output_len; parser_pos+=sizeof(u32_t); for(int i=0;i<n;i++) { if(parser_pos+(int)sizeof(u16_t)>current_len) {mylog(log_info,"failed2 \n");return -1;} len_arr[i]=(int)read_u16(input_buf+parser_pos); parser_pos+=(int)sizeof(u16_t); if(parser_pos+len_arr[i]>current_len) {mylog(log_info,"failed 3 %d %d %d\n",parser_pos,len_arr[i],current_len);return -1;} s_arr[i]=input_buf+parser_pos; parser_pos+=len_arr[i]; } return 0; }