Exemple #1
0
int		parse_lc(t_sym **sym_lst, t_sect **sect_lst, char *ptr, uint8_t mask)
{
	int						i;
	int						ncmds;
	struct load_command		*lc;
	struct mach_header		*header;

	header = (struct mach_header *)ptr;
	ncmds = IS_BE(mask) ? swap_uint32(header->ncmds) : header->ncmds;
	swap_load_command(lc = ((void *)ptr +
		(IS_ARCH_64(mask) ? sizeof(struct mach_header_64)
		: sizeof(struct mach_header))), IS_BE(mask));
	ncmds = IS_BE(mask) ? swap_uint32(header->ncmds) : header->ncmds;
	i = 0;
	while (i < ncmds)
	{
		if (lc->cmd == LC_SEGMENT_64 || lc->cmd == LC_SEGMENT)
			add_sect_lst(lc, sect_lst, mask);
		else if (lc->cmd == LC_SYMTAB)
			if (add_symtab_lst((struct symtab_command *)lc,
					ptr, sym_lst, mask) == -1)
				return (EXIT_FAILURE);
		swap_load_command(lc = (void *)lc + lc->cmdsize, IS_BE(mask));
		i++;
	}
	return (0);
}
Exemple #2
0
void		handle_fat(char *ptr, char *file, int from, t_opt opt)
{
	struct fat_header	*header;
	struct fat_arch		*arch;
	int					size;
	uint32_t			offset;
	int					find;

	header = (struct fat_header*)ptr;
	size = swap_uint32(header->nfat_arch);
	arch = (void*)ptr + sizeof(header);
	find = find_x86_64(size, arch);
	offset = 0;
	if (find != 0)
	{
		while (size != find)
		{
			arch += sizeof(arch) / sizeof(void*);
			size--;
		}
		if (swap_uint32(arch->cputype) == CPU_TYPE_X86_64)
			offset = arch->offset;
		ft_otool(ptr + swap_uint32(offset), file, from, opt);
	}
	else
		other_arch(arch, ptr, file, opt);
}
// The labels values are 0 to 9.
void parseMnistSetLabels(const std::string& label_file, std::vector<size_t>* labels) {
  std::ifstream ifs_label(label_file, std::ios::in | std::ios::binary);

  if (ifs_label.fail()) {
    throw convnet_error("Failed to open file: " + label_file);
  }

  uint32_t magic_number;
  uint32_t num_items;

  ifs_label.read((char*) &magic_number, 4);
  ifs_label.read((char*) &num_items, 4);

  swap_uint32(magic_number);
  swap_uint32(num_items);

  if (magic_number != 0x00000801 || num_items <= 0) {
    throw convnet_error("MNIST label-file format error");
  }

  for (size_t i = 0; i < num_items; i++) {
    uint8_t label;
    ifs_label.read((char*) &label, 1);
    labels->push_back((size_t) label);
  }
}
Exemple #4
0
void		sec_32_cigam(int ncmds, struct load_command *lc, t_lst **section)
{
	unsigned int				j;
	int							k;
	struct section				*sec;
	struct segment_command		*seg;

	*section = NULL;
	k = 1;
	while (ncmds >= 0)
	{
		if (lc->cmd && swap_uint32(lc->cmd) == LC_SEGMENT)
		{
			j = -1;
			seg = (struct segment_command*)lc;
			sec = (struct section*)((void *)seg + sizeof(*seg));
			while (++j < swap_uint32(seg->nsects))
			{
				add_lst(section, new_lst_sec(sec->sectname, k++));
				sec = (void *)sec + sizeof(*sec);
			}
		}
		if (ft_strcmp(seg->segname, SEG_OBJC) == 0)
			break ;
		lc = swap_uint32(lc->cmdsize) + (void*)lc;
		ncmds--;
	}
}
static int of_update_property_value(void *blob,
				int property_offset,
				const void *value,
				int valuelen)
{
	int oldlen;
	unsigned int *plen;
	unsigned char *pvalue;
	void *point;
	int ret;

	plen = (unsigned int *)of_dt_struct_offset(blob, property_offset + 4);
	pvalue = (unsigned char *)of_dt_struct_offset(blob,
						property_offset + 12);
	point = (void *)pvalue;

	/* get the old len of value */
	oldlen = swap_uint32(*plen);

	ret = of_blob_move_dt_struct(blob, point,
			OF_ALIGN(oldlen), OF_ALIGN(valuelen));
	if (ret)
		return ret;

	/* set the new len and value */
	*plen = swap_uint32(valuelen);
	memcpy(pvalue, value, valuelen);

	return 0;
}
Exemple #6
0
static void swap_snoop_packet(struct snoop_packet *p)
{
	swap_uint32(&p->caplen);
	swap_uint32(&p->len);
	swap_uint32(&p->offset);
	swap_uint32(&((p->ts).tv_sec));
	swap_int32(&((p->ts).tv_usec));
}
void packetDetails_tcp(uint8_t *packetData)
{
	tcpHeader = (tcpHeader_t*)(packetData);

	printf("TCP header\n");

	PRINTINFO("Source port");
	PRINTPORT(tcpHeader->sourcePort);

	PRINTINFO("Destination port");
	PRINTPORT(tcpHeader->destinationPort);

	PRINTINFO("Sequence number");
	PRINTHEX32(swap_uint32(tcpHeader->sequenceNumber));

	PRINTINFO("Acknowledgement number");
	PRINTHEX32(swap_uint32(tcpHeader->acknowledgementNumber));

	// Flags
	uint16_t flag = swap_uint16(tcpHeader->flags);
	PRINTFLAG("Header length");
	PRINTUINT8(((flag & TCP_headerLength) >> TCP_headerLengthPos)*4);

	PRINTFLAG("Reserved");
	PRINTHEX16((flag & TCP_reserved) >> TCP_reservedPos);

	PRINTFLAG("URG");
	printf("%s\n", flagSetOrNot((flag & TCP_urg) >> TCP_urgPos));

	PRINTFLAG("ACK");
	printf("%s\n", flagSetOrNot((flag & TCP_ack) >> TCP_ackPos));

	PRINTFLAG("PSH");
	printf("%s\n", flagSetOrNot((flag & TCP_push) >> TCP_pushPos));

	PRINTFLAG("RST");
	printf("%s\n", flagSetOrNot((flag & TCP_reset) >> TCP_resetPos));

	PRINTFLAG("SYN");
	printf("%s\n", flagSetOrNot((flag & TCP_syn) >> TCP_synPos));

	PRINTFLAG("FIN");
	printf("%s\n", flagSetOrNot((flag & TCP_fin) >> TCP_synPos));

	PRINTINFO("Window size");
	PRINTUINT16(swap_uint16(tcpHeader->windowSize));

	PRINTINFO("Checksum");
	PRINTHEX16(swap_uint16(tcpHeader->checksum));

	PRINTINFO("Urgent pointer");
	PRINTUINT16(swap_uint16(tcpHeader->urgentPointer));

	packetDetails_data(packetData + TCP_LENGTH, (swap_uint16(ipHeader->totalLength) - (ipHeader->headerLength)*4 - TCP_LENGTH));
}
Exemple #8
0
UMachDebugInfo::UMachDebugInfo(Project *uproject)
{

    //first we read temporary the number / file assoziation


    QFile fmap( uproject->getProjectDir()->absoluteFilePath(QString(uproject->getName() + ".umx.fmap")) );
    if (!fmap.open(QIODevice::ReadOnly))
        throw (QString("Failed to open file"));

    QMap <uint32_t,IUasmFile*>fmapTable;

    QTextStream in(&fmap);
    QString fmapLine;
    QStringList fmapParseList;
    uint32_t fileId;
    IUasmFile *uasmFile;

    while (!(fmapLine = in.readLine()).isEmpty()) {

        fmapParseList = fmapLine.split(" ");

        //file Number
        fileId =  (uint32_t)fmapParseList.at(0).toInt();

        //file ponter
        uasmFile = uproject->getFileByAbsPath(fmapParseList.at(1));
        if (!uasmFile) throw (QString("File not in Project!"));

        //ad to temp map
        fmapTable.insert(fileId, uasmFile);
    }

    fmap.close();

    //now we read in binary data from debug and insert it into the overall table

    QFile debug( uproject->getProjectDir()->absoluteFilePath(QString(uproject->getName() + ".umx.debug")) );
    if (!debug.open(QIODevice::ReadOnly))
        throw (QString("Failed to open file"));

    //BIG-ENDIAN
    //<FILE-ID><LINE-NO><ADDRESS>
    uint32_t debugDatum[3];

    while (debug.read((char*)debugDatum, 12)) {
        //swap endianess to little
        uasmFile = fmapTable.value(swap_uint32(debugDatum[0]));
        uint32_t address = swap_uint32(debugDatum[2]);
        m_addressTable.insert(address, (new debugAddressEntry(uasmFile, swap_uint32(debugDatum[1]), address, NULL)));
    }

    debug.close();

}
Exemple #9
0
END_TEST

START_TEST(test_swap_uint32) {
    uint32 ile;
    uint32_be ibe;
    
    ile = 0x11223344U;
    ibe = swap_uint32(ile);
#ifndef WORDS_BIGENDIAN
    fail_if(ibe != 0x44332211U);
#endif
    fail_if(swap_uint32(ibe) != ile);
}
Exemple #10
0
END_TEST

START_TEST(test_swap_uint32_neg) {
    uint32 ile;
    uint32_be ibe;
    
    ile = 0xFFFEFDFCU;
    ibe = swap_uint32(ile);
#ifndef WORDS_BIGENDIAN
    fail_if(ibe != 0xFCFDFEFFU);
#endif
    fail_if(swap_uint32(ibe) != ile);
}
Exemple #11
0
static void swap_netmon_header(struct cap_header *h)
{
	swap_uint16(&h->captype);
	swap_uint16(&h->starttime.wYear);
	swap_uint16(&h->starttime.wMonth);
	swap_uint16(&h->starttime.wDayOfWeek);
	swap_uint16(&h->starttime.wDay);
	swap_uint16(&h->starttime.wHour);
	swap_uint16(&h->starttime.wMinute);
	swap_uint16(&h->starttime.wSecond);
	swap_uint16(&h->starttime.wMilliseconds);
	swap_uint32(&h->frameoffset);
	swap_uint32(&h->framelength);
}
Exemple #12
0
/** @ingroup substem_name
 * @brief Compute SSL IPAD and OPAD values.
 *
 * Computes a partial SSL MAC of the SSL secret. These values are later used
 * to compute the complete SSL MAC of a packet. The hash algorith for the MAC
 * is MD5. (SHA-1 SSL MACs don't us IPAD/OPAD values.)
 *
 * @param secret_p      RO: Pointer to the 16-byte MAC secret key.
 * @param ipad_p        WO: Pointer to the buffer that is to receive the 
 *                          precomputed IPAD values.
 * @param opad_p        WO: Pointer to the buffer that is to receive the 
 *                          precomputed OPAD values.
 *
 * @par Externals:
 *    None.
 *
 * @return
 *    N8_STATUS_OK - the function succeeded. 
 *
 * @par Errors:
 *    None.
 *   
 * @par Locks:
 *    None.
 *
 * @par Assumptions:
 *    IPAD and OPAD values are returned as arrays of uint32_t. 
 *****************************************************************************/
N8_Status_t n8_precompute_ssl_ipad_opad(N8_Buffer_t *secret_p,
                                        uint32_t *ipad_p, 
                                        uint32_t *opad_p)
{
   N8_Status_t status = N8_STATUS_OK;
   N8_PRECOMP_MD5_CTX     ctx;

   /* Hash the secret and pad_1 string using the IPAD context. */
   n8_precomp_MD5_Init(&ctx);
   n8_precomp_MD5_Update(&ctx, secret_p, SSL_MD5_Secret_Length);
   n8_precomp_MD5_Update(&ctx, pad_1, SSL_MD5_Pad_Length);
   ipad_p[0] = swap_uint32(ctx.A); 
   ipad_p[1] = swap_uint32(ctx.B); 
   ipad_p[2] = swap_uint32(ctx.C); 
   ipad_p[3] = swap_uint32(ctx.D);
#ifdef HMAC_DEBUG
   DBG(("IPAD={A=%08x B=%08x C=%08x D=%08x}\n", 
          ctx.A, ctx.B, ctx.C, ctx.D));
#endif

   /* Hash the secret and pad_2 string using the OPAD context. */
   n8_precomp_MD5_Init(&ctx);
   n8_precomp_MD5_Update(&ctx, secret_p, SSL_MD5_Secret_Length);
   n8_precomp_MD5_Update(&ctx, pad_2, SSL_MD5_Pad_Length);
   opad_p[0] = swap_uint32(ctx.A); 
   opad_p[1] = swap_uint32(ctx.B); 
   opad_p[2] = swap_uint32(ctx.C); 
   opad_p[3] = swap_uint32(ctx.D); 
#ifdef HMAC_DEBUG
   DBG(("OPAD={A=%08x B=%08x C=%08x D=%08x}\n", 
          ctx.A, ctx.B, ctx.C, ctx.D));
#endif
   
   return status;
} /* n8_precompute_ssl_ipad_opad */
Exemple #13
0
static inline void scale_sample_int32_t(int32_t *buf, int i, int vol, int swap)
{
	int64_t sample = swap ? (int32_t)swap_uint32(buf[i]) : buf[i];

	if (sample < 0) {
		sample = (sample * vol - SOFT_VOL_SCALE / 2) / SOFT_VOL_SCALE;
		if (sample < INT32_MIN)
			sample = INT32_MIN;
	} else {
		sample = (sample * vol + SOFT_VOL_SCALE / 2) / SOFT_VOL_SCALE;
		if (sample > INT32_MAX)
			sample = INT32_MAX;
	}
	buf[i] = swap ? swap_uint32(sample) : sample;
}
Exemple #14
0
void ga_cross_2p(knapsack_t *k, knapsack_solution_t *sa, knapsack_solution_t *sb) {
	int cross_point1 = rand() % k->n;
	int cross_point2 = rand() % k->n;
	int i;

	if (cross_point1 > cross_point2) {
		swap_uint32(&cross_point1, &cross_point2);
	}

	for (i = 0; i < k->n; i++) {
		if (i < cross_point1 && i > cross_point2) {
			swap_uint32(&sa->items[i], &sb->items[i]);
		}
	}
}
Exemple #15
0
uint32_t read_uint32(FILEBUFFER *f,JENV *env)
{
	uint32_t val,tmp;
	unsigned int pos;
	char *p;
	uint32_t *buf;
	assert(env!=NULL);
	assert(f!=NULL);
	if(file_len_dispo(f)<4)
	{
		tjvm_env_add_error_c(env,"Error in file : invalide size");
		return 0;
	}
	//assert(f->pos+4<f->len);
	pos=f->pos;
	buf=(uint32_t *)(f->buf+pos);
	//tmp=*buf[pos+1];
	val=swap_uint32(*buf);
	//pshort=(unsigned short *)f->buf;
		//version_mineur=swap_uint16(*pshort);
		//pshort++;
	f->pos+=4;
	assert(file_valide(f));
	return val;
}
Exemple #16
0
/* read an array */
static amf0_data * amf0_array_read(read_proc_t read_proc, void * user_data) {
    size_t i;
    amf0_data * element;
    amf0_data * data = amf0_array_new();
    if (data != NULL) {
        uint32_t array_size;
        if (read_proc(&array_size, sizeof(uint32_t), user_data) == sizeof(uint32_t)) {
            array_size = swap_uint32(array_size);
            
            for (i = 0; i < array_size; ++i) {
                element = amf0_data_read(read_proc, user_data);

                if (element != NULL) {
                    if (amf0_array_push(data, element) == NULL) {
                        amf0_data_free(element);
                        amf0_data_free(data);
                        return NULL;
                    }
                }
                else {
                    amf0_data_free(data);
                    return NULL;
                }
            }
        }
        else {
            amf0_data_free(data);
            return NULL;
        }
    }
    return data;
}
Exemple #17
0
static void	other_arch(struct fat_arch *arch, char *ptr, char *file, t_opt opt)
{
	int					size;

	size = swap_uint32(((struct fat_header*)ptr)->nfat_arch);
	while (size)
	{
		ft_putstr(file);
		if (swap_uint32(arch->cputype) == CPU_TYPE_POWERPC)
			ft_putendl(" (architecture ppc):");
		else if (swap_uint32(arch->cputype) == CPU_TYPE_I386)
			ft_putendl(" (architecture i386):");
		ft_otool(ptr + swap_uint32(arch->offset), file, FROM_AR, opt);
		arch += sizeof(arch) / sizeof(void*);
		size--;
	}
}
/* return the token and the next token offset
 */
static int of_get_token_nextoffset(void *blob,
				int startoffset,
				int *nextoffset,
				unsigned int *token)
{
	const unsigned int *p, *plen;
	unsigned int tag;
	const char *cell;
	unsigned int offset = startoffset;

	*nextoffset = -1;

	if (offset % 4) {
		dbg_info("DT: the token offset is not aligned\n");
		return -1;
	}

	/* Get the token */
	p = (unsigned int *)of_dt_struct_offset(blob, offset);
	tag = swap_uint32(*p);

	/* to get offset for the next token */
	offset += 4;
	if (tag  == OF_DT_TOKEN_NODE_BEGIN) {
		/* node name */
		cell = (char *)of_dt_struct_offset(blob, offset);
		do {
			cell++;
			offset++;
		} while (*cell != '\0');
	} else if (tag == OF_DT_TOKEN_PROP) {
		/* the property value size */
		plen = (unsigned int *)of_dt_struct_offset(blob, offset);
		/* name offset + value size + value */
		offset += swap_uint32(*plen) + 8;
	} else if ((tag != OF_DT_TOKEN_NODE_END)
			&& (tag != OF_DT_TOKEN_NOP)
			&& (tag != OF_DT_END))
		return -1;

	*nextoffset = OF_ALIGN(offset);
	*token = tag;

	return 0;
}
Exemple #19
0
void ga_cross_1p(knapsack_t *k, knapsack_solution_t *sa, knapsack_solution_t *sb) {
	int cross_point1 = rand() % k->n;
	int i;

	for (i = 0; i < k->n; i++) {
		if (i < cross_point1) {
			swap_uint32(&sa->items[i], &sb->items[i]);
		}
	}
}
Exemple #20
0
void NetworkMessage::AddU32(const uint32_t& value)
{
	if (!canAdd(4))
	{
		return;
	}

	*(uint32_t*)(m_MsgBuf + m_ReadPos) = swap_uint32(value);
	m_ReadPos += 4;
	m_MsgSize += 4;
}
static int of_add_property(void *blob,
				int nextoffset,
				const char *property_name,
				const void *value,
				int valuelen)
{
	int string_offset;
	unsigned int *p;
	unsigned int addr;
	int len;
	int ret;

	/* check if the property name in the dt_strings,
	 * else add the string in dt strings
	 */
	ret = of_string_is_find_strings_blob(blob,
				property_name, &string_offset);
	if (ret) {
		ret = of_add_string_strings_blob(blob,
				property_name, &string_offset);
		if (ret)
			return ret;
	}

	/* add the property node in dt struct */
	len = 12 + OF_ALIGN(valuelen);
	addr = of_dt_struct_offset(blob, nextoffset);
	ret = of_blob_move_dt_struct(blob, (void *)addr, 0, len);
	if (ret)
		return ret;

	p = (unsigned int *)addr;

	/* set property node: token, value size, name offset, value */
	*p++ = swap_uint32(OF_DT_TOKEN_PROP);
	*p++ = swap_uint32(valuelen);
	*p++ = swap_uint32(string_offset);
	memcpy((unsigned char *)p, value, valuelen);

	return 0;
}
void parseMnistHeader(std::ifstream& ifs, mnist_header& header) {
  ifs.read((char*) &header.magic_number, 4);
  ifs.read((char*) &header.num_images, 4);
  ifs.read((char*) &header.num_rows, 4);
  ifs.read((char*) &header.num_columns, 4);
  
  // MNIST integers stored in big-endian(most significant bit) format
  // Reverses order to little-endian byte order
  swap_uint32(header.magic_number);
  swap_uint32(header.num_images);
  swap_uint32(header.num_rows);
  swap_uint32(header.num_columns);
  
  if (header.magic_number != 0x00000803 || header.num_images <= 0) {
    throw convnet_error("MNIST label-file format error");
  }
  
  if (ifs.fail()) {
    throw convnet_error("File error");
  }
}
/* The /memory node
 * Required properties:
 * - device_type: has to be "memory".
 * - reg: this property contains all the physical memory ranges of your boards.
 */
int fixup_memory_node(void *blob,
			unsigned int *mem_bank,
			unsigned int *mem_size)
{
	int nodeoffset;
	unsigned int data[2];
	int valuelen;
	int ret;

	ret = of_get_node_offset(blob, "memory", &nodeoffset);
	if (ret) {
		dbg_info("DT: doesn't support add node\n");
		return ret;
	}

	/*
	 * if the property doesn't exit, add it
	 * if the property exists, update it.
	 */
	/* set "device_type" property */
	ret = of_set_property(blob, nodeoffset,
			"device_type", "memory", sizeof("memory"));
	if (ret) {
		dbg_info("DT: could not set device_type property\n");
		return ret;
	}

	/* set "reg" property */
	valuelen = 8;
	data[0] = swap_uint32(*mem_bank);
	data[1] = swap_uint32(*mem_size);

	ret = of_set_property(blob, nodeoffset, "reg", data, valuelen);
	if (ret) {
		dbg_info("DT: could not set reg property\n");
		return ret;
	}

	return 0;
}
Exemple #24
0
void ga_cross_2p(bool *a, bool *b, uint32_t n) {
	uint32_t cross_point1 = rand() % n;
	uint32_t cross_point2 = rand() % n;

	if (cross_point1 > cross_point2) {
		swap_uint32(&cross_point1, &cross_point2);
	}

	for (uint32_t i = 0; i < n; i++) {
		if (i < cross_point1 && i > cross_point2) {
			swap_bool(&a[i], &b[i]);
		}
	}
}
Exemple #25
0
/* write an array */
static size_t amf0_array_write(amf0_data * data, write_proc_t write_proc, void * user_data) {
    amf0_node * node;
    size_t w = 0;
    uint32_t s;

    s = swap_uint32(data->list_data.size);
    w += write_proc(&s, sizeof(uint32_t), user_data);
    node = amf0_array_first(data);
    while (node != NULL) {
        w += amf0_data_write(amf0_array_get(node), write_proc, user_data);
        node = amf0_array_next(node);
    }

    return w;
}
Exemple #26
0
static int	find_x86_64(uint32_t size, struct fat_arch *arch)
{
	uint32_t			find;

	find = 0;
	while (size)
	{
		if (swap_uint32(arch->cputype) == CPU_TYPE_X86_64)
		{
			find = size;
			break ;
		}
		arch += sizeof(arch) / sizeof(void*);
		size--;
	}
	return (find);
}
Exemple #27
0
static int raw_on_header(flv_header * header, flv_parser * parser) {
    int * n;
    
    n = (int*) malloc(sizeof(uint32));
    if (n == NULL) {
        return ERROR_MEMORY;
    }

    parser->user_data = n;
    *n = 0;

    printf("Magic: %.3s\n", header->signature);
    printf("Version: %d\n", header->version);
    printf("Has audio: %s\n", flv_header_has_audio(*header) ? "yes" : "no");
    printf("Has video: %s\n", flv_header_has_video(*header) ? "yes" : "no");
    printf("Offset: %u\n", swap_uint32(header->offset));
    return OK;
}
Exemple #28
0
/* write an associative array */
static size_t amf0_associative_array_write(amf0_data * data, write_proc_t write_proc, void * user_data) {
    amf0_node * node;
    size_t w = 0;
    uint32_t s;
    uint16_t filler = swap_uint16(0);
    uint8_t terminator = AMF0_TYPE_OBJECT_END;

    s = swap_uint32(data->list_data.size) / 2;
    w += write_proc(&s, sizeof(uint32_t), user_data);
    node = amf0_associative_array_first(data);
    while (node != NULL) {
        w += amf0_string_write(amf0_associative_array_get_name(node), write_proc, user_data);
        w += amf0_data_write(amf0_associative_array_get_data(node), write_proc, user_data);
        node = amf0_associative_array_next(node);
    }

    /* empty string is the last element */
    w += write_proc(&filler, sizeof(uint16_t), user_data);
    /* an object ends with 0x09 */
    w += write_proc(&terminator, sizeof(uint8_t), user_data);

    return w;
}
Exemple #29
0
/* read an array */
static amf_data * amf_array_read(amf_read_proc read_proc, void * user_data) {
    size_t i;
    amf_data * element;
    byte error_code;
    amf_data * data;
    uint32 array_size;

    data = amf_array_new();
    if (data == NULL) {
        return NULL;
    }

    if (read_proc(&array_size, sizeof(uint32), user_data) < sizeof(uint32)) {
        amf_data_free(data);
        return amf_data_error(AMF_ERROR_EOF);
    }

    array_size = swap_uint32(array_size);

    for (i = 0; i < array_size; ++i) {
        element = amf_data_read(read_proc, user_data);
        error_code = amf_data_get_error_code(element);
        if (error_code != AMF_ERROR_OK) {
            amf_data_free(element);
            amf_data_free(data);
            return amf_data_error(error_code);
        }

        if (amf_array_push(data, element) == NULL) {
            amf_data_free(element);
            amf_data_free(data);
            return NULL;
        }
    }

    return data;
}
static int of_get_property_offset_by_name(void *blob,
					unsigned int nodeoffset,
					char *name,
					int *offset)
{
	unsigned int nameoffset;
	unsigned int *p;
	unsigned int namelen = strlen(name);
	int startoffset = nodeoffset;
	int property_offset = 0;
	int nextoffset = 0;
	char *string;
	int ret;

	*offset = 0;

	while (1) {
		ret = of_get_next_property_offset(blob, startoffset,
					&property_offset, &nextoffset);
		if (ret)
			return ret;

		p = (unsigned int *)of_dt_struct_offset(blob,
						property_offset + 8);
		nameoffset = swap_uint32(*p);
		string = of_get_string_by_offset(blob, nameoffset);
		if ((strlen(string) == namelen)
			&& (memcmp(string, name, namelen) == 0)) {
			*offset = property_offset;
			return 0;
		}
		startoffset = nextoffset;
	}

	return -1;
}