flat assembler
Message board for the users of flat assembler.

Index > Linux > fasm elf64 - ncurses colour help

Author
Thread Post new topic Reply to topic
duanebonas6822



Joined: 06 Dec 2024
Posts: 22
duanebonas6822 06 Dec 2024, 16:38
Hi anybody need help on running C NCURSES via FASM format ELF

I need help getting colour to work like the macro controlls this in NASM but i cant define
the string in FASM, Can anyone read this here is how my FASM binary is set up.
Code:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 format ELF64 executable 3
 use64

 entry start
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# MY SYM + RELA DEFINED LIKE THIS  


 Elf64_Sym _has_colors-strtab,0,0,STB_GLOBAL,STT_FUNC,0,0
 Elf64_Sym _init_color-strtab,0,0,STB_GLOBAL,STT_FUNC,0,0
 Elf64_Sym _init_extended_color-strtab,0,0,STB_GLOBAL,STT_FUNC,0,0
 Elf64_Sym _init_extended_pair-strtab,0,0,STB_GLOBAL,STT_FUNC,0,0
 Elf64_Sym _init_pair-strtab,0,0,STB_GLOBAL,STT_FUNC,0,0
 Elf64_Sym _extended_color_content-strtab,0,0,STB_GLOBAL,STT_FUNC,0,0
 Elf64_Sym _extended_pair_content-strtab,0,0,STB_GLOBAL,STT_FUNC,0,0
 Elf64_Sym _wbkgd-strtab,0,0,STB_GLOBAL,STT_FUNC,0,0

 Elf64_Rela  has_colors,401,R_X86_64_64
 Elf64_Rela  init_color,402,R_X86_64_64
 Elf64_Rela  init_extended_color,403,R_X86_64_64
 Elf64_Rela  init_extended_pair,404,R_X86_64_64
 Elf64_Rela  init_pair,405,R_X86_64_64
 Elf64_Rela  extended_color_content,406,R_X86_64_64
 Elf64_Rela  extended_pair_content,407,R_X86_64_64
 Elf64_Rela  wbkgd,408,R_X86_64_64

# SYMBOLS LIKE THIS 

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
 _initscr db "initscr", 0
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

 define COLOR_BLACK    0
 define COLOR_RED      1
 define COLOR_GREEN    2
 define COLOR_YELLOW   3
 define COLOR_BLUE     4
 define COLOR_MAGENTA  5
 define COLOR_CYAN     6
 define COLOR_WHITE    7

 define BLACK_ON_YELLOW 1


; define COLOR_PAIR(n) ((n) << (8))                    <<-- (FASM CANT DO - ??)

This is how you get colour pairs to work in NASM like:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  mov rdx, COLOR_YELLOW
  mov rsi, COLOR_BLACK
  mov rdi, BLACK_ON_YELLOW
  call init_pair
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# ON FASM JUST NO WAY TO DEFINE THE MACRO LIKE BELOW
#
#  COLOR_PAIR(BLACK_ON_YELLOW)                  <<--(HOW TO GET THIS - ?)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   mov esi, COLOR_PAIR(BLACK_ON_YELLOW)
   mov edi, [hWindow]
   call wattron
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    

If anyone knows how i can get FASM with:

format ELF64 executable 3
use64

to recognize the [ define COLOR_PAIR(n) ((n) << (8)) ], like NASM does

I basically just need to get ncurses to recognise the colour pallet values

like [ call init_pair ] generates to shorts or ints

so if anybody can help me on this , its down to FASM not being able to

recognise the %define like NASM does the macro cant change colour

Anyone no what i mean lol, rerally needed to figure this out, wonder

if there is maybe to or the values together but still dont know how

ncurses is going to work as macro will never work. ??

Edit by revolution: Added code tags

_________________
d.bonas
Post 06 Dec 2024, 16:38
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 06 Dec 2024, 16:52
Code:
BLACK_ON_YELLOW_PAIR = BLACK_ON_YELLOW shl 8
;...
   mov esi, BLACK_ON_YELLOW_PAIR
;...    
Post 06 Dec 2024, 16:52
View user's profile Send private message Visit poster's website Reply with quote
duanebonas6822



Joined: 06 Dec 2024
Posts: 22
duanebonas6822 06 Dec 2024, 16:55
Anybody who reads, what im trying to do is run FASM remotely as exploit and use ncurses to display differant windows that i could revert and connect to forkpty and openpty, I already have execve bash working with a pty through child, im just trying to get ncurses colour to work and it just seems like the C syntax isnt going to work, all my other C libs like scanf all work but like stated above NCURSES has syntax via define that wont work with FASM , if anyone knows what i mean or knows how to get ncurses working with colour that is direxctly in ncurses not some old dos format, my program is huge to upload all its just the basic colour help i need. thanks if anyone reading
Post 06 Dec 2024, 16:55
View user's profile Send private message Reply with quote
duanebonas6822



Joined: 06 Dec 2024
Posts: 22
duanebonas6822 06 Dec 2024, 17:01
ok ill have a look soon, report if get this working
Post 06 Dec 2024, 17:01
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 06 Dec 2024, 17:43
fasm doesn't have inline macros (aka functions). Making a macro might be useful to you.
Code:
macro PAIR colour { colour#_PAIR = colour shl 8 }
PAIR   BLACK_ON_YELLOW
;...
   mov esi, BLACK_ON_YELLOW_PAIR
;...    
Post 06 Dec 2024, 17:43
View user's profile Send private message Visit poster's website Reply with quote
duanebonas6822



Joined: 06 Dec 2024
Posts: 22
duanebonas6822 06 Dec 2024, 18:03
I still cant get it to work what i need is the total equivilant of:

;define COLOR_PAIR(n) ((n) << (Cool)

NASM needs the COLOR_PAIR specific keyword to work, i just get confused how C header which is the exactly as above gets mapped
to my fully statically PIC manually configured FASM binary,

so what would it look like when i call;

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mov rsi, COLOR_PAIR(BLACK_ON_YELLOW)
mov rdi, [hWindow]
call wattron
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

or

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mov rsi, COLOR_PAIR(BLACK_ON_YELLOW)
mov rdi,[hWindow]
call wbkgd
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

; I know this confusing on FASM my background just goes yellow with wbkgd
but fasm needs this COLOR_PAIR macro, its not a function so doesnt gets
called just anyone knows, its only summet simple i think
Post 06 Dec 2024, 18:03
View user's profile Send private message Reply with quote
duanebonas6822



Joined: 06 Dec 2024
Posts: 22
duanebonas6822 06 Dec 2024, 18:19
yeah i think a macro might be the way, its just figuring out how to get this macro to convert to FASM, as im not moving to NASM, FASM is the only way i can build a exploit binary that is PIE OR PIC when u run readelf, This matters a lot like, i can remotely just connect to any machine and launch SUID ROOT commands, Also i think if a binary is PIE or PIC commands can just be run which doesnt even matter if they have NULLS, There is loads of other C like commands i need to convert like this, Im gonna have a look into macros in bit, But can you just confirm that i should be able to get these NCURSES colors working by messing on with what im going on about, people don't realize how stress full it is writing exploits , especially in assembley as everybody writes in different ways, i like structure to my code, like my code readable but assembly rocks the amount of memory unsafe commands i am able to launch from these FASM suid binary's is unbelievable, once my binary is remote its just a matter of breaking the shell out of the environment, that's why ncurses is needed can run commands in different windows for different output, thats my plan , thanks for anybody tho that knows what im on bout
Post 06 Dec 2024, 18:19
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 06 Dec 2024, 18:29
You can try to make COLOR_PAIR an equate
Code:
COLOR_PAIR equ 256 *    
Then it gets replaced to:
Code:
mov rsi, 256 * (BLACK_ON_YELLOW)    
Post 06 Dec 2024, 18:29
View user's profile Send private message Visit poster's website Reply with quote
duanebonas6822



Joined: 06 Dec 2024
Posts: 22
duanebonas6822 06 Dec 2024, 18:41
yeah im gonna have a look at some macros and that later, yeah i think the equ just makes it equal to whatever, i know when i set pty values i just do this like or:


or dword [c_cc], VEOL + VEOL2 + VREPRINT + VSWTC + VERASE + VWERASE + VLNEXT
mov rdi, 7
mov rsi, 0x5402
mov rdx, termios
mov rax, 0x10

maybe i can or together values i dunno gonna read over macros later, but for any TUI programs color support is essential
Post 06 Dec 2024, 18:41
View user's profile Send private message Reply with quote
duanebonas6822



Joined: 06 Dec 2024
Posts: 22
duanebonas6822 06 Dec 2024, 19:09
; ANYONE NCURSES NOTE

You have to use attr_on or attr_set if you want to use a color pair number greater than 255, and you must not use the COLOR_PAIR macro
(because that will mask the color pair number to 8 bits)
This is somewhat explained in the attron/attr_on manpage but not very well

Still finding info but not sure the COLOR_PAIR macro is even needed, i will post once i get colours working, just know a few ppl might be messing on with TUI apps, little things like this come in handy..
Post 06 Dec 2024, 19:09
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.