mirror of https://github.com/AxioDL/nod.git
DOL/Apploader buffer maker
This commit is contained in:
parent
b6969a82dc
commit
b8236ba6d7
|
@ -101,14 +101,14 @@ public:
|
||||||
m_name(name) {}
|
m_name(name) {}
|
||||||
inline Kind getKind() const {return m_kind;}
|
inline Kind getKind() const {return m_kind;}
|
||||||
inline const std::string& getName() const {return m_name;}
|
inline const std::string& getName() const {return m_name;}
|
||||||
std::unique_ptr<IPartReadStream> beginReadStream() const
|
std::unique_ptr<IPartReadStream> beginReadStream(uint64_t offset=0) const
|
||||||
{
|
{
|
||||||
if (m_kind != NODE_FILE)
|
if (m_kind != NODE_FILE)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("unable to stream a non-file");
|
throw std::runtime_error("unable to stream a non-file");
|
||||||
return std::unique_ptr<IPartReadStream>();
|
return std::unique_ptr<IPartReadStream>();
|
||||||
}
|
}
|
||||||
return m_parent.beginReadStream(m_discOffset);
|
return m_parent.beginReadStream(m_discOffset + offset);
|
||||||
}
|
}
|
||||||
inline std::vector<Node>::iterator rawBegin() const {return m_childrenBegin;}
|
inline std::vector<Node>::iterator rawBegin() const {return m_childrenBegin;}
|
||||||
inline std::vector<Node>::iterator rawEnd() const {return m_childrenEnd;}
|
inline std::vector<Node>::iterator rawEnd() const {return m_childrenEnd;}
|
||||||
|
@ -144,6 +144,10 @@ public:
|
||||||
std::vector<Node> m_nodes;
|
std::vector<Node> m_nodes;
|
||||||
void parseFST(IPartReadStream& s);
|
void parseFST(IPartReadStream& s);
|
||||||
|
|
||||||
|
DOLHeader m_dolHead;
|
||||||
|
uint64_t m_dolSz;
|
||||||
|
void parseDOL(IPartReadStream& s);
|
||||||
|
|
||||||
const DiscBase& m_parent;
|
const DiscBase& m_parent;
|
||||||
Kind m_kind;
|
Kind m_kind;
|
||||||
uint64_t m_offset;
|
uint64_t m_offset;
|
||||||
|
@ -153,9 +157,39 @@ public:
|
||||||
virtual uint64_t normalizeOffset(uint64_t anOffset) const {return anOffset;}
|
virtual uint64_t normalizeOffset(uint64_t anOffset) const {return anOffset;}
|
||||||
inline Kind getKind() const {return m_kind;}
|
inline Kind getKind() const {return m_kind;}
|
||||||
virtual std::unique_ptr<IPartReadStream> beginReadStream(uint64_t offset=0) const=0;
|
virtual std::unique_ptr<IPartReadStream> beginReadStream(uint64_t offset=0) const=0;
|
||||||
|
inline std::unique_ptr<IPartReadStream> beginDOLReadStream(uint64_t offset=0) const
|
||||||
|
{return beginReadStream(m_dolOff + offset);}
|
||||||
|
inline std::unique_ptr<IPartReadStream> beginFSTReadStream(uint64_t offset=0) const
|
||||||
|
{return beginReadStream(m_fstOff + offset);}
|
||||||
|
inline std::unique_ptr<IPartReadStream> beginApploaderReadStream(uint64_t offset=0) const
|
||||||
|
{return beginReadStream(0x2440 + offset);}
|
||||||
inline const Node& getFSTRoot() const {return m_nodes[0];}
|
inline const Node& getFSTRoot() const {return m_nodes[0];}
|
||||||
inline Node& getFSTRoot() {return m_nodes[0];}
|
inline Node& getFSTRoot() {return m_nodes[0];}
|
||||||
void extractToDirectory(const SystemString& path, bool force=false);
|
void extractToDirectory(const SystemString& path, bool force=false);
|
||||||
|
|
||||||
|
inline uint64_t getDOLSize() const {return m_dolSz;}
|
||||||
|
inline std::unique_ptr<uint8_t[]> getDOLBuf() const
|
||||||
|
{
|
||||||
|
std::unique_ptr<uint8_t[]> buf(new uint8_t[m_dolSz]);
|
||||||
|
beginDOLReadStream()->read(buf.get(), m_dolSz);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline uint64_t getFSTSize() const {return m_fstSz;}
|
||||||
|
inline std::unique_ptr<uint8_t[]> getFSTBuf() const
|
||||||
|
{
|
||||||
|
std::unique_ptr<uint8_t[]> buf(new uint8_t[m_fstSz]);
|
||||||
|
beginFSTReadStream()->read(buf.get(), m_fstSz);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline uint64_t getApploaderSize() const {return m_apploaderSz;}
|
||||||
|
inline std::unique_ptr<uint8_t[]> getApploaderBuf() const
|
||||||
|
{
|
||||||
|
std::unique_ptr<uint8_t[]> buf(new uint8_t[m_apploaderSz]);
|
||||||
|
beginApploaderReadStream()->read(buf.get(), m_apploaderSz);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -43,6 +43,20 @@ void DiscBase::IPartition::parseFST(IPartReadStream& s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DiscBase::IPartition::parseDOL(IPartReadStream& s)
|
||||||
|
{
|
||||||
|
/* Read Dol header */
|
||||||
|
s.read(&m_dolHead, sizeof(DOLHeader));
|
||||||
|
|
||||||
|
/* Calculate Dol size */
|
||||||
|
uint32_t dolSize = SBig(m_dolHead.textOff[0]) - sizeof(DOLHeader);
|
||||||
|
for (uint32_t i = 0 ; i < 7 ; i++)
|
||||||
|
dolSize += SBig(m_dolHead.textSizes[i]);
|
||||||
|
for (uint32_t i = 0 ; i < 11 ; i++)
|
||||||
|
dolSize += SBig(m_dolHead.dataSizes[i]);
|
||||||
|
m_dolSz = dolSize;
|
||||||
|
}
|
||||||
|
|
||||||
void DiscBase::IPartition::Node::extractToDirectory(const SystemString& basePath, bool force)
|
void DiscBase::IPartition::Node::extractToDirectory(const SystemString& basePath, bool force)
|
||||||
{
|
{
|
||||||
SystemStringView nameView(getName());
|
SystemStringView nameView(getName());
|
||||||
|
@ -83,32 +97,16 @@ void DiscBase::IPartition::extractToDirectory(const SystemString& path, bool for
|
||||||
SystemString apploaderPath = path + _S("/apploader.bin");
|
SystemString apploaderPath = path + _S("/apploader.bin");
|
||||||
if (force || Stat(apploaderPath.c_str(), &theStat))
|
if (force || Stat(apploaderPath.c_str(), &theStat))
|
||||||
{
|
{
|
||||||
std::unique_ptr<uint8_t[]> buf(new uint8_t[m_apploaderSz]);
|
std::unique_ptr<uint8_t[]> buf = getApploaderBuf();
|
||||||
std::unique_ptr<IPartReadStream> rs = beginReadStream(0x2440);
|
NewFileIO(apploaderPath)->beginWriteStream()->write(buf.get(), m_apploaderSz);
|
||||||
rs->read(buf.get(), m_apploaderSz);
|
|
||||||
std::unique_ptr<IFileIO::IWriteStream> ws = NewFileIO(apploaderPath)->beginWriteStream();
|
|
||||||
ws->write(buf.get(), m_apploaderSz);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Extract Dol */
|
/* Extract Dol */
|
||||||
SystemString dolPath = path + _S("/main.dol");
|
SystemString dolPath = path + _S("/main.dol");
|
||||||
if (force || Stat(dolPath.c_str(), &theStat))
|
if (force || Stat(dolPath.c_str(), &theStat))
|
||||||
{
|
{
|
||||||
std::unique_ptr<IPartReadStream> rs = beginReadStream(m_dolOff);
|
std::unique_ptr<uint8_t[]> buf = getDOLBuf();
|
||||||
/* Read Dol header */
|
NewFileIO(dolPath)->beginWriteStream()->write(buf.get(), m_dolSz);
|
||||||
DOLHeader hdr;
|
|
||||||
rs->read(&hdr, sizeof(DOLHeader));
|
|
||||||
std::unique_ptr<IFileIO::IWriteStream> ws = NewFileIO(dolPath)->beginWriteStream();
|
|
||||||
ws->write(&hdr, sizeof(DOLHeader));
|
|
||||||
/* Calculate Dol size */
|
|
||||||
uint32_t dolSize = SBig(hdr.textOff[0]) - sizeof(DOLHeader);
|
|
||||||
for (uint32_t i = 0 ; i < 7 ; i++)
|
|
||||||
dolSize += SBig(hdr.textSizes[i]);
|
|
||||||
for (uint32_t i = 0 ; i < 11 ; i++)
|
|
||||||
dolSize += SBig(hdr.dataSizes[i]);
|
|
||||||
std::unique_ptr<uint8_t[]> buf(new uint8_t[dolSize]);
|
|
||||||
rs->read(buf.get(), dolSize);
|
|
||||||
ws->write(buf.get(), dolSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Extract Filesystem */
|
/* Extract Filesystem */
|
||||||
|
|
|
@ -22,6 +22,10 @@ public:
|
||||||
|
|
||||||
/* Yay files!! */
|
/* Yay files!! */
|
||||||
parseFST(*s.get());
|
parseFST(*s.get());
|
||||||
|
|
||||||
|
/* Also make DOL header and size handy */
|
||||||
|
s->seek(m_dolOff);
|
||||||
|
parseDOL(*s.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
class PartReadStream : public IPartReadStream
|
class PartReadStream : public IPartReadStream
|
||||||
|
|
|
@ -249,6 +249,10 @@ public:
|
||||||
|
|
||||||
/* Yay files!! */
|
/* Yay files!! */
|
||||||
parseFST(*ds.get());
|
parseFST(*ds.get());
|
||||||
|
|
||||||
|
/* Also make DOL header and size handy */
|
||||||
|
ds->seek(m_dolOff);
|
||||||
|
parseDOL(*ds.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
class PartReadStream : public IPartReadStream
|
class PartReadStream : public IPartReadStream
|
||||||
|
|
Loading…
Reference in New Issue