Skip to content

Commit

Permalink
lock region and language
Browse files Browse the repository at this point in the history
  • Loading branch information
dnasdw committed Jan 20, 2018
1 parent c58d105 commit 6efe6bd
Show file tree
Hide file tree
Showing 9 changed files with 1,206 additions and 3 deletions.
2 changes: 1 addition & 1 deletion 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 1)
set(_3DSTOOL_PATCHLEVEL 0)
set(_3DSTOOL_PATCHLEVEL 1)
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ An all-in-one tool for extracting/creating 3ds roms.
## History

- v1.1.0 @ 2018.01.03 - A new beginning
- v1.1.1 @ 2018.01.21 - Lock region and language

### v1.0

Expand Down
14 changes: 14 additions & 0 deletions bin/ext_key.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,7 @@
00040000001C1900 19B9AEE5B914F9ECAE44B3509CA3C822
00040000001C1A00 841B2AC0890599A9960FAA3049BDF461
00040000001C1F00 0680EBFB1C9F18F25C25BBAC2B2E3C50
00040000001C2000 967411DEA911D5E20C823C401D23E0A9
00040000001C2100 006BC9B7D841D22F19E3A1417478831C
00040000001C2500 218468DC8625CE8250A11DD7A9D1D730
00040000001C2600 B0DCE4284E39713C6DF40BA71ABB0BCF
Expand Down Expand Up @@ -1316,6 +1317,7 @@
00040000001C7E00 9C63AD66731B3ACD47804025AEF5D57F
00040000001C8200 E093B5B390DC2A7A3840A622CEDB6DE6
00040000001C8300 A8BE57F742FE3C0B1BAAAA686AB8F6CF
00040000001C8F00 F989E5CC074D7F7448688884F7909E7A
00040000001C9200 52C38F38E4559DF9F6B51A64F64FFD2A
00040000001C9400 DCD34B18A5E570F88B0CB056BB1253C5
00040000001C9700 C5E89BA9DA5ADD58BC0BEE772D8BD4C8
Expand All @@ -1328,13 +1330,16 @@
00040000001C9F00 DAF122F1D3B976E26C023A5CDCDBFEE0
00040000001CA100 A188F1E33E0E40E22961D997BEA3F4D4
00040000001CA800 BC766C1AAA7AD881F3705B894240D727
00040000001CAB00 28F9D733E828EC064934EC36FACE3D07
00040000001CAC00 3753BB5D4CF2B52DE87899C76C7B204C
00040000001CAD00 DFF0981B156D63BD1BFB52475C4A7BED
00040000001CB300 AA1F307322B15615E9A9CEF7CB2AFC26
00040000001CB400 F967EB6E57FAAAB9B0CEC33F76F8AD6E
00040000001CB600 338D239998E441C2EE84C5B5B514161B
00040000001CB800 1FBBF2D59FBC81943A624DA34FEEC162
00040000001CB900 6F0311322FAB582D51993568DED3D7E8
00040000001CBF00 24615F24DF7C3A1D4A373BC09D3DF958
00040000001CC200 A87C0C386FB328FBCD9ED0E3637556D9
00040000001CC300 25422DE201F14165BA517AD43B4DEEA9
00040000001CC400 32624379C7C1305D34451C53179210E5
00040000001CC500 EFA2003525BE470D99CBB69BF9F96E24
Expand All @@ -1348,11 +1353,17 @@
00040000001CD300 B9BEC473A1BA15E4E030373652D693DC
00040000001CD500 02625F777DE1B8D8DF573D4FCA70E0C6
00040000001CD600 54112CEB304A18A8AB6088AD17E074E5
00040000001CD900 B71BB287BAE85D3620F422EC6D694E15
00040000001CDD00 E9BDC86CAE90B6BC9AFAD809FDF44BEF
00040000001CDE00 6563EB16B265D6F6237C2B4F5234C321
00040000001CE000 B9C2D4CFDD33FEC7A65A5BC474A7AE1D
00040000001CF700 5972355F05C9CEE372BF96A07841D007
00040000001CFD00 3277ABFFD9C42B92958922EEF9D00FB5
00040000001CFF00 A90D0A44E38655B4D0C26F998ED9345D
00040000001D0900 E9D344283411C3C4EE702EBF98DB6F85
00040000001D0C00 9ACF1243D40F4E79C75F3CC0B7254736
00040000001D0E00 208312DE6B0ABFD40E22CE974A285D1D
00040000001D1300 09E9B2205D3DDFB05E9E440804B08E30
000400000F700400 0D65CBD40F2728586CA4DAE3B8681313
000400000F700700 C6EE84F157E15E8B7E716090D2ED5DE4
000400000F700800 9A83F7FEB62E8D9AACB5AA7761A00590
Expand Down Expand Up @@ -1517,6 +1528,7 @@
000400000F70C600 F377B9F29A210B704805C937AA6E4663
000400000F70C700 DD5068B175857B768B2BA9C5551FC9A4
000400000F70C800 0ED531D0438958D4FB56621ECF2F2E07
000400000F70CB00 383CAB2FF6AF470B3F2E67D55DE61DB6
000400000F70CC00 2A42359594E873BCA27CD1FDAF76BE99
000400000F70CD00 058537FDB20D91601BCC628FCF88A904
000400000F70CF00 60519EDED5C60F8FAC5278E111988CE0
Expand All @@ -1527,6 +1539,7 @@
000400000F70D600 02D74984A8B81D45DB7065A634F01747
000400000F70D700 DD261F8A373E3C07A4274A028B4C3F00
000400000F70D900 179C70E1A8615B5C53F6BDDBFEDDD299
000400000F70DB00 351B5E329DDC4DCFD624F04D1733FDDE
000400000F70DE00 6BEFD48958D75C3AF4A1F2DD96E41B41
000400000F70E000 813C66B7C3629266F41835E4E03B4639
000400000F70E100 6D864FAB9ABED9608A84FCB09D53AA53
Expand All @@ -1549,4 +1562,5 @@
000400000F70FA00 6E939F87C4A1C496D91C11AC99805508
000400000F70FB00 D9F2FE442F94B131C2A9FB50BAD4D77B
000400000F70FE00 F54AB07CF639670FB88002A7487EF2FA
000400000F710500 E6253A2F3E1789A82D54E4CD9CC93F0F
000400000FF3E300 AA9B98FB66563D5E847A619E4D03DF15
3 changes: 3 additions & 0 deletions dep/src/capstone/msvc/stdint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#ifndef MSVC_STDINT_H_
#define MSVC_STDINT_H_
#endif // MSVC_STDINT_H_
149 changes: 149 additions & 0 deletions src/3dstool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "3dscrypt.h"
#include "backwardlz77.h"
#include "banner.h"
#include "code.h"
#include "exefs.h"
#include "huffman.h"
#include "lz77.h"
Expand All @@ -25,6 +26,7 @@ C3dsTool::SOption C3dsTool::s_Option[] =
{ USTR("pad"), USTR('p'), USTR("pad the cci file") },
{ USTR("diff"), 0, USTR("create the patch file from the old file and the new file") },
{ USTR("patch"), 0, USTR("apply the patch file to the target file") },
{ USTR("lock"), 0, USTR("modify some function in the code file") },
{ USTR("download"), USTR('d'), USTR("download ext key") },
{ USTR("sample"), 0, USTR("show the samples") },
{ USTR("help"), USTR('h'), USTR("show this help") },
Expand Down Expand Up @@ -108,6 +110,10 @@ C3dsTool::SOption C3dsTool::s_Option[] =
{ nullptr, 0, USTR("\nbanner:") },
{ nullptr, 0, USTR(" extract/create:") },
{ USTR("banner-dir"), 0, USTR("the banner dir for the banner file") },
{ nullptr, 0, USTR("\ncode:") },
{ nullptr, 0, USTR(" lock:") },
{ USTR("region"), 0, USTR("[JPN|USA|EUR|AUS|CHN|KOR|TWN]") },
{ USTR("language"), 0, USTR("[JP|EN|FR|GE|IT|SP|CN|KR|DU|PO|RU|TW]") },
{ nullptr, 0, nullptr }
};

Expand All @@ -119,6 +125,8 @@ C3dsTool::C3dsTool()
, m_nCompressAlign(1)
, m_eCompressType(kCompressTypeNone)
, m_nYaz0Align(0)
, m_nRegionCode(-1)
, m_nLanguageCode(-1)
, m_nDownloadBegin(-1)
, m_nDownloadEnd(-1)
, m_bNotPad(false)
Expand Down Expand Up @@ -448,6 +456,14 @@ int C3dsTool::CheckOptions()
return 1;
}
}
if (m_eAction == kActionLock)
{
if (m_nRegionCode < 0 && m_nLanguageCode < 0)
{
UPrintf(USTR("ERROR: no --region or --language option\n\n"));
return 1;
}
}
if (m_eAction == kActionDownload)
{
if (m_nDownloadBegin < 0 && m_nDownloadEnd < 0)
Expand Down Expand Up @@ -568,6 +584,14 @@ int C3dsTool::Action()
return 1;
}
}
if (m_eAction == kActionLock)
{
if (!lock())
{
UPrintf(USTR("ERROR: modify function failed\n\n"));
return 1;
}
}
if (m_eAction == kActionDownload)
{
if (!download())
Expand Down Expand Up @@ -690,6 +714,17 @@ C3dsTool::EParseOptionReturn C3dsTool::parseOptions(const UChar* a_pName, int& a
return kParseOptionReturnOptionConflict;
}
}
else if (UCscmp(a_pName, USTR("lock")) == 0)
{
if (m_eAction == kActionNone)
{
m_eAction = kActionLock;
}
else if (m_eAction != kActionLock && m_eAction != kActionHelp)
{
return kParseOptionReturnOptionConflict;
}
}
else if (UCscmp(a_pName, USTR("download")) == 0)
{
if (m_eAction == kActionNone)
Expand Down Expand Up @@ -1228,6 +1263,108 @@ C3dsTool::EParseOptionReturn C3dsTool::parseOptions(const UChar* a_pName, int& a
}
m_sBannerDirName = a_pArgv[++a_nIndex];
}
else if (UCscmp(a_pName, USTR("region")) == 0)
{
if (a_nIndex + 1 >= a_nArgc)
{
return kParseOptionReturnNoArgument;
}
UChar* pRegion = a_pArgv[++a_nIndex];
if (UCscmp(pRegion, USTR("JPN")) == 0)
{
m_nRegionCode = 0;
}
else if (UCscmp(pRegion, USTR("USA")) == 0)
{
m_nRegionCode = 1;
}
else if (UCscmp(pRegion, USTR("EUR")) == 0)
{
m_nRegionCode = 2;
}
else if (UCscmp(pRegion, USTR("AUS")) == 0)
{
m_nRegionCode = 3;
}
else if (UCscmp(pRegion, USTR("CHN")) == 0)
{
m_nRegionCode = 4;
}
else if (UCscmp(pRegion, USTR("KOR")) == 0)
{
m_nRegionCode = 5;
}
else if (UCscmp(pRegion, USTR("TWN")) == 0)
{
m_nRegionCode = 6;
}
else
{
m_sMessage = pRegion;
return kParseOptionReturnUnknownArgument;
}
}
else if (UCscmp(a_pName, USTR("language")) == 0)
{
if (a_nIndex + 1 >= a_nArgc)
{
return kParseOptionReturnNoArgument;
}
UChar* pLanguage = a_pArgv[++a_nIndex];
if (UCscmp(pLanguage, USTR("JP")) == 0)
{
m_nLanguageCode = 0;
}
else if (UCscmp(pLanguage, USTR("EN")) == 0)
{
m_nLanguageCode = 1;
}
else if (UCscmp(pLanguage, USTR("FR")) == 0)
{
m_nLanguageCode = 2;
}
else if (UCscmp(pLanguage, USTR("GE")) == 0)
{
m_nLanguageCode = 3;
}
else if (UCscmp(pLanguage, USTR("IT")) == 0)
{
m_nLanguageCode = 4;
}
else if (UCscmp(pLanguage, USTR("SP")) == 0)
{
m_nLanguageCode = 5;
}
else if (UCscmp(pLanguage, USTR("CN")) == 0)
{
m_nLanguageCode = 6;
}
else if (UCscmp(pLanguage, USTR("KR")) == 0)
{
m_nLanguageCode = 7;
}
else if (UCscmp(pLanguage, USTR("DU")) == 0)
{
m_nLanguageCode = 8;
}
else if (UCscmp(pLanguage, USTR("PO")) == 0)
{
m_nLanguageCode = 9;
}
else if (UCscmp(pLanguage, USTR("RU")) == 0)
{
m_nLanguageCode = 10;
}
else if (UCscmp(pLanguage, USTR("TW")) == 0)
{
m_nLanguageCode = 11;
}
else
{
m_sMessage = pLanguage;
return kParseOptionReturnUnknownArgument;
}
}
return kParseOptionReturnSuccess;
}

Expand Down Expand Up @@ -1751,6 +1888,16 @@ bool C3dsTool::patchFile()
return patch.ApplyPatchFile();
}

bool C3dsTool::lock()
{
CCode code;
code.SetFileName(m_sFileName);
code.SetVerbose(m_bVerbose);
code.SetRegionCode(m_nRegionCode);
code.SetLanguageCode(m_nLanguageCode);
return code.Lock();
}

bool C3dsTool::download()
{
if (m_nDownloadBegin > m_nDownloadEnd)
Expand Down Expand Up @@ -1899,6 +2046,8 @@ int C3dsTool::sample()
UPrintf(USTR("3dstool --diff -vt cfa --old old.cfa --new new.cfa --patch-file patch.3ps\n\n"));
UPrintf(USTR("# apply patch file\n"));
UPrintf(USTR("3dstool --patch -vf input.bin --patch-file patch.3ps\n\n"));
UPrintf(USTR("# lock region JPN and lock language JP\n"));
UPrintf(USTR("3dstool --lock -vf code.bin --region JPN --language JP\n\n"));
UPrintf(USTR("# download ext key\n"));
UPrintf(USTR("3dstool -dv --download-begin 00000 --download-end 02FFF\n\n"));
return 0;
Expand Down
4 changes: 4 additions & 0 deletions src/3dstool.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class C3dsTool
kActionPad,
kActionDiff,
kActionPatch,
kActionLock,
kActionDownload,
kActionSample,
kActionHelp
Expand Down Expand Up @@ -78,6 +79,7 @@ class C3dsTool
bool padFile();
bool diffFile();
bool patchFile();
bool lock();
bool download();
int sample();
EAction m_eAction;
Expand All @@ -96,6 +98,8 @@ class C3dsTool
UString m_sOldFileName;
UString m_sNewFileName;
UString m_sPatchFileName;
n32 m_nRegionCode;
n32 m_nLanguageCode;
n32 m_nDownloadBegin;
n32 m_nDownloadEnd;
map<int, UString> m_mNcchFileName;
Expand Down
13 changes: 11 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
AUTO_FILES("." "src" "\\.(cpp|h)$")
include_directories(${DEP_INCLUDE_DIR})
if(MSVC_VERSION LESS 1600)
AUTO_FILES("${ROOT_SOURCE_DIR}/dep/src/capstone/msvc" "src" "\\.h$")
endif()
AUTO_FILES("${ROOT_SOURCE_DIR}/dep/src/capstone-3.0.5-rc3/include" "src" "\\.h$")
AUTO_FILES("${ROOT_SOURCE_DIR}/dep/src/capstone-3.0.5-rc3" "src" "capstone-3.0.5-rc3/[^/]+\\.(c|h)$")
AUTO_FILES("${ROOT_SOURCE_DIR}/dep/src/capstone-3.0.5-rc3/arch/ARM" "src" "\\.(c|h|inc)$")
include_directories(${DEP_INCLUDE_DIR} "${ROOT_SOURCE_DIR}/dep/src/capstone-3.0.5-rc3/include")
if(MSVC_VERSION LESS 1600)
include_directories("${ROOT_SOURCE_DIR}/dep/src/capstone/msvc")
endif()
link_directories(${DEP_LIBRARY_DIR})
add_definitions(-DSDW_MAIN -DCURL_STATICLIB)
add_definitions(-DSDW_MAIN -DCURL_STATICLIB -DCAPSTONE_USE_SYS_DYN_MEM -DCAPSTONE_HAS_ARM)
if(APPLE)
add_definitions(-DSDW_XCONVERT)
endif()
Expand Down
Loading

0 comments on commit 6efe6bd

Please sign in to comment.