[英]Is it possible to manually pad a struct in order to isololate the variable you want to read/write to? [closed]
For example if I have the following struct located in ah file and I need to access (read) the variable Alerted .例如,如果我在 ah 文件中有以下结构,并且我需要访问(读取)变量Alerted 。 How would I manually pad this struct so that I am able to access this variable?
我将如何手动填充这个结构,以便我能够访问这个变量?
struct _MYSTRUCT
{
struct _DISPATCHER_HEADER Header;
VOID* SListFaultAddress;
ULONGLONG QuantumTarget;
VOID* InitialStack;
VOID* volatile StackLimit;
VOID* StackBase;
ULONGLONG ThreadLock;
volatile ULONGLONG CycleTime;
ULONG CurrentRunTime;
ULONG ExpectedRunTime;
VOID* KernelStack;
struct _XSAVE_FORMAT* StateSaveArea;
struct _KSCHEDULING_GROUP* volatile SchedulingGroup;
union _KWAIT_STATUS_REGISTER WaitRegister;
volatile UCHAR Running;
UCHAR Alerted[2];
}
EDIT: I need to be able to access variables belonging to the _KTHREAD struct and I cannot find any documentation for this struct on Microsoft website.编辑:我需要能够访问属于 _KTHREAD 结构的变量,并且我在 Microsoft 网站上找不到该结构的任何文档。 Please this project of mine is just for fun not going into production code of any sort.
请我的这个项目只是为了好玩,而不是进入任何形式的生产代码。
It is not clear why you can't use object->alerted
directly, but it seems that you want to access alerted
without specifying the name of the member, in this case you can use offsetof , an example:不清楚为什么不能直接使用
object->alerted
,但似乎您想在不指定成员名称的情况下访问alerted
,在这种情况下您可以使用offsetof ,例如:
#include <stdio.h>
#include <stddef.h>
struct T
{
int a, b, c;
unsigned char alerted[2];
};
static size_t offset = offsetof(struct T, alerted);
void func(void *object)
{
printf("%c%c\n",
((unsigned char *)object + offset)[0],
((unsigned char *)object + offset)[1]
);
}
int main(void)
{
struct T t = {1, 2, 3, "ab"};
func(&t);
return 0;
}
Output: Output:
ab
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.