Esempio n. 1
0
//--------------------------------------------------------------------------
// Name: generate_symbols
// Desc:
//--------------------------------------------------------------------------
bool generate_symbols(const QString &filename, std::ostream &os) {

	QFile file(filename);
	if(file.open(QIODevice::ReadOnly)) {
#if QT_VERSION >= 0x040700
		os << qPrintable(QDateTime::currentDateTimeUtc().toString(Qt::ISODate)) << " +0000" << '\n';
#else
		os << qPrintable(QDateTime::currentDateTime().toUTC().toString(Qt::ISODate)) << "+0000" << '\n';
#endif
		const QByteArray md5 = edb::v1::get_file_md5(filename);
		os << md5.toHex().data() << ' ' << qPrintable(QFileInfo(filename).absoluteFilePath()) << '\n';

		if(auto file_ptr = reinterpret_cast<void *>(file.map(0, file.size(), QFile::NoOptions))) {
			if(is_elf64(file_ptr)) {
				process_symbols<elf64_model>(file_ptr, file.size(), os);
				return true;
			} else if(is_elf32(file_ptr)) {
				process_symbols<elf32_model>(file_ptr, file.size(), os);
				return true;
			} else {
				qDebug() << "unknown file type";
			}
		}
	}
	return false;
}
Esempio n. 2
0
elf32_phdr_t* read_elf32_phdrs(char* filename, elf32_ehdr_t* ehdr, elf32_phdr_t* phdrs)
{
  int fd = 0;
  int n = 0;
  int phdrs_sz = 0;

  if (!ehdr) {
    fprintf(stderr,"Empty ELF32 header!\n");
    return 0;
  }

  if (!is_elf32((char*)ehdr)) {
    fprintf(stderr,"Incorrect ELF32 header\n");
    return 0;
  }

  if (ehdr->e_phnum)
    phdrs_sz = ehdr->e_phnum*sizeof(elf32_phdr_t);
  else {
    fprintf(stderr,"Missing program headers\n");
    return 0;
  }

  if (!phdrs)
    phdrs = (elf32_phdr_t*)malloc(phdrs_sz);

  if (!phdrs) {
    perror(__FUNCTION__);
    return 0;
  }

  if ((fd = open(filename,O_RDONLY)) < 0) {
    perror(__FUNCTION__);
    return 0;
  }

  if(lseek(fd, ehdr->e_phoff, SEEK_SET) < 0) {
    perror(__FUNCTION__);
    free(phdrs);
    return 0;
  }

  if ((n = read(fd, phdrs, phdrs_sz)) < 0) {
    perror(__FUNCTION__);
    free(phdrs);
    close(fd);

    return 0;
  }

  if (n != phdrs_sz) {
    fprintf(stderr,"Wrong size: want %d but get %d bytes\n", phdrs_sz, n);
    free(phdrs);
  }

  close(fd);

  return phdrs;
}
Esempio n. 3
0
static void prep_kernel(unsigned long a1, unsigned long a2)
{
	int len;

	vmlinuz.addr = (unsigned long)_vmlinux_start;
	vmlinuz.size = (unsigned long)(_vmlinux_end - _vmlinux_start);

	/* gunzip the ELF header of the kernel */
	if (*(unsigned short *)vmlinuz.addr == 0x1f8b) {
		len = vmlinuz.size;
		gunzip(elfheader, sizeof(elfheader),
				(unsigned char *)vmlinuz.addr, &len);
	} else
		memcpy(elfheader, (const void *)vmlinuz.addr,
		       sizeof(elfheader));

	if (!is_elf64(elfheader) && !is_elf32(elfheader)) {
		printf("Error: not a valid PPC32 or PPC64 ELF file!\n\r");
		exit();
	}
	if (platform_ops.image_hdr)
		platform_ops.image_hdr(elfheader);

	/* We need to alloc the memsize plus the file offset since gzip
	 * will expand the header (file offset), then the kernel, then
	 * possible rubbish we don't care about. But the kernel bss must
	 * be claimed (it will be zero'd by the kernel itself)
	 */
	printf("Allocating 0x%lx bytes for kernel ...\n\r", vmlinux.memsize);
	vmlinux.addr = (unsigned long)malloc(vmlinux.memsize);
	if (vmlinux.addr == 0) {
		printf("Can't allocate memory for kernel image !\n\r");
		exit();
	}

	/*
	 * Now find the initrd
	 *
	 * First see if we have an image attached to us.  If so
	 * allocate memory for it and copy it there.
	 */
	initrd.size = (unsigned long)(_initrd_end - _initrd_start);
	initrd.memsize = initrd.size;
	if (initrd.size > 0) {
		printf("Allocating 0x%lx bytes for initrd ...\n\r",
		       initrd.size);
		initrd.addr = (unsigned long)malloc((u32)initrd.size);
		if (initrd.addr == 0) {
			printf("Can't allocate memory for initial "
					"ramdisk !\n\r");
			exit();
		}
		printf("initial ramdisk moving 0x%lx <- 0x%lx "
			"(0x%lx bytes)\n\r", initrd.addr,
			(unsigned long)_initrd_start, initrd.size);
		memmove((void *)initrd.addr, (void *)_initrd_start,
			initrd.size);
		printf("initrd head: 0x%lx\n\r",
				*((unsigned long *)initrd.addr));
	} else if (a2 != 0) {
		/* Otherwise, see if yaboot or another loader gave us an initrd */
		initrd.addr = a1;
		initrd.memsize = initrd.size = a2;
		printf("Using loader supplied initrd at 0x%lx (0x%lx bytes)\n\r",
		       initrd.addr, initrd.size);
	}

	/* Eventually gunzip the kernel */
	if (*(unsigned short *)vmlinuz.addr == 0x1f8b) {
		printf("gunzipping (0x%lx <- 0x%lx:0x%0lx)...",
		       vmlinux.addr, vmlinuz.addr, vmlinuz.addr+vmlinuz.size);
		len = vmlinuz.size;
		gunzip((void *)vmlinux.addr, vmlinux.memsize,
			(unsigned char *)vmlinuz.addr, &len);
		printf("done 0x%lx bytes\n\r", len);
	} else {
		memmove((void *)vmlinux.addr,(void *)vmlinuz.addr,
			vmlinuz.size);
	}

	/* Skip over the ELF header */
#ifdef DEBUG
	printf("... skipping 0x%lx bytes of ELF header\n\r",
			elfoffset);
#endif
	vmlinux.addr += elfoffset;

	flush_cache((void *)vmlinux.addr, vmlinux.size);
}
Esempio n. 4
0
void start(unsigned long a1, unsigned long a2, void *promptr, void *sp)
{
	int len;
	kernel_entry_t kernel_entry;

	memset(__bss_start, 0, _end - __bss_start);

	prom = (int (*)(void *)) promptr;
	chosen_handle = finddevice("/chosen");
	if (chosen_handle == (void *) -1)
		exit();
	if (getprop(chosen_handle, "stdout", &stdout, sizeof(stdout)) != 4)
		exit();

	printf("\n\rzImage starting: loaded at 0x%p (sp: 0x%p)\n\r", _start, sp);

	/*
	 * The first available claim_base must be above the end of the
	 * the loaded kernel wrapper file (_start to _end includes the
	 * initrd image if it is present) and rounded up to a nice
	 * 1 MB boundary for good measure.
	 */

	claim_base = _ALIGN_UP((unsigned long)_end, ONE_MB);

	vmlinuz.addr = (unsigned long)_vmlinux_start;
	vmlinuz.size = (unsigned long)(_vmlinux_end - _vmlinux_start);

	/* gunzip the ELF header of the kernel */
	if (*(unsigned short *)vmlinuz.addr == 0x1f8b) {
		len = vmlinuz.size;
		gunzip(elfheader, sizeof(elfheader),
				(unsigned char *)vmlinuz.addr, &len);
	} else
		memcpy(elfheader, (const void *)vmlinuz.addr, sizeof(elfheader));

	if (!is_elf64(elfheader) && !is_elf32(elfheader)) {
		printf("Error: not a valid PPC32 or PPC64 ELF file!\n\r");
		exit();
	}

	/* We need to claim the memsize plus the file offset since gzip
	 * will expand the header (file offset), then the kernel, then
	 * possible rubbish we don't care about. But the kernel bss must
	 * be claimed (it will be zero'd by the kernel itself)
	 */
	printf("Allocating 0x%lx bytes for kernel ...\n\r", vmlinux.memsize);
	vmlinux.addr = try_claim(vmlinux.memsize);
	if (vmlinux.addr == 0) {
		printf("Can't allocate memory for kernel image !\n\r");
		exit();
	}

	/*
	 * Now we try to claim memory for the initrd (and copy it there)
	 */
	initrd.size = (unsigned long)(_initrd_end - _initrd_start);
	initrd.memsize = initrd.size;
	if ( initrd.size > 0 ) {
		printf("Allocating 0x%lx bytes for initrd ...\n\r", initrd.size);
		initrd.addr = try_claim(initrd.size);
		if (initrd.addr == 0) {
			printf("Can't allocate memory for initial ramdisk !\n\r");
			exit();
		}
		a1 = initrd.addr;
		a2 = initrd.size;
		printf("initial ramdisk moving 0x%lx <- 0x%lx (0x%lx bytes)\n\r",
		       initrd.addr, (unsigned long)_initrd_start, initrd.size);
		memmove((void *)initrd.addr, (void *)_initrd_start, initrd.size);
		printf("initrd head: 0x%lx\n\r", *((unsigned long *)initrd.addr));
	}

	/* Eventually gunzip the kernel */
	if (*(unsigned short *)vmlinuz.addr == 0x1f8b) {
		printf("gunzipping (0x%lx <- 0x%lx:0x%0lx)...",
		       vmlinux.addr, vmlinuz.addr, vmlinuz.addr+vmlinuz.size);
		len = vmlinuz.size;
		gunzip((void *)vmlinux.addr, vmlinux.memsize,
			(unsigned char *)vmlinuz.addr, &len);
		printf("done 0x%lx bytes\n\r", len);
	} else {
		memmove((void *)vmlinux.addr,(void *)vmlinuz.addr,vmlinuz.size);
	}

	export_cmdline(chosen_handle);

	/* Skip over the ELF header */
#ifdef DEBUG
	printf("... skipping 0x%lx bytes of ELF header\n\r",
			elfoffset);
#endif
	vmlinux.addr += elfoffset;

	flush_cache((void *)vmlinux.addr, vmlinux.size);

	kernel_entry = (kernel_entry_t)vmlinux.addr;
#ifdef DEBUG
	printf( "kernel:\n\r"
		"        entry addr = 0x%lx\n\r"
		"        a1         = 0x%lx,\n\r"
		"        a2         = 0x%lx,\n\r"
		"        prom       = 0x%lx,\n\r"
		"        bi_recs    = 0x%lx,\n\r",
		(unsigned long)kernel_entry, a1, a2,
		(unsigned long)prom, NULL);
#endif

	kernel_entry(a1, a2, prom, NULL);

	printf("Error: Linux kernel returned to zImage bootloader!\n\r");

	exit();
}