我们如何访问内存地址 [英] How we access memory address

查看:112
本文介绍了我们如何访问内存地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何使用c ++访问windows的任何内存地址。



我真实而简单的问题是,我们如何使用c ++在窗口中更改内容



例如:我们如何使用c ++语言改变计算机时间。



请告诉我这个。

How we access any memory address of windows using c++.

my real and simple question is that, how we change something in the window using c++

Exmaple: how we change computer time using c++ language.

Please tell me about this .

推荐答案

无法直接在现代操作系统中处理或读取或写入计算机的物理内存。这在20 - 30年前就已经存在,但从那时起,引入了内存管理器,将物理地址映射到虚拟地址。这就是为什么你可以运行10个应用程序,每个应用程序在一个只有2 GB内存的系统上分配1GB内存!



因此你需要的是完全不同的方法。操作系统为许多库提供了可以访问所有类型信息的功能。例如,您可以使用 C时间库查询当前时间[ ^ ]。也可以设置系统时间,但这取决于操作系统使用的功能。例如。对于Windows,您可以使用 SetSystemTime() [ ^ ]



更一般地说,无论你想在系统中查询或更改什么,只需google for it,你会发现很多引用系统库和函数,通常有关于如何使用它们的示例代码。
The physical memory of a computer cannot be directly adressed or read or written in a modern OS. This used to be possible some 20-30 years ago, but since then memory managers were introduced, which map the physical addresses to virtual addresses. That is why you can run 10 applications that each allocate 1GB of memory on a system that only has 2 GB of memory available!

What you have in mind therefore requires an entirely different approach. The operating system offers many libraries with functions that give you access to all kind of information. For instance you can query the current time using the C Time library[^]. Setting the system time is also possible, but it depends on the OS what function to use. E.g. for Windows you can use SetSystemTime()[^]

More generally, whatever you wish to query or change in the system, just google for it, and you will find a multitude of references to system libraries and functions, often with example code on how to use them.


如果使用& SomeFunctionName,则获取其地址。然后你可以读取那些内容(你将读取该地址代码的字节)。

不幸的是,通过内存保护你不能简单地写在那里,但这是故意的。 br $> b $ b

但你真的想问什么?我认为只是读取给定内存地址中的字节不是你想要做的。那么,你真正想要的是什么?



如果你想读任何地址,就足以用某些东西填充指针(例如char *)比如0xAA00120或你认为合适的任何东西。

Ex:

If you use &SomeFunctionName you get its address. You can then read that content (you will be reading the bytes of the code that's at that address).
Unfortunately, by the memory protection you can't simply write there, but that's on purpose.

But what do you really want to ask? I think that simply reading the bytes inside a given memory address is not what you want to do. So, what do you really want?

If you want to read "any address", it is enough to fill a pointer (char *, for example) with something like 0xAA00120 or anything you see fit.
Ex:
char *address = (char *)0xAA00120
char c = address[0]; // this reads the address 0xAA00120... 
// it will probably cause an exception if this is not a valid address, though.


这篇关于我们如何访问内存地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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