是否有类似 ILDASM/ILASM 的工具适用于 .net-core?
具体来说,我正在寻找能够在 Linux 上运行的工具(这也是为什么要使用 .net-core 的原因)。
ildasm和ilasm工具都是使用此存储库中的CoreCLR构建的:https://github.com/dotnet/coreclr。它们包含与Windows版本相似的功能(不包括GUI等)。
还有一些NuGet软件包也包含它们(https://www.nuget.org/packages?q=ildasm),但它们是特定于平台的,并且还需要匹配的CoreCLR版本才能使用,因此通过NuGet使用它们并不简单。在您的平台上运行这些工具最简单的方法就是从coreclr存储库中构建它们。
看起来在Linux上没有微软的本地工具能够完成这些功能,目前也没有内置于dot-net-core中。
不过,Mono可以允许对IL代码进行汇编和反汇编:
您所需要的是:
ilasm - For assembling
monodis - For disassembling
这些可以在mono-utils包中找到:
例如,在Debian 8上,我执行了以下操作:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb http://download.mono-project.com/repo/debian jessie" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
sudo apt-get update
apt-get install mono-devel mono-utils
ikdasm
比monodis
更适合反汇编。 - Vladimir Panteleev让我们使用相关的nuget包“安装”ildasm工具:
dotnet --info
# execution result
..
Runtime Environment:
OS Name: ubuntu
OS Version: 18.04
OS Platform: Linux
RID: ubuntu.18.04-x64 # <----
..
chmod +x ildasm
sudo mv ildasm /usr/share/dotnet/shared/Microsoft.NETCore.App/{version}/
ln -s /usr/share/dotnet/shared/Microsoft.NETCore.App/{version}/ildasm ildasm
./ildasm {path}/project.dll >> {path}/project.il
# install .net core runtime if required
# sudo apt-get update; \
# sudo apt-get install -y apt-transport-https && \
# sudo apt-get update && \
# sudo apt-get install -y dotnet-runtime-3.0
# find required tool
dotnet tool search ildasm
# output:
# Package ID Latest Version Authors Downloads Verified
# ---------------------------------------------------------------------------
# dotnet-ildasm 0.12.2 pjbgf 100154
# dotasm 1.0.1 DotAsm 434
# install tool
dotnet tool install -g dotnet-ildasm
将IL输出到文件:
# go to project folder
cd ../project/bin/Debug/netx.x
dotnet ildasm program.dll -o program.il