Results 1 to 4 of 4

Thread: What's wrong with this DOL launcher?

  1. #1
    New Member
    Join Date
    Jul 2010
    Posts
    17
    Thanks
    1
    Thanked 1 Time in 1 Post

    What's wrong with this DOL launcher?

    Hey, all!

    I'm using libwiigui to sort of create an "onboard operating system", but right now, I'm having trouble with launching DOLs.

    I tried to launch a DOL...and the bg music on libwiigui started "lagging", like
    ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ

    I don't really know how to explain it. O_O
    I also need the console to debug my load function, so I'll know what's wrong.

    Is there a problem with my code?
    Or do I have to "exit" libwiigui?
    dol.c
    PHP Code:
     /*
      * @author: Tonyyyyyyy
      * 
      * @summary:  This file provides functions for launching DOLs.
      * @origin: Based off of *cough* ripped off of *cough* geckoloader.
      *
      * @date: 7.19.2010
     */
     
     #include "dol.h"

    // This is from geckoloader...
    // this code was contributed by shagkur of the devkitpro team, thx!

    typedef struct _dolheader {
        
    u32 text_pos[7];
        
    u32 data_pos[11];
        
    u32 text_start[7];
        
    u32 data_start[11];
        
    u32 text_size[7];
        
    u32 data_size[11];
        
    u32 bss_start;
        
    u32 bss_size;
        
    u32 entry_point;
    dolheader;

    u32 load_dol_image (void *dolstart) {
        
    u32 i;
        
    dolheader *dolfile;

        if (
    dolstart) {
            
    dolfile = (dolheader *) dolstart;
            for (
    07i++) {
                if ((!
    dolfile->text_size[i]) || (dolfile->text_start[i] < 0x100))
                    continue;
    \
                
    ICInvalidateRange ((void *) dolfile->text_start[i],
                                                        
    dolfile->text_size[i]);
                
    memmove ((void *) dolfile->text_start[i],
                                     
    dolstart+dolfile->text_pos[i],
                                     
    dolfile->text_size[i]);
            }

            for(
    011i++) {
                if ((!
    dolfile->data_size[i]) ||
                                (
    dolfile->data_start[i] < 0x100))
                                    continue;

                
    memmove ((void*) dolfile->data_start[i],
                                     
    dolstart+dolfile->data_pos[i],
                                     
    dolfile->data_size[i]);
                
    DCFlushRangeNoSync ((void *) dolfile->data_start[i],
                                                
    dolfile->data_size[i]);
            }
            
            
    memset ((void *) dolfile->bss_start0dolfile->bss_size);
            
    DCFlushRange((void *) dolfile->bss_startdolfile->bss_size);

            return 
    dolfile->entry_point;
        }

        return 
    0;

    launch.cpp
    PHP Code:
    #include "launch.h"

    //extern void __exception_closeall();
    //extern s32 __IOS_ShutdownSubsystems();

    s32 getImageType(void addr)
    {
        
    Elf32_Ehdr *ehdr/* Elf header structure pointer */

        
    ehdr = (Elf32_Ehdr *) addr;

        if (!
    IS_ELF (*ehdr))
            return 
    0;

        if (
    ehdr->e_type != ET_EXEC)
            return -
    1;

        if (
    ehdr->e_machine != EM_PPC)
            return -
    1;

        return 
    1;
    }

    int launch(char locdir[999], char filname[13])
    {
    /*
        //Set this...
        unsigned int i;
        
        for(i = 0; i < strlen(locdir); i++)
        {
            if((i+1) != strlen(locdir))
                locdir[i] = locdir[i +1];
            else
                locdir[i] = '/';
        }
        printf("%s", locdir);
        sleep(5000);*/
        //Variables
        /*
        FATFS ffs;
        DIR appdir;
        
        char filename[50+1];
        char thefile[1][50];
        FILINFO finfo;
        FIL fp;
        
        WORD bytes_read;
        u32 bytes_read_total;
        u8 *data = (u8 *)0x92000000;
        */
        
    s32 res;
        
    u32 level;
        
        if(!
    fatInitDefault())
        {
            
    //Error handler here...
        
    }
        
        
    //ELF/DOL buffer
        
    void buffer;
        
    //Entry point
        
    void (*ep)();
        
        
    char formatted[999];
        
        
    sprintf(formatted"%s/%s"locdirfilname);
        
        
    //Mount FAT FS
        
        //if(f_mount(0, &ffs) != FR_OK)
            //return -1;
            
        //res = f_opendir(&appdir, locdir);
        
        //if(res != FR_OK)
            //return -1;
            
        
    FILE inputFile;
        
        
    inputFile fopen(formatted"rb");
        
    /*    
        memset(&finfo, 0, sizeof(finfo));
        f_readdir(&appdir, &finfo);
        
        while(strlen(finfo.fname) != 0)
        {
            if(strtoupper(finfo.fname) == strtoupper(filname))
            {
                memcpy(thefile[0], finfo.fname, strlen(finfo.fname));
                printf(thefile[0]);
                sleep(5000);
            }
            
            f_readdir(&appdir, &finfo);
        }
        snprintf(filename, 50, "%s%s", locdir, filname);
        
        //"Pre-checking" phase
        if(f_stat(filename, &finfo) != FR_OK)
            return -1;
        if(f_open(&fp, filename, FA_READ) != FR_OK)
            return -1;
        */
        
        
    int pos ftell(inputFile);
        
    fseek(inputFile0SEEK_END);
        
    int size ftell(inputFile);
        
    fseek(inputFileposSEEK_SET);
        
        
    buffer malloc(size);
        
        
    fread(buffer1sizeinputFile);
        
        
    //Now that we're done with our checks, let's start reading the file.
        //bytes_read = bytes_read_total = 0;
        
        
    res getImageType(buffer);
        
        if(
    res == 1)//ELF
        
    {
            
        }
        else
    //Probably a DOL...
        
    {
            
    ep = (void(*)())load_dol_image(buffer);
        }
        
    fclose(inputFile);
        
        
    __IOS_ShutdownSubsystems();
        
    _CPU_ISR_Disable (level);
        
    __exception_closeall ();
        
    //This is it!
        
    ep();
        
    //And we're back.
        
    _CPU_ISR_Restore (level);
        
        
    //Successful?
        
    return 0;
    }

    int test()
    {
        return 
    1;


  2. 1 User Says Thank You Tonyyyyyyy For This Useful Post


  3. #2
    New Member 540_Slider's Avatar
    Join Date
    May 2010
    Posts
    13
    Thanks
    0
    Thanked 2 Times in 2 Posts
    I am also known as Jwop.

  4. 1 User Says Thank You 540_Slider For This Useful Post


  5. #3
    New Member
    Join Date
    May 2012
    Posts
    2
    Thanks
    0
    Thanked 2 Times in 2 Posts
    The code looks fine to me, except the buffer part, it looks like it keeps allocating the memory to the wrong partitions as far as ive tested it. Seeming as your buffer is elf/dos, I was able to convert the code into elf rather than dos, as now homebrew prefers the elf? ( always get confused which one it is) but looking at the buffer given in the website, it is compatible with conversions.

  6. 1 User Says Thank You Fro//t For This Useful Post


  7. #4
    New Member
    Join Date
    May 2012
    Posts
    2
    Thanks
    0
    Thanked 2 Times in 2 Posts
    *dol my bad...

    ProFro//t (ProFrozt)

  8. 1 User Says Thank You Fro//t For This Useful Post


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •