コード例 #1
0
        private string GetName(ref IMAGE_RESOURCE_DIRECTORY_ENTRY entry, int resourceStartFileOffset)
        {
            int offset = resourceStartFileOffset + entry.NameOffset;
            int len    = Image.Read <ushort>(ref offset);

            StringBuilder sb = new StringBuilder(len);

            for (int i = 0; i < len; i++)
            {
                char c = (char)Image.Read <ushort>(ref offset);
                if (c == 0)
                {
                    break;
                }

                sb.Append(c);
            }

            return(sb.ToString());
        }
コード例 #2
0
        private ResourceEntry[] GetChildren()
        {
            if (_children != null)
            {
                return(_children);
            }

            if (IsLeaf)
            {
                return(_children = s_emptyChildren);
            }

            ResourceEntry            root = Image.Resources;
            int                      resourceStartFileOffset = root._offset;
            int                      offset = _offset;
            IMAGE_RESOURCE_DIRECTORY hdr    = Image.Read <IMAGE_RESOURCE_DIRECTORY>(ref offset);

            int count = hdr.NumberOfNamedEntries + hdr.NumberOfIdEntries;

            ResourceEntry[] result = new ResourceEntry[count];

            for (int i = 0; i < count; i++)
            {
                IMAGE_RESOURCE_DIRECTORY_ENTRY entry = Image.Read <IMAGE_RESOURCE_DIRECTORY_ENTRY>(ref offset);
                string name;
                if (this == root)
                {
                    name = IMAGE_RESOURCE_DIRECTORY_ENTRY.GetTypeNameForTypeId(entry.Id);
                }
                else
                {
                    name = GetName(ref entry, resourceStartFileOffset);
                }

                result[i] = new ResourceEntry(Image, this, name, entry.IsLeaf, resourceStartFileOffset + entry.DataOffset);
            }

            return(_children = result);
        }