H
H
hitakiri2020-07-15 23:16:29
linux
hitakiri, 2020-07-15 23:16:29

How to correctly connect cinvoke to FASM under ELF64?

Elementary preparation for a beginner:

format ELF64 executable 3
entry start

  ; include 'linInclude/import32.inc'
  ; include 'linInclude/proc32.inc'
  ; interpreter '/lib/ld-linux.so.2'

  include 'linInclude/import64.inc'
  include 'linInclude/proc64.inc'
  interpreter '/lib64/ld-linux-x86-64.so.2'

  needed  'libc.so.6'

  import  exit,\
          printf

segment readable executable
      cinvoke printf, fmtS, msg
         cinvoke	exit

segment readable writeable
      msg db 'Hello, World!', 0xA, 0
          fmtS db '%s', 0xA, 0


In 32-bit mode (invert imports and change ELF64 to ELF) everything works.
When switching to 64-bit, it compiles, but on startup it gives a Segmentation fault (core dumped)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2020-07-16
@jcmvbkbc

include 'linInclude/proc64.inc'

There is no such file in the standard distribution of fasm, is there? Where did you get it?
I got this code:
format ELF64 executable 3

  include '/usr/share/fasm/examples/elfexe/dynamic/import64.inc'
  interpreter '/lib64/ld-linux-x86-64.so.2'

  needed  'libc.so.6'

  import  exit, printf

segment readable executable
entry $

        lea rdi, [fmtS]
        lea rsi, [msg]
        call [printf]
        call [exit]

segment readable writeable
        msg db 'Hello, World!', 0xA, 0
        fmtS db '%s', 0xA, 0

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question