|
|
#1 |
|
Accessing RAM directly
Hi Guys,
The desire to alter RAM directly arose from the need to cheat in a commercial game Action Replay style ![]() I have printed some content to screen in ASCII by declaring a C char array, and accessing elements outside of it. By incrementing or decrementing the array index variable I think I am seeing the RAM space the program is running in. A lot of it is Human readable. I can't recognise words relating to any program running in the background (ie. the aforementioned commercial game). The program that reads the RAM crashes after a while looking in each direction of whatever memory vector where the C array was declared (bad access) Any thoughts? Is this part of the program sandboxing? |
|
|
|
0
|
|
|
#2 |
|
You are not seeing the current values of another program (or it's code). When your application starts it is allocated a certain sized slice of RAM. This is will be larger than the amount of RAM you really need right now. This RAM will almost certainly have been used by another program before you. The OS does not bother zeroing out RAM before giving it to you. So if you do not zero it out you will see old values form another program. You will crash as soon as you try and access memory outside of that allocated to you.
__________________
Sponsor me to cycle 100Km round London in the dark |
|
|
|
0
|
|
|
#3 | |
|
Quote:
iOS, like most other modern OS's, is a protected virtual memory system. Each application's address space is completely isolated from those of other applications. If your app could see old "values from another program" then that would be a serious security hole! |
||
|
|
0
|
|
|
#4 |
|
Read up on virtual memory systems and TLBs. All the addresses get changed before using them to access physical RAM locations.
|
|
|
|
0
|
|
|
#5 | |
|
Quote:
That means the page will definately be zeroes the first time you malloc it. However, free'ing memory inside your own virtual process space and allocating it again might not result in getting zero'ed out pages. It's highly OS/libc dependent. Take the following code : Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char ** argv)
{
char * a;
int i = -1;
do
{
a = malloc(sizeof(char) * 51);
a[50] = '\0';
printf("a string: %s\na pointer: %p\n", a, a);
memset(a, 'b', 50);
printf("a string: %s\na pointer: %p\n", a, a);
free(a);
i++;
} while (!i);
return EXIT_SUCCESS;
}
Code:
$ ./test a string: a pointer: 0x8ea9008 a string: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb a pointer: 0x8ea9008 a string: a pointer: 0x8ea9008 a string: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb a pointer: 0x8ea9008 Code:
$ ./test a string: a pointer: 0x7fc9c9403980 a string: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb a pointer: 0x7fc9c9403980 a string: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb a pointer: 0x7fc9c9403980 a string: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb a pointer: 0x7fc9c9403980
__________________
"What you leave behind is not what is engraved in stone monuments, but what is woven into the lives of others." -- Pericles |
||
|
|
0
|
|
|
#6 | |
|
Quote:
__________________
Regards, Duncan Champney, WareTo. Check out our latest app, Face Dancer, available for free on the App Store. |
||
|
|
0
|
|
|
#7 |
|
Old thread, but you could access your own RAM this way right?
So for example, loading one wav file, and then changing it's contents by searching for the header, maintaining it, but altering the pcm data? Or more simply, looking for the string in a UIlabel, and replacing it with a string of the same length? I don't know if this passes Analyse, or Validation for App Store, for writing an array out of bounds, but I ran it on my iPhone 4 (an ASCII RAM reader). The gain for me, is it might be a better/quicker way to deal with a bitmap image.
__________________
Mac Mini, iPhone 4S, iPhone 5, iPad 3rd Gen, iPad mini. |
|
|
|
0
|
|
|
#8 |
|
Your code shouldn't read or write outside blocks of memory that it allocated (by malloc or other APIs). Reading and writing bytes, ints, whatever inside these blocks of memory should work fine, for bitmaps for example.
Be aware that errors in pointer arithmetic are a very common cause of bugs and you should stay away from it if you can. |
|
|
|
0
|
|
|
#9 | |
|
Quote:
__________________
Regards, Duncan Champney, WareTo. Check out our latest app, Face Dancer, available for free on the App Store. |
||
|
|
0
|
|
|
#10 | |
|
Quote:
![]() One App I have working writes to a bitmap image and displays it for every frame: Code:
// make changes to the bitmap array data here
myData = [NSData dataWithBytes:(const void *)imgfile length:sizeof(char)*imgfilelength];
myImage = [UIImage imageWithData: myData];
Code:
// make changes to the bitmap data where it actually exists in memory Writing to the array out of bounds might not even get past the compiler.
__________________
Mac Mini, iPhone 4S, iPhone 5, iPad 3rd Gen, iPad mini. |
||
|
|
0
|
|
|
#11 |
|
Most of the data for an image is in the GPUs memory, which is in a completely different address space, not accessible from your app. Every pointer in your app is re-mapped by the OS and CPU TLB to point to a small limited sandbox of real memory.
|
|
|
|
0
|
|
|
#12 | |
|
Quote:
The data format is important, because some formats aren't easily or quickly writable. For example, JPEG. PNG isn't necessarily quick, either, but it's probably better than JPEG. Still, both of those are formats for external use, i.e. for files intended for storage or interchange. Neither one is an efficient in-memory bitmap representation. In general, the way to get fast images on iOS is to use a CGImageRef; don't even bother with UIImages. If you're fiddling with bitmaps by breaking into the UIImage encapsulation, then you probably haven't looked at CGImage yet. |
||
|
|
0
|
|
|
#13 | |
|
Quote:
I agree with everything you say, but if you want fast image manipulation, the best way to do it is in OpenGL, not Core Graphics at all. The underlying graphics hardware uses OpenGL, so you can work directly with the rendering engine. Sadly, there's no OpenCL exposed in iOS, so you're left using shader language, but it's possible to manipulate images and render them to the screen at 30 FPS - something that's not possible with CPU-based rendering.
__________________
Regards, Duncan Champney, WareTo. Check out our latest app, Face Dancer, available for free on the App Store. |
||
|
|
0
|
|
|
#14 |
|
Windows bitmap that exists in a c array with the header intact
so it can be emailed out. I'm modifying the c array, then using the code above to display it.
__________________
Mac Mini, iPhone 4S, iPhone 5, iPad 3rd Gen, iPad mini. |
|
|
|
0
|
|
|
#15 |
|
Creating an image (or uploading a 2D texture) is the only way to get a modified bitmap into the GPU and from there to the display.
From an iOS app's point of view, you might as well assume the GPU and its memory are on on another separate system or device. No way to access that image memory directly. It's also in an opaque and device/OS dependent internal GPU format. |
|
|
|
0
|
|
|
#16 |
|
Guess I have to stick to what I'm doing then.
I haven't bothered trying reading what's in RAM where a program has images, etc. in it because it's not the current project.
__________________
Mac Mini, iPhone 4S, iPhone 5, iPad 3rd Gen, iPad mini. |
|
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 09:00 PM.










Linear Mode
