HyperDbg Debugger
Loading...
Searching...
No Matches
Callstack.h File Reference

Kernel headers for callstacks. More...

Go to the source code of this file.

Functions

BOOLEAN CallstackWalkthroughStack (PDEBUGGER_SINGLE_CALLSTACK_FRAME AddressToSaveFrames, UINT64 StackBaseAddress, UINT32 Size, BOOLEAN Is32Bit)
 Walkthrough the stack.
 

Detailed Description

Kernel headers for callstacks.

Author
Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
Version
0.1
Date
2022-03-05

Function Documentation

◆ CallstackWalkthroughStack()

BOOLEAN CallstackWalkthroughStack ( PDEBUGGER_SINGLE_CALLSTACK_FRAME AddressToSaveFrames,
UINT64 StackBaseAddress,
UINT32 Size,
BOOLEAN Is32Bit )

Walkthrough the stack.

Parameters
AddressToSaveFrames
StackBaseAddress
Size
Is32Bit
Returns
BOOLEAN
29{
30 UINT32 FrameIndex = 0;
31 UINT16 AddressMode = 0;
32 UINT64 Value = (UINT64)NULL;
33 UINT64 CurrentStackAddress = (UINT64)NULL;
34
35 if (Size == 0)
36 {
37 return FALSE;
38 }
39
40 if (Is32Bit)
41 {
42 //
43 // 32-bit interpretation
44 //
45 AddressMode = sizeof(UINT32);
46 FrameIndex = Size / AddressMode;
47 }
48 else
49 {
50 //
51 // 64-bit interpretation
52 //
53 AddressMode = sizeof(UINT64);
54 FrameIndex = Size / AddressMode;
55 }
56
57 //
58 // Walkthrough the stack
59 //
60 for (size_t i = 0; i < FrameIndex; i++)
61 {
62 //
63 // Compute the current stack position address
64 //
65 CurrentStackAddress = StackBaseAddress + (i * AddressMode);
66
67 if (!CheckAccessValidityAndSafety(CurrentStackAddress, AddressMode))
68 {
69 AddressToSaveFrames[i].IsStackAddressValid = FALSE;
70
71 //
72 // Stack is no longer valid or available to access from here
73 //
74 return FALSE;
75 }
76
77 //
78 // Stack address is valid
79 //
80 AddressToSaveFrames[i].IsStackAddressValid = TRUE;
81
82 //
83 // Read the 4 or 8 byte from the target stack
84 //
85 MemoryMapperReadMemorySafeOnTargetProcess(CurrentStackAddress, &Value, AddressMode);
86
87 //
88 // Set the value
89 //
90 AddressToSaveFrames[i].Value = Value;
91
92 //
93 // This implementation has a problem, if the target jump is between two page were the second
94 // page is not available, it fails to set it as the valid address,
95 // We should check it for this page attribute (check boundary) but for now, i'm lazy enough
96 // to let it unimplemented
97 //
98 // Check if value is a valid address
99 //
101 {
102 //
103 // It's a valid address
104 //
105 AddressToSaveFrames[i].IsValidAddress = TRUE;
106
107 //
108 // Check if the target page has NX bit (executable page)
109 //
111
112 //
113 // Read the memory at the target address
114 //
116 AddressToSaveFrames[i].InstructionBytesOnRip,
118 }
119 }
120
121 //
122 // Stack walk is finished
123 //
124 return TRUE;
125}
BOOLEAN CheckAccessValidityAndSafety(UINT64 TargetAddress, UINT32 Size)
Check the safety to access the memory.
Definition AddressCheck.c:156
unsigned short UINT16
Definition BasicTypes.h:47
#define TRUE
Definition BasicTypes.h:55
#define FALSE
Definition BasicTypes.h:54
unsigned __int64 UINT64
Definition BasicTypes.h:21
unsigned int UINT32
Definition BasicTypes.h:48
#define MAXIMUM_CALL_INSTR_SIZE
maximum size for call instruction in Intel
Definition Constants.h:473
_Use_decl_annotations_ BOOLEAN MemoryMapperReadMemorySafeOnTargetProcess(UINT64 VaAddressToRead, PVOID BufferToSaveMemory, SIZE_T SizeToRead)
Read memory safely by mapping the buffer on the target process memory (It's a wrapper)
Definition MemoryMapper.c:1120
_Use_decl_annotations_ BOOLEAN MemoryMapperCheckIfPageIsNxBitSetOnTargetProcess(PVOID Va)
This function checks target process to see if the page has NX bit or not.
Definition MemoryMapper.c:475
RequestedActionOfThePacket Value(0x1) 00000000
BOOLEAN IsExecutable
Definition RequestStructures.h:764
BOOLEAN IsStackAddressValid
Definition RequestStructures.h:762
UINT64 Value
Definition RequestStructures.h:765
BOOLEAN IsValidAddress
Definition RequestStructures.h:763