首页 > 系统相关 >进程注入检测 —— RtlCaptureStackBackTrace 获取当前函数的调用栈函数

进程注入检测 —— RtlCaptureStackBackTrace 获取当前函数的调用栈函数

时间:2023-08-02 19:34:21浏览次数:40  
标签:调用 hash 函数 trace RtlCaptureStackBackTrace frames stack captured

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.

FramesToCapture

The number of frames to be captured.

BackTrace

An array of pointers captured from the current stack trace.

BackTraceHash

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)

  • Article
  • 10/22/2021
  • 2 minutes to read

 

The RtlCaptureStackBackTrace routine captures a stack trace by walking the stack and recording the information for each frame.

Syntax

C++Copy

 

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


标签:调用,hash,函数,trace,RtlCaptureStackBackTrace,frames,stack,captured
From: https://blog.51cto.com/u_11908275/6941862

相关文章

  • 实验七 字符串的内建函数
    实验七字符串的内建函数一、实验目的1、培养分析问题并对进行建模的能力。2、熟练运用字符串内键函数解决实际问题。二、实验内容1、将字母全部转换为大写或小写,如:”ILovePython”转化结果:“ilovepython”或者“ILOVEPYTHON”2、判断用户名是否合法,从键盘上输入一个用户......
  • 实验十一 函数基本应用
    实验十一函数基本应用一、实验目的1、培养分析问题并对进行建模的能力。2、熟练运用函数解决实际问题。二、实验内容1、定义一个getMax函数,返回三个数(从键盘输入的整数)中的最大值。比如:输入:123返回:32、编写函数,求出"+1/(1*2)-1/(2*3)+1/(3*4)-1/4*5+…)"前n项的和,函......
  • 【逆向】x64程序逆向基础——调用约定和栈使用
    【逆向】x64程序逆向基础 主要区别1.所有地址指针都是64位。2.增加和扩展新的寄存器,并兼容原32位版本的通用寄存器。3.原指令指针寄存器EIP扩展为RIP。寄存器1.64位寄存器兼容原32位寄存器。2.新增加8个XMM寄存器(XMM8-XMM15)。3.扩展原32位寄存器的64位版本,并增加8个......
  • 无涯教程-Lua - if语句函数
    if语句由布尔表达式组成,后跟一个或多个语句。ifstatement-语法Lua编程语言中的if语句的语法是-if(boolean_expression)then--[statement(s)willexecuteifthebooleanexpressionistrue--]end如果布尔表达式的输出为true,则将执行if语句中的代码块。如果......
  • 当编译器没有SetProcessDpiAwareness()这个函数时...
    #include<Shlobj.h>intsetdpi(){//定义一个函数指针类型typedefHRESULT(WINAPI*SetProcessDpiAwarenessFunc)(intvalue);//加载Shcore.dllHMODULEhModule=LoadLibrary("Shcore.dll");if(hModule==NULL){//加载失败......
  • 无涯教程-Lua - nested语句函数
    Lua编程语言允许在另一个循环中使用一个循环。以下部分显示了一些示例来说明这一概念。nestedloops-语法Lua中嵌套for循环语句的语法如下-forinit,max/minvalue,incrementdoforinit,max/minvalue,incrementdostatement(s)endstatement(s)en......
  • 无涯教程-Lua - repeat...until 语句函数
    与for和while循环(它们在循环顶部测试循环条件)不同,Lua编程中的repeat...until循环语言在循环的底部检查其条件。repeat...until循环与while循环相似,不同之处在于,保证do...while循环至少执行一次。repeat...untilloop-语法Lua编程语言中repeat...until循......
  • Winform两个项目间的调用
    Winform1:staticclassProgram   {       ///<summary>       ///应用程序的主入口点。       ///</summary>       [STAThread]       staticvoidMain(string[]args)       {           Application.Ena......
  • WebApi接口的调用和传参
    publicCommon.mdlResultModel<mdlGetHistoryData>GetHistoryDataByCondition(intpDeviceId,intpPageIndex,intpPageSize,stringpStartTime,stringpEndTime)       {           Common.mdlResultModel<mdlGetHistoryData>objResult=newCommon.m......
  • CubeMX生成工程之不能进入main函数的解决方法
    问题打开CubeMX生成的工程,在编译没有问题的情况下,烧录程序,板子没反应解决过程Step1.关闭所有外设只使用GPIODO输出结果:没反应Step2.进入联调,发现不能进入main函数(如下图)解决方法按照如下设置......