flat assembler
Message board for the users of flat assembler.

Index > Linux > [solved] Linux elf64 macro help

Author
Thread Post new topic Reply to topic
duanebonas6822



Joined: 06 Dec 2024
Posts: 22
duanebonas6822 22 Dec 2024, 22:15
Hi, im just getting into macros, I have a huge binary with like 2000+ manually linked C libraries, does anybody know how i can call socket like this:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
macro socket domain, type, protocol {
mov rdi, domain
mov rsi, type
mov rdx, protocol
call [socket]
}

; mov rax, CTL_socket
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

My main binary is already defined like this for over 2000+ C calls and i get memory already defined

# ALL STATICALLY DEFINED LIKE THESE I JUST HOPE I DONT HAVE TO DELETE THEM
# ALL AS IT TOOK AGES BUT THE MACROS ARE UNBELIEVABLE, I CAN CODE MORE
# LIKE IN C AND ITS MUCH QUICKER ??

Elf64_Sym socket-strtab,0,0,STB_GLOBAL,STT_FUNC,0,0
Elf64_Rela socket,1337,R_X86_64_64

_socket db "socket", 0

socket dq ?

# THIS IS HOW I RUN THE CODE

; socket AF_INET, SOCK_STREAM, 0

ANY HELP APPRECIATED

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(ERROR)~~~~~~~~~~~~
shellcode40.asm [20932]:
socket dq ?

shellcode40.asm [15162] socket [1]:
mov rdi, domain

processed: mov rdi,dq ?
error: invalid operand.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

_________________
d.bonas
Post 22 Dec 2024, 22:15
View user's profile Send private message Reply with quote
duanebonas6822



Joined: 06 Dec 2024
Posts: 22
duanebonas6822 22 Dec 2024, 23:29
Anybody know if the statically linked C librarys are going to work with macros, really needed anyone to comment on this by tomorrow, just i need my binary to be Position independant with no linker at all, i can get normal syscalls to work ok but i just dont know if it possible to use macros with call [socket], as the memory is defined like this:

_socket db "socket", 0

and also like this

socket dq ?

# i reading up on ccall but even that i not quite sure even works fully with format elf64, i can get them working with extern socket as it doesnt declair memory, but that cant be used like i want, cheers let know anyone
Post 22 Dec 2024, 23:29
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 23 Dec 2024, 00:04
You seem to be defining socket twice?
Code:
macro socket ...
;...
socket dq ? ; this expands the "socket" macro with domain="dq ?" and type/protocol undefined, hence the error    
Post 23 Dec 2024, 00:04
View user's profile Send private message Visit poster's website Reply with quote
duanebonas6822



Joined: 06 Dec 2024
Posts: 22
duanebonas6822 23 Dec 2024, 00:06
OMG, i been here for 2 hours wondering how to figure calling with this memory address error:

# It only works without a memory address at all called like this:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
macro socketvv domain, type, protocol {
mov rdi, domain
mov rsi, type
mov rdx, protocol
call [socket]
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# I cant believe i could use macros like this to make programming easier, i was writing assembley the bastard hard way
# for ages, i been stressing out for months ways to get C code to execute with messing on with stack alligning and it
# gets stressing as hell. Really if anyone is trying to get C code and assembley to work dont use summet like NASM
# these macros are magical, i can repeat TEXT and do things miles faster. I wish i would of read up on these macros ages ago
# FASM is the Daddy, long live ASM hahaha, gonna be checking out all the posts on macro tricks
Post 23 Dec 2024, 00:06
View user's profile Send private message Reply with quote
duanebonas6822



Joined: 06 Dec 2024
Posts: 22
duanebonas6822 23 Dec 2024, 00:12
well i have it working now, i just sat and read all the docs fully last nite and realized that i have been ignoring the macros, they do exactly what ive been doing the hard way for ages. I just have already thought of loads of ways they can be used, u just have to really take time to understand how structs and memory work , lol but no cheers mate for the reply many thanks i take note of the above response but just sat reading lol
Post 23 Dec 2024, 00:12
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.