public ResourcesDlg(ResourceDirectory rootDir) { InitializeComponent(); TreeNode rootDirectoryNode = new TreeNode("Root Resource Directory"); rootDirectoryNode.Tag = rootDir; PopulateDirectory(rootDirectoryNode, rootDir); treeView1.Nodes.Add(rootDirectoryNode); }
internal ResourceDirectoryEntry(DataDirectory dataDirectory, Location dataLocation, ResourceDirectory parentDirectory, IMAGE_RESOURCE_DIRECTORY_ENTRY directoryEntry) : base(dataDirectory,dataLocation) { parent_directory = parentDirectory; entry = directoryEntry; name = null; directory = null; data = null; }
private void PopulateDirectory(TreeNode parentNode, ResourceDirectory directory) { for (int i = 0; i < directory.ChildEntries.Length; i++) { TreeNode node = new TreeNode("Resource Directory Entry - ID:" + directory.ChildEntries[i].Name); node.Tag = directory.ChildEntries[i]; PopulateDirectoryEntry(node, directory.ChildEntries[i]); parentNode.Nodes.Add(node); } }
private static ResourceDirectory ReadResourceDirectoryTable(BinaryReader dr) { var t = new ResourceDirectory { Characteristics = dr.ReadUInt32(), TimeDateStamp = dr.ReadUInt32(), MajorVersion = dr.ReadUInt16(), MinVersion = dr.ReadUInt16(), NumNameEntries = dr.ReadUInt16(), NumIdEntries = dr.ReadUInt16() }; return t; }
public ResourceWalker(PortableExecutable image) { IMAGE_DATA_DIRECTORY rsrcDir = image.NTHeader.OptionalHeader.DataDirectory[(int)DATA_DIRECTORIES.ResourceTable]; IMAGE_RESOURCE_DIRECTORY rootDir; uint rootAddr = 0; if (rsrcDir.VirtualAddress > 0 && rsrcDir.Size > 0) { if (image.Read((rootAddr = image.GetPtrFromRVA(rsrcDir.VirtualAddress)), System.IO.SeekOrigin.Begin, out rootDir)) this.Root = new ResourceDirectory(image, new IMAGE_RESOURCE_DIRECTORY_ENTRY() { SubdirectoryRva = 0x80000000 }, false, rootAddr); else throw image.GetLastError(); } }
/// <summary> /// Creates a new immutable instance of this class. /// </summary> /// <param name="filePath">A file path the points to a PE file.</param> public PortableExecutable(string filePath) { _data = File.ReadAllBytes(filePath); using (var br = new BlobReader(_data, 0, _data.Length)) { br.Read(ref _dosHeader); br.Seek((int)_dosHeader.e_lfanew); br.Read(ref _signature); br.Read(ref _fileHeader); if (_fileHeader.OptionalHeaderSize > 0) { br.Read(ref _imageType); switch (_imageType) { case ImageType.PE32: br.Read(ref _optionalHeader32); br.Read(ref _dataDirectories, (int)_optionalHeader32.DataDirectoryCount); break; case ImageType.PE64: br.Read(ref _optionalHeader64); br.Read(ref _dataDirectories, (int)_optionalHeader64.DataDirectoryCount); break; default: throw new ArgumentException("UnknownImageType"); } } br.Read(ref _sectionHeaders, _fileHeader.SectionCount); if (_dataDirectories[(int)DataDirectoryType.CliHeader].RVA > 0) { var cliHeaderOffset = FindDataDirectoryOffset(DataDirectoryType.CliHeader); br.Seek(cliHeaderOffset); br.Read(ref _cliHeader); var metaDataRootOffset = FindRvaOffset(_cliHeader.MetadataRVA); _metadataRoot = new MetadataRoot(new Slice(_data, metaDataRootOffset, (int)_cliHeader.MetadataSize)); } var resourceHeader = _dataDirectories[(int)DataDirectoryType.Resource]; if (resourceHeader.RVA > 0) { var offset = FindDataDirectoryOffset(DataDirectoryType.Resource); br.Seek(offset); _resourceDirectory = new ResourceDirectory(br.ReadSlice((int)resourceHeader.Size), this); } } }
private void WriteDirectory(ResourceDirectory directory) { Writer.WriteStructure<Structures.IMAGE_RESOURCE_DIRECTORY>(directory.rawDirectory); foreach (ResourceDirectoryEntry entry in directory.ChildEntries) { Writer.WriteStructure<Structures.IMAGE_RESOURCE_DIRECTORY_ENTRY>(entry.rawEntry); } foreach (ResourceDirectoryEntry entry in directory.ChildEntries) { uint offsetToData = entry.OffsetToData; if (offsetToData >= 0x80000000) offsetToData -= 0x80000000; Writer.MoveToOffset(offsetToData + resourceDirectory.TargetOffset.FileOffset); WriteDirectoryEntry(entry); } }
private void Write(ResourceDirectory directory, int writeDepth, int currentDepth, ref int offset, Dictionary<string, int> strings, ref int stringTableOffset, ByteBuffer stringTable) { if (currentDepth == writeDepth) { ushort namedEntries = directory.SortEntries(); // directory header win32_resources.WriteUInt32(directory.Characteristics); win32_resources.WriteUInt32(directory.TimeDateStamp); win32_resources.WriteUInt16(directory.MajorVersion); win32_resources.WriteUInt16(directory.MinVersion); win32_resources.WriteUInt16(namedEntries); win32_resources.WriteUInt16((ushort)(directory.Entries.Count - namedEntries)); foreach (ResourceEntry entry in directory.Entries) { WriteEntry(entry, ref offset, strings, ref stringTableOffset, stringTable); } } else { foreach (ResourceEntry entry in directory.Entries) { Write(entry.Directory, writeDepth, currentDepth + 1, ref offset, strings, ref stringTableOffset, stringTable); } } }
private static int GetDirectoryLength(ResourceDirectory dir) { int length = 16 + dir.Entries.Count * 8; foreach (ResourceEntry entry in dir.Entries) length += GetDirectoryLength(entry); return length; }
void GetWin32Resources() { if (module.Win32Resources != null) { win32_rva = module.Win32RVA; win32_resources = new ByteBuffer(module.Win32Resources); return; } if (module.Win32ResourceDirectory != null) { win32_resources_directory = module.Win32ResourceDirectory; return; } var rsrc = GetImageResourceSection(); if (rsrc == null) return; var raw_resources = new byte [rsrc.Data.Length]; Buffer.BlockCopy (rsrc.Data, 0, raw_resources, 0, rsrc.Data.Length); win32_rva = rsrc.VirtualAddress; win32_resources = new ByteBuffer (raw_resources); }
public ResourceDirectory GetDirectory() { if (directory == null && ((entry.OffsetToData & 0x80000000) == 0x80000000)) { LocationCalculator calc = DataDirectory.Directories.Image.GetCalculator(); Stream stream = DataDirectory.Directories.Image.GetStream(); uint offset = entry.OffsetToData & 0x7fffffff; uint rva = DataDirectory.VirtualAddress + offset; ulong va = DataDirectory.Directories.Image.NTHeaders.OptionalHeader.ImageBase + rva; ulong file_offset = calc.RVAToOffset(rva); uint size = Utils.SizeOf<IMAGE_RESOURCE_DIRECTORY>().ToUInt32(); Section section = calc.RVAToSection(rva); Location location = new Location(file_offset, rva, va, size, size, section); directory = new ResourceDirectory(parent_directory.DataDirectory,location,this); } return directory; }
private static void Print(ResourceDirectory resources) { Print(resources, 0); Console.WriteLine(); }
private void WriteWin32ResourcesDirectory(ResourceDirectory directory) { win32_resources = new ByteBuffer(); if (directory.Entries.Count != 0) { int stringTableOffset = GetDirectoryLength(directory); Dictionary<string, int> strings = new Dictionary<string, int>(); ByteBuffer stringTable = new ByteBuffer(16); int offset = 16 + directory.Entries.Count * 8; for (int pass = 0; pass < 3; pass++) Write(directory, pass, 0, ref offset, strings, ref stringTableOffset, stringTable); // the pecoff spec says that the string table is between the directory entries and the data entries, // but the windows linker puts them after the data entries, so we do too. stringTable.Align(4); offset += stringTable.length; WriteResourceDataEntries(directory, ref offset); win32_resources.WriteBytes(stringTable); WriteData(directory); } }
private void AddResourceNode(ResourceDirectory Node, long PEIndex, long RVA, long ResourSectRva) { PEFileIndex = PEIndex + RVA; //设置位置 Loadbyte(ref Node.Characteristics); Loadbyte(ref Node.TimeDateStamp); Loadbyte(ref Node.MajorVersion); Loadbyte(ref Node.MinorVersion); Loadbyte(ref Node.NumberOfNamedEntries); Loadbyte(ref Node.NumberOfIdEntries); long NameRVA = GetLong(Node.NumberOfNamedEntries); for (int i = 0; i != NameRVA; i++) { ResourceDirectory.DirectoryEntry Entry = new ResourceDirectory.DirectoryEntry(); Loadbyte(ref Entry.Name); Loadbyte(ref Entry.Id); byte[] Temp = new byte[2]; Temp[0] = Entry.Name[0]; Temp[1] = Entry.Name[1]; long NameIndex = GetLong(Temp) + PEIndex; Temp[0] = PEFileByte[NameIndex + 0]; Temp[1] = PEFileByte[NameIndex + 1]; long NameCount = GetLong(Temp); Node.Name = new byte[NameCount * 2]; for (int z = 0; z != Node.Name.Length; z++) { Node.Name[z] = PEFileByte[NameIndex + 2 + z]; } //System.Windows.Forms.MessageBox.Show(GetString(Entry.ID)); Temp[0] = Entry.Id[2]; Temp[1] = Entry.Id[3]; long OldIndex = PEFileIndex; if (GetLong(Temp) == 0) { Temp[0] = Entry.Id[0]; Temp[1] = Entry.Id[1]; PEFileIndex = GetLong(Temp) + PEIndex; ResourceDirectory.DirectoryEntry.DataEntry DataRVA = new ResourceDirectory.DirectoryEntry.DataEntry(); Loadbyte(ref DataRVA.ResourRVA); Loadbyte(ref DataRVA.ResourSize); Loadbyte(ref DataRVA.ResourTest); Loadbyte(ref DataRVA.ResourWen); PEFileIndex = OldIndex; Entry.DataEntryList.Add(DataRVA); //System.Windows.Forms.MessageBox.Show(GetString(DataRVA.ResourRVA)+"*"+GetString(DataRVA.ResourSize)); } else { Temp[0] = Entry.Id[0]; Temp[1] = Entry.Id[1]; ResourceDirectory Resource = new ResourceDirectory(); Entry.NodeDirectoryList.Add(Resource); AddResourceNode(Resource, PEIndex, GetLong(Temp), ResourSectRva); } PEFileIndex = OldIndex; Node.EntryList.Add(Entry); } long Count = GetLong(Node.NumberOfIdEntries); for (int i = 0; i != Count; i++) { ResourceDirectory.DirectoryEntry Entry = new ResourceDirectory.DirectoryEntry(); Loadbyte(ref Entry.Name); Loadbyte(ref Entry.Id); //System.Windows.Forms.MessageBox.Show(GetString(Entry.Name)+"_"+GetString(Entry.Id)); byte[] Temp = new byte[2]; Temp[0] = Entry.Id[2]; Temp[1] = Entry.Id[3]; long OldIndex = PEFileIndex; if (GetLong(Temp) == 0) { Temp[0] = Entry.Id[0]; Temp[1] = Entry.Id[1]; PEFileIndex = GetLong(Temp) + PEIndex; ResourceDirectory.DirectoryEntry.DataEntry DataRVA = new ResourceDirectory.DirectoryEntry.DataEntry(); Loadbyte(ref DataRVA.ResourRVA); Loadbyte(ref DataRVA.ResourSize); Loadbyte(ref DataRVA.ResourTest); Loadbyte(ref DataRVA.ResourWen); long FileRva = GetLong(DataRVA.ResourRVA) - ResourSectRva + PEIndex; DataRVA.FileStarIndex = FileRva; DataRVA.FileEndIndex = FileRva + GetLong(DataRVA.ResourSize); PEFileIndex = OldIndex; Entry.DataEntryList.Add(DataRVA); //System.Windows.Forms.MessageBox.Show(GetString(DataRVA.ResourRVA)+"*"+GetString(DataRVA.ResourSize)); } else { Temp[0] = Entry.Id[0]; Temp[1] = Entry.Id[1]; ResourceDirectory Resource = new ResourceDirectory(); Entry.NodeDirectoryList.Add(Resource); AddResourceNode(Resource, PEIndex, GetLong(Temp), ResourSectRva); } PEFileIndex = OldIndex; Node.EntryList.Add(Entry); } }
static byte[] TryCreateIcon(ref DataReader reader, ResourceDirectory iconDir) { try { reader.Position = 0; var outStream = new MemoryStream(); var writer = new BinaryWriter(outStream); // Write GRPICONDIR writer.Write(reader.ReadUInt16()); writer.Write(reader.ReadUInt16()); ushort numImages; writer.Write(numImages = reader.ReadUInt16()); var entries = new List <GrpIconDirEntry>(); for (int i = 0; i < numImages; i++) { var e = new GrpIconDirEntry(); entries.Add(e); e.bWidth = reader.ReadByte(); e.bHeight = reader.ReadByte(); e.bColorCount = reader.ReadByte(); e.bReserved = reader.ReadByte(); e.wPlanes = reader.ReadUInt16(); e.wBitCount = reader.ReadUInt16(); e.dwBytesInRes = reader.ReadUInt32(); e.nID = reader.ReadUInt16(); } uint dataOffset = 2 * 3 + (uint)entries.Count * 0x10; foreach (var e in entries) { writer.Write(e.bWidth); writer.Write(e.bHeight); writer.Write(e.bColorCount); writer.Write(e.bReserved); writer.Write(e.wPlanes); writer.Write(e.wBitCount); writer.Write(e.dwBytesInRes); writer.Write(dataOffset); dataOffset += e.dwBytesInRes; } foreach (var e in entries) { var d = iconDir.Directories.FirstOrDefault(a => a.Name == new ResourceName(e.nID)); if (d == null || d.Data.Count == 0) { return(null); } var r = d.Data[0].CreateReader(); Debug.Assert(r.Length == e.dwBytesInRes); if (r.Length < e.dwBytesInRes) { return(null); } writer.Write(r.ReadBytes((int)e.dwBytesInRes), 0, (int)e.dwBytesInRes); } return(outStream.ToArray()); } catch (IOException) { } return(null); }
/// <summary>Create instance of dialog resource class</summary> /// <param name="directory">Resource directory</param> public ResourceDialog(ResourceDirectory directory) : base(directory, WinNT.Resource.RESOURCE_DIRECTORY_TYPE.RT_DIALOG) { }
private void AddResourceDirectoryRow(DataTable MyTable, ResourceDirectory Node, string ParentID) { string Name = ""; if (Node.Name != null) { Name = GetString(Node.Name, "UNICODE"); } for (int i = 0; i != Node.EntryList.Count; i++) { ResourceDirectory.DirectoryEntry Entry = (ResourceDirectory.DirectoryEntry)Node.EntryList[i]; long ID = GetLong(Entry.Name); string GUID = Guid.NewGuid().ToString(); string IDNAME = "ID{" + ID + "}"; if (Name.Length != 0) IDNAME += "Name{" + Name + "}"; if (ParentID.Length == 0) { switch (ID) { case 1: IDNAME += "Type{Cursor}"; break; case 2: IDNAME += "Type{Bitmap}"; break; case 3: IDNAME += "Type{Icon}"; break; case 4: IDNAME += "Type{Cursor}"; break; case 5: IDNAME += "Type{Menu}"; break; case 6: IDNAME += "Type{Dialog}"; break; case 7: IDNAME += "Type{String Table}"; break; case 8: IDNAME += "Type{Font Directory}"; break; case 9: IDNAME += "Type{Font}"; break; case 10: IDNAME += "Type{Accelerators}"; break; case 11: IDNAME += "Type{Unformatted}"; break; case 12: IDNAME += "Type{Message Table}"; break; case 13: IDNAME += "Type{Group Cursor}"; break; case 14: IDNAME += "Type{Group Icon}"; break; case 15: IDNAME += "Type{Information}"; break; case 16: IDNAME += "Type{Version}"; break; default: IDNAME += "Type{未定义}"; break; } } MyTable.Rows.Add(new string[] { GUID, IDNAME, ParentID }); for (int z = 0; z != Entry.DataEntryList.Count; z++) { ResourceDirectory.DirectoryEntry.DataEntry Data = (ResourceDirectory.DirectoryEntry.DataEntry)Entry.DataEntryList[z]; string Text = "Address{" + GetString(Data.ResourRVA) + "} Size{" + GetString(Data.ResourSize) + "} FileBegin{" + Data.FileStarIndex.ToString() + "-" + Data.FileEndIndex.ToString() + "}"; MyTable.Rows.Add(new string[] { Guid.NewGuid().ToString(), Text, GUID }); } for (int z = 0; z != Entry.NodeDirectoryList.Count; z++) { AddResourceDirectoryRow(MyTable, (ResourceDirectory)Entry.NodeDirectoryList[z], GUID); } } }
private void MergeDirectory(List<ResourceEntry> parents, ResourceDirectory ret, AssemblyDefinition ass, ResourceDirectory directory) { foreach (var entry in directory.Entries) { var exist = ret.Entries.FirstOrDefault(x => entry.Name == null ? entry.Id == x.Id : entry.Name == x.Name); if (exist == null) ret.Entries.Add(entry); else MergeEntry(parents, exist, ass, entry); } }
protected ResourceComponent RetrieveResource(ResourceDirectory resourcesDirectory, object[] keys, uint keyIndex) { ResourceComponent component = resourcesDirectory[keys[keyIndex]]; if (keyIndex == (keys.Length - 1)) { return component; } if (component is ResourceDirectory) { return this.RetrieveResource((ResourceDirectory) component, keys, keyIndex + 1); } return null; }
void Add(ResourceDirectory rd) { AddToStack(rd); }
public PeReader(string fPath) { m_fPath = fPath; m_peImage = new PEImage(File.ReadAllBytes(fPath)); if (m_peImage.ImageNTHeaders.OptionalHeader.DataDirectories.Length >= 14) { ImageDataDirectory DotNetDir = m_peImage.ImageNTHeaders.OptionalHeader.DataDirectories[14]; if (m_peImage.ToFileOffset(DotNetDir.VirtualAddress) != 0 && DotNetDir.Size >= 72) { m_cor20Header = new ImageCor20Header(m_peImage.CreateStream(m_peImage.ToFileOffset(DotNetDir.VirtualAddress), 0x48), false); if (m_peImage.ToFileOffset(m_cor20Header.MetaData.VirtualAddress) != 0 && m_cor20Header.MetaData.Size >= 16) { m_isManaged = true; uint mdSize = m_cor20Header.MetaData.Size; RVA mdRva = m_cor20Header.MetaData.VirtualAddress; MetaDataHeader mdHeader = new MetaDataHeader(m_peImage.CreateStream(m_peImage.ToFileOffset(mdRva), mdSize), false); m_RunTimeVersion = mdHeader.VersionString; } } } if (m_isManaged == true) { ImageSectionHeader sect = m_peImage.ImageSectionHeaders.Where(f => f.DisplayName == ".rsrc").FirstOrDefault(); if ((sect != null)) { ImageDataDirectory resourceTable = m_peImage.ImageNTHeaders.OptionalHeader.DataDirectories[2]; if ((resourceTable != null)) { uint rva = (uint)resourceTable.VirtualAddress; uint size = sect.VirtualSize > 0 ? sect.VirtualSize : sect.SizeOfRawData; if (rva >= (uint)sect.VirtualAddress && rva < (uint)sect.VirtualAddress + size) { Stream StreamRead = m_peImage.CreateFullStream().CreateStream(); long baseAddress = StreamRead.Seek(sect.PointerToRawData + (rva - (uint)sect.VirtualAddress), SeekOrigin.Begin); ResourceDirectory dirInfo = new ResourceDirectory(StreamRead, baseAddress); if ((dirInfo != null)) { using (BinaryReader reader = new BinaryReader(StreamRead)) { dirInfo.Read(reader, true, 0); ResourceEntry IconGroup = null; List <ResourceEntry> IconImages = new List <ResourceEntry>(); foreach (ResourceDirectory dir in dirInfo.Directorys) { if (dir.DirectoryEntry.Name == Convert.ToUInt32(Win32ResourceType.RT_GROUP_ICON)) { IconGroup = dir.GetFirstEntry(); break; } } foreach (ResourceDirectory dir in dirInfo.Directorys) { if (dir.DirectoryEntry.Name == Convert.ToUInt32(Win32ResourceType.RT_ICON)) { IconImages = dir.GetAllEntrys(); IconImages.Reverse(); break; } } if (IconGroup != null) { IconResource icon = new IconResource(StreamRead, IconGroup.DataAddress, sect.PointerToRawData, (uint)sect.VirtualAddress); icon.Seek(); if (!icon.Read(reader, IconImages)) { m_MainIcon = null; } m_MainIcon = icon.GetIcon(reader); } } } } } } } }
private void WriteData(ResourceDirectory directory) { foreach (ResourceEntry entry in directory.Entries) { if (entry.Data != null) { win32_resources.WriteBytes(entry.Data); win32_resources.Align(4); } else { WriteData(entry.Directory); } } }
internal void ReadRootDirectory() { image.SetOffset(resourceDirectory.TargetOffset.FileOffset); rootDirectory = ReadDirectory(null); }
private void WriteResourceDataEntries(ResourceDirectory directory, ref int offset) { foreach (ResourceEntry entry in directory.Entries) { if (entry.Data != null) { win32_resources.WriteUInt32((uint) (rsrc.VirtualAddress + offset)); win32_resources.WriteInt32(entry.Data.Length); win32_resources.WriteUInt32(entry.CodePage); win32_resources.WriteUInt32(entry.Reserved); offset += (entry.Data.Length + 3) & ~3; } else { WriteResourceDataEntries(entry.Directory, ref offset); } } }
protected string GenerateCommandLineCommands(string ManifestFile, string currentAbi, string currentResourceOutputFile) { // For creating Resource.Designer.cs: // Running command: C:\Program Files (x86)\Android\android-sdk-windows\platform-tools\aapt // "package" // "-M" "C:\Users\Jonathan\AppData\Local\Temp\ryob4gaw.way\AndroidManifest.xml" // "-J" "C:\Users\Jonathan\AppData\Local\Temp\ryob4gaw.way" // "-F" "C:\Users\Jonathan\AppData\Local\Temp\ryob4gaw.way\resources.apk" // "-S" "c:\users\jonathan\documents\visual studio 2010\Projects\MonoAndroidApplication4\MonoAndroidApplication4\obj\Debug\res" // "-I" "C:\Program Files (x86)\Android\android-sdk-windows\platforms\android-8\android.jar" // "--max-res-version" "10" // For packaging: // Running command: C:\Program Files (x86)\Android\android-sdk-windows\platform-tools\aapt // "package" // "-f" // "-m" // "-M" "AndroidManifest.xml" // "-J" "src" // "--custom-package" "androidmsbuildtest.androidmsbuildtest" // "-F" "bin\packaged_resources" // "-S" "C:\Users\Jonathan\Documents\Visual Studio 2010\Projects\AndroidMSBuildTest\AndroidMSBuildTest\obj\Debug\res" // "-I" "C:\Program Files (x86)\Android\android-sdk-windows\platforms\android-8\android.jar" // "--extra-packages" "com.facebook.android:my.another.library" var cmd = new CommandLineBuilder(); cmd.AppendSwitch("package"); if (MonoAndroidHelper.LogInternalExceptions) { cmd.AppendSwitch("-v"); } if (NonConstantId) { cmd.AppendSwitch("--non-constant-id"); } cmd.AppendSwitch("-f"); cmd.AppendSwitch("-m"); string manifestFile; string manifestDir = Path.Combine(Path.GetDirectoryName(ManifestFile), currentAbi != null ? currentAbi : "manifest"); Directory.CreateDirectory(manifestDir); manifestFile = Path.Combine(manifestDir, Path.GetFileName(ManifestFile)); ManifestDocument manifest = new ManifestDocument(ManifestFile, this.Log); if (currentAbi != null) { manifest.SetAbi(currentAbi); } manifest.ApplicationName = ApplicationName; manifest.Save(manifestFile); cmd.AppendSwitchIfNotNull("-M ", manifestFile); Directory.CreateDirectory(JavaDesignerOutputDirectory); cmd.AppendSwitchIfNotNull("-J ", JavaDesignerOutputDirectory); if (PackageName != null) { cmd.AppendSwitchIfNotNull("--custom-package ", PackageName.ToLowerInvariant()); } if (!string.IsNullOrEmpty(currentResourceOutputFile)) { cmd.AppendSwitchIfNotNull("-F ", currentResourceOutputFile + ".bk"); } // The order of -S arguments is *important*, always make sure this one comes FIRST cmd.AppendSwitchIfNotNull("-S ", ResourceDirectory.TrimEnd('\\')); if (AdditionalResourceDirectories != null) { foreach (var resdir in AdditionalResourceDirectories) { cmd.AppendSwitchIfNotNull("-S ", resdir.ItemSpec.TrimEnd('\\')); } } if (AdditionalAndroidResourcePaths != null) { foreach (var dir in AdditionalAndroidResourcePaths) { cmd.AppendSwitchIfNotNull("-S ", Path.Combine(dir.ItemSpec.TrimEnd(System.IO.Path.DirectorySeparatorChar), "res")); } } if (LibraryProjectJars != null) { foreach (var jar in LibraryProjectJars) { cmd.AppendSwitchIfNotNull("-j ", jar); } } cmd.AppendSwitchIfNotNull("-I ", JavaPlatformJarPath); // Add asset directory if it exists if (!string.IsNullOrWhiteSpace(AssetDirectory) && Directory.Exists(AssetDirectory)) { cmd.AppendSwitchIfNotNull("-A ", AssetDirectory.TrimEnd('\\')); } if (!string.IsNullOrWhiteSpace(UncompressedFileExtensions)) { foreach (var ext in UncompressedFileExtensions.Split(new char[] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries)) { cmd.AppendSwitchIfNotNull("-0 ", ext); } } if (!string.IsNullOrEmpty(ExtraPackages)) { cmd.AppendSwitchIfNotNull("--extra-packages ", ExtraPackages); } // TODO: handle resource names if (ExplicitCrunch) { cmd.AppendSwitch("--no-crunch"); } cmd.AppendSwitch("--auto-add-overlay"); var extraArgsExpanded = ExpandString(ExtraArgs); if (extraArgsExpanded != ExtraArgs) { Log.LogDebugMessage(" ExtraArgs expanded: {0}", extraArgsExpanded); } if (!string.IsNullOrWhiteSpace(extraArgsExpanded)) { cmd.AppendSwitch(extraArgsExpanded); } if (!AndroidUseLatestPlatformSdk) { cmd.AppendSwitchIfNotNull("--max-res-version ", ApiLevel); } return(cmd.ToString()); }
internal void ReadRootDirectory() { if (resourceDirectory.TargetOffset.FileOffset != 0) { rootDirectory = ReadDirectory(0, null); } }
/// <summary> /// 读取资源表 /// </summary> private void LoadResourceDirectory() { #region 初始化 if (_OptionalDirAttrib.DirByte.Count < 3) return; OptionalDirAttrib.DirAttrib ImporRVA = (OptionalDirAttrib.DirAttrib)_OptionalDirAttrib.DirByte[2]; long ImporAddress = GetLong(ImporRVA.DirRva); //获取的位置 if (ImporAddress == 0) return; long ImporSize = GetLong(ImporRVA.DirSize); //获取大小 _ResourceDirectory = new ResourceDirectory(); long SizeRva = 0; long PointerRva = 0; long StarRva = 0; long EndRva = 0; long PEIndex = 0; #endregion #region 获取位置 for (int i = 0; i != _SectionTable.Section.Count; i++) //循环节表 { SectionTable.SectionData Sect = (SectionTable.SectionData)_SectionTable.Section[i]; StarRva = GetLong(Sect.SizeOfRawDataRVA); EndRva = GetLong(Sect.SizeOfRawDataSize); if (ImporAddress >= StarRva && ImporAddress < StarRva + EndRva) { SizeRva = GetLong(Sect.SizeOfRawDataRVA); PointerRva = GetLong(Sect.PointerToRawData); PEFileIndex = ImporAddress - SizeRva + PointerRva; PEIndex = PEFileIndex; _ResourceDirectory.FileStarIndex = PEFileIndex; _ResourceDirectory.FileEndIndex = PEFileIndex + ImporSize; break; } } if (SizeRva == 0 && PointerRva == 0) return; #endregion AddResourceNode(_ResourceDirectory, PEIndex, 0, StarRva); }
private ResourceDirectory MergeWin32Resources(ResourceDirectory primary) { if (primary == null) return null; foreach (var ass in OtherAssemblies) { MergeDirectory(new List<ResourceEntry>(), primary, ass, ass.MainModule.Win32ResourceDirectory); } return primary; }
private void MergeDirectory(List <ResourceEntry> parents, ResourceDirectory ret, AssemblyDefinition ass, ResourceDirectory directory) { foreach (var entry in directory.Entries) { var exist = ret.Entries.FirstOrDefault(x => entry.Name == null ? entry.Id == x.Id : entry.Name == x.Name); if (exist == null) { ret.Entries.Add(entry); } else { MergeEntry(parents, exist, ass, entry); } } }