Beispiel #1
0
 private static void WriteEntry(ByteBuffer win32_resources, ResourceEntry entry, ref int offset, Dictionary <string, int> strings, ref int stringTableOffset, ByteBuffer stringTable)
 {
     WriteNameOrOrdinal(win32_resources, entry, strings, ref stringTableOffset, stringTable);
     if (entry.Data == null)
     {
         win32_resources.WriteUInt32(0x80000000U | (uint)offset);
         offset += entry.Directory.Entries.Count * 8;
     }
     else
     {
         win32_resources.WriteUInt32((uint)offset);
     }
     offset += 16;
 }
Beispiel #2
0
        private static ResourceEntry ReadResourceEntry(BinaryReader dr, uint baseAddress)
        {
            var  re     = new ResourceEntry();
            uint id     = dr.ReadUInt32();
            uint offset = dr.ReadUInt32();
            long pos    = dr.BaseStream.Position;

            if ((id & 0x80000000) != 0)
            {
                dr.BaseStream.Position = (id & 0x7fffffff);
                var b = new StringBuilder();
                int c;
                while ((c = dr.Read()) > 0)
                {
                    b.Append((char)c);
                }
                re.Name = b.ToString();
            }
            else
            {
                re.Id = id;
            }
            if ((offset & 0x80000000) != 0)
            {
                dr.BaseStream.Position = (offset & 0x7fffffff);
                re.Directory           = ReadResourceDirectory(dr, baseAddress);
            }
            else
            {
                dr.BaseStream.Position = offset;
                uint rva  = dr.ReadUInt32();
                uint size = dr.ReadUInt32();
                uint cp   = dr.ReadUInt32();
                uint res  = dr.ReadUInt32();
                re.CodePage            = cp;
                re.Reserved            = res;
                dr.BaseStream.Position = (rva - baseAddress);
                re.Data = dr.ReadBytes((int)size);
            }
            dr.BaseStream.Position = pos;
            return(re);
        }
Beispiel #3
0
 private static void WriteNameOrOrdinal(ByteBuffer win32_resources, ResourceEntry entry, Dictionary <string, int> strings, ref int stringTableOffset, ByteBuffer stringTable)
 {
     if (entry.Name == null)
     {
         win32_resources.WriteUInt32(entry.Id);
     }
     else
     {
         int stringOffset;
         if (!strings.TryGetValue(entry.Name, out stringOffset))
         {
             stringOffset = stringTableOffset;
             strings.Add(entry.Name, stringOffset);
             stringTableOffset += entry.Name.Length * 2 + 2;
             stringTable.WriteUInt16((ushort)entry.Name.Length);
             foreach (char c in entry.Name)
             {
                 stringTable.WriteInt16((short)c);
             }
         }
         win32_resources.WriteUInt32(0x80000000U | (uint)stringOffset);
     }
 }
Beispiel #4
0
 private void MergeEntry(List <ResourceEntry> parents, ResourceEntry exist, AssemblyDefinition ass, ResourceEntry entry)
 {
     if (exist.Data != null && entry.Data != null)
     {
         if (IsAspResourceEntry(parents, exist))
         {
             _aspOffsets[ass] = exist.Data.Length;
             byte[] newData = new byte[exist.Data.Length + entry.Data.Length];
             Array.Copy(exist.Data, 0, newData, 0, exist.Data.Length);
             Array.Copy(entry.Data, 0, newData, exist.Data.Length, entry.Data.Length);
             exist.Data = newData;
         }
         else if (!IsVersionInfoResource(parents, exist))
         {
             _logger.Warn(string.Format("Duplicate Win32 resource with id={0}, parents=[{1}], name={2} in assembly {3}, ignoring", entry.Id, string.Join(",", parents.Select(p => p.Name ?? p.Id.ToString()).ToArray()), entry.Name, ass.Name));
         }
         return;
     }
     if (exist.Data != null || entry.Data != null)
     {
         _logger.Warn("Inconsistent Win32 resources, ignoring");
         return;
     }
     parents.Add(exist);
     MergeDirectory(parents, exist.Directory, ass, entry.Directory);
     parents.RemoveAt(parents.Count - 1);
 }
Beispiel #5
0
 private static bool IsVersionInfoResource(List <ResourceEntry> parents, ResourceEntry exist)
 {
     return(exist.Id == 0 && parents.Count == 2 && parents[0].Id == 16 && parents[1].Id == 1);
 }
Beispiel #6
0
 private static bool IsAspResourceEntry(List <ResourceEntry> parents, ResourceEntry exist)
 {
     return(exist.Id == 101 && parents.Count == 1 && parents[0].Id == 3771);
 }