Skip to content

Commit

Permalink
Make shared
Browse files Browse the repository at this point in the history
  • Loading branch information
nxtn committed Dec 2, 2019
1 parent ea77aec commit dea4798
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Microsoft.Diagnostics.Runtime.Linux;
Expand Down Expand Up @@ -142,23 +141,8 @@ public bool GetThreadContext(uint threadID, uint contextFlags, Span<byte> contex
public unsafe void GetVersionInfo(ulong baseAddress, out VersionInfo version)
{
ElfLoadedImage image = _core.LoadedImages.First(image => (ulong)image.BaseAddress == baseAddress);

long loadAddress = 0;
long loadSize = 0;
foreach (ElfProgramHeader programHeader in image.Open().ProgramHeaders)
{
if (programHeader.Type == ElfProgramHeaderType.Load && programHeader.IsWritable)
{
loadAddress = programHeader.VirtualAddress;
loadSize = programHeader.VirtualSize;
break;
}
}

Debug.Assert(loadAddress != 0);
Debug.Assert(loadSize != 0);

LinuxFunctions.GetVersionInfo(this, baseAddress + (ulong)loadAddress, (ulong)loadSize, out version);
ElfFile file = image.Open();
LinuxFunctions.GetVersionInfo(this, baseAddress, file, out version);
}

public uint ReadDwordUnsafe(ulong addr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,7 @@ public unsafe void GetVersionInfo(ulong baseAddress, out VersionInfo version)
{
MemoryVirtualAddressSpace memoryAddressSpace = new MemoryVirtualAddressSpace(this);
ElfFile file = new ElfFile(new Reader(memoryAddressSpace), (long)baseAddress);

long loadAddress = 0;
long loadSize = 0;
foreach (ElfProgramHeader programHeader in file.ProgramHeaders)
{
if (programHeader.Type == ElfProgramHeaderType.Load && programHeader.IsWritable)
{
loadAddress = programHeader.VirtualAddress;
loadSize = programHeader.VirtualSize;
break;
}
}

Debug.Assert(loadAddress != 0);
Debug.Assert(loadSize != 0);

LinuxFunctions.GetVersionInfo(this, baseAddress + (ulong)loadAddress, (ulong)loadSize, out version);
LinuxFunctions.GetVersionInfo(this, baseAddress, file, out version);
}

public bool ReadMemory(ulong address, Span<byte> span, out int bytesRead)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ public LinuxFunctions()
}
}

internal static void GetVersionInfo(IDataReader dataReader, ulong baseAddress, ElfFile loadedFile, out VersionInfo version)
{
foreach (ElfProgramHeader programHeader in loadedFile.ProgramHeaders)
{
if (programHeader.Type == ElfProgramHeaderType.Load && programHeader.IsWritable)
{
long loadAddress = programHeader.VirtualAddress;
long loadSize = programHeader.VirtualSize;
GetVersionInfo(dataReader, baseAddress + (ulong)loadAddress, (ulong)loadSize, out version);
return;
}
}

version = default;
}

internal static unsafe void GetVersionInfo(IDataReader dataReader, ulong address, ulong size, out VersionInfo version)
{
Span<byte> buffer = stackalloc byte[s_versionLength];
Expand Down

0 comments on commit dea4798

Please sign in to comment.