How could I access the memory of a running program? [closed] - c

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Presuming I have a program in C:
#include<stdio.h>
#include<time.h>
int main()
{
int a = rand() % 1000;
return 0;
}
How can I find the value of "a" without printing it on the console, but by accessing, with a linux terminal command, its address to read the value from it?
Or generally, how can I map all the written values of a binary without seeing its implementation (like a "blackbox")?

Memory is accessible via /proc/pid/mem, index is /proc/pid/maps, Python prototype is how-do-i-read-from-proc-pid-mem-under-linux.

Related

How to store value of a variable in c after closing [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am doing a project on railway reservation system, my program is working fine, but when I close the program and then again start booking tickets,seat no again takes the previous value, I'm doing the project in c.
You'll need to write all of the data to a file before the program closes, and then read the data from the file when the program starts again.
That's right.

Error in C program, using VS2017 for the first time [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I getting code 0 error while compiling very simple code. How do I solve it?
I using VS 2017 for the first time.
#include <stdio.h>
void main()
{
printf("My name is Haim");
}
The two rows in the middle are not supposed to be there!
Haim
Your main() should return some exit code. So int should be as the return type.
In the other hand exit code 0 means, that everything was succesfull, see.

How to calculate running time in C language [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
The following function is not compiling:
double GetCurTime()
{
LARGE_INTEGER CounterFreq;
QueryPerformanceFrequency(&CounterFreq);
LARGE_INTEGER Counter;
QueryPerformanceCounter(&Counter);
return (double)Counter.QuadPart / (double)CounterFreq.QuadPart;
}
The C the compiler I am using does not recognize LARGE_INTEGER and QueryPerformanceFrequency.
If anyone recognizes these items, can you please suggest where I might find them?
Perhaps they are in a header file, or a library that I do not currently have.
Include the <time.h> library and use the time_t time(time_t *timer); function.
Also, if you want to use QueryPerformanceCounter, then you need to include Winbase.h (and Windows.h).

Main function in C [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am not sure how will this program behave?
I ran this code but I am not able to figure out any reasoning behind the way it works
int main()
{
return main();
}
main() is a function by itself. The line return main() calls the function again. So in effect it should run an infinite loop. You wouldn't get any output (you said you ran it. didn't it crash?).
In reality it would be like staring into a mirror with another mirror placed behind you. You would only see endless reflections. . :)

What does this piece of c code do? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I came across this piece of code, but am not able to entirely make sense of it:
(((x)[y] << 8) | (x)[(y)+1])
where x is a pointer to a const unsigned char and y is an integer.
It extracts the 16-bit big-endian value starting at index y from array x.

Resources