Author Topic: exe file is not valid win32 aplication  (Read 9994 times)

Offline Alvin_Sanchez12

  • Jr. Member
  • *
  • Posts: 4
exe file is not valid win32 aplication
« on: September 18, 2020, 01:28:46 PM »
Hi there, my name is alvin and im 15 years old and i was beginer in assembly and i want to ask a quesion how i fix test.exe is not valid win32 application currently im using windows

Offline debs3759

  • Global Moderator
  • Full Member
  • *****
  • Posts: 221
  • Country: gb
    • GPUZoo
Re: exe file is not valid win32 aplication
« Reply #1 on: September 18, 2020, 02:03:06 PM »
If you show us your code and how you are creating your exe file someone may be able to help you. Without any more info it's impossible to know what the problem is.
My graphics card database: www.gpuzoo.com

Offline Alvin_Sanchez12

  • Jr. Member
  • *
  • Posts: 4
Re: exe file is not valid win32 aplication
« Reply #2 on: September 18, 2020, 02:08:17 PM »
this my test.asm code
section .data
msg db "hello worlds",0
msg_len equ $-msg

section .text
global _start

mov eax, 4
mov ebx, 1
mov ecx, msg
mov edx, msg_len
syscall

mov eax, 1
mov ebx, 1
syscall

i trying run with nasm
nasm -f win64 -o test.obj test.asm

and link with ld
ld -m i386pe -s -o test.exe test.obj

did i get wrong?

Offline Alvin_Sanchez12

  • Jr. Member
  • *
  • Posts: 4
Re: exe file is not valid win32 aplication
« Reply #3 on: September 18, 2020, 02:09:11 PM »
currently im using windows 7

Offline debs3759

  • Global Moderator
  • Full Member
  • *****
  • Posts: 221
  • Country: gb
    • GPUZoo
Re: exe file is not valid win32 aplication
« Reply #4 on: September 18, 2020, 02:34:27 PM »
I'm not a Windows coder (yet), but it looks like you are writing 32-bit code, and telling nasm to generate a 64-bit object file, which you then try linking as a 32-bit executable. I don't know if that is the problem though, hopefully someone with Windows and 64-bit experience will be along soon.
My graphics card database: www.gpuzoo.com

Offline TmX

  • Jr. Member
  • *
  • Posts: 7
Re: exe file is not valid win32 aplication
« Reply #5 on: September 18, 2020, 02:47:51 PM »
Looks like you are compiling Linux code on Windows.
And not sure if you invoke the GNU linker (ld) correctly.


Offline Alvin_Sanchez12

  • Jr. Member
  • *
  • Posts: 4
Re: exe file is not valid win32 aplication
« Reply #6 on: September 19, 2020, 12:41:03 AM »
so  what is the code for windows looks like?

Offline fredericopissarra

  • Full Member
  • **
  • Posts: 368
  • Country: br
Re: exe file is not valid win32 aplication
« Reply #7 on: September 19, 2020, 11:11:39 AM »
so  what is the code for windows looks like?

You need to use Win32 API and MinGW (or Cygwin):

Code: [Select]
  bits  64
  default rel

STD_OUTPUT_HANDLE equ -11

  section .rodata

msg:
  db  `Hello, world.\n`
msg_size  equ $ - msg

  section .text

  extern __imp_GetStdHandle
  extern __imp_WriteConsoleA
  extern __imp_ExitProcess

  global _start
_start:
  mov   ecx,STD_OUTPUT_HANDLE
  call  [__imp_GetStdHandle]

  mov   rcx,rax
  lea   rdx,[msg]
  mov   r8d,msg_size
  xor   r9d,r9d
  push  0
  call  [__imp_WriteConsoleA]
 
  xor   ecx,ecx
  jmp   [__imp_ExitProcess]
To compile and link:
Code: [Select]
$ nasm -fwin64 -o win.o win.asm
$ x86_64-w64-mingw32-ld -e _start -o win.exe win.o \
  -L /usr/x86_64-w64-mingw32/lib -lkernel32
« Last Edit: September 19, 2020, 11:17:59 AM by fredericopissarra »