Click here to Skip to main content
15,895,709 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
GeneralRe: Replacement for Inline Assembly Pin
CPallini13-Dec-13 10:02
mveCPallini13-Dec-13 10:02 
AnswerRe: Replacement for Inline Assembly Pin
Chris Losinger15-Dec-13 4:47
professionalChris Losinger15-Dec-13 4:47 
GeneralRe: Replacement for Inline Assembly Pin
Richard Andrew x6415-Dec-13 5:20
professionalRichard Andrew x6415-Dec-13 5:20 
QuestionC Language Tutorial Pin
tgsb11-Dec-13 22:00
tgsb11-Dec-13 22:00 
AnswerRe: C Language Tutorial Pin
Richard MacCutchan11-Dec-13 22:07
mveRichard MacCutchan11-Dec-13 22:07 
QuestionHow to get the android nowtime screen-picture from PC by adb ?? Pin
chehongyang11-Dec-13 19:41
chehongyang11-Dec-13 19:41 
AnswerRe: How to get the android nowtime screen-picture from PC by adb ?? Pin
Albert Holguin12-Dec-13 4:16
professionalAlbert Holguin12-Dec-13 4:16 
Questionto show an color filled object on the top of everything Pin
transoft11-Dec-13 8:34
transoft11-Dec-13 8:34 
AnswerRe: to show an color filled object on the top of everything Pin
Chris Losinger11-Dec-13 10:39
professionalChris Losinger11-Dec-13 10:39 
AnswerRe: to show an color filled object on the top of everything Pin
Albert Holguin12-Dec-13 4:19
professionalAlbert Holguin12-Dec-13 4:19 
Questionstd::swap Corruption [Answered] Pin
Skippums11-Dec-13 7:26
Skippums11-Dec-13 7:26 
AnswerRe: std::swap Corruption Pin
Skippums11-Dec-13 8:35
Skippums11-Dec-13 8:35 
QuestionQuestion About Threads Pin
AmbiguousName11-Dec-13 5:55
AmbiguousName11-Dec-13 5:55 
AnswerRe: Question About Threads Pin
jschell11-Dec-13 9:03
jschell11-Dec-13 9:03 
AnswerRe: Question About Threads Pin
Chris Losinger11-Dec-13 10:37
professionalChris Losinger11-Dec-13 10:37 
GeneralRe: Question About Threads Pin
Richard Andrew x6411-Dec-13 13:56
professionalRichard Andrew x6411-Dec-13 13:56 

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.