吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1415|回复: 15
收起左侧

[已解决] 各位老师,C++读取内存字符串数据出错?

[复制链接]
jtwc 发表于 2022-5-27 19:06
本帖最后由 jtwc 于 2022-5-27 19:18 编辑

各位老师,C++读取内存字符串数据出错?如何改呢?谢谢了
代码如下:
char dwsunshineAddressValue = 0;
if (FALSE == ReadProcessMemory(hProcess, (void*)0x11D17D61, &dwsunshineAddressValue, sizeof(char), NULL))

                {
                        //printf("读取静态地址.\n");

                }
char a[] = { dwsunshineAddressValue };
printf(“%s\n", a);
1.png
2.png

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

unmask 发表于 2022-5-27 19:20
本帖最后由 unmask 于 2022-5-27 19:22 编辑

你只声明了一位char,并且也只读取了一位char,所以请打印char:printf(“%c\n", a),打印string会出现越界乱码现象。
或者读取6位字符:ReadProcessMemory(hProcess, (void*)0x11D17D61, &dwsunshineAddressValue, 6, NULL),可是可能会内存越界,因为你的栈目前只有一位char是合法的。
 楼主| jtwc 发表于 2022-5-27 19:22
unmask 发表于 2022-5-27 19:20
你只声明了一位char,并且也只读取了一位char,所以请打印char:printf(“%c\n", a),打印string会出现越界 ...

老师,也出错,谢谢了
2.png
unmask 发表于 2022-5-27 19:37
sam喵喵 发表于 2022-5-27 19:39
把char a[]改成char* a试试
 楼主| jtwc 发表于 2022-5-27 19:41
unmask 发表于 2022-5-27 19:37
printf(“%c\n", a[0])

老师,这样只能输出1位,要输出整个字符串,谢谢了
 楼主| jtwc 发表于 2022-5-27 19:44
sam喵喵 发表于 2022-5-27 19:39
把char a[]改成char* a试试

老师,试过了,不行,谢谢了
wangyujie96 发表于 2022-5-27 19:48
BOOL ReadProcessMemory(
  [in]  HANDLE  hProcess,
  [in]  LPCVOID lpBaseAddress,
  [out] LPVOID  lpBuffer,
  [in]  SIZE_T  nSize,
  [out] SIZE_T  *lpNumberOfBytesRead
);
Parameters
[in] hProcessA handle to the process with memory that is being read. The handle must have PROCESS_VM_READ access to the process.
[in] lpBaseAddressA pointer to the base address in the specified process from which to read. Before any data transfer occurs, the system verifies that all data in the base address and memory of the specified size is accessible for read access, and if it is not accessible the function fails.
[out] lpBufferA pointer to a buffer that receives the contents from the address space of the specified process.
[in] nSizeThe number of bytes to be read from the specified process.
[out] lpNumberOfBytesReadA pointer to a variable that receives the number of bytes transferred into the specified buffer. If lpNumberOfBytesRead is NULL, the parameter is ignored.
unmask 发表于 2022-5-27 19:49
jtwc 发表于 2022-5-27 19:41
老师,这样只能输出1位,要输出整个字符串,谢谢了

[C++] 纯文本查看 复制代码
int main(int argc, char const *argv[])
{
    char dwsunshineAddressValue[7] = {0};
    if (FALSE == ReadProcessMemory(hProcess, (void *)0x11D17D61, dwsunshineAddressValue, sizeof(dwsunshineAddressValue) - 1, NULL))
    {
        // printf("读取静态地址.\n");
    }
    printf("%s\n", dwsunshineAddressValue);
}

免费评分

参与人数 1吾爱币 +1 热心值 +1 收起 理由
jtwc + 1 + 1 我很赞同!

查看全部评分

 楼主| jtwc 发表于 2022-5-27 19:54
unmask 发表于 2022-5-27 19:49
[mw_shl_code=cpp,true]int main(int argc, char const *argv[])
{
    char dwsunshineAddressValue[7 ...

老师,非常正确,谢谢了
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止回复与主题无关非技术内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-25 23:23

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表