Пример #1
0
int dusb_decomp(const char *filename)
{
	char src_name[1024];
	char dst_name[1024];
	unsigned char data;
	int i;

	strcpy(src_name, filename);
    strcat(src_name, ".hex");

	strcpy(dst_name, filename);
    strcat(dst_name, ".pkt");
    
	hex = fopen(src_name, "rt");
    if(hex == NULL)
    {
        fprintf(stderr, "Unable to open this file: %s\n", src_name);
        return -1;
    }

	log = fopen(dst_name, "wt");
	if(log == NULL)
    {
        fprintf(stderr, "Unable to open this file: %s\n", dst_name);
        return -1;
    }

	{
		char line[256];

		fgets(line, sizeof(line), hex);
		fgets(line, sizeof(line), hex);
		fgets(line, sizeof(line), hex);
	}

	fprintf(log, "TI packet decompiler for D-USB, version 1.0\n");

	while(hex_read(&data) != -1)
	{
		dusb_write(0, data);
	}

	fprintf(log, "() Packet types found: ");
	for(i = 0; i < ptf; i++) fprintf(log, "%02x ", pkt_type_found[i]);
	fprintf(log, "\n");
	fprintf(log, "{} Data codes found: ");
	for(i = 0; i < dcf; i++) fprintf(log, "%04x ", data_code_found[i]);
	fprintf(log, "\n");

	fclose(hex);

	return 0;
}
Пример #2
0
int nsp_decomp(const char *filename)
{
	char src_name[1024];
	char dst_name[1024];
	char line[256];
	unsigned char data;
	int i;

	strcpy(src_name, filename);
	strcat(src_name, ".hex");

	strcpy(dst_name, filename);
	strcat(dst_name, ".pkt");

	hex = fopen(src_name, "rt");
	if(hex == NULL)
	{
		fprintf(stderr, "Unable to open this file: %s\n", src_name);
		return -1;
	}

	logfile = fopen(dst_name, "wt");
	if(logfile == NULL)
	{
		fprintf(stderr, "Unable to open this file: %s\n", dst_name);
		fclose(hex);
		return -1;
	}

	if (fgets(line, sizeof(line), hex) == NULL) goto exit;
	if (fgets(line, sizeof(line), hex) == NULL) goto exit;
	if (fgets(line, sizeof(line), hex) == NULL) goto exit;

	fprintf(logfile, "TI packet decompiler for NSpire, version 1.0\n");

	while(hex_read(&data) != -1)
	{
		dusb_write(0, data);
	}

	fprintf(logfile, "() Service IDs found: ");
	for(i = 0; i < sif; i++) fprintf(logfile, "%04x ", sid_found[i]);
	fprintf(logfile, "\n");
	fprintf(logfile, "() Addresses found: ");
	for(i = 0; i < af; i++) fprintf(logfile, "%04x ", addr_found[i]);
	fprintf(logfile, "\n");

exit:
	fclose(logfile);
	fclose(hex);

	return 0;
}
Пример #3
0
/* mi_image: Create a mi_image from the contents of filename
 */
mi_image *mi_load_hexfile(char *filename)
{
  mi_image *img;
  hex_record *r;
  FILE *f;
  hex_file *hf;



  if(filename == NULL) {
    return NULL;
  }



  f=fopen(filename, "r");
  if(f == NULL) {
    return NULL;
  }



  hf=hex_open(f);
  if(hf == NULL) {
    fclose(f);
    return NULL;
  }



  img=malloc(sizeof(mi_image));
  if(img == NULL) {
    fclose(f);
    free(hf);
    return NULL;
  }



  /* These nulls may not be required, but make me feel safer when
   *  using free_image() on an error
   */
  img->program = NULL;
  img->id = NULL;
  img->config = NULL;
  img->devid = NULL;
  img->eeprom = NULL;



  img->program=mi_make_patch(MI_PROGRAM_BASE, MI_PROGRAM_TOP);
  img->id=mi_make_patch(MI_ID_BASE, MI_ID_TOP);
  img->config=mi_make_patch(MI_CONFIG_BASE, MI_CONFIG_TOP);
  img->devid=mi_make_patch(MI_DEVID_BASE, MI_DEVID_TOP);
  img->eeprom=mi_make_patch(MI_EEPROM_BASE, MI_EEPROM_TOP);

  if(img->program == NULL || img->id == NULL || img->config == NULL
     || img->devid == NULL || img->eeprom == NULL) {
    fclose(f);
    free(hf);
    mi_free_image(img);
    return NULL;
  }



  while((r=hex_read(hf))) {
    if(r->type == 0) {
      /*
      printf("file: %.2i@0x%.8X:\t", r->datlen, r->addr);
      for(i=0;i<r->datlen;i++) {
        printf("%.2x", r->data[i]);
      }
      printf("\n");
      */

      if(r->addr >= MI_PROGRAM_BASE && r->addr <= MI_PROGRAM_TOP) {
        //        printf("Program memory\n");
        mi_modify_patch(img->program, r->addr, r->datlen, r->data);
      }

      if(r->addr >= MI_ID_BASE && r->addr <= MI_ID_TOP) {
        //        printf("ID memory\n");
        mi_modify_patch(img->id, r->addr, r->datlen, r->data);
      }

      if(r->addr >= MI_CONFIG_BASE && r->addr <= MI_CONFIG_TOP) {
        //        printf("Config memory\n");
        mi_modify_patch(img->config, r->addr, r->datlen, r->data);
      }

      if(r->addr >= MI_DEVID_BASE && r->addr <= MI_DEVID_TOP) {
        //        printf("Devid memory\n");
        mi_modify_patch(img->devid, r->addr, r->datlen, r->data);
      }


    }
    free(r);
    //    printf("\n");
  }



  free(hf);
  fclose(f);
  return img;
}
Пример #4
0
int dusb_decomp(const char *filename)
{
	char src_name[1024];
	char dst_name[1024];
	char line[256];
	unsigned char data = 0;
	unsigned int i;

	snprintf(src_name, sizeof(src_name) - 1, "%s.hex", filename);
	src_name[sizeof(src_name) - 1] = 0;

	snprintf(dst_name, sizeof(dst_name) - 1, "%s.pkt", filename);
	dst_name[sizeof(dst_name) - 1] = 0;

	hex = fopen(src_name, "rt");
	if (hex == NULL)
	{
		fprintf(stderr, "Unable to open input file: %s\n", src_name);
		return -1;
	}

	logfile = fopen(dst_name, "wt");
	if (logfile == NULL)
	{
		fprintf(stderr, "Unable to open output file: %s\n", dst_name);
		fclose(hex);
		return -1;
	}

	fprintf(logfile, "TI packet decompiler for D-USB, version 1.0\n");

	// skip comments
	if (   fgets(line, sizeof(line), hex) == NULL
	    || fgets(line, sizeof(line), hex) == NULL
	    || fgets(line, sizeof(line), hex) == NULL)
	{
		goto exit;
	}

	while (hex_read(&data) != -1)
	{
		dusb_write(0, data);
	}

	fprintf(logfile, "() Packet types found: ");
	for (i = 0; i < ptf; i++)
	{
		fprintf(logfile, "%02x ", pkt_type_found[i]);
	}
	fprintf(logfile, "\n");
	fprintf(logfile, "{} Data codes found: ");
	for (i = 0; i < dcf; i++)
	{
		fprintf(logfile, "%04x ", data_code_found[i]);
	}
	fprintf(logfile, "\n");

exit:
	fclose(logfile);
	fclose(hex);

	return 0;
}