Example #1
0
int first_bytes_header(u16 seqnum, char *header, int header_len, char *buf, int buf_len){	
	int len;

	len=encode_to_7bit(header, (buf_len+6)*2, 5);
	if (len==-1){
		return -1;
	};

	seqnum=bswap16(seqnum);
	memcpy(header+len,(char *)&seqnum,2);
	seqnum=bswap16(seqnum);
	len+=2;
	
	header[len]=buf_len+2;
	len++;

	header[len]=0x32;
	len++;

	seqnum--;
	seqnum=bswap16(seqnum);
	memcpy(header+len,(char *)&seqnum,2);
	len+=2;

	return len;

};
Example #2
0
void
ffs_dinode2_swap(struct ufs2_dinode *o, struct ufs2_dinode *n)
{
	n->di_mode = bswap16(o->di_mode);
	n->di_nlink = bswap16(o->di_nlink);
	n->di_uid = bswap32(o->di_uid);
	n->di_gid = bswap32(o->di_gid);
	n->di_blksize = bswap32(o->di_blksize);
	n->di_size = bswap64(o->di_size);
	n->di_blocks = bswap64(o->di_blocks);
	n->di_atime = bswap64(o->di_atime);
	n->di_atimensec = bswap32(o->di_atimensec);
	n->di_mtime = bswap64(o->di_mtime);
	n->di_mtimensec = bswap32(o->di_mtimensec);
	n->di_ctime = bswap64(o->di_ctime);
	n->di_ctimensec = bswap32(o->di_ctimensec);
	n->di_birthtime = bswap64(o->di_ctime);
	n->di_birthnsec = bswap32(o->di_ctimensec);
	n->di_gen = bswap32(o->di_gen);
	n->di_kernflags = bswap32(o->di_kernflags);
	n->di_flags = bswap32(o->di_flags);
	n->di_extsize = bswap32(o->di_extsize);
	memcpy(n->di_extb, o->di_extb, sizeof(n->di_extb));
	memcpy(n->di_db, o->di_db, sizeof(n->di_db));
	memcpy(n->di_ib, o->di_ib, sizeof(n->di_ib));
}
Example #3
0
int process_tcp_pkt2(char *pkt, int pkt_len, int *last_recv_pkt_num) {
	int ret;

	RC4_crypt(pkt, pkt_len, &rc4_save, 0);

	memcpy(last_recv_pkt_num,pkt+1,2);
	*last_recv_pkt_num=bswap16(*last_recv_pkt_num);
	(*last_recv_pkt_num)++;
	*last_recv_pkt_num=bswap16(*last_recv_pkt_num);

	show_memory(pkt,pkt_len,"result2:");
	
	// supernode check
	// if yet 06 0x21 blob, this is supernode reply
	ret=main_unpack_test(pkt, pkt_len, 0x06, 0x21) ;

	if (ret==0){
		//printf("skype client, dumping nodes\n");
		//main_unpack_saveip(pkt,pkt_len);
		return -1;
	};

	
	return 0;
};
Example #4
0
extern "C" void AsebaSendBuffer(AsebaVMState *vm, const uint8* data, uint16 length)
{
	Enki::AsebaMarxbot& marxBot = *asebaSocketMaps[vm];
	Dashel::Stream* stream = marxBot.stream;
	if (!stream)
		return;
	
	// send to stream
	try
	{
		uint16 temp;
		temp = bswap16(length - 2);
		stream->write(&temp, 2);
		temp = bswap16(vm->nodeId);
		stream->write(&temp, 2);
		stream->write(data, length);
		stream->flush();

		// push to other nodes
		for (size_t i = 0; i < marxBot.modules.size(); ++i)
		{
			Enki::AsebaMarxbot::Module& module = *(marxBot.modules[i]);
			if (&(module.vm) != vm) 
			{
				module.events.push_back(Enki::AsebaMarxbot::Event(vm->nodeId, data, length));
				AsebaProcessIncomingEvents(&(module.vm));
			}
		}
	}
	catch (Dashel::DashelException e)
	{
		std::cerr << "Cannot write to socket: " << stream->getFailReason() << std::endl;
	}
}
void dvb_desc_service_location_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf, struct dvb_desc *desc)
{
	struct dvb_desc_service_location *service_location = (struct dvb_desc_service_location *) desc;
	uint8_t *endbuf = buf + desc->length;
	ssize_t size = sizeof(struct dvb_desc_service_location) - sizeof(struct dvb_desc);
	struct dvb_desc_service_location_element *element;
	int i;

	if (buf + size > endbuf) {
		dvb_logerr("%s: short read %d/%zd bytes", __FUNCTION__, endbuf - buf, size);
		return;
	}

	memcpy(desc->data, buf, size);
	bswap16(service_location->bitfield);
	buf += size;

	if (service_location->elements == 0)
		return;

	size = service_location->elements * sizeof(struct dvb_desc_service_location_element);
	if (buf + size > endbuf) {
		dvb_logerr("%s: short read %d/%zd bytes", __FUNCTION__, endbuf - buf, size);
		return;
	}
	service_location->element = malloc(size);
	element = service_location->element;
	for (i = 0; i < service_location->elements; i++) {
		memcpy(element, buf, sizeof(struct dvb_desc_service_location_element) - 1); /* no \0 in lang */
		buf += sizeof(struct dvb_desc_service_location_element) - 1;
		element->language[3] = '\0';
		bswap16(element->bitfield);
		element++;
	}
}
Example #6
0
struct mpeg_odsmt_section *mpeg_odsmt_section_codec(struct section_ext * ext)
{
	struct mpeg_odsmt_section * odsmt = (struct mpeg_odsmt_section *)ext;
	uint8_t * buf = (uint8_t *)ext;
	size_t pos = sizeof(struct section_ext);
	size_t len = section_ext_length(ext);
	int i;

	if (len < sizeof(struct mpeg_odsmt_section))
		return NULL;

	pos++;

	if (odsmt->stream_count == 0) {
		struct mpeg_odsmt_stream * stream =
			(struct mpeg_odsmt_stream *) (buf + pos);

		if ((pos + sizeof(struct mpeg_odsmt_stream_single)) > len)
			return NULL;

		bswap16(buf+pos);
		pos+=3;

		if ((pos + stream->u.single.es_info_length) >= len)
			return NULL;

		if (verify_descriptors(buf + pos, stream->u.single.es_info_length))
			return NULL;

		pos += stream->u.single.es_info_length;
	} else {
		for (i=0; i< odsmt->stream_count; i++) {
			struct mpeg_odsmt_stream * stream =
				(struct mpeg_odsmt_stream *)(buf + pos);

			if ((pos + sizeof(struct mpeg_odsmt_stream_multi)) > len)
				return NULL;

			bswap16(buf+pos);
			pos += sizeof(struct mpeg_odsmt_stream_multi);

			if ((pos + stream->u.multi.es_info_length) > len)
				return NULL;

			if (verify_descriptors(buf + pos,
			    stream->u.multi.es_info_length))
				return NULL;

			pos += stream->u.multi.es_info_length;
		}
	}

	if (pos != len)
		return NULL;

	return (struct mpeg_odsmt_section *) ext;
}
Example #7
0
struct dvb_int_section * dvb_int_section_codec(struct section_ext *ext)
{
	uint8_t *buf = (uint8_t *) ext;
	struct dvb_int_section *in = (struct dvb_int_section *) ext;
	size_t pos = sizeof(struct section_ext);
	size_t len = section_ext_length(ext);

	if (len < sizeof(struct dvb_int_section))
		return NULL;

	bswap32(buf+8);
	bswap16(buf+12);
	pos += 6;

	if (len - pos < in->platform_descriptors_length)
		return NULL;

	if (verify_descriptors(buf + pos, in->platform_descriptors_length))
		return NULL;

	pos += in->platform_descriptors_length;

	while (pos < len) {
		struct dvb_int_target *s2 = (struct dvb_int_target *) (buf + pos);
		struct dvb_int_operational_loop *s3;

		bswap16(buf + pos); /* target_descriptor_loop_length swap */

		if (len - pos < s2->target_descriptors_length)
			return NULL;

		pos += sizeof(struct dvb_int_target);

		if (verify_descriptors(buf + pos, s2->target_descriptors_length))
			return NULL;

		pos += s2->target_descriptors_length;

		s3 = (struct dvb_int_operational_loop *) (buf + pos);

		bswap16(buf + pos); /* operational_descriptor_loop_length swap */

		if (len - pos < s3->operational_descriptors_length)
			return NULL;

		pos += sizeof(struct dvb_int_operational_loop);

		if (verify_descriptors(buf + pos, s3->operational_descriptors_length))
			return NULL;

		pos += s3->operational_descriptors_length;
	}

	return (struct dvb_int_section *) ext;
}
struct dvb_nit_section *dvb_nit_section_codec(struct section_ext * ext)
{
	uint8_t * buf = (uint8_t *) ext;
	struct dvb_nit_section * ret = (struct dvb_nit_section *) ext;
	size_t pos = sizeof(struct section_ext);
	size_t len = section_ext_length(ext);

	if (len < sizeof(struct dvb_nit_section))
		return NULL;

	bswap16(buf + pos);
	pos += 2;

	if ((pos + ret->network_descriptors_length) > len)
		return NULL;

	if (verify_descriptors(buf + pos, ret->network_descriptors_length))
		return NULL;

	pos += ret->network_descriptors_length;

	if ((pos + sizeof(struct dvb_nit_section_part2)) > len)
		return NULL;

	bswap16(buf + pos);
	pos += 2;

	while (pos < len) {
		struct dvb_nit_transport *transport =
			(struct dvb_nit_transport *)(buf + pos);

		if ((pos + sizeof(struct dvb_nit_transport)) > len)
			return NULL;

		bswap16(buf + pos);
		bswap16(buf + pos + 2);
		bswap16(buf + pos + 4);

		pos += sizeof(struct dvb_nit_transport);

		if ((pos + transport->transport_descriptors_length) > len)
			return NULL;

		if (verify_descriptors(buf + pos,
					transport->transport_descriptors_length))
			return NULL;

		pos += transport->transport_descriptors_length;
	}

	if (pos != len)
		return NULL;

	return ret;
}
Example #9
0
void dvb_table_sdt_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf,
			ssize_t buflen, uint8_t *table, ssize_t *table_length)
{
	const uint8_t *p = buf, *endbuf = buf + buflen - 4;
	struct dvb_table_sdt *sdt = (void *)table;
	struct dvb_table_sdt_service **head = &sdt->service;
	size_t size = offsetof(struct dvb_table_sdt, service);

	if (*table_length > 0) {
		/* find end of curent list */
		while (*head != NULL)
			head = &(*head)->next;
	} else {
		if (p + size > endbuf) {
			dvb_logerr("SDT table was truncated. Need %zu bytes, but has only %zu.",
					size, buflen);
			return;
		}
		memcpy(sdt, p, size);
		*table_length = sizeof(struct dvb_table_sdt);

		bswap16(sdt->network_id);

		sdt->service = NULL;
	}
	p += size;

	size = offsetof(struct dvb_table_sdt_service, descriptor);
	while (p + size <= endbuf) {
		struct dvb_table_sdt_service *service;

		service = malloc(sizeof(struct dvb_table_sdt_service));

		memcpy(service, p, size);
		p += size;

		bswap16(service->service_id);
		bswap16(service->bitfield);
		service->descriptor = NULL;
		service->next = NULL;

		*head = service;
		head = &(*head)->next;

		/* get the descriptors for each program */
		dvb_parse_descriptors(parms, p, service->section_length,
				      &service->descriptor);

		p += service->section_length;
	}
	if (endbuf - p)
		dvb_logerr("PAT table has %zu spurious bytes at the end.",
			   endbuf - p);
}
Example #10
0
/* warning: addr must be aligned */
static inline uint32_t glue(address_space_lduw_internal, SUFFIX)(ARG1_DECL,
    hwaddr addr, MemTxAttrs attrs, MemTxResult *result,
    enum device_endian endian)
{
    uint8_t *ptr;
    uint64_t val;
    MemoryRegion *mr;
    hwaddr l = 2;
    hwaddr addr1;
    MemTxResult r;
    bool release_lock = false;

    RCU_READ_LOCK();
    mr = TRANSLATE(addr, &addr1, &l, false);
    if (l < 2 || !IS_DIRECT(mr, false)) {
        release_lock |= prepare_mmio_access(mr);

        /* I/O case */
        r = memory_region_dispatch_read(mr, addr1, &val, 2, attrs);
#if defined(TARGET_WORDS_BIGENDIAN)
        if (endian == DEVICE_LITTLE_ENDIAN) {
            val = bswap16(val);
        }
#else
        if (endian == DEVICE_BIG_ENDIAN) {
            val = bswap16(val);
        }
#endif
    } else {
        /* RAM case */
        ptr = MAP_RAM(mr, addr1);
        switch (endian) {
        case DEVICE_LITTLE_ENDIAN:
            val = lduw_le_p(ptr);
            break;
        case DEVICE_BIG_ENDIAN:
            val = lduw_be_p(ptr);
            break;
        default:
            val = lduw_p(ptr);
            break;
        }
        r = MEMTX_OK;
    }
    if (result) {
        *result = r;
    }
    if (release_lock) {
        qemu_mutex_unlock_iothread();
    }
    RCU_READ_UNLOCK();
    return val;
}
Example #11
0
void
MsgTalk :: swap(uint8_t* aBuf) const
{
    ASSERT(aBuf != nullptr);

    MsgInfo* info = (MsgInfo*)aBuf;

    info->Color = bswap32(info->Color);
    info->Channel = bswap16(info->Channel);
    info->Style = bswap16(info->Style);
    info->Timestamp = bswap32(info->Timestamp);
}
Example #12
0
///////////////////////////////
//tcp second packet
////////////////////////////////
int make_tcp_pkt2(u16 seqnum, u32 rnd, char *pkt, int *pkt_len) {
	int len;
	u32	iv;

	u8 result[0x1000];
	int result_len;

	//42394 - 0xA59A my iport
	skype_thing	mythings[] = {
		{0, 0x01, 0x00000003, 0},
		{1, 0x0D, 0xD6BA8CD9, 0x9205E2CD},
		{0, 0x10, 0xA59A, 0},
	};
	int mythings_len=3;

	u8 send_probe_pkt[]="\x30\xFF\xFF\x13\xF2\x01\xFF\xFF\x42\x44\x40\xFA\x3B\x4C\xE4\xAF\x94\xD9\x8C\xBA\xD6\xCD\xE2\x05\x92";
	len=sizeof(send_probe_pkt)-1;


	//main_unpack(send_probe_pkt,len);
	result_len=main_pack(mythings, mythings_len, result, sizeof(result)-1 );
	//show_memory(result,nlen,"packed42:");
	//main_unpack(result,nlen);

	memcpy(send_probe_pkt+8,result,result_len);

	show_memory(send_probe_pkt,len,"send pkt2:");


	seqnum=bswap16(seqnum);
	memcpy(send_probe_pkt+1,(char *)&seqnum,2);
	seqnum=bswap16(seqnum);

	seqnum=bswap16(seqnum-1);
	memcpy(send_probe_pkt+6,(char *)&seqnum,2);
	seqnum=bswap16(seqnum-1);

	iv = rnd;

	Skype_RC4_Expand_IV (&rc4, iv, 1);
	
	RC4_crypt (send_probe_pkt, len, &rc4, 0);


	memcpy(pkt,send_probe_pkt,len);
	
	*pkt_len=len;


	return 0;
};
Example #13
0
	virtual void incomingData(Dashel::Stream *stream)
	{
		uint16 temp;
		uint16 len;
		
		stream->read(&temp, 2);
		len = bswap16(temp);
		stream->read(&temp, 2);
		lastMessageSource = bswap16(temp);
		lastMessageData.resize(len+2);
		stream->read(&lastMessageData[0], lastMessageData.size());
		
		AsebaProcessIncomingEvents(&vm);
	}
Example #14
0
void DualshockPad::receivedHIDReport(const uint8_t* data, size_t length, HIDReportType tp, uint32_t message) {
  if (message != 1 || length != 49 || tp != HIDReportType::Input)
    return;
  DualshockPadState state = *reinterpret_cast<const DualshockPadState*>(data);

  for (int i = 0; i < 3; i++)
    state.m_accelerometer[i] = bswap16(state.m_accelerometer[i]);

  state.m_gyrometerZ = bswap16(state.m_gyrometerZ);
  const double zeroG = 511.5; // 1.65/3.3*1023 (1,65V);
  float accXval = -((double)state.m_accelerometer[0] - zeroG);
  float accYval = -((double)state.m_accelerometer[1] - zeroG);
  float accZval = -((double)state.m_accelerometer[2] - zeroG);
  state.accPitch = (atan2(accYval, accZval) + M_PIF) * RAD_TO_DEG;
  state.accYaw = (atan2(accXval, accZval) + M_PIF) * RAD_TO_DEG;
  state.gyroZ = (state.m_gyrometerZ / 1023.f);

  {
    std::lock_guard<std::mutex> lk(m_callbackLock);
    if (m_callback)
      m_callback->controllerUpdate(*this, state);
  }

  if (m_rumbleRequest != m_rumbleState) {
    if (True(m_rumbleRequest & EDualshockMotor::Left)) {
      m_report.rumble.leftDuration = m_rumbleDuration[0];
      m_report.rumble.leftForce = m_rumbleIntensity[0];
    } else {
      m_report.rumble.leftDuration = 0;
      m_report.rumble.leftForce = 0;
    }

    if (True(m_rumbleRequest & EDualshockMotor::Right)) {
      m_report.rumble.rightDuration = m_rumbleDuration[1];
      m_report.rumble.rightOn = m_rumbleIntensity[1] > 0;
    } else {
      m_report.rumble.rightDuration = 0;
      m_report.rumble.rightOn = false;
    }
    sendHIDReport(m_report.buf, sizeof(m_report), HIDReportType::Output, 0x01);
    m_rumbleState = m_rumbleRequest;
  } else {
    if (state.m_reserved5[8] & 0x80)
      m_rumbleRequest &= ~EDualshockMotor::Right;
    if (state.m_reserved5[7] & 0x01)
      m_rumbleRequest &= ~EDualshockMotor::Left;
    m_rumbleState = m_rumbleRequest;
  }
}
Example #15
0
///////////////////////////////
//tcp third packet
////////////////////////////////
int make_tcp_pkt3(u16 seqnum, u32 rnd, char *pkt, int *pkt_len) {
	int len;
	u8 result[0x1000];
	int result_len;

	skype_thing	mythings[] = {
		{0, 0x04, 0x10, 0},
		{0, 0x05, 0x06, 0},
	};
	int mythings_len=2;

	//u8 send_probe_pkt[]="\x16\xFF\xFF\x06\x82\x03\xFF\xFF\x42\x33\x48\x93";
	u8 send_probe_pkt[]="\x14\xFF\xFF\x06\x32\xFF\xFF\x42\x85\x14\xC9";
	len=sizeof(send_probe_pkt)-1;


	//main_unpack(send_probe_pkt,len);
	result_len=main_pack(mythings, mythings_len, result, sizeof(result)-1 );
	//show_memory(result,result_len,"packed42:");
	//main_unpack(result,result_len);

	memcpy(send_probe_pkt+7,result,result_len);
	show_memory(send_probe_pkt,len,"send pkt3:");


	//seq
	seqnum=bswap16(seqnum);
	memcpy(send_probe_pkt+1,(char *)&seqnum,2);
	seqnum=bswap16(seqnum);

	seqnum--;
	seqnum=bswap16(seqnum);
	memcpy(send_probe_pkt+5,(char *)&seqnum,2);
	seqnum=bswap16(seqnum);


	len=0;
	memcpy(pkt+len,send_probe_pkt,sizeof(send_probe_pkt)-1);
	len+=sizeof(send_probe_pkt)-1;

	
	RC4_crypt (pkt, len, &rc4, 0);

	*pkt_len=len;


	return 0;
};
struct atsc_eit_section *atsc_eit_section_codec(struct atsc_section_psip *psip)
{
	uint8_t * buf = (uint8_t *) psip;
	size_t pos = 0;
	size_t len = section_ext_length(&(psip->ext_head));
	int idx;

	if (len < sizeof(struct atsc_eit_section))
		return NULL;
	struct atsc_eit_section *eit = (struct atsc_eit_section *) psip;

	pos += sizeof(struct atsc_eit_section);
	for(idx =0; idx < eit->num_events_in_section; idx++) {
		if (len < (pos + sizeof(struct atsc_eit_event)))
			return NULL;
		struct atsc_eit_event *event = (struct atsc_eit_event *) (buf+pos);

		bswap16(buf+pos);
		bswap32(buf+pos+2);
		bswap32(buf+pos+6);

		pos += sizeof(struct atsc_eit_event);
		if (len < (pos + event->title_length))
			return NULL;
		if (atsc_text_validate(buf+pos, event->title_length))
			return NULL;

		pos += event->title_length;
		if (len < (pos + sizeof(struct atsc_eit_event_part2)))
			return NULL;
		struct atsc_eit_event_part2 *part2 = (struct atsc_eit_event_part2 *) (buf+pos);

		bswap16(buf+pos);

		pos += sizeof(struct atsc_eit_event_part2);
		if (len < (pos + part2->descriptors_length))
			return NULL;

		if (verify_descriptors(buf + pos, part2->descriptors_length))
			return NULL;
		pos += part2->descriptors_length;
	}

	if (pos != len)
		return NULL;

	return (struct atsc_eit_section *) psip;
}
Example #17
0
/*
 * Switch memory window position. Return PCI mem address seen at the beginning
 * of window.
 */
bus_addr_t
empb_switch_window(struct empb_softc *sc, bus_addr_t address) 
{
	int s;
	uint16_t win_reg;
#ifdef EMPB_DEBUG
	uint16_t rwin_reg;
#endif /* EMPB_DEBUG */

	WINDOW_LOCK(s);

	win_reg = bswap16((address >> EMPB_WINDOW_SHIFT) 
	    & sc->pci_mem_win_mask);

	bus_space_write_2(sc->setup_area_t, sc->setup_area_h,
	    EMPB_SETUP_WINDOW_OFF, win_reg);

	/* store window pos, like: sc->pci_mem_win_pos = win_reg ? */

#ifdef EMPB_DEBUG
	rwin_reg = bus_space_read_2(sc->setup_area_t, sc->setup_area_h,
	    EMPB_SETUP_WINDOW_OFF);

	aprint_normal("empb: access to %p window switch to %x => reg now %x\n",
	    (void*) address, win_reg, rwin_reg);
#endif /* EMPB_DEBUG */

	WINDOW_UNLOCK(s);	

	return (bus_addr_t)((bswap16(win_reg)) << EMPB_WINDOW_SHIFT);
}
Example #18
0
static long ReadDirEntry(InodePtr dirInode, long *fileInodeNum,
			 long *dirIndex, char **name)
{
  struct ext2fs_direct *dir;
  char                 *buffer;
  long                 offset, index;
  long                 blockNum, inodeNum;
  
  while (1) {
    index = *dirIndex;
    
    offset = index % gBlockSize;
    blockNum = index / gBlockSize;
    
    buffer = ReadFileBlock(dirInode, blockNum, 0, gBlockSize, 0, 1);
    if (buffer == 0) return -1;
    
    dir = (struct ext2fs_direct *)(buffer + offset);
    *dirIndex += bswap16(dir->e2d_reclen);
    
    inodeNum = bswap32(dir->e2d_ino);
    if (inodeNum != 0) break;
    
    if (offset != 0) return -1;
  }
  
  *fileInodeNum = inodeNum;
  *name = strncpy(gTempName2, dir->e2d_name, dir->e2d_namlen);
  
  return 0;
}
Example #19
0
void ledma_memory_write(void *opaque, hwaddr addr,
                        uint8_t *buf, int len, int do_bswap)
{
    DMAState *s = opaque;
    int l, i;
    uint16_t tmp_buf[32];

    addr |= s->dmaregs[3];
    trace_ledma_memory_write(addr);
    if (do_bswap) {
        sparc_iommu_memory_write(s->iommu, addr, buf, len);
    } else {
        addr &= ~1;
        len &= ~1;
        while (len > 0) {
            l = len;
            if (l > sizeof(tmp_buf))
                l = sizeof(tmp_buf);
            for(i = 0; i < l; i += 2) {
                tmp_buf[i >> 1] = bswap16(*(uint16_t *)(buf + i));
            }
            sparc_iommu_memory_write(s->iommu, addr, (uint8_t *)tmp_buf, l);
            len -= l;
            buf += l;
            addr += l;
        }
    }
}
Example #20
0
//
// Process aes
//
int process_aes(char *globalptr, char *buf, int buf_len, int usekey, int blkseq, int need_xor){	
	u32 aes_checksum_crc32;
	u32 pkt_crc32;

	struct global_s *global;
	global=(struct global_s *)globalptr;

	// Re-calculate 41 checksum(crc32)
	aes_checksum_crc32=Calculate_CRC32_For41(buf,buf_len);
	if(DEBUG_LEVEL>=100) printf("aes_checksum_crc32=0x%08X\n",aes_checksum_crc32);
	aes_checksum_crc32=bswap16(aes_checksum_crc32);	
	memcpy(buf+buf_len,&aes_checksum_crc32,2);
	buf_len+=2;

	
	//aes encrypt block 3
	//blkseq=0x06;	
	process_aes_crypt(globalptr, buf, buf_len, usekey, blkseq, need_xor);

	//crc32 after aes encrypt
	pkt_crc32=Calculate_CRC32( (char *)buf,buf_len);
	pkt_crc32=pkt_crc32 & 0xffff;
	pkt_crc32=pkt_crc32 ^ blkseq;
	if(DEBUG_LEVEL>=100) printf("crc32(after aes crypt)=%08X\n",pkt_crc32);
	memcpy(buf+buf_len, &pkt_crc32, 2);
	buf_len+=2;

	return buf_len;

};
Example #21
0
int main ()
{
    printf ("        bswap16 (0x1234)             -> %#x \n",   bswap16 (0x1234));
    printf ("        bswap32 (0x12345678)         -> %#x \n",   bswap32 (0x12345678));
    printf ("        bswap64 (0x1234567890abcdef) -> %#llx \n", bswap64 (0x1234567890abcdefLL));
    return 0;
}
Example #22
0
ssize_t dvb_mpeg_ts_init(struct dvb_v5_fe_parms *parms, const uint8_t *buf, ssize_t buflen, uint8_t *table, ssize_t *table_length)
{
	struct dvb_mpeg_ts *ts = (struct dvb_mpeg_ts *) table;
	const uint8_t *p = buf;

	if (buf[0] != DVB_MPEG_TS) {
		dvb_logerr("mpeg ts invalid marker 0x%02x, sould be 0x%02x", buf[0], DVB_MPEG_TS);
		*table_length = 0;
		return -1;
	}

	memcpy(table, p, sizeof(struct dvb_mpeg_ts));
	p += sizeof(struct dvb_mpeg_ts);

	bswap16(ts->bitfield);

	if (ts->adaptation_field) {
		memcpy(ts->adaption, p, sizeof(struct dvb_mpeg_ts_adaption));
		p += ts->adaption->length + 1;
		/* FIXME: copy adaption->lenght bytes */
	}

	*table_length = p - buf;
	return p - buf;
}
Example #23
0
Psmf::Psmf(u32 data) {
	headerOffset = data;
	magic = Memory::Read_U32(data);
	version = Memory::Read_U32(data + 4);
	streamOffset = bswap32(Memory::Read_U32(data + 8));
	streamSize = bswap32(Memory::Read_U32(data + 12));
	streamDataTotalSize = bswap32(Memory::Read_U32(data + 0x50));
	presentationStartTime = getMpegTimeStamp(Memory::GetPointer(data + PSMF_FIRST_TIMESTAMP_OFFSET));
	presentationEndTime = getMpegTimeStamp(Memory::GetPointer(data + PSMF_LAST_TIMESTAMP_OFFSET));
	streamDataNextBlockSize = bswap32(Memory::Read_U32(data + 0x6A));
	streamDataNextInnerBlockSize = bswap32(Memory::Read_U32(data + 0x7C));
	numStreams = bswap16(Memory::Read_U16(data + 0x80));

	currentStreamNum = -1;
	currentAudioStreamNum = -1;
	currentVideoStreamNum = -1;

	for (int i = 0; i < numStreams; i++) {
		PsmfStream *stream = 0;
		u32 currentStreamAddr = data + 0x82 + i * 16;
		int streamId = Memory::Read_U8(currentStreamAddr);
		if ((streamId & PSMF_VIDEO_STREAM_ID) == PSMF_VIDEO_STREAM_ID) {
			stream = new PsmfStream(PSMF_AVC_STREAM, ++currentVideoStreamNum);
			stream->readMPEGVideoStreamParams(currentStreamAddr, this);
		} else if ((streamId & PSMF_AUDIO_STREAM_ID) == PSMF_AUDIO_STREAM_ID) {
			stream = new PsmfStream(PSMF_ATRAC_STREAM, ++currentAudioStreamNum);
			stream->readPrivateAudioStreamParams(currentStreamAddr, this);
		}
		if (stream) {
			currentStreamNum++;
			streamMap[currentStreamNum] = stream;
		}
	}
}
Example #24
0
static void test_bswap(void *p)
{
	int_check(bswap16(0xff01), 0x01ff);
	int_check(bswap32(0x01020304), 0x04030201);
	int_check(bswap64(0x0102030405060708ULL), 0x0807060504030201ULL);
end:;
}
Example #25
0
void ledma_memory_write(void *opaque, target_phys_addr_t addr, 
                        uint8_t *buf, int len, int do_bswap)
{
    DMAState *s = opaque;
    int l, i;
    uint16_t tmp_buf[32];

    DPRINTF("DMA read, direction: %c, addr 0x%8.8x\n",
            s->dmaregs[0] & DMA_WRITE_MEM ? 'w': 'r', s->dmaregs[1]);
    addr |= s->dmaregs[7];
    if (do_bswap) {
        sparc_iommu_memory_write(s->iommu, addr, buf, len);
    } else {
        addr &= ~1;
        len &= ~1;
        while (len > 0) {
            l = len;
            if (l > sizeof(tmp_buf))
                l = sizeof(tmp_buf);
            for(i = 0; i < l; i += 2) {
                tmp_buf[i >> 1] = bswap16(*(uint16_t *)(buf + i));
            }
            sparc_iommu_memory_write(s->iommu, addr, (uint8_t *)tmp_buf, l);
            len -= l;
            buf += l;
            addr += l;
        }
    }
}
Example #26
0
void testNewSpecBin(void)
{
    char *error = NULL;

    union {
        uint16_t num;
        char bytes[2];
    } n16;

    n16.num = 5;
    n16.num = bswap16(n16.num);

    union {
        uint32_t num;
        char bytes[4];
    } n32;

    n32.num = 5;
    n32.num = bswap32(n32.num);

    char buf[] = {'\x93', /* 10010011 */
        '\xc4', (uint8_t)5, 'H', 'e', 'l', 'l', 'o',
        '\xc5', n16.bytes[0], n16.bytes[1], 'H', 'e', 'l', 'l', 'o',
        '\xc6', n32.bytes[0], n32.bytes[1], n32.bytes[2], n32.bytes[3],
                                                    'H', 'e', 'l', 'l', 'o',
    };
    size_t n = sizeof(buf);

    CU_ASSERT_EQUAL(msgpackclen_buf_read (buf, n, &error), n);
    CU_ASSERT_PTR_EQUAL(error, NULL);

    if (error)
        free(error);
}
Example #27
0
uint16_t
dkcksum_mmeye(struct disklabel *lp)
{
	struct disklabel tdl;
	int i, offset;
	uint16_t *start, *end, *fstype;
	uint16_t sum = 0;

	tdl = *lp;

	for (i = 0; i < MAXPARTITIONS; i++) {
		fstype = (uint16_t *)&tdl.d_partitions[i].p_fstype;
		*fstype = bswap16(*fstype);
	}

	offset = offsetof(struct disklabel,
	    d_partitions[le16toh(lp->d_npartitions)]);
	start = (uint16_t *)&tdl;
	end = start + offset;

	while (start < end)
		sum ^= *start++;

#ifdef COMPAT_MMEYE_OLDLABEL_BROKEN
	if (sum != 0 &&
	    tdl.d_checksum == 0) {
		printf("disklabel: mmeye oldlabel broken found\n");
		sum = 0;	/* XXXX */
	}
#endif

	return (sum);
}
Example #28
0
static uint32_t PPC_PCIIO_readw (void *opaque, target_phys_addr_t addr)
{
    PREPPCIState *s = opaque;
    uint32_t val;
    val = pci_data_read(s->bus, PPC_PCIIO_config(addr), 2);
    val = bswap16(val);
    return val;
}
static void PPC_PCIIO_writew (void *opaque, target_phys_addr_t addr, uint32_t val)
{
    PREPPCIState *s = opaque;
#ifdef TARGET_WORDS_BIGENDIAN
    val = bswap16(val);
#endif
    pci_data_write(s->bus, PPC_PCIIO_config(addr), val, 2);
}
Example #30
0
static void pci_vpb_config_writew (void *opaque, target_phys_addr_t addr,
                                   uint32_t val)
{
#ifdef TARGET_WORDS_BIGENDIAN
    val = bswap16(val);
#endif
    pci_data_write(opaque, vpb_pci_config_addr (addr), val, 2);
}