diff --git a/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL.ncb b/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL.ncb index 3345b57..d071236 100644 Binary files a/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL.ncb and b/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL.ncb differ diff --git a/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL.suo b/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL.suo index 434aa88..f84c0fc 100644 Binary files a/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL.suo and b/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL.suo differ diff --git a/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/FingerPrinterTWL.cpp b/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/FingerPrinterTWL.cpp index 76f2c4f..b51a62e 100644 --- a/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/FingerPrinterTWL.cpp +++ b/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/FingerPrinterTWL.cpp @@ -3,16 +3,43 @@ #include "stdafx.h" #include "Form1.h" +extern void fingerprintConsole( cli::array ^args ); + using namespace FingerPrinterTWL; [STAThreadAttribute] int main(array ^args) { - // コントロールが作成される前に、Windows XP ビジュアル効果を有効にします - Application::EnableVisualStyles(); - Application::SetCompatibleTextRenderingDefault(false); + // GUIモードかチェック + bool guimode = false; + for each( System::String ^arg in args ) + { + if( arg->StartsWith("-") && (arg->IndexOf('g') >= 0) ) + { + guimode = true; + } + } - // メイン ウィンドウを作成して、実行します - Application::Run(gcnew Form1()); + if( (args->Length == 0) || guimode ) + { + // コントロールが作成される前に、Windows XP ビジュアル効果を有効にします + Application::EnableVisualStyles(); + Application::SetCompatibleTextRenderingDefault(false); + + // メイン ウィンドウを作成して、実行します + Application::Run(gcnew Form1()); + } + else + { + try + { + fingerprintConsole( args ); + } + catch( System::Exception ^ex ) + { + System::Console::WriteLine(ex->Message); + return -1; + } + } return 0; } diff --git a/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/FingerPrinterTWL.vcproj b/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/FingerPrinterTWL.vcproj index fce5c15..eb30221 100644 --- a/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/FingerPrinterTWL.vcproj +++ b/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/FingerPrinterTWL.vcproj @@ -203,6 +203,10 @@ RelativePath=".\AssemblyInfo.cpp" > + + diff --git a/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/FingerPrinterTWL.vcproj.RED.nishikawa_takeshi.user b/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/FingerPrinterTWL.vcproj.RED.nishikawa_takeshi.user index 7963a7f..58b35ae 100644 --- a/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/FingerPrinterTWL.vcproj.RED.nishikawa_takeshi.user +++ b/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/FingerPrinterTWL.vcproj.RED.nishikawa_takeshi.user @@ -11,7 +11,7 @@ SRL."); + throw gcnew Exception("Failed to transform TAD => SRL."); } this->srlbin = ReadBin(tmp); System::IO::File::Delete(tmp); // 中間ファイルを削除する @@ -132,7 +132,7 @@ void Form1::commonSaveRom( System::String ^dstpath ) if( this->rTad->Checked && !(this->rh->s.titleID_Hi && TITLE_ID_MEDIA_MASK) ) { - throw gcnew Exception("Cannot make TAD file for software intended for Game Card."); + throw gcnew Exception("Cannot make TAD file from the software intended for Game Card."); } this->fingerprintRomHeader(); @@ -144,6 +144,7 @@ void Form1::commonSaveRom( System::String ^dstpath ) System::String ^tmp = ".\\tmp" + System::DateTime::Now.ToString("yyyyMMddHHmmss") + ".srl"; WriteBin( tmp, this->srlbin ); makeTad( maketad_path, tmp, dstpath ); + System::IO::File::Delete(tmp); } else { @@ -155,19 +156,11 @@ void Form1::commonSaveRom( System::String ^dstpath ) // ボタンが押されたときの処理 (catch文必須) // ------------------------------------------------------------------ -void Form1::procOpenRomButton( System::String ^path ) +void Form1::procOpenRomButton() { try { - System::String ^rompath = nullptr; - if( !path ) - { - rompath = OpenFileUsingDialog( this->prevDir, "rom format (*.srl;*.tad)|*.srl;*.tad|All files (*.*)|*.*" ); - } - else - { - rompath = System::String::Copy(path); - } + System::String ^rompath = OpenFileUsingDialog( this->prevDir, "rom format (*.srl;*.tad)|*.srl;*.tad|All files (*.*)|*.*" ); if( !rompath ) { return; @@ -177,10 +170,7 @@ void Form1::procOpenRomButton( System::String ^path ) this->tboxFile->SelectionStart = rompath->Length; // 入りきらないときに右端を表示する this->rSrl->Checked = true; this->rTad->Checked = false; - if( !path ) - { - this->prevDir = System::IO::Path::GetDirectoryName( rompath ); // あらかじめパスが指定されたときには更新しない - } + this->prevDir = System::IO::Path::GetDirectoryName( rompath ); // あらかじめパスが指定されたときには更新しない } catch( System::Exception ^ex ) { @@ -221,6 +211,23 @@ void Form1::procSaveRomButton() } } +void Form1::procDragDrop( System::String ^rompath ) +{ + try + { + this->commonOpenRom( rompath ); + this->tboxFile->Text = rompath; + this->tboxFile->SelectionStart = rompath->Length; // 入りきらないときに右端を表示する + this->rSrl->Checked = true; + this->rTad->Checked = false; + } + catch( System::Exception ^ex ) + { + this->tboxFile->Text = ""; // クリア + this->errMsg( ex->Message ); + } +} + void Form1::procAboutButton() { try diff --git a/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/Form1.h b/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/Form1.h index 93e4503..4137ff8 100644 --- a/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/Form1.h +++ b/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/Form1.h @@ -338,8 +338,9 @@ namespace FingerPrinterTWL { // ボタンが押されたときの処理(例外catchを入れること) private: - void procOpenRomButton( System::String ^path ); + void procOpenRomButton(); void procSaveRomButton(); + void procDragDrop( System::String ^rompath ); void procAboutButton(); // ダイアログ @@ -355,7 +356,7 @@ namespace FingerPrinterTWL { private: System::Void butFile_Click(System::Object^ sender, System::EventArgs^ e) { - this->procOpenRomButton(nullptr); + this->procOpenRomButton(); } private: System::Void butFP_Click(System::Object^ sender, System::EventArgs^ e) @@ -376,7 +377,7 @@ namespace FingerPrinterTWL { { array ^files = dynamic_cast< array ^>(e->Data->GetData( DataFormats::FileDrop ) ); String ^path = files[0]; - this->procOpenRomButton( path ); // ボタンが押されたときと同じ挙動 + this->procDragDrop( path ); } // 再びボタン private: diff --git a/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/FormAbout.cpp b/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/FormAbout.cpp new file mode 100644 index 0000000..a202a0c --- /dev/null +++ b/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/FormAbout.cpp @@ -0,0 +1,3 @@ +#include "StdAfx.h" +#include "FormAbout.h" + diff --git a/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/FormAbout.h b/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/FormAbout.h new file mode 100644 index 0000000..d53f6ff --- /dev/null +++ b/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/FormAbout.h @@ -0,0 +1,156 @@ +#pragma once + +using namespace System; +using namespace System::ComponentModel; +using namespace System::Collections; +using namespace System::Windows::Forms; +using namespace System::Data; +using namespace System::Drawing; + + +namespace FingerPrinterTWL { + + /// + /// FormAbout の概要 + /// + /// 警告: このクラスの名前を変更する場合、このクラスが依存するすべての .resx ファイルに関連付けられた + /// マネージ リソース コンパイラ ツールに対して 'Resource File Name' プロパティを + /// 変更する必要があります。この変更を行わないと、 + /// デザイナと、このフォームに関連付けられたローカライズ済みリソースとが、 + /// 正しく相互に利用できなくなります。 + /// + public ref class FormAbout : public System::Windows::Forms::Form + { + public: + FormAbout(void) + { + InitializeComponent(); + // + //TODO: ここにコンストラクタ コードを追加します + // + this->construct(); + } + + protected: + /// + /// 使用中のリソースをすべてクリーンアップします。 + /// + ~FormAbout() + { + if (components) + { + delete components; + } + } + private: System::Windows::Forms::Label^ lab; + protected: + private: System::Windows::Forms::Label^ labVersion; + private: System::Windows::Forms::Label^ label1; + private: System::Windows::Forms::TextBox^ tboxRemarks; + private: System::Windows::Forms::Button^ butOK; + + protected: + + private: + /// + /// 必要なデザイナ変数です。 + /// + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + /// + /// デザイナ サポートに必要なメソッドです。このメソッドの内容を + /// コード エディタで変更しないでください。 + /// + void InitializeComponent(void) + { + this->lab = (gcnew System::Windows::Forms::Label()); + this->labVersion = (gcnew System::Windows::Forms::Label()); + this->label1 = (gcnew System::Windows::Forms::Label()); + this->tboxRemarks = (gcnew System::Windows::Forms::TextBox()); + this->butOK = (gcnew System::Windows::Forms::Button()); + this->SuspendLayout(); + // + // lab + // + this->lab->AutoSize = true; + this->lab->Location = System::Drawing::Point(29, 25); + this->lab->Name = L"lab"; + this->lab->Size = System::Drawing::Size(96, 12); + this->lab->TabIndex = 0; + this->lab->Text = L"TWL Fingerprinter"; + // + // labVersion + // + this->labVersion->AutoSize = true; + this->labVersion->Location = System::Drawing::Point(29, 46); + this->labVersion->Name = L"labVersion"; + this->labVersion->Size = System::Drawing::Size(44, 12); + this->labVersion->TabIndex = 1; + this->labVersion->Text = L"Version"; + // + // label1 + // + this->label1->AutoSize = true; + this->label1->Location = System::Drawing::Point(29, 67); + this->label1->Name = L"label1"; + this->label1->Size = System::Drawing::Size(138, 12); + this->label1->TabIndex = 2; + this->label1->Text = L"(C)2009 Nintendo Co., Ltd."; + // + // tboxRemarks + // + this->tboxRemarks->BackColor = System::Drawing::SystemColors::MenuBar; + this->tboxRemarks->Location = System::Drawing::Point(23, 101); + this->tboxRemarks->Multiline = true; + this->tboxRemarks->Name = L"tboxRemarks"; + this->tboxRemarks->Size = System::Drawing::Size(238, 70); + this->tboxRemarks->TabIndex = 3; + // + // butOK + // + this->butOK->Location = System::Drawing::Point(103, 190); + this->butOK->Name = L"butOK"; + this->butOK->Size = System::Drawing::Size(75, 23); + this->butOK->TabIndex = 4; + this->butOK->Text = L"OK"; + this->butOK->UseVisualStyleBackColor = true; + this->butOK->Click += gcnew System::EventHandler(this, &FormAbout::butOK_Click); + // + // FormAbout + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 12); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(292, 230); + this->Controls->Add(this->butOK); + this->Controls->Add(this->tboxRemarks); + this->Controls->Add(this->label1); + this->Controls->Add(this->labVersion); + this->Controls->Add(this->lab); + this->Name = L"FormAbout"; + this->Text = L"FormAbout"; + this->ResumeLayout(false); + this->PerformLayout(); + + } +#pragma endregion + + private: + void construct() + { + // バージョン情報 + System::Reflection::Assembly ^ass = System::Reflection::Assembly::GetEntryAssembly(); + System::Version ^ver = ass->GetName()->Version; + this->labVersion->Text = "Version " + ver->Major.ToString() + "." + ver->Minor.ToString(); + // OpenSSL ライセンス注意書き + this->tboxRemarks->Text = "This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit (http://www.openssl.org/)"; + this->tboxRemarks->SelectionStart = 0; + } + + private: + System::Void butOK_Click(System::Object^ sender, System::EventArgs^ e) + { + this->Close(); + } +}; +} diff --git a/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/FormAbout.resx b/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/FormAbout.resx new file mode 100644 index 0000000..ff31a6d --- /dev/null +++ b/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/FormAbout.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/FormCheck.cpp b/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/FormCheck.cpp new file mode 100644 index 0000000..bd8e694 --- /dev/null +++ b/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/FormCheck.cpp @@ -0,0 +1,3 @@ +#include "StdAfx.h" +#include "FormCheck.h" + diff --git a/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/FormCheck.h b/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/FormCheck.h new file mode 100644 index 0000000..f9622e8 --- /dev/null +++ b/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/FormCheck.h @@ -0,0 +1,197 @@ +#pragma once + +#include "fingerprint_util.h" + +using namespace System; +using namespace System::ComponentModel; +using namespace System::Collections; +using namespace System::Windows::Forms; +using namespace System::Data; +using namespace System::Drawing; + + +namespace FingerPrinterTWL { + + /// + /// FormCheck の概要 + /// + /// 警告: このクラスの名前を変更する場合、このクラスが依存するすべての .resx ファイルに関連付けられた + /// マネージ リソース コンパイラ ツールに対して 'Resource File Name' プロパティを + /// 変更する必要があります。この変更を行わないと、 + /// デザイナと、このフォームに関連付けられたローカライズ済みリソースとが、 + /// 正しく相互に利用できなくなります。 + /// + public ref class FormCheck : public System::Windows::Forms::Form + { + public: + FormCheck(void) + { + InitializeComponent(); + // + //TODO: ここにコンストラクタ コードを追加します + // + } + + protected: + /// + /// 使用中のリソースをすべてクリーンアップします。 + /// + ~FormCheck() + { + if (components) + { + delete components; + } + } + private: System::Windows::Forms::Label^ labMsg; + private: System::Windows::Forms::Label^ labWarning; + private: System::Windows::Forms::Label^ labAscii; + private: System::Windows::Forms::Label^ labHex; + private: System::Windows::Forms::TextBox^ tboxAscii; + private: System::Windows::Forms::TextBox^ tboxHex; + private: System::Windows::Forms::Button^ butOK; + + + + protected: + + + private: + /// + /// 必要なデザイナ変数です。 + /// + System::ComponentModel::Container ^components; + +#pragma region Windows Form Designer generated code + /// + /// デザイナ サポートに必要なメソッドです。このメソッドの内容を + /// コード エディタで変更しないでください。 + /// + void InitializeComponent(void) + { + this->labMsg = (gcnew System::Windows::Forms::Label()); + this->labWarning = (gcnew System::Windows::Forms::Label()); + this->labAscii = (gcnew System::Windows::Forms::Label()); + this->labHex = (gcnew System::Windows::Forms::Label()); + this->tboxAscii = (gcnew System::Windows::Forms::TextBox()); + this->tboxHex = (gcnew System::Windows::Forms::TextBox()); + this->butOK = (gcnew System::Windows::Forms::Button()); + this->SuspendLayout(); + // + // labMsg + // + this->labMsg->AutoSize = true; + this->labMsg->Location = System::Drawing::Point(21, 27); + this->labMsg->Name = L"labMsg"; + this->labMsg->Size = System::Drawing::Size(290, 12); + this->labMsg->TabIndex = 0; + this->labMsg->Text = L"The fingerprint has been registered in the ROM already."; + // + // labWarning + // + this->labWarning->AutoSize = true; + this->labWarning->Location = System::Drawing::Point(21, 47); + this->labWarning->Name = L"labWarning"; + this->labWarning->Size = System::Drawing::Size(261, 12); + this->labWarning->TabIndex = 1; + this->labWarning->Text = L"You can replace it with new one by re-registering."; + // + // labAscii + // + this->labAscii->AutoSize = true; + this->labAscii->Location = System::Drawing::Point(21, 96); + this->labAscii->Name = L"labAscii"; + this->labAscii->Size = System::Drawing::Size(94, 12); + this->labAscii->TabIndex = 2; + this->labAscii->Text = L"ASCII Characters"; + // + // labHex + // + this->labHex->AutoSize = true; + this->labHex->Location = System::Drawing::Point(21, 167); + this->labHex->Name = L"labHex"; + this->labHex->Size = System::Drawing::Size(119, 12); + this->labHex->TabIndex = 3; + this->labHex->Text = L"Hexadecimal Numbers"; + // + // tboxAscii + // + this->tboxAscii->Location = System::Drawing::Point(23, 111); + this->tboxAscii->Multiline = true; + this->tboxAscii->Name = L"tboxAscii"; + this->tboxAscii->ReadOnly = true; + this->tboxAscii->Size = System::Drawing::Size(288, 37); + this->tboxAscii->TabIndex = 4; + // + // tboxHex + // + this->tboxHex->Location = System::Drawing::Point(23, 182); + this->tboxHex->Multiline = true; + this->tboxHex->Name = L"tboxHex"; + this->tboxHex->ReadOnly = true; + this->tboxHex->Size = System::Drawing::Size(288, 37); + this->tboxHex->TabIndex = 5; + // + // butOK + // + this->butOK->Location = System::Drawing::Point(172, 257); + this->butOK->Name = L"butOK"; + this->butOK->Size = System::Drawing::Size(75, 23); + this->butOK->TabIndex = 6; + this->butOK->Text = L"OK"; + this->butOK->UseVisualStyleBackColor = true; + this->butOK->Click += gcnew System::EventHandler(this, &FormCheck::butOK_Click); + // + // FormCheck + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 12); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->ClientSize = System::Drawing::Size(418, 296); + this->Controls->Add(this->butOK); + this->Controls->Add(this->tboxHex); + this->Controls->Add(this->tboxAscii); + this->Controls->Add(this->labHex); + this->Controls->Add(this->labAscii); + this->Controls->Add(this->labWarning); + this->Controls->Add(this->labMsg); + this->Name = L"FormCheck"; + this->Text = L"Fingerprint Checker"; + this->ResumeLayout(false); + this->PerformLayout(); + + } +#pragma endregion + + // ================================================================================ + // フィンガープリントの表示 + // ================================================================================ + public: + void displayFingerprint( unsigned char fingerprint[32] ) + { + cli::array ^bytes = gcnew cli::array(32); + int i; + for( i=0; i < 32; i++ ) + { + bytes[i] = fingerprint[i]; + } + this->displayFingerprint( bytes ); + } + void displayFingerprint( cli::array ^fingerprint ) + { + this->tboxAscii->Text = TransBytesToString( fingerprint ); + this->tboxHex->Text = TransBytesToHexString( fingerprint ); + + this->tboxAscii->SelectionStart = 0; + this->tboxHex->SelectionStart = 0; + } + + // ================================================================================ + // GUI処理 + // ================================================================================ + private: + System::Void butOK_Click(System::Object^ sender, System::EventArgs^ e) + { + this->Close(); + } +}; +} diff --git a/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/FormCheck.resx b/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/FormCheck.resx new file mode 100644 index 0000000..ff31a6d --- /dev/null +++ b/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/FormCheck.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/fingerprint_console.cpp b/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/fingerprint_console.cpp new file mode 100644 index 0000000..09384f5 --- /dev/null +++ b/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/fingerprint_console.cpp @@ -0,0 +1,195 @@ +#include "stdafx.h" +#include "fingerprint_util.h" +#include "MasterEditorTWL/split_tad.h" + +using namespace System; + +// +// usage +// +void usage() +{ + System::String ^msg = + "Usage:\n" + + "FingerprintTWL.exe input_rom output_rom [options]\n\n" + + "options:\n" + + "-a ASCII_CHARACTORS: register ASCII charactors as fingerprint.\n" + + "-b HEX_NUMBERS: regsiter hexadicimal charactors as fingerprint.\n" + + "-s : output the ROM as SRL format.\n" + + "-t : output the ROM as TAD format.\n" + + "-f : Force to overwrite the fingerprint to the already fingerprinted ROM.\n" + "-g : GUI mode. Other options are ignored.\n" + + "-h : display this usage.\n"; + System::Console::WriteLine( "{0}", msg ); +} + +// +// コンソール処理 +// +void fingerprintConsole( cli::array ^args ) +{ + System::String ^optarg; + char opt; + bool isAscii = false; + bool isTad = false; + bool isForce = false; + System::String ^fingerprint; + + while( (opt = getopt(args, "a:b:stfgh", optarg)) >= 0 ) + { + switch( opt ) + { + case 'a': + isAscii = true; + fingerprint = System::String::Copy(optarg); + break; + + case 'b': + isAscii = false; + fingerprint = System::String::Copy(optarg); + break; + + case 't': + isTad = true; + break; + + case 's': + isTad = false; + break; + + case 'f': + isForce = false; + break; + + case 'g': + return; + break; + + case 'h': + usage(); + return; + break; + + default: + throw gcnew System::Exception( "Arguments error." ); + break; + } + } + + if( args->Length < 2 ) + { + throw gcnew System::Exception( "Arguments error." ); + } + + // 入出力ファイルのパス + System::String ^srcpath = args[0]; + System::String ^dstpath = args[1]; + System::Console::WriteLine( "Input file: {0}", srcpath ); + System::Console::WriteLine( "Output file: {0}", dstpath ); + System::Console::WriteLine(); + + // SRLの読み込み + cli::array ^srlbin; + if( System::IO::Path::GetExtension(srcpath)->ToUpper()->Equals(".TAD") ) + { + // TADの場合 split_tad + System::Console::WriteLine( "*** Transform TAD => SRL ***" ); + System::String ^tmp = ".\\tmp" + System::DateTime::Now.ToString("yyyyMMddHHmmss") + ".srl"; + if( splitTad(srcpath, tmp) < 0 ) + { + throw gcnew System::Exception("Failed to transform TAD => SRL."); + } + srlbin = ReadBin(tmp); + System::IO::File::Delete(tmp); // 中間ファイルを削除する + } + else + { + srlbin = ReadBin(srcpath); + } + ROM_Header rh; + ExtractRomHeader( srlbin, &rh ); + + // fingerprint が埋め込まれていたら表示して上書き確認をする + bool isFingerprint = false; + int i; + for( i=0; i < 32; i++ ) + { + if( rh.s.reserved_C[i] != 0 ) + { + isFingerprint = true; + break; + } + } + if( isFingerprint ) + { + cli::array ^bytes = gcnew cli::array(32); + int i; + for( i=0; i < 32; i++ ) + { + bytes[i] = rh.s.reserved_C[i]; + } + + System::Console::WriteLine( "*** Check the fingerprint ***" ); + System::Console::WriteLine( "ASCII Charactors:" ); + System::Console::WriteLine( "{0}", TransBytesToString(bytes) ); + System::Console::WriteLine( "Hexadecimal Numbers:" ); + System::Console::WriteLine( "{0}", TransBytesToHexString(bytes) ); + System::Console::WriteLine(); + System::Console::WriteLine( "The fingerprint has already been registered in the ROM." ); + System::Console::WriteLine(); + + if( !isForce ) + { + System::Console::WriteLine( "Overwrite it? (y/n) > " ); + System::ConsoleKeyInfo ^key = System::Console::ReadKey(); + if( (key->KeyChar == 'y') || (key->KeyChar == 'Y') ) + { + System::Console::WriteLine( "Overwrite the fingerprint." ); + } + else + { + throw gcnew System::Exception( "Canceled." ); + } + } + } + + // fingerprint の埋め込み + System::Console::WriteLine( "*** Register the fingerprint ***" ); + cli::array ^bytes; + if( isAscii ) + { + System::Console::WriteLine( "ASCII Charactors:" ); + System::Console::WriteLine( "{0}", fingerprint ); + bytes = TransStringToBytes( fingerprint, 32 ); + } + else + { + bytes = TransHexStringToBytes( fingerprint, 32 ); + } + pin_ptr buf = &bytes[0]; // 解放の必要なし + memcpy( rh.s.reserved_C, buf, 32 ); + SignRomHeader( &rh ); // 署名 + System::Console::WriteLine( "Hexadecimal Numbers:" ); + System::Console::WriteLine( "{0}", TransBytesToHexString(bytes) ); + + // maketad + if( isTad ) + { + System::String ^bindir = System::IO::Path::GetDirectoryName( System::Reflection::Assembly::GetEntryAssembly()->Location ); + if( !bindir->EndsWith("\\") ) + { + bindir = bindir + "\\"; + } + System::String ^maketad_path = bindir + "maketad.exe"; + + System::Console::WriteLine( "*** Transform SRL => TAD ***" ); + System::String ^tmp = ".\\tmp" + System::DateTime::Now.ToString("yyyyMMddHHmmss") + ".srl"; + WriteBin( tmp, srlbin ); + makeTad( maketad_path, tmp, dstpath ); + System::IO::File::Delete(tmp); + } + else + { + WriteBin( dstpath, srlbin ); + } +} \ No newline at end of file diff --git a/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/fingerprint_util.h b/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/fingerprint_util.h index 8ff7d48..e8dfbf5 100644 --- a/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/fingerprint_util.h +++ b/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/fingerprint_util.h @@ -77,3 +77,19 @@ System::String^ SaveFileUsingDialog( System::String ^defdir, System::String ^fil // @arg [in] 入力SRLのパス // @arg [in] 出力SRLのパス void makeTad( System::String ^maketad_path, System::String ^srlpath, System::String ^tadpath ); + +// ---------------------------------------------------------------------- +// コンソール +// ---------------------------------------------------------------------- + +// getopt : 引数を解析してオプションが見つかったら1つ返す +// @arg [in/out] 引数 (オプションが見つかった場合削除されていく) +// @arg [in] オプション許可リスト +// @arg [out] オプション引数の格納場所 (ない場合 nullptrが入る) +// @ret 最初に見つかったオプション +char getopt( cli::array ^%args, System::String ^condition, System::String ^% optarg ); + +// args から特定の要素を削除 +// @arg [in] 引数 +// @arg [in] 削除する要素のインデックス +void shrinkArgs( cli::array ^%args, const int index ); diff --git a/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/fingerprinter_util.cpp b/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/fingerprinter_util.cpp index 40ac61f..7e99868 100644 --- a/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/fingerprinter_util.cpp +++ b/build/tools/MasterEditor/FingerPrinterTWL/FingerPrinterTWL/fingerprinter_util.cpp @@ -7,6 +7,7 @@ #include #include #include +#include "fingerprint_util.h" using namespace MasterEditorTWL; @@ -27,7 +28,7 @@ cli::array^ ReadBin( System::String ^path ) { if( fopen_s( &fp, pch, "rb" ) != NULL ) { - ex = gcnew System::Exception( "Fail to open file:" + path ); + ex = gcnew System::Exception( "Failed to open file:" + path ); throw ex; } @@ -40,7 +41,7 @@ cli::array^ ReadBin( System::String ^path ) fseek( fp, 0, SEEK_SET ); if( fread( (void*)pbin, 1, size, fp ) != size ) { - ex = gcnew System::Exception( "Fail to read data from " + path ); + ex = gcnew System::Exception( "Failed to read data from " + path ); throw ex; } } @@ -68,7 +69,7 @@ void WriteBin( System::String ^path, cli::array ^bin ) { if( fopen_s( &fp, pch, "w+b" ) != NULL ) // 上書き・バイナリ { - ex = gcnew System::Exception( "Fail to open file:" + path ); + ex = gcnew System::Exception( "Failed to open file:" + path ); throw ex; } @@ -78,7 +79,7 @@ void WriteBin( System::String ^path, cli::array ^bin ) (void)fseek( fp, 0, SEEK_SET ); if( fwrite( (const void*)pbin, 1, size, fp ) != size ) { - ex = gcnew System::Exception( "Fail to write data to " + path ); + ex = gcnew System::Exception( "Failed to write data to " + path ); throw ex; } } @@ -105,13 +106,13 @@ void ReadRomHeader( System::String ^srlpath, ROM_Header *dstrh ) { if( fopen_s( &fp, pchFile, "rb" ) != NULL ) { - ex = gcnew System::Exception( "Fail to open file:" + srlpath ); + ex = gcnew System::Exception( "Failed to open file:" + srlpath ); throw ex; } fseek( fp, 0, SEEK_SET ); if( fread( (void*)dstrh, 1, sizeof(ROM_Header), fp ) != sizeof(ROM_Header) ) { - ex = gcnew System::Exception( "Fail to read data from " + srlpath ); + ex = gcnew System::Exception( "Failed to read data from " + srlpath ); throw ex; } } @@ -138,14 +139,14 @@ void WriteRomHeader( System::String ^srlpath, ROM_Header *srcrh ) { if( fopen_s( &fp, pchFile, "r+b" ) != NULL ) // 上書き・バイナリ { - ex = gcnew System::Exception( "Fail to open file:" + srlpath ); + ex = gcnew System::Exception( "Failed to open file:" + srlpath ); throw ex; } (void)fseek( fp, 0, SEEK_SET ); if( fwrite( (const void*)srcrh, 1, sizeof(ROM_Header), fp ) != sizeof(ROM_Header) ) { - ex = gcnew System::Exception( "Fail to write data to " + srlpath ); + ex = gcnew System::Exception( "Failed to write data to " + srlpath ); throw ex; } } @@ -202,12 +203,12 @@ void CopyFile( System::String ^srcpath, System::String ^dstpath ) { if( fopen_s( &ifp, pchSrcFile, "rb" ) != NULL ) { - ex = gcnew System::Exception( "Fail to open file:" + srcpath ); + ex = gcnew System::Exception( "Failed to open file:" + srcpath ); throw ex; } if( fopen_s( &ofp, pchDstFile, "wb" ) != NULL ) // 同名ファイルを削除して新規にライト・バイナリ { - ex = gcnew System::Exception( "Fail to open file:" + dstpath ); + ex = gcnew System::Exception( "Failed to open file:" + dstpath ); throw ex; } @@ -225,12 +226,12 @@ void CopyFile( System::String ^srcpath, System::String ^dstpath ) if( datasize != fread(buf, 1, datasize, ifp) ) { - ex = gcnew System::Exception( "Fail to read data from " + srcpath ); + ex = gcnew System::Exception( "Failed to read data from " + srcpath ); throw ex; } if( datasize != fwrite(buf, 1, datasize, ofp) ) { - ex = gcnew System::Exception( "Fail to write data to " + dstpath ); + ex = gcnew System::Exception( "Failed to write data to " + dstpath ); throw ex; } size -= datasize; @@ -307,7 +308,7 @@ void SignRomHeader( ROM_Header *rh ) result = ACSign_Encrypto( signDst, privateKey, &signSrc, sizeof(SignatureData) ); if( !result ) { - throw gcnew System::Exception( "Exception: Fail to calc the hash of the ROM header." ); + throw gcnew System::Exception( "Exception: Failed to calc the hash of the ROM header." ); } // 署名を解除してダイジェストと一致するかベリファイする @@ -319,7 +320,7 @@ void SignRomHeader( ROM_Header *rh ) } if( !result || (memcmp( &signSrc, &(decryptBlock[pos+1]), sizeof(SignatureData) ) != 0) ) { - throw gcnew System::Exception( "Exception: Fail to compare the hash of the ROM header." ); + throw gcnew System::Exception( "Exception: Failed to compare the hash of the ROM header." ); } // ROMヘッダに署名を上書き @@ -504,5 +505,97 @@ System::String^ SaveFileUsingDialog( System::String ^defdir, System::String ^fil // @arg [in] 出力SRLのパス void makeTad( System::String ^maketad_path, System::String ^srlpath, System::String ^tadpath ) { - System::Diagnostics::Process::Start( maketad_path, "\"" + srlpath + "\" -o \"" + tadpath + "\"" ); + System::Diagnostics::ProcessStartInfo ^info = gcnew System::Diagnostics::ProcessStartInfo(); + info->FileName = maketad_path; + info->Arguments = "\"" + srlpath + "\" -o \"" + tadpath + "\""; + info->CreateNoWindow = true; + info->UseShellExecute = false; + info->RedirectStandardError = true; + + System::Diagnostics::Process ^p = System::Diagnostics::Process::Start( info ); + //p->WaitForExit(); + System::String ^output = p->StandardError->ReadToEnd(); + output->Replace( (char)'\r\r\n', (char)'\n' ); + System::Console::WriteLine( "{0}", output ); + + if( output != "" ) + { + throw gcnew System::Exception("Failed to transform SRL to TAD."); + } +} + +// ---------------------------------------------------------------------- +// コンソール +// ---------------------------------------------------------------------- + +// getopt : 引数を解析してオプションが見つかったら1つ返す +// @arg [in/out] 引数 (オプションが見つかった場合削除されていく) +// @arg [in] オプション許可リスト +// @arg [out] オプション引数の格納場所 (ない場合 nullptrが入る) +// @ret 最初に見つかったオプション +char getopt( cli::array ^%args, System::String ^condition, System::String ^% optarg ) +{ + char opt=0; + + // 初期化 + optarg = nullptr; + + // オプションを探して条件に合うかどうかを調べる + int ai; + int ci = 0; + for( ai=0; ai < args->Length; ai++ ) + { + System::String ^arg = args[ai]; + if( arg->StartsWith("-") && arg->Length >= 2 ) + { + // 条件に合うオプションかどうかを調べる + ci = condition->IndexOf( arg[1] ); + if( ci >= 0 ) + { + opt = (char)condition[ci]; + } + break; + } + } + // オプションはあったが条件にない不正なオプションだった + if( ci < 0 ) + { + return ((char)0); + } + // オプションが存在しなかった + if( ai == args->Length ) + { + return ((char)-1); + } + + // オプション引数があるかチェック + if( ((ci+1) < condition->Length) && (condition[ci+1] == ':') ) + { + if( ((ai+1) < args->Length) && !args[ai+1]->StartsWith("-") ) + { + optarg = System::String::Copy(args[ai+1]); + shrinkArgs( args, ai+1); + } + else + { + return ((char)0); // オプション引数がない + } + } + + // オプションを削除する + shrinkArgs( args, ai ); + return opt; +} + +// args から特定の要素を削除 +// @arg [in] 引数 +// @arg [in] 削除する要素のインデックス +void shrinkArgs( cli::array ^%args, const int index ) +{ + int i; + for( i=index+1; i < args->Length; i++ ) + { + args[i-1] = args[i]; + } + cli::array::Resize( args, args->Length - 1 ); }