I assemble the following:
Code:
global _printhello ;exports
SECTION .text
_printhello:
mov ah, 09h
mov edx, string ;32-bit register usage is necessary for win32 obj file
int 21h
int 20h
SECTION .data
string db 'Hello world!$'
to a win32 obj file:
C:\>nasmw -f win32 phile.asm
This produces a .obj file phile.obj
Because borland c++ 5.5 doesn't want to link this .obj file I use the COFF2OMF import library conversion tool.
C:\>coff2omf phile.obj crap.obj
Then I atttempt to use the exported function _printhello in a C program:
Code:
#include <stdio.h>
void printhello();
int main() {
printhello();
return 0;
}
I compile it and link it together with phile.obj .
Upon execution an invalid page fault exception occurs and it crashes...
Also, when I try to debug it with ollydbg it gives some warning that it might be a self-modifying file or something.
Can anybody help me?