-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable analysis for managed binary #335
Changes from 2 commits
ce7ec85
2fb9917
2c5fab7
a11b918
d00f1a7
6dda74e
703b000
2bb08fc
53c5787
5a171d9
3c8b349
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,7 @@ private Pdb LoadPdb() | |
// We should never be required to load a PDB for a managed assembly that does | ||
// not incorporate native code, as no managed-relevant rule currently crawls | ||
// PDBs for its analysis. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delete all this eventually. :) #Closed |
||
Debug.Assert(!this.PE.IsManaged || this.PE.IsMixedMode); | ||
// Debug.Assert(!this.PE.IsManaged || this.PE.IsMixedMode); | ||
|
||
Pdb pdb = null; | ||
try | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.IO; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
using System.Threading; | ||
|
@@ -22,6 +24,11 @@ public sealed class Pdb : IDisposable, IDiaLoadCallback2 | |
private StringBuilder loadTrace; | ||
private readonly Lazy<Symbol> globalScope; | ||
private bool restrictReferenceAndOriginalPathAccess; | ||
private PdbFileType pdbFileType; | ||
private const string s_windowsPdbSignature = "Microsoft C/C++ MSF 7.00\r\n\x001ADS\x0000\x0000\x0000"; | ||
private const string s_portablePdbSignature = "BSJB"; | ||
public static readonly ImmutableArray<byte> WindowsPdbSignature = ImmutableArray.Create(Encoding.ASCII.GetBytes(s_windowsPdbSignature)); | ||
public static readonly ImmutableArray<byte> PortablePdbSignature = ImmutableArray.Create(Encoding.ASCII.GetBytes(s_portablePdbSignature)); | ||
|
||
/// <summary> | ||
/// Load debug info from PE or PDB, using symbolPath to help find symbols | ||
|
@@ -134,6 +141,46 @@ private void WindowsNativeLoadPdbUsingDia(string pePath, string symbolPath, stri | |
|
||
public bool IsStripped => this.GlobalScope.IsStripped; | ||
|
||
public PdbFileType FileType | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should cache this property value rather than computing it every time. #Resolved There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
{ | ||
get | ||
{ | ||
if (this.pdbFileType != PdbFileType.Unknown) | ||
{ | ||
return this.pdbFileType; | ||
} | ||
|
||
if (Directory.Exists(PdbLocation)) | ||
{ | ||
return PdbFileType.Unknown; | ||
} | ||
|
||
int max = Math.Max(WindowsPdbSignature.Length, PortablePdbSignature.Length); | ||
|
||
byte[] b = new byte[max]; | ||
|
||
using (FileStream fs = File.OpenRead(PdbLocation)) | ||
{ | ||
if (fs.Read(b, 0, b.Length) != b.Length) | ||
{ | ||
return this.pdbFileType; | ||
} | ||
} | ||
|
||
Span<byte> span = b.AsSpan(); | ||
|
||
if (WindowsPdbSignature.AsSpan().SequenceEqual(span.Slice(0, WindowsPdbSignature.Length))) | ||
{ | ||
this.pdbFileType = PdbFileType.Windows; | ||
} | ||
else if (PortablePdbSignature.AsSpan().SequenceEqual(span.Slice(0, PortablePdbSignature.Length))) | ||
{ | ||
this.pdbFileType = PdbFileType.Portable; | ||
} | ||
|
||
return this.pdbFileType; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Get the list of modules in this executable | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Microsoft.CodeAnalysis.BinaryParsers | ||
{ | ||
/// <summary> | ||
/// What is the format of a file. | ||
/// </summary> | ||
public enum PdbFileType | ||
{ | ||
/// <summary> | ||
/// Unknown format. | ||
/// </summary> | ||
Unknown, | ||
|
||
/// <summary> | ||
/// Windows specific format. | ||
/// </summary> | ||
Windows, | ||
|
||
/// <summary> | ||
/// Portable OS format. | ||
/// </summary> | ||
Portable, | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in other checks, the absence of a PDB results in an error level notification, not a 'not applicable' message. 'Not applicable' is not the right return value here, as this return value means 'the binary isn't a valid scan target'. that's not true here, managed code is a valid scan target, the problem is that we can't analyze it due to a missing pdb. you should go look and see how the native pdb reading errors handle a missing pdb.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you validate again? pushed new changes. Thank you
In reply to: 563214549 [](ancestors = 563214549)