フィンガープリンタ:CUI版も実装。追加し忘れていたファイルを追加。

git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlToolsRED@261 7061adef-622a-194b-ae81-725974e89856
This commit is contained in:
nishikawa_takeshi 2009-04-17 07:41:32 +00:00
parent 5bba671855
commit a5cbc2ae3b
16 changed files with 983 additions and 41 deletions

View File

@ -3,16 +3,43 @@
#include "stdafx.h"
#include "Form1.h"
extern void fingerprintConsole( cli::array<System::String^> ^args );
using namespace FingerPrinterTWL;
[STAThreadAttribute]
int main(array<System::String ^> ^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;
}

View File

@ -203,6 +203,10 @@
RelativePath=".\AssemblyInfo.cpp"
>
</File>
<File
RelativePath=".\fingerprint_console.cpp"
>
</File>
<File
RelativePath=".\fingerprinter_util.cpp"
>

View File

@ -11,7 +11,7 @@
<DebugSettings
Command="$(TargetPath)"
WorkingDirectory=""
CommandArguments=""
CommandArguments="-a TEST &quot;C:\\test_program.nand.tad&quot; -t test.tad"
Attach="false"
DebuggerType="3"
Remote="1"
@ -22,7 +22,7 @@
SQLDebugging=""
Environment=""
EnvironmentMerge="true"
DebuggerFlavor=""
DebuggerFlavor="0"
MPIRunCommand=""
MPIRunArguments=""
MPIRunWorkingDirectory=""

View File

@ -94,7 +94,7 @@ void Form1::commonOpenRom( System::String ^srcpath )
System::String ^tmp = ".\\tmp" + System::DateTime::Now.ToString("yyyyMMddHHmmss") + ".srl";
if( splitTad(srcpath, tmp) < 0 )
{
throw gcnew Exception("Fail to transform TAD => 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

View File

@ -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<String^> ^files = dynamic_cast< array<String^> ^>(e->Data->GetData( DataFormats::FileDrop ) );
String ^path = files[0];
this->procOpenRomButton( path ); // ボタンが押されたときと同じ挙動
this->procDragDrop( path );
}
// 再びボタン
private:

View File

@ -0,0 +1,3 @@
#include "StdAfx.h"
#include "FormAbout.h"

View File

@ -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 {
/// <summary>
/// FormAbout の概要
///
/// 警告: このクラスの名前を変更する場合、このクラスが依存するすべての .resx ファイルに関連付けられた
/// マネージ リソース コンパイラ ツールに対して 'Resource File Name' プロパティを
/// 変更する必要があります。この変更を行わないと、
/// デザイナと、このフォームに関連付けられたローカライズ済みリソースとが、
/// 正しく相互に利用できなくなります。
/// </summary>
public ref class FormAbout : public System::Windows::Forms::Form
{
public:
FormAbout(void)
{
InitializeComponent();
//
//TODO: ここにコンストラクタ コードを追加します
//
this->construct();
}
protected:
/// <summary>
/// 使用中のリソースをすべてクリーンアップします。
/// </summary>
~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:
/// <summary>
/// 必要なデザイナ変数です。
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
/// コード エディタで変更しないでください。
/// </summary>
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();
}
};
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,3 @@
#include "StdAfx.h"
#include "FormCheck.h"

View File

@ -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 {
/// <summary>
/// FormCheck の概要
///
/// 警告: このクラスの名前を変更する場合、このクラスが依存するすべての .resx ファイルに関連付けられた
/// マネージ リソース コンパイラ ツールに対して 'Resource File Name' プロパティを
/// 変更する必要があります。この変更を行わないと、
/// デザイナと、このフォームに関連付けられたローカライズ済みリソースとが、
/// 正しく相互に利用できなくなります。
/// </summary>
public ref class FormCheck : public System::Windows::Forms::Form
{
public:
FormCheck(void)
{
InitializeComponent();
//
//TODO: ここにコンストラクタ コードを追加します
//
}
protected:
/// <summary>
/// 使用中のリソースをすべてクリーンアップします。
/// </summary>
~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:
/// <summary>
/// 必要なデザイナ変数です。
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
/// コード エディタで変更しないでください。
/// </summary>
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<System::Byte> ^bytes = gcnew cli::array<System::Byte>(32);
int i;
for( i=0; i < 32; i++ )
{
bytes[i] = fingerprint[i];
}
this->displayFingerprint( bytes );
}
void displayFingerprint( cli::array<System::Byte> ^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();
}
};
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -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<System::String^> ^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<System::Byte> ^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<System::Byte> ^bytes = gcnew cli::array<System::Byte>(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<System::Byte> ^bytes;
if( isAscii )
{
System::Console::WriteLine( "ASCII Charactors:" );
System::Console::WriteLine( "{0}", fingerprint );
bytes = TransStringToBytes( fingerprint, 32 );
}
else
{
bytes = TransHexStringToBytes( fingerprint, 32 );
}
pin_ptr<unsigned char> 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 );
}
}

View File

@ -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<System::String^> ^%args, System::String ^condition, System::String ^% optarg );
// args から特定の要素を削除
// @arg [in] 引数
// @arg [in] 削除する要素のインデックス
void shrinkArgs( cli::array<System::String^> ^%args, const int index );

View File

@ -7,6 +7,7 @@
#include <cstring>
#include <cstdio>
#include <MasterEditorTWL/keys.h>
#include "fingerprint_util.h"
using namespace MasterEditorTWL;
@ -27,7 +28,7 @@ cli::array<System::Byte>^ 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<System::Byte>^ 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<System::Byte> ^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<System::Byte> ^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<System::String^> ^%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<System::String^> ^%args, const int index )
{
int i;
for( i=index+1; i < args->Length; i++ )
{
args[i-1] = args[i];
}
cli::array<System::String^>::Resize( args, args->Length - 1 );
}