gpt4 book ai didi

c - 有趣的内存钩中的符号

转载 作者:太空宇宙 更新时间:2023-11-04 05:28:36 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
What is the use of ## preprocessor in C

来自 Fun with Google TTS ...任何人都可以阐明这段代码是如何工作的?特别是 - “c##_”是什么符号? -

#define DsHook(a,b,c) if (!c##_) { 
INT_PTR* p=b+*(INT_PTR**)a; VirtualProtect(&c##_,4,PAGE_EXECUTE_READWRITE,&no);
*(INT_PTR*)&c##_=*p; VirtualProtect(p,4,PAGE_EXECUTE_READWRITE,&no); *p=(INT_PTR)c;

它在代码中展开为 -

//  redirect  7th member func of IAsyncReader (SyncReadAlligned) to grab mp3 data from output pin of source filter
DsHook(reader,6,SyncReadAlligned);

我想,这不是很安全的玩内存方式,但作者评论为“不重要”:

Unimportant code like hook is folded in snippet form but feel free to unfold and format the code in the way you like.

附言如果 Google 已阻止“Fun with Google”本身(如果有人有兴趣测试)。

更新:我认为,简短的分析是——为了“重定向 IAsyncReader (SyncReadAlligned) 的第 7 个成员函数以从源过滤器的输出引脚获取 mp3 数据”,我们将提交页面的某些区域的内存保护从“无论它是什么”更改为 PAGE_EXECUTE_READWRITE(允许完全访问)。

关于安全 MSDN 说 -

It is best to avoid using VirtualProtect to change page protections on memory blocks allocated by GlobalAlloc, HeapAlloc, or LocalAlloc, because multiple memory blocks can exist on a single page. ... When protecting a region that will be executable, the calling program bears responsibility for ensuring cache coherency...

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com