Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
254 views
in Technique[技术] by (71.8m points)

C Pointers to scan memory

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.

So this is what i came up with :

#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
", *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.

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

It is weird, the pointer, being a character,

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

and get the corresponding character out of it.

Thanks for any help you can give me.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...