コード例 #1
0
 public RenameInfo(ResourceElement element, string newName)
 {
     this.element = element;
     this.newName = newName;
     this.foundInCode = false;
 }
コード例 #2
0
ファイル: ResourceWriter.cs プロジェクト: GreenDamTan/de4dot
 void WriteData(BinaryWriter writer, ResourceElement info, IFormatter formatter)
 {
     var code = GetResourceType(info.ResourceData);
     WriteUInt32(writer, (uint)code);
     info.ResourceData.WriteData(writer, formatter);
 }
コード例 #3
0
 string getNewName(ResourceElement elem)
 {
     if (elem.ResourceData.Code != ResourceTypeCode.String)
         return createDefaultName();
     var stringData = (BuiltInResourceData)elem.ResourceData;
     var name = createPrefixFromStringData((string)stringData.Data);
     return createName(counter => counter == 0 ? name : string.Format("{0}_{1}", name, counter));
 }
コード例 #4
0
ファイル: ResourceReader.cs プロジェクト: Joelone/de4dot
        ResourceElementSet read()
        {
            ResourceElementSet resources = new ResourceElementSet();

            uint sig = reader.ReadUInt32();
            if (sig != 0xBEEFCACE)
                throw new ResourceReaderException(string.Format("Invalid resource sig: {0:X8}", sig));
            if (!checkReaders())
                throw new ResourceReaderException("Invalid resource reader");
            int version = reader.ReadInt32();
            if (version != 2)
                throw new ResourceReaderException(string.Format("Invalid resource version: {0}", version));
            int numResources = reader.ReadInt32();
            if (numResources < 0)
                throw new ResourceReaderException(string.Format("Invalid number of resources: {0}", numResources));
            int numUserTypes = reader.ReadInt32();
            if (numUserTypes < 0)
                throw new ResourceReaderException(string.Format("Invalid number of user types: {0}", numUserTypes));

            var userTypes = new List<UserResourceType>();
            for (int i = 0; i < numUserTypes; i++)
                userTypes.Add(new UserResourceType(reader.ReadString(), ResourceTypeCode.UserTypes + i));
            reader.BaseStream.Position = (reader.BaseStream.Position + 7) & ~7;

            var hashes = new int[numResources];
            for (int i = 0; i < numResources; i++)
                hashes[i] = reader.ReadInt32();
            var offsets = new int[numResources];
            for (int i = 0; i < numResources; i++)
                offsets[i] = reader.ReadInt32();

            long baseOffset = reader.BaseStream.Position;
            long dataBaseOffset = reader.ReadInt32();
            long nameBaseOffset = reader.BaseStream.Position;
            long end = reader.BaseStream.Length;

            var infos = new List<ResourceInfo>(numResources);

            var nameReader = new BinaryReader(reader.BaseStream, Encoding.Unicode);
            for (int i = 0; i < numResources; i++) {
                nameReader.BaseStream.Position = nameBaseOffset + offsets[i];
                var name = nameReader.ReadString();
                long offset = dataBaseOffset + nameReader.ReadInt32();
                infos.Add(new ResourceInfo(name, offset));
            }

            infos.Sort(sortResourceInfo);
            for (int i = 0; i < infos.Count; i++) {
                var info = infos[i];
                var element = new ResourceElement();
                element.Name = info.name;
                reader.BaseStream.Position = info.offset;
                long nextDataOffset = i == infos.Count - 1 ? end : infos[i + 1].offset;
                int size = (int)(nextDataOffset - info.offset);
                element.ResourceData = readResourceData(userTypes, size);

                resources.add(element);
            }

            return resources;
        }
コード例 #5
0
ファイル: ResourceElementSet.cs プロジェクト: Joelone/de4dot
 public void add(ResourceElement elem)
 {
     dict[elem.Name] = elem;
 }
コード例 #6
0
        ResourceElementSet read()
        {
            ResourceElementSet resources = new ResourceElementSet();

            uint sig = reader.ReadUInt32();

            if (sig != 0xBEEFCACE)
            {
                throw new ResourceReaderException(string.Format("Invalid resource sig: {0:X8}", sig));
            }
            if (!checkReaders())
            {
                throw new ResourceReaderException("Invalid resource reader");
            }
            int version = reader.ReadInt32();

            if (version != 2)
            {
                throw new ResourceReaderException(string.Format("Invalid resource version: {0}", version));
            }
            int numResources = reader.ReadInt32();

            if (numResources < 0)
            {
                throw new ResourceReaderException(string.Format("Invalid number of resources: {0}", numResources));
            }
            int numUserTypes = reader.ReadInt32();

            if (numUserTypes < 0)
            {
                throw new ResourceReaderException(string.Format("Invalid number of user types: {0}", numUserTypes));
            }

            var userTypes = new List <UserResourceType>();

            for (int i = 0; i < numUserTypes; i++)
            {
                userTypes.Add(new UserResourceType(reader.ReadString(), ResourceTypeCode.UserTypes + i));
            }
            reader.Position = (reader.Position + 7) & ~7;

            var hashes = new int[numResources];

            for (int i = 0; i < numResources; i++)
            {
                hashes[i] = reader.ReadInt32();
            }
            var offsets = new int[numResources];

            for (int i = 0; i < numResources; i++)
            {
                offsets[i] = reader.ReadInt32();
            }

            long baseOffset     = reader.Position;
            long dataBaseOffset = reader.ReadInt32();
            long nameBaseOffset = reader.Position;
            long end            = reader.Length;

            var infos = new List <ResourceInfo>(numResources);

            for (int i = 0; i < numResources; i++)
            {
                reader.Position = nameBaseOffset + offsets[i];
                var  name   = reader.ReadString(Encoding.Unicode);
                long offset = dataBaseOffset + reader.ReadInt32();
                infos.Add(new ResourceInfo(name, offset));
            }

            infos.Sort((a, b) => a.offset.CompareTo(b.offset));
            for (int i = 0; i < infos.Count; i++)
            {
                var info    = infos[i];
                var element = new ResourceElement();
                element.Name    = info.name;
                reader.Position = info.offset;
                long nextDataOffset = i == infos.Count - 1 ? end : infos[i + 1].offset;
                int  size           = (int)(nextDataOffset - info.offset);
                element.ResourceData = readResourceData(userTypes, size);

                resources.add(element);
            }

            return(resources);
        }
コード例 #7
0
 public void Add(ResourceElement elem)
 {
     dict[elem.Name] = elem;
 }