コード例 #1
0
        static void Main(string[] args)
        {
            var reader = new BinaryReader();
            var writer = new BinaryWriter();

            string[] sData = Console.ReadLine().Split();

            int structuresCount = int.Parse(sData[0]);
            int structuresLines = int.Parse(sData[1]);

            string        name  = null;
            List <string> types = new List <string> ();

            StructDescription[] structs = new StructDescription[structuresCount];
            int currentStruct           = 0;

            for (int i = 0; i < structuresLines; i++)
            {
                string[] words = Console.ReadLine().Split().Where(w => !string.IsNullOrEmpty(w)).ToArray();
                if (words[0].Equals("struct"))
                {
                    if (name != null)
                    {
                        structs[currentStruct] = new StructDescription(name, types.ToArray());
                        currentStruct++;
                        types.Clear();
                    }

                    name = words[1];
                }
                else
                {
                    types.Add(words[0]);
                }
            }

            structs[currentStruct] = new StructDescription(name, types.ToArray());

            string binary = Console.ReadLine();

            var read = reader.ReadBinary(structs, binary);

            string output = string.Empty;

            foreach (var s in read.values)
            {
                output += s.ToString();
            }

            Console.WriteLine(output.TrimEnd('\n', ' '));
        }
コード例 #2
0
ファイル: PackageReader.cs プロジェクト: xupefei/EAGSS
        internal static MemoryStream GetContent(StructDescription.ContentInfo cInfo)
        {
            byte[] bs;
            using (var br = new BinaryReader(new FileStream(cInfo.Path, FileMode.Open)))
            {
                br.BaseStream.Position = cInfo.Offset;

                bs = AESEncryptionAlgorithm.AESDecrypt(br.ReadBytes(cInfo.Length));

                //remove padding 0x00
                bs = BytesHelper.CopyBlock(bs, 0, cInfo.RealLength);
            }

            return new MemoryStream(bs);
        }
コード例 #3
0
        void BuildEjobDescription()
        {
            if (_ejobDescription == null)
            {
                using (var handler = SymbolHandler.Create(SymbolOptions.CaseInsensitive)) {
                    var address = handler.LoadSymbolsForModule(@"%systemroot%\system32\ntoskrnl.exe");
                    if (address == 0)
                    {
                        throw new Win32Exception(Marshal.GetLastWin32Error());
                    }
                    var types = handler.EnumTypes(address, "_ejob");
                    Debug.Assert(types != null && types.Count == 1);

                    _ejobDescription = handler.BuildStructDescription(address, types[0].TypeIndex);
                }
            }
        }
コード例 #4
0
ファイル: PackageIndexer.cs プロジェクト: xupefei/EAGSS
        private Dictionary<string, StructDescription.ContentInfo> GetOnePackageIndex(string pkgName, StructDescription.PackageInfo pInfo, BinaryReader br)
        {
            var dictEntryInfo =
                new Dictionary<string, StructDescription.ContentInfo>(StringComparer.OrdinalIgnoreCase);

            for (int i = 0; i < pInfo.EntryCount; i++)
            {
                var eInfo =
                    BytesHelper.BytesToStruct<StructDescription.EntryInfo>(
                        br.ReadBytes(Marshal.SizeOf(new StructDescription.EntryInfo())));

                var cInfo = new StructDescription.ContentInfo(pkgName, eInfo.Start, eInfo.Length,
                                                              eInfo.RealLength);

                dictEntryInfo.Add(eInfo.Name, cInfo);
            }

            return dictEntryInfo;
        }
コード例 #5
0
            public Struct ReadBinary(StructDescription desc, StructDescription[] structs, string binary, ref int position)
            {
                IStructValue[] values = new IStructValue[desc.types.Length];

                for (int i = 0; i < values.Length; i++)
                {
                    string type = desc.types[i];
                    if (binaryTypes.ContainsKey(type))
                    {
                        values[i] = new CustomStructValue(binaryTypes[type].ReadType(binary, ref position), type);
                    }
                    else
                    {
                        var st = structs.First(s => s.name.Equals(type));
                        values[i] = ReadBinary(st, structs, binary, ref position);
                    }
                }

                return(new Struct(desc.name, desc.types, values));
            }