private void WriteEntry(ResourceEntry entry, ref int offset, Dictionary <string, int> strings, ref int stringTableOffset, ByteBuffer stringTable) { WriteNameOrOrdinal(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; }
private static ResourceEntry ReadResourceEntry(BinaryReader dr, uint baseAddress) { ResourceEntry resourceEntry = new ResourceEntry(); uint num = dr.ReadUInt32(); uint num2 = dr.ReadUInt32(); long position = dr.BaseStream.Position; if ((num & 2147483648u) != 0u) { dr.BaseStream.Position = (long)((ulong)(num & 2147483647u)); StringBuilder stringBuilder = new StringBuilder(); int num3; while ((num3 = dr.Read()) > 0) { stringBuilder.Append((char)num3); } resourceEntry.Name = stringBuilder.ToString(); } else { resourceEntry.Id = num; } if ((num2 & 2147483648u) != 0u) { dr.BaseStream.Position = (long)((ulong)(num2 & 2147483647u)); resourceEntry.Directory = RsrcReader.ReadResourceDirectory(dr, baseAddress); } else { dr.BaseStream.Position = (long)((ulong)num2); uint num4 = dr.ReadUInt32(); uint count = dr.ReadUInt32(); uint codePage = dr.ReadUInt32(); uint reserved = dr.ReadUInt32(); resourceEntry.CodePage = codePage; resourceEntry.Reserved = reserved; dr.BaseStream.Position = (long)((ulong)(num4 - baseAddress)); resourceEntry.Data = dr.ReadBytes((int)count); } dr.BaseStream.Position = position; return(resourceEntry); }
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); }
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; }
private void WriteNameOrOrdinal(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); } }
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); }
private static bool IsVersionInfoResource(List<ResourceEntry> parents, ResourceEntry exist) { return exist.Id == 0 && parents.Count == 2 && parents[0].Id == 16 && parents[1].Id == 1; }
private static bool IsAspResourceEntry(List<ResourceEntry> parents, ResourceEntry exist) { return exist.Id == 101 && parents.Count == 1 && parents[0].Id == 3771; }
private void WriteNameOrOrdinal(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); } }
private void WriteEntry(ResourceEntry entry, ref int offset, Dictionary<string, int> strings, ref int stringTableOffset, ByteBuffer stringTable) { WriteNameOrOrdinal(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; }
private static int GetDirectoryLength(ResourceEntry entry) { if (entry.Data != null) return 16; return GetDirectoryLength(entry.Directory); }