internal static byte[] GetBuildId(ElfInfo elf) { foreach (ElfSectionInfo sectionInfo in (IEnumerable <ElfSectionInfo>)elf.SectionInfos) { if (sectionInfo.SectionType == ElfSectionType.Note) { ElfNoteSectionInfo info = new ElfNoteSectionInfo(sectionInfo); if (ElfGnuNoteSection.IsElfGnuNoteSection(info) && ElfGnuNoteSection.GetGnuNoteSectionType(info) == ElfGnuNoteSectionType.BuildId) { return(info.Desc); } } } return((byte[])null); }
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; } }