在 C 中选择什么作为好的标记?

发布于 2024-09-18 07:13:35 字数 141 浏览 3 评论 0原文

因此,我想知道除了常见的 0xDEADBEEF 或不太吸引人的(对于正确的代码)0x0BADA550 之外,C 中是否有一个好的标记可供选择。

你最喜欢什么? 是否有任何理由选择一个特定值或另一个值?

So, I'm wondering if there's a good marker to choose in C, apart from the common 0xDEADBEEFor the less appealing (for proper code) 0x0BADA550.

What's your favorite?
Is there any reason to choose one particular value or another?

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

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

发布评论

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

评论(6

长不大的小祸害 2024-09-25 07:13:35

维基百科有关于此主题的整个页面;它提供了很多示例和使用它们的著名软件。

无论如何,如果你正在使用 x86,你应该考虑遵循 @torak 的建议,充满 int 3 的内存救了我好几次。如果您觉得有创意,可以让它更容易识别并使用 CC90CC90,它转换为交替的 int 3nop

Wikipedia has a whole page on this subject; it provides a lot of examples and famous software in which they are used.

Anyway, if you are working on x86 you should consider following @torak's suggestion, memory filled with int 3 saved me several times. If you feel creative, you may make it more recognizable and use CC90CC90, which translates to alternated int 3 and nop.

小清晰的声音 2024-09-25 07:13:35

我能想到的唯一可能具有超过审美价值的标记是0xCCCCCCCC。如果由于某种错误而被执行,0xCC 会转换为 INT 3 指令。

这适用于 IA-32 和 x86-64。我不确定其他架构是否有等效的东西。

The only marker that I can think of that might have more than asthetic value is 0xCCCCCCCC. If, through some kind of error, it was executed 0xCC translates to an INT 3 instruction.

This will work in IA-32 and x86-64. Im not sure if there are equivalents for other architectures.

我是男神闪亮亮 2024-09-25 07:13:35

好吧,我总是选择 0x800000000x80000001 为每个新区域类型递增,以用有符号整数来触发意外值。对于无符号类型,这些值的使用会非常大,对于有符号类型来说,这些值很大程度上是负值,并且对于所做的任何减法突然变成正值(从而同时测试其他错误)。这还有另一个巧妙的副作用,即会设置各种 ALU 位,例如溢出,可以通过使用 -ftrapv 和其他编译器标志来检测。

Well I always picked 0x80000000, 0x80000001 incrementing for each new region type to tickle unexpected values with signed integers. Use of these values will be strangely large for unsigned types, largely negative for signed types, and abruptly become positive for any subtractions made (thereby testing for other bugs at the same time). This has another neat side effect, in that various ALU bits will be set such as overflow, which can be detected through use of -ftrapv and other compiler flags.

烟酒忠诚 2024-09-25 07:13:35

0xBABECAFE0xBADADD000xBADBAD000xFADEFADE

0xCAFEBABE 是我理解的魔力Java 的编号。唯一比另一个更好的是它不太可能出现在数据或未初始化的内存中。因此,请勿使用 0x00000000 或全部 F

0xBABECAFE, 0xBADADD00, 0xBADBAD00, 0xFADEFADE

0xCAFEBABE is, I understand, the magic number for Java. The only thing that makes one better than another is how unlikely it is to appear in data or uninitialized memory. So don't use 0x00000000 or all Fs.

陌路黄昏 2024-09-25 07:13:35

这取决于您想要标记的内容。例如,您是否需要区分已分配但未初始化的内存和已释放的内存?如果是这样,则两者需要不同的标记。

It depends what you're trying to mark. For example, do you need to distinguish between allocated but uninitialized memory and deallocated memory? If so, you need different markers for the two.

我早已燃尽 2024-09-25 07:13:35

每个人都有自己的偏好。如果团队中的每个人都使用不同的标记,则可以帮助确定错误的来源。如:

“DEADBEEF?哦,这一定是约翰的密码。”

Everyone has their preference. If everyone on the team uses a different marker, it can help to determine the source of an error. As in:

"DEADBEEF? Oh, this must be from John's code."

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