Writing a Specific CRC32 Signature on a File

Just say I know the CRC32 Signature that I want to put on my file but I don't know how to specify it in my code so that when it signs the file it signs it using that specific signature that I specified, like if I open a file called "dune.map" and I know that the signature is supposed to be "DE545GHJ" how would I put that in my code so that when I click "sign" it signs the file using that specific signature, but then I want to open another file called "backwash.map" and I know that the signature for that file is "DDFGSFFG" how would I specify it in the code so that when I want to sign it it signs it with that signature In other words I want my program to sign different files using the signatures that I specify. Here's my code so far:

pragma once

namespace CRC32 {

using namespace System;

using namespace System::ComponentModel;

using namespace System::Collections;

using namespace System::Windows::Forms;

using namespace System::Data;

using namespace System::Drawing;

/// <summary>

/// Summary for Form1

///

/// WARNING: If you change the name of this class, you will need to change the

/// 'Resource File Name' property for the managed resource compiler tool

/// associated with all .resx files this class depends on. Otherwise,

/// the designers will not be able to interact properly with localized

/// resources associated with this form.

/// </summary>

public ref class Form1 : public System::Windows::Forms::Form

{

public:

Form1(void)

{

InitializeComponent();

//

//TODO: Add the constructor code here

//

}

protected:

/// <summary>

/// Clean up any resources being used.

/// </summary>

~Form1()

{

if (components)

{

delete components;

}

}

private: System::Windows::Forms::Button^ button1;

protected:

private: System::Windows::Forms::ListBox^ listBox1;

private: System::Windows::Forms::OpenFileDialog^ openFileDialog1;

private: System::Windows::Forms::Button^ button2;

private: System::Windows::Forms::Button^ button3;

private: System::Windows::Forms::Button^ button4;

private: System::Windows::Forms::Button^ button5;

private:

/// <summary>

/// Required designer variable.

/// </summary>

System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

void InitializeComponent(void)

{

this->button1 = (gcnew System::Windows::Forms::Button());

this->listBox1 = (gcnew System::Windows::Forms::ListBox());

this->openFileDialog1 = (gcnew System::Windows::Forms::OpenFileDialog());

this->button2 = (gcnew System::Windows::Forms::Button());

this->button3 = (gcnew System::Windows::Forms::Button());

this->button4 = (gcnew System::Windows::Forms::Button());

this->button5 = (gcnew System::Windows::Forms::Button());

this->SuspendLayout();

//

// button1

//

this->button1->Location = System::Drawing::Point(12, 12);

this->button1->Name = L"button1";

this->button1->Size = System::Drawing::Size(75, 23);

this->button1->TabIndex = 0;

this->button1->Text = L"Open";

this->button1->UseVisualStyleBackColor = true;

this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);

//

// listBox1

//

this->listBox1->BackColor = System::Drawing::SystemColors::WindowFrame;

this->listBox1->ForeColor = System::Drawing::SystemColors::Window;

this->listBox1->FormattingEnabled = true;

this->listBox1->Location = System::Drawing::Point(12, 41);

this->listBox1->Name = L"listBox1";

this->listBox1->Size = System::Drawing::Size(320, 186);

this->listBox1->TabIndex = 3;

//

// openFileDialog1

//

this->openFileDialog1->FileName = L"openFileDialog1";

//

// button2

//

this->button2->Location = System::Drawing::Point(93, 12);

this->button2->Name = L"button2";

this->button2->Size = System::Drawing::Size(75, 23);

this->button2->TabIndex = 4;

this->button2->Text = L"Close";

this->button2->UseVisualStyleBackColor = true;

this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);

//

// button3

//

this->button3->Location = System::Drawing::Point(176, 12);

this->button3->Name = L"button3";

this->button3->Size = System::Drawing::Size(75, 23);

this->button3->TabIndex = 5;

this->button3->Text = L"Check";

this->button3->UseVisualStyleBackColor = true;

this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);

//

// button4

//

this->button4->Location = System::Drawing::Point(257, 12);

this->button4->Name = L"button4";

this->button4->Size = System::Drawing::Size(75, 23);

this->button4->TabIndex = 6;

this->button4->Text = L"Sign";

this->button4->UseVisualStyleBackColor = true;

this->button4->Click += gcnew System::EventHandler(this, &Form1::button4_Click);

//

// button5

//

this->button5->Location = System::Drawing::Point(255, 233);

this->button5->Name = L"button5";

this->button5->Size = System::Drawing::Size(75, 23);

this->button5->TabIndex = 7;

this->button5->Text = L"Exit";

this->button5->UseVisualStyleBackColor = true;

this->button5->Click += gcnew System::EventHandler(this, &Form1::button5_Click);

//

// Form1

//

this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);

this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;

this->ClientSize = System::Drawing::Size(342, 266);

this->Controls->Add(this->button5);

this->Controls->Add(this->button4);

this->Controls->Add(this->button3);

this->Controls->Add(this->button2);

this->Controls->Add(this->listBox1);

this->Controls->Add(this->button1);

this->Name = L"Form1";

this->Text = L"CRC32";

this->ResumeLayout(false);

}

#pragma endregion

private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {

openFileDialog1->Title = "Select a File";

openFileDialog1->Filter = "All Files(*.*)|*.*";

openFileDialog1->FileName = "";

openFileDialog1->Multiselect = true;

if(openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)

listBox1->Items->AddRange(openFileDialog1->FileNames);

}

private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {

int nCount = listBox1->Items->Count;

for(int nIndex = nCount - 1; nIndex >= 0; nIndex--)

if(listBox1->SelectedIndices->Contains(nIndex))

listBox1->Items->RemoveAt(nIndex);

}

private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {

}

private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {

System::DateTime dtStart = System::DateTime::Now;

for each(String ^sFile in listBox1->Items)

{

System::IO::FileStream ^fs = gcnew System::IO::FileStream(sFile, System::IO::FileMode::Open, System::IO::FileAccess::ReadWrite, System::IO::FileShare::Read);

if(fs->Length % 4 != 0)

{

MessageBox::Show("The selected file(s) " + sFile + " is/are not bounded to four...I apologize, but the file will not be signed.", "CRC32", MessageBoxButtons::OK, MessageBoxIcon::Exclamation);

continue;

}

int nChecksum = 0;

System::IO::BinaryReader ^br = gcnew System::IO::BinaryReader(fs);

br->BaseStream->Position = 0x800;

int nEndOfFile = safe_cast<int>(fs->Length);

for(int x = 0x800; x < nEndOfFile; x += 4)

nChecksum ^= br->ReadInt32();

fs->Position = 0x2d0;

fs->Write(BitConverter::GetBytes(nChecksum), 0, 4);

br->Close();

fs->Close();

fs = nullptr;

}

MessageBox::Show("Complete!\nStart Time: " + dtStart.ToString() + "\nFinish Time: " + System::DateTime::Now.ToString(), "CRC32", MessageBoxButtons::OK, MessageBoxIcon::Information);

}

private: System::Void button5_Click(System::Object^ sender, System::EventArgs^ e) {

Close();

}

};

}




Answer this question

Writing a Specific CRC32 Signature on a File

  • raider123

    Does it change it to something random, or something specific Changing it to something random is easy, just change the file, mostly likely by adding some bytes to the end.



  • Clement Pang

    Yes, I realize what you are saying but I have a program that my friend gave me and it gives the .map file a different signature than It already had. He wanted to see if I could make that program over but even better. If you want I could send you that program through e-mail and then you could look at it, although I don't have the source code for it that's why I was asking you.



  • PRedd

    I believe the signature is a hash of the bytes in the file. The whole point of such a signature is that a file which has been tampered with will not generate the same signature.

    In short, it can't be done. When you hack a file and try to pass it off as something it is not, the signature will be what protects the users of that file, if they bother to check, they will find out it has been tampered with.



  • ceswell

    So... Do you know how to do it

  • Amit Pandya

    Something Specific. Ok um...... My friend gave me a program that is called cmr cmr=coolspot's map resigner, it resigns the .map but they have to be specific in order for the file to work correctly otherwise it will come up as a corrupted file on the screen. So i'm trying to redo that program except better, but I do not have the source code.



  • Writing a Specific CRC32 Signature on a File