注册 登录
编程论坛 C++教室

取内存中字符串长度的问题

sunstarmail 发布于 2011-03-18 21:27, 1200 次点击
DWORK MemAddrtemp=0x12345678;
//MemAddrtemp 存放字符串一级指针
ReadProcessMemory(processH,(LPCVOID)MemAddrtemp,&MemAddrtemp,4,&byread);
//用ReadProcessMemory 读取到字符串变量首地址,再次存入MemAddrtemp

之后要怎么才能取得MemAddrtemp指向的字符串长度?
9 回复
#2
hahayezhe2011-03-18 21:36
确定C风格么?
_tcslen((char*)MemAddrtemp);
#3
sunstarmail2011-03-18 21:51
能通过编译但运行后,直接内存错误,是什么问题呢
#4
hahayezhe2011-03-18 21:52
0x12345678 该地址是什么?
你确定是个字符串的首地址 末尾用\0结束
你确定指向的内存是可读的?!
#5
sunstarmail2011-03-18 21:58

    DWORD MemAddrtemp=0x12345678,byread;
    char gamename[]="同在一天空下吧";
    ReadProcessMemory(processH,(LPCVOID)MemAddrtemp,&MemAddrtemp,4,&byread);
    ReadProcessMemory(processH,(LPCVOID)MemAddrtemp,&MemAddrtemp,4,&byread);
    MemAddrtemp+=0x24;
    ReadProcessMemory(processH,(LPCVOID)MemAddrtemp,&MemAddrtemp,4,&byread);
   
    _tcslen((char*)MemAddrtemp)
地址应该没错,不加字符长度判断能写入.

[ 本帖最后由 sunstarmail 于 2011-3-18 23:25 编辑 ]
#6
hahayezhe2011-03-18 22:01
你是从别的进程中读数据!
你确定那个进程的变量是全局的?
你确定每次启动时地址都不变?!
#7
hahayezhe2011-03-18 22:05
还有你以为你MemAddrtemp的地址是别的进程的 就能访问了 ?
你调用MemAddrtemp时里面的数据一定是指向本地的!
你要讲对方的那段数据内存拷过来才行
(_tcslen((char*)MemAddrtemp)里的MemAddrtemp指向本进程 并不是你读的那个进程!
#8
sunstarmail2011-03-18 22:09
0x0061B034是基地址,经过几次指针,MemAddrtemp储存的地址最后和远程程序字符串首地址对应,字符串后是00结尾
#9
sunstarmail2011-03-18 22:13
以下是引用hahayezhe在2011-3-18 22:05:37的发言:

还有你以为你MemAddrtemp的地址是别的进程的 就能访问了 ?
你调用MemAddrtemp时里面的数据一定是指向本地的!
你要讲对方的那段数据内存拷过来才行
(_tcslen((char*)MemAddrtemp)里的MemAddrtemp指向本进程 并不是你读的那个进程!
有办法能读取远程进程吗?
#10
sunstarmail2011-03-18 23:23
谢谢,明白.刚才晕头了
1