Originally Posted by Sissi
Hi guys, i tryed to include the encrypt and decrypt functions into my own project, which should check automatically, if the itemtype.dat was updated by conquer and then decrypt, replace some strings in it and write back encrypted into itemtype.dat.
Here is my code:
/*
* Erstellt mit SharpDevelop.
* Datum: 27.04.2008
* Zeit: 10:57
*
* Sie können diese Vorlage unter Extras > Optionen > Codeerstellung > Standardheader ändern.
*/
using System;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
namespace CO4US
{
/// <summary>
/// Description of Form1.
/// </summary>
public partial class frmSpecial : Form
{
public frmSpecial()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
void CmdBackClick(object sender, EventArgs e)
{
this.Hide();
}
void CmdItemTypeClick(object sender, EventArgs e)
{
byte[] bytes;
bytes = HoleDaten("ItemType");
Decrypt(ref bytes);
}
byte[] HoleDaten(string Datei)
{
if (Datei == "ItemType" || Datei == "Monster")
{
Datei = "ini" + Path.DirectorySeparatorChar + Datei + ".dat";
}
if (Datei == "MapItemIcon")
{
Datei +=".ani";
}
string Pfad = System.IO.Directory.GetCurrentDirectory();
Pfad = Directory.GetParent(Pfad).ToString();
Pfad = @"C:ProgrammeConquer 2.0";
string DateiPfad = Pfad + Path.DirectorySeparatorChar + Datei;
MessageBox.Show(DateiPfad);
byte[] bytes = File.ReadAllBytes(DateiPfad);
return bytes;
}
static byte[] key = {
0xAD ,0x6B ,0x4F ,0xFB ,0xDD ,0xB8 ,0x0E ,0x09 ,0x13 ,0x33 ,0x8F ,0xF5 ,0x43 ,0x09 ,0x15 ,0x88 ,0x5D ,0x80 ,0xA3 ,0x45 ,0x2D ,0x42 ,0x08 ,0x56 ,0x80 ,0xF8 ,0x19 ,0xC5 ,0x88 ,0x1B ,0x3E ,0xEF
,0x81 ,0x07 ,0x30 ,0x36 ,0x95 ,0x52 ,0x00 ,0xF7 ,0xFD ,0x5B ,0x5C ,0xBC ,0x6A ,0x26 ,0x0E ,0xB2 ,0xA3 ,0x67 ,0xC5 ,0x5D ,0x6F ,0xDC ,0x18 ,0x8A ,0xB5 ,0xE0 ,0xC8 ,0x85 ,0xE2 ,0x3E ,0x45 ,0x8D
,0x8B ,0x43 ,0x74 ,0x85 ,0x54 ,0x17 ,0xB0 ,0xEC ,0x10 ,0x4D ,0x0F ,0x0F ,0x29 ,0xB8 ,0xE6 ,0x7D ,0x42 ,0x80 ,0x8F ,0xBC ,0x1C ,0x76 ,0x69 ,0x3A ,0xB6 ,0xA5 ,0x21 ,0x86 ,0xB9 ,0x29 ,0x30 ,0xC0
,0x12 ,0x45 ,0xA5 ,0x4F ,0xE1 ,0xAF ,0x25 ,0xD1 ,0x92 ,0x2E ,0x30 ,0x58 ,0x49 ,0x67 ,0xA5 ,0xD3 ,0x84 ,0xF4 ,0x89 ,0xCA ,0xFC ,0xB7 ,0x04 ,0x4F ,0xCC ,0x6E ,0xAC ,0x31 ,0xD4 ,0x87 ,0x07 ,0x72};
static void Decrypt(ref byte[] bytes)
{
if (bytes.Length < 0)
return;
int i = 1;
byte t1 = 0;
int t2;
while (i < bytes.Length)
{
MessageBox.Show(bytes[i].ToString());
t1 = (byte)(bytes[i] ^ key[(byte)i % 0x80]);
t2 = i % 0x8;
bytes[i] = (byte)((t1 << (0x8 - t2)) + (t1 >> t2));
i++;
}
}
static void Encrypt(ref byte[] bytes)
{
if (bytes.Length < 0)
return;
int i = 1;
byte t1 = 0;
int t2;
while (i < bytes.Length)
{
t2 = i % 0x8;
t1 = (byte)((bytes[i] >> (0x8 - t2)) + (bytes[i] << t2));
bytes[i] = (byte)(t1 ^ key[(byte)i % 0x80]);
i++;
}
}
}
}
Everytime i try to run it, it says "overflow" and i found out it stops at the function decrypt at bytes[i] = (byte)((t1 << (0x8 - t2)) + (t1 >> t2));
I worked the original programm through and the variables at the first time are have the same worth like they are in my program, but in my program is an overflow. I hope you can help me.
Mfg Sissi.
|