From: Evenbit on
On Apr 13, 2:46 am, Frank Kotler <fbkot...(a)verizon.net> wrote:
> Evenbit wrote:
> > On Apr 12, 11:45 pm, "Evenbit" <nbaker2...(a)charter.net> wrote:
>
> >>Speaking of mess (locally and on the net), I have been looking all
> >>over but still can't find the all the magic numbers I need to make
> >>Linux sys-calls. Does anyone know the value for the 'flags' argument
> >>to 'sys_open' when you want it read only? I know that sys_open is 5.
>
> > Nevermind -- I found it! Jeff Owen to my rescue...
>
> > ; file_open - open named file
> > ; INPUTS
> > ; ebx = ptr to full file path
> > ; ecx = access flags
> > ; O_RDONLY 00
> > ; O_WRONLY 01
> > ; O_RDWR 02
> > ;
> > ; O_CREAT 0100
> > ; O_EXCL 0200
> > ; O_NOCTTY 0400
> > ; O_TRUNC 01000
> > ; O_APPEND 02000
> > ; O_NONBLOCK 04000
> > ; O_NDELAY O_NONBLOCK
> > ; O_SYNC 010000 specific to ext2 fs and block devices
> > ; FASYNC 020000 fcntl, for BSD compatibility
> > ; O_DIRECT 040000 direct disk access hint-currently
> > ignored
> > ; O_LARGEFILE 0100000
> > ; O_DIRECTORY 0200000 must be a directory
> > ; O_NOFOLLOW 0400000 don't follow links;
> > ;
> > ; edx = permissions used if file created
> > ; S_ISUID 04000 set user ID on execution
> > ; S_ISGID 02000 set group ID on execution
> > ; S_ISVTX 01000 sticky bit
> > ; S_IRUSR 00400 read by owner(S_IREAD)
> > ; S_IWUSR 00200 write by owner(S_IWRITE)
> > ; S_IXUSR 00100 execute/search by owner(S_IEXEC)
> > ; S_IRGRP 00040 read by group
> > ; S_IWGRP 00020 write by group
> > ; S_IXGRP 00010 execute/search by group
> > ; S_IROTH 00004 read by others
> > ; S_IWOTH 00002 write by others
> > ; S_IXOTH 00001 execute/search by others
> > ; OUTPUT
> > ; eax = negative if error (error number)
> > ; eax = positive file handle if success
> > ; flags are set for js jns jump
>
> Note that those numbers are *octal* (leading 0)!

Thanks for the "heads-up"!

> I'm fairly sure HLA
> knows these equates, but named in lowercase "linux.o_rdonly", etc.

But I'm trying to do something in Nasmese! ;) It has been "a while"
and my memory fails. Still trying to recall where I stashed all those
previous code examples. I just "guessed" at the numbers for stdin &
stdout and got lucky. :)

Yeppers, I scrolled right past them earlier (we're always "blind" when
we are *looking* for stuff) but here they are in 'linux.hhf' --

o_rdonly := 0;
o_wronly := 1;
o_rdwr := 2;
o_accmode := 3;
o_creat := $40;
o_excl := $80;
o_noctty := $100;
o_trunc := $200;
o_append := $400;
o_noblock := $800;
o_ndelay := o_noblock;
o_sync := $1000;
o_fsync := o_sync;
o_async := $2000;

o_direct := $4000;
o_largefile := $8000;
o_directory := $1_0000;
o_nofollow := $2_0000;
o_atomiclookup := $20_0000;

s_isuid := %100_000_000_000;
s_isgid := %010_000_000_000;
s_isvtx := %001_000_000_000;
s_iread := usr_r;
s_iwrite:= usr_w;
s_iexec := usr_x;
s_irgrp := grp_r;
s_iwgrp := grp_w;
s_ixgrp := grp_x;
s_iroth := all_r;
s_iwoth := all_w;
s_ixoth := all_x;

s_irwxu := usr_r | usr_w | usr_x;
s_irwxg := grp_r | grp_w | grp_x;
s_irwxo := all_r | all_w | all_x;

Nathan.

From: Frank Kotler on
Evenbit wrote:
> On Apr 13, 12:36 am, Charles Crayne <charles.cra...(a)crayne.org> wrote:
>
>>On 12 Apr 2007 20:45:15 -0700
>>
>>"Evenbit" <nbaker2...(a)charter.net> wrote:
>>
>>>I know that sys_open is 5.
>>
>>Yes, in 32-bit mode, but they renumbered all the sys calls for 64-bit
>>mode, so, to plan for the future, you should use an include file, rather
>>than code the actual numbers.
>
>
> Tell that to Frank. He's been setting a bad example here these past
> couple of years. ;)

S'true. My excuse is that I don't want to include the whole include
file, nor require anyone to possess a particular include file. In my
defense, I usually write it as:

mov eax, 5 ; __NR_open

so that it can be "fixed" with the delete key, if/when one obtains such
a file. I think "__NR_open" is uglier than a bulldog's hind end, and
would prefer "sys_open", but that's how C calls 'em...

Converting code to 64-bit is going to require more than just changing
the call numbers, I'm afraid. First parameter goes in rdi, not ebx. Even
if you "just call printf", it's different. Almost enough to make one
wish one were a HLL coder! Almost... :)

Best,
Frank
From: Evenbit on
On Apr 13, 4:11 am, Frank Kotler <fbkot...(a)verizon.net> wrote:
> Converting code to 64-bit is going to require more than just changing
> the call numbers, I'm afraid. First parameter goes in rdi, not ebx. Even
> if you "just call printf", it's different. Almost enough to make one
> wish one were a HLL coder! Almost... :)

Just looking at the pile-of-hay in "strings.c" at [ http://www.chkrootkit.org/
] should be enough to keep anyone away from HLLs! Even a/b's code
looks more appetizing. I did a quick "sans libs" HLA version for
Winders:

program mystrings;

#include( "w.hhf" )



var

hInput :dword;

hOutput :dword;

got :dword;

buff :byte[4];

temp :byte[128];



begin mystrings;



w.GetStdHandle( w.STD_INPUT_HANDLE );

mov( eax, hInput );

w.GetStdHandle( w.STD_OUTPUT_HANDLE );

mov( eax, hOutput );

mov( 0, ecx );

lea( ebx, temp[0] );



forever



push( ebx );

push( ecx );

w.ReadFile( hInput, buff[0], 1, got, NULL );

pop( ecx );

pop( ebx );

mov( got, eax );

breakif ( eax = 0 );

mov( buff[0], al );

if ( al < 32 ) then

continue;

endif;

if ( al > 126 ) then

continue;

endif;

mov( al, [ebx+ecx] );

inc( ecx );

if ( ecx = 4 ) then



forever



push( ebx );

push( ecx );

w.ReadFile( hInput, buff[0], 1, got, NULL );

pop( ecx );

pop( ebx );

mov( got, eax );

breakif ( eax = 0 );

mov( buff[0], al );

if ( al < 32 ) then

break;

endif;

if ( al > 126 ) then

break;

endif;

mov( al, [ebx+ecx] );

inc( ecx );

breakif ( ecx = 124 );



endfor;



mov( 13, al );

mov( al, [ebx+ecx] );

inc( ecx );

mov( 10, al );

mov( al, [ebx+ecx] );

inc( ecx );

mov( 0, al );

mov( al, [ebx+ecx] );

push( ebx );

w.WriteFile( hOutput, temp[0], ecx, got, NULL );

pop( ebx );

mov( 0, ecx );



endif;



endfor;



end mystrings;


As you can see, I will still need to do a non-HLA version to get away
from that "baby-bottle" feeling.

Nathan.

From: Frank Kotler on
Evenbit wrote:

....
> But I'm trying to do something in Nasmese! ;)

The include files with the asmutils package from
http://www.linuxassembly.org might be a good bet. Kind of a PITA to use
- you've gotta define an OS - but if you define BSD, you get the BSD
style int 80h call, and other subtle differences... In BSD, the dirent
structure includes a file type. In Linux, we need to call "stat" to find
out if a dirent is a file, or subdirectory, or what. If you use the
equates and macros, you can get "portable" code that will assemble for
Linux or BSD (and some others) just by changing a command line switch.
Almost like HLA... only not portable to Windows.

The asmutils macros do not include any 64-bit support (Nasm hasn't got
it for Linux yet), but could be expanded to cover it. If you use:

sys_write STDOUT, msg, msg_len

you don't need to know __NR_write or STDOUT, or whether the parameters
go in ebx, ecx, ... or rdi, rsi, ... or on the stack. The price you pay
is that it doesn't "show" as much...

Best,
Frank
From: Evenbit on
On Apr 13, 4:52 am, Frank Kotler <fbkot...(a)verizon.net> wrote:
> you don't need to know __NR_write or STDOUT, or whether the parameters
> go in ebx, ecx, ... or rdi, rsi, ... or on the stack. The price you pay
> is that it doesn't "show" as much...

....and once you start down *that* path...

....sooner or later you are creating a monstrous "standard library" and
adding nice "language features" to the compiler...

....and you find yourself back where you started in High Loopy
Land!! :)

Nathan.

First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8
Prev: DIV overflow
Next: RIP relative adresses