Skip to content

Commit

Permalink
Fix bug on running in file export mode. +semver: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pjbgf committed Jun 2, 2017
1 parent cc466e5 commit a6cbd03
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 34 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ before_install:
- chmod +x build.sh
- chmod +x run-cross-checks.sh
- dotnet restore
- sudo apt-get install mono-utils

install:
- ./build.sh -c Release
Expand Down
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Paulo Gomes (https://pjbgf.mit-license.org/)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Linux Build](https://travis-ci.org/pjbgf/dotnet-ildasm.svg?branch=master)](https://travis-ci.org/pjbgf/dotnet-ildasm)
[![Nuget](https://img.shields.io/nuget/dt/dotnet-ildasm.svg)](http://nuget.org/packages/dotnet-ildasm)
[![Nuget](https://img.shields.io/nuget/v/dotnet-ildasm.svg)](http://nuget.org/packages/dotnet-ildasm)

[![License](http://img.shields.io/:license-mit-blue.svg)](http://pjbgf.mit-license.org)

# Install (as CLI Tool)

Expand Down
15 changes: 15 additions & 0 deletions run-cross-checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,18 @@ else
mono src/dotnet-ildasm/bin/Release/net45/dotnet-ildasm.exe src/dotnet-ildasm.Sample/bin/Release/net45/dotnet-ildasm.Sample.exe -o net45_net45.il

fi

if [[ ! -v RUN_REASSEMBLE_TESTS ]]
then

echo "Not running reassembling tests."

else

echo "Reassembling .IL's onto Portable executable files again."
ilasm netcore_netstandard16.il /dll /output:netcore_netstandard16.dll
ilasm netcore_net45.il /exe /output:netcore_net45.exe
ilasm net45_netcore.il /exe /output:net45_netcore.exe
ilasm net45_net45.il /exe /output:net45_net45.exe

fi
3 changes: 1 addition & 2 deletions src/dotnet-ildasm/MethodProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public void WriteBody(MethodDefinition method)
var ilProcessor = method.Body.GetILProcessor();
foreach (var instruction in ilProcessor.Body.Instructions)
{
//_outputWriter.WriteLine(instruction.ToString());
_instructionProcessor.WriteInstruction(instruction);
}
}
Expand All @@ -53,7 +52,7 @@ private void WriteLocalVariablesIfNeeded(MethodDefinition method)
{
if (method.Body.Variables.Count == 1)
_outputWriter.WriteLine($".locals init(class {method.Body.Variables.First().VariableType.ToILType()} V_0)");
else
else if(method.Body.Variables.Count > 1)
{
int parameterIndex = 0;
_outputWriter.WriteLine(
Expand Down
51 changes: 23 additions & 28 deletions src/dotnet-ildasm/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,49 +23,44 @@ private static int OnError()

private static int PrepareToExecute(CommandOptions options)
{
DeleteOutputFileWhenForceOutputOverwriteFlagOn(options);

var indentationProvider = new IndentationProvider();
var outputWriter = GetOutputWriter(options, indentationProvider);

Console.WriteLine();
if (File.Exists(options.OutputPath) && !options.ForceOutputOverwrite)
if (File.Exists(options.OutputPath) && !options.IsTextOutput)
{
Console.WriteLine($"Error: The file {options.OutputPath} already exists. Use --force to force it to be overwritten.");
return -1;
if (!options.ForceOutputOverwrite)
{
Console.WriteLine(
$"Error: The file {options.OutputPath} already exists. Use --force to force it to be overwritten.");
return -1;
}

File.Delete(options.OutputPath);
}

var outputWriter = GetOutputWriter(options, indentationProvider);

return ExecuteDisassembler(options, outputWriter);
}

private static int ExecuteDisassembler(CommandOptions options, IOutputWriter outputWriter)
{
using (outputWriter)
{
var assemblyDataProcessor = new AssemblyDataProcessor(options.FilePath, outputWriter);
var assemblyDefinitionResolver = new AssemblyDefinitionResolver();
var disassembler = new Disassembler(assemblyDataProcessor, assemblyDefinitionResolver);
var assemblyDataProcessor = new AssemblyDataProcessor(options.FilePath, outputWriter);
var assemblyDefinitionResolver = new AssemblyDefinitionResolver();
var disassembler = new Disassembler(assemblyDataProcessor, assemblyDefinitionResolver);

var itemFilter = new ItemFilter(options.ItemFilter);
var result = disassembler.Execute(options, itemFilter);
var itemFilter = new ItemFilter(options.ItemFilter);
var result = disassembler.Execute(options, itemFilter);
outputWriter.Dispose();

if (result.Succeeded || !options.IsTextOutput)
{
Console.WriteLine(result.Message);
return 0;
}

Console.WriteLine($"Error: {result.Message}");
return -1;
}
}

private static void DeleteOutputFileWhenForceOutputOverwriteFlagOn(CommandOptions options)
{
if (!options.IsTextOutput && options.ForceOutputOverwrite)
if (result.Succeeded || !options.IsTextOutput)
{
File.Delete(options.OutputPath);
Console.WriteLine(result.Message);
return 0;
}

Console.WriteLine($"Error: {result.Message}");
return -1;
}

private static IOutputWriter GetOutputWriter(CommandOptions options, IndentationProvider indentationProvider)
Expand Down
2 changes: 1 addition & 1 deletion src/dotnet-ildasm/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"dotnet-ildasm": {
"commandName": "Project",
"commandLineArgs": "..\\dotnet-ildasm.Sample\\bin\\Debug\\netstandard1.6\\dotnet-ildasm.Sample.dll -t -i ::PublicVoidMethodParams"
"commandLineArgs": "..\\dotnet-ildasm.Sample\\bin\\Release\\netstandard1.6\\dotnet-ildasm.Sample.dll -t -i ::UsingTryCatch"
}
}
}
4 changes: 2 additions & 2 deletions src/dotnet-ildasm/dotnet-ildasm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
<AssemblyVersion>$(GitVersion_AssemblySemVer)</AssemblyVersion>
<FileVersion>$(GitVersion_AssemblySemVer)</FileVersion>
<Description>Light-weight cross platform IL disassembler tool.</Description>
<PackageReleaseNotes>This version adds code indentation and allows files to be reassembled by MS ILASM.</PackageReleaseNotes>
<PackageReleaseNotes>This version adds code indentation and support to structs.</PackageReleaseNotes>
<PackageLicenseUrl>https://pjbgf.mit-license.org/</PackageLicenseUrl>
<PackageId>dotnet-ildasm</PackageId>
<PackageTags>dotnet-ildasm, ildasm, cil, msil, dotnet-cli</PackageTags>
<PackageTags>dotnet-ildasm, ildasm, cil, msil, dotnet-cli, disassembler, dotnet-core</PackageTags>
<Authors>pjbgf</Authors>
<PackageProjectUrl>https://github.com/pjbgf/dotnet-ildasm</PackageProjectUrl>
</PropertyGroup>
Expand Down

0 comments on commit a6cbd03

Please sign in to comment.