【问题标题】:Force compiler to accept an unused string?强制编译器接受未使用的字符串?
【发布时间】:2017-04-10 04:11:37
【问题描述】:

我正在制作一个要求用户反编译二进制文件的破解挑战。

我尝试包含以下内容,以阻止尝试使用字符串反转二进制文件的用户:

const string pointless = "Strings would be too easy";

不幸的是,在我的代码中没有引用它,冗余代码在编译时被删除。有没有办法告诉编译器无论如何都要包含它?

【问题讨论】:

  • 你可以无意义地引用它。
  • @RaymondChen 我同意,但我想知道是否有更好的方法!

标签: c# .net decompiler


【解决方案1】:

使用变量是将变量保留在编译代码中的唯一方法。现在接下来不要在编译代码中使用这个 using 语句。

所以最后我们有两个任务。

  • Use variable
  • 然后是not to get this using code in compiled code

而且您知道,如果您使用过,您肯定会在编译后的代码中得到它。我们将变量与Debug 类一起使用,因此只有将其编译为debug 模式才能得到,如果编译与release 模式相同的代码,则不会得到using your variable 代码。如下 -

const string pointless = "Strings would be too easy";
Debug.WriteLine(pointless);

现在因为您使用了该变量,所以它不会从编译格式中删除。现在,如果您将代码编译为debug,您将得到Debug.WriteLine(pointless);

但是现在将您的代码编译为release 模式,您将获得您的变量,但不是这个Debug.WriteLine(pointless);

希望对你有帮助。!!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-18
    • 2010-11-11
    相关资源
    最近更新 更多