Groups | Search | Server Info | Login | Register


Groups > de.comp.lang.assembler > #1240

Re: MZ + PE + Code := Flat Image für Windows 10 64-Bit - NASM / YASM

From Jens Kallup <paule32.jk@gmail.com>
Newsgroups de.comp.lang.assembler
Subject Re: MZ + PE + Code := Flat Image für Windows 10 64-Bit - NASM / YASM
Date 2023-10-29 16:38 +0100
Organization kallup non-profit
Message-ID <kq7cj5F60lqU1@mid.individual.net> (permalink)
References <kq6ju5F6i5U1@mid.individual.net> <uhlk3i$3shdj$1@dont-email.me>

Show all headers | View raw


Hallo Herbert,

welchen Assembler nutzt Du?
sieht fast so aus, also wäre das für Ardunio...

Ich habe in der Zwischenzeit den Code abgeändert, aber da ist
noch irgendwo der Wurm drinn.
Möglicherweise ein Array-Problem.
Aber das konnte ich jetzt nicht hinbiegen, weil ich damit dann
voodoo Programming betreibe - was nicht sehr prikelnd sein kann.

Ich starte das Programm, aber die DLL scheint nicht geladen zu
werden, da sonst die MessageBoxA im DLL begin main Block aufpoppen
müsste ...

Ich habe zusätzlich eine DLL in FPC (Free Pascal Compiler) ge-
schrieben:

library kalle32;
uses windows;
procedure kalli(h: HWND; t,c: PChar; u: UINT); stdcall; export;
begin
MessageBoxA(h,t,c,u);
end;
begin
MessageBoxA(0,'xxxxx','tttt',0);
end.
--------------------
BITS 64

%define align(n,r) (((n+(r-1))/r)*r)

; 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 iatbl                ; 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 itbl                 ; Import, RVA
     dd itbl_size            ; Import, Size

opt_hdr_size equ $-opt_hdr

; Section Table
     section_name db '.'     ; Name
     times 8-($-section_name) db 0
     dd sect_size            ; VirtualSize
     dd iatbl                ; VirtualAddress
     dd code_size            ; SizeOfRawData
     dd iatbl                ; PointerToRawData
     dd 0                    ; PointerToRelocations
     dd 0                    ; PointerToLinenumbers
     dw 0                    ; NumberOfRelocations
     dw 0                    ; NumberOfLinenumbers
     dd 0x60000020           ; Characteristics

hdr_size equ $-$$

code:
; Import Address Directory
iatbl:
     dq symbol_1
     dq symbol_2
     dq 0
iatbl_size equ $-iatbl

; Strings
title:
     db "Hallo Welt !!!", 0
content:
     db "ABCDEFGHIJKL", 0

; Entry
entry:
   mov r9d, 0x00240040     ; uType
   lea r8, [rel title]     ; lpCaption
   lea rdx, [rel content]  ; lpText
   xor ecx, ecx            ; hWnd
   mov rax, [rel iatbl + 8]  ; MessageBoxN
   call rax


     times align($-$$,16)-($-$$) db 0xcc

; Import Directory 1
itbl:
     dq intbl_1              ; OriginalFirstThunk
     dd 0                    ; TimeDateStamp
     dd dll_name_1           ; ForwarderChain
     dd iatbl                ; Name
     dq 0                    ; FirstThunk

; Import Directory 2
itbl_2:
     dq intbl_2              ; OriginalFirstThunk
     dd 0                    ; TimeDateStamp
     dd dll_name_2           ; ForwarderChain
     dd iatbl + 8            ; Name
     dq 0                    ; FirstThunk

itbl_size equ $-itbl

; Import Name Table 1
intbl_1:
     dq symbol_1
     dq 0

; Import Name Table 2
intbl_2:
     dq symbol_2
     dq 0

; Symbol 1
symbol_1:
     dw 0                    ; [UNUSED] Function Order
     db 'MessageBoxA', 0     ; Function Name

; Symbol 2
symbol_2:
     dw 0
     db 'kalli', 0

dll_name_2: db 'kalle32.dll', 0
dll_name_1: db 'USER32.dll' , 0

sect_size equ $-code

     times align($-$$,16)-($-$$) db 0

code_size equ $-code
file_size equ $-$$


-- 
Diese E-Mail wurde von Avast-Antivirussoftware auf Viren geprüft.
www.avast.com

Back to de.comp.lang.assembler | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

MZ + PE + Code := Flat Image für Windows 10 64-Bit - NASM / YASM Jens Kallup <paule32.jk@gmail.com> - 2023-10-29 09:37 +0100
  Re: MZ + PE + Code := Flat Image für Windows 10 64-Bit - NASM / YASM Herbert Kleebauer <klee@unibwm.de> - 2023-10-29 13:44 +0100
    Re: MZ + PE + Code := Flat Image für Windows 10 64-Bit - NASM / YASM Jens Kallup <paule32.jk@gmail.com> - 2023-10-29 16:38 +0100
      kleiner Typo Jens Kallup <paule32.jk@gmail.com> - 2023-10-29 16:40 +0100
      Re: MZ + PE + Code := Flat Image für Windows 10 64-Bit - NASM / YASM Herbert Kleebauer <klee@unibwm.de> - 2023-10-29 17:29 +0100
        Re: MZ + PE + Code := Flat Image für Windows 10 64-Bit - NASM / YASM Blacky Cat <paule32.jk@gmail.com> - 2025-07-26 16:20 +0200

csiph-web