Пример #1
0
static void
exec_files_info (struct target_ops *t)
{
  print_section_info (t, exec_bfd);

  if (vmap)
    {
      struct vmap *vp;

      printf_unfiltered (_("\tMapping info for file `%s'.\n"), vmap->name);
      printf_unfiltered ("\t  %*s   %*s   %*s   %*s %8.8s %s\n",
			 strlen_paddr (), "tstart",
			 strlen_paddr (), "tend",
			 strlen_paddr (), "dstart",
			 strlen_paddr (), "dend",
			 "section",
			 "file(member)");

      for (vp = vmap; vp; vp = vp->nxt)
	printf_unfiltered ("\t0x%s 0x%s 0x%s 0x%s %s%s%s%s\n",
			   paddr (vp->tstart),
			   paddr (vp->tend),
			   paddr (vp->dstart),
			   paddr (vp->dend),
			   vp->name,
			   *vp->member ? "(" : "", vp->member,
			   *vp->member ? ")" : "");
    }
}
Пример #2
0
static void
core_files_info (struct target_ops *t)
{
  print_section_info (core_data, core_bfd);
}
Пример #3
0
void
core_target::files_info ()
{
  print_section_info (&m_core_section_table, core_bfd);
}
Пример #4
0
int main (int argc, char **argv)
{
	int o;
	FILE *f = NULL;
	char *filename = NULL;
	const char *location = NULL;
	int extract = 0;
	char magic[MAGIC_LEN];

	while ((o = getopt(argc, argv, "hixC:")) != -1)
	{
		switch (o) {
		case 'i':
			extract = 0;
			break;
		case 'x':
			extract = 1;
			break;
		case 'C':
			location = optarg;
			break;
		case 'h':
			usage(argv[0]);
			return EXIT_SUCCESS;
		default:
			printf("ERROR: unkown argument '%c'\n\n", o);
			usage(argv[0]);
			return EXIT_FAILURE;
		}
	}

	if (optind >= argc) {
		printf("ERROR: no image-file\n\n");
		usage(argv[0]);
		return EXIT_FAILURE;
	}

	filename = strdup(argv[optind]);
	if (filename == NULL) {
		printf("ERROR: %s\n", strerror(errno));
		return EXIT_FAILURE;
	}

	if ((f = fopen(filename, "r")) == NULL) {
		printf("ERROR: Cannot open image file %s\n", filename);
		return EXIT_FAILURE;
	}

	if (location) {
		DIR *d = NULL;

		if (strlen(location) > (FILE_PATH_MAXLEN - FILE_SECTION_MAXLEN)) {
			printf("ERROR: location path too long\n");
			goto fail;
		}

		d = opendir(location);
		if (!d) {
			printf("ERROR: location dir: %s\n", strerror(errno));
			goto fail;
		}
		closedir(d);
	}

	printf("\nImage file: %s\n\n", filename);

	if (fread(magic, MAGIC_LEN, 1, f) != 1) {
		printf("ERROR: %s\n", strerror(errno));
		goto fail;
	}

	if (memcmp(magic, MAGIC_HEADER, 4) == 0) {
		struct header h;

		if (fread(&h, sizeof(struct header), 1, f) != 1) {
			printf("ERROR: %s\n", strerror(errno));
			goto fail;
		}

		if (!extract) {
			print_header_info(&h);
			printf("\n");
		}

	} else {
		goto fail;
	}

	while (!feof(f)) {

		if (fread(magic, MAGIC_LEN, 1, f) != 1) {
			printf("ERROR: %s\n", strerror(errno));
			goto fail;
		}

		if (memcmp(magic, MAGIC_END, 4) == 0) {

			struct signature s;

			if (fread(&s, sizeof(struct signature), 1, f) != 1) {
				printf("ERROR: %s\n", strerror(errno));
				goto fail;
			}

			if (!extract) {
				printf("Sign CRC: 0x%.8x\n", ntohl(s.crc));
				printf("\n");
			}

			break;
		} else { /* Assume a section */
			struct section s;

			if (fread(&s, sizeof(struct section), 1, f) < 1) {
				printf("ERROR: %s\n", strerror(errno));
				goto fail;
			}

			if (!extract) {
				struct section_crc scrc;

				print_section_info(&s);

				fseek(f, ntohl(s.data_size), SEEK_CUR);

				if (fread(&scrc, sizeof(struct section_crc), 1, f) != 1) {
					printf("ERROR: %s\n", strerror(errno));
					goto fail;
				}

				printf("Section CRC: 0x%.8x\n", ntohl(scrc.crc));
				printf("\n");
			} else {
				char *data = (char *)malloc(ntohl(s.data_size));
				if (data == NULL) {
					printf("ERROR: %s\n", strerror(errno));
					goto fail;
				}

				if (fread(data, ntohl(s.data_size), 1, f) != 1) {
					printf("ERROR: %s\n", strerror(errno));
					goto fail;
				}

				if (write_section(&s, (const char *)data, location) == -1) {
					goto fail;
				}

				free(data);

				fseek(f, sizeof(struct section_crc), SEEK_CUR);
			}

		}
	}

	fclose(f);
	free(filename);

	return EXIT_SUCCESS;

fail:
	fclose(f);
	free(filename);
	return EXIT_FAILURE;
}