public static void GenerateMacExeInfoFile(string exePath, string outFile) { PTCustomizeUtil.FullKeyOffset ppcOffset = PTExeDiscovery.FindMacPPCKeyOffset(exePath); PTCustomizeUtil.FullKeyOffset x86Offset = PTExeDiscovery.FindMacx86KeyOffset(exePath); PTCustomizeUtil.FullKeyOffset x64Offset = PTExeDiscovery.FindMacx64KeyOffset(exePath); PTCustomizeUtil.MacOffset msgOffsets = PTExeDiscovery.FindMacMsgOffsets(exePath); PTCustomizeUtil.MacOffset expirationDateOffset = PTExeDiscovery.FindMacEvalExpirationDateOffset(exePath); PTCustomizeUtil.MacOffset customPicDataOffset = PTExeDiscovery.FindMacCustomPicDataOffsets(exePath); PTCustomizeUtil.MacOffset customPicMsgOffset = PTExeDiscovery.FindMacCustomPicMsgOffset(exePath); // Output the data StreamWriter sw = new StreamWriter(outFile); sw.WriteLine(PTCustomizeUtil.Ini_MacPPCKeyOffset + ":" + ppcOffset.ToString()); sw.WriteLine(PTCustomizeUtil.Ini_Macx86KeyOffset + ":" + x86Offset.ToString()); sw.WriteLine(PTCustomizeUtil.Ini_Macx64KeyOffset + ":" + x64Offset.ToString()); sw.WriteLine(PTCustomizeUtil.Ini_MacMsgOffsets + ":" + msgOffsets.ToString()); sw.WriteLine(PTCustomizeUtil.Ini_MacEvalExpirationDateOffset + ":" + expirationDateOffset.ToString()); sw.WriteLine(PTCustomizeUtil.Ini_MacPicDataOffset + ":" + customPicDataOffset.ToString()); sw.WriteLine(PTCustomizeUtil.Ini_MacPicMsgOffset + ":" + customPicMsgOffset.ToString()); sw.Close(); }
public static void GenerateExeInfoFile(string exePath, string outFile) { PTCustomizeUtil.FullKeyOffset keyOffset = PTExeDiscovery.FindKeyOffset(exePath); long msgOffset = PTExeDiscovery.FindMsgOffset(exePath); long expirationDateOffset = PTExeDiscovery.FindEvalExpirationDateOffset(exePath); long customPicDataOffset = PTExeDiscovery.FindCustomPicOffset(exePath); long customPicMsgOffset = PTExeDiscovery.FindCustomPicMsgOffset(exePath); // Output the data StreamWriter sw = new StreamWriter(outFile); sw.WriteLine(PTCustomizeUtil.Ini_KeyOffset + ":" + keyOffset.ToString()); sw.WriteLine(PTCustomizeUtil.Ini_MessageOffset + ":" + msgOffset.ToString()); if (expirationDateOffset > 0) { sw.WriteLine(PTCustomizeUtil.Ini_ExpirationDate + ":" + expirationDateOffset.ToString()); } sw.WriteLine(PTCustomizeUtil.Ini_CustomPicData + ":" + customPicDataOffset.ToString()); sw.WriteLine(PTCustomizeUtil.Ini_CustomPicMsg + ":" + customPicMsgOffset.ToString()); sw.Close(); }
/////////////////////////////////////////////////////////////////////////////////////////// /// <summary>Find the offset with in the Prime Time executable of the key value.</summary> /// <param name="exePath">The full path to the Prime Time executable</param> /// <returns>The offset to the key or 0 on error</returns> /////////////////////////////////////////////////////////////////////////////////////////// public static PTCustomizeUtil.FullKeyOffset FindKeyOffset(string exePath, long startOffset) { PTCustomizeUtil.FullKeyOffset retOffset = new PTCustomizeUtil.FullKeyOffset(); // Open the file try { FileStream exeFileStream = File.OpenRead(exePath); BinaryReader reader = new BinaryReader(exeFileStream); byte[] exeFileData = reader.ReadBytes((int)exeFileStream.Length); exeFileStream.Close(); byte[] searchBytes = PTCustomizeUtil.UInt64ToArray(GAME_FIXED_KEYS[0], CharByteOrder); // Go through the file int keyMatchIndex = 0; int byteMatchIndex = 0; long keyMatchStartPosition = 0; long curExeDataByteIndex = startOffset; while (curExeDataByteIndex < exeFileData.Length) { byte curByte = exeFileData[curExeDataByteIndex++]; // If the byte matches the value currently being tested if (curByte == searchBytes[byteMatchIndex]) { // If this is the first match if (byteMatchIndex == 0 && keyMatchIndex == 0) { keyMatchStartPosition = curExeDataByteIndex - 1; } // Increment the search ++byteMatchIndex; } // Else restart the search if there are matches else if (keyMatchIndex > 0 || byteMatchIndex > 0) { // If there are matches then restart keyMatchIndex = 0; searchBytes = PTCustomizeUtil.UInt64ToArray(GAME_FIXED_KEYS[keyMatchIndex], CharByteOrder); byteMatchIndex = 0; // If this byte matches the first byte to find if (curByte == searchBytes[byteMatchIndex]) { ++byteMatchIndex; // Store the offset keyMatchStartPosition = curExeDataByteIndex - 1; } continue; } // If the match has found the first four bytes if (byteMatchIndex == 4) { int oldPadding = retOffset.Intra64bitPadding; // Get passed the padding between the two DWORDs that make up the 64-bit integer retOffset.Intra64bitPadding = StepPassed64Padding(searchBytes[byteMatchIndex], exeFileData, curExeDataByteIndex); curExeDataByteIndex += retOffset.Intra64bitPadding; // If the padding changed then FREAK OUT if (oldPadding != -1 && oldPadding != retOffset.Intra64bitPadding) { // The padding is incorrect so ignore this keyMatchIndex = 0; searchBytes = PTCustomizeUtil.UInt64ToArray(GAME_FIXED_KEYS[keyMatchIndex], CharByteOrder); byteMatchIndex = 0; //throw new ApplicationException( "Intra-64-bit integer offset (Between DWORDs) not standard!" ); } continue; } // Else if the key was matched else if (byteMatchIndex == 8) { ++keyMatchIndex; // If all of the keys have matched if (keyMatchIndex == GAME_FIXED_KEYS.Length) { break; } // The 3 item in the key list is the one that gets overwritten so skip it else if (keyMatchIndex == 2) { int amountToSkip = 8 + retOffset.Inter64bitPadding + retOffset.Intra64bitPadding; curExeDataByteIndex += amountToSkip; keyMatchIndex = 3; } // Get the new bytes to find searchBytes = PTCustomizeUtil.UInt64ToArray(GAME_FIXED_KEYS[keyMatchIndex], CharByteOrder); byteMatchIndex = 0; int oldPadding = retOffset.Inter64bitPadding; // Get past the padding between 64-bit integers retOffset.Inter64bitPadding = StepPassed64Padding(searchBytes[byteMatchIndex], exeFileData, curExeDataByteIndex); curExeDataByteIndex += retOffset.Inter64bitPadding; // If the padding changed then FREAK OUT if (oldPadding != -1 && oldPadding != retOffset.Inter64bitPadding) { throw new ApplicationException("64-bit integer offset not standard!"); } continue; } } // If the keys were found if (keyMatchIndex == GAME_FIXED_KEYS.Length) { long PACKED_KEY_LEN = 8 + retOffset.Inter64bitPadding + retOffset.Intra64bitPadding; long actualKeyOffsetFromStart = PACKED_KEY_LEN * ACTUAL_KEY_INDEX; // Store the offset retOffset.KeyOffset = keyMatchStartPosition + actualKeyOffsetFromStart; } } catch (Exception) { // This is just here for convenience in case I want to handle the exception or not throw; } return(retOffset); }
/////////////////////////////////////////////////////////////////////////////////////////// /// <summary>Find the offset with in the Prime Time executable of the key value.</summary> /// <param name="exePath">The full path to the Prime Time executable</param> /// <returns>The offset to the key or 0 on error</returns> /////////////////////////////////////////////////////////////////////////////////////////// public static PTCustomizeUtil.FullKeyOffset FindMacx64KeyOffset(string exePath) { PTCustomizeUtil.FullKeyOffset keyOffset = PTExeDiscovery.FindKeyOffset(exePath); return(PTExeDiscovery.FindKeyOffset(exePath, keyOffset.KeyOffset + 10)); }