user14872555
user14872555

Reputation:

Undefined reference when trying to link C++ and Assembly (GCC x86)

So I'm trying to make NTDLL Syscalls using Assembly and linking in my C++ project but every time I compile I get a :(.text+0xf2b): undefined reference to `NtClose@4'

(Using NtClose as an example, every function I try to call from assembly on C++ I get this)

Syscalls.S:

.text
    .global NtClose

NtClose:
    movl    $0x3000F,       %eax
    movl    $0x4B307170,    %edx
    call    *%edx
    ret     $4

Typedef (Syscalls.h):

EXTERN_C NTSTATUS NTAPI NtClose(IN HANDLE ObjectHandle);

Calling like this (Injection.cpp):

NtClose(Thread);

Compiling with:

CC=gcc
CXX=g++

$(ASM_OBJ_FILES): $(OBJ_DIR)/%.o: %.S
    $(CC) -c $< -o $@

$(CPP_OBJ_FILES): $(OBJ_DIR)/%.o: %.cpp
    $(CXX) $(CXXFLAGS) -c $< -o $@

And linking like this:

$(OUT): $(OBJ_FILES)
    $(CXX) $^ -o $@ $(LNKFLAGS)

Yes I am including Syscalls.h

Upvotes: 0

Views: 372

Answers (1)

yugr
yugr

Reputation: 21886

NTAPI (in fact all stdcall) functions are decorated with @N where N stands for number of arguments. So you'll need to modify name of function accordingly.

Upvotes: 1

Related Questions