[c#]如何指定/GS,c#应用程序的选项?

发布于 2024-08-11 07:42:49 字数 384 浏览 7 评论 0原文

如您所知,/GS 是 Visual C++ 编译器或链接器选项。

  1. 我可以在 C# 编译器或链接器中指定 /GS 吗?

  2. 这些标志在 C# 应用程序中默认启用吗?

    [编辑]:更改问题内容:

    2a。是否启用了这些功能(通过 Visual C++ 中的这些编译器选项) 在 C# 应用程序中默认情况下?

  3. 有没有办法找出 .exe/.dll 文件是否是使用这些标志构建的?

    有没有办法

提前致谢。

As you know, /GS are Visual C++ Compiler or Linker Options.

  1. Can i Specify /GS in c# compiler or linker?

  2. Are these flags enabled by default in c# applications?

    [Edit]: change the question contents:

    2a. Are these features enabled (by these compiler options as in Visual C++)
    by default in c# applications?

  3. Is there a way to find out wheather a .exe/.dll file is build with these flags?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏末染殇 2024-08-18 07:42:49

C# 中不存在这些选项,因为 C# 生成托管代码,而 C++ 生成本机代码(机器语言代码)。托管代码被称为“可验证”,因为它具有比 C/C++ 更严格的检查,并且以 C++ 和本机代码无法做到的方式强制执行类型安全。 (这些检查与用 C++/CLI 编写的托管代码无关)。

这很大程度上是因为本机代码直接在硬件上运行,而托管代码在 .NET 运行时 (CLR) 内运行。

请允许我一一检查选项

  1. /analyze - 我不太熟悉这个选项,但看看 它检查的内容列表,这些错误都不可能存在,也不是托管代码中的问题。例如,第一个警告 C6031 不是问题,因为托管代码将抛出一个异常,当它不成功时,该异常不能被忽略。
  2. /GS - 托管代码(忽略不安全)不直接访问内存并且不受缓冲区溢出的影响。您将得到一个异常,而不是溢出到其他内存中。
  3. /DynamicBase - 托管代码生成称为中间语言 (IL) 的字节,并动态编译为本机代码 ( JIT)在运行时运行,因此它没有固定的地址空间来随机化。
  4. /SafeSEH - 托管代码有自己的异常机制并且不使用 SEH。

None of those options exist in C# because C# generates managed code and C++ generates native code (machine language code). Managed code is called 'verifiable' because it has much stricter checking than C/C++ and enforces type safety in ways that C++ and native code cannot. (These checks are irrelevant for managed code written in C++/CLI).

Much of this is due to the fact that that native code runs directly on the hardware and managed code runs inside the .NET run time (CLR).

Allow me to go over the options one by one

  1. /analyze - I'm not all the familiar with this option, but looking at the list of what it checks, none of those errors are possible or a problem in managed code. For example the first warning C6031 is not a problem because managed codes will throw an exception that can't be ignored when it doesn't succeed.
  2. /GS - Managed code (ignoring unsafe) doesn't directly access memory and is immune to buffer overflows. You'll get an exception rather than overflowing into other memory.
  3. /DynamicBase - Managed code produces byte called Intermediate Language (IL) and is dynamically compiled to native code (JIT) at run time, so it has no fixed address space to randomize.
  4. /SafeSEH - Managed code has it's own exception mechanism and doesn't use SEH.
梦里泪两行 2024-08-18 07:42:49

我猜您尝试进行代码审核/运行静态分析工具以确保 正在遵循安全/SDL 最佳实践。如果您继续阅读...

有一个名为 Binscope 的工具,可用于检查您的本机/C++ 二进制文件是否使用 /GS、/SafeSEH、/NXCOMPAT 和 /DYNAMICBASE 进行编译。这些是 C++ 特定选项,使攻击者更难利用缓冲区溢出。 (Binscope 还检查其他一些内容)

Binscope 在 C#/托管二进制文件中检查的唯一内容是它们是否使用强名称。与 C# 的 binscope 最接近的是 FxCop它将详细说明托管 .Net 代码中的一系列潜在问题。为了安全起见,请修复 FxCop 生成的所有安全警告,然后您就可以开始了。

/analyze 标志使 Visual Studio 对您的本机代码进行一些静态分析,并让您知道它是否发现任何可疑内容。 C#/.Net 的等效项是 FxCop 的安全部分。

I'm guessing your trying to do a code audit/run static analysis tools to ensure that security/SDL best practices are being followed. If you are keep reading...

There is a tool called Binscope that can be used to check that your native/C++ binaries are compiled with the /GS, /SafeSEH, /NXCOMPAT, and /DYNAMICBASE. These are C++ specific options that make it harder for attackers to exploit buffer overruns. (Binscope also checks for a few other things)

The only thing Binscope checks for in C#/managed binaries is if they are using strong names. The closest thing to binscope for C# is FxCop which will detail a bunch of potential issues in your managed .Net code. For security, fix any security warnings that FxCop produces and you are on your way.

The /analyze flag causes Visual Studio to do some static analysis of your native code and lets you know if it finds anything suspicious. The C#/.Net equivalent is the security part of FxCop.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文