Humungous refactor

This commit is contained in:
Jack Andersen 2016-03-04 13:04:30 -10:00
parent 7320b76ff4
commit 556a5868bb
28 changed files with 191 additions and 192 deletions

6
.gitmodules vendored
View File

@ -1,3 +1,3 @@
[submodule "log-visor"] [submodule "logvisor"]
path = log-visor path = logvisor
url = https://github.com/AxioDL/log-visor.git url = https://github.com/AxioDL/logvisor.git

View File

@ -1,20 +1,20 @@
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
cmake_minimum_required(VERSION 3.0) cmake_minimum_required(VERSION 3.0)
project(NODLib) project(nod)
endif() endif()
if(NOT MSVC) if(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
endif() endif()
if (NOT TARGET LogVisor) if (NOT TARGET logvisor)
add_subdirectory(LogVisor) add_subdirectory(logvisor)
set(LOG_VISOR_INCLUDE_DIR LogVisor/include) set(LOGVISOR_INCLUDE_DIR logvisor/include)
endif() endif()
include_directories(include ${LOG_VISOR_INCLUDE_DIR}) include_directories(include ${LOGVISOR_INCLUDE_DIR})
file(GLOB NOD_HEADERS include/NOD/*.h*) file(GLOB NOD_HEADERS include/nod/*.h*)
add_subdirectory(lib) add_subdirectory(lib)
add_subdirectory(driver) add_subdirectory(driver)
install(DIRECTORY include/NOD DESTINATION include/NOD) install(DIRECTORY include/nod DESTINATION include/nod)

View File

@ -1,7 +1,6 @@
add_executable(nodtool add_executable(nodtool main.cpp)
main.cpp)
target_link_libraries(nodtool NOD LogVisor) target_link_libraries(nodtool nod logvisor)
if (NOT WIN32) if (NOT WIN32)
target_link_libraries(nodtool pthread) target_link_libraries(nodtool pthread)
endif() endif()

View File

@ -1,7 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <LogVisor/LogVisor.hpp> #include "logvisor/logvisor.hpp"
#include "NOD/NOD.hpp" #include "nod/nod.hpp"
static void printHelp() static void printHelp()
{ {
@ -33,13 +33,13 @@ int main(int argc, char* argv[])
} }
/* Enable logging to console */ /* Enable logging to console */
LogVisor::RegisterConsoleLogger(); logvisor::RegisterConsoleLogger();
NOD::ExtractionContext ctx = { true, true, [&](const std::string& str){ nod::ExtractionContext ctx = { true, true, [&](const std::string& str){
fprintf(stderr, "%s\n", str.c_str()); fprintf(stderr, "%s\n", str.c_str());
}}; }};
const NOD::SystemChar* inDir = nullptr; const nod::SystemChar* inDir = nullptr;
const NOD::SystemChar* outDir = _S("."); const nod::SystemChar* outDir = _S(".");
for (int a=2 ; a<argc ; ++a) for (int a=2 ; a<argc ; ++a)
{ {
@ -57,17 +57,17 @@ int main(int argc, char* argv[])
if (!strcasecmp(argv[1], _S("extract"))) if (!strcasecmp(argv[1], _S("extract")))
{ {
bool isWii; bool isWii;
std::unique_ptr<NOD::DiscBase> disc = NOD::OpenDiscFromImage(inDir, isWii); std::unique_ptr<nod::DiscBase> disc = nod::OpenDiscFromImage(inDir, isWii);
if (!disc) if (!disc)
return 1; return 1;
NOD::Mkdir(outDir, 0755); nod::Mkdir(outDir, 0755);
if (isWii) if (isWii)
static_cast<NOD::DiscWii&>(*disc).writeOutDataPartitionHeader( static_cast<nod::DiscWii&>(*disc).writeOutDataPartitionHeader(
(NOD::SystemString(outDir) + _S("/partition_head.bin")).c_str()); (nod::SystemString(outDir) + _S("/partition_head.bin")).c_str());
NOD::Partition* dataPart = disc->getDataPartition(); nod::Partition* dataPart = disc->getDataPartition();
if (!dataPart) if (!dataPart)
return 1; return 1;
@ -78,27 +78,27 @@ int main(int argc, char* argv[])
{ {
#if NOD_UCS2 #if NOD_UCS2
if (wcslen(argv[2]) < 6) if (wcslen(argv[2]) < 6)
NOD::LogModule.report(LogVisor::FatalError, _S("game-id is not at least 6 characters")); nod::LogModule.report(logvisor::Fatal, _S("game-id is not at least 6 characters"));
#else #else
if (strlen(argv[2]) < 6) if (strlen(argv[2]) < 6)
NOD::LogModule.report(LogVisor::FatalError, _S("game-id is not at least 6 characters")); nod::LogModule.report(logvisor::Fatal, _S("game-id is not at least 6 characters"));
#endif #endif
/* Pre-validate paths */ /* Pre-validate paths */
NOD::Sstat theStat; nod::Sstat theStat;
if (NOD::Stat(argv[4], &theStat) || !S_ISDIR(theStat.st_mode)) if (nod::Stat(argv[4], &theStat) || !S_ISDIR(theStat.st_mode))
NOD::LogModule.report(LogVisor::FatalError, _S("unable to stat %s as directory"), argv[4]); nod::LogModule.report(logvisor::Fatal, _S("unable to stat %s as directory"), argv[4]);
if (NOD::Stat(argv[5], &theStat) || !S_ISREG(theStat.st_mode)) if (nod::Stat(argv[5], &theStat) || !S_ISREG(theStat.st_mode))
NOD::LogModule.report(LogVisor::FatalError, _S("unable to stat %s as file"), argv[5]); nod::LogModule.report(logvisor::Fatal, _S("unable to stat %s as file"), argv[5]);
if (NOD::Stat(argv[6], &theStat) || !S_ISREG(theStat.st_mode)) if (nod::Stat(argv[6], &theStat) || !S_ISREG(theStat.st_mode))
NOD::LogModule.report(LogVisor::FatalError, "unable to stat %s as file", argv[6]); nod::LogModule.report(logvisor::Fatal, "unable to stat %s as file", argv[6]);
NOD::SystemString gameIdSys(argv[2]); nod::SystemString gameIdSys(argv[2]);
NOD::SystemUTF8View gameId(gameIdSys); nod::SystemUTF8View gameId(gameIdSys);
NOD::SystemString gameTitleSys(argv[3]); nod::SystemString gameTitleSys(argv[3]);
NOD::SystemUTF8View gameTitle(gameTitleSys); nod::SystemUTF8View gameTitle(gameTitleSys);
size_t lastIdx = -1; size_t lastIdx = -1;
auto progFunc = [&](size_t idx, const NOD::SystemString& name, size_t bytes) auto progFunc = [&](size_t idx, const nod::SystemString& name, size_t bytes)
{ {
if (idx != lastIdx) if (idx != lastIdx)
{ {
@ -106,9 +106,9 @@ int main(int argc, char* argv[])
printf("\n"); printf("\n");
} }
if (bytes != -1) if (bytes != -1)
NOD::Printf(_S("\r%s %" PRISize " B"), name.c_str(), bytes); nod::Printf(_S("\r%s %" PRISize " B"), name.c_str(), bytes);
else else
NOD::Printf(_S("\r%s"), name.c_str()); nod::Printf(_S("\r%s"), name.c_str());
fflush(stdout); fflush(stdout);
}; };
@ -116,14 +116,14 @@ int main(int argc, char* argv[])
if (argc < 8) if (argc < 8)
{ {
NOD::SystemString outPath(argv[4]); nod::SystemString outPath(argv[4]);
outPath.append(_S(".iso")); outPath.append(_S(".iso"));
NOD::DiscBuilderGCN b(outPath.c_str(), gameId.utf8_str().c_str(), gameTitle.utf8_str().c_str(), 0x0003EB60, progFunc); nod::DiscBuilderGCN b(outPath.c_str(), gameId.utf8_str().c_str(), gameTitle.utf8_str().c_str(), 0x0003EB60, progFunc);
ret = b.buildFromDirectory(argv[4], argv[5], argv[6]); ret = b.buildFromDirectory(argv[4], argv[5], argv[6]);
} }
else else
{ {
NOD::DiscBuilderGCN b(argv[7], gameId.utf8_str().c_str(), gameTitle.utf8_str().c_str(), 0x0003EB60, progFunc); nod::DiscBuilderGCN b(argv[7], gameId.utf8_str().c_str(), gameTitle.utf8_str().c_str(), 0x0003EB60, progFunc);
ret = b.buildFromDirectory(argv[4], argv[5], argv[6]); ret = b.buildFromDirectory(argv[4], argv[5], argv[6]);
} }
@ -135,29 +135,29 @@ int main(int argc, char* argv[])
{ {
#if NOD_UCS2 #if NOD_UCS2
if (wcslen(argv[2]) < 6) if (wcslen(argv[2]) < 6)
NOD::LogModule.report(LogVisor::FatalError, _S("game-id is not at least 6 characters")); nod::LogModule.report(logvisor::Fatal, _S("game-id is not at least 6 characters"));
#else #else
if (strlen(argv[2]) < 6) if (strlen(argv[2]) < 6)
NOD::LogModule.report(LogVisor::FatalError, _S("game-id is not at least 6 characters")); nod::LogModule.report(logvisor::Fatal, _S("game-id is not at least 6 characters"));
#endif #endif
/* Pre-validate paths */ /* Pre-validate paths */
NOD::Sstat theStat; nod::Sstat theStat;
if (NOD::Stat(argv[4], &theStat) || !S_ISDIR(theStat.st_mode)) if (nod::Stat(argv[4], &theStat) || !S_ISDIR(theStat.st_mode))
NOD::LogModule.report(LogVisor::FatalError, _S("unable to stat %s as directory"), argv[4]); nod::LogModule.report(logvisor::Fatal, _S("unable to stat %s as directory"), argv[4]);
if (NOD::Stat(argv[5], &theStat) || !S_ISREG(theStat.st_mode)) if (nod::Stat(argv[5], &theStat) || !S_ISREG(theStat.st_mode))
NOD::LogModule.report(LogVisor::FatalError, _S("unable to stat %s as file"), argv[5]); nod::LogModule.report(logvisor::Fatal, _S("unable to stat %s as file"), argv[5]);
if (NOD::Stat(argv[6], &theStat) || !S_ISREG(theStat.st_mode)) if (nod::Stat(argv[6], &theStat) || !S_ISREG(theStat.st_mode))
NOD::LogModule.report(LogVisor::FatalError, _S("unable to stat %s as file"), argv[6]); nod::LogModule.report(logvisor::Fatal, _S("unable to stat %s as file"), argv[6]);
if (NOD::Stat(argv[7], &theStat) || !S_ISREG(theStat.st_mode)) if (nod::Stat(argv[7], &theStat) || !S_ISREG(theStat.st_mode))
NOD::LogModule.report(LogVisor::FatalError, _S("unable to stat %s as file"), argv[7]); nod::LogModule.report(logvisor::Fatal, _S("unable to stat %s as file"), argv[7]);
NOD::SystemString gameIdSys(argv[2]); nod::SystemString gameIdSys(argv[2]);
NOD::SystemUTF8View gameId(gameIdSys); nod::SystemUTF8View gameId(gameIdSys);
NOD::SystemString gameTitleSys(argv[3]); nod::SystemString gameTitleSys(argv[3]);
NOD::SystemUTF8View gameTitle(gameTitleSys); nod::SystemUTF8View gameTitle(gameTitleSys);
size_t lastIdx = -1; size_t lastIdx = -1;
auto progFunc = [&](size_t idx, const NOD::SystemString& name, size_t bytes) auto progFunc = [&](size_t idx, const nod::SystemString& name, size_t bytes)
{ {
if (idx != lastIdx) if (idx != lastIdx)
{ {
@ -165,9 +165,9 @@ int main(int argc, char* argv[])
printf("\n"); printf("\n");
} }
if (bytes != -1) if (bytes != -1)
NOD::Printf(_S("\r%s %" PRISize " B"), name.c_str(), bytes); nod::Printf(_S("\r%s %" PRISize " B"), name.c_str(), bytes);
else else
NOD::Printf(_S("\r%s"), name.c_str()); nod::Printf(_S("\r%s"), name.c_str());
fflush(stdout); fflush(stdout);
}; };
@ -176,14 +176,14 @@ int main(int argc, char* argv[])
if (argc < 9) if (argc < 9)
{ {
NOD::SystemString outPath(argv[4]); nod::SystemString outPath(argv[4]);
outPath.append(_S(".iso")); outPath.append(_S(".iso"));
NOD::DiscBuilderWii b(outPath.c_str(), gameId.utf8_str().c_str(), gameTitle.utf8_str().c_str(), dual, progFunc); nod::DiscBuilderWii b(outPath.c_str(), gameId.utf8_str().c_str(), gameTitle.utf8_str().c_str(), dual, progFunc);
ret = b.buildFromDirectory(argv[4], argv[5], argv[6], argv[7]); ret = b.buildFromDirectory(argv[4], argv[5], argv[6], argv[7]);
} }
else else
{ {
NOD::DiscBuilderWii b(argv[8], gameId.utf8_str().c_str(), gameTitle.utf8_str().c_str(), dual, progFunc); nod::DiscBuilderWii b(argv[8], gameId.utf8_str().c_str(), gameTitle.utf8_str().c_str(), dual, progFunc);
ret = b.buildFromDirectory(argv[4], argv[5], argv[6], argv[7]); ret = b.buildFromDirectory(argv[4], argv[5], argv[6], argv[7]);
} }

View File

@ -3,7 +3,7 @@
#include "Util.hpp" #include "Util.hpp"
namespace NOD namespace nod
{ {
struct CaseInsensitiveCompare struct CaseInsensitiveCompare

View File

@ -12,7 +12,7 @@
#include "IDiscIO.hpp" #include "IDiscIO.hpp"
#include "IFileIO.hpp" #include "IFileIO.hpp"
namespace NOD namespace nod
{ {
class FSTNode class FSTNode
@ -150,7 +150,7 @@ public:
{ {
if (m_kind != Kind::File) if (m_kind != Kind::File)
{ {
LogModule.report(LogVisor::Error, "unable to stream a non-file %s", m_name.c_str()); LogModule.report(logvisor::Error, "unable to stream a non-file %s", m_name.c_str());
return std::unique_ptr<IPartReadStream>(); return std::unique_ptr<IPartReadStream>();
} }
return m_parent.beginReadStream(m_discOffset + offset); return m_parent.beginReadStream(m_discOffset + offset);
@ -159,7 +159,7 @@ public:
{ {
if (m_kind != Kind::File) if (m_kind != Kind::File)
{ {
LogModule.report(LogVisor::Error, "unable to buffer a non-file %s", m_name.c_str()); LogModule.report(logvisor::Error, "unable to buffer a non-file %s", m_name.c_str());
return std::unique_ptr<uint8_t[]>(); return std::unique_ptr<uint8_t[]>();
} }
uint8_t* buf = new uint8_t[m_discLength]; uint8_t* buf = new uint8_t[m_discLength];

View File

@ -3,7 +3,7 @@
#include "DiscBase.hpp" #include "DiscBase.hpp"
namespace NOD namespace nod
{ {
class DiscGCN : public DiscBase class DiscGCN : public DiscBase

View File

@ -3,7 +3,7 @@
#include "DiscBase.hpp" #include "DiscBase.hpp"
namespace NOD namespace nod
{ {
class DiscWii : public DiscBase class DiscWii : public DiscBase

View File

@ -7,11 +7,11 @@
#include <stdint.h> #include <stdint.h>
#if NOD_ATHENA #if NOD_ATHENA
#include <Athena/IStreamReader.hpp> #include <athena/IStreamReader.hpp>
#include <Athena/IStreamWriter.hpp> #include <athena/IStreamWriter.hpp>
#endif #endif
namespace NOD namespace nod
{ {
class IDiscIO class IDiscIO
@ -54,17 +54,17 @@ struct IPartWriteStream
#if NOD_ATHENA #if NOD_ATHENA
class AthenaPartReadStream : public Athena::io::IStreamReader class AthenaPartReadStream : public athena::io::IStreamReader
{ {
std::unique_ptr<IPartReadStream> m_rs; std::unique_ptr<IPartReadStream> m_rs;
public: public:
AthenaPartReadStream(std::unique_ptr<IPartReadStream>&& rs) : m_rs(std::move(rs)) {} AthenaPartReadStream(std::unique_ptr<IPartReadStream>&& rs) : m_rs(std::move(rs)) {}
inline void seek(atInt64 off, Athena::SeekOrigin origin) inline void seek(atInt64 off, athena::SeekOrigin origin)
{ {
if (origin == Athena::Begin) if (origin == athena::Begin)
m_rs->seek(off, SEEK_SET); m_rs->seek(off, SEEK_SET);
else if (origin == Athena::Current) else if (origin == athena::Current)
m_rs->seek(off, SEEK_CUR); m_rs->seek(off, SEEK_CUR);
} }
inline atUint64 position() const {return m_rs->position();} inline atUint64 position() const {return m_rs->position();}

View File

@ -6,7 +6,7 @@
#include "IDiscIO.hpp" #include "IDiscIO.hpp"
#include "Util.hpp" #include "Util.hpp"
namespace NOD namespace nod
{ {
class IFileIO class IFileIO

View File

@ -25,7 +25,7 @@
#include <string> #include <string>
#include <cstring> #include <cstring>
#include <algorithm> #include <algorithm>
#include <LogVisor/LogVisor.hpp> #include "logvisor/logvisor.hpp"
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(disable : 4996) #pragma warning(disable : 4996)
@ -47,7 +47,7 @@
#undef min #undef min
#undef max #undef max
namespace NOD namespace nod
{ {
/* define our own min/max to avoid MSVC BS */ /* define our own min/max to avoid MSVC BS */
template<typename T> template<typename T>
@ -56,7 +56,7 @@ template<typename T>
inline T max(T a, T b) { return a > b ? a : b; } inline T max(T a, T b) { return a > b ? a : b; }
/* Log Module */ /* Log Module */
extern LogVisor::LogModule LogModule; extern logvisor::Module LogModule;
/* filesystem char type */ /* filesystem char type */
#if _WIN32 && UNICODE #if _WIN32 && UNICODE
@ -272,7 +272,7 @@ static inline FILE* Fopen(const SystemChar* path, const SystemChar* mode, FileLo
LockFileEx((HANDLE)(uintptr_t)_fileno(fp), (lock == FileLockType::Write) ? LOCKFILE_EXCLUSIVE_LOCK : 0, 0, 0, 1, &ov); LockFileEx((HANDLE)(uintptr_t)_fileno(fp), (lock == FileLockType::Write) ? LOCKFILE_EXCLUSIVE_LOCK : 0, 0, 0, 1, &ov);
#else #else
if (flock(fileno(fp), ((lock == FileLockType::Write) ? LOCK_EX : LOCK_SH) | LOCK_NB)) if (flock(fileno(fp), ((lock == FileLockType::Write) ? LOCK_EX : LOCK_SH) | LOCK_NB))
LogModule.report(LogVisor::Error, "flock %s: %s", path, strerror(errno)); LogModule.report(logvisor::Error, "flock %s: %s", path, strerror(errno));
#endif #endif
} }
@ -309,16 +309,16 @@ static inline bool CheckFreeSpace(const SystemChar* path, size_t reqSz)
wchar_t* end; wchar_t* end;
DWORD ret = GetFullPathNameW(path, 1024, buf, &end); DWORD ret = GetFullPathNameW(path, 1024, buf, &end);
if (!ret || ret > 1024) if (!ret || ret > 1024)
LogModule.report(LogVisor::FatalError, _S("GetFullPathNameW %s"), path); LogModule.report(logvisor::Fatal, _S("GetFullPathNameW %s"), path);
if (end) if (end)
end[0] = L'\0'; end[0] = L'\0';
if (!GetDiskFreeSpaceExW(buf, &freeBytes, nullptr, nullptr)) if (!GetDiskFreeSpaceExW(buf, &freeBytes, nullptr, nullptr))
LogModule.report(LogVisor::FatalError, _S("GetDiskFreeSpaceExW %s: %d"), path, GetLastError()); LogModule.report(logvisor::Fatal, _S("GetDiskFreeSpaceExW %s: %d"), path, GetLastError());
return reqSz < freeBytes.QuadPart; return reqSz < freeBytes.QuadPart;
#else #else
struct statvfs svfs; struct statvfs svfs;
if (statvfs(path, &svfs)) if (statvfs(path, &svfs))
LogModule.report(LogVisor::FatalError, "statvfs %s: %s", path, strerror(errno)); LogModule.report(logvisor::Fatal, "statvfs %s: %s", path, strerror(errno));
return reqSz < svfs.f_frsize * svfs.f_bavail; return reqSz < svfs.f_frsize * svfs.f_bavail;
#endif #endif
} }

View File

@ -5,7 +5,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <memory> #include <memory>
namespace NOD namespace nod
{ {
class IAES class IAES

View File

@ -3,10 +3,10 @@
#include <memory> #include <memory>
#include <functional> #include <functional>
#include <LogVisor/LogVisor.hpp> #include "logvisor/logvisor.hpp"
#include "Util.hpp" #include "Util.hpp"
namespace NOD namespace nod
{ {
class DiscBase; class DiscBase;

View File

@ -4,7 +4,7 @@ set(PLAT_SRCS FileIOFILE.cpp)
else() else()
set(PLAT_SRCS FileIOWin32.cpp) set(PLAT_SRCS FileIOWin32.cpp)
endif() endif()
add_library(NOD add_library(nod
aes.cpp aes.cpp
sha1.c sha1.c
DiscBase.cpp DiscBase.cpp
@ -13,9 +13,9 @@ add_library(NOD
DiscIOWBFS.cpp DiscIOWBFS.cpp
DiscWii.cpp DiscWii.cpp
DirectoryEnumerator.cpp DirectoryEnumerator.cpp
NOD.cpp nod.cpp
${PLAT_SRCS} ${PLAT_SRCS}
${NOD_HEADERS}) ${NOD_HEADERS})
if(NOT WIN32) if(NOT MSVC)
set_source_files_properties(aes.cpp PROPERTIES COMPILE_FLAGS -maes) set_source_files_properties(aes.cpp PROPERTIES COMPILE_FLAGS -maes)
endif() endif()

View File

@ -7,9 +7,9 @@
#include <map> #include <map>
#include "NOD/DirectoryEnumerator.hpp" #include "nod/DirectoryEnumerator.hpp"
namespace NOD namespace nod
{ {
DirectoryEnumerator::DirectoryEnumerator(const SystemChar* path, Mode mode, DirectoryEnumerator::DirectoryEnumerator(const SystemChar* path, Mode mode,

View File

@ -1,7 +1,7 @@
#include "NOD/DiscBase.hpp" #include "nod/DiscBase.hpp"
#include "NOD/IFileIO.hpp" #include "nod/IFileIO.hpp"
#include "NOD/DirectoryEnumerator.hpp" #include "nod/DirectoryEnumerator.hpp"
#include "NOD/NOD.hpp" #include "nod/nod.hpp"
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
@ -35,7 +35,7 @@ static void* memmem(const void *haystack, size_t hlen, const void *needle, size_
#include <algorithm> #include <algorithm>
namespace NOD namespace nod
{ {
void DiscBase::IPartition::parseFST(IPartReadStream& s) void DiscBase::IPartition::parseFST(IPartReadStream& s)
@ -101,7 +101,7 @@ bool DiscBase::IPartition::Node::extractToDirectory(const SystemString& basePath
ctx.progressCB(getName()); ctx.progressCB(getName());
if (Mkdir(path.c_str(), 0755) && errno != EEXIST) if (Mkdir(path.c_str(), 0755) && errno != EEXIST)
{ {
LogModule.report(LogVisor::Error, _S("unable to mkdir '%s'"), path.c_str()); LogModule.report(logvisor::Error, _S("unable to mkdir '%s'"), path.c_str());
return false; return false;
} }
for (Node& subnode : *this) for (Node& subnode : *this)
@ -130,7 +130,7 @@ bool DiscBase::IPartition::extractToDirectory(const SystemString& path,
Sstat theStat; Sstat theStat;
if (Mkdir(path.c_str(), 0755) && errno != EEXIST) if (Mkdir(path.c_str(), 0755) && errno != EEXIST)
{ {
LogModule.report(LogVisor::Error, _S("unable to mkdir '%s'"), path.c_str()); LogModule.report(logvisor::Error, _S("unable to mkdir '%s'"), path.c_str());
return false; return false;
} }
@ -158,7 +158,7 @@ bool DiscBase::IPartition::extractToDirectory(const SystemString& path,
SystemString fsPath = path + _S("/fsroot"); SystemString fsPath = path + _S("/fsroot");
if (Mkdir(fsPath.c_str(), 0755) && errno != EEXIST) if (Mkdir(fsPath.c_str(), 0755) && errno != EEXIST)
{ {
LogModule.report(LogVisor::Error, _S("unable to mkdir '%s'"), fsPath.c_str()); LogModule.report(logvisor::Error, _S("unable to mkdir '%s'"), fsPath.c_str());
return false; return false;
} }
@ -177,17 +177,17 @@ static uint64_t GetInode(const SystemChar* path)
FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL,
nullptr); nullptr);
if (!fp) if (!fp)
LogModule.report(LogVisor::FatalError, _S("unable to open %s"), path); LogModule.report(logvisor::Fatal, _S("unable to open %s"), path);
BY_HANDLE_FILE_INFORMATION info; BY_HANDLE_FILE_INFORMATION info;
if (!GetFileInformationByHandle(fp, &info)) if (!GetFileInformationByHandle(fp, &info))
LogModule.report(LogVisor::FatalError, _S("unable to GetFileInformationByHandle %s"), path); LogModule.report(logvisor::Fatal, _S("unable to GetFileInformationByHandle %s"), path);
inode = uint64_t(info.nFileIndexHigh) << 32; inode = uint64_t(info.nFileIndexHigh) << 32;
inode |= uint64_t(info.nFileIndexLow); inode |= uint64_t(info.nFileIndexLow);
CloseHandle(fp); CloseHandle(fp);
#else #else
struct stat st; struct stat st;
if (stat(path, &st)) if (stat(path, &st))
LogModule.report(LogVisor::FatalError, _S("unable to stat %s"), path); LogModule.report(logvisor::Fatal, _S("unable to stat %s"), path);
inode = uint64_t(st.st_ino); inode = uint64_t(st.st_ino);
#endif #endif
return inode; return inode;
@ -277,7 +277,7 @@ void DiscBuilderBase::PartitionBuilderBase::recursiveBuildNodes(IPartWriteStream
++m_parent.m_progressIdx; ++m_parent.m_progressIdx;
while (xferSz < e.m_fileSz) while (xferSz < e.m_fileSz)
{ {
size_t rdSz = rs->read(buf, NOD::min(size_t(0x8000ul), e.m_fileSz - xferSz)); size_t rdSz = rs->read(buf, nod::min(size_t(0x8000ul), e.m_fileSz - xferSz));
if (!rdSz) if (!rdSz)
break; break;
ws.write(buf, rdSz); ws.write(buf, rdSz);
@ -329,7 +329,7 @@ bool DiscBuilderBase::PartitionBuilderBase::buildFromDirectory(IPartWriteStream&
const SystemChar* apploaderIn) const SystemChar* apploaderIn)
{ {
if (!dirIn || !dolIn || !apploaderIn) if (!dirIn || !dolIn || !apploaderIn)
LogModule.report(LogVisor::FatalError, _S("all arguments must be supplied to buildFromDirectory()")); LogModule.report(logvisor::Fatal, _S("all arguments must be supplied to buildFromDirectory()"));
/* Clear file */ /* Clear file */
++m_parent.m_progressIdx; ++m_parent.m_progressIdx;
@ -343,7 +343,7 @@ bool DiscBuilderBase::PartitionBuilderBase::buildFromDirectory(IPartWriteStream&
{ {
Sstat dolStat; Sstat dolStat;
if (Stat(dolIn, &dolStat)) if (Stat(dolIn, &dolStat))
LogModule.report(LogVisor::FatalError, _S("unable to stat %s"), dolIn); LogModule.report(logvisor::Fatal, _S("unable to stat %s"), dolIn);
size_t fileSz = ROUND_UP_32(dolStat.st_size); size_t fileSz = ROUND_UP_32(dolStat.st_size);
uint64_t fileOff = userAllocate(fileSz, ws); uint64_t fileOff = userAllocate(fileSz, ws);
m_dolOffset = fileOff; m_dolOffset = fileOff;

View File

@ -1,7 +1,7 @@
#include "NOD/DiscGCN.hpp" #include "nod/DiscGCN.hpp"
#define BUFFER_SZ 0x8000 #define BUFFER_SZ 0x8000
namespace NOD namespace nod
{ {
class PartitionGCN : public DiscBase::IPartition class PartitionGCN : public DiscBase::IPartition
@ -152,7 +152,7 @@ public:
m_curUser &= 0xfffffffffffffff0; m_curUser &= 0xfffffffffffffff0;
if (m_curUser < 0x30000) if (m_curUser < 0x30000)
{ {
LogModule.report(LogVisor::FatalError, "user area low mark reached"); LogModule.report(logvisor::Fatal, "user area low mark reached");
return -1; return -1;
} }
static_cast<PartWriteStream&>(ws).seek(m_curUser); static_cast<PartWriteStream&>(ws).seek(m_curUser);
@ -194,7 +194,7 @@ public:
ws->write(buf, rdSz); ws->write(buf, rdSz);
xferSz += rdSz; xferSz += rdSz;
if (0x2440 + xferSz >= m_curUser) if (0x2440 + xferSz >= m_curUser)
LogModule.report(LogVisor::FatalError, LogModule.report(logvisor::Fatal,
"apploader flows into user area (one or the other is too big)"); "apploader flows into user area (one or the other is too big)");
m_parent.m_progressCB(m_parent.m_progressIdx, apploaderName, xferSz); m_parent.m_progressCB(m_parent.m_progressIdx, apploaderName, xferSz);
} }
@ -211,7 +211,7 @@ public:
fstSz = ROUND_UP_32(fstSz); fstSz = ROUND_UP_32(fstSz);
if (fstOff + fstSz >= m_curUser) if (fstOff + fstSz >= m_curUser)
LogModule.report(LogVisor::FatalError, LogModule.report(logvisor::Fatal,
"FST flows into user area (one or the other is too big)"); "FST flows into user area (one or the other is too big)");
ws = beginWriteStream(0x420); ws = beginWriteStream(0x420);
@ -236,7 +236,7 @@ bool DiscBuilderGCN::buildFromDirectory(const SystemChar* dirIn, const SystemCha
if (!CheckFreeSpace(m_outPath, 0x57058000)) if (!CheckFreeSpace(m_outPath, 0x57058000))
{ {
LogModule.report(LogVisor::Error, _S("not enough free disk space for %s"), m_outPath); LogModule.report(logvisor::Error, _S("not enough free disk space for %s"), m_outPath);
return false; return false;
} }
++m_progressIdx; ++m_progressIdx;

View File

@ -1,9 +1,9 @@
#include <stdio.h> #include <stdio.h>
#include "NOD/Util.hpp" #include "nod/Util.hpp"
#include "NOD/IDiscIO.hpp" #include "nod/IDiscIO.hpp"
#include "NOD/IFileIO.hpp" #include "nod/IFileIO.hpp"
namespace NOD namespace nod
{ {
class DiscIOISO : public IDiscIO class DiscIOISO : public IDiscIO

View File

@ -1,10 +1,10 @@
#include <stdio.h> #include <stdio.h>
#include <inttypes.h> #include <inttypes.h>
#include "NOD/Util.hpp" #include "nod/Util.hpp"
#include "NOD/IDiscIO.hpp" #include "nod/IDiscIO.hpp"
#include "NOD/IFileIO.hpp" #include "nod/IFileIO.hpp"
namespace NOD namespace nod
{ {
#define ALIGN_LBA(x) (((x)+p->hd_sec_sz-1)&(~(p->hd_sec_sz-1))) #define ALIGN_LBA(x) (((x)+p->hd_sec_sz-1)&(~(p->hd_sec_sz-1)))
@ -80,7 +80,7 @@ class DiscIOWBFS : public IDiscIO
rs.seek(off, SEEK_SET); rs.seek(off, SEEK_SET);
if (rs.read(buf, count*512ULL) != count*512ULL) if (rs.read(buf, count*512ULL) != count*512ULL)
{ {
LogModule.report(LogVisor::FatalError, "error reading disc"); LogModule.report(logvisor::Fatal, "error reading disc");
return 1; return 1;
} }
return 0; return 0;
@ -97,7 +97,7 @@ public:
WBFS* p = &wbfs; WBFS* p = &wbfs;
WBFSHead tmpHead; WBFSHead tmpHead;
if (rs->read(&tmpHead, sizeof(tmpHead)) != sizeof(tmpHead)) if (rs->read(&tmpHead, sizeof(tmpHead)) != sizeof(tmpHead))
LogModule.report(LogVisor::FatalError, "unable to read WBFS head"); LogModule.report(logvisor::Fatal, "unable to read WBFS head");
unsigned hd_sector_size = 1 << tmpHead.hd_sec_sz_s; unsigned hd_sector_size = 1 << tmpHead.hd_sec_sz_s;
unsigned num_hd_sector = SBig(tmpHead.n_hd_sec); unsigned num_hd_sector = SBig(tmpHead.n_hd_sec);
@ -105,7 +105,7 @@ public:
WBFSHead* head = (WBFSHead*)wbfsHead.get(); WBFSHead* head = (WBFSHead*)wbfsHead.get();
rs->seek(0, SEEK_SET); rs->seek(0, SEEK_SET);
if (rs->read(head, hd_sector_size) != hd_sector_size) if (rs->read(head, hd_sector_size) != hd_sector_size)
LogModule.report(LogVisor::FatalError, "unable to read WBFS head"); LogModule.report(logvisor::Fatal, "unable to read WBFS head");
//constants, but put here for consistancy //constants, but put here for consistancy
p->wii_sec_sz = 0x8000; p->wii_sec_sz = 0x8000;
@ -115,10 +115,10 @@ public:
p->part_lba = 0; p->part_lba = 0;
_wbfsReadSector(*rs, p->part_lba, 1, head); _wbfsReadSector(*rs, p->part_lba, 1, head);
if (hd_sector_size && head->hd_sec_sz_s != size_to_shift(hd_sector_size)) { if (hd_sector_size && head->hd_sec_sz_s != size_to_shift(hd_sector_size)) {
LogModule.report(LogVisor::FatalError, "hd sector size doesn't match"); LogModule.report(logvisor::Fatal, "hd sector size doesn't match");
} }
if (num_hd_sector && head->n_hd_sec != SBig(num_hd_sector)) { if (num_hd_sector && head->n_hd_sec != SBig(num_hd_sector)) {
LogModule.report(LogVisor::FatalError, "hd num sector doesn't match"); LogModule.report(logvisor::Fatal, "hd num sector doesn't match");
} }
p->hd_sec_sz = 1<<head->hd_sec_sz_s; p->hd_sec_sz = 1<<head->hd_sec_sz_s;
p->hd_sec_sz_s = head->hd_sec_sz_s; p->hd_sec_sz_s = head->hd_sec_sz_s;
@ -146,7 +146,7 @@ public:
{ {
wbfsDiscInfo.reset(new uint8_t[p->disc_info_sz]); wbfsDiscInfo.reset(new uint8_t[p->disc_info_sz]);
if (!wbfsDiscInfo) if (!wbfsDiscInfo)
LogModule.report(LogVisor::FatalError, "allocating memory"); LogModule.report(logvisor::Fatal, "allocating memory");
_wbfsReadSector(*rs, p->part_lba+1, disc_info_sz_lba, wbfsDiscInfo.get()); _wbfsReadSector(*rs, p->part_lba+1, disc_info_sz_lba, wbfsDiscInfo.get());
p->n_disc_open++; p->n_disc_open++;
//for(i=0;i<p->n_wbfs_sec_per_disc;i++) //for(i=0;i<p->n_wbfs_sec_per_disc;i++)

View File

@ -1,10 +1,10 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "NOD/DiscWii.hpp" #include "nod/DiscWii.hpp"
#include "NOD/aes.hpp" #include "nod/aes.hpp"
#include "NOD/sha1.h" #include "nod/sha1.h"
namespace NOD namespace nod
{ {
static const uint8_t COMMON_KEYS[2][16] = static const uint8_t COMMON_KEYS[2][16] =
@ -348,7 +348,7 @@ public:
std::unique_ptr<IDiscIO::IReadStream> rs = m_parent.getDiscIO().beginReadStream(m_offset + 0x2B4); std::unique_ptr<IDiscIO::IReadStream> rs = m_parent.getDiscIO().beginReadStream(m_offset + 0x2B4);
uint32_t h3; uint32_t h3;
if (rs->read(&h3, 4) != 4) if (rs->read(&h3, 4) != 4)
LogModule.report(LogVisor::FatalError, _S("unable to read H3 offset from %s"), pathOut); LogModule.report(logvisor::Fatal, _S("unable to read H3 offset from %s"), pathOut);
h3 = SBig(h3); h3 = SBig(h3);
h3Off = uint64_t(h3) << 2; h3Off = uint64_t(h3) << 2;
} }
@ -358,7 +358,7 @@ public:
std::unique_ptr<IDiscIO::IReadStream> rs = m_parent.getDiscIO().beginReadStream(m_offset); std::unique_ptr<IDiscIO::IReadStream> rs = m_parent.getDiscIO().beginReadStream(m_offset);
while (rem) while (rem)
{ {
size_t rdSz = NOD::min(rem, size_t(8192ul)); size_t rdSz = nod::min(rem, size_t(8192ul));
rs->read(buf, rdSz); rs->read(buf, rdSz);
ws->write(buf, rdSz); ws->write(buf, rdSz);
rem -= rdSz; rem -= rdSz;
@ -410,7 +410,7 @@ DiscWii::DiscWii(std::unique_ptr<IDiscIO>&& dio)
kind = part.partType; kind = part.partType;
break; break;
default: default:
LogModule.report(LogVisor::FatalError, "invalid partition type %d", part.partType); LogModule.report(logvisor::Fatal, "invalid partition type %d", part.partType);
} }
m_partitions.emplace_back(new PartitionWii(*this, kind, part.partDataOff << 2)); m_partitions.emplace_back(new PartitionWii(*this, kind, part.partDataOff << 2));
} }
@ -512,7 +512,7 @@ public:
} }
if (m_fio->write(m_buf, 0x200000) != 0x200000) if (m_fio->write(m_buf, 0x200000) != 0x200000)
LogModule.report(LogVisor::FatalError, "unable to write full disc group"); LogModule.report(logvisor::Fatal, "unable to write full disc group");
} }
public: public:
@ -520,7 +520,7 @@ public:
: m_parent(parent), m_baseOffset(baseOffset), m_offset(offset) : m_parent(parent), m_baseOffset(baseOffset), m_offset(offset)
{ {
if (offset % 0x1F0000) if (offset % 0x1F0000)
LogModule.report(LogVisor::FatalError, "partition write stream MUST begin on 0x1F0000-aligned boundary"); LogModule.report(logvisor::Fatal, "partition write stream MUST begin on 0x1F0000-aligned boundary");
size_t group = m_offset / 0x1F0000; size_t group = m_offset / 0x1F0000;
m_fio = m_parent.m_parent.getFileIO().beginWriteStream(m_baseOffset + group * 0x200000); m_fio = m_parent.m_parent.getFileIO().beginWriteStream(m_baseOffset + group * 0x200000);
m_curGroup = group; m_curGroup = group;
@ -597,14 +597,14 @@ public:
reqSz = ROUND_UP_32(reqSz); reqSz = ROUND_UP_32(reqSz);
if (m_curUser + reqSz >= 0x1FB450000) if (m_curUser + reqSz >= 0x1FB450000)
{ {
LogModule.report(LogVisor::FatalError, "partition exceeds maximum single-partition capacity"); LogModule.report(logvisor::Fatal, "partition exceeds maximum single-partition capacity");
return -1; return -1;
} }
uint64_t ret = m_curUser; uint64_t ret = m_curUser;
PartWriteStream& cws = static_cast<PartWriteStream&>(ws); PartWriteStream& cws = static_cast<PartWriteStream&>(ws);
if (cws.m_offset > ret) if (cws.m_offset > ret)
{ {
LogModule.report(LogVisor::FatalError, "partition overwrite error"); LogModule.report(logvisor::Fatal, "partition overwrite error");
return -1; return -1;
} }
while (cws.m_offset < ret) while (cws.m_offset < ret)
@ -634,27 +634,27 @@ public:
uint8_t tkey[16]; uint8_t tkey[16];
{ {
if (ph->beginReadStream(0x1BF)->read(tkey, 16) != 16) if (ph->beginReadStream(0x1BF)->read(tkey, 16) != 16)
LogModule.report(LogVisor::FatalError, _S("unable to read title key from %s"), partHeadIn); LogModule.report(logvisor::Fatal, _S("unable to read title key from %s"), partHeadIn);
} }
uint8_t tkeyiv[16] = {}; uint8_t tkeyiv[16] = {};
{ {
if (ph->beginReadStream(0x1DC)->read(tkeyiv, 8) != 8) if (ph->beginReadStream(0x1DC)->read(tkeyiv, 8) != 8)
LogModule.report(LogVisor::FatalError, _S("unable to read title key IV from %s"), partHeadIn); LogModule.report(logvisor::Fatal, _S("unable to read title key IV from %s"), partHeadIn);
} }
uint8_t ccIdx; uint8_t ccIdx;
{ {
if (ph->beginReadStream(0x1F1)->read(&ccIdx, 1) != 1) if (ph->beginReadStream(0x1F1)->read(&ccIdx, 1) != 1)
LogModule.report(LogVisor::FatalError, _S("unable to read common key index from %s"), partHeadIn); LogModule.report(logvisor::Fatal, _S("unable to read common key index from %s"), partHeadIn);
if (ccIdx > 1) if (ccIdx > 1)
LogModule.report(LogVisor::FatalError, _S("common key index may only be 0 or 1")); LogModule.report(logvisor::Fatal, _S("common key index may only be 0 or 1"));
} }
uint32_t tmdSz; uint32_t tmdSz;
{ {
if (ph->beginReadStream(0x2A4)->read(&tmdSz, 4) != 4) if (ph->beginReadStream(0x2A4)->read(&tmdSz, 4) != 4)
LogModule.report(LogVisor::FatalError, _S("unable to read TMD size from %s"), partHeadIn); LogModule.report(logvisor::Fatal, _S("unable to read TMD size from %s"), partHeadIn);
tmdSz = SBig(tmdSz); tmdSz = SBig(tmdSz);
} }
@ -662,7 +662,7 @@ public:
{ {
uint32_t h3Ptr; uint32_t h3Ptr;
if (ph->beginReadStream(0x2B4)->read(&h3Ptr, 4) != 4) if (ph->beginReadStream(0x2B4)->read(&h3Ptr, 4) != 4)
LogModule.report(LogVisor::FatalError, _S("unable to read H3 pointer from %s"), partHeadIn); LogModule.report(logvisor::Fatal, _S("unable to read H3 pointer from %s"), partHeadIn);
h3Off = uint64_t(SBig(h3Ptr)) << 2; h3Off = uint64_t(SBig(h3Ptr)) << 2;
} }
@ -670,14 +670,14 @@ public:
{ {
uint32_t dataPtr; uint32_t dataPtr;
if (ph->beginReadStream(0x2B8)->read(&dataPtr, 4) != 4) if (ph->beginReadStream(0x2B8)->read(&dataPtr, 4) != 4)
LogModule.report(LogVisor::FatalError, _S("unable to read data pointer from %s"), partHeadIn); LogModule.report(logvisor::Fatal, _S("unable to read data pointer from %s"), partHeadIn);
dataOff = uint64_t(SBig(dataPtr)) << 2; dataOff = uint64_t(SBig(dataPtr)) << 2;
} }
m_userOffset = dataOff; m_userOffset = dataOff;
std::unique_ptr<uint8_t[]> tmdData(new uint8_t[tmdSz]); std::unique_ptr<uint8_t[]> tmdData(new uint8_t[tmdSz]);
if (ph->beginReadStream(0x2C0)->read(tmdData.get(), tmdSz) != tmdSz) if (ph->beginReadStream(0x2C0)->read(tmdData.get(), tmdSz) != tmdSz)
LogModule.report(LogVisor::FatalError, _S("unable to read TMD from %s"), partHeadIn); LogModule.report(logvisor::Fatal, _S("unable to read TMD from %s"), partHeadIn);
/* Copy partition head up to H3 table */ /* Copy partition head up to H3 table */
std::unique_ptr<IFileIO::IWriteStream> ws = m_parent.getFileIO().beginWriteStream(m_baseOffset); std::unique_ptr<IFileIO::IWriteStream> ws = m_parent.getFileIO().beginWriteStream(m_baseOffset);
@ -732,7 +732,7 @@ public:
/* Get Apploader Size */ /* Get Apploader Size */
Sstat theStat; Sstat theStat;
if (Stat(apploaderIn, &theStat)) if (Stat(apploaderIn, &theStat))
LogModule.report(LogVisor::FatalError, _S("unable to stat %s"), apploaderIn); LogModule.report(logvisor::Fatal, _S("unable to stat %s"), apploaderIn);
/* Compute boot table members and write */ /* Compute boot table members and write */
size_t fstOff = 0x2440 + ROUND_UP_32(theStat.st_size); size_t fstOff = 0x2440 + ROUND_UP_32(theStat.st_size);
@ -741,7 +741,7 @@ public:
fstSz = ROUND_UP_32(fstSz); fstSz = ROUND_UP_32(fstSz);
if (fstOff + fstSz >= 0x1F0000) if (fstOff + fstSz >= 0x1F0000)
LogModule.report(LogVisor::FatalError, LogModule.report(logvisor::Fatal,
"FST flows into user area (one or the other is too big)"); "FST flows into user area (one or the other is too big)");
cws->write(nullptr, 0x420 - sizeof(Header)); cws->write(nullptr, 0x420 - sizeof(Header));
@ -767,14 +767,14 @@ public:
cws->write(buf, rdSz); cws->write(buf, rdSz);
xferSz += rdSz; xferSz += rdSz;
if (0x2440 + xferSz >= 0x1F0000) if (0x2440 + xferSz >= 0x1F0000)
LogModule.report(LogVisor::FatalError, LogModule.report(logvisor::Fatal,
"apploader flows into user area (one or the other is too big)"); "apploader flows into user area (one or the other is too big)");
m_parent.m_progressCB(m_parent.m_progressIdx, apploaderName, xferSz); m_parent.m_progressCB(m_parent.m_progressIdx, apploaderName, xferSz);
} }
size_t fstOffRel = fstOff - 0x2440; size_t fstOffRel = fstOff - 0x2440;
if (xferSz > fstOffRel) if (xferSz > fstOffRel)
LogModule.report(LogVisor::FatalError, "apploader unexpectedly flows into FST"); LogModule.report(logvisor::Fatal, "apploader unexpectedly flows into FST");
for (size_t i=0 ; i<fstOffRel-xferSz ; ++i) for (size_t i=0 ; i<fstOffRel-xferSz ; ++i)
cws->write("\xff", 1); cws->write("\xff", 1);
@ -856,7 +856,7 @@ bool DiscBuilderWii::buildFromDirectory(const SystemChar* dirIn, const SystemCha
if (!CheckFreeSpace(m_outPath, m_discCapacity)) if (!CheckFreeSpace(m_outPath, m_discCapacity))
{ {
LogModule.report(LogVisor::Error, _S("not enough free disk space for %s"), m_outPath); LogModule.report(logvisor::Error, _S("not enough free disk space for %s"), m_outPath);
return false; return false;
} }
++m_progressIdx; ++m_progressIdx;
@ -867,7 +867,7 @@ bool DiscBuilderWii::buildFromDirectory(const SystemChar* dirIn, const SystemCha
filledSz = pb.buildFromDirectory(dirIn, dolIn, apploaderIn, partHeadIn); filledSz = pb.buildFromDirectory(dirIn, dolIn, apploaderIn, partHeadIn);
if (filledSz >= m_discCapacity) if (filledSz >= m_discCapacity)
{ {
LogModule.report(LogVisor::FatalError, "data partition exceeds disc capacity"); LogModule.report(logvisor::Fatal, "data partition exceeds disc capacity");
return false; return false;
} }

View File

@ -1,10 +1,10 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <inttypes.h> #include <inttypes.h>
#include "NOD/Util.hpp" #include "nod/Util.hpp"
#include "NOD/IFileIO.hpp" #include "nod/IFileIO.hpp"
namespace NOD namespace nod
{ {
class FileIOFILE : public IFileIO class FileIOFILE : public IFileIO
@ -46,7 +46,7 @@ public:
{ {
fp = fopen(path.c_str(), "wb"); fp = fopen(path.c_str(), "wb");
if (!fp) if (!fp)
LogModule.report(LogVisor::FatalError, _S("unable to open '%s' for writing"), path.c_str()); LogModule.report(logvisor::Fatal, _S("unable to open '%s' for writing"), path.c_str());
} }
WriteStream(const SystemString& path, uint64_t offset, int64_t maxWriteSize) WriteStream(const SystemString& path, uint64_t offset, int64_t maxWriteSize)
: m_maxWriteSize(maxWriteSize) : m_maxWriteSize(maxWriteSize)
@ -61,7 +61,7 @@ public:
FSeek(fp, offset, SEEK_SET); FSeek(fp, offset, SEEK_SET);
return; return;
FailLoc: FailLoc:
LogModule.report(LogVisor::FatalError, _S("unable to open '%s' for writing"), path.c_str()); LogModule.report(logvisor::Fatal, _S("unable to open '%s' for writing"), path.c_str());
} }
~WriteStream() ~WriteStream()
{ {
@ -72,7 +72,7 @@ public:
if (m_maxWriteSize >= 0) if (m_maxWriteSize >= 0)
{ {
if (FTell(fp) + length > m_maxWriteSize) if (FTell(fp) + length > m_maxWriteSize)
LogModule.report(LogVisor::FatalError, _S("write operation exceeds file's %" PRIi64 "-byte limit"), m_maxWriteSize); LogModule.report(logvisor::Fatal, _S("write operation exceeds file's %" PRIi64 "-byte limit"), m_maxWriteSize);
} }
return fwrite(buf, 1, length, fp); return fwrite(buf, 1, length, fp);
} }
@ -82,16 +82,16 @@ public:
uint8_t buf[0x7c00]; uint8_t buf[0x7c00];
while (length) while (length)
{ {
uint64_t thisSz = NOD::min(uint64_t(0x7c00), length); uint64_t thisSz = nod::min(uint64_t(0x7c00), length);
uint64_t readSz = discio.read(buf, thisSz); uint64_t readSz = discio.read(buf, thisSz);
if (thisSz != readSz) if (thisSz != readSz)
{ {
LogModule.report(LogVisor::FatalError, "unable to read enough from disc"); LogModule.report(logvisor::Fatal, "unable to read enough from disc");
return read; return read;
} }
if (write(buf, readSz) != readSz) if (write(buf, readSz) != readSz)
{ {
LogModule.report(LogVisor::FatalError, "unable to write in file"); LogModule.report(logvisor::Fatal, "unable to write in file");
return read; return read;
} }
length -= thisSz; length -= thisSz;
@ -116,7 +116,7 @@ public:
{ {
fp = fopen(path.c_str(), "rb"); fp = fopen(path.c_str(), "rb");
if (!fp) if (!fp)
LogModule.report(LogVisor::FatalError, _S("unable to open '%s' for reading"), path.c_str()); LogModule.report(logvisor::Fatal, _S("unable to open '%s' for reading"), path.c_str());
} }
ReadStream(const SystemString& path, uint64_t offset) ReadStream(const SystemString& path, uint64_t offset)
: ReadStream(path) : ReadStream(path)
@ -145,15 +145,15 @@ public:
uint8_t buf[0x7c00]; uint8_t buf[0x7c00];
while (length) while (length)
{ {
uint64_t thisSz = NOD::min(uint64_t(0x7c00), length); uint64_t thisSz = nod::min(uint64_t(0x7c00), length);
if (read(buf, thisSz) != thisSz) if (read(buf, thisSz) != thisSz)
{ {
LogModule.report(LogVisor::FatalError, "unable to read enough from file"); LogModule.report(logvisor::Fatal, "unable to read enough from file");
return written; return written;
} }
if (discio.write(buf, thisSz) != thisSz) if (discio.write(buf, thisSz) != thisSz)
{ {
LogModule.report(LogVisor::FatalError, "unable to write enough to disc"); LogModule.report(logvisor::Fatal, "unable to write enough to disc");
return written; return written;
} }
length -= thisSz; length -= thisSz;

View File

@ -1,10 +1,10 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <inttypes.h> #include <inttypes.h>
#include "NOD/Util.hpp" #include "nod/Util.hpp"
#include "NOD/IFileIO.hpp" #include "nod/IFileIO.hpp"
namespace NOD namespace nod
{ {
class FileIOWin32 : public IFileIO class FileIOWin32 : public IFileIO
@ -53,7 +53,7 @@ public:
fp = CreateFileW(path.c_str(), GENERIC_WRITE, FILE_SHARE_WRITE, fp = CreateFileW(path.c_str(), GENERIC_WRITE, FILE_SHARE_WRITE,
nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
if (fp == INVALID_HANDLE_VALUE) if (fp == INVALID_HANDLE_VALUE)
LogModule.report(LogVisor::FatalError, _S("unable to open '%s' for writing"), path.c_str()); LogModule.report(logvisor::Fatal, _S("unable to open '%s' for writing"), path.c_str());
} }
WriteStream(const SystemString& path, uint64_t offset, int64_t maxWriteSize) WriteStream(const SystemString& path, uint64_t offset, int64_t maxWriteSize)
: m_maxWriteSize(maxWriteSize) : m_maxWriteSize(maxWriteSize)
@ -61,7 +61,7 @@ public:
fp = CreateFileW(path.c_str(), GENERIC_WRITE, FILE_SHARE_WRITE, fp = CreateFileW(path.c_str(), GENERIC_WRITE, FILE_SHARE_WRITE,
nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
if (fp == INVALID_HANDLE_VALUE) if (fp == INVALID_HANDLE_VALUE)
LogModule.report(LogVisor::FatalError, _S("unable to open '%s' for writing"), path.c_str()); LogModule.report(logvisor::Fatal, _S("unable to open '%s' for writing"), path.c_str());
LARGE_INTEGER lioffset; LARGE_INTEGER lioffset;
lioffset.QuadPart = offset; lioffset.QuadPart = offset;
SetFilePointerEx(fp, lioffset, nullptr, FILE_BEGIN); SetFilePointerEx(fp, lioffset, nullptr, FILE_BEGIN);
@ -78,7 +78,7 @@ public:
LARGE_INTEGER res; LARGE_INTEGER res;
SetFilePointerEx(fp, li, &res, FILE_CURRENT); SetFilePointerEx(fp, li, &res, FILE_CURRENT);
if (res.QuadPart + int64_t(length) > m_maxWriteSize) if (res.QuadPart + int64_t(length) > m_maxWriteSize)
LogModule.report(LogVisor::FatalError, _S("write operation exceeds file's %" PRIi64 "-byte limit"), m_maxWriteSize); LogModule.report(logvisor::Fatal, _S("write operation exceeds file's %" PRIi64 "-byte limit"), m_maxWriteSize);
} }
DWORD ret = 0; DWORD ret = 0;
@ -91,16 +91,16 @@ public:
uint8_t buf[0x7c00]; uint8_t buf[0x7c00];
while (length) while (length)
{ {
uint64_t thisSz = NOD::min(uint64_t(0x7c00), length); uint64_t thisSz = nod::min(uint64_t(0x7c00), length);
uint64_t readSz = discio.read(buf, thisSz); uint64_t readSz = discio.read(buf, thisSz);
if (thisSz != readSz) if (thisSz != readSz)
{ {
LogModule.report(LogVisor::FatalError, "unable to read enough from disc"); LogModule.report(logvisor::Fatal, "unable to read enough from disc");
return read; return read;
} }
if (write(buf, readSz) != readSz) if (write(buf, readSz) != readSz)
{ {
LogModule.report(LogVisor::FatalError, "unable to write in file"); LogModule.report(logvisor::Fatal, "unable to write in file");
return read; return read;
} }
length -= thisSz; length -= thisSz;
@ -126,7 +126,7 @@ public:
fp = CreateFileW(path.c_str(), GENERIC_READ, FILE_SHARE_READ, fp = CreateFileW(path.c_str(), GENERIC_READ, FILE_SHARE_READ,
nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
if (fp == INVALID_HANDLE_VALUE) if (fp == INVALID_HANDLE_VALUE)
LogModule.report(LogVisor::FatalError, _S("unable to open '%s' for reading"), path.c_str()); LogModule.report(logvisor::Fatal, _S("unable to open '%s' for reading"), path.c_str());
} }
ReadStream(const SystemString& path, uint64_t offset) ReadStream(const SystemString& path, uint64_t offset)
: ReadStream(path) : ReadStream(path)
@ -164,15 +164,15 @@ public:
uint8_t buf[0x7c00]; uint8_t buf[0x7c00];
while (length) while (length)
{ {
uint64_t thisSz = NOD::min(uint64_t(0x7c00), length); uint64_t thisSz = nod::min(uint64_t(0x7c00), length);
if (read(buf, thisSz) != thisSz) if (read(buf, thisSz) != thisSz)
{ {
LogModule.report(LogVisor::FatalError, "unable to read enough from file"); LogModule.report(logvisor::Fatal, "unable to read enough from file");
return written; return written;
} }
if (discio.write(buf, thisSz) != thisSz) if (discio.write(buf, thisSz) != thisSz)
{ {
LogModule.report(LogVisor::FatalError, "unable to write enough to disc"); LogModule.report(logvisor::Fatal, "unable to write enough to disc");
return written; return written;
} }
length -= thisSz; length -= thisSz;

View File

@ -1,4 +1,4 @@
#include "NOD/aes.hpp" #include "nod/aes.hpp"
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -8,7 +8,7 @@
#include <cpuid.h> #include <cpuid.h>
#endif #endif
namespace NOD namespace nod
{ {
/* rotates x one bit to the left */ /* rotates x one bit to the left */

View File

@ -1,11 +1,11 @@
#include <stdio.h> #include <stdio.h>
#include "NOD/NOD.hpp" #include "nod/nod.hpp"
#include "NOD/DiscBase.hpp" #include "nod/DiscBase.hpp"
namespace NOD namespace nod
{ {
LogVisor::LogModule LogModule("NODLib"); logvisor::Module LogModule("nod");
std::unique_ptr<IDiscIO> NewDiscIOISO(const SystemChar* path); std::unique_ptr<IDiscIO> NewDiscIOISO(const SystemChar* path);
std::unique_ptr<IDiscIO> NewDiscIOWBFS(const SystemChar* path); std::unique_ptr<IDiscIO> NewDiscIOWBFS(const SystemChar* path);
@ -16,7 +16,7 @@ std::unique_ptr<DiscBase> OpenDiscFromImage(const SystemChar* path, bool& isWii)
std::unique_ptr<IFileIO> fio = NewFileIO(path); std::unique_ptr<IFileIO> fio = NewFileIO(path);
if (!fio->exists()) if (!fio->exists())
{ {
LogModule.report(LogVisor::Error, _S("Unable to open '%s'"), path); LogModule.report(logvisor::Error, _S("Unable to open '%s'"), path);
return std::unique_ptr<DiscBase>(); return std::unique_ptr<DiscBase>();
} }
std::unique_ptr<IFileIO::IReadStream> rs = fio->beginReadStream(); std::unique_ptr<IFileIO::IReadStream> rs = fio->beginReadStream();
@ -25,9 +25,9 @@ std::unique_ptr<DiscBase> OpenDiscFromImage(const SystemChar* path, bool& isWii)
std::unique_ptr<IDiscIO> discIO; std::unique_ptr<IDiscIO> discIO;
uint32_t magic = 0; uint32_t magic = 0;
if (rs->read(&magic, 4) != 4) if (rs->read(&magic, 4) != 4)
LogModule.report(LogVisor::FatalError, _S("Unable to read magic from '%s'"), path); LogModule.report(logvisor::Fatal, _S("Unable to read magic from '%s'"), path);
if (magic == NOD::SBig((uint32_t)'WBFS')) if (magic == nod::SBig((uint32_t)'WBFS'))
{ {
discIO = NewDiscIOWBFS(path); discIO = NewDiscIOWBFS(path);
isWii = true; isWii = true;
@ -36,7 +36,7 @@ std::unique_ptr<DiscBase> OpenDiscFromImage(const SystemChar* path, bool& isWii)
{ {
rs->seek(0x18, SEEK_SET); rs->seek(0x18, SEEK_SET);
rs->read(&magic, 4); rs->read(&magic, 4);
magic = NOD::SBig(magic); magic = nod::SBig(magic);
if (magic == 0x5D1C9EA3) if (magic == 0x5D1C9EA3)
{ {
discIO = NewDiscIOISO(path); discIO = NewDiscIOISO(path);
@ -45,7 +45,7 @@ std::unique_ptr<DiscBase> OpenDiscFromImage(const SystemChar* path, bool& isWii)
else else
{ {
rs->read(&magic, 4); rs->read(&magic, 4);
magic = NOD::SBig(magic); magic = nod::SBig(magic);
if (magic == 0xC2339F3D) if (magic == 0xC2339F3D)
discIO = NewDiscIOISO(path); discIO = NewDiscIOISO(path);
} }
@ -53,7 +53,7 @@ std::unique_ptr<DiscBase> OpenDiscFromImage(const SystemChar* path, bool& isWii)
if (!discIO) if (!discIO)
{ {
LogModule.report(LogVisor::Error, _S("'%s' is not a valid image"), path); LogModule.report(logvisor::Error, _S("'%s' is not a valid image"), path);
return std::unique_ptr<DiscBase>(); return std::unique_ptr<DiscBase>();
} }

View File

@ -5,7 +5,7 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include "NOD/sha1.h" #include "nod/sha1.h"
#ifdef __BIG_ENDIAN__ #ifdef __BIG_ENDIAN__
# define SHA_BIG_ENDIAN # define SHA_BIG_ENDIAN

@ -1 +0,0 @@
Subproject commit 55b81ec091e9f0e57bd7d092a396916234b1ada5

1
logvisor Submodule

@ -0,0 +1 @@
Subproject commit db415516f6742bd3fe4d2616d478b232cc33ab34