Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
	if (argc < 3) {
		usage();
		goto exit_failure;
	}

	vita_imports_t *imports = vita_imports_load(argv[1], 1);

	if (imports == NULL) {
		goto exit_failure;
	}

	if (chdir(argv[2])) {
		perror(argv[2]);
		goto exit_failure;
	}

	if (!generate_assembly(imports)) {
		fprintf(stderr, "Error generating the assembly file\n");
		goto exit_failure;
	}

	if (!generate_makefile(imports)) {
		fprintf(stderr, "Error generating the assembly makefile\n");
		goto exit_failure;
	}

	vita_imports_free(imports);

	return EXIT_SUCCESS;
exit_failure:
	return EXIT_FAILURE;
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
	if (argc < 3) {
		usage();
		goto exit_failure;
	}

	int imports_count = argc - 2;

	vita_imports_t **imports = malloc(sizeof(vita_imports_t*) * imports_count);

	int i;
	for (i = 0; i < imports_count; i++)
	{
		vita_imports_t *imp = vita_imports_load(argv[i + 1], 1);

		if (imp == NULL) {
			goto exit_failure;
		}

		imports[i] = imp;
	}

#if defined(_WIN32) && !defined(__CYGWIN__)
	mkdir(argv[argc - 1]);
#else
	mkdir(argv[argc - 1], 0777); // create directory if it doesn't exist
#endif

	if (chdir(argv[argc - 1])) {
		perror(argv[argc - 1]);
		goto exit_failure;
	}

	if (!generate_assembly(imports, imports_count)) {
		fprintf(stderr, "Error generating the assembly file\n");
		goto exit_failure;
	}

	if (!generate_makefile(imports, imports_count)) {
		fprintf(stderr, "Error generating the assembly makefile\n");
		goto exit_failure;
	}

	for (i = 0; i < imports_count; i++)
	{
		vita_imports_free(imports[i]);
	}
	
	free(imports);

	return EXIT_SUCCESS;
exit_failure:
	return EXIT_FAILURE;
}
Ejemplo n.º 3
0
int main(int argc, char *argv[])
{
	vita_elf_t *ve;
	vita_imports_t **imports;
	sce_module_info_t *module_info;
	sce_section_sizes_t section_sizes;
	void *encoded_modinfo;
	vita_elf_rela_table_t rtable = {};
	int imports_count;

	int status = EXIT_SUCCESS;

	if (argc < 3)
		errx(EXIT_FAILURE,"Usage: vita-elf-create input-elf output-elf [extra.json ...]");

	if ((ve = vita_elf_load(argv[1])) == NULL)
		return EXIT_FAILURE;

	if (!(imports = load_imports(argc, argv, &imports_count)))
		return EXIT_FAILURE;

	if (!vita_elf_lookup_imports(ve, imports, imports_count))
		status = EXIT_FAILURE;

	if (ve->fstubs_ndx) {
		printf("Function stubs in section %d:\n", ve->fstubs_ndx);
		print_stubs(ve->fstubs, ve->num_fstubs);
	}
	if (ve->vstubs_ndx) {
		printf("Variable stubs in section %d:\n", ve->vstubs_ndx);
		print_stubs(ve->vstubs, ve->num_vstubs);
	}

	printf("Relocations:\n");
	list_rels(ve);

	printf("Segments:\n");
	list_segments(ve);

	module_info = sce_elf_module_info_create(ve);

	int total_size = sce_elf_module_info_get_size(module_info, &section_sizes);
	int curpos = 0;
	printf("Total SCE data size: %d / %x\n", total_size, total_size);
#define PRINTSEC(name) printf("  .%.*s.%s: %d (%x @ %x)\n", (int)strcspn(#name,"_"), #name, strchr(#name,'_')+1, section_sizes.name, section_sizes.name, curpos+ve->segments[0].vaddr+ve->segments[0].memsz); curpos += section_sizes.name
	PRINTSEC(sceModuleInfo_rodata);
	PRINTSEC(sceLib_ent);
	PRINTSEC(sceExport_rodata);
	PRINTSEC(sceLib_stubs);
	PRINTSEC(sceImport_rodata);
	PRINTSEC(sceFNID_rodata);
	PRINTSEC(sceFStub_rodata);
	PRINTSEC(sceVNID_rodata);
	PRINTSEC(sceVStub_rodata);

	strncpy(module_info->name, argv[1], sizeof(module_info->name) - 1);

	encoded_modinfo = sce_elf_module_info_encode(
			module_info, ve, &section_sizes, &rtable);

	printf("Relocations from encoded modinfo:\n");
	print_rtable(&rtable);

	FILE *outfile;
	Elf *dest;
	ASSERT(dest = elf_utils_copy_to_file(argv[2], ve->elf, &outfile));
	ASSERT(elf_utils_duplicate_shstrtab(dest));
	ASSERT(sce_elf_discard_invalid_relocs(ve, ve->rela_tables));
	ASSERT(sce_elf_write_module_info(dest, ve, &section_sizes, encoded_modinfo));
	rtable.next = ve->rela_tables;
	ASSERT(sce_elf_write_rela_sections(dest, ve, &rtable));
	ASSERT(sce_elf_rewrite_stubs(dest, ve));
	ELF_ASSERT(elf_update(dest, ELF_C_WRITE) >= 0);
	elf_end(dest);
	ASSERT(sce_elf_set_headers(outfile, ve));
	fclose(outfile);


	sce_elf_module_info_free(module_info);
	vita_elf_free(ve);

	int i;
	for (i = 0; i < imports_count; i++) {
		vita_imports_free(imports[i]);
	}

	free(imports);

	return status;
failure:
	return EXIT_FAILURE;
}