コード例 #1
0
ファイル: elf.c プロジェクト: Q-Taro/BootCode
/* main ---------------------------------------------------------------------*/
int
main(int argc, char* argv[])
{
	int		fd_s, fd_d;
	int		i;
	struct stat	s;	
	Elf32_Ehdr	e_eh;
	Elf32_Phdr	e_ph[32];
	Elf32_Addr	addr;
	int		size;

	if (argc < 3) {
		fprintf(stderr, "elf error 0\n");
		exit(1);
	}
	
	if (((fd_s = open(argv[1], O_RDWR)) < 0) ||
			(fd_d = open(argv[2], O_RDWR | O_CREAT)) < 0) {
		fprintf(stderr, "elf error 1\n");
		exit(1);
	}

	elf(fd_s, fd_d, PT_LOAD, PF_R | PF_X, &addr, &size, 0);
	elf(fd_s, fd_d, PT_LOAD, PF_R | PF_W, &addr, &size, 1);
	exit(0);
}
コード例 #2
0
ファイル: dmanager.cpp プロジェクト: killbug2004/dDeflect
bool DManager::__secure_elf(const QByteArray &data, const DManager::secured_file_info &sfi) {
  ELF elf(data);

  if(elf.is_x64()) {
      /*
      ss = test_one_ex<Registers_x64>(&elf, type, method, handler, x, obfuscate);
      if (ss == SecuredState::NONCOMPATIBLE)
        return true;
      if (ss != SecuredState::SECURED)
        return false;
      */
      // TODO: add error codes
      return __secure_elf<Registers_x64>(&elf, sfi);
  }


  if(elf.is_x86()) {
      /*
      ss = test_one_ex<Registers_x86>(&elf, type, method, handler, x, obfuscate);
      if (ss == SecuredState::NONCOMPATIBLE)
        return true;
      if (ss != SecuredState::SECURED)
        return false;
      */
      return __secure_elf<Registers_x86>(&elf, sfi);
  }


  LOG_ERROR("Elf architecture is not superted");

  return false;
}
コード例 #3
0
ファイル: vitalink.cpp プロジェクト: xyzz/vitalink
void fixup_elf(int argc, char *argv[]) {
	try {
		Elf elf(argv[2]);
		elf.FixupTopEnd();
		elf.Write(argv[2]);
	} catch (const std::runtime_error &e) {
		std::cerr << e.what() << std::endl;
		exit(1);
	}
}
コード例 #4
0
ファイル: task_entry.cpp プロジェクト: shockkolate/shockk-os
void task_entry(const char *exe_name) {
	__asm__ ("sti");

	screen_print("spawned new task\n");
	screen_print("loading ");
	screen_print(exe_name);
	screen_put('\n');

	const char *paths[] = {"bin", exe_name};
	auto mData = _kernel_state.fs.GetInode(2, paths);
	if(mData.IsNothing()) { kernel_panic("failed to get inode"); }
	auto data = mData.FromJust();

	_kernel_state.pager->Enable(_kernel_state.task->context);
	ELF elf(data);

	user_enter(elf.entry(), &_kernel_state.task->stack[PAGE_ALLOCATOR_PAGE_SIZE * Task::STACK_PAGES]);

	for(;;) { __asm__ ("hlt"); } // unreachable
}
コード例 #5
0
ファイル: santa.c プロジェクト: lubos734/IOS-projekt-2
/**hlavni funkce main**/
int main(int argc, char *argv[])
{
    if((soubor=fopen("santa.out", "w")) == NULL)
    {
        chyba(CHYBA_OTEV_SOU);
        return 2;
    }

    if((argc==2) && (strcmp("--help", argv[1]) == 0))
    {
        napoveda();
        return 0;
    }

/**volani argumentu**/
    arg(argc, argv);
    tmp_elf = cislo_elfa;

 /**********volani vytvoreni sdilene pameti******************/
    sdilena_pamet();
/***********volani vytvoreni semafaoru*****/
    semafory();

/********vytvoreni santy a elfu********/


    for(int i=0; i < tmp_elf + 1; i++)
	{
		switch(fork())
		{
			case 0: //dite
				if(i==0) // prvni dite == santa
				{
					santa();
					return 0;
				}
				else       // ostatni jsou elfove
				{
					elf_id=i;
					elf();
					return 0;
				}
				break;

			case -1:
				chyba(CHYBA_FORK);
				mazani_sem();
				mazani_pameti();
				return 2;
				break;

			default: //rodic

				break;
		}
	}

    for(int i = 0; i < tmp_elf + 1; i++)
    {
        wait(NULL);
    }
    mazani_sem();
    mazani_pameti();
    zav_sou();
    return 0;
}
コード例 #6
0
void Process::
start(es::File* file, const char* argument)
{
    Monitor::Synchronized method(monitor);

    // XXX Check no elf file is set yet.

    const unsigned stackSize = 2*1024*1024;
    Thread* thread(createThread(stackSize));
    ASSERT(thread);
    syscallTable[1].set(thread, es::Thread::iid(), true);   // just for reference counting

    Elf elf(file);

    if (elf.getType() != ET_EXEC)
    {
        esReport("Process::%s - the specified file is not an executable file.\n", __func__);
        return;
    }

    Handle<es::Pageable> pageable(file->getPageable());
    if (!pageable)
    {
        esReport("Process::%s - the specified file is not mappable file.\n", __func__);
        return;
    }

    for (int i(0); i < elf.getPhnum(); ++i)
    {
        Elf32_Phdr phdr;

        if (!elf.getPhdr(i, &phdr))
        {
            return;
        }

        switch (phdr.p_type)
        {
        case PT_TLS:
            // Make spece for TCB
#ifdef VERBOSE
            Elf::dumpPhdr(&phdr);
#endif  // VERBOSE
            tlsImage = (void*) phdr.p_vaddr;
            tlsImageSize = phdr.p_filesz;
            tlsSize = phdr.p_memsz;
            tlsAlign = phdr.p_align;
            break;
        case PT_LOAD:
            // Map PT_LOAD segment
            unsigned prot(es::CurrentProcess::PROT_NONE);
            if (phdr.p_flags & PF_X)
            {
                prot |= es::CurrentProcess::PROT_EXEC;
            }
            if (phdr.p_flags & PF_W)
            {
                prot |= es::CurrentProcess::PROT_WRITE;
            }
            if (phdr.p_flags & PF_R)
            {
                prot |= es::CurrentProcess::PROT_READ;
            }
            if (prot == es::CurrentProcess::PROT_NONE)
            {
                continue;
            }

            unsigned flags(es::CurrentProcess::MAP_FIXED);
            if (phdr.p_flags & PF_W)
            {
                flags |= es::CurrentProcess::MAP_PRIVATE;
            }
            else
            {
                flags |= es::CurrentProcess::MAP_SHARED;
            }

            if (phdr.p_flags & PF_W)
            {
                if ((unsigned long) end < phdr.p_vaddr + phdr.p_memsz)
                {
                    end = (void*) (phdr.p_vaddr + phdr.p_memsz);
                }
            }

            void* addr = map((void*) phdr.p_vaddr, phdr.p_memsz, prot, flags,
                             pageable, phdr.p_offset,
                             phdr.p_filesz, USER_MIN, USER_MAX);
            break;
        }
    }

    char name[32];
    file->getName(name, sizeof name);
    esReport("start %p %s from %p\n", this, name, elf.getEntry());

#ifdef VERBOSE
    dump();
    esReport("break: %p\n", end);
#endif // VERBOSE

    // Copy-in the argument.
    Ureg* ureg(static_cast<Ureg*>(thread->param));
    char* args = (char*) &ureg[1];
    *args++ = '\0'; // sentinel
    if (argument)
    {
        size_t len = strlen(argument);
        memmove(args, argument, len + 1);   // XXX over run check
    }

    thread->entry(elf.getEntry());
    thread->start();
}
コード例 #7
0
ファイル: main.c プロジェクト: doniexun/compiler-18
int main(int argc, const char *argv[])
{
	PgmSP ast; /* abstract syntax tree */
	char pgm[120] = "input.pas";
	char *codef;
	char *listingf;
	char *stablistf;
	char *asmlistf;
	char *astlistf;
	int fnlen;
	if (argc < 2) {
		fprintf(stdout, "usage: ./compiler <filename>\n");
		exit(1);
	}
	strcpy(pgm,argv[argc-1]);
	source = fopen(pgm, "r");
	if (source == NULL) {
		fprintf(stderr, "File %s not found\n", pgm);
		exit(1);
	}
	if (strchr(pgm, '.') == NULL) {
		strcat(pgm, ".pas");
	}
	fnlen = strcspn(pgm, ".");

	codef = (char *)calloc(fnlen + 6, sizeof(char));
	strncpy(codef, pgm, fnlen);
	strcat(codef, ".qaud");
	code = fopen(codef, "w");
	if (code == NULL) {
		fprintf(stderr, "Unable to open %s\n", codef);
		exit(1);
	}

	listingf = (char *)calloc(fnlen + 5, sizeof(char));
	strncpy(listingf, pgm, fnlen);
	strcat(listingf, ".lst");
	listing = fopen(listingf, "w");
	if (listing == NULL) {
		fprintf(stderr, "Unable to open %s\n", listingf);
		exit(1);
	}

	asmlistf = (char *)calloc(fnlen + 5, sizeof(char));
	strncpy(asmlistf, pgm, fnlen);
	strcat(asmlistf, ".asm");
	asmlist = fopen(asmlistf, "w");
	if (asmlist == NULL) {
		fprintf(stderr, "Unable to open %s\n", asmlistf);
		exit(1);
	}

	astlistf = (char *)calloc(fnlen + 5, sizeof(char));
	strncpy(astlistf, pgm, fnlen);
	strcat(astlistf, ".xml");
	astlist = fopen(astlistf, "w");
	if (astlist == NULL) {
		fprintf(stderr, "Unable to open %s\n", astlistf);
		exit(1);
	}

	stablistf = (char *)calloc(fnlen + 5, sizeof(char));
	strncpy(stablistf, pgm, fnlen);
	strcat(stablistf, ".stb");
	stablist = fopen(stablistf, "w");
	if (stablist == NULL) {
		fprintf(stderr, "Unable to open %s\n", stablistf);
		exit(1);
	}

	if (argv[argc-2][0] == 'd') {
		listing = stdout;
		code = stdout;
		stablist = stdout;
	}
	errlist = stderr;
	tiplist = stderr;
	if (runlevel > 2) {
		ast = parse();
	} else {
		exit(1);
	}
	if (runlevel > 1) {
		analyse(ast);
		coder(ast);
	} else {
		exit(1);
	}
	if (runlevel > 0) {
		elf();
		make_fgraph();
	} else {
		exit(1);
	}
	// add optimization
	fclose(source);
	fclose(code);
	fclose(asmlist);
	fclose(astlist);
	fclose(listing);
	fclose(stablist);
	fclose(errlist);
	fclose(tiplist);
	return 0;
}
コード例 #8
0
ファイル: readself.c プロジェクト: Joonie86/vitatool
void readself(){
	printf("\nReading...\n");
	u32 offset=0;
	u32 magic               = be32(self);         /* 53434500 = SCE\0 */
	offset += sizeof(u32);
	u32 version             = le32(self+offset);  /* header version 3*/
	offset += sizeof(u32);
	u16 sdk_type            = le16(self+offset);  /* SDK type */
	offset += sizeof(u16);
	u16 header_type         = le16(self+offset);  /* 1 self, 2 unknown, 3 pkg */
	offset += sizeof(u16);
	u32 metadata_offset     = le32(self+offset);  /* metadata offset */
	offset += sizeof(u32);
	u64 header_len          = le64(self+offset);  /* self header length */
	offset += sizeof(u64);
	u64 elf_filesize        = le64(self+offset);  /* ELF file length */
	offset += sizeof(u64);
	u64 self_filesize       = le64(self+offset);  /* SELF file length */
	offset += sizeof(u64);
	u64 unknown1            = le64(self+offset);  /* UNKNOWN */
	offset += sizeof(u64);
	u64 self_offset         = le64(self+offset);  /* Self Offset */
	offset += sizeof(u64);
	u64 appinfo_offset      = le64(self+offset);  /* app info offset */
	offset += sizeof(u64);
	u64 elf_offset          = le64(self+offset);  /* ELF #1 offset */
	offset += sizeof(u64);
	u64 phdr_offset         = le64(self+offset);  /* program header offset */
	offset += sizeof(u64);
	u64 shdr_offset         = le64(self+offset);  /* section header offset */
	offset += sizeof(u64);
	u64 section_info_offset = le64(self+offset);  /* section info offset */
	offset += sizeof(u64);
	u64 sceversion_offset   = le64(self+offset);  /* version offset */
	offset += sizeof(u64);
	u64 controlinfo_offset  = le64(self+offset);  /* control info offset */
	offset += sizeof(u64);
	u64 controlinfo_size    = le64(self+offset);  /* control info size */
	offset += sizeof(u64);


	if(magic!=HDR)
		fail("\nERROR! Not a PlayStation Vita Self File (Magic: %08x)",magic);

	if(header_type!=1){
		char* HType;
		if(header_type==2)
			HType = "rvk";
		else if(header_type==3)
			HType = "pkg";
		else if(header_type==4)
			HType = "spp";
		else
			HType = "Unknown";

		fail("\nERROR! Not a PlayStation Vita Self File (Type : %08x)\n"
		       "                                               [%s]",header_type,HType);
	}

	printf("Magic                   0x%08x\n",magic);
	printf("Version                 0x%08x\n",version);
	printf("SDK Type                0x%08x\n",sdk_type);
	printf("Header Type             0x%08x\n",header_type);
	printf("Metadata offset         0x%08x\n",metadata_offset);
	printf("Header Length           0x%016lx (%lu Bytes)\n",header_len,header_len);
	printf("Elf Size                0x%016lx (%lu Bytes)\n",elf_filesize,elf_filesize);
	printf("Self Size               0x%016lx (%lu Bytes)\n",self_filesize,self_filesize);
	printf("Unknown_1               0x%016lx\n",unknown1);
	printf("Self Offset             0x%016lx\n",self_offset);
	printf("Application Info Offset 0x%016lx\n",appinfo_offset);
	printf("Elf Offset              0x%016lx\n",elf_offset);
	printf("Program hdr  Offset     0x%016lx\n",phdr_offset);
	printf("Section hdr  Offset     0x%016lx\n",shdr_offset);
	printf("Section Info Offset     0x%016lx\n",section_info_offset);
	printf("Version Offset          0x%016lx\n",sceversion_offset);
	printf("Control Info Offset     0x%016lx\n",controlinfo_offset);
	printf("Control Info Size       0x%016lx (%lu Bytes)\n",controlinfo_size,controlinfo_size);
	
	app_info(appinfo_offset);
	elf(elf_offset);
	program_hdr(phdr_offset);
	section_hdr(shdr_offset);
	sce_version(sceversion_offset);
	control_information(controlinfo_offset);

	printf("\nDone\n");
}