Beispiel #1
0
static void search_attr_req(const struct l2cap_frame *frame,
						struct tid_data *tid)
{
	uint32_t search_bytes, attr_bytes;

	search_bytes = get_bytes(frame->data, frame->size);
	print_field("Search pattern: [len %d]", search_bytes);

	if (search_bytes + 2 > frame->size) {
		print_text(COLOR_ERROR, "invalid search list length");
		packet_hexdump(frame->data, frame->size);
		return;
	}

	decode_data_elements(0, 2, frame->data, search_bytes, NULL);

	print_field("Max record count: %d",
				get_be16(frame->data + search_bytes));

	attr_bytes = get_bytes(frame->data + search_bytes + 2,
				frame->size - search_bytes - 2);
	print_field("Attribute list: [len %d]", attr_bytes);

	if (search_bytes + attr_bytes > frame->size) {
		print_text(COLOR_ERROR, "invalid attribute list length");
		return;
	}

	decode_data_elements(0, 2, frame->data + search_bytes + 2,
						attr_bytes, NULL);

	store_continuation(tid, frame->data + search_bytes + 2 + attr_bytes,
				frame->size - search_bytes - 2 - attr_bytes);
}
Beispiel #2
0
static int
get_usage (uint8_t * report_descriptor, size_t size,
	   unsigned short *usage_page, unsigned short *usage)
{
  size_t i = 0;
  int size_code;
  int data_len, key_size;
  int usage_found = 0, usage_page_found = 0;

  while (i < size)
    {
      int key = report_descriptor[i];
      int key_cmd = key & 0xfc;

      if ((key & 0xf0) == 0xf0)
	{
	  fprintf (stderr, "invalid data received.\n");
	  return -1;
	}
      else
	{
	  size_code = key & 0x3;
	  switch (size_code)
	    {
	    case 0:
	    case 1:
	    case 2:
	      data_len = size_code;
	      break;
	    case 3:
	      data_len = 4;
	      break;
	    default:
	      /* Can't ever happen since size_code is & 0x3 */
	      data_len = 0;
	      break;
	    };
	  key_size = 1;
	}

      if (key_cmd == 0x4)
	{
	  *usage_page = get_bytes (report_descriptor, size, data_len, i);
	  usage_page_found = 1;
	}
      if (key_cmd == 0x8)
	{
	  *usage = get_bytes (report_descriptor, size, data_len, i);
	  usage_found = 1;
	}

      if (usage_page_found && usage_found)
	return 0;		/* success */

      i += data_len + key_size;
    }

  return -1;			/* failure */
}
Beispiel #3
0
int
Stream::get_string_ptr( char const *&s ) {
	char	c;
	void 	*tmp_ptr = 0;
    int     len;

	s = NULL;
	switch(_code){
		case internal:
		case external:
                    // For 6.2 compatibility, we had to put this code back 
                    if (!get_encryption()) {
                        if (!peek(c)) return FALSE;
                        if (c == '\255'){
                            if (get_bytes(&c, 1) != 1) return FALSE;
							s = NULL;
                        }
                        else{
                            if (get_ptr(tmp_ptr, '\0') <= 0) return FALSE;
							s = (char *)tmp_ptr;
                        }
                    }
                    else { // 6.3 with encryption support
                        // First, get length
                        if (get(len) == FALSE) {
                            return FALSE;
                        }

						if( !decrypt_buf || decrypt_buf_len < len ) {
							free( decrypt_buf );
							decrypt_buf = (char *)malloc(len);
							ASSERT( decrypt_buf );
							decrypt_buf_len = len;
						}

                        if( get_bytes(decrypt_buf, len) != len ) {
                            return FALSE;
                        }

                        if( *decrypt_buf == '\255' ) {
							s = NULL;
                        }
                        else {
							s = decrypt_buf;
                        }
                    }
                    break;

		case ascii:
			return FALSE;
	}
	if( s ) {
		NETWORK_TRACE("get string ptr " << s);
	}
	else {
		NETWORK_TRACE("get string ptr NULL");
	}
	return TRUE;
}
/* Check that an in-use record is valid. */
static bool tdb_check_used_record(struct tdb_context *tdb,
				  tdb_off_t off,
				  const struct tdb_record *rec,
				  unsigned char **hashes,
				  int (*check)(TDB_DATA, TDB_DATA, void *),
				  void *private_data)
{
	TDB_DATA key, data;

	if (!tdb_check_record(tdb, off, rec))
		return false;

	/* key + data + tailer must fit in record */
	if (rec->key_len + rec->data_len + sizeof(tdb_off_t) > rec->rec_len) {
		TDB_LOG((tdb, TDB_DEBUG_ERROR,
			 "Record offset %d too short for contents\n", off));
		return false;
	}

	key = get_bytes(tdb, off + sizeof(*rec), rec->key_len);
	if (!key.dptr)
		return false;

	if (tdb->hash_fn(&key) != rec->full_hash) {
		TDB_LOG((tdb, TDB_DEBUG_ERROR,
			 "Record offset %d has incorrect hash\n", off));
		goto fail_put_key;
	}

	/* Mark this offset as a known value for this hash bucket. */
	record_offset(hashes[BUCKET(rec->full_hash)+1], off);
	/* And similarly if the next pointer is valid. */
	if (rec->next)
		record_offset(hashes[BUCKET(rec->full_hash)+1], rec->next);

	/* If they supply a check function and this record isn't dead,
	   get data and feed it. */
	if (check && rec->magic != TDB_DEAD_MAGIC) {
		data = get_bytes(tdb, off + sizeof(*rec) + rec->key_len,
				 rec->data_len);
		if (!data.dptr)
			goto fail_put_key;

		if (check(key, data, private_data) == -1)
			goto fail_put_data;
		put_bytes(tdb, data);
	}

	put_bytes(tdb, key);
	return true;

fail_put_data:
	put_bytes(tdb, data);
fail_put_key:
	put_bytes(tdb, key);
	return false;
}
Beispiel #5
0
/** @return 1 is ok, <= 0 is failure */
static int convert_data(struct burn_write_opts *o, struct burn_track *track,
			 int inmode, unsigned char *data)
{
	int outlen, inlen;
	int offset = -1;
	int outmode;

	outmode = get_outmode(o);
	if (outmode == 0)
		outmode = inmode;

	outlen = burn_sector_length(outmode);
	inlen = burn_sector_length(inmode);

	/* ts A61010 */
	/* a ssert(outlen >= inlen); */
	if (outlen < inlen)
		return 0;

	if ((outmode & BURN_MODE_BITS) == (inmode & BURN_MODE_BITS)) {
		/* see MMC-5 4.2.3.8.5.3 Block Format for Mode 2 form 1 Data
		            Table 24  Mode 2 Formed Sector Sub-header Format */
		if (track != NULL)
			if (track->cdxa_conversion == 1)
				inlen += 8;

		get_bytes(track, inlen, data);

		if (track != NULL)
			if (track->cdxa_conversion == 1)
				memmove(data, data + 8, inlen - 8);
		return 1;
	}

	/* ts A61010 */
	/* a ssert(outmode & BURN_MODE_RAW); */
	if (!(outmode & BURN_MODE_RAW))
		return 0;

	if (inmode & BURN_MODE1)
		offset = 16;
	if (inmode & BURN_MODE_RAW)
		offset = 0;
	if (inmode & BURN_AUDIO)
		offset = 0;

	/* ts A61010 */
	/* a ssert(offset != -1); */
	if (offset == -1)
		return 0;

	get_bytes(track, inlen, data + offset);
	return 1;
}
Beispiel #6
0
int speed(char *dev, char *type, int max) {
    int first, end, perc;

    first = get_bytes(dev, type);
    sleep(1);
    end = get_bytes(dev, type);

    perc=((end - first) * 100) / max;
    if(perc > 100) perc=100;

    printf("%d\n", perc);
    return 0;
}
Beispiel #7
0
int 
Stream::get( int64_t	&l)
{
	int		i;
	char	sign;
	// On Windows, INT_SIZE == sizeof(int64_t).
	// MSVC won't allocate an array of size 0, so just skip it.
	#ifndef WIN32
	char pad[INT_SIZE-sizeof(int64_t)];
	#endif

	switch(_code){
		case internal:
			if (get_bytes(&l, sizeof(int64_t)) != sizeof(int64_t)) return FALSE;
			break;

		case external:
			if ((sizeof(int) == sizeof(int64_t)) || (sizeof(int64_t) > INT_SIZE)) {
				if (!get(i)) return FALSE;
				l = (long) i;
			} else {
				#ifndef WIN32
				if (sizeof(int64_t) < INT_SIZE) {
					if (get_bytes(pad, INT_SIZE-sizeof(int64_t))
						!= INT_SIZE-sizeof(int64_t)) {
						return FALSE;
					}
				}
				#endif
				if (get_bytes(&l, sizeof(int64_t)) != sizeof(int64_t)) return FALSE;
				if (!hton_is_noop()) { // need to convert to host order
					l = ntohLL(l);
				}
				sign = (l >= 0) ? 0 : 0xff;
				#ifndef WIN32
				for (int s=0; s < INT_SIZE-(int)sizeof(int64_t); s++) { // overflow?
					if (pad[s] != sign) {
						return FALSE; // overflow
					}
				}
				#endif
			}
			break;

		case ascii:
			return FALSE;
	}
    NETWORK_TRACE("get int64_t " << l);
	return TRUE;
}
Beispiel #8
0
static void attr_req(const struct l2cap_frame *frame, struct tid_data *tid)
{
	uint32_t attr_bytes;

	if (frame->size < 6) {
		print_text(COLOR_ERROR, "invalid size");
		packet_hexdump(frame->data, frame->size);
		return;
	}

	print_field("Record handle: 0x%4.4x", get_be32(frame->data));
	print_field("Max attribute bytes: %d", get_be16(frame->data + 4));

	attr_bytes = get_bytes(frame->data + 6, frame->size - 6);
	print_field("Attribute list: [len %d]", attr_bytes);

	if (attr_bytes + 6 > frame->size) {
		print_text(COLOR_ERROR, "invalid attribute list length");
		packet_hexdump(frame->data, frame->size);
		return;
	}

	decode_data_elements(0, 2, frame->data + 6, attr_bytes, NULL);

	store_continuation(tid, frame->data + 6 + attr_bytes,
					frame->size - 6 - attr_bytes);
}
Beispiel #9
0
int
RAND_egd_bytes(const char *filename, int size)
{
    void *data;
    int ret;

    if (size <= 0)
        return 0;

    data = malloc(size);
    if (data == NULL)
        return 0;

    ret = get_bytes(filename, data, size);
    if (ret != 1) {
        free(data);
        return ret;
    }

    RAND_seed(data, size);

    memset(data, 0, size);
    free(data);

    return 1;
}
Beispiel #10
0
int main(int argc, char *argv[])
{
    struct elf_handle *handle;
    char *file, *bytes;
    int size;

    file = parse_args(argc, argv);

    if (!options.flat_binary) {
        if ((handle = elf_init(file)) == NULL) {
            fprintf(stderr, "Failed to initialize elf file %s: %s\n", file, strerror(errno));
            return 1;
        }
        bytes = get_bytes(handle, options.function, &size);

        elf_free(handle);
    } else
        bytes = read_flat_binary(file, &size);

    fprintf(stderr, "Printing shellcode (%d bytes)\n", size);
    if (!strcasecmp(options.format, "python"))
        print_opcodes_py(bytes, size);
    else if (!strcasecmp(options.format, "hexdump"))
        print_opcodes_hex(bytes, size);
    else if (!strcasecmp(options.format, "raw"))
        print_opcodes_raw(bytes, size);
    else
        print_opcodes_C(bytes, size);
    fflush(stdout);

    free(bytes);

    return 0;
}
// -----------------------------------------------------------------------------
int BlockFile::fread_number() 		// read an <int> value from bin file
{
	char ca[SIZEINT];
	get_bytes(ca, SIZEINT);

	return *((int *)ca);
}
Beispiel #12
0
char *rm16_sreg(char *buffer, int *j, int *error)
{
	int err = 0; 
	memset(str, '\0', 255) ;
	if (get_bytes(1, *j))
	{
		*error = 1 ; 
		return str ;
	}
	unsigned char reg = ((buffer[++(*j)] & 0x38) >> 3) ;
	(*j)-- ; 
	char *s =  rm(buffer, j, 16, &err)  ;
	if (err)
	{
		*error = 1 ;
		return str ;
	}
	if (reg < 4)
	{
		char *sreg = segreg[reg] ;
		sprintf(str,"%s,%s", s, sreg) ;
		*error = 0 ;
	} else *error = 1 ; 
	return str ;
}
Beispiel #13
0
char *call_inter(char *buffer, int *j, int *err)
{
	memset(str, '\0', 255) ;
	if (get_bytes(4, *j))
	{
		*err = 1 ; 
		return str ;
	}
	(*j)++ ;
	bytes++ ; 
	unsigned char offset_low = buffer[*j] ; 
	(*j)++ ;
	bytes++ ;
	unsigned char offset_high = buffer[*j] ; 
	(*j)++ ;
	bytes++ ;
	unsigned char seg_low = buffer[*j] ; 
	(*j)++ ;
	bytes++ ;
	unsigned char seg_high = buffer[*j] ; 
	unsigned short offset = ((offset_high << 8) + offset_low) ; 
	unsigned short seg = ((seg_high << 8) + seg_low) ;
	sprintf(str,"0x%x:0x%x", seg, offset) ;
	return str ;	
}
Beispiel #14
0
char *moffs16(char *buffer, int *j, int *err)
{
	memset(str, '\0', 255) ;
	char segment[10] ;
	memset(segment, '\0', 10) ;
	if (segment_override >= 0)
	{
		switch (segment_override)
		{
			case ES: sprintf(segment, "es:") ; break ;
			case CS: sprintf(segment, "cs:") ; break ;
			case SS: sprintf(segment, "ss:") ; break ;
			case DS: sprintf(segment, "ds:") ; break ;
		}
		segment_override = -1 ;
	}
	if (get_bytes(2, *j))
	{
		*err = 1 ; 
		return str ; 
	}
	(*j)++ ; 
	bytes++ ;
	unsigned char low = buffer[*j] ; 
	(*j)++ ;
	bytes++ ; 
	unsigned char high = buffer[*j] ; 
	unsigned short imm16 = ((high << 8) + low) ;
	sprintf(str, "[%s0x%x]", segment, imm16) ;
	return str ;
}
Beispiel #15
0
static inline AVP_dword DATA_PARAM get_size_t( Serialize* sz, AVP_size_t* val ) {
	if ( get_bytes(sz,val,sizeof(AVP_size_t)) != sizeof(AVP_size_t) )
		return 0;

	WriteSize_tPtr( val, *val );
	return sizeof(AVP_size_t);
}
Beispiel #16
0
/* Description: This function writes a command to the camera and checks if the
                write was done successfully by checking camera's response.
   Parameters:  fd: serial port file descriptor
                msg: the command to be send to the camera
   Returns:     1: if the write was successful
                0: otherwise
*/
int write_check(int fd, char *msg, int respond_size)
{
	char respond[5];

	// write the command to the camera
	if( write(fd, msg, strlen(msg)) != (int)strlen(msg) )
	{
		printf( "Cmucam2: writing to serial device failed.\n" );
		return 0;
	}

	if( get_bytes(fd, respond, respond_size) < 1 )
	{
		printf( "Cmucam2: get bytes failed\n" );
		return 0;
	}

	// If NCK is returned, there was an error in writing
	if(respond[0] == 'N')
	{
		printf("Cmucam2: received NCK!\n");
		return 0;
	}
	return 1;
}
Beispiel #17
0
char *rm16_imm8(char *buffer, int *j, int *err)
{
	int error = 0 ;
	memset(str, '\0', 255) ;
	char *s = rm(buffer, j, 16, &error) ;
	if (error)
	{
		*err = 1 ; 
		return str ;
	}
	(*j)++ ;
	if (get_bytes(1, *j))
	{
		(*j)--;
		*err = 1 ; 
		return str ;
	}
	(*j)--;
	(*j)++; 
	bytes++ ;
	signed char imm8 = buffer[*j] ; 
	char sign = '+' ;
	if (imm8 < 0) 
	{
		sign = '-' ;
		imm8 = -imm8 ;
	}
	sprintf(str, "%s,byte %c0x%x", s, sign, imm8) ;
	return str ;
}
// -----------------------------------------------------------------------------
//  Read a <block> from <index>
//
//  We point out the difference of counting among the <number>, <act_block> 
//  and <pos>.
//  (1) <num_blocks_>: record the number of blocks, excluding the block
//      of header. start from 1. (internal block)
//  (2) <act_block_>: record the number of blocks currently read or written,
//      including the block of header, thus when we read or write file,
//      current <act_block> equal to 1. <act_block> is corresponding to
//      file pointer.
//  (3) <index> : record position of block we want to read or write, excluding
//      the block of header. start from 0. (external block), i.e., when 
//      <index> = 0, the file pointer is pointed to next block after the 
//      block of header, at this time, <act_block_> equals to 1.
//
//  i.e. if number = 3, there are 4 blocks in the file, 1 header block +
//  3 data block.
//
//  When file is opened, <act_block_> = 1. if <index> = 1, it means that we 
//  want to read or write the 3rd block (2nd data block), thus firstly index++,
//  then <index> = 2, then fseek move to 2nd data block.
//
//  After reading or writing the 2nd data block, file pointer is pointed to 
//  the 3rd data block. As we know it has read or written 3 blocks, thus 
//  currently <act_block> = <index> + 1 = 2 + 1 = 3.
// -----------------------------------------------------------------------------
bool BlockFile::read_block(			// read a <block> from <index>
	Block block,						// a <block> (return)
	int index)							// pos of the block
{
	index++;						// extrnl block to intrnl block
									// move to the position
	if (index <= num_blocks_ && index > 0) {
		seek_block(index);
	}
	else {
		printf("BlockFile::read_block request the block %d "
			"which is illegal.", index - 1);
		error("\n", true);
	}

	get_bytes(block, block_length_);// read the block
	if (index + 1 > num_blocks_) {	// <fp_> reaches the end of file
		fseek(fp_, 0, SEEK_SET);
		act_block_ = 0;				// <act_block_> rewind to start pos
	}
	else {
		act_block_ = index + 1;		// <act_block_> to next pos
	}
	return true;
}
Beispiel #19
0
char *rm16_imm16(char *buffer, int *j, int *err)
{
	int error = 0; 
	memset(str, '\0', 255) ;
	char *s = rm(buffer, j, 16, &error) ;
	if (error)
	{
		*err = 1 ; 
		return str ;
	}
	(*j)++ ;
	if (get_bytes(2, *j))
	{
		(*j)-- ;
		*err = 1 ;
		return str ;
	}
	(*j)-- ;
	(*j)++;
	bytes++ ;
	unsigned char low = buffer[*j] ; 
	(*j)++ ;
	bytes++ ;
	unsigned char high = buffer[*j] ; 
	unsigned short imm16 = ((high << 8) + low) ; 
	sprintf(str, "%s,0x%x", s, imm16) ;
	return str ;
}
Beispiel #20
0
static inline AVP_dword DATA_PARAM get_qword ( Serialize* sz, AVP_qword* val ) {
	if ( get_bytes(sz,val,sizeof(AVP_qword)) != sizeof(AVP_qword) )
		return 0;

	WriteQWordPtr( val, *val );
	return sizeof(AVP_qword);
}
Beispiel #21
0
// Increase the maximum number of interrupts
static void _max_irqs(struct client *client, uint8_t id)
{
    struct psl *psl;
    uint8_t buffer[MAX_LINE_CHARS];
    uint8_t major, minor;
    uint16_t value;

    // Retrieve requested new maximum interrupts
    psl = _find_psl(id, &major, &minor);
    if (get_bytes(client->fd, 2, buffer, psl->timeout, &(client->abort),
                  psl->dbg_fp, psl->dbg_id, client->context) < 0) {
        client_drop(client, PSL_IDLE_CYCLES, CLIENT_NONE);
        return;
    }
    memcpy((char *)&client->max_irqs, (char *)buffer, sizeof(uint16_t));
    client->max_irqs = ntohs(client->max_irqs);

    // Limit to legal value
    if (client->max_irqs < psl->mmio->desc.num_ints_per_process)
        client->max_irqs = psl->mmio->desc.num_ints_per_process;
    if (client->max_irqs > 2037 / psl->mmio->desc.num_of_processes)
        client->max_irqs = 2037 / psl->mmio->desc.num_of_processes;

    // Return set value
    buffer[0] = PSLSE_MAX_INT;
    value = htons(client->max_irqs);
    memcpy(&(buffer[1]), (char *)&value, 2);
    if (put_bytes(client->fd, 3, buffer, psl->dbg_fp, psl->dbg_id,
                  client->context) < 0) {
        client_drop(client, PSL_IDLE_CYCLES, CLIENT_NONE);
    }
}
Beispiel #22
0
static char *
get_address_block_header(struct olsrv2* olsr,
             struct address_block_info *info, char *msg_ptr)
{

  olsr_u8_t head_octet, tail_octet;

  msg_ptr = get_u8(msg_ptr, &info->num_addr);

  // check head_length & no_tail bit
  msg_ptr = get_u8(msg_ptr, &head_octet);
  info->head_length = head_octet & GET_HEAD_LENGTH;
  info->no_tail = (head_octet & NO_TAIL) != 0 ? 1 : 0;

  // get head
  memset(&info->head, 0 , sizeof(union olsr_ip_addr));
  msg_ptr = get_bytes(msg_ptr, info->head_length, &info->head);

  //check invalid info
  if(info->head_length > olsr->olsr_cnf->ipsize)
    olsr_printf("\n\tWarning : [length is too long (%u) ] %s(%u)\n", info->head_length, __FUNCTION__, __LINE__);

  //check tail part
  if(info->no_tail == 0){ // contains tail
    msg_ptr = get_u8(msg_ptr, &tail_octet);
    info->tail_length = tail_octet & GET_TAIL_LENGTH;
    info->zero_tail = (tail_octet & ZERO_TAIL) != 0 ? 1 : 0;

    //get tail
    memset(&info->tail, 0, sizeof(union olsr_ip_addr));
    if(info->zero_tail == 0)
      msg_ptr = get_bytes(msg_ptr, info->tail_length, &info->tail);

    //check invalid info
    if(info->tail_length > olsr->olsr_cnf->ipsize)
      olsr_printf("\n\tWarning : [length is too long (%u) ] %s(%u)\n", info->head_length, __FUNCTION__, __LINE__);

  }else{ // not includes tail
    info->tail_length = 0;
    info->zero_tail = 1;
  }

  //mid_length
  info->mid_length = (olsr_u8_t)olsr->olsr_cnf->ipsize - info->head_length - info->tail_length;

  return msg_ptr;
}
Beispiel #23
0
int 
Stream::get( int		&i)
{
	int		tmp;
	char	pad[INT_SIZE-sizeof(int)], sign;

	switch(_code){
		case internal:
			if (get_bytes(&i, sizeof(int)) != sizeof(int)) {
                dprintf(D_NETWORK, "Stream::get(int) from internal failed\n");
                return FALSE;
            }
			break;

		case external: {
			if (INT_SIZE > sizeof(int)) { // get overflow bytes
				if (get_bytes(pad, INT_SIZE-sizeof(int))
					!= INT_SIZE-sizeof(int)) {
                    dprintf(D_NETWORK, "Stream::get(int) failed to read padding\n");
					return FALSE;
				}
			}
			if (get_bytes(&tmp, sizeof(int)) != sizeof(int)) {
                dprintf(D_NETWORK, "Stream::get(int) failed to read int\n");
                return FALSE;
            }
			i = ntohl(tmp);
			sign = (i >= 0) ? 0 : 0xff;
			for (int s=0; s < INT_SIZE-(int)sizeof(int); s++) { // chk 4 overflow
				if (pad[s] != sign) {
                    dprintf(D_NETWORK,
                            "Stream::get(int) incorrect pad received: %x\n",
                            pad[s]);
					return FALSE; // overflow
				}
			}
			break;
		}

		case ascii:
			return FALSE;
	}
   putcount =0;
   getcount += 4;
   NETWORK_TRACE("get int " << i<< " c(" << getcount << ") ");
	return TRUE;
}
Beispiel #24
0
static inline AVP_dword DATA_PARAM get_avp_property( Serialize* sz, AVP_Property* val ) {
	if ( get_bytes(sz,val,sizeof(AVP_Property)) == sizeof(AVP_Property) ) {
		val->id = ReadWordPtr (&val->id);
		return sizeof(AVP_Property);
	}

	return 0;
}
Beispiel #25
0
static Xauth *
read_numeric(FILE *fp)
{
    Xauth *auth;

    auth = (Xauth *) malloc (sizeof (Xauth));
    if (!auth) goto bad;
    auth->family = 0;
    auth->address = NULL;
    auth->address_length = 0;
    auth->number = NULL;
    auth->number_length = 0;
    auth->name = NULL;
    auth->name_length = 0;
    auth->data = NULL;
    auth->data_length = 0;

    if (!get_short (fp, (unsigned short *) &auth->family))
      goto bad;
    if (!get_short (fp, (unsigned short *) &auth->address_length))
      goto bad;
    if (!get_bytes (fp, (unsigned int) auth->address_length, &auth->address))
      goto bad;
    if (!get_short (fp, (unsigned short *) &auth->number_length))
      goto bad;
    if (!get_bytes (fp, (unsigned int) auth->number_length, &auth->number))
      goto bad;
    if (!get_short (fp, (unsigned short *) &auth->name_length))
      goto bad;
    if (!get_bytes (fp, (unsigned int) auth->name_length, &auth->name))
      goto bad;
    if (!get_short (fp, (unsigned short *) &auth->data_length))
      goto bad;
    if (!get_bytes (fp, (unsigned int) auth->data_length, &auth->data))
      goto bad;
    
    switch (getinput (fp)) {		/* get end of line */
      case EOF:
      case '\n':
	return auth;
    }

  bad:
    if (auth) XauDisposeAuth (auth);	/* won't free null pointers */
    return NULL;
}
Beispiel #26
0
/*For rank 2, I believe I'm doing this correctly, but doesn't work as expected when printed*/
void arr_set(Array * arr, int coords[3], void * val ){
	int bytes = get_bytes(arr);

	if (arr->rank == 1){
		memcpy(&(arr->vals[coords[0]* bytes]), val, bytes);
	}
	if (arr->rank == 2){
		memcpy(&(arr->vals[(arr->dims[0] * coords[1] + coords[0]) * bytes]), val, bytes);
	}
}
char* 
get_string(int pipe) {
    short len;
    int readres;
    char *str;
    
    /* Read the string length */

    get_bytes(pipe, &len, 2);

    /* Malloc the string with null termination */
    str = (char*) malloc(len+1);

    get_bytes(pipe, str, len);

    str[len] = '\0';

    return str;
}
Beispiel #28
0
 template<class T> bool 
 unpack_int (T *v)
 {
   u_int8_t buf[sizeof (T)];
   bool ok = get_bytes (buf, sizeof (T));
   if (ok) {
     big_endian (*v, buf, sizeof (T));
   } 
   return ok;
 }
Beispiel #29
0
static pyc_object *get_ascii_object_generic(RBuffer *buffer, ut32 size,
		bool interned) {
	pyc_object *ret = R_NEW0 (pyc_object);
	if (!ret)
		return NULL;
	ret->type = TYPE_ASCII;
	ret->data = get_bytes (buffer, size);
	if (!ret->data)
		R_FREE (ret);
	return ret;
}
Beispiel #30
0
int 
Stream::get( long	&l)
{
	int		i;
	char	pad[INT_SIZE-sizeof(long)], sign;

	switch(_code){
		case internal:
			if (get_bytes(&l, sizeof(long)) != sizeof(long)) return FALSE;
			break;

		case external:
			if ((sizeof(int) == sizeof(long)) || (sizeof(long) > INT_SIZE)) {
				if (!get(i)) return FALSE;
				l = (long) i;
			} else {
				if (sizeof(long) < INT_SIZE) {
					if (get_bytes(pad, INT_SIZE-sizeof(long))
						!= INT_SIZE-sizeof(long)) {
						return FALSE;
					}
				}
				if (get_bytes(&l, sizeof(long)) != sizeof(long)) return FALSE;
				if (!hton_is_noop()) { // need to convert to host order
					l = ntohL(l);
				}
				sign = (l >= 0) ? 0 : 0xff;
				for (int s=0; s < INT_SIZE-(int)sizeof(long); s++) { // overflow?
					if (pad[s] != sign) {
						return FALSE; // overflow
					}
				}
			}
			break;

		case ascii:
			return FALSE;
	}
    NETWORK_TRACE("get long " << l);
	return TRUE;
}