private async Task ResolveSymlinks(IList <SDModule> modules) { foreach (SDModule module in modules) { SDCDModule cdModule = (SDCDModule)module; string output = await processHandler.ExecuteProcessAndGetOutputAsync("readlink", "-f " + cdModule.LocalPath); string path = output.Trim(); cdModule.LocalPath = path; cdModule.FileName = Path.GetFileName(path); } }
private async Task <Tuple <SDFileAndLineNumber, string> > Address2MethodSourceAsync(ulong instrPtr, SDCDModule module) { ulong relativeIp = instrPtr; string mainExecutable = ((SDCDSystemContext)analysisResult.SystemContext).FileName; mainExecutable = Path.GetFileName(mainExecutable); if (mainExecutable != module.FileName) { // Subtract modules start address unless it's the main executable relativeIp -= module.StartAddress + 1; } string output = await processHandler.ExecuteProcessAndGetOutputAsync("addr2line", $"-f -C -e {module.LocalPath} 0x{relativeIp.ToString("X")}"); string[] lines = output.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); if (lines.Length < 2) { Console.WriteLine($"Output of addr2line is invalid ({lines.Length} lines)! First line: {lines?[0]}"); return(Tuple.Create <SDFileAndLineNumber, string>(new SDFileAndLineNumber(), null)); } string methodName = lines[0]; string fileLine = lines[1]; SDFileAndLineNumber sourceInfo = RetrieveSourceInfo(fileLine); return(Tuple.Create(sourceInfo, methodName)); }
private async Task <Tuple <SDFileAndLineNumber, string> > Address2MethodSourceAsync(ulong instrPtr, SDCDModule module) { ulong relativeIp = instrPtr; var systemContext = (SDCDSystemContext)analysisResult.SystemContext; // Calculate the relative IP to the base module. // For this we must subtract the start address of the whole module from the IP // The module start address from the parameter is only the start address of the segment. // We get the real module start address by subtracting the page offset multiplied by the page size from the segment start. ulong moduleStartAddress = module.StartAddress - (module.Offset * (uint)systemContext.PageSize); relativeIp -= moduleStartAddress + 1; string output = await processHandler.ExecuteProcessAndGetOutputAsync("addr2line", $"-f -C -e {module.LocalPath} 0x{relativeIp.ToString("X")}"); string[] lines = output.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); if (lines.Length < 2) { Console.WriteLine($"Output of addr2line is invalid ({lines.Length} lines)! First line: {lines?[0]}"); return(Tuple.Create <SDFileAndLineNumber, string>(new SDFileAndLineNumber(), null)); } string methodName = lines[0]; string fileLine = lines[1]; SDFileAndLineNumber sourceInfo = RetrieveSourceInfo(fileLine); return(Tuple.Create(sourceInfo, methodName)); }
/// <summary> /// Overrides the original *.so with the unstripped binary /// </summary> private async Task UnstripLibrary(SDCDModule module, string hash) { if (IsDebugFileAvailable(module, hash)) { filesystem.Move(module.LocalPath, module.LocalPath + ".old"); await processHandler.ExecuteProcessAndGetOutputAsync("eu-unstrip", $"-o {module.LocalPath} {module.LocalPath}.old {DebugFilePath(module.LocalPath, hash)}"); filesystem.Delete(module.LocalPath + ".old"); } }
/// <summary> /// Overrides the original *.so with the unstripped binary /// </summary> private async Task UnstripLibrary(SDCDModule module, string hash) { if (IsDebugFileAvailable(module, hash)) { string tempBinary = module.LocalPath + ".old"; if (filesystem.GetFile(tempBinary).Exists) { filesystem.Delete(tempBinary); } filesystem.Move(module.LocalPath, tempBinary); await processHandler.ExecuteProcessAndGetOutputAsync("eu-unstrip", $"-o {module.LocalPath} {tempBinary} {DebugFilePath(module.LocalPath, hash)}"); filesystem.Delete(tempBinary); } }
private async Task <Tuple <SDFileAndLineNumber, string> > Address2MethodSourceAsync(ulong instrPtr, SDCDModule module) { ulong relativeIp = instrPtr; if (module.DebugSymbolPath != null && module.DebugSymbolPath != "") { // If there is a debug file, link it (required for addr2line to find the dbg file) LinkDebugFile(module.LocalPath, module.DebugSymbolPath); } string output = await processHandler.ExecuteProcessAndGetOutputAsync("addr2line", $"-f -C -e {module.LocalPath} 0x{relativeIp.ToString("X")}"); string[] lines = output.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); if (lines.Length < 2) { Console.WriteLine($"Output of addr2line is invalid ({lines.Length} lines)! First line: {lines?[0]}"); return(Tuple.Create <SDFileAndLineNumber, string>(new SDFileAndLineNumber(), null)); } string methodName = lines[0]; string fileLine = lines[1]; SDFileAndLineNumber sourceInfo = RetrieveSourceInfo(fileLine); return(Tuple.Create(sourceInfo, methodName)); }