首页
社区
课程
招聘
内核编程中 C的基本语法问题
发表于: 2014-10-29 21:49 14343

内核编程中 C的基本语法问题

2014-10-29 21:49
14343
鄙人基础太差
学习内核时候 看前人的代码
(ULONG)pCurrentEprocess = (ULONG)pListActiveProcess->Flink;
(ULONG)pCurrentEprocess = (ULONG)pCurrentEprocess ->g_Offset_Eprocess_Flink;  

其中上面两句编译错误
1>driver.cpp(453): error C2106: “=”: 左操作数必须为左值
1>driver.cpp(454): error C2106: “=”: 左操作数必须为左值

难道代码有问题?

NTSTATUS
LookupProcessByName(
  IN PCHAR pcProcessName,
  OUT PEPROCESS *pEprocess
  )
{ 
  NTSTATUS  status;
  ULONG    uCurrentProcessId = 0;
  ULONG    uStartProcessId = 0; 
  ULONG    uCount = 0;
  ULONG    uLength = 0;
  PLIST_ENTRY  pListActiveProcess;
  PEPROCESS  pCurrentEprocess = NULL;

  
  if (!ARGUMENT_PRESENT(pcProcessName) || !ARGUMENT_PRESENT(pEprocess))
  {
    return STATUS_INVALID_PARAMETER;
  }

  uLength = strlen(pcProcessName);

  pCurrentEprocess = g_pEprocess_System;

  uStartProcessId = *((PULONG)((ULONG)pCurrentEprocess + g_Offset_Eprocess_ProcessId));

  uCurrentProcessId = uStartProcessId;

  while(1)
  {
    if(_strnicmp(pcProcessName, (PVOID)((ULONG)pCurrentEprocess + g_Offset_Eprocess_Name), uLength) == 0)
    {
      *pEprocess = pCurrentEprocess;
      status = STATUS_SUCCESS;
      break;
    }
    else if ((uCount >= 1) && (uStartProcessId == uCurrentProcessId))
    {
      *pEprocess = 0x00000000;
      status = STATUS_NOT_FOUND;
      break;
    }
    else 
    {
      pListActiveProcess = (LIST_ENTRY *)((ULONG)pCurrentEprocess + g_Offset_Eprocess_Flink);
      (ULONG)pCurrentEprocess = (ULONG)pListActiveProcess->Flink;
      //这句左值错误
     (ULONG)pCurrentEprocess = (ULONG)pCurrentEprocess - g_Offset_Eprocess_Flink;  //这句左值错误
      uCurrentProcessId = *(PULONG)((ULONG)pCurrentEprocess + g_Offset_Eprocess_ProcessId);
      uCount++;
    }
  }
  return status;
}




[课程]Linux pwn 探索篇!

收藏
免费 0
支持
分享
最新回复 (7)
雪    币: 185
活跃值: (25)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
(ULONG)pCurrentEprocess  明显要换成 ULONG   pCurrentEprocess 啊。
2014-10-29 22:03
0
雪    币: 645
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
(ULONG)pCurrentEprocess = (ULONG)pListActiveProcess->Flink;
这代码 语法就存在问题  强制转换 产生临时变量 不能为左值 这段代码 论坛以前的帖子好多都有这句代码
2014-10-29 22:09
0
雪    币: 21
活跃值: (244)
能力值: ( LV9,RANK:330 )
在线值:
发帖
回帖
粉丝
4
这样写呢。。
pCurrentEprocess =(PEPROCESS)((ULONG)pCurrentEprocess - g_Offset_Eprocess_Flink);
2014-10-29 22:46
0
雪    币: 645
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
回楼上的朋友 这样写法 语法正确的  我只是不明白  我上面贴的那个代码 论坛里以前的好多帖子都有这种写法 证明应该是编译能通过的 但是在语法上来说是不行的 VS报错 我编译的是cpp 不是C文件
2014-10-29 23:39
0
雪    币: 11
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
强制转换后表达式会有返回操作,而作为左值是不能对其操作的。C语法
2014-10-29 23:54
0
雪    币: 267
活跃值: (438)
能力值: ( LV9,RANK:190 )
在线值:
发帖
回帖
粉丝
7
这种编写代码的习惯只限制在win 32,换到64以后你就知道头大。
2014-10-30 07:50
0
雪    币: 459
活跃值: (344)
能力值: ( LV8,RANK:120 )
在线值:
发帖
回帖
粉丝
8
看着语法错误
2014-10-30 08:32
0
游客
登录 | 注册 方可回帖
返回
//