diff --git a/build/tools/MasterEditor/split_tad_console/Debug/split_tad_console.ilk b/build/tools/MasterEditor/split_tad_console/Debug/split_tad_console.ilk new file mode 100644 index 0000000..e69de29 diff --git a/build/tools/MasterEditor/split_tad_console/split_tad_console.ncb b/build/tools/MasterEditor/split_tad_console/split_tad_console.ncb new file mode 100644 index 0000000..a81423b Binary files /dev/null and b/build/tools/MasterEditor/split_tad_console/split_tad_console.ncb differ diff --git a/build/tools/MasterEditor/split_tad_console/split_tad_console.sln b/build/tools/MasterEditor/split_tad_console/split_tad_console.sln new file mode 100644 index 0000000..d9e0d11 --- /dev/null +++ b/build/tools/MasterEditor/split_tad_console/split_tad_console.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "split_tad_console", "split_tad_console\split_tad_console.vcproj", "{B89F1089-C492-4520-93FE-E40FA17D00CE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B89F1089-C492-4520-93FE-E40FA17D00CE}.Debug|Win32.ActiveCfg = Debug|Win32 + {B89F1089-C492-4520-93FE-E40FA17D00CE}.Debug|Win32.Build.0 = Debug|Win32 + {B89F1089-C492-4520-93FE-E40FA17D00CE}.Release|Win32.ActiveCfg = Release|Win32 + {B89F1089-C492-4520-93FE-E40FA17D00CE}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/build/tools/MasterEditor/split_tad_console/split_tad_console.suo b/build/tools/MasterEditor/split_tad_console/split_tad_console.suo new file mode 100644 index 0000000..147dab2 Binary files /dev/null and b/build/tools/MasterEditor/split_tad_console/split_tad_console.suo differ diff --git a/build/tools/MasterEditor/split_tad_console/split_tad_console/AssemblyInfo.cpp b/build/tools/MasterEditor/split_tad_console/split_tad_console/AssemblyInfo.cpp new file mode 100644 index 0000000..9996e02 --- /dev/null +++ b/build/tools/MasterEditor/split_tad_console/split_tad_console/AssemblyInfo.cpp @@ -0,0 +1,40 @@ +#include "stdafx.h" + +using namespace System; +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; +using namespace System::Security::Permissions; + +// +// ƒAƒZƒ“ƒuƒŠ‚ÉŠÖ‚·‚éˆê”Êî•ñ‚͈ȉº‚Ì‘®«ƒZƒbƒg‚ð‚Æ‚¨‚µ‚ħŒä‚³‚ê‚Ü‚·B +// ƒAƒZƒ“ƒuƒŠ‚ÉŠÖ˜A•t‚¯‚ç‚ê‚Ä‚¢‚éî•ñ‚ð•ÏX‚·‚é‚É‚ÍA +// ‚±‚ê‚ç‚Ì‘®«’l‚ð•ÏX‚µ‚Ä‚­‚¾‚³‚¢B +// +[assembly:AssemblyTitleAttribute("split_tad_console")]; +[assembly:AssemblyDescriptionAttribute("")]; +[assembly:AssemblyConfigurationAttribute("")]; +[assembly:AssemblyCompanyAttribute("”C“V“°Š”Ž®‰ïŽÐ")]; +[assembly:AssemblyProductAttribute("split_tad_console")]; +[assembly:AssemblyCopyrightAttribute("Copyright (c) ”C“V“°Š”Ž®‰ïŽÐ 2008")]; +[assembly:AssemblyTrademarkAttribute("")]; +[assembly:AssemblyCultureAttribute("")]; + +// +// ƒAƒZƒ“ƒuƒŠ‚̃o[ƒWƒ‡ƒ“î•ñ‚ÍAˆÈ‰º‚Ì 4 ‚‚̒l‚Å\¬‚³‚ê‚Ä‚¢‚Ü‚·: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// ‚·‚ׂĂ̒l‚ðŽw’è‚·‚é‚©A‰º‚̂悤‚É '*' ‚ðŽg‚Á‚ÄƒŠƒrƒWƒ‡ƒ“‚¨‚æ‚уrƒ‹ƒh”Ô†‚ð +// Šù’è’l‚É‚·‚邱‚Æ‚ª‚Å‚«‚Ü‚·: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + +[assembly:CLSCompliantAttribute(true)]; + +[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)]; diff --git a/build/tools/MasterEditor/split_tad_console/split_tad_console/Debug/BuildLog.htm b/build/tools/MasterEditor/split_tad_console/split_tad_console/Debug/BuildLog.htm new file mode 100644 index 0000000..51909df Binary files /dev/null and b/build/tools/MasterEditor/split_tad_console/split_tad_console/Debug/BuildLog.htm differ diff --git a/build/tools/MasterEditor/split_tad_console/split_tad_console/ReadMe.txt b/build/tools/MasterEditor/split_tad_console/split_tad_console/ReadMe.txt new file mode 100644 index 0000000..d358380 --- /dev/null +++ b/build/tools/MasterEditor/split_tad_console/split_tad_console/ReadMe.txt @@ -0,0 +1,29 @@ +=============================================================================== + ƒAƒvƒŠƒP[ƒVƒ‡ƒ“ : split_tad_console ƒvƒƒWƒFƒNƒg‚ÌŠT—v +=============================================================================== + +‚±‚Ì split_tad_console ƒAƒvƒŠƒP[ƒVƒ‡ƒ“‚ÍAAppWizard ‚É‚æ‚Á‚Ä쬂³‚ê‚Ü‚µ‚½B + +‚±‚̃tƒ@ƒCƒ‹‚É‚ÍAsplit_tad_console ƒAƒvƒŠƒP[ƒVƒ‡ƒ“‚ð\¬‚·‚éŠeƒtƒ@ƒCƒ‹‚Ì +“à—e‚ÌŠT—ª‚ª‹Lq‚³‚ê‚Ä‚¢‚Ü‚·B + +split_tad_console.vcproj + ‚±‚ê‚ÍAƒAƒvƒŠƒP[ƒVƒ‡ƒ“ ƒEƒBƒU[ƒh‚Ŷ¬‚³‚ê‚é VC++ ƒvƒƒWƒFƒNƒg‚̃ƒCƒ“‚Ì + ƒvƒƒWƒFƒNƒg ƒtƒ@ƒCƒ‹‚Å‚·B + ƒtƒ@ƒCƒ‹‚𶬂µ‚½ Visual C++ ‚̃o[ƒWƒ‡ƒ“î•ñ‚ÆAƒAƒvƒŠƒP[ƒVƒ‡ƒ“ ƒEƒBƒU[ + ƒh‚Å‘I‘ð‚µ‚½ƒvƒ‰ƒbƒgƒtƒH[ƒ€A\¬A‚¨‚æ‚уvƒƒWƒFƒNƒg‚Ì‹@”\‚ÉŠÖ‚·‚éî•ñ‚ª + ‹Lq‚³‚ê‚Ä‚¢‚Ü‚·B + +split_tad_console.cpp + ‚±‚ê‚ÍAƒƒCƒ“‚̃AƒvƒŠƒP[ƒVƒ‡ƒ“ ƒ\[ƒX ƒtƒ@ƒCƒ‹‚Å‚·B + +AssemblyInfo.cpp + ƒAƒZƒ“ƒuƒŠ ƒƒ^ƒf[ƒ^‚ð•ÏX‚·‚邽‚߂̃JƒXƒ^ƒ€‘®«‚ªŠÜ‚Ü‚ê‚Ä‚¢‚Ü‚·B + +/////////////////////////////////////////////////////////////////////////////// +‚»‚Ì‘¼‚̃ƒ‚ : + +AppWizard ‚Å‚ÍA"TODO:" ‚ðŽg—p‚µ‚ÄAƒ†[ƒU[‚ª’ljÁ‚Ü‚½‚̓JƒXƒ^ƒ}ƒCƒY‚·‚éƒ\[ƒX +•”•ª‚ðŽ¦‚µ‚Ü‚·B + +/////////////////////////////////////////////////////////////////////////////// diff --git a/build/tools/MasterEditor/split_tad_console/split_tad_console/app.ico b/build/tools/MasterEditor/split_tad_console/split_tad_console/app.ico new file mode 100644 index 0000000..3a5525f Binary files /dev/null and b/build/tools/MasterEditor/split_tad_console/split_tad_console/app.ico differ diff --git a/build/tools/MasterEditor/split_tad_console/split_tad_console/app.rc b/build/tools/MasterEditor/split_tad_console/split_tad_console/app.rc new file mode 100644 index 0000000..2ad8e34 --- /dev/null +++ b/build/tools/MasterEditor/split_tad_console/split_tad_console/app.rc @@ -0,0 +1,63 @@ +// Microsoft Visual C++ ‚Ŷ¬‚³‚ꂽƒŠƒ\[ƒX ƒXƒNƒŠƒvƒg‚Å‚·B +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// ‰pŒê (•Ä‘) ƒŠƒ\[ƒX + + +///////////////////////////////////////////////////////////////////////////// +// +// ƒAƒCƒRƒ“ +// + +// ʼn‚É”z’u‚³‚ꂽƒAƒCƒRƒ“A‚Ü‚½‚Í ID ’l‚ªÅ‚à’á‚¢ƒAƒCƒRƒ“‚ªAƒAƒvƒŠƒP[ƒVƒ‡ƒ“ ƒAƒCƒRƒ“‚ɂȂè‚Ü‚·B + +LANGUAGE 17, 1 +#pragma code_page(932) +1 ICON "app.ico" + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" + "\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\0" +END + +#endif // APSTUDIO_INVOKED + +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE 3 ƒŠƒ\[ƒX‚©‚綬‚³‚ê‚Ü‚µ‚½B +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // APSTUDIO_INVOKED ‚łȂ¢ê‡ + diff --git a/build/tools/MasterEditor/split_tad_console/split_tad_console/resource.h b/build/tools/MasterEditor/split_tad_console/split_tad_console/resource.h new file mode 100644 index 0000000..1f2251c --- /dev/null +++ b/build/tools/MasterEditor/split_tad_console/split_tad_console/resource.h @@ -0,0 +1,3 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by app.rc diff --git a/build/tools/MasterEditor/split_tad_console/split_tad_console/split_tad.cpp b/build/tools/MasterEditor/split_tad_console/split_tad_console/split_tad.cpp new file mode 100644 index 0000000..7cdca9b --- /dev/null +++ b/build/tools/MasterEditor/split_tad_console/split_tad_console/split_tad.cpp @@ -0,0 +1,252 @@ +#include "stdafx.h" +#include "twl/types.h" +#include +#include +#include "split_tad.h" +#include "split_tad_util.h" + + +// ------------------------------------------------------ +// 錾‚Æ’è” +// ------------------------------------------------------ + +// internal functions +cli::array^ readTitleKey( cli::array ^ticket ); +cli::array^ decCBC( cli::array ^ Key, cli::array ^ IV, cli::array ^cipherText ); +cli::array ^readContentsInfo( cli::array ^tmd ); + +// tadŠO‚µ—p‚ÌŒ® +const u8 commonKey[] = +{ + 0xA1,0x60,0x4A,0x6A,0x71,0x23,0xB5,0x29,0xAE,0x8B,0xEC,0x32,0xC8,0x16,0xFC,0xAA +}; + + +// ------------------------------------------------------ +// tadŠO‚µˆ—–{‘Ì(split_tad_dev.pl ‚̈ÚA) +// ------------------------------------------------------ + +// +// tad ƒtƒ@ƒCƒ‹‚©‚ç srl(0”Ԗڂ̃Rƒ“ƒeƒ“ƒc)‚𔲂«o‚· +// +// @ret ¬Œ÷‚µ‚½‚Æ‚«0 ޏ”s‚µ‚½‚畉‚Ì’l +// +int splitTad( System::String ^filename ) +{ + FILE *fp = NULL; + const char *pchFilename = + (const char*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi( filename ).ToPointer(); + + if( fopen_s( &fp, pchFilename, "rb" ) != NULL ) + { + return -1; + } + + cli::array ^mbuf = subStr( fp, 0, 32 ); + + u32 hdrSize = reverseEndian( unpack32(mbuf, 0) ); // Šî–{“I‚ɃrƒbƒOƒGƒ“ƒfƒBƒAƒ“ + u16 tadType = reverseEndian( unpack16(mbuf, 4) ); + u16 tadVersion = reverseEndian( unpack16(mbuf, 6) ); + u32 certSize = reverseEndian( unpack32(mbuf, 8) ); + u32 crlSize = reverseEndian( unpack32(mbuf, 12) ); + u32 ticketSize = reverseEndian( unpack32(mbuf, 16) ); + u32 tmdSize = reverseEndian( unpack32(mbuf, 20) ); + u32 contentSize = reverseEndian( unpack32(mbuf, 24) ); + u32 metaSize = reverseEndian( unpack32(mbuf, 28) ); + + printf( "hdrSize %d\n", hdrSize ); + printf( "tadType %c%c\n", tadType>>8, tadType&0xFF ); + printf( "tadVersion %d\n", tadVersion ); + printf( "certSize %d\n", certSize ); + printf( "crlSize %d\n", crlSize ); + printf( "ticketSize %d\n", ticketSize ); + printf( "tmdSize %d\n", tmdSize ); + printf( "contentSize %d\n", contentSize ); + printf( "metaSize %d\n", metaSize ); + + u32 certOffset = roundUp( hdrSize, 64); + u32 crlOffset = roundUp( certOffset + certSize, 64); + u32 ticketOffset = roundUp( crlOffset + crlSize, 64); + u32 tmdOffset = roundUp( ticketOffset + ticketSize, 64); + u32 contentOffset = roundUp( tmdOffset + tmdSize, 64); + u32 metaOffset = roundUp( contentOffset + contentSize, 64); + u32 fileSize = roundUp( metaOffset + metaSize, 64); + + fseek( fp, 0, SEEK_END ); + u32 orgFileSize = ftell( fp ); + if( fileSize != orgFileSize ) + { + printf( "file size is not expected size(=%d)", fileSize ); + fclose( fp ); + return -1; + } + cli::array ^ticket = subStr( fp, ticketOffset, ticketSize ); + cli::array ^tmd = subStr( fp, tmdOffset, tmdSize ); + cli::array ^content = subStr( fp, contentOffset, contentSize ); + + //saveFile( "cert.bin", subStr( fp, certOffset, certSize ) ); + //saveFile( "crl.bin", subStr( fp, crlOffset, crlSize ) ); + //saveFile( "ticket.bin", ticket ); + //saveFile( "tmd.bin", tmd ); + //saveFile( "meta.bin", subStr( fp, metaOffset, metaSize ) ); + + cli::array ^titleKey = readTitleKey( ticket ); + cli::array ^rci = readContentsInfo( tmd ); + dumpBytes( titleKey ); + + u32 offset = 0; + for each( rcContentsInfo ^ci in rci ) + { + u32 size = roundUp( (u32)ci->size, 16 ); + cli::array ^enc_content_x = subStr( content, offset, size ); + cli::array ^content_x_iv = resizeBytes( pack16( reverseEndian(ci->idx) ), 14 ); // ƒrƒbƒOƒGƒ“ƒfƒBƒAƒ“‚É‚µ‚Ä‚¨‚­ + cli::array ^dec_content_x = decCBC( titleKey, content_x_iv, enc_content_x ); + cli::array ^dec_content = subStr( dec_content_x, 0, ci->size ); + System::Security::Cryptography::SHA1 ^sha1 = gcnew System::Security::Cryptography::SHA1Managed(); + cli::array ^hash = sha1->ComputeHash( dec_content ); + + dumpBytes( hash ); + pin_ptr calc = &hash[0]; // ŒvŽZ‚Å‹‚ß‚½ƒnƒbƒVƒ… + pin_ptr extr = &ci->hash[0]; // ’Šo‚µ‚½ƒnƒbƒVƒ… + if( memcmp( calc, extr, 20 ) == 0 ) + { + printf( "hash OK\n" ); + } + else + { + printf( "hash mismatch\n" ); + } + saveFile( "content_" + ci->idx.ToString() + ".encrypted.bin", enc_content_x ); + saveFile( "content_" + ci->idx.ToString() + ".bin", dec_content ); + offset += roundUp( size, 64 ); + } + fclose( fp ); + return 0; +} + +// ------------------------------------------------------ +// internal functions +// ------------------------------------------------------ + +// +// title_key ‚Ì•œ† +// +// @ret title_key ‚̃oƒCƒg—ñ +// +cli::array^ readTitleKey( cli::array ^ticket ) +{ + cli::array ^encTitleKey = subStr( ticket, 0x1BF, 16 ); + cli::array ^IV = resizeBytes( subStr( ticket, 0x1DC, 8 ), 8 ); // 16ƒoƒCƒg‚ÉŠg’£‚µ‚ăPƒc‚Ì8ƒoƒCƒg‚ð0‚Å–„‚ß‚é + + cli::array ^comKey = gcnew cli::array(16); + pin_ptr pComKey = &comKey[0]; + memcpy( pComKey, commonKey, 16 ); + + cli::array ^plain; + try + { + plain = decCBC( comKey, IV, encTitleKey ); + } + catch (System::Exception ^ e) + { + System::Console::WriteLine("Error: {0}", e->Message); + } + return plain; +} + +// +// tmd ‚©‚çŠeƒRƒ“ƒeƒ“ƒcƒtƒ@ƒCƒ‹‚Ìî•ñ‚𔲂«o‚· +// +// @ret ŠeƒRƒ“ƒeƒ“ƒcƒtƒ@ƒCƒ‹‚Ìî•ñ‚ð‚܂Ƃ߂½ Array +// +cli::array ^readContentsInfo( cli::array ^tmd ) +{ + u16 nContent = reverseEndian( unpack16(tmd, 0x1DE) ); + cli::array ^ci = gcnew cli::array( nContent ); + + u16 i; + for( i=0; i < nContent; i++ ) + { + u32 offset = 0x1E4 + 36*i; + ci[i] = gcnew rcContentsInfo; + ci[i]->cid = reverseEndian( unpack32(tmd, offset) ); + ci[i]->idx = reverseEndian( unpack16(tmd, offset + 4) ); + ci[i]->type = reverseEndian( unpack16(tmd, offset + 6) ); + ci[i]->size = reverseEndian( unpack32(tmd, offset + 12) ); + ci[i]->hash = subStr( tmd, offset + 16, 20 ); + } + return ci; +} + +// +// AES•œ† : System::Security::Cryptography::RijndaelManaged ‚̃wƒ‹ƒv‚̃Tƒ“ƒvƒ‹‚ðƒRƒsƒy +// +// @ret •œ†Œã‚̃f[ƒ^ +// +cli::array^ decCBC( cli::array ^ Key, cli::array ^ IV, cli::array ^cipherText ) +{ + // Check arguments. + if (!cipherText || cipherText->Length <= 0) + throw gcnew System::ArgumentNullException("cipherText"); + if (!Key || Key->Length <= 0) + throw gcnew System::ArgumentNullException("Key"); + if (!IV || IV->Length <= 0) + throw gcnew System::ArgumentNullException("Key"); + + // TDeclare the streams used + // to decrypt to an in memory + // array of bytes. + System::IO::MemoryStream ^msDecrypt; + System::Security::Cryptography::CryptoStream ^csDecrypt; + + // Declare the RijndaelManaged object + // used to decrypt the data. + System::Security::Cryptography::RijndaelManaged ^aesAlg; + + // Declare the string used to hold + // the decrypted text. + cli::array ^plain = gcnew cli::array(cipherText->Length); + + try + { + // Create a RijndaelManaged object + // with the specified key and IV. + aesAlg = gcnew System::Security::Cryptography::RijndaelManaged(); + aesAlg->Mode = System::Security::Cryptography::CipherMode::CBC; // CBCƒ‚[ƒh + aesAlg->Key = Key; + aesAlg->IV = IV; + aesAlg->Padding = System::Security::Cryptography::PaddingMode::Zeros; + + // Create a decrytor to perform the stream transform. + System::Security::Cryptography::ICryptoTransform ^ decryptor + = aesAlg->CreateDecryptor(aesAlg->Key, aesAlg->IV); + + // Create the streams used for decryption. + msDecrypt = gcnew System::IO::MemoryStream(cipherText); + csDecrypt = gcnew System::Security::Cryptography::CryptoStream + (msDecrypt, decryptor, System::Security::Cryptography::CryptoStreamMode::Read); + csDecrypt->Read( plain, 0, cipherText->Length ); + //srDecrypt = gcnew System::IO::StreamReader(csDecrypt); + + //// Read the decrypted bytes from the decrypting stream + //// and place them in a string. + //plaintext = srDecrypt->ReadToEnd(); + } + finally + { + // Clean things up. + + // Close the streams. + if (csDecrypt) + csDecrypt->Close(); + if (msDecrypt) + msDecrypt->Close(); + + // Clear the RijndaelManaged object. + if (aesAlg) + aesAlg->Clear(); + } + return plain; +} + +// end of file diff --git a/build/tools/MasterEditor/split_tad_console/split_tad_console/split_tad.h b/build/tools/MasterEditor/split_tad_console/split_tad_console/split_tad.h new file mode 100644 index 0000000..9e21fe2 --- /dev/null +++ b/build/tools/MasterEditor/split_tad_console/split_tad_console/split_tad.h @@ -0,0 +1,73 @@ +#pragma once + +#include "twl/types.h" +#include +#include + + +// ------------------------------------------------------ +// APIs +// ------------------------------------------------------ + +// tad ƒtƒ@ƒCƒ‹‚©‚ç srl(0”Ԗڂ̃Rƒ“ƒeƒ“ƒc)‚𔲂«o‚· +// (split_tad_dev.pl ‚̈ÚA) +int splitTad( System::String ^filename ); + + +// ------------------------------------------------------ +// “à•”ˆ——p‚Ì\‘¢‘Ì(錾‚¾‚¯‚Å‚«‚È‚¢‚̂Ńwƒbƒ_‚É’u‚­) +// ------------------------------------------------------ + +// ƒRƒ“ƒeƒ“ƒcî•ñ‚Ì\‘¢‘Ì +ref class rcContentsInfo +{ +private: + System::UInt32 ^h_cid; + System::UInt16 ^h_idx; + System::UInt16 ^h_type; + System::UInt32 ^h_size; + cli::array ^h_hash; +public: + rcContentsInfo() + { + this->h_cid = gcnew System::UInt32; + this->h_idx = gcnew System::UInt16; + this->h_type = gcnew System::UInt16; + this->h_size = gcnew System::UInt32; + this->h_hash = gcnew cli::array(20); // ŒÅ’è’· : ‰ð•ú‚Ì•K—v‚È‚µ + } +public: + property System::UInt32 cid + { + void set( System::UInt32 v ){ *this->h_cid = v; }; + System::UInt32 get(void){ return *this->h_cid; } + } + property System::UInt16 idx + { + void set( System::UInt16 v ){ *this->h_idx = v; }; + System::UInt16 get(void){ return *this->h_idx; } + } + property System::UInt16 type + { + void set( System::UInt16 v ){ *this->h_type = v; }; + System::UInt16 get(void){ return *this->h_type; } + } + property System::UInt32 size + { + void set( System::UInt32 v ){ *this->h_size = v; }; + System::UInt32 get(void){ return *this->h_size; } + } + property cli::array ^hash + { + void set( cli::array ^h ) + { + cli::array::Copy( h, this->h_hash, 20 ); + } + cli::array ^get(void) + { + cli::array ^cp = gcnew cli::array(20); // ƒRƒs[‚ð•Ô‚· + cli::array::Copy( this->h_hash, cp, 20 ); + return cp; + } + } +}; diff --git a/build/tools/MasterEditor/split_tad_console/split_tad_console/split_tad_console.cpp b/build/tools/MasterEditor/split_tad_console/split_tad_console/split_tad_console.cpp new file mode 100644 index 0000000..943bff7 --- /dev/null +++ b/build/tools/MasterEditor/split_tad_console/split_tad_console/split_tad_console.cpp @@ -0,0 +1,17 @@ +// split_tad_console.cpp : ƒƒCƒ“ ƒvƒƒWƒFƒNƒg ƒtƒ@ƒCƒ‹‚Å‚·B + +#include "stdafx.h" +#include "twl/types.h" +#include +#include +#include "split_tad.h" + +using namespace System; + +int main(array ^args) +{ + splitTad( args[0] ); + + return 0; +} + diff --git a/build/tools/MasterEditor/split_tad_console/split_tad_console/split_tad_console.vcproj b/build/tools/MasterEditor/split_tad_console/split_tad_console/split_tad_console.vcproj new file mode 100644 index 0000000..bd0b7de --- /dev/null +++ b/build/tools/MasterEditor/split_tad_console/split_tad_console/split_tad_console.vcproj @@ -0,0 +1,266 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build/tools/MasterEditor/split_tad_console/split_tad_console/split_tad_console.vcproj.RED.nishikawa_takeshi.user b/build/tools/MasterEditor/split_tad_console/split_tad_console/split_tad_console.vcproj.RED.nishikawa_takeshi.user new file mode 100644 index 0000000..7963a7f --- /dev/null +++ b/build/tools/MasterEditor/split_tad_console/split_tad_console/split_tad_console.vcproj.RED.nishikawa_takeshi.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/build/tools/MasterEditor/split_tad_console/split_tad_console/split_tad_util.cpp b/build/tools/MasterEditor/split_tad_console/split_tad_console/split_tad_util.cpp new file mode 100644 index 0000000..3b7ff04 --- /dev/null +++ b/build/tools/MasterEditor/split_tad_console/split_tad_console/split_tad_util.cpp @@ -0,0 +1,149 @@ +#include "stdafx.h" +#include "twl/types.h" +#include +#include +#include "split_tad_util.h" + + +// ƒtƒ@ƒCƒ‹‚©‚ç•”•ªƒoƒCƒg—ñ‚𔲂«o‚· +cli::array^ subStr( FILE *fp, const int offset, const int size ) +{ + if( size <= 0 ) + { + return nullptr; + } + cli::array ^mbuf = gcnew cli::array(size); // ƒƒ‚ƒŠ‰ð•ú‚Ì•K—v‚È‚µ + pin_ptr buf = &mbuf[0]; // fread ‚ª unmanaged ”z—ñ‚ðˆø”‚É‚·‚é‚̂ŕϊ· + + (void)fseek( fp, offset, SEEK_SET ); + if( fread( buf, 1, size, fp ) != size ) + { + return nullptr; + } + return mbuf; // managed ‚̂ق¤‚ð•Ô‚· +} + +// ƒoƒCƒg—ñ‚©‚ç•”•ªƒoƒCƒg—ñ‚𔲂«o‚· +cli::array^ subStr( cli::array ^bytes, const int offset, const int size ) +{ + cli::array ^sub = gcnew cli::array(size); + + cli::array::Copy( bytes, offset, sub, 0, size ); + return sub; +} + +// ƒtƒ@ƒCƒ‹‚ð쬂µ‚ăoƒCƒg—ñ‚ðŠi”[‚·‚é +int saveFp( FILE *fp, cli::array ^bytes ) +{ + if( bytes == nullptr ) + { + return 0; // ‹ó‚̃tƒ@ƒCƒ‹‚ð‚‚­‚肽‚¢‚Æ‚¢‚¤‚±‚ƂȂ̂ųíI—¹‚Ƃ݂Ȃ· + } + pin_ptr tmp = &bytes[0]; // arrayŒ^‚͂ӂ‚¤‚Ì”z—ñ‚ł͂Ȃ¢‚̂ŃoƒCƒg”z—ñ‚ɕϊ· + int size = bytes->Length; + + if( fwrite( tmp, 1, size, fp ) != size ) + { + return -1; + } + return 0; +} + +int saveFile( System::String ^filename, cli::array ^bytes ) +{ + FILE *fp = NULL; + const char *pchFilename = + (const char*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi( filename ).ToPointer(); + + // ƒtƒ@ƒCƒ‹‚ÉROMƒwƒbƒ_‚ðƒ‰ƒCƒg + if( fopen_s( &fp, pchFilename, "wb" ) != NULL ) // ã‘‚«EƒoƒCƒiƒŠ + { + return -1; + } + fseek( fp, 0, SEEK_SET ); + int r = saveFp( fp, bytes ); + fclose( fp ); + + return r; +} + +// ƒGƒ“ƒfƒBƒAƒ“‚ð‹t“]‚³‚¹‚é(tad‚̓rƒbƒOƒGƒ“ƒfƒBƒAƒ“‚Ȃ̂ł ‚Á‚½‚Ù‚¤‚ª•Ö—˜) +u32 reverseEndian( const u32 v ) +{ + u32 ret = (v<<24) | ((v<<8) & 0x00FF0000) | ((v>>8) & 0x0000FF00) | (v>>24); + return ret; +} + +u16 reverseEndian( const u16 v ) +{ + u16 ret = (v<<8) | (v>>8); + return ret; +} + +// ‘½ƒoƒCƒg’l‚ðƒoƒCƒg—ñ‚ɕϊ·(ƒŠƒgƒ‹ƒGƒ“ƒfƒBƒAƒ“) *** perl‚Ìpack‚ðˆÓޝ *** +cli::array ^pack32( u32 v ) +{ + cli::array ^bytes = gcnew cli::array(4); + bytes[0] = v & 0xFF; + bytes[1] = (v >> 8) & 0xFF; + bytes[2] = (v >> 16) & 0xFF; + bytes[3] = (v >> 24) & 0xFF; + return bytes; +} + +cli::array ^pack16( u16 v ) +{ + cli::array ^bytes = gcnew cli::array(2); + bytes[0] = v & 0xFF; + bytes[1] = v >>8; + return bytes; +} + +// ƒoƒCƒg—ñ‚Ì•”•ªƒoƒCƒg—ñ‚©‚瑽ƒoƒCƒg’l‚Æ‚µ‚ĉðŽß(ƒŠƒgƒ‹ƒGƒ“ƒfƒBƒAƒ“) *** perl‚Ìunpack‚ðˆÓޝ *** +u32 unpack32( cli::array ^bytes, const int index ) +{ + pin_ptr tmp = &bytes[0]; + u32 v = (u32)*((u32*)(tmp+index)); + return v; +} + +u16 unpack16( cli::array ^bytes, const int index ) +{ + pin_ptr tmp = &bytes[0]; + u16 v = (u16)*((u16*)(tmp+index)); + return v; +} + +// ŠÛ‚ß‚é +u32 roundUp( const u32 v, const u32 align ) +{ + u32 r = ((v + align - 1) / align) * align; + return r; +} + +u16 roundUp( const u16 v, const u16 align ) +{ + u16 r = ((v + align - 1) / align) * align; + return r; +} + +// ƒoƒCƒg—ñ‚Ì’·‚³‚ðŠg’£‚µ‚Ä––”ö‚ð0‚Å–„‚ß‚é +// (0x12345678 => 0x1234567800000000) +cli::array ^resizeBytes( cli::array ^org, const int difSize ) +{ + cli::array ^r = gcnew cli::array( org->Length + difSize ); + cli::array::Copy( org, 0, r, 0, org->Length ); + return r; +} + +// ƒoƒCƒg—ñ‚ð16i‚Å•\ަ +void dumpBytes( cli::array ^bytes ) +{ + for each( System::Byte b in bytes ) + { + printf( "%02x", b ); + } + printf( "\n" ); +} + +// end of file diff --git a/build/tools/MasterEditor/split_tad_console/split_tad_console/split_tad_util.h b/build/tools/MasterEditor/split_tad_console/split_tad_console/split_tad_util.h new file mode 100644 index 0000000..1c31f5a --- /dev/null +++ b/build/tools/MasterEditor/split_tad_console/split_tad_console/split_tad_util.h @@ -0,0 +1,80 @@ +#pragma once + +#include "twl/types.h" +#include +#include + + +// ------------------------------------------------------ +// APIs +// ------------------------------------------------------ + +// +// ƒtƒ@ƒCƒ‹‚©‚ç•”•ªƒoƒCƒg—ñ‚𔲂«o‚· +// +// @ret ”²‚«o‚µ‚½ƒoƒCƒg—ñ +// +cli::array^ subStr( FILE *fp, const int offset, const int size ); + +// +// ƒoƒCƒg—ñ‚©‚ç•”•ªƒoƒCƒg—ñ‚𔲂«o‚· +// +// @ret ”²‚«o‚µ‚½ƒoƒCƒg—ñ +// +cli::array^ subStr( cli::array ^bytes, const int offset, const int size ); + +// +// ƒtƒ@ƒCƒ‹‚ð쬂µ‚ăoƒCƒg—ñ‚ðŠi”[‚·‚é +// +// @ret ¬Œ÷‚µ‚½‚ç0 ޏ”s‚µ‚½‚畉‚Ì’l +// +int saveFp( FILE *fp, cli::array ^bytes ); +int saveFile( System::String ^filename, cli::array ^bytes ); + +// +// ƒGƒ“ƒfƒBƒAƒ“‚ð‹t“]‚³‚¹‚é(tad‚̓rƒbƒOƒGƒ“ƒfƒBƒAƒ“‚Ȃ̂ł ‚Á‚½‚Ù‚¤‚ª•Ö—˜) +// +// @ret ƒGƒ“ƒfƒBƒAƒ“‹t“]Œã‚Ì’l +// +u32 reverseEndian( const u32 v ); +u16 reverseEndian( const u16 v ); + +// +// ‘½ƒoƒCƒg’l‚ðƒoƒCƒg—ñ‚ɕϊ·(ƒŠƒgƒ‹ƒGƒ“ƒfƒBƒAƒ“) *** perl‚Ìpack‚ðˆÓޝ *** +// +// @ret •ÏŠ·Œã‚̃oƒCƒg—ñ +// +cli::array ^pack32( u32 v ); +cli::array ^pack16( u16 v ); + +// +// ƒoƒCƒg—ñ‚Ì•”•ªƒoƒCƒg—ñ‚©‚瑽ƒoƒCƒg’l‚Æ‚µ‚ĉðŽß(ƒŠƒgƒ‹ƒGƒ“ƒfƒBƒAƒ“) *** perl‚Ìunpack‚ðˆÓޝ *** +// +// @arg [in] ƒoƒCƒg—ñ +// @arg [in] ‰½ƒoƒCƒg–Ú‚©‚ç‚𑽃oƒCƒg’l‚Ƃ݂Ȃ·‚© +// +// @ret ‰ðŽß‚µ‚½Œã‚Ì‘½ƒoƒCƒg’l +// +u32 unpack32( cli::array ^bytes, const int index ); +u16 unpack16( cli::array ^bytes, const int index ); + +// +// ŠÛ‚ß‚é +// +u32 roundUp( const u32 v, const u32 align ); +u16 roundUp( const u16 v, const u16 align ); + +// +// ƒoƒCƒg—ñ‚Ì’·‚³‚ðŠg’£‚µ‚Ä––”ö‚ð0‚Å–„‚ß‚é +// (0x12345678 => 0x1234567800000000) +// +// @arg [in] Šg’£‘O‚̃oƒCƒg—ñ +// @arg [in] ‰½ƒoƒCƒgŠg’£‚·‚é‚©(Šg’£•ª‚¾‚¯‚ðŽw’è —á‚¦‚Î4ƒoƒCƒg‚ð5ƒoƒCƒg‚É‚·‚éꇂɂÍ1‚ðŽw’è) +// +// @ret Šg’£Œã‚̃oƒCƒg—ñ(V‚½‚ȃoƒCƒg—ñ‚ð“à•”‚Ŷ¬) +// +cli::array ^resizeBytes( cli::array ^org, const int difSize ); + +// ƒoƒCƒg—ñ‚ð16i‚Å•\ަ +void dumpBytes( cli::array ^bytes ); + diff --git a/build/tools/MasterEditor/split_tad_console/split_tad_console/stdafx.cpp b/build/tools/MasterEditor/split_tad_console/split_tad_console/stdafx.cpp new file mode 100644 index 0000000..0ac359e --- /dev/null +++ b/build/tools/MasterEditor/split_tad_console/split_tad_console/stdafx.cpp @@ -0,0 +1,7 @@ +// stdafx.cpp : •W€ƒCƒ“ƒNƒ‹[ƒh split_tad_console.pch ‚݂̂ð +// ŠÜ‚Þƒ\[ƒX ƒtƒ@ƒCƒ‹‚ÍAƒvƒŠƒRƒ“ƒpƒCƒ‹Ï‚݃wƒbƒ_[‚ɂȂè‚Ü‚·B +// stdafx.obj ‚ɂ̓vƒŠƒRƒ“ƒpƒCƒ‹Ï‚ÝŒ^î•ñ‚ªŠÜ‚Ü‚ê‚Ü‚·B + +#include "stdafx.h" + + diff --git a/build/tools/MasterEditor/split_tad_console/split_tad_console/stdafx.h b/build/tools/MasterEditor/split_tad_console/split_tad_console/stdafx.h new file mode 100644 index 0000000..d0e2c99 --- /dev/null +++ b/build/tools/MasterEditor/split_tad_console/split_tad_console/stdafx.h @@ -0,0 +1,8 @@ +// stdafx.h : •W€‚̃VƒXƒeƒ€ ƒCƒ“ƒNƒ‹[ƒh ƒtƒ@ƒCƒ‹‚̃Cƒ“ƒNƒ‹[ƒh ƒtƒ@ƒCƒ‹A‚Ü‚½‚Í +// ŽQƉñ”‚ª‘½‚­A‚©‚‚ ‚Ü‚è•ÏX‚³‚ê‚È‚¢AƒvƒƒWƒFƒNƒgê—p‚̃Cƒ“ƒNƒ‹[ƒh ƒtƒ@ƒCƒ‹ +// ‚ð‹Lq‚µ‚Ü‚·B +// + +#pragma once + +// TODO: ƒvƒƒOƒ‰ƒ€‚É•K—v‚ȒljÁƒwƒbƒ_[‚ð‚±‚±‚ÅŽQÆ‚µ‚Ä‚­‚¾‚³‚¢B