Exemple #1
0
void ActionLaunchElf(const char * filename) {
    char * elf = NULL;
    // read file by chunk
    FILE * f = fopen(filename, "rb");
    int size = 0;
    int chunk = 65536;
    float pct = 0.0f;

    //FileIsElf(filename);

    if (f) {
        // get the file size
        fseek(f, 0, SEEK_END);
        size = ftell(f);
        // 0
        fseek(f, 0, SEEK_SET);

        if (size == 0)
            return;


        elf = (char*) malloc(size);

        for (int i = 0; i < size; i += fread(elf + i, 1, chunk, f)) {
            pct = ((float) i / (float) (size));
            App.SetProgressValue(pct);
        }
        fclose(f);

        // read elf header ...
        unsigned int elf_header = 0x7F454C46;
        if (memcmp(&elf_header, elf, 4) == 0) {
            elf_runFromMemory(elf, size);
        } else {

            App.Alert("Not a valid elf !!");
        }

    }
    fclose(f);
}
Exemple #2
0
int main(){
	// Init console and video
	videoInit();

	// Create FILE type for our elf to load from USB to memory address
	FILE *elfFile = fopen("uda:/xenon.elf32", "rb");

	// Get the size of the elf
	fseek(elfFile, 0, SEEK_END);
	elfSize = ftell(elfFile);
	rewind(elfFile);

	/* Now that we have all the info we need about the file,
	   we can read the executeable into the memory address
	   we defined at the top of the file.
	*/
	fread(&elfPosition[elfSize], 1, elfSize, elfFile);

	// Execute the elf from the memory address
	elf_runFromMemory(elfPosition, elfSize);
}