static char ReadCharNN(vfsStream& f) { char c; while(!f.Eof()) { f.Read(&c, 1); if(c != 0) break; } return c; }
static void GoToNN(vfsStream& f) { while(!f.Eof()) { char c; f.Read(&c, 1); if(c != 0) { f.Seek(f.Tell() - 1); break; } } }
handler::error_code handler::init(vfsStream& stream) { m_stream_offset = stream.Tell(); m_stream = &stream; return ok; }
void ControlInfo::Load(vfsStream& f) { type = Read32(f); size = Read32(f); next = Read64(f); if (type == 1) { control_flags.ctrl_flag1 = Read32(f); control_flags.unknown1 = Read32(f); control_flags.unknown2 = Read32(f); control_flags.unknown3 = Read32(f); control_flags.unknown4 = Read32(f); control_flags.unknown5 = Read32(f); control_flags.unknown6 = Read32(f); control_flags.unknown7 = Read32(f); } else if (type == 2) { if (size == 0x30) { f.Read(file_digest_30.digest, 20); file_digest_30.unknown = Read64(f); } else if (size == 0x40) { f.Read(file_digest_40.digest1, 20); f.Read(file_digest_40.digest2, 20); file_digest_40.unknown = Read64(f); } } else if (type == 3) { npdrm.magic = Read32(f); npdrm.unknown1 = Read32(f); npdrm.license = Read32(f); npdrm.type = Read32(f); f.Read(npdrm.content_id, 48); f.Read(npdrm.digest, 16); f.Read(npdrm.invdigest, 16); f.Read(npdrm.xordigest, 16); npdrm.unknown2 = Read64(f); npdrm.unknown3 = Read64(f); } }
u32 LoadSpuImage(vfsStream& stream) { ELFLoader l(stream); l.LoadInfo(); g_spu_offset = Memory.MainMem.Alloc(0xFFFFED - stream.GetSize()); l.LoadData(g_spu_offset); return g_spu_offset + l.GetEntry(); }
static wxString ReadString(vfsStream& f, const u32 size) { wxString ret = wxEmptyString; for(uint i=0; i<size && !f.Eof(); ++i) { ret += ReadChar(f); } return ret; }
static wxString ReadString(vfsStream& f) { wxString ret = wxEmptyString; while(!f.Eof()) { const char c = ReadChar(f); if(c == 0) break; ret += c; } return ret; }
bool loader::load(vfsStream& stream) { for (auto i : m_handlers) { i->set_status(i->init(stream)); if (i->get_status() == handler::ok) { i->set_status(i->load()); if (i->get_status() == handler::ok) { return true; } LOG_NOTICE(LOADER, "loader::load() failed: %s", i->get_error_code().c_str()); } else { LOG_NOTICE(LOADER, "loader::init() failed: %s", i->get_error_code().c_str()); stream.Seek(i->get_stream_offset()); } } return false; }
force_inline void Write64(vfsStream& f, const be_t<u64> data) { f.Write(&data, sizeof(data)); }
force_inline void Write16LE(vfsStream& f, const u16 data) { f.Write(&data, sizeof(data)); }
static char ReadChar(vfsStream& f) { char c; f.Read(&c, 1); return c; }
__forceinline void Write64LE(vfsStream& f, const u64 data) { f.Write(&data, sizeof(data)); }
__forceinline void Write8(vfsStream& f, const u8 data) { f.Write(&data, sizeof(data)); }
void Elf32_Phdr::LoadLE(vfsStream& f) { f.Read(this, sizeof(*this)); }
__forceinline u8 Read8(vfsStream& f) { u8 ret; f.Read(&ret, sizeof(ret)); return ret; }
void Signature::Load(vfsStream& f) { f.Read(r, 21); f.Read(s, 21); f.Read(padding, 6); }
void SectionHash::Load(vfsStream& f) { f.Read(sha1, 20); f.Read(padding, 12); f.Read(hmac_key, 64); }
force_inline void Write32LE(vfsStream& f, const u32 data) { f.Write(&data, sizeof(data)); }
__forceinline u16 Read16LE(vfsStream& f) { u16 ret; f.Read(&ret, sizeof(ret)); return ret; }
__forceinline u64 Read64(vfsStream& f) { be_t<u64> ret; f.Read(&ret, sizeof(ret)); return ret; }
__forceinline u32 Read32(vfsStream& f) { be_t<u32> ret; f.Read(&ret, sizeof(ret)); return ret; }
__forceinline u64 Read64LE(vfsStream& f) { u64 ret; f.Read(&ret, sizeof(ret)); return ret; }
__forceinline u32 Read32LE(vfsStream& f) { u32 ret; f.Read(&ret, sizeof(ret)); return ret; }
__forceinline u16 Read16(vfsStream& f) { be_t<u16> ret; f.Read(&ret, sizeof(ret)); return ret; }