private void buttonFindOffset_Click(object sender, EventArgs e) { try { PTCustomizeUtil.FullKeyOffset keyOffset = PTExeDiscovery.FindKeyOffset(textBoxFindOffsetFile.Text); textBoxKeyOffset.Text = keyOffset.KeyOffset.ToString(); textBoxInt64Pad.Text = keyOffset.Inter64bitPadding.ToString() + "," + keyOffset.Intra64bitPadding; } catch (Exception exc) { MessageBox.Show("Failed: " + exc.Message); } }
private void buttonOverwriteKey_Click(object sender, EventArgs e) { // Get the key value UInt64 keyValue = 0; if (textBoxOverwriteKeyValue.Text.StartsWith("0x")) { string val = textBoxOverwriteKeyValue.Text.Substring(2); if (!UInt64.TryParse(val, NumberStyles.AllowHexSpecifier, NumberFormatInfo.CurrentInfo, out keyValue)) { MessageBox.Show("Invalid key value entered"); return; } } else if (!UInt64.TryParse(textBoxOverwriteKeyValue.Text, out keyValue)) { MessageBox.Show("Invalid key value entered"); return; } // Get the value offset long keyOffsetx = 0; if (!long.TryParse(textBoxKeyOffset.Text, out keyOffsetx)) { MessageBox.Show("Invalid key offset entered"); return; } PTCustomizeUtil.FullKeyOffset keyOffset = new PTCustomizeUtil.FullKeyOffset(); keyOffset.KeyOffset = keyOffsetx; string[] int64KeyOffsets = textBoxInt64Pad.Text.Split(','); keyOffset.Inter64bitPadding = int.Parse(int64KeyOffsets[0]); keyOffset.Intra64bitPadding = int.Parse(int64KeyOffsets[1]); // Overwrite the key m_PTUtil.OverwriteValueInEXE(textBoxFindOffsetFile.Text, keyValue, keyOffset); }
private void ReadKey(string exeFile) { // Get the value offset long keyOffsetVal = 0; if (!long.TryParse(textBoxKeyOffset.Text, out keyOffsetVal)) { MessageBox.Show("Invalid key offset entered"); return; } PTCustomizeUtil.FullKeyOffset keyOffset = new PTCustomizeUtil.FullKeyOffset(); keyOffset.KeyOffset = keyOffsetVal; string[] int64KeyOffsets = textBoxInt64Pad.Text.Split(','); keyOffset.Inter64bitPadding = int.Parse(int64KeyOffsets[0]); keyOffset.Intra64bitPadding = int.Parse(int64KeyOffsets[1]); UInt64 keyVal = m_PTUtil.GetKeyFromExe(exeFile, keyOffset); textBoxReadKey.Text = keyVal.ToString() + " ( 0x" + keyVal.ToString("X") + " )"; }
private static void HandleCmdLine(string[] args) { // If the application is being run from the command line if (args[0] == "/geninfofile") { if (args.Length != 3) { MessageBox.Show("Pass the EXE path as the first parameter and the output file as the second."); return; } // Get the EXE path string exePath = args[1]; string outFile = args[2]; FileInfo exeInfo = new FileInfo(exePath); if (!exeInfo.Exists) { Console.WriteLine("Cannot find EXE file (" + exePath + ")"); } else { PTExeDiscovery.GenerateExeInfoFile(exePath, outFile); } return; } else if (args[0] == "/genmacinfofile") { if (args.Length != 3) { MessageBox.Show("Pass the EXE path as the first parameter and the output file as the second."); return; } // Get the EXE path string exePath = args[1]; string outFile = args[2]; FileInfo exeInfo = new FileInfo(exePath); if (!exeInfo.Exists) { Console.WriteLine("Cannot find EXE file (" + exePath + ")"); } else { PTExeDiscovery.GenerateMacExeInfoFile(exePath, outFile); } return; } else if (args[0] == "/setkey") { if (args.Length != 5) { MessageBox.Show("USAGE: MsgKeyGen /setkey keyoffset intra64Padding keyvalue exepath"); return; } // Get the values long keyOffsetVal = long.Parse(args[1]); UInt64 keyValue = UInt64.Parse(args[2]); int intra64Padding = int.Parse(args[3]); string exePath = args[4]; FileInfo exeInfo = new FileInfo(exePath); if (!exeInfo.Exists) { Console.WriteLine("Cannot find EXE file (" + exePath + ")"); } else { PTWebApp.PTCustomizeUtil util = new PTWebApp.PTCustomizeUtil(); PTCustomizeUtil.FullKeyOffset keyOffset = new PTCustomizeUtil.FullKeyOffset(); keyOffset.KeyOffset = keyOffsetVal; keyOffset.Intra64bitPadding = intra64Padding; // Modify the EXE util.OverwriteValueInEXE(exePath, keyValue, keyOffset); Console.WriteLine("EXE key updated"); } return; } else if (args[0] == "/findandsetkey") { if (args.Length != 3) { MessageBox.Show("USAGE: MsgKeyGen /findandsetkey keyvalue exepath"); return; } // Get the values UInt64 keyValue = UInt64.Parse(args[1]); string exePath = args[2]; FileInfo exeInfo = new FileInfo(exePath); if (!exeInfo.Exists) { Console.WriteLine("Cannot find EXE file (" + exePath + ")"); } else { PTCustomizeUtil util = new PTCustomizeUtil(); // Modify the EXE PTCustomizeUtil.FullKeyOffset keyOffset = PTExeDiscovery.FindKeyOffset(exePath); if (keyOffset.KeyOffset != 0) { util.OverwriteValueInEXE(exePath, keyValue, keyOffset); Console.WriteLine("EXE key updated (Key found at:" + keyOffset + ")"); } else { Console.WriteLine("Failed to find key offsset"); } } return; } else if (args[0] == "/setmsg") { if (args.Length != 4) { MessageBox.Show("USAGE: MsgKeyGen /setmsg msgoffset msg exepath"); return; } // Get the values long msgOffset = long.Parse(args[1]); string msg = args[2]; string exePath = args[3]; FileInfo exeInfo = new FileInfo(exePath); if (!exeInfo.Exists) { Console.WriteLine("Cannot find EXE file (" + exePath + ")"); } else { PTCustomizeUtil util = new PTCustomizeUtil(); // Modify the EXE util.OverwriteMsg(exePath, msgOffset, msg); Console.WriteLine("EXE message updated"); } return; } else if (args[0] == "/findandsetmsg") { if (args.Length != 3) { MessageBox.Show("USAGE: MsgKeyGen /findandsetmsg msg exepath"); return; } // Get the values string msg = args[1]; string exePath = args[2]; FileInfo exeInfo = new FileInfo(exePath); if (!exeInfo.Exists) { Console.WriteLine("Cannot find EXE file (" + exePath + ")"); } else { long msgOffset = PTExeDiscovery.FindMsgOffset(exePath); // Modify the EXE if (msgOffset != 0) { new PTCustomizeUtil().OverwriteMsg(exePath, msgOffset, msg); Console.WriteLine("EXE message updated (message found at: " + msgOffset + ")"); } else { Console.WriteLine("Failed to find message offset"); } } return; } }