summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmy <amycmyu@gmail.com>2018-08-25 20:55:56 -0700
committerGitHub <noreply@github.com>2018-08-25 20:55:56 -0700
commit5d2ae2fc7f97f31fa2730fadfc56b832299fd9e0 (patch)
treeed2ed8595d21c89c93c43c73e157c2833741749f
parentc08d352c637af95f23ad3f9eb62436b2865500a4 (diff)
downloadcoreclr-5d2ae2fc7f97f31fa2730fadfc56b832299fd9e0.tar.gz
coreclr-5d2ae2fc7f97f31fa2730fadfc56b832299fd9e0.tar.bz2
coreclr-5d2ae2fc7f97f31fa2730fadfc56b832299fd9e0.zip
R2RDump - Non-Windows machine code (#19638)
* Get machine architecture for non-Windows images * Update readme * Throw exception if machine is invalid, output OS * Capitalization
-rw-r--r--src/tools/r2rdump/R2RReader.cs32
-rw-r--r--src/tools/r2rdump/TextDumper.cs1
2 files changed, 29 insertions, 4 deletions
diff --git a/src/tools/r2rdump/R2RReader.cs b/src/tools/r2rdump/R2RReader.cs
index 549415f669..d73fdc80b1 100644
--- a/src/tools/r2rdump/R2RReader.cs
+++ b/src/tools/r2rdump/R2RReader.cs
@@ -43,6 +43,19 @@ namespace R2RDump
}
}
+ /// <summary>
+ /// based on <a href="https://github.com/dotnet/coreclr/blob/master/src/inc/pedecoder.h">src/inc/pedecoder.h</a> IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE
+ /// </summary>
+ public enum OperatingSystem
+ {
+ Apple = 0x4644,
+ FreeBSD = 0xADC4,
+ Linux = 0x7B79,
+ NetBSD = 0x1993,
+ Windows = 0,
+ Unknown = -1
+ }
+
public class R2RReader
{
/// <summary>
@@ -76,6 +89,8 @@ namespace R2RDump
/// </summary>
public Machine Machine { get; set; }
+ public OperatingSystem OS { get; set; }
+
/// <summary>
/// The preferred address of the first byte of image when loaded into memory;
/// must be a multiple of 64K.
@@ -127,11 +142,20 @@ namespace R2RDump
throw new BadImageFormatException("The file is not a ReadyToRun image");
}
- Machine = PEReader.PEHeaders.CoffHeader.Machine;
- if (!Machine.IsDefined(typeof(Machine), Machine))
+ uint machine = (uint)PEReader.PEHeaders.CoffHeader.Machine;
+ OS = OperatingSystem.Unknown;
+ foreach(OperatingSystem os in Enum.GetValues(typeof(OperatingSystem)))
+ {
+ Machine = (Machine)(machine ^ (uint)os);
+ if (Enum.IsDefined(typeof(Machine), Machine))
+ {
+ OS = os;
+ break;
+ }
+ }
+ if (OS == OperatingSystem.Unknown)
{
- R2RDump.WriteWarning($"Invalid Machine: {Machine}");
- Machine = Machine.Amd64;
+ throw new BadImageFormatException($"Invalid Machine: {machine}");
}
ImageBase = PEReader.PEHeaders.PEHeader.ImageBase;
diff --git a/src/tools/r2rdump/TextDumper.cs b/src/tools/r2rdump/TextDumper.cs
index 1406fd2ac1..e7b249e331 100644
--- a/src/tools/r2rdump/TextDumper.cs
+++ b/src/tools/r2rdump/TextDumper.cs
@@ -26,6 +26,7 @@ namespace R2RDump
internal override void Begin()
{
_writer.WriteLine($"Filename: {_r2r.Filename}");
+ _writer.WriteLine($"OS: {_r2r.OS}");
_writer.WriteLine($"Machine: {_r2r.Machine}");
_writer.WriteLine($"ImageBase: 0x{_r2r.ImageBase:X8}");
SkipLine();