コード例 #1
0
int main(int argc, char *argv[]) {
    char msg[] = {0x21,0x11};
    char res[N_BYTE_SIZE];
    char strN[] = STR_N;
    char strE[] = STR_e;
    char strD[] = STR_d;

    int res_size;

    int strNLen = strlen(strN);
    int strELen = strlen(strE);
    int strDLen = strlen(strD);
    u32 i;

    //for (i=0; i<0xffffff; i++) {

        res_size = libperm_rsa_modPow((u8 *)msg, sizeof(msg), strE, strELen, strN, strNLen, res);
        dump_bytes(res, res_size);
        res_size = libperm_rsa_modPow(res, res_size, strD, strDLen, strN, strNLen, res);


        dump_bytes(res, res_size);

        if (memcmp((void *)msg, res, res_size) == 0) {
            printf("#successed.\n");
        } else {
            fprintf(stderr, "#failed, i: %d\n", i);
            printf("#failed, i: %d\n", i);
        }
    //}

    return 0;
}
コード例 #2
0
ファイル: util.c プロジェクト: KpuBopy4ka/obexd-map
void dump_bufs(const void *mem1, size_t len1, const void *mem2, size_t len2)
{
	g_printerr("\nExpected: ");
	dump_bytes(mem1, len1);
	g_printerr("Got:      ");
	dump_bytes(mem2, len2);
}
コード例 #3
0
ファイル: dmu_send.c プロジェクト: EDV-Lotse/zfs
static int
dump_spill(dmu_sendarg_t *dsp, uint64_t object, int blksz, void *data)
{
	struct drr_spill *drrs = &(dsp->dsa_drr->drr_u.drr_spill);

	if (dsp->dsa_pending_op != PENDING_NONE) {
		if (dump_bytes(dsp, dsp->dsa_drr,
		    sizeof (dmu_replay_record_t)) != 0)
			return (EINTR);
		dsp->dsa_pending_op = PENDING_NONE;
	}

	/* write a SPILL record */
	bzero(dsp->dsa_drr, sizeof (dmu_replay_record_t));
	dsp->dsa_drr->drr_type = DRR_SPILL;
	drrs->drr_object = object;
	drrs->drr_length = blksz;
	drrs->drr_toguid = dsp->dsa_toguid;

	if (dump_bytes(dsp, dsp->dsa_drr, sizeof (dmu_replay_record_t)))
		return (EINTR);
	if (dump_bytes(dsp, data, blksz))
		return (EINTR);
	return (0);
}
コード例 #4
0
ファイル: gstspu-pgs.c プロジェクト: drothlis/gst-plugins-bad
static int
parse_pgs_packet (GstDVDSpu * dvdspu, guint8 type, guint8 * payload,
    guint16 len)
{
  SpuPgsState *pgs_state = &dvdspu->spu_state.pgs;
  int ret = 0;

  if (!pgs_state->in_presentation_segment
      && type != PGS_COMMAND_PRESENTATION_SEGMENT) {
    PGS_DUMP ("Expected BEGIN PRESENTATION SEGMENT command. "
        "Got command type 0x%02x len %u. Skipping\n", type, len);
    return 0;
  }

  switch (type) {
    case PGS_COMMAND_PRESENTATION_SEGMENT:
      PGS_DUMP ("*******************************************\n"
          "Begin PRESENTATION_SEGMENT (0x%02x) packet len %u\n", type, len);
      pgs_state->in_presentation_segment =
          pgs_state->have_presentation_segment = TRUE;
      ret = parse_presentation_segment (dvdspu, type, payload, len);
      break;
    case PGS_COMMAND_SET_OBJECT_DATA:
      PGS_DUMP ("***   Set Object Data (0x%02x) packet len %u\n", type, len);
      ret = parse_set_object_data (dvdspu, type, payload, len);
      break;
    case PGS_COMMAND_SET_PALETTE:
      PGS_DUMP ("***   Set Palette (0x%02x) packet len %u\n", type, len);
      ret = parse_set_palette (dvdspu, type, payload, len);
      break;
    case PGS_COMMAND_SET_WINDOW:
      PGS_DUMP ("***   Set Window command (0x%02x) packet len %u\n", type, len);
      ret = parse_set_window (dvdspu, type, payload, len);
      break;
    case PGS_COMMAND_INTERACTIVE_SEGMENT:
      PGS_DUMP ("***   Interactive Segment command(0x%02x) packet len %u\n",
          type, len);
      dump_bytes (payload, len);
      break;
    case PGS_COMMAND_END_DISPLAY:
      PGS_DUMP ("***   End Display command (0x%02x) packet len %u\n", type,
          len);
      pgs_state->in_presentation_segment = FALSE;
      break;
    default:
      GST_ERROR ("Unknown PGS command: type 0x%02x len %u", type, len);
      dump_bytes (payload, len);
      break;
  }
  PGS_DUMP ("\n");

  return ret;
}
コード例 #5
0
/*
 * For HID class drivers, 4 reports are used to implement
 * Serial Download protocol(SDP)
 * Report 1 (control out endpoint) 16 byte SDP comand
 *  (total of 17 bytes with 1st byte report id of 0x01
 * Report 2 (control out endpoint) data associated with report 1 commands
 *  (max size of 1025 with 1st byte of 0x02)
 * Report 3 (interrupt in endpoint) HAB security state
 *  (max size of 5 bytes with 1st byte of 0x03)
 *  (0x12343412 production)
 *  (0x56787856 engineering)
 * Report 4 (interrupt in endpoint) date associated with report 1 commands
 *  (max size of 65 bytes with 1st byte of 0x04)
 *
 */
int transfer_hid(struct sdp_dev *dev, int report, unsigned char *p, unsigned int cnt,
		unsigned int expected, int* last_trans)
{
	int err;
	struct libusb_device_handle *h = (struct libusb_device_handle *)dev->priv;
	if (cnt > dev->max_transfer)
		cnt = dev->max_transfer;
#ifdef DEBUG
	printf("report=%i\n", report);
	if (report < 3)
		dump_bytes(p, cnt, 0);
#endif
	unsigned char tmp[1028];
	tmp[0] = (unsigned char)report;
	if (report < 3) {
		memcpy(&tmp[1], p, cnt);
		if (report == 2)
			cnt = dev->max_transfer;
		err = libusb_control_transfer(h,
				CTRL_OUT,
				HID_SET_REPORT,
				(HID_REPORT_TYPE_OUTPUT << 8) | report,
				0,
				tmp, cnt + 1, 1000);
		*last_trans = (err > 0) ? err - 1 : 0;
		if (err > 0)
			err = 0;
	} else {
		*last_trans = 0;
		memset(&tmp[1], 0, cnt);
		err = libusb_interrupt_transfer(h, 1 + EP_IN, tmp, cnt + 1, last_trans, 1000);
		dbg_printf("libusb_interrupt_transfer, err=%d, trans=%d\n", err,
				*last_trans);
		if (err >= 0) {
			if (tmp[0] == (unsigned char)report)
				if (*last_trans > 1) {
					*last_trans -= 1;
					memcpy(p, &tmp[1], *last_trans);
				}
			else {
				printf("Unexpected report %i err=%i, cnt=%i, last_trans=%i, %02x %02x %02x %02x\n",
					tmp[0], err, cnt, *last_trans, tmp[0], tmp[1], tmp[2], tmp[3]);
				err = 0;
			}
		}
	}
#ifdef DEBUG
	if (report >= 3)
		dump_bytes(p, cnt, 0);
#endif
	return err;
}
コード例 #6
0
ファイル: radius.c プロジェクト: isomer/radius
static void decode_eap(uint8_t *payload, uint32_t remaining)
{
    printf("EAP:\n");
    if (remaining < sizeof(eap_header_t)) {
        printf(" Truncated header\n");
        return;
    }
    eap_header_t *header = payload;
    payload += sizeof(*header);
    remaining -= sizeof(*header);
    switch(header->code) {
        case 1: /* Request */
        case 2: /* Response */
            printf(" Code: %s\n", header->code == 1 ? "Request" : "Response");
            switch (payload[0]) {
                case 1: printf(" Type: Identity\n");
                        printf(" Message: ");
                        dump_bytes(&payload[1], remaining-1);
                        printf("\n");
                        break;

                case 2:
                        printf(" Type: Notification\n");
                        printf(" Message: ");
                        dump_bytes(&payload[1], remaining-1);
                        printf("\n");
                        break;
                case 3:
                        printf(" Type: Nak\n");
                        printf(" Required type: %d\n", payload[1]);
                        break;
                case 4: printf(" Type: MD5-Challenge\n"); break;
                case 5: printf(" Type: One Time Password\n"); break;
                case 6:  printf(" Type: Generic Token Card\n"); break;
                case 25: printf(" Type: PEAP\n"); break;
                default:
                        printf(" Type: #%d\n", payload[0]);
                        break;
            }
            break;
        case 3: /* Success */
        case 4: /* Failure */
            printf(" Code: %s\n", header->code == 3 ? "Success" : "Failure");
            break;
        default:
            printf(" Code: #%d\n", header->code);
            break;
    }
}
コード例 #7
0
/*
 * For Bulk class drivers, the device is configured as
 * EP0IN, EP0OUT control transfer
 * EP1OUT - bulk out
 * (max packet size of 512 bytes)
 * EP2IN - bulk in
 * (max packet size of 512 bytes)
 */
int transfer(struct libusb_device_handle *h, int report, unsigned char *p, unsigned cnt, int* last_trans, struct usb_id *p_id)
{
	int err;
	if (cnt > p_id->max_transfer)
		cnt = p_id->max_transfer;
#ifdef DEBUG
	printf("report=%i\n", report);
	if (report < 3)
		dump_bytes(p, cnt, 0);
#endif
	if (p_id->mode == MODE_BULK) {
		*last_trans = 0;
		err = libusb_bulk_transfer(h, (report < 3) ? 1 : 2 + EP_IN, p, cnt, last_trans, 1000);
	} else {
		unsigned char tmp[1028];
		tmp[0] = (unsigned char)report;
		if (report < 3) {
			memcpy(&tmp[1], p, cnt);
			err = libusb_control_transfer(h,
					CTRL_OUT,
					HID_SET_REPORT,
					(HID_REPORT_TYPE_OUTPUT << 8) | report,
					0,
					tmp, cnt + 1, 1000);
			*last_trans = (err > 0) ? err - 1 : 0;
			if (err > 0)
				err = 0;
		} else {
			*last_trans = 0;
			memset(&tmp[1], 0, cnt);
			err = libusb_interrupt_transfer(h, 1 + EP_IN, tmp, cnt + 1, last_trans, 1000);
			if (err >= 0) {
				if (tmp[0] == (unsigned char)report)
					if (*last_trans > 1)
						memcpy(p, &tmp[1], *last_trans - 1);
				else {
					printf("Unexpected report %i err=%i, cnt=%i, last_trans=%i, %02x %02x %02x %02x\n",
						tmp[0], err, cnt, *last_trans, tmp[0], tmp[1], tmp[2], tmp[3]);
					err = 0;
				}
			}
		}
	}
#ifdef DEBUG
	if (report >= 3)
		dump_bytes(p, cnt, 0);
#endif
	return err;
}
コード例 #8
0
ファイル: main.c プロジェクト: cyrozap/misoc
static void mr(char *startaddr, char *len)
{
	char *c;
	unsigned int *addr;
	unsigned int length;

	if(*startaddr == 0) {
		printf("mr <address> [length]\n");
		return;
	}
	addr = (unsigned *)strtoul(startaddr, &c, 0);
	if(*c != 0) {
		printf("incorrect address\n");
		return;
	}
	if(*len == 0) {
		length = 4;
	} else {
		length = strtoul(len, &c, 0);
		if(*c != 0) {
			printf("incorrect length\n");
			return;
		}
	}

	dump_bytes(addr, length, (unsigned)addr);
}
コード例 #9
0
ファイル: gstspu-pgs.c プロジェクト: drothlis/gst-plugins-bad
static int
parse_set_palette (GstDVDSpu * dvdspu, guint8 type, guint8 * payload,
    guint16 len)
{
  SpuState *state = &dvdspu->spu_state;

  const gint PGS_PALETTE_ENTRY_SIZE = 5;
  guint8 *end = payload + len;
  guint8 palette_id G_GNUC_UNUSED;
  guint8 palette_version G_GNUC_UNUSED;
  gint n_entries, i;

  if (len < 2)                  /* Palette command too short */
    return 0;
  palette_id = payload[0];
  palette_version = payload[1];
  payload += 2;

  n_entries = (len - 2) / PGS_PALETTE_ENTRY_SIZE;

  PGS_DUMP ("Palette ID %u version %u. %d entries\n",
      palette_id, palette_version, n_entries);
  for (i = 0; i < 256; i++)
    state->pgs.palette[i].A = 0;
  for (i = 0; i < n_entries; i++) {
    guint8 n, Y, U, V, A;
    n = payload[0];
    Y = payload[1];
    U = payload[2];
    V = payload[3];
    A = payload[4];

#if DUMP_FULL_PALETTE
    PGS_DUMP ("Entry %3d: Y %3d U %3d V %3d A %3d  ", n, Y, U, V, A);
    if (((i + 1) % 2) == 0)
      PGS_DUMP ("\n");
#endif

    /* Premultiply the palette entries by the alpha */
    state->pgs.palette[n].Y = Y * A;
    state->pgs.palette[n].U = U * A;
    state->pgs.palette[n].V = V * A;
    state->pgs.palette[n].A = A;

    payload += PGS_PALETTE_ENTRY_SIZE;
  }

#if DUMP_FULL_PALETTE
  if (n_entries > 0 && (i % 2))
    PGS_DUMP ("\n");
#endif

  if (payload != end) {
    GST_ERROR ("PGS Set Palette: %" G_GSSIZE_FORMAT " bytes not consumed",
        (gssize) (end - payload));
    dump_bytes (payload, end - payload);
  }

  return 0;
}
コード例 #10
0
ファイル: scsi-uscsi.c プロジェクト: DjCBS3/mate-disc-burner
void
dump_cdb(guchar *cdb, gint cdblen)
{
	gchar *out = dump_bytes(cdb, cdblen);
	DEBUG("CDB:\t%s", out);
	g_free(out);
}
コード例 #11
0
ファイル: libusb-sniff.c プロジェクト: Andrer757/0xFFFF
int usb_bulk_read(usb_dev_handle * dev, int ep, char * bytes, int size, int timeout) {

	static int (*real_usb_bulk_read)(usb_dev_handle * dev, int ep, char * bytes, int size, int timeout) = NULL;
	int ret;

	if ( ! real_usb_bulk_read )
		real_usb_bulk_read = dlsym(RTLD_NEXT, "usb_bulk_read");

	ret = real_usb_bulk_read(dev, ep, bytes, size, timeout);

	if ( ! getenv("USBSNIFF_SKIP_READ") ) {

		printf("\n==== usb_bulk_read (ep=%d size=%d timeout=%d) ret = %d ====\n", ep, size, timeout, ret);
		if ( ret > 0 ) {
			dump_bytes(bytes, ret);
			printf("====\n");
		}

		if ( getenv("USBSNIFF_WAIT") ) {
			printf("Press ENTER"); fflush(stdout); getchar();
		}

	}

	return ret;

}
コード例 #12
0
ファイル: dmu_send.c プロジェクト: EDV-Lotse/zfs
static int
dump_freeobjects(dmu_sendarg_t *dsp, uint64_t firstobj, uint64_t numobjs)
{
	struct drr_freeobjects *drrfo = &(dsp->dsa_drr->drr_u.drr_freeobjects);

	/*
	 * If there is a pending op, but it's not PENDING_FREEOBJECTS,
	 * push it out, since free block aggregation can only be done for
	 * blocks of the same type (i.e., DRR_FREE records can only be
	 * aggregated with other DRR_FREE records.  DRR_FREEOBJECTS records
	 * can only be aggregated with other DRR_FREEOBJECTS records.
	 */
	if (dsp->dsa_pending_op != PENDING_NONE &&
	    dsp->dsa_pending_op != PENDING_FREEOBJECTS) {
		if (dump_bytes(dsp, dsp->dsa_drr,
		    sizeof (dmu_replay_record_t)) != 0)
			return (EINTR);
		dsp->dsa_pending_op = PENDING_NONE;
	}
	if (dsp->dsa_pending_op == PENDING_FREEOBJECTS) {
		/*
		 * See whether this free object array can be aggregated
		 * with pending one
		 */
		if (drrfo->drr_firstobj + drrfo->drr_numobjs == firstobj) {
			drrfo->drr_numobjs += numobjs;
			return (0);
		} else {
			/* can't be aggregated.  Push out pending record */
			if (dump_bytes(dsp, dsp->dsa_drr,
			    sizeof (dmu_replay_record_t)) != 0)
				return (EINTR);
			dsp->dsa_pending_op = PENDING_NONE;
		}
	}

	/* write a FREEOBJECTS record */
	bzero(dsp->dsa_drr, sizeof (dmu_replay_record_t));
	dsp->dsa_drr->drr_type = DRR_FREEOBJECTS;
	drrfo->drr_firstobj = firstobj;
	drrfo->drr_numobjs = numobjs;
	drrfo->drr_toguid = dsp->dsa_toguid;

	dsp->dsa_pending_op = PENDING_FREEOBJECTS;

	return (0);
}
コード例 #13
0
ファイル: http.c プロジェクト: aNeutrino/lanmap2
static size_t dump_data(const parse_frame *f, int opt, FILE *out, const http *h)
{
  int bytes = fprintf(out, "bytes=%u\n", (unsigned)f->len);
  bytes += dump_bytes(f->off, f->len, out);
  fputc('\n', out);
  bytes++;
  return (size_t)bytes;
}
コード例 #14
0
ファイル: ar.c プロジェクト: meesokim/z88dk
void dump_code( FILE *fp, char *filename, long fp_start )
{
    int code_size;
    int org;
    char *section_name;

    fseek( fp, fp_start, SEEK_SET );

    if ( file_version >= 5 )
    {
        while (1)
        {
            code_size = xfread_long( fp, filename );
            if ( code_size < 0 )
                break;
            section_name = xfread_string( fp, filename );

            if ( file_version >= 8 )
                org = (int) xfread_long( fp, filename );
            else
                org = -1;

            printf("  Code: %d bytes", code_size );
            if ( org >= 0 )
                printf(", ORG at $%04X", org );
            print_section_name( section_name );
            printf("\n");

            dump_bytes( fp, filename, code_size );
        }
    }
    else
    {
        code_size = xfread_word( fp, filename );
        if ( code_size == 0 )
            code_size = 0x10000;
        if ( code_size > 0 )
        {
            printf("  Code: %d bytes\n", code_size );
            dump_bytes( fp, filename, code_size );
        }
    }
}
コード例 #15
0
ファイル: dce-rpc.c プロジェクト: wflk/lanmap2
static size_t dump_resp(const void *buf, size_t len, FILE *out)
{
    const dcerpc_resp *r = buf;
    size_t bytes = dump_flags(&r->flags, out);
    bytes += fprintf(out,
                     " fraglen=%hu authlen=%hu callid=%lu alloc_hint=%lu context=0x%04hx op=%hu\n",
                     r->fraglen, r->authlen, (unsigned long)r->callid, (unsigned long)r->alloc_hint, r->contextid, r->opnum);
    bytes += dump_bytes((char *)r->data, len - sizeof *r + 1, out);
    return bytes;
}
コード例 #16
0
ファイル: gstspu-pgs.c プロジェクト: drothlis/gst-plugins-bad
static int
parse_set_window (GstDVDSpu * dvdspu, guint8 type, guint8 * payload,
    guint16 len)
{
  SpuState *state = &dvdspu->spu_state;
  guint8 *end = payload + len;
  guint8 win_count, win_id G_GNUC_UNUSED;
  gint i;

  if (payload + 1 > end)
    return 0;

  dump_bytes (payload, len);

  win_count = payload[0];
  payload++;

  for (i = 0; i < win_count; i++) {
    if (payload + 9 > end)
      return 0;

    /* FIXME: Store each window ID separately into an array */
    win_id = payload[0];
    state->pgs.win_x = GST_READ_UINT16_BE (payload + 1);
    state->pgs.win_y = GST_READ_UINT16_BE (payload + 3);
    state->pgs.win_w = GST_READ_UINT16_BE (payload + 5);
    state->pgs.win_h = GST_READ_UINT16_BE (payload + 7);
    payload += 9;

    PGS_DUMP ("Win ID %u x %d y %d w %d h %d\n",
        win_id, state->pgs.win_x, state->pgs.win_y, state->pgs.win_w,
        state->pgs.win_h);
  }

  if (payload != end) {
    GST_ERROR ("PGS Set Window: %" G_GSSIZE_FORMAT " bytes not consumed",
        (gssize) (end - payload));
    dump_bytes (payload, end - payload);
  }

  return 0;
}
コード例 #17
0
ファイル: dmu_send.c プロジェクト: EDV-Lotse/zfs
static int
dump_dnode(dmu_sendarg_t *dsp, uint64_t object, dnode_phys_t *dnp)
{
	struct drr_object *drro = &(dsp->dsa_drr->drr_u.drr_object);

	if (dnp == NULL || dnp->dn_type == DMU_OT_NONE)
		return (dump_freeobjects(dsp, object, 1));

	if (dsp->dsa_pending_op != PENDING_NONE) {
		if (dump_bytes(dsp, dsp->dsa_drr,
		    sizeof (dmu_replay_record_t)) != 0)
			return (EINTR);
		dsp->dsa_pending_op = PENDING_NONE;
	}

	/* write an OBJECT record */
	bzero(dsp->dsa_drr, sizeof (dmu_replay_record_t));
	dsp->dsa_drr->drr_type = DRR_OBJECT;
	drro->drr_object = object;
	drro->drr_type = dnp->dn_type;
	drro->drr_bonustype = dnp->dn_bonustype;
	drro->drr_blksz = dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT;
	drro->drr_bonuslen = dnp->dn_bonuslen;
	drro->drr_checksumtype = dnp->dn_checksum;
	drro->drr_compress = dnp->dn_compress;
	drro->drr_toguid = dsp->dsa_toguid;

	if (dump_bytes(dsp, dsp->dsa_drr, sizeof (dmu_replay_record_t)) != 0)
		return (EINTR);

	if (dump_bytes(dsp, DN_BONUS(dnp), P2ROUNDUP(dnp->dn_bonuslen, 8)) != 0)
		return (EINTR);

	/* free anything past the end of the file */
	if (dump_free(dsp, object, (dnp->dn_maxblkid + 1) *
	    (dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT), -1ULL))
		return (EINTR);
	if (dsp->dsa_err)
		return (EINTR);
	return (0);
}
コード例 #18
0
ファイル: dmu_send.c プロジェクト: EDV-Lotse/zfs
static int
dump_data(dmu_sendarg_t *dsp, dmu_object_type_t type,
    uint64_t object, uint64_t offset, int blksz, const blkptr_t *bp, void *data)
{
	struct drr_write *drrw = &(dsp->dsa_drr->drr_u.drr_write);


	/*
	 * If there is any kind of pending aggregation (currently either
	 * a grouping of free objects or free blocks), push it out to
	 * the stream, since aggregation can't be done across operations
	 * of different types.
	 */
	if (dsp->dsa_pending_op != PENDING_NONE) {
		if (dump_bytes(dsp, dsp->dsa_drr,
		    sizeof (dmu_replay_record_t)) != 0)
			return (EINTR);
		dsp->dsa_pending_op = PENDING_NONE;
	}
	/* write a DATA record */
	bzero(dsp->dsa_drr, sizeof (dmu_replay_record_t));
	dsp->dsa_drr->drr_type = DRR_WRITE;
	drrw->drr_object = object;
	drrw->drr_type = type;
	drrw->drr_offset = offset;
	drrw->drr_length = blksz;
	drrw->drr_toguid = dsp->dsa_toguid;
	drrw->drr_checksumtype = BP_GET_CHECKSUM(bp);
	if (zio_checksum_table[drrw->drr_checksumtype].ci_dedup)
		drrw->drr_checksumflags |= DRR_CHECKSUM_DEDUP;
	DDK_SET_LSIZE(&drrw->drr_key, BP_GET_LSIZE(bp));
	DDK_SET_PSIZE(&drrw->drr_key, BP_GET_PSIZE(bp));
	DDK_SET_COMPRESS(&drrw->drr_key, BP_GET_COMPRESS(bp));
	drrw->drr_key.ddk_cksum = bp->blk_cksum;

	if (dump_bytes(dsp, dsp->dsa_drr, sizeof (dmu_replay_record_t)) != 0)
		return (EINTR);
	if (dump_bytes(dsp, data, blksz) != 0)
		return (EINTR);
	return (0);
}
コード例 #19
0
ファイル: imx_usb.c プロジェクト: hikob/imx_usb_loader
int transfer_bulk(struct sdp_dev *dev, int report, unsigned char *p, unsigned int cnt,
		unsigned int expected, int* last_trans)
{
	int err;
	struct libusb_device_handle *h = (struct libusb_device_handle *)dev->priv;
	if (cnt > dev->max_transfer)
		cnt = dev->max_transfer;
#ifdef DEBUG
	printf("report=%i\n", report);
	if (report < 3)
		dump_bytes(p, cnt, 0);
#endif
	*last_trans = 0;
	err = libusb_bulk_transfer(h, (report < 3) ? 1 : 2 + EP_IN, p, cnt, last_trans, 1000);

#ifdef DEBUG
	if (report >= 3)
		dump_bytes(p, cnt, 0);
#endif
	return err;
}
コード例 #20
0
ファイル: dump.c プロジェクト: sparkhom/mindy
static void dump_string_guts(int short_op, int long_op, char *str, int length)
{
    if (length < 256) {
        dump_op(short_op);
        dump_byte(length);
    }
    else {
        dump_op(long_op);
        dump_int(length);
    }
    dump_bytes(str, length);
}
コード例 #21
0
ファイル: io.c プロジェクト: effaremment/alice
int
sys_write(struct tcb *tcp)
{
	if (entering(tcp)) {
		printfd(tcp, tcp->u_arg[0]);
		tprints(", ");
		printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
		dump_bytes(tcp, tcp->u_arg[1], tcp->u_arg[2]);
		tprintf(", %lu", tcp->u_arg[2]);
	}
	return 0;
}
コード例 #22
0
ファイル: libusb-sniff.c プロジェクト: Andrer757/0xFFFF
int usb_control_msg(usb_dev_handle *dev, int requesttype, int request, int value, int index, char *bytes, int size, int timeout) {

	static int (*real_usb_control_msg)(usb_dev_handle *dev, int requesttype, int request, int value, int index, char *bytes, int size, int timeout) = NULL;
	int ret;

	if ( ! real_usb_control_msg )
		real_usb_control_msg = dlsym(RTLD_NEXT, "usb_control_msg");

	if ( requesttype == 64 && ! getenv("USBSNIFF_SKIP_CONTROL") ) {

		printf("\n==== usb_control_msg(requesttype=%d, request=%d, value=%d, index=%d, size=%d, timeout=%d) ====\n", requesttype, request, value, index, size, timeout);
		dump_bytes(bytes, size);
		printf("====\n");

		if ( getenv("USBSNIFF_WAIT") ) {
			printf("Press ENTER"); fflush(stdout); getchar();
		}

	}

	ret = real_usb_control_msg(dev, requesttype, request, value, index, bytes, size, timeout);

	if ( requesttype != 64 && ! getenv("USBSNIFF_SKIP_CONTROL") ) {

		printf("\n==== usb_control_msg(requesttype=%d, request=%d, value=%d, index=%d, size=%d, timeout=%d) ret = %d ====\n", requesttype, request, value, index, size, timeout, ret);
		if ( ret > 0 ) {
			dump_bytes(bytes, ret);
			printf("====\n");
		}

		if ( getenv("USBSNIFF_WAIT") ) {
			printf("Press ENTER"); fflush(stdout); getchar();
		}

	}

	return ret;

}
コード例 #23
0
ファイル: io.c プロジェクト: effaremment/alice
int
sys_pwrite(struct tcb *tcp)
{
	if (entering(tcp)) {
		printfd(tcp, tcp->u_arg[0]);
		tprints(", ");
		printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
		dump_bytes(tcp, tcp->u_arg[1], tcp->u_arg[2]);
		tprintf(", %lu, ", tcp->u_arg[2]);
		printllval(tcp, "%llu", PREAD_OFFSET_ARG);
	}
	return 0;
}
コード例 #24
0
ファイル: monitor_upload.c プロジェクト: MEGA65/mega65-core
int allocate_cluster(unsigned int cluster)
{
  int retVal=0;

  do {
    int fat_sector_num=cluster/(512/4);
    int fat_sector_offset=(cluster*4)&0x1FF;
    if (fat_sector_num>=sectors_per_fat) {
      printf("ERROR: cluster number too large.\n");
      retVal=-1; break;
    }

    // Read in the sector of FAT1
    unsigned char fat_sector[512];
    if (read_sector(partition_start+fat1_sector+fat_sector_num,fat_sector,0)) {
      printf("ERROR: Failed to read sector $%x of first FAT\n",fat_sector_num);
      retVal=-1; break;
    }

    dump_bytes(0,"FAT sector",fat_sector,512);
    
    printf("Marking cluster $%x in use by writing to offset $%x of FAT sector $%x\n",
	   cluster,fat_sector_offset,fat_sector_num);
    
    // Set the bytes for this cluster to $0FFFFF8 to mark end of chain and in use
    fat_sector[fat_sector_offset+0]=0xf8;
    fat_sector[fat_sector_offset+1]=0xff;
    fat_sector[fat_sector_offset+2]=0xff;
    fat_sector[fat_sector_offset+3]=0x0f;

    printf("Marking cluster in use in FAT1\n");

    // Write sector back to FAT1
    if (write_sector(partition_start+fat1_sector+fat_sector_num,fat_sector)) {
      printf("ERROR: Failed to write updated FAT sector $%x to FAT1\n",fat_sector_num);
      retVal=-1; break; }

    printf("Marking cluster in use in FAT2\n");

    // Write sector back to FAT2
    if (write_sector(partition_start+fat2_sector+fat_sector_num,fat_sector)) {
      printf("ERROR: Failed to write updated FAT sector $%x to FAT1\n",fat_sector_num);
      retVal=-1; break; }

    printf("Done allocating cluster\n");
    
  } while(0);
  
  return retVal;
}
コード例 #25
0
ファイル: packet_debug.c プロジェクト: ingenthr/libcouchbase
LIBCOUCHBASE_API
bool libcouchbase_packet_debug(libcouchbase_t instance, const void *ptr)
{
    (void)instance;
    const protocol_binary_request_header *req = ptr;

    assert((req->request.magic == PROTOCOL_BINARY_REQ) ||
           (req->request.magic == PROTOCOL_BINARY_RES));

    print_header();
    dump_bytes((void*)req, ntohl(req->request.bodylen) + sizeof(*req));
    printf("\n\nHeader breakdown\n");
    printf("Field        (offset) (value)\n");
    printf("Magic            (0): 0x%02x (%s)\n",
           req->request.magic,
           req->request.magic == PROTOCOL_BINARY_REQ ?
           "PROTOCOL_BINARY_REQ" : "PROTOCOL_BINARY_RES");
    printf("Opcode           (1): 0x%02x (%s)\n",
           req->request.opcode, get_command_name(req->request.opcode));
    printf("Key length     (2-3): ");
    print_uint16(req->request.keylen, true, true);
    printf("Extra length     (4): 0x%02x\n", req->request.extlen);
    printf("Data type        (5): 0x%02x\n", req->request.datatype);
    if (req->request.magic == PROTOCOL_BINARY_REQ) {
        printf("vbucket        (6-7): ");
        print_uint16(req->request.vbucket, true, true);
    } else {
        printf("Status         (6-7): ");
        print_uint16(req->request.vbucket, false, false);
        printf(" (%s)\n", get_response_name(req->request.vbucket));
    }
    printf("Total body    (8-11): ");
    print_uint32(req->request.bodylen, true, true);
    printf("Opaque       (12-15): ");
    print_uint32(req->request.opaque, true, true);
    printf("CAS          (16-23): ");
    print_uint64(req->request.cas, true, true);

    if (req->request.magic == PROTOCOL_BINARY_REQ) {
        if (packets[req->request.opcode].req != NULL) {
            packets[req->request.opcode].req((void*)req);
        }
    } else {
        if (packets[req->request.opcode].res != NULL) {
            packets[req->request.opcode].res((void*)req);
        }
    }

    return true;
}
コード例 #26
0
ファイル: cdp.c プロジェクト: aNeutrino/lanmap2
/**
 * process 'TestCase' cases: parse hex->binary, parse/dump, compare dump to expected
 */
static void test(void)
{
  unsigned i, passed = 0;
  FILE *f = tmpfile();
  if (NULL == f) {
    perror("tmpfile");
  } else {
    for (i = 0; i < sizeof TestCase / sizeof TestCase[0]; i++) {
      char inbuf[1024];
      size_t inlen = decode_hex_dump(inbuf, sizeof inbuf, TestCase[i].in, strlen(TestCase[i].in));
      printf("before:\n%s\n", TestCase[i].in);
      printf("after:\n");
      dump_bytes(inbuf, inlen, stdout);
      fputc('\n', stdout);
      if (inlen) {
        char outbuf[1024];
        size_t outlen;
        parse_frame pf = { PROT_CDP, inlen, inbuf, NULL };
        int match;
        rewind(f);
        parse(inbuf, inlen, &pf, NULL);
        dump(&pf, 0, f);
        fflush(f);
        rewind(f);
        if (NULL == fgets(outbuf, sizeof outbuf, f)) {
          perror("fgets");
          break;
        }
        match = 0 == strcmp(TestCase[i].out, outbuf);
        passed += match;
        printf("#%u\n"
              "expected=%s"
              "received=%s"
              "%s\n",
              i,
              TestCase[i].out,
              outbuf,
              match ? "OK" : "!!");
      }
    }
  }
  fclose(f);
  i = sizeof TestCase / sizeof TestCase[0];
  printf("Passed=%u/%u\n",
    passed, i);
  assert(passed == i);
}
コード例 #27
0
ファイル: io.c プロジェクト: effaremment/alice
/* Returns the total bytes dumped */
unsigned long
dump_iov(struct tcb *tcp, unsigned long len, unsigned long addr)
{
	unsigned long toret = 0;
#if SUPPORTED_PERSONALITIES > 1
	union {
		struct { u_int32_t base; u_int32_t len; } iov32;
		struct { u_int64_t base; u_int64_t len; } iov64;
	} iov;
#define sizeof_iov \
	(current_wordsize == 4 ? sizeof(iov.iov32) : sizeof(iov.iov64))
#define iov_iov_base \
	(current_wordsize == 4 ? (uint64_t) iov.iov32.base : iov.iov64.base)
#define iov_iov_len \
	(current_wordsize == 4 ? (uint64_t) iov.iov32.len : iov.iov64.len)
#else
	struct iovec iov;
#define sizeof_iov sizeof(iov)
#define iov_iov_base iov.iov_base
#define iov_iov_len iov.iov_len
#endif
	unsigned long size, cur, end;

	if (!len) {
		return 0;
	}

	size = len * sizeof_iov;
	end = addr + size;

	if (size / sizeof_iov != len || end < addr) {
		assert(0);
	}

	for (cur = addr; cur < end; cur += sizeof_iov) {
		if (umoven(tcp, cur, sizeof_iov, (char *) &iov) < 0) {
			assert(0);
		}
		unsigned long len = iov_iov_len;
		dump_bytes(tcp, (long) iov_iov_base, len);
		toret += len;
	}
#undef sizeof_iov
#undef iov_iov_base
#undef iov_iov_len
	return toret;
}
コード例 #28
0
ファイル: udpdump.cpp プロジェクト: tardfs/frontend
int _tmain(int argc, _TCHAR* argv[])
{
	WSADATA wsd ;
    printf("Start networking...\n") ;
    if ( WSAStartup( MAKEWORD(2,1), &wsd ) != 0 )
    {
        printf("error WSAStartup()\n" ) ;
        return (-1) ;
    }
	s = socket(PF_INET,SOCK_DGRAM,IPPROTO_UDP) ;
	if (s==INVALID_SOCKET)
	{
		printf("error socket()\n") ;
		return (-1) ;
	}

	sockaddr_in local ;
    memset(&local,0,sizeof(sockaddr_in)) ;
    local.sin_family = AF_INET ;
    local.sin_port = htons(0xc000) ;
    local.sin_addr.S_un.S_addr = htonl(INADDR_ANY) ;
    if (bind(s,(sockaddr*)&local,sizeof(sockaddr_in))==SOCKET_ERROR)
    {
		printf("bind() error\n") ;
        return (-1) ;
    }

	while(!kbhit())
	{
		int ret = 0 ;
		sockaddr_in peer ;
		int peerlen = sizeof(sockaddr_in) ;
		if ((ret=recvfrom(s, (char*)rxBuf, 2048, 0, (sockaddr*)&peer, &peerlen))<0)
		{ 
			printf("error recvfrom(): %08d\n",WSAGetLastError()) ;
			break ;
		}
		printf("%d bytes received:\n", ret ) ;
		dump_bytes(rxBuf,ret) ;
	}

    closesocket(s) ;
	WSACleanup() ;
	return (0) ;
}
コード例 #29
0
ファイル: libusb-sniff.c プロジェクト: Andrer757/0xFFFF
int usb_bulk_write(usb_dev_handle * dev, int ep, const char * bytes, int size, int timeout) {

	static int (*real_usb_bulk_write)(usb_dev_handle * dev, int ep, const char * bytes, int size, int timeout) = NULL;

	if ( ! real_usb_bulk_write )
		real_usb_bulk_write = dlsym(RTLD_NEXT, "usb_bulk_write");

	if ( ! getenv("USBSNIFF_SKIP_WRITE") ) {

		printf("\n==== usb_bulk_write (ep=%d size=%d timeout=%d) ====\n", ep, size, timeout);
		dump_bytes(bytes, size);
		printf("====\n");

		if ( getenv("USBSNIFF_WAIT") ) {
			printf("Press ENTER"); fflush(stdout); getchar();
		}

	}

	return real_usb_bulk_write(dev, ep, bytes, size, timeout);

}
コード例 #30
0
ファイル: dump.c プロジェクト: sparkhom/mindy
static void dump_component(struct component *c)
{
    struct constant *constant;
    struct block *block;
    int bytes;

    if (c->nconstants <= UCHAR_MAX && c->bytes <= USHRT_MAX) {
        dump_op(fop_SHORT_COMPONENT);
        dump_byte(c->nconstants);
        dump_short((short)(c->bytes));
    }
    else {
        dump_op(fop_COMPONENT);
        dump_int(c->nconstants);
        dump_int(c->bytes);
    }

    if (c->debug_name)
        dump_literal(c->debug_name);
    else
        dump_op(fop_FALSE);

    dump_integer(c->frame_size);

    dump_debug_info(c);

    for (constant = c->constants; constant != NULL; constant = constant->next)
        dump_constant(constant);

    bytes = 0;
    for (block = c->blocks; block != NULL; block = block->next) {
        int count = block->end - block->bytes;
        dump_bytes(block->bytes, count);
        bytes += count;
    }
    if (bytes != c->bytes)
        lose("Planned on writing %d bytes, but ended up writing %d instead.",
             c->bytes, bytes);
}