RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 886982
Accepted
Kir_Antipov
Kir_Antipov
Asked:2020-09-29 20:46:48 +0000 UTC2020-09-29 20:46:48 +0000 UTC 2020-09-29 20:46:48 +0000 UTC

使用通用中间语言

  • 772

最近,为了了解我每天工作的一切,用CIL编写变得非常有趣)

在这方面,出现了一个问题:是否有任何IDE用于在 pure 上开发应用程序IL,以及应该为更详细的研究准备什么(因为到目前为止,我的武器库中只有我之前读过的直觉,IL以及维基百科上带有列表说明的页面)

到目前为止,我只找到了 Visual Studio 的扩展,但它只允许您将指令集成IL到代码中C#,F#或者VB,这不是我希望看到的¯\_(ツ)_/¯

.net
  • 1 1 个回答
  • 10 Views

1 个回答

  • Voted
  1. Best Answer
    MSDN.WhiteKnight
    2020-10-04T15:53:04Z2020-10-04T15:53:04Z

    是否有任何用于开发纯 IL 应用程序的 IDE

    或者,使用自定义模板使 Visual Studio 本身成为这样的 IDE。

    一、项目模板

    让我们创建一个 C# 控制台应用程序项目,我们称之为 CilProject。

    在解决方案资源管理器中,在项目的上下文菜单中,调用“卸载项目”项。在同一个地方,对于卸载的项目,我们将调用“更改项目”项。

    在 XML 中查找节点

    <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets>
    

    并将其替换为以下代码:

      <Import Project="$(MSBuildToolsPath)\Microsoft.Common.targets" />
    
      <Target Name="CreateManifestResourceNames" />
    
      <Target Name="CoreCompile" Inputs="$(MSBuildAllProjects);@(Compile);" Outputs="@(IntermediateAssembly);">
        <GetFrameworkPath>
          <Output TaskParameter="Path" PropertyName="FrameworkPath" />
        </GetFrameworkPath>
    
        <PropertyGroup>
          <IlAsmCommand>&quot;$(FrameworkPath)\Ilasm.exe&quot; /NOLOGO /DLL /OUTPUT:&quot;@(IntermediateAssembly)&quot; </IlAsmCommand>
        </PropertyGroup>
    
        <PropertyGroup Condition=" '$(Configuration)' == 'Debug' " >
          <IlAsmCommand>$(IlAsmCommand) /DEBUG </IlAsmCommand>
        </PropertyGroup>
    
        <PropertyGroup Condition=" '$(Configuration)' == 'Release' " ><IlAsmCommand>$(IlAsmCommand) /OPTIMIZE </IlAsmCommand></PropertyGroup>
    
        <PropertyGroup Condition=" '$(AssemblyOriginatorKeyFile)' != '' " >
          <IlAsmCommand>$(IlAsmCommand) /KEY:&quot;$(AssemblyOriginatorKeyFile)&quot; </IlAsmCommand>
        </PropertyGroup>
    
        <Exec Command="$(IlAsmCommand) @(Compile->'&quot;%(FullPath)&quot;', ' ')" 
              Outputs="@(IntermediateAssembly)" />
    
        <CallTarget Targets="$(TargetsTriggeredByCompilation)" Condition="'$(TargetsTriggeredByCompilation)' != ''" />
      </Target>
    

    再次加载项目(在同一个上下文菜单中,选择“重新加载项目”项)。

    将 AssemblyInfo.cs 替换为 AssemblyInfo.il:

    .assembly CilProject { }
    

    将 Program.cs 替换为 Program.il:

    .method public static void Main() cil managed
    {
         .entrypoint
         .maxstack 1
        ldstr "Hello, world!"
        call void [mscorlib]System.Console::WriteLine(string)
        call int32 [mscorlib]System.Console::Read()
        pop
        ret
    }
    

    对于这两个 .il 文件,在properties中将Build 操作设置为Compile 。之后,项目应该构建并运行。

    在 Visual Studio 中,选择Project - Template Export - Project Template,在对话框中输入名称和描述,并选中“Automatically import into Visual Studio”复选框。结果应该是以下 CilProject.csproj 模板(适用于 VS 2017 和 .NET 4.0):

    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
      <PropertyGroup>
        <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
        <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
        <ProjectGuid>{$guid1$}</ProjectGuid>
        <OutputType>Exe</OutputType>
        <RootNamespace>$safeprojectname$</RootNamespace>
        <AssemblyName>$safeprojectname$</AssemblyName>
        <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
        <FileAlignment>512</FileAlignment>
        <Deterministic>true</Deterministic>
      </PropertyGroup>
      <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
        <PlatformTarget>AnyCPU</PlatformTarget>
        <DebugSymbols>true</DebugSymbols>
        <DebugType>full</DebugType>
        <Optimize>false</Optimize>
        <OutputPath>bin\Debug\</OutputPath>
        <DefineConstants>DEBUG;TRACE</DefineConstants>
        <ErrorReport>prompt</ErrorReport>
        <WarningLevel>4</WarningLevel>
      </PropertyGroup>
      <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
        <PlatformTarget>AnyCPU</PlatformTarget>
        <DebugType>pdbonly</DebugType>
        <Optimize>true</Optimize>
        <OutputPath>bin\Release\</OutputPath>
        <DefineConstants>TRACE</DefineConstants>
        <ErrorReport>prompt</ErrorReport>
        <WarningLevel>4</WarningLevel>
      </PropertyGroup>
      <ItemGroup>
        <Reference Include="System" />
      </ItemGroup>
      <ItemGroup>
        <Compile Include="Program.il" />
        <Compile Include="Properties\AssemblyInfo.il" />
      </ItemGroup>
      <Import Project="$(MSBuildToolsPath)\Microsoft.Common.targets" />
      <Target Name="CreateManifestResourceNames" />
      <Target Name="CoreCompile" Inputs="$(MSBuildAllProjects);@(Compile);" Outputs="@(IntermediateAssembly);">
        <GetFrameworkPath>
          <Output TaskParameter="Path" PropertyName="FrameworkPath" />
        </GetFrameworkPath>
        <PropertyGroup>
          <IlAsmCommand>"$(FrameworkPath)\Ilasm.exe" /NOLOGO /OUTPUT:"@(IntermediateAssembly)" </IlAsmCommand>
        </PropertyGroup>
        <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
          <IlAsmCommand>$(IlAsmCommand) /DEBUG </IlAsmCommand>
        </PropertyGroup>
        <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
          <IlAsmCommand>$(IlAsmCommand) /OPTIMIZE </IlAsmCommand>
        </PropertyGroup>
        <PropertyGroup Condition=" '$(AssemblyOriginatorKeyFile)' != '' ">
          <IlAsmCommand>$(IlAsmCommand) /KEY:"$(AssemblyOriginatorKeyFile)" </IlAsmCommand>
        </PropertyGroup>
        <Exec Command="$(IlAsmCommand) @(Compile->'&quot;%(FullPath)&quot;', ' ')" Outputs="@(IntermediateAssembly)" />
        <CallTarget Targets="$(TargetsTriggeredByCompilation)" Condition="'$(TargetsTriggeredByCompilation)' != ''" />
      </Target>
    </Project>
    

    模板文件将放置在(Мои документы)\Visual Studio 2017\Templates\ProjectTemplates. 之后,我们的 CilProject 就会出现在 Visual C# 类别中的项目创建窗口中。

    项目

    您已经可以编写程序(在 AssemblyInfo.il 中输入对程序集的引用,并通过“编译”程序集操作将代码添加为 .il 文件)。

    二、元素模板

    为方便起见,我们还将创建一个类模板。让我们添加 Class1.il 文件:

    .class public auto ansi beforefieldinit Class1
           extends [mscorlib]System.Object
    {
        .method public hidebysig static void Method() cil managed
        {       
            ret
        }
    } 
    

    在 Visual Studio 中,选择Project - Template Export - Element Template ,在对话框中选择Class1.il文件,勾选“Automatically import into Visual Studio”并输入其余参数。获取目录中带有模板的zip文件(Мои документы)\Visual Studio 2017\Templates\ItemTemplates,解压并打开.vstemplate文件。找到其中的节点<ProjectItem...>并将属性添加到它ItemType="Compile":

    <VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Item">
      <TemplateData>
        <DefaultName>CilClass.il</DefaultName>
        <Name>CilClass</Name>
        <Description>Class (CIL)</Description>
        <ProjectType>CSharp</ProjectType>
        <SortOrder>10</SortOrder>
        <Icon>__TemplateIcon.ico</Icon>
      </TemplateData>
      <TemplateContent>
        <References />
        <ProjectItem ItemType="Compile" SubType="" TargetFileName="$fileinputname$.il" ReplaceParameters="true">Class1.il</ProjectItem>
      </TemplateContent>
    </VSTemplate>
    

    让我们将文件打包在同一个 ZIP 存档中,并将其放在ItemTemplates目录中旧文件的位置。让我们重新启动工作室,然后在添加元素的窗口中,在“Visual C# 元素”类别中将出现我们的类模板。

    分类

    结果

    像这样的东西:

    IDE

    优点:调试工作,输出编译器错误和警告指示文件和行,您可以在调试/发布配置之间切换。

    缺点:项目属性不起作用,通过工作室界面添加链接的功能,语法突出显示,编辑期间的错误检查等等。

    输出模板文件:项目模板、元素模板。

    应该准备什么来进行更详细的研究

    IL Disassembler实用程序, System.Reflection.Emit.OpCodes类文档,规范的第三部分。

    来源

    Visual Studio 项目和项模板

    如何加载我在 Visual Studio 中创建的模板?

    是否有任何从 Visual Studio 项目中编译 CIL 代码的示例

    • 4

相关问题

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    是否可以在 C++ 中继承类 <---> 结构?

    • 2 个回答
  • Marko Smith

    这种神经网络架构适合文本分类吗?

    • 1 个回答
  • Marko Smith

    为什么分配的工作方式不同?

    • 3 个回答
  • Marko Smith

    控制台中的光标坐标

    • 1 个回答
  • Marko Smith

    如何在 C++ 中删除类的实例?

    • 4 个回答
  • Marko Smith

    点是否属于线段的问题

    • 2 个回答
  • Marko Smith

    json结构错误

    • 1 个回答
  • Marko Smith

    ServiceWorker 中的“获取”事件

    • 1 个回答
  • Marko Smith

    c ++控制台应用程序exe文件[重复]

    • 1 个回答
  • Marko Smith

    按多列从sql表中选择

    • 1 个回答
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Suvitruf - Andrei Apanasik 什么是空? 2020-08-21 01:48:09 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5