mirror of
https://github.com/jakcron/nstool
synced 2024-11-15 10:16:42 +00:00
Port AssetHeader to libtoolchain.
This commit is contained in:
parent
6a3bd0e562
commit
b51ce51b15
2 changed files with 33 additions and 35 deletions
|
@ -1,8 +1,9 @@
|
||||||
#include "AssetProcess.h"
|
#include "AssetProcess.h"
|
||||||
|
|
||||||
#include "utils.h"
|
#include "util.h"
|
||||||
|
|
||||||
nstool::AssetProcess::AssetProcess() :
|
nstool::AssetProcess::AssetProcess() :
|
||||||
|
mModuleName("nstool::AssetProcess::"),
|
||||||
mFile(),
|
mFile(),
|
||||||
mCliOutputMode(true, false, false, false),
|
mCliOutputMode(true, false, false, false),
|
||||||
mVerify(false)
|
mVerify(false)
|
||||||
|
@ -37,17 +38,17 @@ void nstool::AssetProcess::setListFs(bool list)
|
||||||
mRomfs.setListFs(list);
|
mRomfs.setListFs(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nstool::AssetProcess::setIconExtractPath(const std::string& path)
|
void nstool::AssetProcess::setIconExtractPath(const tc::io::Path& path)
|
||||||
{
|
{
|
||||||
mIconExtractPath = path;
|
mIconExtractPath = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
void nstool::AssetProcess::setNacpExtractPath(const std::string& path)
|
void nstool::AssetProcess::setNacpExtractPath(const tc::io::Path& path)
|
||||||
{
|
{
|
||||||
mNacpExtractPath = path;
|
mNacpExtractPath = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
void nstool::AssetProcess::setRomfsExtractPath(const std::string& path)
|
void nstool::AssetProcess::setRomfsExtractPath(const tc::io::Path& path)
|
||||||
{
|
{
|
||||||
mRomfs.setExtractPath(path);
|
mRomfs.setExtractPath(path);
|
||||||
}
|
}
|
||||||
|
@ -55,49 +56,46 @@ void nstool::AssetProcess::setRomfsExtractPath(const std::string& path)
|
||||||
|
|
||||||
void nstool::AssetProcess::importHeader()
|
void nstool::AssetProcess::importHeader()
|
||||||
{
|
{
|
||||||
tc::ByteData scratch;
|
|
||||||
|
|
||||||
if (mFile == nullptr)
|
if (mFile == nullptr)
|
||||||
{
|
{
|
||||||
throw tc::Exception(kModuleName, "No file reader set.");
|
throw tc::Exception(mModuleName, "No file reader set.");
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t file_size = tc::io::IOUtil::castInt64ToSize(mFile->length());
|
if (mFile->length() < tc::io::IOUtil::castSizeToInt64(sizeof(nn::hac::sAssetHeader)))
|
||||||
|
|
||||||
if (file_size < sizeof(nn::hac::sAssetHeader))
|
|
||||||
{
|
{
|
||||||
throw tc::Exception(kModuleName, "Corrupt ASET: file too small");
|
throw tc::Exception(mModuleName, "Corrupt ASET: file too small");
|
||||||
}
|
}
|
||||||
|
|
||||||
scratch.alloc(sizeof(nn::hac::sAssetHeader));
|
tc::ByteData scratch = tc::ByteData(sizeof(nn::hac::sAssetHeader));
|
||||||
mFile->read(scratch.data(), 0, scratch.size());
|
mFile->seek(0, tc::io::SeekOrigin::Begin);
|
||||||
|
mFile->read(scratch.data(), scratch.size());
|
||||||
|
|
||||||
mHdr.fromBytes(scratch.data(), scratch.size());
|
mHdr.fromBytes(scratch.data(), scratch.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void nstool::AssetProcess::processSections()
|
void nstool::AssetProcess::processSections()
|
||||||
{
|
{
|
||||||
size_t file_size = tc::io::IOUtil::castInt64ToSize(mFile->length());
|
int64_t file_size = mFile->length();
|
||||||
|
|
||||||
if (mHdr.getIconInfo().size > 0 && mIconExtractPath.isSet())
|
if (mHdr.getIconInfo().size > 0 && mIconExtractPath.isSet())
|
||||||
{
|
{
|
||||||
if ((mHdr.getIconInfo().size + mHdr.getIconInfo().offset) > file_size)
|
if ((mHdr.getIconInfo().size + mHdr.getIconInfo().offset) > file_size)
|
||||||
throw tc::Exception(kModuleName, "ASET geometry for icon beyond file size");
|
throw tc::Exception(mModuleName, "ASET geometry for icon beyond file size");
|
||||||
|
|
||||||
writeSubStreamToFile(mFile, tc::io::IOUtil::castSizeToInt64(mHdr.getIconInfo().offset), tc::io::IOUtil::castSizeToInt64(mHdr.getIconInfo().size), mIconExtractPath.get());
|
writeSubStreamToFile(mFile, mHdr.getIconInfo().offset, mHdr.getIconInfo().size, mIconExtractPath.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mHdr.getNacpInfo().size > 0)
|
if (mHdr.getNacpInfo().size > 0)
|
||||||
{
|
{
|
||||||
if ((mHdr.getNacpInfo().size + mHdr.getNacpInfo().offset) > file_size)
|
if ((mHdr.getNacpInfo().size + mHdr.getNacpInfo().offset) > file_size)
|
||||||
throw tc::Exception(kModuleName, "ASET geometry for nacp beyond file size");
|
throw tc::Exception(mModuleName, "ASET geometry for nacp beyond file size");
|
||||||
|
|
||||||
if (mNacpExtractPath.isSet())
|
if (mNacpExtractPath.isSet())
|
||||||
{
|
{
|
||||||
writeSubStreamToFile(mFile, tc::io::IOUtil::castSizeToInt64(mHdr.getNacpInfo().offset), tc::io::IOUtil::castSizeToInt64(mHdr.getNacpInfo().size), mNacpExtractPath.get());
|
writeSubStreamToFile(mFile, mHdr.getNacpInfo().offset, mHdr.getNacpInfo().size, mNacpExtractPath.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
mNacp.setInputFile(std::make_shared<tc::io::SubStream>(mFile, tc::io::IOUtil::castSizeToInt64(mHdr.getNacpInfo().offset), tc::io::IOUtil::castSizeToInt64(mHdr.getNacpInfo().size)));
|
mNacp.setInputFile(std::make_shared<tc::io::SubStream>(mFile, mHdr.getNacpInfo().offset, mHdr.getNacpInfo().size));
|
||||||
mNacp.setCliOutputMode(mCliOutputMode);
|
mNacp.setCliOutputMode(mCliOutputMode);
|
||||||
mNacp.setVerifyMode(mVerify);
|
mNacp.setVerifyMode(mVerify);
|
||||||
|
|
||||||
|
@ -107,9 +105,9 @@ void nstool::AssetProcess::processSections()
|
||||||
if (mHdr.getRomfsInfo().size > 0)
|
if (mHdr.getRomfsInfo().size > 0)
|
||||||
{
|
{
|
||||||
if ((mHdr.getRomfsInfo().size + mHdr.getRomfsInfo().offset) > file_size)
|
if ((mHdr.getRomfsInfo().size + mHdr.getRomfsInfo().offset) > file_size)
|
||||||
throw tc::Exception(kModuleName, "ASET geometry for romfs beyond file size");
|
throw tc::Exception(mModuleName, "ASET geometry for romfs beyond file size");
|
||||||
|
|
||||||
mRomfs.setInputFile(std::make_shared<tc::io::SubStream>(mFile, tc::io::IOUtil::castSizeToInt64(mHdr.getRomfsInfo().offset), tc::io::IOUtil::castSizeToInt64(mHdr.getRomfsInfo().size)));
|
mRomfs.setInputFile(std::make_shared<tc::io::SubStream>(mFile, mHdr.getRomfsInfo().offset, mHdr.getRomfsInfo().size));
|
||||||
mRomfs.setCliOutputMode(mCliOutputMode);
|
mRomfs.setCliOutputMode(mCliOutputMode);
|
||||||
mRomfs.setVerifyMode(mVerify);
|
mRomfs.setVerifyMode(mVerify);
|
||||||
|
|
||||||
|
@ -121,16 +119,16 @@ void nstool::AssetProcess::displayHeader()
|
||||||
{
|
{
|
||||||
if (mCliOutputMode.show_layout)
|
if (mCliOutputMode.show_layout)
|
||||||
{
|
{
|
||||||
std::cout << "[ASET Header]" << std::endl;
|
fmt::print("[ASET Header]\n");
|
||||||
std::cout << " Icon:" << std::endl;
|
fmt::print(" Icon:\n");
|
||||||
std::cout << " Offset: 0x" << std::hex << mHdr.getIconInfo().offset << std::endl;
|
fmt::print(" Offset: 0x{:x}\n", mHdr.getIconInfo().offset);
|
||||||
std::cout << " Size: 0x" << std::hex << mHdr.getIconInfo().size << std::endl;
|
fmt::print(" Size: 0x{:x}\n", mHdr.getIconInfo().size);
|
||||||
std::cout << " NACP:" << std::endl;
|
fmt::print(" NACP:\n");
|
||||||
std::cout << " Offset: 0x" << std::hex << mHdr.getNacpInfo().offset << std::endl;
|
fmt::print(" Offset: 0x{:x}\n", mHdr.getNacpInfo().offset);
|
||||||
std::cout << " Size: 0x" << std::hex << mHdr.getNacpInfo().size << std::endl;
|
fmt::print(" Size: 0x{:x}\n", mHdr.getNacpInfo().size);
|
||||||
std::cout << " RomFS:" << std::endl;
|
fmt::print(" RomFS:\n");
|
||||||
std::cout << " Offset: 0x" << std::hex << mHdr.getRomfsInfo().offset << std::endl;
|
fmt::print(" Offset: 0x{:x}\n", mHdr.getRomfsInfo().offset);
|
||||||
std::cout << " Size: 0x" << std::hex << mHdr.getRomfsInfo().size << std::endl;
|
fmt::print(" Size: 0x{:x}\n", mHdr.getRomfsInfo().size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,13 +20,13 @@ public:
|
||||||
|
|
||||||
void setListFs(bool list);
|
void setListFs(bool list);
|
||||||
|
|
||||||
void setIconExtractPath(const std::string& path);
|
void setIconExtractPath(const tc::io::Path& path);
|
||||||
void setNacpExtractPath(const std::string& path);
|
void setNacpExtractPath(const tc::io::Path& path);
|
||||||
void setRomfsExtractPath(const std::string& path);
|
void setRomfsExtractPath(const tc::io::Path& path);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::string kModuleName = "AssetProcess";
|
std::string mModuleName;
|
||||||
|
|
||||||
std::shared_ptr<tc::io::IStream> mFile;
|
std::shared_ptr<tc::io::IStream> mFile;
|
||||||
CliOutputMode mCliOutputMode;
|
CliOutputMode mCliOutputMode;
|
||||||
|
|
Loading…
Reference in a new issue