Exemplo n.º 1
0
int dumpCode(const char *progName, const char *name, const struct Buffer *buf) {
	int retVal = 0;
	uint32 i;
	uint32 vp = 0;

	for ( i = 1; i < buf->length; i++ ) {
		if (
			buf->data[i] == VID_LSB && buf->data[i+1] == VID_MSB &&
			buf->data[i+2] == PID_LSB && buf->data[i+3] == PID_MSB )
		{
			if ( vp ) {
				fprintf(stderr, "%s: Refusing to override VID:PID@%04X with %04X\n", progName, vp, i);
				FAIL(9, cleanup);
			}
			vp = i;
			i += 3;
		}
	}
	if ( !vp ) {
		fprintf(stderr, "%s: Not enough occurrances of vp\n", progName);
		FAIL(10, cleanup);
	}

	printf("/*\n * THIS FILE IS MACHINE-GENERATED! DO NOT EDIT IT!\n */\n");
	printf("#include \"../firmware.h\"\n\n");
	printf("static const uint8 data[] = {\n");
	dumpBytes(buf->data, buf->length);
	printf("};\n");
	printf("const struct FirmwareInfo %sFirmware = {\n", name);
	printf("\tdata, %d, 0x%04X\n", buf->length, vp);
	printf("};\n");
cleanup:
	return retVal;
}
Exemplo n.º 2
0
static int GatherFragmentData(u_char *buffer, ECB_t * ECB)
{
  int i;
  int nextFragLen, totalDataCount;
  u_char *bufptr, *memptr;

  totalDataCount = 0;
  bufptr = buffer;
  for (i = 0; i < ECB->FragmentCount; i++) {
    nextFragLen = ECB->FragTable[i].Length;
    memptr = FARt_PTR(ECB->FragTable[i].Address);
    if (i == 0) {
      /* subtract off IPX header size from first fragment */
      nextFragLen -= 30;
      memptr += 30;
    }
    if (nextFragLen) {
      /* DANG_FIXTHIS - dumb use of hardcoded 1500 here */
      if (totalDataCount + nextFragLen > 1500) {
	return (-1);
      }
      memcpy(bufptr, memptr, nextFragLen);
      bufptr += nextFragLen;
      totalDataCount += nextFragLen;
    }
  }
  n_printf("IPX: gathered %d fragments for %d bytes of data\n",
	   ECB->FragmentCount, totalDataCount);
  if (debug_level('n')) {
    dumpBytes(buffer, totalDataCount);
  }
  return (totalDataCount);
}
Exemplo n.º 3
0
static void printECB(ECB_t * ECB)
{
  int i;

  if(debug_level('n')) {
    n_printf("--DOS ECB (dump)--\n");
    dumpBytes((u_char *) ECB, 60);
    n_printf("--DOS ECB--\n");
    n_printf("Link             %04x:%04x\n", ECB->Link.segment, ECB->Link.offset);
    n_printf("ESR              %04x:%04x\n", ECB->ESRAddress.segment, ECB->ESRAddress.offset);
    n_printf("InUseFlag        %02x\n", ECB->InUseFlag);
    n_printf("CompletionCode   %02x\n", ECB->CompletionCode);
    n_printf("ECBSocket	     %04x\n", ntohs(ECB->ECBSocket));
    n_printf("ImmediateAddress %02X%02X%02X%02X%02X%02X\n",
      ECB->ImmediateAddress[0],
      ECB->ImmediateAddress[1],
      ECB->ImmediateAddress[2],
      ECB->ImmediateAddress[3],
      ECB->ImmediateAddress[4],
      ECB->ImmediateAddress[5]);
    n_printf("FragmentCount	 %d\n", ECB->FragmentCount);
    for (i = 0; i < ECB->FragmentCount; i++) {
      n_printf("Frag[%d].Length   %d\n", i, ECB->FragTable[i].Length);
      n_printf("Frag[%d].Address	 %p\n", i,
        FARt_PTR(ECB->FragTable[i].Address));
    }
  }
}
Exemplo n.º 4
0
/*
 * Name: kernel_main
 *
 * Description: Main kernel loop. Never returns. 
 *
 */
void kernel_main() 
{

    terminal_initialize();

    setup_memory();

    unsigned char *ptr = kmalloc(4096, GFP_KERNEL); 

    printk("%p --> %p\n", ptr, *ptr);

    unsigned long val = 0xdeadbeef;
    memcpy(ptr, &val, 4);
    dumpBytes(ptr, 4);

    printk("pages used %p out of %p\n", mem_stats.nr_used_frames, mem_stats.nr_total_frames);

	unsigned long virt_addr = boot_kmalloc();
	printk("boot_kmalloc = %p\n", virt_addr);
	
	virt_addr = boot_kmalloc();
	printk("boot_kmalloc = %p\n", virt_addr);

	ptr = (unsigned char *) 0xc0000000;
	*ptr = 0x77;
	



    // Kernel never returns from this function.
	while (1) {}
}
Exemplo n.º 5
0
/**
 * Output the given list of moviesto the file specified by the outputFile global
 * variable
 * @param list The list to output
 */
void dumpList(MovieNodeType *list) {

	if (list == NULL) {
		return;
	}

	unsigned char bytes[MAX_BYTES];

	fprintf(outputFile, "     ------------ LIST ------------\n");
	fprintf(outputFile, "      -- head:    ");
	convertToBytes((int) list, bytes);
	dumpBytes(bytes, MAX_BYTES);

	while (list != NULL) {

		fprintf(outputFile, "     -----------  node addr:  ");
		convertToBytes((int) list, bytes);
		dumpBytes(bytes, MAX_BYTES);

		fprintf(outputFile, "     -----------              data:  ");
		convertToBytes((int) list->data, bytes);
		dumpBytes(bytes, MAX_BYTES);

		fprintf(outputFile,
				"     -----------                     -- title: %s\n",
				list->data->title);
		fprintf(outputFile,
				"     -----------                     -- year:  %d\n",
				list->data->year);
		fprintf(outputFile,
				"     -----------                     -- genre: %s\n",
				getGenre(list->data->genre));

		fprintf(outputFile, "     -----------              prev:  ");
		convertToBytes((int) list->prev, bytes);
		dumpBytes(bytes, MAX_BYTES);

		fprintf(outputFile, "     -----------              next:  ");
		convertToBytes((int) list->next, bytes);
		dumpBytes(bytes, MAX_BYTES);

		list = list->next;
	}

	fprintf(outputFile, "     -------- END OF LIST --------\n");

}
Exemplo n.º 6
0
void dumpVar(VarType *var)
{
  unsigned char bytes[MAX_BYTES];
  int nBytes;

  printf("     ----  name:  %s\n", var->name);

  convertToBytes(var->value, bytes);

  printf("     ---- value:  ");
  nBytes = getNumBytes(var->dType);
  dumpBytes(bytes, nBytes);

  if (var->dType == C_INT_PTR) {
    printf("     ----  ptee:  ");
    convertToBytes((int) *((int*)var->value), bytes);
    dumpBytes(bytes, MAX_BYTES);
  }
}
Exemplo n.º 7
0
void printPlaceObject2(FILE *f, int length)
{
  int start = fileOffset;
  int flags = readUInt8(f);
  int l;

  println("Depth: %i", readUInt16(f));

  if(flags & PLACE_HASMOVE)
    println("Has move flag");

  if(flags & PLACE_HASCHARACTER)
    println("Character ID: %i", readUInt16(f));

  if(flags & PLACE_HASMATRIX)
  {
    println("Matrix:");
    printMatrix(f);
  }

  if(flags & PLACE_HASCXFORM)
  {
    print("CXForm: ");
    printCXForm(f, true);
    putchar('\n');
  }

  if(flags & PLACE_HASRATIO)
    println("Ratio: %i", readUInt16(f));

  if(flags & PLACE_HASNAME)
    println("Name: %s", readString(f));

  if(flags & PLACE_HASCLIP)
    println("ClipDepth: %i", readUInt16(f));

  if(flags & PLACE_RESERVED)
  {
    println("Mystery number: %04x", readUInt16(f));

    flags = readUInt16(f);
    println("Clip flags: %04x", flags);

    while((flags = readUInt16(f)) != 0)
    {
      println("Flags: %04x", flags);
      l = readUInt32(f);
      decompileAction(f, l, 0);
    }
  }

  dumpBytes(f, length-(fileOffset-start));
}
Exemplo n.º 8
0
static void packetRx(void *user, hfPacketT *packet) {

    switch (packet->h.h.operation_code) {
    case OP_STATUS:
        printf("op_status die %u\n", (unsigned int) packet->h.h.chip_address);
        printf("  temperature %5.1f voltage %5.3f\n",
               (double) GN_DIE_TEMPERATURE(
                            packet->d.opStatus.monitor.die_temperature),
               (double) GN_CORE_VOLTAGE(
                            packet->d.opStatus.monitor.core_voltage[0]));
        break;
    case OP_CONFIG:
        printf("op_config\n");
        break;
    case OP_USB_INIT:
        printf("op_usb_init\n");
        break;
    case OP_GWQ_STATUS:
        printf("op_gwq_status\n");
        break;
    case OP_DIE_STATUS:
        printf("op_die_status: die %2u\n",
               (unsigned int) packet->h.h.chip_address);
        printf("  temperature %5.1f voltage %5.3f\n",
               (double) GN_DIE_TEMPERATURE(
                            packet->d.opDieStatus.die.die_temperature),
               (double) GN_CORE_VOLTAGE(
                            packet->d.opDieStatus.die.core_voltage[0]));
        break;
    case OP_USB_NOTICE:
        packet->d.b[packet->h.h.data_length * 4] = '\0';
        printf("op_usb_notice: \"%s\"\n", &packet->d.b[4]);
        break;
    default:
        puts("packet rx:");
        dumpBytes(&packet->h.b[0], 8 + packet->h.h.data_length * 4);
        break;
    }
}
Exemplo n.º 9
0
static void printIPXHeader(IPXPacket_t * IPXHeader)
{
  if (debug_level('n')) {
    n_printf("--IPX Header (dump)--\n");
    dumpBytes((u_char *) IPXHeader, 30);
    n_printf("--IPX Header --\n");
    n_printf("Checksum         %04x\n", ntohs(IPXHeader->Checksum));
    n_printf("Length           %d\n", ntohs(IPXHeader->Length));
    n_printf("TransportControl %d\n", IPXHeader->TransportControl);
    n_printf("PacketType       %d\n", IPXHeader->PacketType);
    n_printf("Destination      %02X%02X%02X%02X:%02X%02X%02X%02X%02X%02X:%02X%02X\n",
      IPXHeader->Destination.Network[0],
      IPXHeader->Destination.Network[1],
      IPXHeader->Destination.Network[2],
      IPXHeader->Destination.Network[3],
      IPXHeader->Destination.Node[0],
      IPXHeader->Destination.Node[1],
      IPXHeader->Destination.Node[2],
      IPXHeader->Destination.Node[3],
      IPXHeader->Destination.Node[4],
      IPXHeader->Destination.Node[5],
      IPXHeader->Destination.Socket[0],
      IPXHeader->Destination.Socket[1]);
    n_printf("Source           %02X%02X%02X%02X:%02X%02X%02X%02X%02X%02X:%02X%02X\n",
      IPXHeader->Source.Network[0],
      IPXHeader->Source.Network[1],
      IPXHeader->Source.Network[2],
      IPXHeader->Source.Network[3],
      IPXHeader->Source.Node[0],
      IPXHeader->Source.Node[1],
      IPXHeader->Source.Node[2],
      IPXHeader->Source.Node[3],
      IPXHeader->Source.Node[4],
      IPXHeader->Source.Node[5],
      IPXHeader->Source.Socket[0],
      IPXHeader->Source.Socket[1]);
  }
}
Exemplo n.º 10
0
static int ScatterFragmentData(int size, unsigned char *buffer, ECB_t * ECB,
                               struct sockaddr_ipx *sipx)
{
  int i;
  int nextFragLen, dataLeftCount;
  u_char *bufptr, *memptr;
  IPXPacket_t *IPXHeader;

  n_printf("received data bytes:\n");
  if (debug_level('n')) {
    dumpBytes(buffer, size);
  }
  dataLeftCount = size;
  bufptr = buffer;
  if (ECB->FragmentCount < 1 || ECB->FragTable[0].Length < 30) {
    /* posted listen has a fragment error */
    n_printf("IPX: listen packet fragment error\n");
    return (size);
  }
  i = 0;
  while (i < ECB->FragmentCount && dataLeftCount) {
    nextFragLen = ECB->FragTable[i].Length;
    memptr = FARt_PTR(ECB->FragTable[i].Address);
    n_printf("IPX: filling fragment %d at %p, max_length %d with %d bytes left\n",
	     i, FARt_PTR(ECB->FragTable[i].Address), nextFragLen,
	     dataLeftCount);
    if (i == 0) {
      /* subtract off IPX header size from first fragment */
      nextFragLen -= 30;
      /* also, fill out IPX header */
      /* use data from sipx to fill out source address */
      IPXHeader = (IPXPacket_t *) memptr;
      IPXHeader->Checksum = 0xFFFF;
      IPXHeader->Length = htons(size + 30); /* in network order */
      /* DANG_FIXTHIS - use real values to fill out IPX header here */
      IPXHeader->TransportControl = 1;
      IPXHeader->PacketType = 0;
      memcpy((u_char *) & IPXHeader->Destination, MyAddress, 10);
      memcpy(&IPXHeader->Destination.Socket, &ECB->ECBSocket, 2);
      memcpy(IPXHeader->Source.Network, (char *) &sipx->sipx_network, 4);
      memcpy(IPXHeader->Source.Node, sipx->sipx_node, 6);
      memcpy(IPXHeader->Source.Socket, &sipx->sipx_port, 2);
      /* DANG_FIXTHIS - kludge for bug in linux IPX stack */
      /* IPX stack returns data count including IPX header */
      /*			dataLeftCount -= 30; */
      memptr += 30;
      printIPXHeader(IPXHeader);
    }
    if (nextFragLen > dataLeftCount) {
      nextFragLen = dataLeftCount;
    }
    if (nextFragLen) {
      memcpy(memptr, bufptr, nextFragLen);
      bufptr += nextFragLen;
      dataLeftCount -= nextFragLen;
    }
    i++;
  }
  n_printf("IPX: scattered %d fragments, %d bytes left over.\n",
	   i, dataLeftCount);
  return (dataLeftCount);
}
Exemplo n.º 11
0
// Dump binary attributes of an object
void dump_binaries(sqlite3* db, long long oid)
{
	int rv;
	unsigned long count;
	sqlite3_stmt* sqlcnt = NULL;
	sqlite3_stmt* sqlid = NULL;
	std::string commandcnt = "select count(id) from attribute_binary where object_id=?;";
	std::string commandid = "select id from attribute_binary where object_id=?;";
	rv = sqlite3_prepare_v2(db, commandcnt.c_str(), -1, &sqlcnt, NULL);
	if (rv != SQLITE_OK)
	{
		fprintf(stderr, "can't count the object table: %d(%s)\n",
			rv, sqlite3_errmsg(db));
		sqlite3_finalize(sqlcnt);
		return;
	}
	rv = sqlite3_bind_int64(sqlcnt, 1, oid);
	if (rv != SQLITE_OK)
	{
		fprintf(stderr, "can't bind the object id: %d(%s)\n",
			rv, sqlite3_errmsg(db));
		sqlite3_finalize(sqlcnt);
		return;
	}
	while ((rv = sqlite3_step(sqlcnt)) == SQLITE_BUSY)
	{
		sched_yield();
	}
	if (rv != SQLITE_ROW)
	{
		fprintf(stderr, "can't count the object table: %d(%s)\n",
			rv, sqlite3_errmsg(db));
		sqlite3_finalize(sqlcnt);
		return;
	}
	count = sqlite3_column_int(sqlcnt, 0);
	sqlite3_finalize(sqlcnt);
	if (count == 0)
		return;

	printf("%lu binary attributes for object %lld\n", count, oid);

	rv = sqlite3_prepare_v2(db, commandid.c_str(), -1, &sqlid, NULL);
	if (rv != SQLITE_OK)
	{
		fprintf(stderr, "can't count the object table: %d(%s)\n",
			rv, sqlite3_errmsg(db));
		sqlite3_finalize(sqlid);
		return;
	}
	rv = sqlite3_bind_int64(sqlid, 1, oid);
	if (rv != SQLITE_OK)
	{
		fprintf(stderr, "can't bind the object id: %d(%s)\n",
			rv, sqlite3_errmsg(db));
		sqlite3_finalize(sqlid);
		return;
	}
	while (count-- > 0) {
		while ((rv = sqlite3_step(sqlid)) == SQLITE_BUSY)
		{
			sched_yield();
		}
		if (rv != SQLITE_ROW)
		{
			if (rv != SQLITE_DONE)
			{
				fprintf(stderr,
					"can't get next object id: %d(%s)\n",
					rv, sqlite3_errmsg(db));
			}
			sqlite3_finalize(sqlid);
			return;
		}
		long long id = sqlite3_column_int64(sqlid, 0);

		uint64_t type;
		std::vector<uint8_t> value;
		if (!getBytes(db, oid, id, type, value))
		{
			return;
		}
		dumpULong(type);
		if ((uint64_t)((uint32_t)type) != type)
		{
			printf("overflow attribute type\n");
		}
		else
		{
			dumpCKA((unsigned long) type, 48);
			printf("\n");
		}
		dumpULong((uint64_t) value.size());
		printf("(length %lu)\n", (unsigned long) value.size());
		dumpBytes(value);
	}
}
Exemplo n.º 12
0
static Stack readActionRecord(FILE *f)
{
  int length = 0, type = readUInt8(f);

  if((type&0x80) == 0x80)
    length = readUInt16(f);

  switch(type)
  {
    /* no-arg */
    case SWFACTION_GETTIMER:
    case SWFACTION_STOPDRAGMOVIE:
    case SWFACTION_NEXTFRAME:
    case SWFACTION_PREVFRAME:
    case SWFACTION_PLAY:
    case SWFACTION_STOP:
    case SWFACTION_TOGGLEQUALITY:
    case SWFACTION_STOPSOUNDS:
      return newTree(NULL, type, NULL);

    case SWFACTION_POP:
	  /* pop(); */
      return newTree(NULL, type, NULL);

    /* one-arg */
    case SWFACTION_STRINGLENGTH:
    case SWFACTION_INT:
    case SWFACTION_RANDOM:
    case SWFACTION_MBLENGTH:
    case SWFACTION_ORD:
    case SWFACTION_CHR:
    case SWFACTION_MBORD:
    case SWFACTION_MBCHR:
    case SWFACTION_LOGICALNOT:
    case SWFACTION_GETVARIABLE:
    case SWFACTION_REMOVECLIP:
    case SWFACTION_TRACE:
    case SWFACTION_SETTARGETEXPRESSION:
    case SWFACTION_CALLFRAME:
      return newTree(pop(), type, NULL);

    /* two-arg */
    case SWFACTION_ADD:
    case SWFACTION_MULTIPLY:
    case SWFACTION_DIVIDE:
    case SWFACTION_EQUAL:
    case SWFACTION_LESSTHAN:
    case SWFACTION_LOGICALAND:
    case SWFACTION_LOGICALOR:
    case SWFACTION_STRINGEQ:
    case SWFACTION_SETVARIABLE:
    case SWFACTION_STRINGCONCAT:
    case SWFACTION_STRINGCOMPARE:
	{
      Stack right = pop();
      Stack left = pop();
      return newTree(left, type, right);
	}

    case SWFACTION_GETPROPERTY:
    {
      Stack right = pop();
      Stack left = pop();

      if(right->type == 's')
      {
	Stack New = newProperty(atoi(right->data.string));
	destroy(right);
	right = New;
      }
      return newTree(left, type, right);
    }

    case SWFACTION_SUBTRACT:
    {
      Stack right = pop();
      Stack left = pop();

      if(left->type == 's' &&
	 strcmp(left->data.string, "0") == 0)
      {
	destroy(left);
	right->data.string = negateString(right->data.string);
	return right;
      }

      return newTree(left, type, right);
    }

    /* three-arg */
    case SWFACTION_SETPROPERTY:
	{
	  Stack value = pop();
	  Stack property = pop();
	  Stack target = pop();

      if(property->type == 's')
      {
	Stack New = newProperty(atoi(property->data.string));
	destroy(property);
	property = New;
      }

      return newTree(newTree(target, type, property),
		     SWFACTION_SETVARIABLE, value);
	}

    case SWFACTION_MBSUBSTRING:
    case SWFACTION_SUBSTRING:
	{
	  Stack s3 = pop();
	  Stack s2 = pop();
	  Stack s1 = pop();
      return newTree(s1, type, newTree(s2, type, s3));
	}

    case SWFACTION_DUPLICATECLIP:
    {
      Stack level = pop();
      Stack target = pop();
      Stack source = pop();
      Stack arg;

      if(level->type != 't' ||
	 level->data.tree->action != SWFACTION_ADD)
	error("WTHIT property not found in duplicateClip target level!");

      if(level->data.tree->left->type == 'p' &&
	 level->data.tree->left->data.prop == PROPERTY_WTHIT)
      {
        arg = level->data.tree->right;
	level->data.tree->right = NULL;
      }
      else if(level->data.tree->right->type == 'p' &&
	      level->data.tree->right->data.prop == PROPERTY_WTHIT)
      {
        arg = level->data.tree->left;
        level->data.tree->left = NULL;
      }
      else
	error("WTHIT property not found in duplicateClip target level!");

      destroy(level);

      return newTree(source, type, newTree(target, type, arg));
    }


    /* weird ops */
    case SWFACTION_STARTDRAGMOVIE:
    {
      Stack target = pop();
      Stack lockmouse = pop();
      Stack constraint = pop();

      if(constraint->type != 's')
	error("Sorry, decompiler can't deal with conditional constraint!");

      if(strcmp(constraint->data.string, "0") == 0)
	return newTree(constraint, type, newTree(lockmouse, type, target));
      else
	  {
		Stack s4 = pop();
		Stack s3 = pop();
		Stack s2 = pop();
		Stack s1 = pop();

	return newTree(newTree(newTree(s1, type, s2), type,
			       newTree(s3, type, s4)), type,
		       newTree(lockmouse, type, target));
	  }
    }

    case SWFACTION_PUSHDATA:
    {
      int local_type = readUInt8(f);
      if(local_type==0)
	return newString(readString(f));
      else
      {
	readUInt16(f); /* 0x0000 */
        return newProperty(getSetProperty(readUInt16(f)));
      }
    }

    case SWFACTION_GOTOFRAME:
      return newTree((Stack)readUInt16(f), type, NULL);

    case SWFACTION_GETURL:
    {
      char *url = readString(f);
      char *target = readString(f);
      return newTree((Stack)url, type, (Stack)target);
    }

    case SWFACTION_GETURL2:
	{
	  Stack target = pop();
	  Stack url = pop();
      return newTree((Stack)readUInt8(f), type, newTree(url, type, target));
	}

    case SWFACTION_WAITFORFRAMEEXPRESSION:
      return newTree((Stack)readUInt8(f), type, NULL);

    case SWFACTION_GOTOEXPRESSION:
      return newTree(pop(), type, (Stack)readUInt8(f));

    case SWFACTION_SETTARGET:
    case SWFACTION_GOTOLABEL:
      return newTree((Stack)readString(f), type, NULL);


    /* branches */
    case SWFACTION_BRANCHIFTRUE:
      return newTree(pop(), type, (Stack)readSInt16(f));

    case SWFACTION_BRANCHALWAYS:
      return newTree(NULL, type, (Stack)readSInt16(f));

    case SWFACTION_WAITFORFRAME:
	{
	  Stack left = (Stack)readUInt16(f);
	  Stack right = (Stack)readUInt8(f);
      return newTree(left, type, right);
	}

    case SWFACTION_END:
      return NULL;

    default:
      printf("Unknown Action: %02X\n", type);
      dumpBytes(f, length);
      return NULL;
  }
}
Exemplo n.º 13
0
int main(int argc, char *argv[]) {
    int result;
    int usbInitialized;
    libusb_device **devices;
    struct libusb_device_descriptor desc;
    libusb_device_handle *dev;
    int count;
    unsigned char usbBuffer[64];
    int i, j;

    result = 0;
    usbInitialized = 0;
    dev = NULL;

    if (result == 0 && libusb_init(NULL)) {
        fprintf(stderr, "failed to initialize libusb\n");
        result = 1;
    }

    if (result == 0) {
        usbInitialized = 1;
        libusb_set_debug(NULL, 0);
        count = libusb_get_device_list(NULL, &devices);
        if (count < 0) {
            fprintf(stderr, "failed to get device list\n");
            result = 1;
        }
    }
    if (result == 0) {
        for (i = 0, j = -1; i < count && result == 0; i++) {
            if (libusb_get_device_descriptor(devices[i], &desc) ==
                LIBUSB_SUCCESS) {
                if ((desc.idVendor == HF_USB_VENDOR_ID &&
                     desc.idProduct == HF_USB_PRODUCT_ID_G1)) {
                    if (j >= 0) {
                        fprintf(stderr, "more than one device found; aborting");
                        result = 1;
                    } else
                        j = i;
                }
            }
        }
        if (j < 0) {
            fprintf(stderr, "failed to find device\n");
            result = 1;
        }
        if (result == 0) {
            if (libusb_open(devices[j], &dev)) {
                fprintf(stderr, "failed to open device\n");
                result = 1;
            }
        }
        libusb_free_device_list(devices, 1);
    }


    if (result == 0) {
        count = libusb_control_transfer(dev,
                                        LIBUSB_ENDPOINT_IN |
                                        LIBUSB_REQUEST_TYPE_VENDOR |
                                        LIBUSB_RECIPIENT_INTERFACE,
                                        0xd0, /* request */
                                        0x0000, /* value */
                                        0x0000, /* index */
                                        usbBuffer,
                                        64,
                                        TIMEOUT);
        if (count > 0)
            dumpBytes(usbBuffer, count);
        else {
            fprintf(stderr, "error reading debug buffer %d\n", count);
            result = 1;
        }
    }

    if (usbInitialized) {
        if (dev)
            libusb_close(dev);
        libusb_exit(NULL);
    }

    return result;
}
Exemplo n.º 14
0
int printActionRecord(FILE *f)
{
  int length = 0, type = readUInt8(f);

  if((type&0x80) == 0x80)
    length = readUInt16(f);

  switch(type)
  {
    case SWFACTION_ADD:
      println("Add");
      break;
    case SWFACTION_SUBTRACT:
      println("Subtract");
      break;
    case SWFACTION_MULTIPLY:
      println("Multiply");
      break;
    case SWFACTION_DIVIDE:
      println("Divide");
      break;
    case SWFACTION_EQUAL:
      println("Equals");
      break;
    case SWFACTION_STRICTEQ:
      println("Strictly Equals");
      break;
    case SWFACTION_LESSTHAN:
      println("Less Than");
      break;
    case SWFACTION_LOGICALAND:
      println("And");
      break;
    case SWFACTION_LOGICALOR:
      println("Or");
      break;
    case SWFACTION_LOGICALNOT:
      println("Not");
      break;
    case SWFACTION_STRINGEQ:
      println("String eq");
      break;
    case SWFACTION_STRINGLENGTH:
      println("String Length");
      break;
    case SWFACTION_SUBSTRING:
      println("Substring");
      break;
    case SWFACTION_INT:
      println("Int");
      break;
    case SWFACTION_POP:
      println("Pop");
      break;
    case SWFACTION_SWAP:
      println("Swap");
      break;
    case SWFACTION_INITOBJECT:
      println("Init Object");
      break;
    case SWFACTION_INITARRAY:
      println("Init Array");
      break;
    case SWFACTION_GETVARIABLE:
      println("Get Variable");
      break;
    case SWFACTION_SETVARIABLE:
      println("Set Variable");
      break;
    case SWFACTION_SETTARGETEXPRESSION:
      println("Set Target Expression");
      break;
    case SWFACTION_STRINGCONCAT:
      println("String Concat");
      break;
    case SWFACTION_GETPROPERTY:
      println("Get Property");
      break;
    case SWFACTION_SETPROPERTY:
      println("Set Property");
      break;
    case SWFACTION_DUPLICATECLIP:
      println("Duplicate Clip");
      break;
    case SWFACTION_REMOVECLIP:
      println("Remove Clip");
      break;
    case SWFACTION_TRACE:
      println("Trace");
      break;
    case SWFACTION_STARTDRAGMOVIE:
      println("Start Drag Movie");
      break;
    case SWFACTION_STOPDRAGMOVIE:
      println("Stop Drag Movie");
      break;
    case SWFACTION_STRINGCOMPARE:
      println("String Compare");
      break;
    case SWFACTION_RANDOM:
      println("Random");
      break;
    case SWFACTION_MBLENGTH:
      println("String MB Length");
      break;
    case SWFACTION_ORD:
      println("Ord");
      break;
    case SWFACTION_CHR:
      println("Chr");
      break;
    case SWFACTION_GETTIMER:
      println("Get Timer");
      break;
    case SWFACTION_MBSUBSTRING:
      println("MB Substring");
      break;
    case SWFACTION_MBORD:
      println("MB Ord");
      break;
    case SWFACTION_MBCHR:
      println("MB Chr");
      break;
    case SWFACTION_NEXTFRAME:
      println("Next Frame");
      break;
    case SWFACTION_PREVFRAME:
      println("Previous Frame");
      break;
    case SWFACTION_PLAY:
      println("Play");
      break;
    case SWFACTION_STOP:
      println("Stop");
      break;
    case SWFACTION_TOGGLEQUALITY:
      println("Toggle Quality");
      break;
    case SWFACTION_STOPSOUNDS:
      println("Stop Sounds");
      break;

    /* ops with args */
    case SWFACTION_PUSHDATA:
    {
      int type;
      int start = fileOffset;
      int count = 0;

      print("Push:");
      while(fileOffset < start+length)
      {
	if ( count++ ) putchar(',');
	switch(type = readUInt8(f))
	{
	  case 0: /* string */
	    printf(" string:%s", readString(f));
	    break;
	  case 1: /* property */
	    readUInt16(f); /* always 0? */
	    printf(" property:%04x", readUInt16(f));
	    break;
	  case 2: /* null */
	    printf(" NULL");
	    break;
	  case 3: /* ??? */
	    printf(" type_3:");
	    break;
	  case 4: 
	    printf(" register:%i", readUInt8(f));
	    break;
	  case 5:
	    if(readUInt8(f))
	      printf(" TRUE");
	    else
	      printf(" FALSE");
	    break;
	  case 6: /* double */
	    printf(" double:%f", readDouble(f));
	    break;
	  case 7: /* int */
	    printf(" int:%i", readSInt32(f));
	    break;
	  case 8: /* dictionary */
	    printf(" dict:\"%s\"", dictionary[readUInt8(f)]);
	    break;
	  default:
	    printf(" unknown_type_%i", type);
	}
      }
      putchar('\n');
      break;
    }
    case SWFACTION_GOTOFRAME:
      println("Goto Frame %i", readUInt16(f));
      break;
    case SWFACTION_GETURL:
    {
      char *url = readString(f);
      println("Get URL \"%s\" target \"%s\"", url, readString(f));
      break;
    }
    case SWFACTION_WAITFORFRAMEEXPRESSION:
      println("Wait For Frame Expression, skip %i\n", readUInt8(f));
      break;
    case SWFACTION_BRANCHALWAYS:
      println("Branch Always %i", readSInt16(f));
      break;
    case SWFACTION_GETURL2:
    {
      int flags = readUInt8(f);

      switch(flags)
      {
        case 0: println("Get URL2 (Don't send)"); break;
        case 1: println("Get URL2 (GET)"); break;
        case 2: println("Get URL2 (POST)"); break;
        default: println("GET URL2 (0x%x)", flags);
      }
      break;
    }
    case SWFACTION_BRANCHIFTRUE:
      println("Branch If True %i", readSInt16(f));
      break;
    case SWFACTION_CALLFRAME:
      println("Call Frame");
      dumpBytes(f, length);
      break;
    case SWFACTION_GOTOEXPRESSION:
      print("Goto Expression");
      if(readUInt8(f) == 1)
	printf(" and Play\n");
      else
	printf(" and Stop\n");
      break;
    case SWFACTION_WAITFORFRAME:
    {
      int frame = readUInt16(f);
      println("Wait for frame %i else skip %i", frame, readUInt8(f));
      break;
    }
    case SWFACTION_SETTARGET:
      println("Set Target %s", readString(f));
      break;
    case SWFACTION_GOTOLABEL:
      println("Goto Label %s", readString(f));
      break;
    case SWFACTION_END:
      return 0;
      break;

    /* f5 ops */
    case SWFACTION_DELETE:
      println("Delete");
      break;

    case SWFACTION_DELETEVAR:
      println("Delete2");
      break;

    case SWFACTION_VAR:
      println("Var");
      break;
    case SWFACTION_VAREQUALS:
      println("Var Assign");
      break;
    case SWFACTION_CALLFUNCTION:
      println("Call Function");
      break;
    case SWFACTION_RETURN:
      println("Return");
      break;
    case SWFACTION_MODULO:
      println("Modulo");
      break;
    case SWFACTION_NEW:
      println("New");
      break;
    case SWFACTION_NEWMETHOD:
      println("NewMethod");
      break;
    case SWFACTION_TYPEOF:
      println("Typeof");
      break;
    case SWFACTION_TARGETPATH:
      println("TargetPath");
      break;
    case SWFACTION_NEWADD:
      println("New Add");
      break;
    case SWFACTION_NEWLESSTHAN:
      println("New Less Than");
      break;
    case SWFACTION_NEWEQUAL:
      println("New Equals");
      break;
    case SWFACTION_DUP:
      println("Dup");
      break;
    case SWFACTION_GETMEMBER:
      println("Get Member");
      break;
    case SWFACTION_SETMEMBER:
      println("Set Member");
      break;
    case SWFACTION_INCREMENT:
      println("Increment");
      break;
    case SWFACTION_DECREMENT:
      println("Decrement");
      break;
    case SWFACTION_CALLMETHOD:
      println("Call Method");
      break;
    case SWFACTION_BITWISEAND:
      println("Bitwise And");
      break;
    case SWFACTION_BITWISEOR:
      println("Bitwise Or");
      break;
    case SWFACTION_BITWISEXOR:
      println("Bitwise Xor");
      break;
    case SWFACTION_SHIFTLEFT:
      println("Shift Left");
      break;
    case SWFACTION_SHIFTRIGHT:
      println("Shift Right");
      break;
    case SWFACTION_SHIFTRIGHT2:
      println("Shift Right 2");
      break;

    case SWFACTION_DECLARENAMES:
    {
      int i, n = readUInt16(f);
      print("Declare Dictionary:");

      for(i=0; i<n; ++i)
	printf(" %s%c", dictionary[i]=readString(f), (i<n-1)?',':'\n');

      break;
    }
    case SWFACTION_WITH:
    {
      println("With");

      ++gIndent;
      printDoAction(f, readUInt16(f));
      --gIndent;

      break;
    }
    case SWFACTION_DEFINEFUNCTION:
    {
      char *name = readString(f);
      int n = readUInt16(f);

      print("function %s(", name);

      if(n>0)
      {
	printf("%s", readString(f));
	--n;
      }

      for(; n>0; --n)
	printf(", %s", readString(f));

      putchar(')');
      putchar('\n');

      ++gIndent;
      printDoAction(f, readUInt16(f));
      --gIndent;

      break;
    }

    case SWFACTION_ENUMERATE:
      println("Enumerate");
      break;

    case SWFACTION_SETREGISTER:
      println("Set Register %i", readUInt8(f));
      break;

    default:
      println("Unknown Action: %02X", type);
      dumpBytes(f, length);
  }
  return 1;
}
Exemplo n.º 15
0
int dumpCode(
	const char *progName, const char *name, const struct Buffer *buf1, const struct Buffer *buf2)
{
	int returnCode = 0;
	uint16 i;
	uint16 d0E = 0;
	uint16 d0F = 0;
	uint16 vp = 0;
	uint16 outBits = 0;
	uint16 outBitsComp = 0;
	uint16 oeRegs[NUM_OE_BITS+1];
	uint16 oeRegsLen = 0;
	uint16 allBits[NUM_ALL_BITS+1];
	uint16 allBitsLen = 0;
	uint16 allBitsComp[NUM_ALL_BITS+1];
	uint16 allBitsCompLen = 0;
	uint16 tdoBit[NUM_TDO_BIT+1];
	uint16 tdoBitLen = 0;
	uint16 tdiBit[NUM_TDI_BIT+1];
	uint16 tdiBitLen = 0;
	uint16 tmsBit[NUM_TMS_BIT+1];
	uint16 tmsBitLen = 0;
	uint16 tckBit[NUM_TCK_BIT+1];
	uint16 tckBitLen = 0;

	if ( buf1->length != buf2->length ) {
		fprintf(stderr, "%s: File lengths differ (%d != %d)\n", progName, buf1->length, buf2->length);
		FAIL(20);
	}

	if ( *buf1->data != *buf2->data ) {
		fprintf(stderr, "%s: First bytes differ (0x%02X != 0x%02X)\n", progName, *buf1->data, *buf2->data);
		FAIL(21);
	}

	for ( i = 1; i < buf1->length; i++ ) {
		if (
			buf1->data[i] == 0xB4 && buf2->data[i] == 0xB4 &&
			buf1->data[i+1] == 0x04 && buf2->data[i+1] == 0x04 &&
			buf1->data[i+2] == 0x13 && buf2->data[i+2] == 0x13 &&
			buf1->data[i+3] == 0x86 && buf2->data[i+3] == 0x86 )
		{
			if ( vp ) {
				fprintf(stderr, "%s: Refusing to override VID:PID@%04X with %04X\n", progName, vp, i);
				FAIL(22);
			}
			vp = i;
			i += 3;
		} else if ( buf1->data[i] != buf2->data[i] ) {
			if ( buf1->data[i] == 0x0E && buf2->data[i] == 0x0C ) {
				if ( d0E ) {
					fprintf(stderr, "%s: Refusing to override 0E->0C@%04X with %04X\n", progName, d0E, i);
					FAIL(23);
				}
				d0E = i;
			} else if ( buf1->data[i] == 0x0F && buf2->data[i] == 0x0D ) {
				if ( d0F ) {
					fprintf(stderr, "%s: Refusing to override 0F->0D@%04X with %04X\n", progName, d0F, i);
					FAIL(24);
				}
				d0F = i;
			} else if ( buf1->data[i] == OUTBITS_1 && buf2->data[i] == OUTBITS_2 ) {
				if ( outBits ) {
					fprintf(stderr, "%s: Refusing to override outBits@%04X with %04X\n", progName, outBits, i);
					FAIL(25);
				}
				outBits = i;
			} else if ( buf1->data[i] == OUTBITS_COMP_1 && buf2->data[i] == OUTBITS_COMP_2 ) {
				if ( outBitsComp ) {
					fprintf(stderr, "%s: Refusing to override outBitsComp@%04X with %04X\n", progName, outBitsComp, i);
					FAIL(26);
				}
				outBitsComp = i;
			} else if ( buf1->data[i] == 0xB5 && buf2->data[i] == 0xB4 ) {
				if ( oeRegsLen > NUM_OE_BITS ) {
					fprintf(stderr, "%s: Too many occurrances of oeRegs@%04X\n", progName, i);
					FAIL(27);
				}
				oeRegs[oeRegsLen++] = i;
			} else if ( buf1->data[i] == ALLBITS_1 && buf2->data[i] == ALLBITS_2 ) {
				if ( allBitsLen > NUM_ALL_BITS ) {
					fprintf(stderr, "%s: Too many occurrances of allBits@%04X\n", progName, i);
					FAIL(28);
				}
				allBits[allBitsLen++] = i;
			} else if ( buf1->data[i] == ALLBITS_COMP_1 && buf2->data[i] == ALLBITS_COMP_2 ) {
				if ( allBitsCompLen > NUM_ALL_BITS ) {
					fprintf(stderr, "%s: Too many occurrances of allBitsComp@%04X\n", progName, i);
					FAIL(29);
				}
				allBitsComp[allBitsCompLen++] = i;
			} else if ( buf1->data[i] == TDO_ADDR_1 && buf2->data[i] == TDO_ADDR_2 ) {
				if ( tdoBitLen > NUM_TDO_BIT ) {
					fprintf(stderr, "%s: Too many occurrances of tdoBit@%04X\n", progName, i);
					FAIL(30);
				}
				tdoBit[tdoBitLen++] = i;
			} else if ( buf1->data[i] == TDI_ADDR_1 && buf2->data[i] == TDI_ADDR_2 ) {
				if ( tdiBitLen > NUM_TDI_BIT ) {
					fprintf(stderr, "%s: Too many occurrances of tdiBit@%04X\n", progName, i);
					FAIL(31);
				}
				tdiBit[tdiBitLen++] = i;
			} else if ( buf1->data[i] == TMS_ADDR_1 && buf2->data[i] == TMS_ADDR_2 ) {
				if ( tmsBitLen > NUM_TMS_BIT ) {
					fprintf(stderr, "%s: Too many occurrances of tmsBit@%04X\n", progName, i);
					FAIL(32);
				}
				tmsBit[tmsBitLen++] = i;
			} else if ( buf1->data[i] == TCK_ADDR_1 && buf2->data[i] == TCK_ADDR_2 ) {
				if ( tckBitLen > NUM_TCK_BIT ) {
					fprintf(stderr, "%s: Too many occurrances of tckBit@%04X\n", progName, i);
					FAIL(33);
				}
				tckBit[tckBitLen++] = i;
			} else {
				fprintf(stderr, "%s: Unsupported diff: %02X->%02X@%04X\n", progName, buf1->data[i], buf2->data[i], i);
				FAIL(34);
			}
		}
	}
	if ( oeRegsLen != NUM_OE_BITS ) {
		fprintf(stderr, "%s: Not enough occurrances of oeRegs\n", progName);
		FAIL(35);
	}
	if ( allBitsLen != NUM_ALL_BITS ) {
		fprintf(stderr, "%s: Not enough occurrances of allBits\n", progName);
		FAIL(36);
	}
	if ( allBitsCompLen != NUM_ALL_BITS ) {
		fprintf(stderr, "%s: Not enough occurrances of allBitsComp\n", progName);
		FAIL(37);
	}
	if ( tdoBitLen != NUM_TDO_BIT ) {
		fprintf(stderr, "%s: Not enough occurrances of tdoBit (expected %d, got %d)\n", progName, NUM_TDO_BIT, tdoBitLen);
		FAIL(38);
	}
	if ( tdiBitLen != NUM_TDI_BIT ) {
		fprintf(stderr, "%s: Not enough occurrances of tdiBit (expected %d, got %d)\n", progName, NUM_TDI_BIT, tdiBitLen);
		FAIL(39);
	}
	if ( tmsBitLen != NUM_TMS_BIT ) {
		fprintf(stderr, "%s: Not enough occurrances of tmsBit (expected %d, got %d)\n", progName, NUM_TMS_BIT, tmsBitLen);
		FAIL(40);
	}
	if ( tckBitLen != NUM_TCK_BIT ) {
		fprintf(stderr, "%s: Not enough occurrances of tckBit (expected %d, got %d)\n", progName, NUM_TCK_BIT, tckBitLen);
		FAIL(41);
	}
	if ( !d0E ) {
		fprintf(stderr, "%s: Not enough occurrances of d0E\n", progName);
		FAIL(42);
	}
	if ( !d0F ) {
		fprintf(stderr, "%s: Not enough occurrances of d0F\n", progName);
		FAIL(43);
	}
	if ( !vp ) {
		fprintf(stderr, "%s: Not enough occurrances of vp\n", progName);
		FAIL(44);
	}
	if ( !outBits ) {
		fprintf(stderr, "%s: Not enough occurrances of outBits\n", progName);
		FAIL(45);
	}
	if ( !outBitsComp ) {
		fprintf(stderr, "%s: Not enough occurrances of outBitsComp\n", progName);
		FAIL(46);
	}

	oeRegs[oeRegsLen++] = 0x0000;
	allBits[allBitsLen++] = 0x0000;
	allBitsComp[allBitsCompLen++] = 0x0000;
	tdoBit[tdoBitLen++] = 0x0000;
	tdiBit[tdiBitLen++] = 0x0000;
	tmsBit[tmsBitLen++] = 0x0000;
	tckBit[tckBitLen++] = 0x0000;

	printf("/*\n * THIS FILE IS MACHINE-GENERATED! DO NOT EDIT IT!\n */\n");
	printf("#include \"../firmware.h\"\n\n");
	printf("static const uint8 data[] = {\n");
	dumpBytes(buf1->data, buf1->length);
	printf("};\n");
	printf("static const uint16 oeRegs[] = {\n");
	dumpWords(oeRegs, oeRegsLen);
	printf("};\n");
	printf("static const uint16 allBits[] = {\n");
	dumpWords(allBits, allBitsLen);
	printf("};\n");
	printf("static const uint16 allBitsComp[] = {\n");
	dumpWords(allBitsComp, allBitsCompLen);
	printf("};\n");
	printf("static const uint16 tdoBit[] = {\n");
	dumpWords(tdoBit, tdoBitLen);
	printf("};\n");
	printf("static const uint16 tdiBit[] = {\n");
	dumpWords(tdiBit, tdiBitLen);
	printf("};\n");
	printf("static const uint16 tmsBit[] = {\n");
	dumpWords(tmsBit, tmsBitLen);
	printf("};\n");
	printf("static const uint16 tckBit[] = {\n");
	dumpWords(tckBit, tckBitLen);
	printf("};\n");
	printf("const struct FirmwareInfo %sFirmware = {\n", name);
	printf("\tdata, %d,\n", buf1->length);
	printf("\t0x%04X, 0x%04X, 0x%04X,\n", vp, d0E, d0F);
	printf("\t0x%04X, 0x%04X,\n", outBits, outBitsComp);
	printf("\toeRegs,\n");
	printf("\tallBits, allBitsComp,\n");
	printf("\ttdoBit,\n");
	printf("\ttdiBit,\n");
	printf("\ttmsBit,\n");
	printf("\ttckBit\n");
	printf("};\n");
cleanup:
	return returnCode;
}