C扫描内存的指针 [英] C Pointers to scan memory

查看:111
本文介绍了C扫描内存的指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试扫描系统的内存.

I sm trying to scan a system's memory.

我的计划: 创建指向内存的指针, 并在每个循环中将此指针向上移动一个字节.

My plan : Create pointers to point to memory, And move this pointer up one byte each loop.

这就是我想出的:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

const char *MemAdressPointer(int n);

int main(void) {

    int i = 0;
    for(i = 0; i<100; i++)
    {
        const char* pAddr = MemAdressPointer(i+5000);
        printf("%c hexadecimal value of : 0x%p with i at : %i\n", *pAddr, pAddr, i);
    }
    getchar();
    return 0;
}

const char *MemAdressPointer(int n)
{
    void *p1 = (void*) n;

    const char* p2;
    p2 = p1;

    return p2;
}

一切,至少我所知道的,都可以.

Everything, at least that i know of, works.

它会打印出良好的内存地址.

It prints the good memory address.

但是当我打印字符(%c)时,它只是停止响应

But when i print the character (%c) it just stops responding

很奇怪,指针是字符,

不应该指向一个字节并获取该字节的二进制值

shouldn't it point to one byte and get this byte's binary value

并从中获取相应的字符.

and get the corresponding character out of it.

谢谢您能给我的帮助.

推荐答案

这不是现代操作系统的工作方式. 您不能简单地读出系统内存,因为应用程序内存是虚拟化的,并且由于安全策略,操作系统禁止直接访问.

That is not how modern operating systems work. You cannot simply read out the systems ram, because applications memory is virtualized and also the OS prohibits direct access due to security policies.

操作系统可能会提供一些API来访问其他进程的内存(假设您有权这样做).在Win32Api上,这是ReadProcessMemory.

The OS may offer some API to access other processes memory (assumed you have the rights to do). On Win32Api this is ReadProcessMemory.

可能是其他一些OS API允许直接读出系统地址空间. 您可以深入研究如何直接从物理内存中读取数据?

May be some other OS API allows the direct read out of the systems address space. You may dig into How do you read directly from physical memory?

这篇关于C扫描内存的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆