Click here to Skip to main content
15,911,762 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Need help constructing B+ tree PinPopular
David Crow3-Nov-09 4:00
David Crow3-Nov-09 4:00 
QuestionConverting unsigned short int to its hex representation Pin
yeah10003-Nov-09 1:58
yeah10003-Nov-09 1:58 
AnswerRe: Converting unsigned short int to its hex representation Pin
Richard MacCutchan3-Nov-09 2:06
mveRichard MacCutchan3-Nov-09 2:06 
AnswerRe: Converting unsigned short int to its hex representation [fixed: thanks to David] Pin
CPallini3-Nov-09 2:30
mveCPallini3-Nov-09 2:30 
QuestionRe: Converting unsigned short int to its hex representation Pin
David Crow3-Nov-09 3:16
David Crow3-Nov-09 3:16 
AnswerRe: Converting unsigned short int to its hex representation Pin
CPallini3-Nov-09 3:29
mveCPallini3-Nov-09 3:29 
AnswerRe: Converting unsigned short int to its hex representation Pin
yeah10003-Nov-09 4:41
yeah10003-Nov-09 4:41 
AnswerRe: Converting unsigned short int to its hex representation Pin
softwaremonkey4-Nov-09 11:23
softwaremonkey4-Nov-09 11:23 
Questionc++ code Pin
anilga3-Nov-09 1:51
anilga3-Nov-09 1:51 
AnswerRe: c++ code Pin
Nikola Tanev3-Nov-09 2:08
Nikola Tanev3-Nov-09 2:08 
AnswerRe: c++ code Pin
Richard MacCutchan3-Nov-09 2:15
mveRichard MacCutchan3-Nov-09 2:15 
AnswerRe: c++ code Pin
CPallini3-Nov-09 2:18
mveCPallini3-Nov-09 2:18 
AnswerRe: c++ code Pin
Michael Schubert3-Nov-09 2:36
Michael Schubert3-Nov-09 2:36 
AnswerRe: c++ code Pin
David Crow3-Nov-09 3:13
David Crow3-Nov-09 3:13 
AnswerRe: c++ code Pin
Rajesh R Subramanian3-Nov-09 3:15
professionalRajesh R Subramanian3-Nov-09 3:15 
AnswerRe: c++ code Pin
Hamid_RT3-Nov-09 6:39
Hamid_RT3-Nov-09 6:39 
GeneralOT Pin
CPallini3-Nov-09 6:50
mveCPallini3-Nov-09 6:50 
GeneralRe: OT Pin
Hamid_RT3-Nov-09 19:28
Hamid_RT3-Nov-09 19:28 
QuestionHow can add path of all files to List Ctrl those are present in folder ? Pin
Le@rner3-Nov-09 1:51
Le@rner3-Nov-09 1:51 
AnswerRe: How can add path of all files to List Ctrl those are present in folder ? Pin
Code-o-mat3-Nov-09 1:57
Code-o-mat3-Nov-09 1:57 
GeneralRe: How can add path of all files to List Ctrl those are present in folder ? Pin
iwt.dev3-Nov-09 4:34
iwt.dev3-Nov-09 4:34 
GeneralRe: How can add path of all files to List Ctrl those are present in folder ? Pin
David Crow3-Nov-09 5:11
David Crow3-Nov-09 5:11 
QuestionRe: How can add path of all files to List Ctrl those are present in folder ? Pin
David Crow3-Nov-09 3:12
David Crow3-Nov-09 3:12 
QuestionCopy code Pin
Nikola Tanev3-Nov-09 1:24
Nikola Tanev3-Nov-09 1:24 
Ok so I want to learn what is the problem in the following code:

typedef int (*foo_ptr)(void);

static int foo()
{
return 20;
}
static void after_foo(){}

void main(int argc, char **argv)
{
size_t foo_size = (LPBYTE)after_foo - (LPBYTE)foo;

foo_ptr p_foo = (foo_ptr) VirtualAlloc(0, foo_size, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
CopyMemory(p_foo, &foo, foo_size);

int res = (*p_foo)();
}

Now it works perfectly as this but it crashes as soon as i insert printf("something") in the foo function. so the code that fails is the following:

typedef int (*foo_ptr)(void);

static int foo()
{
// this is the only modification
printf("test to print");
return 20;
}

static void after_foo(){}

void main(int argc, char **argv)
{
size_t foo_size = (LPBYTE)after_foo - (LPBYTE)foo;

foo_ptr p_foo = (foo_ptr) VirtualAlloc(0, foo_size, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
CopyMemory(p_foo, &foo, foo_size);

int res = (*p_foo)();
}

What i have noticed is that it crushes each time i insert a code that access the heap memory in the foo function. If i insert a code that allocates a heap it is not a problem (example int x;). I think it is something with the static functions and their address translation (absolute vs relative)...

Any answer would be appreciated

P.S. Please note that i do not want to do some mallware code.. i mean i know how to inject the code in the address space of another process i just cant figure it out how to insert it in the address space of the same process...... I have done a data management component which i use to share data between processes (IPC). The data management component works on a File mapped memory and uses custom heap implementation over that memory (using offsets since the memory is mapped differently in each process) to store the data. Now i want to boost it to share not only data between processes but also a code. The idea is that i do not want to inject the code from another process instead to inject the code in a shared memory space then from another process to copy the function in the local memory space and execute it from there.

Example:
App1 -> store foo() in DM
App2 -> read foo() from DM
App2 -> write foo() in local memory space (with PAGE_EXECUTE_READWRITE protection flag set)
App2 -> execute foo()

* DM is already created and works fine with data
* I understand that foo must not call functions from libraries that are not loaded in App2

Uffff tooo long post... sorry Smile | :)

regards,
Nikola Tanev
AnswerRe: Copy code Pin
Nikola Tanev3-Nov-09 11:32
Nikola Tanev3-Nov-09 11:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.