-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* parent 3a2493f author Eddy Nakamura <ednakamu@microsoft.com> 1621901759 -0300 committer Eddy Nakamura <ednakamu@microsoft.com> 1624275129 -0300 Loading Pdb if not found More improvements Revert "More improvements" This reverts commit 13893c8. More improvements Fixing nullReference exception Refactoring pdb reader Fixing build Improving BA4001 for managed libraries Renaming variables, fixing pdb bug Using interpolation Changing to .NET Compiler and updating summary * Updating pdb reader logic * Updating to x64 debug/release mode; adding tests * Updating to use x64 * Updating scripts * Improving build pipeline * Updating nuspec and scripts * Update ado-build.yml for Azure Pipelines * Update ado-build.yml for Azure Pipelines * Update ado-build.yml for Azure Pipelines * Update ado-build.yml for Azure Pipelines * Update ado-build.yml for Azure Pipelines * Update ado-build.yml for Azure Pipelines * Update ado-build.yml for Azure Pipelines * Update ado-build.yml for Azure Pipelines * Updating script * Updating yml * Updating to run on windows only * Updating sh script * commenting tests for now
- Loading branch information
Showing
25 changed files
with
1,414 additions
and
1,377 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,130 +1,133 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
using Microsoft.CodeAnalysis.BinaryParsers.PortableExecutable; | ||
using Microsoft.CodeAnalysis.BinaryParsers.ProgramDatabase; | ||
using Microsoft.CodeAnalysis.Sarif.Driver; | ||
|
||
namespace Microsoft.CodeAnalysis.IL | ||
{ | ||
internal class DumpCommand : DriverCommand<DumpOptions> | ||
{ | ||
public override int Run(DumpOptions dumpOptions) | ||
{ | ||
var targets = new List<string>(); | ||
|
||
foreach (string specifier in dumpOptions.BinaryFileSpecifiers) | ||
{ | ||
if (Directory.Exists(specifier)) | ||
{ | ||
var fileSpecifier = new FileSpecifier(specifier + ".dll", recurse: dumpOptions.Recurse); | ||
targets.AddRange(fileSpecifier.Files); | ||
|
||
fileSpecifier = new FileSpecifier(specifier + ".exe", recurse: dumpOptions.Recurse); | ||
targets.AddRange(fileSpecifier.Files); | ||
} | ||
else | ||
{ | ||
var fileSpecifier = new FileSpecifier(specifier, recurse: dumpOptions.Recurse); | ||
targets.AddRange(fileSpecifier.Files); | ||
} | ||
} | ||
|
||
var dumpTask = Task.Run(() => Parallel.ForEach(targets, (target) => this.DumpFile(target, dumpOptions.Verbose))); | ||
dumpTask.Wait(); | ||
|
||
return 0; | ||
} | ||
|
||
private const string Indent = "\t"; | ||
private const string Delimiter = ", "; | ||
|
||
private void DumpFile(string target, bool verbose) | ||
{ | ||
PE pe; | ||
var sb = new StringBuilder(); | ||
try | ||
{ | ||
pe = new PE(target); | ||
} | ||
catch (UnauthorizedAccessException) | ||
{ | ||
Console.WriteLine(Path.GetFileName(target) + ": Unauthorized access exception"); | ||
return; | ||
} | ||
|
||
sb.AppendLine(Path.GetFileName(pe.FileName) + ":"); | ||
|
||
if (verbose) | ||
{ | ||
sb.AppendLine(Indent + "Path: " + pe.FileName); | ||
} | ||
|
||
sb.Append(Indent + "Attr: "); | ||
|
||
if (!pe.IsPEFile) | ||
{ | ||
sb.AppendLine("Not a portable executable"); | ||
sb.AppendLine(); | ||
return; | ||
} | ||
|
||
string language = pe.IsManaged ? "Pure Managed" : "Native"; | ||
if (pe.IsManaged && !pe.IsILOnly) { language = "Mixed Managed"; } | ||
sb.Append(language); | ||
|
||
string machine = pe.Machine.ToString(); | ||
sb.Append(Delimiter + machine); | ||
|
||
string subsystem = pe.Subsystem.ToString(); | ||
sb.Append(Delimiter + subsystem); | ||
|
||
if (pe.IsKernelMode) | ||
{ | ||
sb.Append(Delimiter + "Kernel Mode"); | ||
} | ||
|
||
if (pe.IsResourceOnly) | ||
{ | ||
sb.Append(Delimiter + "Resource Only"); | ||
} | ||
|
||
sb.Append(Delimiter + "Link " + pe.LinkerVersion.ToString()); | ||
|
||
sb.AppendLine(); // Close comma-separated attributes line | ||
|
||
sb.Append(Indent + "Pdb : "); | ||
Pdb pdb = null; | ||
try | ||
{ | ||
pdb = new Pdb(pe.FileName); | ||
} | ||
catch (PdbException pdbParseException) | ||
{ | ||
sb.AppendLine(pdbParseException.ExceptionDisplayMessage); | ||
} | ||
|
||
if (pdb != null) | ||
{ | ||
if (verbose) | ||
{ | ||
sb.AppendLine(pdb.PdbLocation); | ||
} | ||
else | ||
{ | ||
sb.AppendLine(Path.GetFileName(pdb.PdbLocation)); | ||
} | ||
} | ||
|
||
sb.AppendLine(Indent + "SHA1: " + pe.SHA1Hash); | ||
|
||
Console.Out.WriteLineAsync(sb.ToString()); | ||
} | ||
} | ||
} | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
using Microsoft.CodeAnalysis.BinaryParsers.PortableExecutable; | ||
using Microsoft.CodeAnalysis.BinaryParsers.ProgramDatabase; | ||
using Microsoft.CodeAnalysis.Sarif.Driver; | ||
|
||
namespace Microsoft.CodeAnalysis.IL | ||
{ | ||
internal class DumpCommand : DriverCommand<DumpOptions> | ||
{ | ||
public override int Run(DumpOptions dumpOptions) | ||
{ | ||
var targets = new List<string>(); | ||
|
||
foreach (string specifier in dumpOptions.BinaryFileSpecifiers) | ||
{ | ||
if (Directory.Exists(specifier)) | ||
{ | ||
var fileSpecifier = new FileSpecifier(specifier + ".dll", recurse: dumpOptions.Recurse); | ||
targets.AddRange(fileSpecifier.Files); | ||
|
||
fileSpecifier = new FileSpecifier(specifier + ".exe", recurse: dumpOptions.Recurse); | ||
targets.AddRange(fileSpecifier.Files); | ||
} | ||
else | ||
{ | ||
var fileSpecifier = new FileSpecifier(specifier, recurse: dumpOptions.Recurse); | ||
targets.AddRange(fileSpecifier.Files); | ||
} | ||
} | ||
|
||
var dumpTask = Task.Run(() => Parallel.ForEach(targets, (target) => this.DumpFile(target, dumpOptions.Verbose))); | ||
dumpTask.Wait(); | ||
|
||
return 0; | ||
} | ||
|
||
private const string Indent = "\t"; | ||
private const string Delimiter = ", "; | ||
|
||
private void DumpFile(string target, bool verbose) | ||
{ | ||
PE pe; | ||
var sb = new StringBuilder(); | ||
try | ||
{ | ||
pe = new PE(target); | ||
} | ||
catch (UnauthorizedAccessException) | ||
{ | ||
Console.WriteLine(Path.GetFileName(target) + ": Unauthorized access exception"); | ||
return; | ||
} | ||
|
||
sb.AppendLine(Path.GetFileName(pe.FileName) + ":"); | ||
|
||
if (verbose) | ||
{ | ||
sb.AppendLine(Indent + "Path: " + pe.FileName); | ||
} | ||
|
||
sb.Append(Indent + "Attr: "); | ||
|
||
if (!pe.IsPEFile) | ||
{ | ||
sb.AppendLine("Not a portable executable"); | ||
sb.AppendLine(); | ||
return; | ||
} | ||
|
||
string language = pe.IsManaged ? "Pure Managed" : "Native"; | ||
if (pe.IsManaged && !pe.IsILOnly) { language = "Mixed Managed"; } | ||
sb.Append(language); | ||
|
||
string machine = pe.Machine.ToString(); | ||
sb.Append(Delimiter + machine); | ||
|
||
string subsystem = pe.Subsystem.ToString(); | ||
sb.Append(Delimiter + subsystem); | ||
|
||
if (pe.IsKernelMode) | ||
{ | ||
sb.Append(Delimiter + "Kernel Mode"); | ||
} | ||
|
||
if (pe.IsResourceOnly) | ||
{ | ||
sb.Append(Delimiter + "Resource Only"); | ||
} | ||
|
||
sb.Append(Delimiter + "Link " + pe.LinkerVersion.ToString()); | ||
|
||
sb.AppendLine(); // Close comma-separated attributes line | ||
|
||
sb.Append(Indent + "Pdb : "); | ||
Pdb pdb = null; | ||
try | ||
{ | ||
string extension = Path.GetExtension(pe.FileName); | ||
pdb = extension.Equals(".pdb", StringComparison.OrdinalIgnoreCase) | ||
? new Pdb(pe.FileName, false) | ||
: new Pdb(pe.FileName, null, null, false); | ||
} | ||
catch (PdbException pdbParseException) | ||
{ | ||
sb.AppendLine(pdbParseException.ExceptionDisplayMessage); | ||
} | ||
|
||
if (pdb != null) | ||
{ | ||
if (verbose) | ||
{ | ||
sb.AppendLine(pdb.PdbLocation); | ||
} | ||
else | ||
{ | ||
sb.AppendLine(Path.GetFileName(pdb.PdbLocation)); | ||
} | ||
} | ||
|
||
sb.AppendLine(Indent + "SHA1: " + pe.SHA1Hash); | ||
|
||
Console.Out.WriteLineAsync(sb.ToString()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.