What I would like to do is find out how to sign halo 2 maps using php. I know I can use the Bitwise Operators for part of this task but I really need help doing this. Here is what I need to do:
starting at offset 2048 (straight after the header) you have to xor every dword together.
So in the various resigner apps we have dotted around the site, they start a loop running that goes from offset 2048 to the very end of the map -4.
Within the loop a var is xored with the dword (read as an int32) from the current stream. The var is then xored again in the next loop with the next dword in the stream and so on. Eventually you have the final checksum, which is then written in at offset 720
I know I will need to first open the map, set the pointer at offset 2048 and then write the content into the file. I really don't know how to do this though. Please could someone help. Thanks.
Here are some examples of resigners in other languages. First Visual Basic:
Map Resigning -
Dim BR As New BinaryReader(New FileStream(Open.FileName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
Dim BW As New BinaryWriter(New FileStream(Open.FileName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
Dim Signature As Int32 = 0
Dim MapSize As Long = BR.BaseStream.Length
BR.BaseStream.Position = 2048
For i As Integer = 2048 To MapSize - 4 Step 4
Signature = Signature Xor BR.ReadInt32
Next
BW.BaseStream.Position = 720
BW.Write(Signature)
BR.Close()
BW.Close()
MsgBox("Encryption signature fixed. New signature is 0x" & Hex(Signature))
Get Map Name & Signature-
Dim BR As New BinaryReader(New FileStream(Open.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
BR.BaseStream.Position = 408
MapName.Text = BR.ReadChars(32)
BR.BaseStream.Position = 720
MapSig.Text = "0x" & Hex(BR.ReadInt32)
BR.Close()
Now Visual C+:
Map Resigning -
[code] BinaryReader BR = new BinaryReader(new FileStream(Open.FileName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite));
BinaryWriter BW = new BinaryWriter(new FileStream(Open.FileName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite));
Int32 Signature = 0;
long MapSize = BR.BaseStream.Length;
BR.BaseStream.Position = 2048;
for (int i = 2048; i <= MapSize - 4; i += 4)
{
Signature = Signature ^ BR.ReadInt32();
}
BW.BaseStream.Position = 720;
BW.Write(Signature);
BR.Close();
BW.Close();
MessageBox.Show("Encryption signature fixed. New signature is 0x" + Signature.ToString("X"));[/code]
Get Map Name & Signature -
[code] BinaryReader BR = new BinaryReader(new FileStream(Open.FileName, FileMode.Open, FileAccess.Read, FileShare.Read));
BR.BaseStream.Position = 408;
char[] charBuf = BR.ReadChars(32);
MapName.Text = new string(charBuf);
BR.BaseStream.Position = 720;
Int32 int32Buf = BR.ReadInt32();
MapSig.Text = int32Buf.ToString("X");
BR.Close();[/code] [/quote]
Now Visual C++:
Map Resigning -
[code] BinaryReader^ BR = gcnew BinaryReader( gcnew FileStream(open->FileName, FileMode::Open, FileAccess::ReadWrite, FileShare::ReadWrite));
BinaryWriter^ BW = gcnew BinaryWriter( gcnew FileStream(open->FileName, FileMode::Open, FileAccess::ReadWrite, FileShare::ReadWrite));
Int32 Signature = 0;
long MapSize = BR->BaseStream->Length;
BR->BaseStream->Position = 2048;
for (int i = 2048; i <= MapSize - 4; i+=4 )
{
Signature ^= BR->ReadInt32();
}
BW->BaseStream->Position = 720;
BW->Write(Signature);
MessageBox::Show("Encryption signature fixed. New signature is 0x" + Signature.ToString("X"));
BR->Close();
BW->Close();[/code]
Get Map Name & Signature -
[code]BinaryReader^ BR = gcnew BinaryReader( gcnew FileStream(open->FileName, FileMode::Open, FileAccess::ReadWrite, FileShare::ReadWrite));
BR->BaseStream->Position = 408;
MapName->Text = gcnew String( BR->ReadChars(32) );
BR->BaseStream->Position = 720;
Int32^ Signature = BR->ReadInt32();
MapSig->Text = "0x" + Signature->ToString("X");
BR->Close();[/code] [/quote]