static byte[] ByteStringToArray(string input) { List <byte> ret = new List <byte>(); input = input.Replace(" ", ""); input = input.Trim(); if (input.Length % 2 == 1) { throw new Exception("Could not convert Byte String to Array. Size incorrect"); } for (int i = 0; i < input.Length; i += 2) { ret.Add(byte.Parse(input.Substring(i, 2), System.Globalization.NumberStyles.HexNumber)); } DLOG.Write("[FindAOB] IDA AOB: "); foreach (byte b in ret) { if (b == 0xAA) { DLOG.Write("? "); } else { DLOG.Write("{0:X2} ", b); } } DLOG.WriteLine(); return(ret.ToArray()); }
private void importToolStripMenuItem_Click(object sender, EventArgs e) { if (dgvStrings.DataSource == null || importCSVthread != null) { return; } OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "CSV|*.csv"; ofd.Multiselect = false; if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { DataTable dt = dgvStrings.DataSource as DataTable; string[] lines = File.ReadAllLines(ofd.FileName); if (lines.Length != dt.Rows.Count) { MessageBox.Show("Incompatible CSV file."); DLOG.WriteLine("[LOAD CSV] Failed. Currently {0} rows, and file has {1}", dt.Rows.Count, lines.Length); } else { DLOG.WriteLine("[LOAD CSV] Working!"); importCSVthread = new System.Threading.Thread(() => { this.Invoke((MethodInvoker) delegate { Dictionary <int, string> changed = new Dictionary <int, string>(); foreach (string line in lines) { int id = int.Parse(line.Substring(0, line.IndexOf(';'))); string name = line.Substring(line.IndexOf(';') + 1); name = name.Trim('"'); name = name.Replace("\"\"", "\""); if (dt.Rows[id][1] as string != name) { int l = (dt.Rows[id][1] as string).Length - name.Length; bytesfree += l; changed.Add(id, name); } } if (bytesfree < 0) { MessageBox.Show("There's not enough room in this client! Try to save the client once to get some space free!"); } else { foreach (var kvp in changed) { dt.Rows[kvp.Key][1] = kvp.Value; } tsBytesAvailable.Text = string.Format("{0:N0} Bytes", bytesfree); } }); importCSVthread = null; }); importCSVthread.Start(); } } }
private void oneTimeTimer_Tick(object sender, EventArgs e) { oneTimeTimer.Enabled = false; DLOG.WriteLine("Checking for updates..."); CraftNetTools.AppUpdates.Check(); DLOG.WriteLine("Done!"); }
static void Main() { AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler); DLOG.WriteLine("STREDIT starting. Set UnhandledExceptionFilter!"); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new frmMain()); }
static bool FindAoBInFile(BinaryReader br, uint StartPos, byte[] AoB, byte skipbyte = 0xFF, bool skipbyteset = false, int length = 0) { br.BaseStream.Position = StartPos; try { while (br.BaseStream.Position != br.BaseStream.Length) { byte[] tmpBuffer = br.ReadBytes(length == 0 ? (int)Math.Min(1024 * 10, br.BaseStream.Length - br.BaseStream.Position) : length); int tmpint = 0; int res = Array.FindIndex(tmpBuffer, 0, tmpBuffer.Length, (byte b) => { if (skipbyteset && AoB[tmpint] == skipbyte) { tmpint += 1; } else if (b == AoB[tmpint]) { tmpint += 1; } else { tmpint = 0; } return(tmpint == AoB.Length); }); if (res >= 0) { long realpos = (br.BaseStream.Position - tmpBuffer.Length) + (res - tmpint) + 1; br.BaseStream.Position = realpos; return(true); } if (length != 0) { return(false); } } } catch { } DLOG.WriteLine("[FindAOB] ------- EOF ---------"); br.BaseStream.Position = StartPos; return(false); }
static void DebugBuffer(BinaryReader pBR, long pPos = 0) { var tmp = pBR.BaseStream.Position; if (pPos != 0) { pBR.BaseStream.Position = pPos; } DLOG.WriteLine("[FDEBUG] ---------------------------------------------------------"); DLOG.WriteLine("[FDEBUG] Current Position {0:X8} ({1:X8})", pBR.BaseStream.Position, pBR.BaseStream.Position + FileOffset); DLOG.Write("[FDEBUG] - Data: "); var data = pBR.ReadBytes(50); foreach (byte b in data) { DLOG.Write("{0:X2} ", b); } pBR.BaseStream.Position = tmp; DLOG.WriteLine(); DLOG.WriteLine("[FDEBUG] ---------------------------------------------------------"); }
static void UpdateBlock(uint pAddr, bool pPool) { if (pPool) { if (BlockStringPool.Min > pAddr) { BlockStringPool.Min = pAddr; } if (BlockStringPool.Max < pAddr) { BlockStringPool.Max = pAddr; } } else { if (BlockStrings.Min > pAddr) { if (BlockStrings.Min >= 0xFFF0000) { BlockStrings.Min = pAddr; } else if (BlockStrings.Min - pAddr <= 0x100000) { BlockStrings.Min = pAddr; } else { DLOG.WriteLine("[LOLTEST] Fail: {0:X8} ({1:X8})", pAddr, BlockStrings.Min - pAddr); } } if (BlockStrings.Max < pAddr) { BlockStrings.Max = pAddr; } } }
private void LoadFile(string pFilename) { NopThis = new List <KeyValuePair <uint, uint> >(); try { StringReferences = new Dictionary <int, Dictionary <int, StringDecodeTypes> >(); this.Invoke((MethodInvoker) delegate { famSep.Visible = famLabel.Visible = false; dgvStrings.DataSource = null; bytesfree = 0; tsBytesAvailable.Text = string.Format(STR_BytesAvailable, 0); tsBlockSize.Text = string.Format(STR_DataSize, 0, 0); tsLoadProgress.Maximum = 18; tsLoadProgress.Value = 0; saveToolStripMenuItem1.Enabled = false; cSVToolStripMenuItem1.Enabled = false; }); GlobalPortPos = 0; DLOG.WriteLine("---------------Loading File------------------"); DLOG.WriteLine("FileName: {0}", pFilename); DLOG.WriteLine("---------------------------------------------"); GC.Collect(); openedFile = pFilename; BlockStringPool = new sBlockSize(); BlockStrings = new sBlockSize(); MemoryStream memstream = new MemoryStream(File.ReadAllBytes(pFilename)); BinaryReader br = new BinaryReader(memstream); AddPoint(); // ---------- FIND AOB ------------- byte[] ExactDataAoB = ByteStringToArray( "D6 DE 75 86 46 64 A3 71 E8 E6 7B D3 33 30 E7 2E" + // Decode Key "10 00 00 00" + // Keylength ^ "AA AA AA 00"); // Amount of strings inside client DLOG.WriteLine("[TEST] Searching for Key, Key Length and Amount of Strings without any file knowledge."); int langpoolstart = -1; if (FindAoBInFile(br, 0x001DEEE8, ExactDataAoB, 0xAA, true)) { DLOG.WriteLine("[INFO] Gotcha! Found @ {0:X8} (FP: {1:X8})", br.BaseStream.Position + FileOffset, br.BaseStream.Position); // DebugBuffer(br); KeyPos = (uint)br.BaseStream.Position; br.ReadBytes(16); // Key _DecodeKeySize = br.ReadInt32(); // Key size lol _StringAmount = br.ReadUInt32(); langpoolstart = (int)br.BaseStream.Position; DLOG.WriteLine("[INFO] Lang pools {0:X8} {1:X8}", langpoolstart, langpoolstart + FileOffset); } else { DLOG.WriteLine("[ERROR] Failed!"); MessageBox.Show("Are you sure this is EMS?"); return; } // String Pool address // 8B 03 89 74 24 28 39 34 A8 0F ? ? 00 00 00 8B 0C AD ? ? ? ? byte[] StringDoesExistCheck = ByteStringToArray( "8B 03" + "89 74 24 28" + "39 34 A8" + // Compare "0F AA AA 00 00 00" + // Jump not zero "8B 0C AD AA AA AA AA"); // Move correct address to ECX if (FindAoBInFile(br, 0x001DEEE8, StringDoesExistCheck, 0xAA, true)) { DLOG.WriteLine("[INFO] Found 'Check if string exist' thing at {0:X8} (FP: {1:X8})", br.BaseStream.Position + FileOffset, br.BaseStream.Position); // DebugBuffer(br); br.BaseStream.Position += 2 + 4 + 3 + 6 + 3; StringsPos = br.ReadUInt32(); DLOG.WriteLine("[INFO] String pool should be at {0:X8} (FP: {1:X8})", StringsPos, StringsPos - FileOffset); } else { DLOG.WriteLine("[ERROR] Failed!"); MessageBox.Show("Are you sure this is EMS?"); return; } DLOG.WriteLine("[DEBUG] Strings in client: {0}", _StringAmount); AddPoint(); br.BaseStream.Position = KeyPos; DecodeKey = br.ReadBytes(_DecodeKeySize); DLOG.Write("[DEBUG] Decode Key: "); foreach (byte b in DecodeKey) { DLOG.Write("{0:X2} ", b); } DLOG.WriteLine(); AddPoint(); DataTable dt = new DataTable("FileStrings"); dt.Columns.Add("ID", typeof(int)).ReadOnly = true; dt.Columns.Add("English", typeof(string)); dt.Columns.Add("French", typeof(string)); dt.Columns.Add("German", typeof(string)); dt.Columns.Add("Spanish", typeof(string)); dt.Columns.Add("Dutch", typeof(string)); //dt.Columns.Add("Content", typeof(string)); //dt.Columns.Add("Unicode", typeof(bool)).ReadOnly = true; Dictionary <byte, List <int> > languageMap = new Dictionary <byte, List <int> >(); br.BaseStream.Position = langpoolstart; int usedStrings = 0; for (int i = 0; i < _StringAmount; i++) { int id = br.ReadInt32(); if (i > 0 && id == 0) { break; } usedStrings++; } br.BaseStream.Position = langpoolstart; for (byte l = 0; l < 5; l++) { DebugBuffer(br); List <int> idlist = new List <int>(); for (int i = 0; i < usedStrings; i++) { idlist.Add(br.ReadInt32()); } br.ReadInt32(); while (idlist[1] != br.ReadInt32()) { ; } br.BaseStream.Position -= 8; languageMap.Add(l, idlist); } br.BaseStream.Position = PlainOffsetToFileOffset(StringsPos); bool unicode = false; for (int i = 0; i < usedStrings; i++) { string decoded1 = Decode(br, languageMap[0][i], out unicode); string decoded2 = Decode(br, languageMap[1][i], out unicode); string decoded3 = Decode(br, languageMap[2][i], out unicode); string decoded4 = Decode(br, languageMap[3][i], out unicode); string decoded5 = Decode(br, languageMap[4][i], out unicode); dt.Rows.Add(i, decoded1, decoded2, decoded3, decoded4, decoded5); } AddPoint(); this.Invoke((MethodInvoker) delegate { dgvStrings.DataSource = dt; tsBlockSize.Text = string.Format(STR_DataSize, BlockStrings.Size, BlockStringPool.Size); tsBytesAvailable.Text = string.Format(STR_BytesAvailable, bytesfree); this.Text = STR_Title + " - File: " + pFilename; saveToolStripMenuItem1.Enabled = true; cSVToolStripMenuItem1.Enabled = true; }); //frmMain.StringsOutput += string.Format("{0:X8} - {1:X8}\r\n", BlockStrings.Min - FileOffset, BlockStrings.Max - FileOffset); //File.WriteAllText("test.txt", frmMain.StringsOutput); AddNewFile(pFilename); loadThread = null; } catch (Exception ex) { DLOG.WriteLine("EXC: Exception written to exlog.txt!"); MessageBox.Show(ex.ToString()); File.AppendAllText(Program.DATAFOLDER + "exlog.txt", "---- " + DateTime.Now + " --" + "\r\n"); File.AppendAllText(Program.DATAFOLDER + "exlog.txt", "--------------Exception--------------\r\n" + ex.ToString() + "\r\n\r\n\r\n\r\n"); } }
private void Form1_Load(object sender, EventArgs e) { DLOG.WriteLine("Starting Debug and stuff. lol!"); LoadLastFiles(); }