hi,

I would like to ask for help concerning the following problem:

I set up a fli4l linux router which should also send me received faxmessages as email attachments.
I need a program which is started like "/usr/local/bin/base64encode \${PDF} \${PDF} | utod >> smtp.cmd"
in order to receive a base64 encoded arttachment instead of the now installed uuencode program.
It works already with uuencode but my email client (I'm used to it) doesn't decode uuencoded attachments, so I need a base64 encoder with about the same functionality as uuencode.
What would help me very much is a program frame for fasm which which gets the 2 environment variables \$PDF (filenames) and can manage the appended output to "| utod >> smtp.cmd" - without the encoding routine which shouldn't be so difficult for me.
I could do it in win32 but I have never coded a linux program before.

Thanks in advance
wolf
Posted on 2003-04-20 04:23:42 by wolf


bazik@exodus bazik $ emerge -s base64
Searching...
[ Results for search key : base64 ]
[ Applications found : 2 ]
* net-mail/base64
Latest version available: 1.3
Latest version installed: [ Not Installed ]
Size of downloaded files: 173 kB
Homepage: [url]http://www.fourmilab.ch/webtools/base64/[/url]
Description: Command line program that encodes/decodes files in base64
[...]


But I'll see if I can hack a assembly programm together :)
Posted on 2003-04-20 05:17:46 by bazik
Thanks a lot!

I think this is exactly the program I need. But as the fli4l-router http://www.fli4l.de is only a very minimal linux installation, I would need a compiled binary and had to hope that it is running with kernel 2.2.19.
You seem to use a smart search machine or use it that way respectively! I found some valuable infos but not this site.

wolf
Posted on 2003-04-20 07:04:11 by wolf
As I dont know which version of GCC us used for fli4l, I compiled that base64 programm static for you.
Posted on 2003-04-20 07:37:55 by bazik
bazik, again, thank you!

I get an "Illegal Instruction" message when calling base64. But anyway - just by chance I discovered that uuencode has a switch -m which will encode the data with base64. Now I can read the fax as attachment though scanlines are doubled. But this is a different matter.
Nevertheless I'm still interested in a linux asmprog skeleton which gets the commandline and handles output just like uuencode or base64.

wolf
Posted on 2003-04-20 10:53:26 by wolf
Exploiting some of the fasm for linux sources (thanks to Privalov) I managed to get a working binary.
There is also a useful site for linux system calls: http://www.lxhp.in-berlin.de/index-lx.shtml

Here is my code:



; fasm implementation of a base64 encoder
; usage: scibase64 filename

format ELF executable
entry start

O_RDONLY=0

section readable writeable

basecode db 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',0

cmderr db 'scibase64 - scientix base64 encoder v1.0',13,10,'usage: scibase64 sourcefile',13,10
cmderr_size = $-cmderr

ferr db 'scibase64 - scientix base64 encoder v1.0',13,10,'file not found',13,10
ferr_size = $-ferr

buff dd ?
fdin dd ?
line dd ?


section readable executable

start:
mov dword[line],0
pop eax ; number of commandline strings no.1 = prog no.2...no.n = arg 1 .. arg n
cmp eax,2 ; one argument
jne cmderror
pop eax ; pointer to progname
pop ebx ; pointer to arg 1 (filename)

call open
call base64
call close

exit:
mov eax,1
xor ebx,ebx
int 0x80


base64:
mov eax,3
mov ebx,[fdin]
mov ecx,buff
mov edx,3
int 80h
cmp eax,3
jne .eof
lea ecx,[buff]
mov al,byte[ecx]
shl eax,8
mov al,byte[ecx+1]
shl eax,8
mov al,byte[ecx+2]

xor edx,edx
xor ebx,ebx
mov dl,al
and dl,3Fh
lea ecx,[basecode]
mov bl,byte[ecx+edx]
shl ebx,8

shr eax,6
mov dl,al
and dl,3Fh
mov bl,byte[ecx+edx]
shl ebx,8

shr eax,6
mov dl,al
and dl,3Fh
mov bl,byte[ecx+edx]
shl ebx,8

shr eax,6
mov dl,al
and dl,3Fh
mov bl,byte[ecx+edx]

call outlong
inc [line]
cmp [line],17
jne base64
call newline
mov dword[line],0
jmp base64

.eof:
cmp eax,2
jne .oneleft
xor eax,eax
lea ecx,[buff]
mov al,byte[ecx]
shl eax,8
mov al,byte[ecx+1]

xor edx,edx
xor ebx,ebx
mov bl,'='
shl ebx,8
mov dl,al
and dl,3Fh
lea ecx,[basecode]
mov bl,byte[ecx+edx]
shl ebx,8

shr eax,6
mov dl,al
and dl,3Fh
mov bl,byte[ecx+edx]
shl ebx,8

shr eax,6
mov dl,al
and dl,3Fh
mov bl,byte[ecx+edx]

call outlong
call newline
jmp .finish

.oneleft:
cmp eax,1
jne .last
xor eax,eax
lea ecx,[buff]
mov al,byte[ecx]
xor edx,edx
xor ebx,ebx
mov bx,'=='
shl ebx,16
mov dl,al
and dl,3Fh
lea ecx,[basecode]
mov bl,byte[ecx+edx]
shl ebx,8

shr eax,6
mov dl,al
and dl,3Fh
mov bl,byte[ecx+edx]

call outlong
.last:
call newline

.finish:
ret


outlong: ; four bytes base64 output for three bytes input
mov dword[buff],ebx
mov eax,4
mov ebx,1
mov ecx,buff
mov edx,4
int 80h
ret


newline:
mov word[buff],0D0Ah
mov eax,4
mov ebx,1
mov ecx,buff
mov edx,2
int 80h
ret

open:
mov eax,5 ; ptr to filename is in ebx already
mov ecx,O_RDONLY
xor edx,edx
int 80h
test eax,eax
js ferror
mov [fdin],eax ; eax = file descriptor of input file
ret

close:
mov eax,6
mov ebx,[fdin]
int 80h
ret

cmderror:
mov ecx,cmderr
mov edx,cmderr_size
jmp error

ferror:
mov ecx,ferr
mov edx,ferr_size

error:
mov eax,4
mov ebx,1
int 80h
jmp exit

wolf
Posted on 2003-04-22 13:16:52 by wolf
Cool :cool:

Great work :alright:

Maybe this can be of some use for you aswell:

(remove .gz extension and unpack with "tar -jxvf asmutils.tar.bz2")
Posted on 2003-04-22 13:23:32 by bazik
What's the point of gzipping a bzip2 compressed file?
Posted on 2003-04-22 15:33:24 by comrade

What's the point of gzipping a bzip2 compressed file?


I didnt say that I gzipped it, I just added the extension because bz2 is not allowed on that board and as gzip it would be over the 300k limit.
Posted on 2003-04-22 15:38:33 by bazik
I found a mistake in the posted code:
beneath the label .oneleft: shl ebx,16 is wrong - it must be shl ebx,8 instead.
for those who urgently need a base64 en/decoder ;) I attach scibase64.asm

wolf
Posted on 2003-04-23 03:42:19 by wolf