A
A
armadillo-cld2020-06-12 01:29:00
C++ / C#
armadillo-cld, 2020-06-12 01:29:00

How to pass control to __asm?

Hello.
Let's say we have this code:

HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
  PROCESSENTRY32 entry;
  DWORD procID = 0;
  if (Process32First(snapshot, &entry) == TRUE) {
    while (Process32Next(snapshot, &entry) == TRUE) {
      if (strcmp(entry.szExeFile, "Checker.exe") == 0) {
        procID = entry.th32ProcessID;
      }
    }
  }
  
  if (procID != 0) {
    HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS | PROCESS_VM_READ, NULL, procID);
    __asm {
      mov eax, hProcess
      push eax
      push 0
      call TerminateProcess
    }
  }

But when executing this code:
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS | PROCESS_VM_READ, NULL, procID);
    __asm {
      mov eax, hProcess
      push eax
      push 0
      call TerminateProcess
    }

He just ignores. Does not close the process.
How to pass control to __asm ​​correctly?

I checked, the process detects, hProcess is not NULL!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2020-06-12
@armadillo-cld

Keyword	Stack cleanup	Parameter passing
__stdcall	Callee	Pushes parameters on the stack, in reverse order (right to left)

https://docs.microsoft.com/en-us/cpp/cpp/argument-...
push 0
push eax
call TerminateProcess

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question