To test the program I have compiled an assembler test program as follows:
nasm -fwin32 hellow.asm && gcc -m32 hellow.obj -o hellow.exe && hellow
Although the program is very small, the executable file is about 294kByte in size. The hexdump starts as follows:
unsigned char rawData[0x049ac3] = {
0x4d,0x5a,0x90,0x00,0x03,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0xff,0xff,0x00,0x00,
0xb8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,
0x0e,0x1f,0xba,0x0e,0x00,0xb4,0x09,0xcd,0x21,0xb8,0x01,0x4c,0xcd,0x21,0x54,0x68,
0x69,0x73,0x20,0x70,0x72,0x6f,0x67,0x72,0x61,0x6d,0x20,0x63,0x61,0x6e,0x6e,0x6f,
0x74,0x20,0x62,0x65,0x20,0x72,0x75,0x6e,0x20,0x69,0x6e,0x20,0x44,0x4f,0x53,0x20,
0x6d,0x6f,0x64,0x65,0x2e,0x0d,0x0d,0x0a,0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x50,0x45,0x00,0x00, 0x4c,0x01,0x10,0x00,0x5d,0xf8,0xc8,0x65,0x00,0x2e,0x04,0x00,0xff,0x04,0x00,0x00,
0xe0,0x00,0x27,0x01, };
int main()
{
RunPortableExecutable(rawData);
}
The call with Visual Studio works without any problems and the reloaded program does its work without errors. The effort that is made here to overwrite a thread with foreign code is considerable and this raises the question why the effort is made. I cannot judge whether the BASIC source code generates a suitable binary code. This is where I would see the first possible source of error. You could test the functionality by writing the binary code from BASIC to an EXE file and checking whether it works.
I am surprised by the magic number
0x5553
used in the example code. In an EXE it should actually be
0x4d5a
, as can also be seen in my sample data.
It is also noticeable that the character strings, which should contain readable hexadecimals, contain an odd number of characters.
"55,53,57,56,81,8B,8B,8D,68,50,6A,FF,BB,81,00,0F,C"
"70,0C,70,0C,70,0C,78,D3,1B,98,9F,38,95,05,26,A6,A"
Possibly the problem is already here ...