PDA

Click to See Complete Forum and Search --> : An odd question


Darkwraith
Jul 14th, 2003, 06:26 PM
Can you directly write machine code into the code segment of a running application?

CodeRonin
Jul 28th, 2003, 05:18 AM
not under windows, i don't know if it works under linux

Darkwraith
Jul 31st, 2003, 04:06 PM
Why?

CornedBee
Aug 1st, 2003, 01:15 AM
You can in windows. I think the 2.6 Linux kernel has an option to disallow it, but in windows you can. It's done when hooking API calls - you actually replace a piece of code from the windows DLLs.

Darkwraith
Aug 1st, 2003, 03:45 PM
Now the application change its own code... :)

CodeRonin
Aug 3rd, 2003, 04:34 AM
When I last tried it under W2K, he didn't allow it... how do you do it?

Darkwraith
Aug 3rd, 2003, 03:37 PM
Oops. I just checked my previous post. It really should be:


Now can the application change its own code...

CornedBee
Aug 4th, 2003, 07:00 AM
If not, you can always allocate some memory with execute rights using VirtualAlloc and write your code there.

Darkwraith
Aug 4th, 2003, 02:04 PM
I am using NASM, and I do not have VirtualAlloc. Where can I get that macro (or call or whatever) from?

CornedBee
Aug 5th, 2003, 01:12 AM
It's a WinAPI call in kernel32.dll.

If you're programming for DOS, you'll have to look up the various INT21h functions to find out how to allocate memory. DOS gives no restrictions at all on what code is accessible how.

In UNIX, you'll have to look it up too.

Darkwraith
Aug 5th, 2003, 02:26 PM
Excuse my ignorance, but is that the same dll that is included in MSVC++?

CornedBee
Aug 6th, 2003, 01:18 AM
It's one of the core dlls of windows, so it doesn't need to come with MSVC++.

Darkwraith
Aug 6th, 2003, 10:55 AM
Where could I find information on kernel32.dll?

CornedBee
Aug 6th, 2003, 01:42 PM
In the SDK docs and with Dependency Viewer (a tool that comes with the SDK and is AFAIK also on the WinXP CD).