mirror of
https://github.com/rvtr/TwlToolsRED.git
synced 2025-10-31 06:41:18 -04:00
split_tad C移植版:perlを移植。マスタエディタに組み込む実験のためにコマンドラインツールとして作成。いずれマスタエディタとソースを統合する。
git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlToolsRED@56 7061adef-622a-194b-ae81-725974e89856
This commit is contained in:
parent
0e98d26a61
commit
b9f04422fb
BIN
build/tools/MasterEditor/split_tad_console/split_tad_console.ncb
Normal file
BIN
build/tools/MasterEditor/split_tad_console/split_tad_console.ncb
Normal file
Binary file not shown.
@ -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
|
||||
BIN
build/tools/MasterEditor/split_tad_console/split_tad_console.suo
Normal file
BIN
build/tools/MasterEditor/split_tad_console/split_tad_console.suo
Normal file
Binary file not shown.
@ -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;
|
||||
|
||||
//
|
||||
// アセンブリに関する一般情報は以下の属性セットをとおして制御されます。
|
||||
// アセンブリに関連付けられている情報を変更するには、
|
||||
// これらの属性値を変更してください。
|
||||
//
|
||||
[assembly:AssemblyTitleAttribute("split_tad_console")];
|
||||
[assembly:AssemblyDescriptionAttribute("")];
|
||||
[assembly:AssemblyConfigurationAttribute("")];
|
||||
[assembly:AssemblyCompanyAttribute("任天堂株式会社")];
|
||||
[assembly:AssemblyProductAttribute("split_tad_console")];
|
||||
[assembly:AssemblyCopyrightAttribute("Copyright (c) 任天堂株式会社 2008")];
|
||||
[assembly:AssemblyTrademarkAttribute("")];
|
||||
[assembly:AssemblyCultureAttribute("")];
|
||||
|
||||
//
|
||||
// アセンブリのバージョン情報は、以下の 4 つの値で構成されています:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// すべての値を指定するか、下のように '*' を使ってリビジョンおよびビルド番号を
|
||||
// 既定値にすることができます:
|
||||
|
||||
[assembly:AssemblyVersionAttribute("1.0.*")];
|
||||
|
||||
[assembly:ComVisible(false)];
|
||||
|
||||
[assembly:CLSCompliantAttribute(true)];
|
||||
|
||||
[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)];
|
||||
Binary file not shown.
@ -0,0 +1,29 @@
|
||||
===============================================================================
|
||||
アプリケーション : split_tad_console プロジェクトの概要
|
||||
===============================================================================
|
||||
|
||||
この split_tad_console アプリケーションは、AppWizard によって作成されました。
|
||||
|
||||
このファイルには、split_tad_console アプリケーションを構成する各ファイルの
|
||||
内容の概略が記述されています。
|
||||
|
||||
split_tad_console.vcproj
|
||||
これは、アプリケーション ウィザードで生成される VC++ プロジェクトのメインの
|
||||
プロジェクト ファイルです。
|
||||
ファイルを生成した Visual C++ のバージョン情報と、アプリケーション ウィザー
|
||||
ドで選択したプラットフォーム、構成、およびプロジェクトの機能に関する情報が
|
||||
記述されています。
|
||||
|
||||
split_tad_console.cpp
|
||||
これは、メインのアプリケーション ソース ファイルです。
|
||||
|
||||
AssemblyInfo.cpp
|
||||
アセンブリ メタデータを変更するためのカスタム属性が含まれています。
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
その他のメモ :
|
||||
|
||||
AppWizard では、"TODO:" を使用して、ユーザーが追加またはカスタマイズするソース
|
||||
部分を示します。
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
@ -0,0 +1,63 @@
|
||||
// Microsoft Visual C++ で生成されたリソース スクリプトです。
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// 英語 (米国) リソース
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// アイコン
|
||||
//
|
||||
|
||||
// 最初に配置されたアイコン、または ID 値が最も低いアイコンが、アプリケーション アイコンになります。
|
||||
|
||||
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 リソースから生成されました。
|
||||
//
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // APSTUDIO_INVOKED でない場合
|
||||
|
||||
@ -0,0 +1,3 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ generated include file.
|
||||
// Used by app.rc
|
||||
@ -0,0 +1,252 @@
|
||||
#include "stdafx.h"
|
||||
#include "twl/types.h"
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include "split_tad.h"
|
||||
#include "split_tad_util.h"
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
// 宣言と定数
|
||||
// ------------------------------------------------------
|
||||
|
||||
// internal functions
|
||||
cli::array<System::Byte>^ readTitleKey( cli::array<System::Byte> ^ticket );
|
||||
cli::array<System::Byte>^ decCBC( cli::array<System::Byte> ^ Key, cli::array<System::Byte> ^ IV, cli::array<System::Byte> ^cipherText );
|
||||
cli::array<rcContentsInfo^> ^readContentsInfo( cli::array<System::Byte> ^tmd );
|
||||
|
||||
// tad外し用の鍵
|
||||
const u8 commonKey[] =
|
||||
{
|
||||
0xA1,0x60,0x4A,0x6A,0x71,0x23,0xB5,0x29,0xAE,0x8B,0xEC,0x32,0xC8,0x16,0xFC,0xAA
|
||||
};
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
// tad外し処理本体(split_tad_dev.pl の移植)
|
||||
// ------------------------------------------------------
|
||||
|
||||
//
|
||||
// tad ファイルから srl(0番目のコンテンツ)を抜き出す
|
||||
//
|
||||
// @ret 成功したとき0 失敗したら負の値
|
||||
//
|
||||
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<System::Byte> ^mbuf = subStr( fp, 0, 32 );
|
||||
|
||||
u32 hdrSize = reverseEndian( unpack32(mbuf, 0) ); // 基本的にビッグエンディアン
|
||||
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<System::Byte> ^ticket = subStr( fp, ticketOffset, ticketSize );
|
||||
cli::array<System::Byte> ^tmd = subStr( fp, tmdOffset, tmdSize );
|
||||
cli::array<System::Byte> ^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<System::Byte> ^titleKey = readTitleKey( ticket );
|
||||
cli::array<rcContentsInfo^> ^rci = readContentsInfo( tmd );
|
||||
dumpBytes( titleKey );
|
||||
|
||||
u32 offset = 0;
|
||||
for each( rcContentsInfo ^ci in rci )
|
||||
{
|
||||
u32 size = roundUp( (u32)ci->size, 16 );
|
||||
cli::array<System::Byte> ^enc_content_x = subStr( content, offset, size );
|
||||
cli::array<System::Byte> ^content_x_iv = resizeBytes( pack16( reverseEndian(ci->idx) ), 14 ); // ビッグエンディアンにしておく
|
||||
cli::array<System::Byte> ^dec_content_x = decCBC( titleKey, content_x_iv, enc_content_x );
|
||||
cli::array<System::Byte> ^dec_content = subStr( dec_content_x, 0, ci->size );
|
||||
System::Security::Cryptography::SHA1 ^sha1 = gcnew System::Security::Cryptography::SHA1Managed();
|
||||
cli::array<System::Byte> ^hash = sha1->ComputeHash( dec_content );
|
||||
|
||||
dumpBytes( hash );
|
||||
pin_ptr<unsigned char> calc = &hash[0]; // 計算で求めたハッシュ
|
||||
pin_ptr<unsigned char> extr = &ci->hash[0]; // 抽出したハッシュ
|
||||
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 のバイト列
|
||||
//
|
||||
cli::array<System::Byte>^ readTitleKey( cli::array<System::Byte> ^ticket )
|
||||
{
|
||||
cli::array<System::Byte> ^encTitleKey = subStr( ticket, 0x1BF, 16 );
|
||||
cli::array<System::Byte> ^IV = resizeBytes( subStr( ticket, 0x1DC, 8 ), 8 ); // 16バイトに拡張してケツの8バイトを0で埋める
|
||||
|
||||
cli::array<System::Byte> ^comKey = gcnew cli::array<System::Byte>(16);
|
||||
pin_ptr<unsigned char> pComKey = &comKey[0];
|
||||
memcpy( pComKey, commonKey, 16 );
|
||||
|
||||
cli::array<System::Byte> ^plain;
|
||||
try
|
||||
{
|
||||
plain = decCBC( comKey, IV, encTitleKey );
|
||||
}
|
||||
catch (System::Exception ^ e)
|
||||
{
|
||||
System::Console::WriteLine("Error: {0}", e->Message);
|
||||
}
|
||||
return plain;
|
||||
}
|
||||
|
||||
//
|
||||
// tmd から各コンテンツファイルの情報を抜き出す
|
||||
//
|
||||
// @ret 各コンテンツファイルの情報をまとめた Array
|
||||
//
|
||||
cli::array<rcContentsInfo^> ^readContentsInfo( cli::array<System::Byte> ^tmd )
|
||||
{
|
||||
u16 nContent = reverseEndian( unpack16(tmd, 0x1DE) );
|
||||
cli::array<rcContentsInfo^> ^ci = gcnew cli::array<rcContentsInfo^>( 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 のヘルプのサンプルをコピペ
|
||||
//
|
||||
// @ret 復号後のデータ
|
||||
//
|
||||
cli::array<System::Byte>^ decCBC( cli::array<System::Byte> ^ Key, cli::array<System::Byte> ^ IV, cli::array<System::Byte> ^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<System::Byte> ^plain = gcnew cli::array<System::Byte>(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モード
|
||||
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
|
||||
@ -0,0 +1,73 @@
|
||||
#pragma once
|
||||
|
||||
#include "twl/types.h"
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
// APIs
|
||||
// ------------------------------------------------------
|
||||
|
||||
// tad ファイルから srl(0番目のコンテンツ)を抜き出す
|
||||
// (split_tad_dev.pl の移植)
|
||||
int splitTad( System::String ^filename );
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
// 内部処理用の構造体(宣言だけできないのでヘッダに置く)
|
||||
// ------------------------------------------------------
|
||||
|
||||
// コンテンツ情報の構造体
|
||||
ref class rcContentsInfo
|
||||
{
|
||||
private:
|
||||
System::UInt32 ^h_cid;
|
||||
System::UInt16 ^h_idx;
|
||||
System::UInt16 ^h_type;
|
||||
System::UInt32 ^h_size;
|
||||
cli::array<System::Byte> ^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<System::Byte>(20); // 固定長 : 解放の必要なし
|
||||
}
|
||||
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<System::Byte> ^hash
|
||||
{
|
||||
void set( cli::array<System::Byte> ^h )
|
||||
{
|
||||
cli::array<System::Byte>::Copy( h, this->h_hash, 20 );
|
||||
}
|
||||
cli::array<System::Byte> ^get(void)
|
||||
{
|
||||
cli::array<System::Byte> ^cp = gcnew cli::array<System::Byte>(20); // コピーを返す
|
||||
cli::array<System::Byte>::Copy( this->h_hash, cp, 20 );
|
||||
return cp;
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -0,0 +1,17 @@
|
||||
// split_tad_console.cpp : メイン プロジェクト ファイルです。
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "twl/types.h"
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include "split_tad.h"
|
||||
|
||||
using namespace System;
|
||||
|
||||
int main(array<System::String ^> ^args)
|
||||
{
|
||||
splitTad( args[0] );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -0,0 +1,266 @@
|
||||
<?xml version="1.0" encoding="shift_jis"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="9.00"
|
||||
Name="split_tad_console"
|
||||
ProjectGUID="{B89F1089-C492-4520-93FE-E40FA17D00CE}"
|
||||
RootNamespace="split_tad_console"
|
||||
Keyword="ManagedCProj"
|
||||
TargetFrameworkVersion="131072"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
ManagedExtensions="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="C:\twlsdk\build\tools\makerom.TWL;C:\twlsdk\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG"
|
||||
RuntimeLibrary="3"
|
||||
UsePrecompiledHeader="2"
|
||||
WarningLevel="3"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="libacsign_X86.a libaes_X86.a libdigest_X86.a libflags_X86.a $(NOINHERIT)"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories=""C:\Documents and Settings\nishikawa_takeshi\My Documents\Visual Studio 2008\Projects\MasterEditorTWL_Common\flags\lib\X86";C:\twlsdk\build\tools\makerom.TWL\digest\lib\X86;C:\twlsdk\build\tools\makerom.TWL\aes\lib\X86;C:\twlsdk\build\tools\makerom.TWL\acsign\lib\X86"
|
||||
GenerateDebugInformation="true"
|
||||
AssemblyDebug="1"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
ManagedExtensions="1"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG"
|
||||
RuntimeLibrary="2"
|
||||
UsePrecompiledHeader="2"
|
||||
WarningLevel="3"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="$(NoInherit)"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="true"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
<AssemblyReference
|
||||
RelativePath="System.dll"
|
||||
AssemblyName="System, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"
|
||||
MinFrameworkVersion="131072"
|
||||
/>
|
||||
<AssemblyReference
|
||||
RelativePath="System.Data.dll"
|
||||
AssemblyName="System.Data, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089, processorArchitecture=x86"
|
||||
MinFrameworkVersion="131072"
|
||||
/>
|
||||
<AssemblyReference
|
||||
RelativePath="System.XML.dll"
|
||||
AssemblyName="System.Xml, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"
|
||||
MinFrameworkVersion="131072"
|
||||
/>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="ソース ファイル"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\AssemblyInfo.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\split_tad.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\split_tad_console.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\split_tad_util.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\stdafx.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="1"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="1"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="ヘッダー ファイル"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\resource.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\split_tad.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\split_tad_util.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\stdafx.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="リソース ファイル"
|
||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
|
||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\app.ico"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\app.rc"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath=".\ReadMe.txt"
|
||||
>
|
||||
</File>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="shift_jis"?>
|
||||
<VisualStudioUserFile
|
||||
ProjectType="Visual C++"
|
||||
Version="9.00"
|
||||
ShowAllFiles="false"
|
||||
>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<DebugSettings
|
||||
Command="$(TargetPath)"
|
||||
WorkingDirectory=""
|
||||
CommandArguments=""
|
||||
Attach="false"
|
||||
DebuggerType="3"
|
||||
Remote="1"
|
||||
RemoteMachine="PC2355"
|
||||
RemoteCommand=""
|
||||
HttpUrl=""
|
||||
PDBPath=""
|
||||
SQLDebugging=""
|
||||
Environment=""
|
||||
EnvironmentMerge="true"
|
||||
DebuggerFlavor=""
|
||||
MPIRunCommand=""
|
||||
MPIRunArguments=""
|
||||
MPIRunWorkingDirectory=""
|
||||
ApplicationCommand=""
|
||||
ApplicationArguments=""
|
||||
ShimCommand=""
|
||||
MPIAcceptMode=""
|
||||
MPIAcceptFilter=""
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<DebugSettings
|
||||
Command="$(TargetPath)"
|
||||
WorkingDirectory=""
|
||||
CommandArguments=""
|
||||
Attach="false"
|
||||
DebuggerType="3"
|
||||
Remote="1"
|
||||
RemoteMachine="PC2355"
|
||||
RemoteCommand=""
|
||||
HttpUrl=""
|
||||
PDBPath=""
|
||||
SQLDebugging=""
|
||||
Environment=""
|
||||
EnvironmentMerge="true"
|
||||
DebuggerFlavor=""
|
||||
MPIRunCommand=""
|
||||
MPIRunArguments=""
|
||||
MPIRunWorkingDirectory=""
|
||||
ApplicationCommand=""
|
||||
ApplicationArguments=""
|
||||
ShimCommand=""
|
||||
MPIAcceptMode=""
|
||||
MPIAcceptFilter=""
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
</VisualStudioUserFile>
|
||||
@ -0,0 +1,149 @@
|
||||
#include "stdafx.h"
|
||||
#include "twl/types.h"
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include "split_tad_util.h"
|
||||
|
||||
|
||||
// ファイルから部分バイト列を抜き出す
|
||||
cli::array<System::Byte>^ subStr( FILE *fp, const int offset, const int size )
|
||||
{
|
||||
if( size <= 0 )
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
cli::array<System::Byte> ^mbuf = gcnew cli::array<System::Byte>(size); // メモリ解放の必要なし
|
||||
pin_ptr<unsigned char> buf = &mbuf[0]; // fread が unmanaged 配列を引数にするので変換
|
||||
|
||||
(void)fseek( fp, offset, SEEK_SET );
|
||||
if( fread( buf, 1, size, fp ) != size )
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
return mbuf; // managed のほうを返す
|
||||
}
|
||||
|
||||
// バイト列から部分バイト列を抜き出す
|
||||
cli::array<System::Byte>^ subStr( cli::array<System::Byte> ^bytes, const int offset, const int size )
|
||||
{
|
||||
cli::array<System::Byte> ^sub = gcnew cli::array<System::Byte>(size);
|
||||
|
||||
cli::array<System::Byte>::Copy( bytes, offset, sub, 0, size );
|
||||
return sub;
|
||||
}
|
||||
|
||||
// ファイルを作成してバイト列を格納する
|
||||
int saveFp( FILE *fp, cli::array<System::Byte> ^bytes )
|
||||
{
|
||||
if( bytes == nullptr )
|
||||
{
|
||||
return 0; // 空のファイルをつくりたいということなので正常終了とみなす
|
||||
}
|
||||
pin_ptr<unsigned char> tmp = &bytes[0]; // array型はふつうの配列ではないのでバイト配列に変換
|
||||
int size = bytes->Length;
|
||||
|
||||
if( fwrite( tmp, 1, size, fp ) != size )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int saveFile( System::String ^filename, cli::array<System::Byte> ^bytes )
|
||||
{
|
||||
FILE *fp = NULL;
|
||||
const char *pchFilename =
|
||||
(const char*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi( filename ).ToPointer();
|
||||
|
||||
// ファイルにROMヘッダをライト
|
||||
if( fopen_s( &fp, pchFilename, "wb" ) != NULL ) // 上書き・バイナリ
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
fseek( fp, 0, SEEK_SET );
|
||||
int r = saveFp( fp, bytes );
|
||||
fclose( fp );
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
// エンディアンを逆転させる(tadはビッグエンディアンなのであったほうが便利)
|
||||
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;
|
||||
}
|
||||
|
||||
// 多バイト値をバイト列に変換(リトルエンディアン) *** perlのpackを意識 ***
|
||||
cli::array<System::Byte> ^pack32( u32 v )
|
||||
{
|
||||
cli::array<System::Byte> ^bytes = gcnew cli::array<System::Byte>(4);
|
||||
bytes[0] = v & 0xFF;
|
||||
bytes[1] = (v >> 8) & 0xFF;
|
||||
bytes[2] = (v >> 16) & 0xFF;
|
||||
bytes[3] = (v >> 24) & 0xFF;
|
||||
return bytes;
|
||||
}
|
||||
|
||||
cli::array<System::Byte> ^pack16( u16 v )
|
||||
{
|
||||
cli::array<System::Byte> ^bytes = gcnew cli::array<System::Byte>(2);
|
||||
bytes[0] = v & 0xFF;
|
||||
bytes[1] = v >>8;
|
||||
return bytes;
|
||||
}
|
||||
|
||||
// バイト列の部分バイト列から多バイト値として解釈(リトルエンディアン) *** perlのunpackを意識 ***
|
||||
u32 unpack32( cli::array<System::Byte> ^bytes, const int index )
|
||||
{
|
||||
pin_ptr<unsigned char> tmp = &bytes[0];
|
||||
u32 v = (u32)*((u32*)(tmp+index));
|
||||
return v;
|
||||
}
|
||||
|
||||
u16 unpack16( cli::array<System::Byte> ^bytes, const int index )
|
||||
{
|
||||
pin_ptr<unsigned char> 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;
|
||||
}
|
||||
|
||||
// バイト列の長さを拡張して末尾を0で埋める
|
||||
// (0x12345678 => 0x1234567800000000)
|
||||
cli::array<System::Byte> ^resizeBytes( cli::array<System::Byte> ^org, const int difSize )
|
||||
{
|
||||
cli::array<System::Byte> ^r = gcnew cli::array<System::Byte>( org->Length + difSize );
|
||||
cli::array<System::Byte>::Copy( org, 0, r, 0, org->Length );
|
||||
return r;
|
||||
}
|
||||
|
||||
// バイト列を16進で表示
|
||||
void dumpBytes( cli::array<System::Byte> ^bytes )
|
||||
{
|
||||
for each( System::Byte b in bytes )
|
||||
{
|
||||
printf( "%02x", b );
|
||||
}
|
||||
printf( "\n" );
|
||||
}
|
||||
|
||||
// end of file
|
||||
@ -0,0 +1,80 @@
|
||||
#pragma once
|
||||
|
||||
#include "twl/types.h"
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
// APIs
|
||||
// ------------------------------------------------------
|
||||
|
||||
//
|
||||
// ファイルから部分バイト列を抜き出す
|
||||
//
|
||||
// @ret 抜き出したバイト列
|
||||
//
|
||||
cli::array<System::Byte>^ subStr( FILE *fp, const int offset, const int size );
|
||||
|
||||
//
|
||||
// バイト列から部分バイト列を抜き出す
|
||||
//
|
||||
// @ret 抜き出したバイト列
|
||||
//
|
||||
cli::array<System::Byte>^ subStr( cli::array<System::Byte> ^bytes, const int offset, const int size );
|
||||
|
||||
//
|
||||
// ファイルを作成してバイト列を格納する
|
||||
//
|
||||
// @ret 成功したら0 失敗したら負の値
|
||||
//
|
||||
int saveFp( FILE *fp, cli::array<System::Byte> ^bytes );
|
||||
int saveFile( System::String ^filename, cli::array<System::Byte> ^bytes );
|
||||
|
||||
//
|
||||
// エンディアンを逆転させる(tadはビッグエンディアンなのであったほうが便利)
|
||||
//
|
||||
// @ret エンディアン逆転後の値
|
||||
//
|
||||
u32 reverseEndian( const u32 v );
|
||||
u16 reverseEndian( const u16 v );
|
||||
|
||||
//
|
||||
// 多バイト値をバイト列に変換(リトルエンディアン) *** perlのpackを意識 ***
|
||||
//
|
||||
// @ret 変換後のバイト列
|
||||
//
|
||||
cli::array<System::Byte> ^pack32( u32 v );
|
||||
cli::array<System::Byte> ^pack16( u16 v );
|
||||
|
||||
//
|
||||
// バイト列の部分バイト列から多バイト値として解釈(リトルエンディアン) *** perlのunpackを意識 ***
|
||||
//
|
||||
// @arg [in] バイト列
|
||||
// @arg [in] 何バイト目からを多バイト値とみなすか
|
||||
//
|
||||
// @ret 解釈した後の多バイト値
|
||||
//
|
||||
u32 unpack32( cli::array<System::Byte> ^bytes, const int index );
|
||||
u16 unpack16( cli::array<System::Byte> ^bytes, const int index );
|
||||
|
||||
//
|
||||
// 丸める
|
||||
//
|
||||
u32 roundUp( const u32 v, const u32 align );
|
||||
u16 roundUp( const u16 v, const u16 align );
|
||||
|
||||
//
|
||||
// バイト列の長さを拡張して末尾を0で埋める
|
||||
// (0x12345678 => 0x1234567800000000)
|
||||
//
|
||||
// @arg [in] 拡張前のバイト列
|
||||
// @arg [in] 何バイト拡張するか(拡張分だけを指定 例えば4バイトを5バイトにする場合には1を指定)
|
||||
//
|
||||
// @ret 拡張後のバイト列(新たなバイト列を内部で生成)
|
||||
//
|
||||
cli::array<System::Byte> ^resizeBytes( cli::array<System::Byte> ^org, const int difSize );
|
||||
|
||||
// バイト列を16進で表示
|
||||
void dumpBytes( cli::array<System::Byte> ^bytes );
|
||||
|
||||
@ -0,0 +1,7 @@
|
||||
// stdafx.cpp : 標準インクルード split_tad_console.pch のみを
|
||||
// 含むソース ファイルは、プリコンパイル済みヘッダーになります。
|
||||
// stdafx.obj にはプリコンパイル済み型情報が含まれます。
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
// stdafx.h : 標準のシステム インクルード ファイルのインクルード ファイル、または
|
||||
// 参照回数が多く、かつあまり変更されない、プロジェクト専用のインクルード ファイル
|
||||
// を記述します。
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
// TODO: プログラムに必要な追加ヘッダーをここで参照してください。
|
||||
Loading…
Reference in New Issue
Block a user