public void SetBssSegment(ElfSegmentInfo info) { if (info == null) { return; } if ((info.VirtualAddress & 15UL) > 0UL) { throw new ArgumentException(string.Format(Resources.Message_InvalidBssSegmentAlign, (object)info.VirtualAddress)); } this.header.BssSize = (uint)info.MemorySize; this.bssMemoryOffset = (uint)info.VirtualAddress; if (this.header.BssSize <= 0U) { return; } if (this.header.DataSize == 0U) { this.header.RoMemoryOffset = this.bssMemoryOffset; } if (this.bssMemoryOffset < this.header.DataMemoryOffset + this.header.DataSize) { throw new ArgumentException(Resources.Message_InvalidBssSegments); } uint num = this.header.DataMemoryOffset + this.header.DataSize; this.header.BssSize += num > 0U ? this.bssMemoryOffset - num : 0U; }
public void SetDataSegment(ElfSegmentInfo info) { if (info == null) { return; } if ((info.VirtualAddress & 4095UL) > 0UL) { throw new ArgumentException(string.Format(Resources.Message_InvalidSegmentAlign, (object)"Data", (object)info.VirtualAddress)); } if (info.MemorySize > (ulong)int.MaxValue) { throw new ArgumentException(string.Format(Resources.Message_InvalidSegmentSize, (object)"Data", (object)info.MemorySize)); } this.header.DataMemoryOffset = (uint)info.VirtualAddress; this.header.DataSize = (uint)info.MemorySize; this.dataBinary = info.GetContents(); this.header.DataFileSize = (uint)this.dataBinary.Length; }
public void SetTextSegment(ElfSegmentInfo info) { if (info == null) { return; } if (info.VirtualAddress != 0UL) { throw new ArgumentException(string.Format(Resources.Message_InvalidTextAddress, (object)info.VirtualAddress)); } if (info.MemorySize > (ulong)int.MaxValue) { throw new ArgumentException(string.Format(Resources.Message_InvalidSegmentSize, (object)"Text", (object)info.MemorySize)); } this.header.TextMemoryOffset = (uint)info.VirtualAddress; this.header.TextSize = (uint)info.MemorySize; this.textBinary = info.GetContents(); this.header.TextFileSize = (uint)this.textBinary.Length; }
private static void Main(string[] args) { if (Directory.Exists(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "en"))) { Thread.CurrentThread.CurrentUICulture = new CultureInfo("en", false); } MakeNsoArgs makeNsoArgs = new MakeNsoArgs(); try { if (!makeNsoArgs.ParseArgs(args)) { return; } } catch { Environment.ExitCode = 1; return; } try { bool flag = true; MakeNsoParams makeNsoParams = makeNsoArgs.Params; NsoFile nsoFile = new NsoFile(); if (makeNsoParams.Compress) { flag = true; } if (makeNsoParams.NoCompress) { flag = false; } nsoFile.CompressMode = flag; nsoFile.SetModuleName(makeNsoParams.ModuleName); ElfInfo elf = new ElfInfo(makeNsoParams.DsoFileName); foreach (ElfSectionInfo sectionInfo in (IEnumerable <ElfSectionInfo>)elf.SectionInfos) { if (elf.FileType == ElfFileType.SharedObjectFile && sectionInfo.AddressAlign > 4096UL) { throw new ArgumentException(string.Format(Resources.Message_InvalidSectionAlign, (object)sectionInfo.SectionName, (object)sectionInfo.AddressAlign)); } } byte[] buildId = BuildId.GetBuildId(elf); if (buildId != null) { nsoFile.SetModuleId(buildId); } elf.GetExElfSegmentInfo(); ElfSegmentInfo roElfSegmentInfo = elf.GetRoElfSegmentInfo(); elf.GetRwElfSegmentInfo(); elf.GetZiElfSegmentInfo(); nsoFile.SetTextSegment(elf.GetExElfSegmentInfo()); nsoFile.SetRoSegment(elf.GetRoElfSegmentInfo()); nsoFile.SetDataSegment(elf.GetRwElfSegmentInfo()); nsoFile.SetBssSegment(elf.GetZiElfSegmentInfo()); ElfSectionInfo infoElfSectionInfo = elf.GetApiInfoElfSectionInfo(); if (infoElfSectionInfo != null) { nsoFile.SetApiInfo(infoElfSectionInfo.VirtualAddress - roElfSegmentInfo.VirtualAddress, infoElfSectionInfo.SectionSize); } nsoFile.CompressTextSegment(); nsoFile.CompressRoSegment(); nsoFile.CompressDataSegment(); nsoFile.CalcPosition(); using (FileStream fs = new FileStream(makeNsoParams.NsoFileName, FileMode.Create, FileAccess.Write)) nsoFile.WriteData(fs); if (!makeNsoParams.VerboseMode) { return; } nsoFile.PrintNsoHeader(); } catch (Exception ex) { Console.Error.WriteLine(string.Format("MakeNso INPUT='{0}', OUTPUT='{1}'", (object)makeNsoArgs.Params.DsoFileName, (object)makeNsoArgs.Params.NsoFileName)); Console.Error.WriteLine(ex.Message); Environment.ExitCode = 1; } }