NO

Author Topic: About freestanding EXE-files in Pelles C  (Read 1278 times)

Offline pink

  • Member
  • *
  • Posts: 1
About freestanding EXE-files in Pelles C
« on: October 08, 2024, 02:52:13 PM »
Hi, i wanna make a executable that does not import kernel32.dll or any dlls, other then the ones i specify

love your software! :D

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: About freestanding EXE-files in Pelles C
« Reply #1 on: October 08, 2024, 03:15:46 PM »
Hello Pink, welcome.
You can use the linker switch "-nodefaultlib". In this case no default library will be searched.
Remember that you have to explicitly specify all libraries required, even the PellesC C runtime.
« Last Edit: October 08, 2024, 05:27:10 PM by frankie »
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

Offline Vortex

  • Member
  • *
  • Posts: 844
    • http://www.vortex.masmcode.com
Re: About freestanding EXE-files in Pelles C
« Reply #2 on: October 08, 2024, 04:01:13 PM »
Hi pink,

Your executable should import from kernel32.dll You must to take in account that this type of executables not importing from kernel32 could trigger the attention of antivirus software. Here is a Poasm example for you :

Code: [Select]
.386
.model flat,stdcall
option casemap:none

include PEBstruct.inc

MB_OK equ 0

GetProcAddr PROTO :DWORD,:DWORD

.data

LoadLibrary db 'LoadLibraryA',0
MessageBox  db 'MessageBoxA',0
ExitProcess db 'ExitProcess',0
user32      db 'user32.dll',0
msg         db 'Hello from MessageBox',0

.code

start:

    call    main

    push    0
    call    eax                 ; Call ExitProcess

main PROC uses esi ebx

    mov     ebx,[fs:030h]       ;   PEB
    mov     ebx,[ebx+00Ch]      ;   PEB->Ldr
    mov     ebx,[ebx+014h]      ;   PEB->Ldr.InMemoryOrderModuleList.Flink (1st entry)
    mov     ebx,[ebx]           ;   2nd Entry
    mov     ebx,[ebx]           ;   3rd Entry
    mov     ebx,[ebx+010h]      ;   Third entry's base address (Kernel32.dll)

    invoke  GetProcAddr,ebx,ADDR LoadLibrary

    push    OFFSET user32
    call    eax

    invoke  GetProcAddr,eax,ADDR MessageBox

    push    MB_OK
    push    OFFSET user32
    push    OFFSET msg
    push    0
    call    eax                 ; Call MessageBox

    invoke  GetProcAddr,ebx,ADDR ExitProcess

    ret

main ENDP

END start
« Last Edit: October 08, 2024, 09:47:56 PM by Vortex »
Code it... That's all...