Einzelnen Beitrag anzeigen

Benutzerbild von paule32.jk
paule32.jk

Registriert seit: 24. Sep 2022
Ort: Planet Erde
218 Beiträge
 
Delphi 11 Alexandria
 
#5

AW: NASM - Erstellung eines Win64-Bit Images für die Verwendung mit mehr als 2 Funcca

  Alt 29. Okt 2023, 18:07
during the waiting Time of your Response, I asked ChatGPT, and formed the following Code.
But it can not execute - I get Windows Error 0x0c - not a valid win32 application.
I dont know why - Did you can see my mistake ?
Thanks for helping.

Code:
BITS 64
 
; DOS Header
    dw 'MZ'                ; e_magic
    dw 0                    ; [UNUSED] e_cblp
    dw 0                    ; [UNUSED] c_cp
    dw 0                    ; [UNUSED] e_crlc
    dw 0                    ; [UNUSED] e_cparhdr
    dw 0                    ; [UNUSED] e_minalloc
    dw 0                    ; [UNUSED] e_maxalloc
    dw 0                    ; [UNUSED] e_ss
    dw 0                    ; [UNUSED] e_sp
    dw 0                    ; [UNUSED] e_csum
    dw 0                    ; [UNUSED] e_ip
    dw 0                    ; [UNUSED] e_cs
    dw 0                    ; [UNUSED] e_lfarlc
    dw 0                    ; [UNUSED] e_ovno
    times 4 dw 0            ; [UNUSED] e_res
    dw 0                    ; [UNUSED] e_oemid
    dw 0                    ; [UNUSED] e_oeminfo
    times 10 dw 0           ; [UNUSED] e_res2
    dd pe_hdr              ; e_lfanew
 
; PE Header
pe_hdr:
    dw 'PE', 0              ; Signature
 
; Image File Header
    dw 0x8664               ; Machine
    dw 0x01                 ; NumberOfSections
    dd 0                    ; [UNUSED] TimeDateStamp
    dd 0                    ; PointerToSymbolTable
    dd 0                    ; NumberOfSymbols
    dw opt_hdr_size        ; SizeOfOptionalHeader
    dw 0x22                 ; Characteristics
 
; Optional Header, COFF Standard Fields
opt_hdr:
    dw 0x020b              ; Magic (PE32+)
    db 0x0e                ; MajorLinkerVersion
    db 0x16                 ; MinorLinkerVersion
    dd code_size           ; SizeOfCode
    dd 0                    ; SizeOfInitializedData
    dd 0                    ; SizeOfUninitializedData
    dd entry               ; AddressOfEntryPoint
    dd file_size           ; BaseOfCode
 
; Optional Header, NT Additional Fields
    dq 0x000140000000       ; ImageBase
    dd 0x10                 ; SectionAlignment
    dd 0x10                 ; FileAlignment
    dw 0x06                 ; MajorOperatingSystemVersion
    dw 0                    ; MinorOperatingSystemVersion
    dw 0                    ; MajorImageVersion
    dw 0                    ; MinorImageVersion
    dw 0x06                 ; MajorSubsystemVersion
    dw 0                    ; MinorSubsystemVersion
    dd 0                    ; Reserved1
    dd file_size           ; SizeOfImage
    dd hdr_size            ; SizeOfHeaders
    dd 0                    ; CheckSum
    dw 0x02                 ; Subsystem (Windows GUI)
    dw 0x8160               ; DllCharacteristics
    dq 0x100000             ; SizeOfStackReserve
    dq 0x1000               ; SizeOfStackCommit
    dq 0x100000             ; SizeOfHeapReserve
    dq 0x1000               ; SizeOfHeapCommit
    dd 0                    ; LoaderFlags
    dd 0x02                 ; NumberOfRvaAndSizes
 
; Optional Header, Data Directories
    dd 0                      ; Export, RVA
    dd 0                      ; Export, Size
   
    dd import_descriptor     ; Import, RVA
    dd import_descriptor_size ; Import, Size
   
    dd 0                      ; Resources, RVA
    dd 0                      ; Resources, Size
 
opt_hdr_size equ $-opt_hdr
 
; Section Table
    section_name db '.text', 0, 0,0     ; Name
    times 8-($-section_name) db 0
    dd sect_size           ; VirtualSize
    dd virtual_address_text ; VirtualAddress
    dd code_size           ; SizeOfRawData
    dd ptr_to_raw_data_text ; PointerToRawData
    dd 0                    ; PointerToRelocations
    dd 0                    ; PointerToLinenumbers
    dw 0                    ; NumberOfRelocations
    dw 0                    ; NumberOfLinenumbers
    dd 0x60000020           ; Characteristics
sect_size equ $-$$ 
 
hdr_size equ $-$$
 
code_src:
section .idata
    ; Import Directory Entry for "user32.dll"
    import_descriptor:
        dq 0                    ; OriginalFirstThunk
        dq 0                    ; TimeDateStamp
        dd 0                    ; ForwarderChain
        dq import_address_table ; RVA to imported functions
        dq dll_name_1           ; Name of import dll
        dq import_name_table   ; RVA for inport name table
        dq 0                    ; Reserved
       
    import_descriptor_size equ $-import_descriptor
   
    ; Import Name Table for imported functions
    import_name_table:
        dq function_1_hint
        dq function_1_name
        dq 0                    ; null-terminator
   
    ; Import Address Table (IAT)
    import_address_table:
        dq 0
        dq 0
       
    function_1_name db 'MessageBoxA', 0
    function_1_hint dw 283

    dll_name_1: db 'user32.dll', 0
   
section .text
 
; Entry
entry:
  ret
  mov r9d, 0x00240040     ; uType
  lea r8, [rel title]    ; lpCaption
  lea rdx, [rel content] ; lpText
  xor ecx, ecx           ; hWnd
; ;mov rax, [rel iatbl]  ; MessageBoxN
  call rax

code_size equ $ - code_src
 
section .data
title:
    db "Hallo Welt !!!", 0
content:
    db "ABCDEFGHIJKL", 0

image_base dq 0x00400000

virtual_address_text dd $ - $$ + image_base
ptr_to_raw_data_text dd $ - $$

file_size equ $-$$
Frag doch einfach
Alles was nicht programmiert werden kann, wird gelötet
  Mit Zitat antworten Zitat