I have some memory address and I need to know,Is it possible to get the data stored in this address by using python language?If so?how is it?I need the code that can do this.Thank you in advance.
Your question is too general, but if I understand you correctly , the answer is: you can't. That is assuming you want to read an arbitrary memory address and not some specific data within your program's data scope.
Not getting into too much detail, arbitrary reads can usually only be performed by the system kernel and not by userspace processes.
what addresses do you have? physical or logical addresses?
You can read them in asm language. you can write a smal code and run it in debug environment in your PC and run debug from your python code using os.system()... and redirect output to a file. However, you cannot read any memory address. Some addresses are prohibited from your OS
I am using VirtualAlloc API to allocate memory then I fill it with data but I need some python code to get the data that are stored in that base address.I think that kind of data is virtual address.but I want to now ,can I get that data?If so,how?
I think if I can get data from that address,I can get any data that are stored in any address unless it was prohibited by OS.
VirtualAlloc should be c++,it and python program running in a different process, you need to have a relatively absolute address of the data you want it.
You didn't say what OS you are using, so I'm guessing its Windows. I'm not an expert on windows memory management, as I primarily use other OSes, but if they use typical techniques, here is how to approach the issue.
As the name of the function says (VirtualAlloc), it allocates a memory in Virtual address space. You don't know the mapping of the virtual space to the physical memory (only the OS/kernel knows this). Also, for security reasons virtual spaces allocated to different programs should not overlap. Therefore this way (direct memory access) is a no go.
The reasonable approach for the programs to exchange data via memory is to use "SharedMemory" technique (Windows/MSDN link below):
Python can also create/access shared memory, but I doubt you can directly utilize the C++ reference. You can however use a C wrapper for Python.
On the other hand, if you just need to have an IPC, maybe using a local socket or file for data exchange would be better idea? It might be easier to implement.