Click here to Skip to main content
15,917,642 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionAllegro Dev C++ program crash Pin
ashutoshrambhal14-Dec-13 23:53
ashutoshrambhal14-Dec-13 23:53 
AnswerRe: Allegro Dev C++ program crash Pin
Richard MacCutchan15-Dec-13 0:38
mveRichard MacCutchan15-Dec-13 0:38 
GeneralRe: Allegro Dev C++ program crash Pin
ashutoshrambhal15-Dec-13 2:46
ashutoshrambhal15-Dec-13 2:46 
GeneralRe: Allegro Dev C++ program crash Pin
Richard MacCutchan15-Dec-13 2:59
mveRichard MacCutchan15-Dec-13 2:59 
QuestionRich edit control and caption Pin
RaymondM14-Dec-13 1:43
RaymondM14-Dec-13 1:43 
SuggestionRe: Rich edit control and caption Pin
Richard MacCutchan15-Dec-13 0:34
mveRichard MacCutchan15-Dec-13 0:34 
AnswerRe: Rich edit control and caption Pin
enhzflep15-Dec-13 3:56
enhzflep15-Dec-13 3:56 
QuestionNON MFC / WINAPI Problem related to Process and Files. Pin
lokesh.mavale13-Dec-13 13:07
lokesh.mavale13-Dec-13 13:07 
QuestionExtract RGB Colors Pin
Django_Untaken13-Dec-13 1:31
Django_Untaken13-Dec-13 1:31 
AnswerRe: Extract RGB Colors Pin
Richard MacCutchan13-Dec-13 1:49
mveRichard MacCutchan13-Dec-13 1:49 
AnswerRe: Extract RGB Colors Pin
CPallini13-Dec-13 3:06
mveCPallini13-Dec-13 3:06 
AnswerRe: Extract RGB Colors Pin
Eugen Podsypalnikov13-Dec-13 3:18
Eugen Podsypalnikov13-Dec-13 3:18 
QuestionC pointer and array question [Resolved] Pin
econy12-Dec-13 20:07
econy12-Dec-13 20:07 
AnswerRe: C pointer and array question Pin
econy12-Dec-13 20:19
econy12-Dec-13 20:19 
AnswerRe: C pointer and array question [Resolved] Pin
Richard MacCutchan12-Dec-13 21:19
mveRichard MacCutchan12-Dec-13 21:19 
AnswerRe: C pointer and array question [Resolved] Pin
Stefan_Lang12-Dec-13 22:42
Stefan_Lang12-Dec-13 22:42 
GeneralRe: C pointer and array question [Resolved] Pin
econy16-Dec-13 9:14
econy16-Dec-13 9:14 
GeneralRe: C pointer and array question [Resolved] Pin
Stefan_Lang16-Dec-13 21:25
Stefan_Lang16-Dec-13 21:25 
AnswerRe: C pointer and array question [Resolved] Pin
Stefan_Lang12-Dec-13 23:14
Stefan_Lang12-Dec-13 23:14 
QuestionReplacement for Inline Assembly Pin
Richard Andrew x6412-Dec-13 18:08
professionalRichard Andrew x6412-Dec-13 18:08 
QuestionRe: Replacement for Inline Assembly Pin
Richard MacCutchan12-Dec-13 21:05
mveRichard MacCutchan12-Dec-13 21:05 
AnswerRe: Replacement for Inline Assembly Pin
Richard Andrew x6413-Dec-13 7:44
professionalRichard Andrew x6413-Dec-13 7:44 
AnswerRe: Replacement for Inline Assembly Pin
Rajesh R Subramanian12-Dec-13 23:31
professionalRajesh R Subramanian12-Dec-13 23:31 
AnswerRe: Replacement for Inline Assembly PinPopular
Eugen Podsypalnikov13-Dec-13 1:14
Eugen Podsypalnikov13-Dec-13 1:14 
// how can I execute a jmp instruction when I need to?

1. Organize a buffer for the JMP executing
C++
  enum {
#ifndef _WIN64
    jmpAddrIdx  = 2,  // Index of the Address in Jump-Buffer
    jmpLen      = 10, // Length of the Jump-Buffer
#else
    jmpAddrIdx  = 3,  // Index of the Address in Jump-Buffer
    jmpLen      = 16, // Length of the Jump-Buffer
#endif
  };
      static BYTE jmp[jmpLen] = {
#ifdef _WIN64
        0x50,                                           // push rax           (len:01)
        0x48, 0xb8,                                     // mov rax, DWORD_PTR (len:10)
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x48, 0x87, 0x04, 0x24,                         // xchg rax, [rsp]    (len:04)
        0xc3                                            // ret                (len:01)
#else
        0x50,                                           // push eax           (len:01)
        0xb8,                                           // mov eax, DWORD_PTR (len:05)
        0x00, 0x00, 0x00, 0x00,
        0x87, 0x04, 0x24,                               // xchg eax, [esp]    (len:03)
        0xc3                                            // ret                (len:01)
#endif
      };

2. Fill the address part there in (low Bytes first)
C++
memcpy(&jmp[jmpAddrIdx], YOUR_DESIRED_ADDRESS, sizeof(DWORD_PTR));

3. Take the pointer of an existing global function(void) (Long enough: see jmpLen above)
4. Mark the addressed space of the function as writeable
C++
DWORD dwOldMode(0);
if (VirtualProtect(pfnYourShellFcn, jmpLen, PAGE_EXECUTE_READWRITE, &dwOldMode)) {

5. Write the jump into the function Smile | :)
C++
memcpy(pfnOriginal, jmp, jmpLen);

6. Mark the space as original
C++
VirtualProtect(pfnYourShellFcn, jmpLen, dwOldMode, &dwOldMode);

7. Call the pointed function Smile | :)
C++
(*pfnYourShellFcn)()

8. Be thrilled.
They sought it with thimbles, they sought it with care;
They pursued it with forks and hope;
They threatened its life with a railway-share;
They charmed it with smiles and soap. Smile | :)


modified 13-Dec-13 7:25am.

GeneralRe: Replacement for Inline Assembly Pin
Richard Andrew x6413-Dec-13 7:25
professionalRichard Andrew x6413-Dec-13 7:25 

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.