コード例 #1
0
        /// <summary>
        /// ログ情報を探索する
        /// </summary>
        /// <returns></returns>
        public bool SearchLogMemoryInfo()
        {
            //プログレス
            Progress = 0;
            //debug
            DateTime st = DateTime.Now;

            List <Memory.MEMORY_BASIC_INFORMATION> WRMemoryInfoList = new List <Memory.MEMORY_BASIC_INFORMATION>();
            Memory memory = new Memory();

            foreach (Memory.MEMORY_BASIC_INFORMATION m in ffxiv.GetMemoryBasicInfos())
            {
                if (m.Type != (uint)Memory.MEMORY_TYPE.MEM_PRIVATE || m.Protect != Memory.MEMORY_ALLOCATION_PROTECT.PAGE_READWRITE)
                {
                    continue;
                }
                //Write Read属性のメモリinfoをリスト化
                WRMemoryInfoList.Add(m);
            }
            WRMemoryInfoList.Sort((a, b) => (int)a.BaseAddress - (int)b.BaseAddress);

            Regex logRegex = new Regex("[0-9A-F]{12}:[^\x00]{0,36}:[^\x00]*?[0-9A-F]{12}:[^\x00]{0,36}");

            int prog = 0;

            foreach (Memory.MEMORY_BASIC_INFORMATION m in WRMemoryInfoList)
            {
                //プログレス
                Progress = 100 * prog++ / WRMemoryInfoList.Count;

                //キャンセル可能
                if (IsCancelPending)
                {
                    IsCancelPending = false;
                    return(false);
                }

                // 1 "::Welcome to Masamune ! 「等」を探す

                byte[] buffer = ffxiv.ReadBytes((int)m.BaseAddress, (int)m.RegionSize);
                string str    = ASCIIEncoding.ASCII.GetString(buffer);
                if (!str.Contains(":"))
                {
                    continue;
                }
                //Welcome to を取得
                //if (Encoding.ASCII.GetString(buffer).Contains("::Welcome to"))
                MatchCollection matches = logRegex.Matches(str);
                foreach (Match match in matches)
                {
                    //キャンセル可能
                    if (IsCancelPending)
                    {
                        IsCancelPending = false;
                        return(false);
                    }

                    string   TimstampHexString = match.Value.Substring(0, 8);
                    DateTime datetime          = FFXIVLog.StartDateTime.AddSeconds(Convert.ToInt32(TimstampHexString, 16));
                    if (datetime < new DateTime(2013, 8, 29) || datetime > DateTime.Now.ToUniversalTime())
                    {
                        continue;
                    }

                    //"::Welcome to"のアドレス
                    int offset = match.Index;
                    if (offset < 12)
                    {
                        continue;
                    }
                    //ログの開始アドレス
                    int ptr_logStart = (int)m.BaseAddress + offset;//
                    //ログを取得して正規表現でチェック
                    byte[] data = ffxiv.ReadBytes(ptr_logStart, 100);
                    //ptr_LogStartRegexが格納されているアドレスをサーチする
                    foreach (Memory.MEMORY_BASIC_INFORMATION _m in WRMemoryInfoList)
                    {
                        byte[]       _buffer = ffxiv.ReadBytes((int)_m.BaseAddress, (int)_m.RegionSize);
                        MemoryStream ms      = new MemoryStream(_buffer);
                        BinaryReader br      = new BinaryReader(ms);
                        while (ms.Position < _buffer.Length - 4)
                        {
                            if (ptr_logStart == br.ReadInt32())//アドレス格納先?
                            {
                                int c_ptr_LogEnd = br.ReadInt32();
                                if (c_ptr_LogEnd >= ptr_logStart &&
                                    c_ptr_LogEnd <= (int)m.BaseAddress + (int)m.RegionSize)
                                {
                                    //見つけた!
                                    LogEntPtr     = (int)_m.BaseAddress + (int)ms.Position - 8;
                                    LogCurrentPtr = LogEntPtr + 4;
                                    LogIndexPtr   = LogEntPtr - 0x10;
                                    LogCountPtr   = LogEntPtr - 0x30;

                                    try
                                    {
                                        GetLogsData();
                                        DateTime fini = DateTime.Now;
                                        System.Diagnostics.Debug.WriteLine((fini - st).TotalSeconds);
                                        return(true);
                                    }
                                    catch
                                    {
                                    }
                                }
                            }
                        }
                    }
                }
            }


            //みつからなかった
            return(false);
        }