Skip to content

Commit

Permalink
fix extract exefs without exefs-dir bug
Browse files Browse the repository at this point in the history
sync with libsundaowen_src
  • Loading branch information
dnasdw committed Apr 20, 2019
1 parent 387de14 commit 21a2b05
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 40 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if(APPLE)
endif()
set(_3DSTOOL_MAJOR 1)
set(_3DSTOOL_MINOR 2)
set(_3DSTOOL_PATCHLEVEL 4)
set(_3DSTOOL_PATCHLEVEL 5)
if(NOT MSVC_IDE AND NOT XCODE_VERSION AND NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif()
Expand Down Expand Up @@ -70,7 +70,9 @@ if(WIN32)
endif()
if(UNIX OR MINGW)
add_definitions(-D_FILE_OFFSET_BITS=64)
if(NOT APPLE)
if(APPLE)
add_definitions(-Wno-shift-overflow)
else()
add_definitions(-Wno-multichar -Wno-unused-result)
endif()
set(CMAKE_INSTALL_RPATH .)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ An all-in-one tool for extracting/creating 3ds roms.
- v1.2.2 @ 2018.08.27 - Fix not encrypt bug
- v1.2.3 @ 2018.09.03 - Fix extract cxi without exefs bug
- v1.2.4 @ 2019.03.28 - Improve lock region
- v1.2.5 @ 2019.04.20 - Fix extract exefs without exefs-dir bug

### v1.1

Expand Down
5 changes: 5 additions & 0 deletions bin/ext_key.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1459,6 +1459,7 @@
00040000001D3A00 55B883541350862ECEEAE64CA7A39EB8
00040000001D3B00 747C0F10C9D222EA59501114DB024192
00040000001D3C00 B7A0294B8712C2346438BFACD27B9D37
00040000001D3E00 9A616CF2F3DA6848EA1294283A4E8E13
00040000001D3F00 1A82A36C84C2ECF1933D6156D7E3F333
00040000001D4000 80CA8BB3E11F631F01E7540AA3454CAE
00040000001D4500 9F62F7E161D51974F2CCE8B860CE749F
Expand Down Expand Up @@ -1487,9 +1488,11 @@
00040000001D6B00 DA03A2E1DBD7A9E3BE1926DDB679FC02
00040000001D6C00 CE196657DAD057778690FC84A3C84BE3
00040000001D6F00 5010F2D2C840FA5ABE9D7CA94B765B1E
00040000001D7100 C28A70F78C756DA3EC068DEBEE7060F3
00040000001D7200 8974BF03C548F5D2ECED338753E19D80
00040000001D7300 4245F9F8820DFFCD18020FC5A7A9FFE9
00040000001D7400 BC02E6103907A3604599573F37FE73EC
00040000001D7500 E63BDD6E998EC03E75E0B0AD4AE9208A
00040000001D7800 EB704CAC88F3CFF78B27F268C679CB1A
00040000001D7D00 14A95854B221AA65D740FDD4682DF318
00040000001D7E00 1D2C4FD379D03B2881AEA20BD5EA6081
Expand Down Expand Up @@ -1726,4 +1729,6 @@
000400000F712000 60423DBB2E17052D3E04ABB04351F74D
000400000F712500 2D5A7BC5ED0F050E77E7E97297988235
000400000F712A00 1B0009156DABDE9D0B8CB0C1C41C2D70
000400000F712E00 C4C86953EA24BE5197D96D0A5C58B7DD
000400000F712F00 7B3D923E61ABAE3A0B042DB118967274
000400000FF3E300 AA9B98FB66563D5E847A619E4D03DF15
4 changes: 2 additions & 2 deletions cmake/AutoFiles.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function(AUTO_FILES FOLDER FILTER PATTERN)
string(REPLACE "./" "" AUTO_FILES_FILTER "${AUTO_FILES_FILTER}")
string(REPLACE "/" "\\" AUTO_FILES_FILTER "${AUTO_FILES_FILTER}")
string(REPLACE "..\\" "../" AUTO_FILES_FILTER "${AUTO_FILES_FILTER}")
if("${AUTO_FILES_FILTER}" STREQUAL "../")
set(AUTO_FILES_FILTER "..")
if("${AUTO_FILES_FILTER}" MATCHES "(.+)/$")
set(AUTO_FILES_FILTER "${CMAKE_MATCH_1}")
endif()
if("${AUTO_FILES_FILTER}" STREQUAL ".")
source_group("${FILTER}" FILES ${AUTO_FILES_FOLDER_FILES})
Expand Down
18 changes: 12 additions & 6 deletions src/exefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,26 @@ bool CExeFs::ExtractFile()
return false;
}
fread(&m_ExeFsSuperBlock, sizeof(m_ExeFsSuperBlock), 1, m_fpExeFs);
if (!UMakeDir(m_sExeFsDirName.c_str()))
if (!m_sExeFsDirName.empty())
{
fclose(m_fpExeFs);
return false;
if (!UMakeDir(m_sExeFsDirName.c_str()))
{
fclose(m_fpExeFs);
return false;
}
}
if (!extractHeader())
{
bResult = false;
}
for (int i = 0; i < 8; i++)
if (!m_sExeFsDirName.empty())
{
if (!extractSection(i))
for (int i = 0; i < 8; i++)
{
bResult = false;
if (!extractSection(i))
{
bResult = false;
}
}
}
fclose(m_fpExeFs);
Expand Down
48 changes: 24 additions & 24 deletions src/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,65 +139,65 @@ int main(int argc, char* argv[])
const UString& UGetModuleFileName()
{
const u32 uMaxPath = 4096;
static UString sFileName;
if (!sFileName.empty())
static UString c_sFileName;
if (!c_sFileName.empty())
{
return sFileName;
return c_sFileName;
}
sFileName.resize(uMaxPath, USTR('\0'));
c_sFileName.resize(uMaxPath, USTR('\0'));
u32 uSize = 0;
#if SDW_PLATFORM == SDW_PLATFORM_WINDOWS
uSize = GetModuleFileNameW(nullptr, &*sFileName.begin(), uMaxPath);
uSize = GetModuleFileNameW(nullptr, &*c_sFileName.begin(), uMaxPath);
#elif SDW_PLATFORM == SDW_PLATFORM_MACOS
char szPath[uMaxPath] = {};
u32 uPathSize = uMaxPath;
if (_NSGetExecutablePath(szPath, &uPathSize) != 0)
{
sFileName.clear();
c_sFileName.clear();
printf("ERROR: _NSGetExecutablePath error\n\n");
}
else if (realpath(szPath, &*sFileName.begin()) == nullptr)
else if (realpath(szPath, &*c_sFileName.begin()) == nullptr)
{
sFileName.clear();
c_sFileName.clear();
printf("ERROR: realpath error\n\n");
}
uSize = strlen(sFileName.c_str());
uSize = strlen(c_sFileName.c_str());
#elif SDW_PLATFORM == SDW_PLATFORM_LINUX || SDW_PLATFORM == SDW_PLATFORM_CYGWIN
ssize_t nCount = readlink("/proc/self/exe", &*sFileName.begin(), uMaxPath);
ssize_t nCount = readlink("/proc/self/exe", &*c_sFileName.begin(), uMaxPath);
if (nCount == -1)
{
sFileName.clear();
c_sFileName.clear();
printf("ERROR: readlink /proc/self/exe error\n\n");
}
else
{
sFileName[nCount] = '\0';
c_sFileName[nCount] = '\0';
}
uSize = strlen(sFileName.c_str());
uSize = strlen(c_sFileName.c_str());
#endif
sFileName.erase(uSize);
sFileName = Replace(sFileName, USTR('\\'), USTR('/'));
return sFileName;
c_sFileName.erase(uSize);
c_sFileName = Replace(c_sFileName, USTR('\\'), USTR('/'));
return c_sFileName;
}

const UString& UGetModuleDirName()
{
static UString sDirName;
if (!sDirName.empty())
static UString c_sDirName;
if (!c_sDirName.empty())
{
return sDirName;
return c_sDirName;
}
sDirName = UGetModuleFileName();
UString::size_type uPos = sDirName.rfind(USTR('/'));
c_sDirName = UGetModuleFileName();
UString::size_type uPos = c_sDirName.rfind(USTR('/'));
if (uPos != UString::npos)
{
sDirName.erase(uPos);
c_sDirName.erase(uPos);
}
else
{
sDirName.clear();
c_sDirName.clear();
}
return sDirName;
return c_sDirName;
}

void SetLocale()
Expand Down
12 changes: 6 additions & 6 deletions src/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ n64 Align(n64 a_nData, n64 a_nAlignment);

#define SDW_BIT64(n) (UINT64_C(1) << (n))

#define SDW_CONVERT_ENDIAN32(n) (((n) >> 24 & 0xFF) | ((n) >> 8 & 0xFF00) | (((n) & 0xFF00) << 8) | (((n) & 0xFF) << 24))
#define SDW_CONVERT_ENDIAN32(n) (((n) >> 24 & 0xFF) | ((n) >> 8 & 0xFF00) | ((n) << 8 & 0xFF0000) | ((n) << 24 & 0xFF000000))

#if SDW_PLATFORM == SDW_PLATFORM_WINDOWS
#define Mkdir _mkdir
Expand Down Expand Up @@ -289,19 +289,19 @@ TDest TSToS(const TSrc& a_sString, const string& a_sSrcType, const string& a_sDe
return sConverted;
}
size_t uStringLeft = a_sString.size() * sizeof(typename TSrc::value_type);
static const n32 c_nBufferSize = 1024;
static const n32 c_nConvertBufferSize = c_nBufferSize - 4;
static const int c_nBufferSize = 1024;
static const int c_nConvertBufferSize = c_nBufferSize - 4;
char szBuffer[c_nBufferSize];
typename TSrc::value_type* pString = const_cast<typename TSrc::value_type*>(a_sString.c_str());
do
{
char* pBuffer = szBuffer;
size_t uBufferLeft = c_nConvertBufferSize;
n32 nError = iconv(cd, reinterpret_cast<char**>(&pString), &uStringLeft, &pBuffer, &uBufferLeft);
int nError = static_cast<int>(iconv(cd, reinterpret_cast<char**>(&pString), &uStringLeft, &pBuffer, &uBufferLeft));
#if SDW_PLATFORM == SDW_PLATFORM_MACOS
if (nError >= 0 || (nError == static_cast<size_t>(-1) && errno == E2BIG))
if (nError >= 0 || (nError == -1 && errno == E2BIG))
#else
if (nError == 0 || (nError == static_cast<size_t>(-1) && errno == E2BIG))
if (nError == 0 || (nError == -1 && errno == E2BIG))
#endif
{
*reinterpret_cast<typename TDest::value_type*>(szBuffer + c_nConvertBufferSize - uBufferLeft) = 0;
Expand Down

0 comments on commit 21a2b05

Please sign in to comment.