memory-address

Why does Go forbid taking the address of (&) map member, yet allows (&) slice element?

瘦欲@ 提交于 2019-11-27 19:28:36
Go doesn't allow taking the address of a map member: // if I do this: p := &mm["abc"] // Syntax Error - cannot take the address of mm["abc"] The rationale is that if Go allows taking this address, when the map backstore grows or shinks, the address can become invalid, confusing the user. But Go slice gets relocated when it outgrows its capacity, yet, Go allows us to take the address of a slice element: a := make([]Test, 5) a[0] = Test{1, "dsfds"} a[1] = Test{2, "sdfd"} a[2] = Test{3, "dsf"} addr1 := reflect.ValueOf(&a[2]).Pointer() fmt.Println("Address of a[2]: ", addr1) a = append(a, Test{4,

Get memory address of member function?

馋奶兔 提交于 2019-11-27 18:33:59
How do I get the absolute address of a member function in C++? (I need this for thunking.) Member function pointers don't work because I can't convert them to absolute addresses ( void * ) -- I need to know the address of the actual function in memory, not simply the address relative to the type. There exists a syntax to get the address of the member function in MSVC (starting from MSVC 2005 IMHO). But it's pretty tricky. Moreover, the obtained pointer is impossible to cast to other pointer type by conventional means. Though there exists a way to do this nevertheless. Here's the example: //

Calling a function through its address in memory in c / c++

旧城冷巷雨未停 提交于 2019-11-27 18:10:46
Given knowledge of the prototype of a function and its address in memory, is it possible to call this function from another process or some piece of code that knows nothing but the prototype and memory address? If possible, how can a returned type be handled back in the code? On modern operating systems, each process has its own address space and addresses are only valid within a process. If you want to execute code in some other process, you either have to inject a shared library or attach your program as a debugger . Once you are in the other program's address space, this code invokes a

Difference between gdb addresses and “real” addresses?

谁说胖子不能爱 提交于 2019-11-27 18:09:27
问题 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.

Is there a symbol that represents the current address in GNU GAS assembly?

大憨熊 提交于 2019-11-27 17:36:05
问题 I am curious to know is there any special GAS syntax to achieve the same like in NASM example: SECTION .data msg: db "Hello World",10,0 ; the 0-terminated string. len: equ $-msg ; "$" means current address. Especially I'm interested in the symbol $ representing the current address. 回答1: There is a useful comparison between gas and NASM here: http://www.ibm.com/developerworks/linux/library/l-gas-nasm/index.html See in particular this part, which I think addresses your question: Listing 2 also

Is it possible to store the address of a label in a variable and use goto to jump to it?

狂风中的少年 提交于 2019-11-27 17:29:58
I know everyone hates gotos. In my code, for reasons I have considered and am comfortable with, they provide an effective solution (ie I'm not looking for "don't do that" as an answer, I understand your reservations, and understand why I am using them anyway). So far they have been fantastic, but I want to expand the functionality in such a way that requires me to essentially be able to store pointers to the labels, then go to them later. If this code worked, it would represent the type of functionality that I need. But it doesn't work, and 30 min of googling hasn't revealed anything. Does

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

爱⌒轻易说出口 提交于 2019-11-27 17:02:46
问题 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

Executing assembler code with python

不想你离开。 提交于 2019-11-27 12:18:25
问题 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? 回答1: 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

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

喜欢而已 提交于 2019-11-27 11:08:19
问题 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

print memory address of Python variable [duplicate]

那年仲夏 提交于 2019-11-27 09:55:48
问题 This question already has an answer here: Accessing Object Memory Address 9 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? 回答1: id is the method you want to use: to convert it to hex: hex(id(variable_here))