Module *__KernelLoadModule(u8 *fileptr, SceKernelLMOption *options, std::string *error_string) { Module *module = 0; // Check for PBP if (memcmp(fileptr, "\0PBP", 4) == 0) { // PBP! u32 version; memcpy(&version, fileptr + 4, 4); u32 offset0, offsets[16]; int numfiles; memcpy(&offset0, fileptr + 8, 4); numfiles = (offset0 - 8)/4; offsets[0] = offset0; for (int i = 1; i < numfiles; i++) memcpy(&offsets[i], fileptr + 12 + 4*i, 4); module = __KernelLoadELFFromPtr(fileptr + offsets[5], PSP_GetDefaultLoadAddress(), error_string); } else { module = __KernelLoadELFFromPtr(fileptr, PSP_GetDefaultLoadAddress(), error_string); } return module; }
u32 sceKernelLoadModule(const char *name, u32 flags) { if(!name) return 0; PSPFileInfo info = pspFileSystem.GetFileInfo(name); std::string error_string; s64 size = (s64)info.size; if (!info.exists) { ERROR_LOG(LOADER, "sceKernelLoadModule(%s, %08x): File does not exist", name, flags); return SCE_KERNEL_ERROR_NOFILE; } if (!size) { ERROR_LOG(LOADER, "sceKernelLoadModule(%s, %08x): Module file is size 0", name, flags); return SCE_KERNEL_ERROR_ILLEGAL_OBJECT; } DEBUG_LOG(LOADER, "sceKernelLoadModule(%s, %08x)", name, flags); SceKernelLMOption *lmoption = 0; int position = 0; // TODO: Use position to decide whether to load high or low if (PARAM(2)) { SceKernelLMOption *lmoption = (SceKernelLMOption *)Memory::GetPointer(PARAM(2)); } Module *module = 0; u8 *temp = new u8[(int)size]; u32 handle = pspFileSystem.OpenFile(name, FILEACCESS_READ); pspFileSystem.ReadFile(handle, temp, (size_t)size); module = __KernelLoadELFFromPtr(temp, 0, &error_string); delete [] temp; pspFileSystem.CloseFile(handle); if (!module) { // Module was blacklisted or couldn't be decrypted, which means it's a kernel module we don't want to run. // Let's just act as if it worked. NOTICE_LOG(LOADER, "Module %s is blacklisted or undecryptable - we lie about success", name); return 1; } if (lmoption) { INFO_LOG(HLE,"%i=sceKernelLoadModule(name=%s,flag=%08x,%08x,%08x,%08x,position = %08x)", module->GetUID(),name,flags, lmoption->size,lmoption->mpidtext,lmoption->mpiddata,lmoption->position); } else { INFO_LOG(HLE,"%i=sceKernelLoadModule(name=%s,flag=%08x,(...))", module->GetUID(), name, flags); } return module->GetUID(); }
bool __KernelLoadPBP(const char *filename, std::string *error_string) { static const char *FileNames[] = { "PARAM.SFO", "ICON0.PNG", "ICON1.PMF", "UNKNOWN.PNG", "PIC1.PNG", "SND0.AT3", "UNKNOWN.PSP", "UNKNOWN.PSAR" }; std::ifstream in(filename, std::ios::binary); char temp[4]; in.read(temp,4); if (memcmp(temp,"\0PBP",4) != 0) { //This is not a valid file! ERROR_LOG(LOADER,"%s is not a valid homebrew PSP1.0 PBP",filename); *error_string = "Not a valid homebrew PBP"; return false; } u32 version, offset0, offsets[16]; int numfiles; in.read((char*)&version,4); in.read((char*)&offset0,4); numfiles = (offset0 - 8) / 4; offsets[0] = offset0; for (int i = 1; i < numfiles; i++) in.read((char*)&offsets[i], 4); // The 6th is always the executable? in.seekg(offsets[5]); //in.read((char*)&id,4); { u8 *elftemp = new u8[1024*1024*8]; in.read((char*)elftemp, 1024*1024*8); Module *module = __KernelLoadELFFromPtr(elftemp, PSP_GetDefaultLoadAddress(), error_string); if (!module) return false; mipsr4k.pc = module->nm.entry_addr; delete [] elftemp; } in.close(); return true; }
u32 sceKernelLoadModuleByID(u32 id, u32 flags, u32 lmoptionPtr) { u32 error; u32 handle = __IoGetFileHandleFromId(id, error); if (handle == (u32)-1) { ERROR_LOG(HLE,"sceKernelLoadModuleByID(%08x, %08x, %08x): could not open file id",id,flags,lmoptionPtr); return error; } SceKernelLMOption *lmoption = 0; if (lmoptionPtr) { lmoption = (SceKernelLMOption *)Memory::GetPointer(lmoptionPtr); } u32 pos = (u32) pspFileSystem.SeekFile(handle, 0, FILEMOVE_CURRENT); size_t size = pspFileSystem.SeekFile(handle, 0, FILEMOVE_END); std::string error_string; pspFileSystem.SeekFile(handle, pos, FILEMOVE_BEGIN); Module *module = 0; u8 *temp = new u8[size]; pspFileSystem.ReadFile(handle, temp, size); module = __KernelLoadELFFromPtr(temp, 0, &error_string); delete [] temp; if (!module) { // Module was blacklisted or couldn't be decrypted, which means it's a kernel module we don't want to run. // Let's just act as if it worked. NOTICE_LOG(LOADER, "Module %d is blacklisted or undecryptable - we lie about success", id); return 1; } if (lmoption) { INFO_LOG(HLE,"%i=sceKernelLoadModuleByID(%d,flag=%08x,%08x,%08x,%08x,position = %08x)", module->GetUID(),id,flags, lmoption->size,lmoption->mpidtext,lmoption->mpiddata,lmoption->position); } else { INFO_LOG(HLE,"%i=sceKernelLoadModuleByID(%d,flag=%08x,(...))", module->GetUID(), id, flags); } return module->GetUID(); }