memory-address

How to test if an address is readable in linux userspace app

你。 提交于 2019-11-29 09:09:48
For debugging purposes I need to test a pointer to see if it points to a valid readable page. Currently I am parsing /proc/[pid]/maps to see if the address is mapped ok, but this seems a bit long-winded. Is there a better way? Thanks. The canonical way is to use the write() system call to read from the page (writing to a dummy pipe() file descriptor). Instead of faulting, it will return -1 with errno == EFAULT if the buffer passed to write() is unreadable. 来源: https://stackoverflow.com/questions/7134590/how-to-test-if-an-address-is-readable-in-linux-userspace-app

Difference between gdb addresses and “real” addresses?

白昼怎懂夜的黑 提交于 2019-11-29 04:21:15
If I run a C/C++ program in gdb (after compiling with the -g flag) and I examine the addresses of certain variables, arguments...etc, and then I run it outside of gdb (using ./ ) will these addresses be the same as the ones I saw in gdb? If they're different are they usually similar or will they be drastically different? I ask this because I have a buffer overflow program that works perfectly in gdb (with and without breakpoints), however when I try to run it outside of gdb it doesn't work. I examine the addresses of certain variables, arguments...etc, and then I run it outside of gdb (using .

Reference as key in swift dictionary

≯℡__Kan透↙ 提交于 2019-11-29 03:45:01
Dictionary key requires Hashable conformance: class Test {} var dictionary = [Test: String]() // Type 'Test' dies not conform to protocol 'Hashable' class Test: NSObject {} var dictionary = [Test: String]() // Works How to get address of pure Swift class instance to use as hashValue ? Martin R For Swift 3 (Xcode 8 beta 6 or later), use ObjectIdentifier . class Test : Hashable { // Swift 2: var hashValue: Int { return unsafeAddressOf(self).hashValue } // Swift 3: var hashValue: Int { return ObjectIdentifier(self).hashValue } } func ==(lhs: Test, rhs: Test) -> Bool { return lhs === rhs } Then a

Find an instruction in an executable file, given its address in a running process?

别等时光非礼了梦想. 提交于 2019-11-29 02:44:59
I'm modifying an old abandonware game to have infinite lives. The Address that has the instruction dec ecx is not the same as its position in the .exe debugged. I remembered that an old friend of mine told me once that there was a formula to get the "true" address with the instruction inside the .exe. Cheat engine gives me the Memory Address. I remember that in the math formula, I needed to get the Module, in OllyDbg i get it. But i can't remember the formula. Somebody know how is that math formula? The formula it's very simple! There's another way to get the file position to permanently

L value vs R value in C

ⅰ亾dé卋堺 提交于 2019-11-29 02:32:30
I am answering a textbook question from this textbook . I am learning about pointers in C and have come across l-values and r-values. From my understanding: l-values are values that are defined after they are executed (++x) r-values are values that are not defined after they are executed (x++) It that correct? The question I wanted to answer (with my attempts): a) Which of the following C expressions are L-Values? 1. x + 2 Not a L value 2. &x Is a L value 3. *&x Is a L value 4. &x + 2 Not a L value 5. *(&x + 2) Is a L value 6. &*y Is a L value b) Is it possible for a C expression to be a L

Why is the address of this volatile variable always at 1?

可紊 提交于 2019-11-28 23:09:32
I wanted to inspect the address of my variable volatile int clock; cout << &clock; But it always says that x is at address 1. Am i doing something wrong?? iostreams will cast most pointers to void * for display - but no conversion exists for volatile pointers. As such C++ falls back to the implicit cast to bool . Cast to void* explicitly if you want to print the address: std::cout << (void*)&clock; There's an operator<< for const void* , but there's no operator<< for volatile void* , and the implicit conversion will not remove volatile (it won't remove const either). As GMan says, the cv

Pointers to elements of STL containers

时间秒杀一切 提交于 2019-11-28 20:22:06
问题 Given an STL container (you may also take boost::unordered_map and boost::multi_index_container into account) that is non-contiguous, is it guaranteed that the memory addresses of the elements inside the container never changes if no element is removed, (but new ones can be added)? e.g. class ABC { }; // //... // std::list<ABC> abclist; ABC abc; abclist.insert(abc); ABC * abc_ptr = &(*abclist.begin()); In other word will abc_ptr be pointed to abc throughout the execution, if I do not remove

Executing assembler code with python

[亡魂溺海] 提交于 2019-11-28 19:34:00
I want to execute assembly code inside a python script. Is that possible? In C programming would be like this static inline getesp(){ __asm__("mov %esp, %eax"); } But how to do that with Python? Is it possible? One way you could do this would be to write a (C) extension for Python. You can take a look at this documentation for full details of how to do that. Another way of developing C-based Python extensions would be to interface directly with an external library using the ctypes module. In any case, you'd need some C code compiled into either a library or an extension and a way to call it

What is the address of a function in a C++ program?

泪湿孤枕 提交于 2019-11-28 18:13:45
As the function is set of instruction stored in one contiguous block of memory. And address of a function (entry point) is the address of the first instruction in the function. (from my knowledge) And thus we can say that the address of function and the address of the first instruction in the function will be the same (In this case the first instruction is the initialization of a variable.). But the program below contradicts the above line. code: #include<iostream> #include<stdio.h> #include<string.h> using namespace std; char ** fun() { static char * z = (char*)"Merry Christmas :)"; return &z

print memory address of Python variable [duplicate]

自作多情 提交于 2019-11-28 17:09:12
This question already has an answer here: Accessing Object Memory Address 8 answers How do I print the memory address of a variable in Python 2.7? I know id() returns the 'id' of a variable or object, but this doesn't return the expected 0x3357e182 style I was expecting to see for a memory address. I want to do something like print &x , where x is a C++ int variable for example. How can I do this in Python? BlackVegetable id is the method you want to use: to convert it to hex: hex(id(variable_here)) For instance: x = 4 print hex(id(x)) Gave me: 0x9cf10c Which is what you want, right? (Fun fact