进程注入检测 —— RtlCaptureStackBackTrace 获取当前函数的调用栈函数
https://stackoverflow.com/questions/590160/how-to-log-stack-frames-with-windows-x64
https://cpp.hotexamples.com/examples/-/-/RtlCaptureStackBackTrace/cpp-rtlcapturestackbacktrace-function-examples.html 例子参考
平日里用VS开发工具在调时在Debug下有一个选项Call Stack快捷键是Alt+7可以看出函数调用的来龙去脉,原来有一个这样原函数存在。
RtlCaptureStackBackTrace
The RtlCaptureStackBackTrace routine captures a stack back trace by walking up the stack and recording the information for each frame.
USHORT
RtlCaptureStackBackTrace(
__in ULONG FramesToSkip,
__in ULONG FramesToCapture,
__out_ecount(FramesToCapture) PVOID *BackTrace,
__out_opt PULONG BackTraceHash
);
Parameters
FramesToSkip- The number of frames to skip from the start of the back trace.
- The number of frames to be captured.
- An array of pointers captured from the current stack trace.
-
An optional value that can be used to organize hash tables. If this parameter is NULL, no hash value is computed.
This value is calculated based on the values of the pointers returned in the BackTrace array. Two identical stack traces will generate identical hash values.
Return Value
The number of captured frames.
Comments
The RtlCaptureStackBackTrace routine captures a stack back trace by walking up the stack and recording the information for each frame.
Important This is an exported function that MUST probe the ability to take page faults.
In Windows XP and Windows Server 2003, the sum of the FramesToSkip and FramesToCapture parameters must be less than 63.
Requirements
Versions: Available in Windows XP and later versions of the Windows operating systems.
IRQL: <= DISPATCH_LEVEL
Headers: Declared in Ntifs.h. Include Ntifs.h or FltKernel.h.
Library: Contained in Ntoskrnl.lib.
官方介绍:
RtlCaptureStackBackTrace function (ntifs.h)
The RtlCaptureStackBackTrace routine captures a stack trace by walking the stack and recording the information for each frame.
Syntax
NTSYSAPI USHORT RtlCaptureStackBackTrace(
[in] ULONG FramesToSkip,
[in] ULONG FramesToCapture,
[out] PVOID *BackTrace,
[out, optional] PULONG BackTraceHash
);
Parameters
[in] FramesToSkip
Number of frames to skip from the start (current call point) of the back trace.
[in] FramesToCapture
Number of frames to be captured.
[out] BackTrace
Caller-allocated array in which pointers to the return addresses captured from the current stack trace are returned.
[out, optional] BackTraceHash
Optional value that can be used to organize hash tables. If this parameter is NULL, RtlCaptureStackBackTrace does not compute and return a hash value.
This hash value is calculated based on the values of the pointers returned in the BackTrace array. Two identical stack traces will generate identical hash values.
Return value
The number of captured frames.
Remarks
RtlCaptureStackBackTrace captures a stack trace for the caller by walking the stack (walking back in call time), and recording information for each frame. Specifically, RtlCaptureStackBackTrace returns pointers to the return addresses of each call on the stack, where the first pointer in the BackTrace array points to the return address of the most recent call, and so on.
Back trace hash values can be used to quickly determine whether two stack traces are identical or different. You can use the hash returned in BackTraceHash to compare stack traces. If you don't want to use hashes, or want to compute your own hash values, set BackTraceHash to NULL.
Requirements
Minimum supported client | Available in starting with Windows XP. |
Target Platform | Universal |
Header | ntifs.h (include Ntifs.h, FltKernel.h) |
Library | NtosKrnl.lib; OneCoreUAP.lib on Windows 10 |
DLL | NtDll.dll (user mode); NtosKrnl.exe (kernel mode) |
IRQL | <= DISPATCH_LEVEL |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
2021-06-23 GIST特征和LMGIST包的python实现(有github)——使用gist特征检测恶意文件