├── CREDITS ├── ChangeLog ├── MCONFIG ├── Makefile ├── README ├── TODO ├── bootdisk.bash ├── doc ├── Asmutils-HOWTO.html ├── acknowledgements.html ├── endorsements.html ├── history.html ├── index.html ├── s-contrib.html ├── s-debug.html ├── s-include.html ├── s-layout.html ├── s-optimize.html ├── sha1sum.html └── sha1sum_toc.html ├── inc ├── elf.inc ├── elfheader.inc ├── errno.inc ├── includes.inc ├── os_atheos.inc ├── os_beos.inc ├── os_bsd.inc ├── os_freebsd.inc ├── os_linux.inc ├── os_netbsd.inc ├── os_openbsd.inc ├── os_qnxrtp.inc ├── os_solaris.inc ├── os_unixware.inc ├── os_v2os.inc ├── syscall.inc └── system.inc ├── lib ├── Makefile ├── heap.asm ├── libc.asm ├── libc.h ├── libc_stub.asm ├── libm.c ├── md5.asm ├── rc6.asm ├── rmd.asm ├── test1.c ├── test2.c └── testm.c └── src ├── Makefile ├── basename.asm ├── bonus ├── asmutils.asm ├── execve.asm ├── fire256.asm ├── game.asm ├── hdragon.asm ├── leaves.asm ├── mandelbrot.asm ├── report.asm ├── snake.asm └── window.asm ├── cal.asm ├── cat.asm ├── cda2raw.asm ├── chmod.asm ├── chown.asm ├── chroot.asm ├── chvt.asm ├── cmp.asm ├── cp.asm ├── cpuinfo.asm ├── cut.asm ├── date.asm ├── dc.asm ├── dd.asm ├── deflate.asm ├── df.asm ├── dirname.asm ├── dmesg.asm ├── du.asm ├── echo.asm ├── eject.asm ├── env.asm ├── extname.asm ├── factor.asm ├── fdisk.asm ├── finger.asm ├── free.asm ├── fromdos.asm ├── ftpd.asm ├── getty.asm ├── gi.asm ├── grep.asm ├── head.asm ├── hexdump.asm ├── host.asm ├── hostname.asm ├── httpd.asm ├── id.asm ├── idea.asm ├── ifconfig.asm ├── init.asm ├── kill.asm ├── killall.asm ├── kldload.asm ├── ksyms.asm ├── less.asm ├── ln.asm ├── ls.asm ├── lsmod.asm ├── lsusb.asm ├── lzss.asm ├── m_inetd.asm ├── md5.asm ├── md5sum.asm ├── mesg.asm ├── mkdir.asm ├── mkfs.minix.asm ├── mknod.asm ├── mount.asm ├── mv.asm ├── nc.asm ├── netstat.asm ├── nice.asm ├── nm.asm ├── nohup.asm ├── od.asm ├── paste.asm ├── ping.asm ├── pop3d.asm ├── proxy.asm ├── ps.asm ├── pwd.asm ├── rc6crypt.asm ├── readelf.asm ├── readkey.asm ├── readlink.asm ├── reboot.asm ├── renice.asm ├── rm.asm ├── rmdsum.asm ├── rot13.asm ├── scan.asm ├── scons.asm ├── sh.asm ├── sha1sum.asm ├── sleep.asm ├── softdog.asm ├── strings.asm ├── swapon.asm ├── sync.asm ├── sysctl.asm ├── tail.asm ├── tar.asm ├── tee.asm ├── telnet.asm ├── telnetd.asm ├── test.asm ├── touch.asm ├── tr.asm ├── true.asm ├── truss.asm ├── tty.asm ├── uname.asm ├── update.asm ├── uptime.asm ├── users.asm ├── uuencode.asm ├── watch.asm ├── wc.asm ├── wget.asm ├── which.asm ├── whoami.asm ├── write.asm └── yes.asm /CREDITS: -------------------------------------------------------------------------------- 1 | This is at least a partial credits-file of people who have contributed 2 | to the asmutils project, in the Linux Kernel CREDITS format. 3 | 4 | Please notify project maintainer if you find any uncertain info here. 5 | 6 | It is sorted by name and formatted to allow easy grepping and 7 | beautification by scripts. The fields are: name (N), email (E), 8 | web-address (W), PGP key ID and fingerprint (P), description (D), 9 | and snail-mail address (S). 10 | 11 | $Id: CREDITS,v 1.20 2006/02/18 10:14:11 konst Exp $ 12 | 13 | ---------- 14 | 15 | N: Dmitry Bakhvalov (DB) 16 | E: dl@gazeta.ru 17 | D: cp.asm id.asm mv.asm ps.asm rm.asm strings.asm wc.asm 18 | 19 | N: Konstantin Boldyshev (KB) 20 | E: konst@linuxassembly.org 21 | D: original asmutils hacker 22 | 23 | N: Christopher Brannon (CB) 24 | E: cbrannon@wilnet1.com 25 | D: uuencode.asm 26 | 27 | N: Julius C. Duque (JD) 28 | E: jcduque@lycos.com 29 | D: sha1sum.asm 30 | 31 | N: Jorge Contreras A. (JC) 32 | E: aioros2000@hotmail.com 33 | D: users.asm 34 | 35 | N: Paul Furber (PF) 36 | E: paulf@gam.co.za 37 | D: fire256.asm, framebuffer stuff in os_linux.inc 38 | 39 | N: Tiago Gasiba (TG) 40 | E: ee97034@fe.up.pt 41 | D: fromdos.asm less.asm readkey.asm whoami.asm 42 | 43 | N: Alexandr Gorlov (AG) 44 | E: winct@mail.ru 45 | D: df.asm dirname.asm sh.asm 46 | 47 | N: Bart Hanssens (BH) 48 | E: antares@mail.dma.be 49 | D: eject.asm kill.asm 50 | 51 | N: Tani Hosokawa (TH) 52 | E: unknown@riverstyx.net 53 | D: initial OpenBSD port 54 | 55 | N: Maciej Hrebien (MH) 56 | E: m_hrebien@wp.pl 57 | D: idea.asm cda2raw.asm md5.asm 58 | 59 | N: Joshua Hudson (JH) 60 | E: joshudson@hotmail.com 61 | D: cut.asm dc.asm du.asm m_inetd.asm mkfs.minix.asm mknod.asm 62 | D: od.asm paste.asm readlink.asm tr.asm which.asm 63 | 64 | N: Yuri Ivliev (YI) 65 | E: yuru@black.cat.kazan.su 66 | D: pwd.asm (stat based part) 67 | 68 | N: Nick Kurshev (NK) 69 | E: nickols_k@mail.ru 70 | D: ksyms.asm lsusb.asm libm.c testm.c 71 | 72 | N: Scott Lanning (SL) 73 | E: slanning@theworld.com 74 | D: cal.asm netstat.asm 75 | 76 | N: Jonathan Leto (JL) 77 | E: jonathan@leto.net 78 | D: chown.asm head.asm renice.asm touch.asm 79 | 80 | N: Indrek Mandre (IM) 81 | E: indrek@mare.ee 82 | D: basename.asm chvt.asm dmesg.asm false.asm lsmod.asm 83 | D: httpd.asm proxy.asm rmmod.asm true.asm yes.asm 84 | 85 | N: Rudolf Marek (RM) 86 | E: marekr2@feld.cvut.cz 87 | D: dd.asm fdisk.asm game.asm heap.asm host.asm httpd.asm 88 | D: sh.asm tar.asm watch.asm 89 | 90 | N: Michal Medvecky (MM) 91 | E: m.medvecky@sh.cvut.cz 92 | D: pop3.asm 93 | 94 | N: Attila Monoses (AM) 95 | E: ata@email.ro 96 | D: ftpd.asm 97 | 98 | N: Jani Monoses (JM) 99 | E: jani@astechnix.ro 100 | D: ifconfig.asm ping.asm tail.asm 101 | 102 | N: Thomas Ogrisegg (TO) 103 | E: tom@rhadamanthys.org 104 | D: cmp.asm finger.asm free.asm getty.asm killall.asm mesg.asm 105 | D: nice.asm nm.asm nohup.asm rot13.asm scons.asm swapon.asm (mkswap extension) 106 | D: sysctl.asm test.asm truss.asm uptime.asm wget.asm write.asm 107 | D: initial Solaris and Unixware ports 108 | 109 | N: Edward Popkov (EP) 110 | E: evpopkov@carry.neonet.lv 111 | D: env.asm 112 | 113 | N: Brian Raiter (BR) 114 | E: breadbox@muppetlabs.com 115 | D: date.asm factor.asm hexdump.asm ls.asm snake.asm 116 | D: elf.inc 117 | 118 | N: H-Peter Recktenwald (PR) 119 | E: lx@lxhp.in-berlin.de 120 | D: cpuinfo.asm extname.asm eject.asm (ccd extension) 121 | D: report.asm errno.inc 122 | 123 | N: Radu Bogdan Rusu (RR) 124 | E: veedee@asmania.com 125 | D: readelf.asm elfheader.inc 126 | 127 | N: Stanislav Ryabenkiy (SR) 128 | E: stani@ryabenkiy.com 129 | D: scan.asm 130 | 131 | N: Karsten Scheibler (KS) 132 | E: karsten.scheibler@bigfoot.de 133 | D: init.asm sh.asm 134 | 135 | N: Cecchinel Stephan (CS) 136 | E: inter.zone@free.fr 137 | D: md5sum.asm rmdsum.asm lzss.asm nc.asm rc6crypt.asm 138 | D: rc6, md5, rmd160 algos (libcrypto) 139 | D: several libc functions 140 | 141 | N: Stephan Walter (SW) 142 | E: stephan.walter@gmx.ch 143 | D: deflate.asm mandelbrot.asm 144 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (C) 1999-2000 Konstantin Boldyshev 2 | # 3 | # Top Makefile for asmutils (GNU make is required) 4 | # 5 | # $Id: Makefile,v 1.1 2000/09/03 16:13:53 konst Exp $ 6 | 7 | include MCONFIG 8 | 9 | SUBDIRS = src lib 10 | DO_MAKE = @ for i in $(SUBDIRS); do $(MAKE) -C $$i $@; done 11 | 12 | all: $(SUBDIRS) 13 | $(DO_MAKE) 14 | 15 | clean: 16 | $(DO_MAKE) 17 | 18 | install: all 19 | $(DO_MAKE) 20 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | 2 | asmutils 3 | ******** 4 | 5 | (version 0.18) 6 | 7 | http://linuxassembly.org 8 | 9 | 10 | Legal stuff 11 | =========== 12 | 13 | All programs in this package are *copyrighted* by their authors, 14 | as stated in the source code and in the CREDITS file. The bulk 15 | of code is written by Konstantin Boldyshev, with contributions 16 | of various hackers all over the world. 17 | 18 | These programs are free software; you can redistribute and/or modify 19 | them under the terms of the version 2 (and only version 2) of the GNU 20 | General Public License as published by the Free Software Foundation. 21 | 22 | These programs are distributed in the hope that they will be useful, 23 | but WITHOUT ANY WARRANTY; without even the implied warranty 24 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 25 | See the version 2 of the GNU General Public License for more details 26 | . 27 | 28 | Authors are not responsible for any damage these programs can do. 29 | This is development version, use solely at your own risk. 30 | 31 | Description 32 | =========== 33 | 34 | asmutils is a set of miscellaneous utilities written in assembly language, 35 | targeted on embedded systems and small distributions (e.g. installation 36 | or rescue disks); also it contains a small libc and a crypto library. 37 | It features the smallest possible size and memory requirements, 38 | the fastest speed, and offers fairly good functionality. 39 | Now project supports Linux and BSD family (FreeBSD, OpenBSD, NetBSD); 40 | Unixware, Solaris, and AtheOS support is in beta stage (also there's 41 | no more supported BeOS port), and it is /theoretically/ possible to 42 | port it to any i386 OS. 43 | 44 | Another goal of this package is to provide a *portable* framework, 45 | and to encourage assembly programmers to write for Linux/UNIX. 46 | Usually UNIX is associated with C, and no one wants to deal with assembly.. 47 | Browse the source, look -- it is simple. Read the docs, start to write, 48 | and you will like it; assembly programming is a lot of fun, especially 49 | when you deal with a UNIX-like operating systems. 50 | 51 | In addition, this package has some "special bonus" like small intros, 52 | games, and other various assembly snippets. 53 | 54 | These utilities also may be useful for system administrators; 55 | there were several reports that they have rescued when libc 56 | crashed and it was not possible to use usual system utilities. 57 | 58 | Hey, we are a light in the darkness of bloatware. Do you see? 59 | 60 | How to install 61 | ============== 62 | 63 | REQUIREMENTS: 64 | 65 | 1) i386 (however some programs may require higher CPU); 66 | some programs may require FPU (or kernel emulation) 67 | 68 | 2) UNIX-like kernel 69 | 70 | 3) ELF/AOUT executable format (actually not a requirement, 71 | you just need to write startup stack preparation 72 | for your executable format on your own) 73 | 74 | For details on compilation process examine doc/Asmutils-HOWTO, 75 | then edit MCONFIG, run '[g]make' and hopefully all will be done. 76 | 77 | '[g]make install' creates bin directory in the source tree and stores 78 | compiled files there (it doesn't copy files elsewhere, neither to /bin 79 | or /usr/bin, nor to /usr/local/bin). 80 | 81 | You may also want to examine a-Linux -- a floppy-based mini-distribution 82 | consisting of Linux kernel and asmutils; it is available for download 83 | from the asmutils homepage as well. 84 | 85 | WARNING: 86 | 87 | Before using any utility first DO LOOK AT ITS SYNTAX; some utils may 88 | work not as you have expected. Syntax can be found in the appropriate 89 | source file (.asm) from the src directory (do not expect any answer 90 | from program on --help switch or without switches). 91 | 92 | 93 | Feedback 94 | ======== 95 | 96 | Contributions are welcome! If you want to contribute some code, 97 | please read the Asmutils-HOWTO in the doc directory. 98 | At least send a bugreport or a success story :) 99 | 100 | $Id: README,v 1.17 2006/02/18 10:13:42 konst Exp $ 101 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | long-term: 2 | 3 | - write new utils and improve existing 4 | - develop libc 5 | - develop multicall binary 6 | - port more code to *BSD 7 | 8 | short-term: 9 | 10 | - develop QNXRTP port 11 | - test AtheOS code 12 | - merge basename, dirname, extname (?) 13 | -------------------------------------------------------------------------------- /doc/acknowledgements.html: -------------------------------------------------------------------------------- 1 | Acknowledgements

B. Acknowledgements

I would like to thank following persons for contributing to this document: 77 | 78 |

  • Brian Raiter (elf.inc description)

  • Dmitry Bakhvalov (using gdb)

-------------------------------------------------------------------------------- /doc/endorsements.html: -------------------------------------------------------------------------------- 1 | Endorsements

C. Endorsements

This version of the document is endorsed by 70 | Konstantin Boldyshev.

Modifications (including translations) must remove this appendix 76 | according to the license agreement.

$Id: Asmutils-HOWTO.sgml,v 1.20 2006/02/18 10:08:03 konst Exp $

-------------------------------------------------------------------------------- /doc/index.html: -------------------------------------------------------------------------------- 1 | Asmutils-HOWTO.html -------------------------------------------------------------------------------- /doc/s-layout.html: -------------------------------------------------------------------------------- 1 | Program layout

2. Program layout

There are three macros that make section definition as simple as possible: 77 | CODESEG, 81 | DATASEG and 85 | UDATASEG 89 | (similar to tasm ideal mode syntax). 93 | END macro marks end of file.

A program should have at least CODESEG (.text) section 102 | and END macro, other sections are optional. 106 | CODESEG is read-only, 110 | DATASEG and UDATASEG are read-write; 117 | i.e. you can place data in CODESEG 121 | as long as you do not change it. 122 | You can also define your own sections if you want, but there's very rare need 123 | to do so. Each section (even if it is empty) enlarges your executable.

START macro tells linker the entry point, 129 | and must be present (if you are not making a library).

Thus, a program's skeleton should look like:

%include "system.inc"
142 | 
143 | CODESEG
144 | 
145 | START:			;entry point
146 | 
147 | 			;code
148 | 
149 | DATASEG
150 | 
151 | 			;data
152 | 
153 | UDATASEG
154 | 
155 | 			;bss
156 | 
157 | END

-------------------------------------------------------------------------------- /doc/sha1sum_toc.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Hacker's SHA-1 Documentation - Table of Contents 6 | 7 | 8 |

Hacker's SHA-1 Documentation

9 |

Programmer's Guide (Edition 1.0)

10 |
Julius C. Duque
11 |

12 |


13 |

22 |


23 | This document was generated on 18 February 2006 using 24 | texi2html 1.56k. 25 | 26 | 27 | -------------------------------------------------------------------------------- /inc/os_qnxrtp.inc: -------------------------------------------------------------------------------- 1 | ; Copyright (C) 2001 Konstantin Boldyshev 2 | ; 3 | ; $Id: os_qnxrtp.inc,v 1.2 2002/02/02 12:33:39 konst Exp $ 4 | ; 5 | ; file : os_qnxrtp.inc 6 | ; created : 16-Aug-2001 7 | ; modified : 20-Aug-2001 8 | ; version : 0.15 9 | ; assembler : nasm 0.98 10 | ; description : QNX RTP 6.1.0 kernel constants 11 | ; author : Konstantin Boldyshev 12 | ; comment : included from system.inc 13 | 14 | %ifndef __SYSTEM_INC 15 | %error "this file must be included from system.inc !" 16 | %endif 17 | 18 | %ifndef __QNXRTP_INC 19 | %define __QNXRTP_INC 20 | 21 | %macro DO_SYSCALL 0 22 | %if __OPTIMIZE__=__O_SIZE__ 23 | push ebp 24 | push edi 25 | push esi 26 | push edx 27 | push ecx 28 | push ebx 29 | push eax 30 | %endif 31 | int 0x28 32 | %if __OPTIMIZE__=__O_SIZE__ 33 | add esp,byte 7*4 34 | %endif 35 | %endmacro 36 | 37 | %macro SYSCALL_GATE 0 38 | __syscall_gate: 39 | 40 | DO_SYSCALL 41 | ret 42 | %endmacro 43 | 44 | %endif 45 | -------------------------------------------------------------------------------- /inc/os_v2os.inc: -------------------------------------------------------------------------------- 1 | ; Copyright (C) 2000 Konstantin Boldyshev 2 | ; 3 | ; $Id: os_v2os.inc,v 1.2 2002/02/02 12:33:39 konst Exp $ 4 | ; 5 | ; file : os_v2os.inc 6 | ; created : 13-Oct-2000 7 | ; modified : 13-Oct-2000 8 | ; version : 0.11 9 | ; assembler : nasm 0.98 10 | ; description : v2os kernel constants 11 | ; author : Konstantin Boldyshev 12 | ; comment : included from system.inc 13 | 14 | %ifndef __SYSTEM_INC 15 | %error "this file must be included from system.inc !" 16 | %endif 17 | 18 | %ifndef __V2OS_INC 19 | %define __V2OS_INC 20 | 21 | %assign SYS_open 0 22 | %assign SYS_close 1 23 | %assign SYS_read 2 24 | %assign SYS_write 3 25 | %assign SYS_ioctl 4 26 | %assign SYS_lseek 5 27 | %assign SYS_time 7 28 | %assign SYS_opendir 0x0c 29 | %assign SYS_closedir 0x0f 30 | %assign SYS_rewinddir 0x17 31 | %assign SYS_reboot 0x18 32 | %assign SYS_readdir 0x1c 33 | %assign SYS_mkdir 0x1e 34 | %assign SYS_symlink 0x1f 35 | %assign SYS_readlink 0x23 36 | %assign SYS_rename 0x26 37 | %assign SYS_unlink 0x27 38 | %assign SYS_mount 0x31 39 | %assign SYS_exit 0x3f 40 | %assign SYS_umount 0x40 41 | %assign SYS_dup2 0x4a 42 | %assign SYS_chdir 0x57 43 | %assign SYS_access 0x58 44 | %assign SYS_statfs 0x5f 45 | %assign SYS_rmdir 0x60 46 | %assign SYS_link 0x6e 47 | %assign SYS_sync 0x6f 48 | %assign SYS_sigaction 0x70 49 | %assign SYS_sigpending 0x71 50 | %assign SYS_pause 0x72 51 | %assign SYS_sigsuspend 0x72 52 | %assign SYS_kill 0x74 53 | %assign SYS_stime 0x76 54 | %assign SYS_getgid 0x77 55 | %assign SYS_getpgrp 0x78 56 | %assign SYS_alarm 0x79 57 | %assign SYS_getppid 0x7a 58 | %assign SYS_getuid 0x7b 59 | %assign SYS_setgid 0x7c 60 | %assign SYS_setpgid 0x7d 61 | %assign SYS_setsid 0x7e 62 | %assign SYS_setuid 0x7f 63 | 64 | %assign SYS_fork 0xa1 65 | %assign SYS_execve 0xa2 66 | %assign SYS_waitpid 0xa3 67 | %assign SYS_gettimeofday 0xa6 68 | 69 | %assign SYS_readv 0xbf 70 | %assign SYS_writev 0xc0 71 | 72 | 73 | %endif 74 | -------------------------------------------------------------------------------- /lib/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (C) 1999-2001 Konstantin Boldyshev 2 | # 3 | # Makefile for libc (GNU make is required) 4 | # 5 | # $Id: Makefile,v 1.12 2006/02/18 09:39:33 konst Exp $ 6 | 7 | # Target CPU (386,486,586,686) 8 | 9 | CPU = 386 10 | 11 | # 12 | 13 | DEBUG = y 14 | 15 | BUILD_LIB = y 16 | 17 | include ../MCONFIG 18 | 19 | BUILD_STATIC = y 20 | BUILD_SHARED = y 21 | 22 | LIBCRYPTO_OBJS = md5.o rc6.o rmd.o 23 | LIBCRYPTO_A = libcrypto.a 24 | LIBCRYPTO_SO = libcrypto.so.0 25 | 26 | STUB_OBJS = libc_stub.o 27 | 28 | LIBC_OBJS = libc.o 29 | LIBC_A = libc.a 30 | LIBC_SO = ./libc.so.0 31 | 32 | LIBM_OBJS = libm.o 33 | LIBM_A = libm.a 34 | LIBM_SO = ./libm.so.0 35 | 36 | CTESTS = test1 test2 37 | 38 | CLEAN_CFLAGS := -D__CPU__=$(CPU) -Wall -O1 -Os -march=i386 39 | 40 | ifdef DEBUG 41 | CLEAN_CFLAGS += -g 42 | else 43 | CLEAN_CFLAGS += -fomit-frame-pointer 44 | endif 45 | 46 | CFLAGS := $(CLEAN_CFLAGS) 47 | 48 | %.o: %.c 49 | $(CC) $(CLEAN_CFLAGS) -c -o $@ $< 50 | 51 | # we are testing our own library, not glibc headers and gcc inlines 52 | # so, disable the damn thing 53 | 54 | CFLAGS += -D__NO_STRING_INLINES -fno-builtin 55 | 56 | # the same with all other glibc crap 57 | 58 | CFLAGS += -nostartfiles -nostdlib 59 | #-Wl,-e,main? 60 | 61 | %: %.c 62 | ifdef BUILD_SHARED 63 | $(CC) $(CFLAGS) -o $@-shared $< $(STUB_OBJS) $(LIBC_SO) 64 | $(CC) $(CFLAGS) -mregparm=3 -D__FASTCALL__\ 65 | -o $@-shared-fastcall $< $(STUB_OBJS) $(LIBC_SO) 66 | endif 67 | ifdef BUILD_STATIC 68 | $(CC) $(CFLAGS) -static -o $@-static $< $(STUB_OBJS) $(LIBC_A) 69 | $(CC) $(CFLAGS) -static -mregparm=3 -D__FASTCALL__\ 70 | -o $@-static-fastcall $< $(STUB_OBJS) $(LIBC_A) 71 | endif 72 | 73 | all: libc libm crypto testc testm 74 | 75 | libc: $(LIBC_OBJS) $(STUB_OBJS) 76 | ifdef BUILD_STATIC 77 | $(AR) rcv $(LIBC_A) $(LIBC_OBJS) 78 | endif 79 | ifdef BUILD_SHARED 80 | $(LD) $(LDFLAGS) -shared -soname $(LIBC_SO) \ 81 | -o $(LIBC_SO) $(LIBC_OBJS) 82 | endif 83 | 84 | libm: $(LIBM_OBJS) 85 | ifdef BUILD_STATIC 86 | $(AR) rcv $(LIBM_A) $(LIBM_OBJS) 87 | endif 88 | ifdef BUILD_SHARED 89 | $(LD) $(LDFLAGS) -shared -soname $(LIBM_SO) \ 90 | -o $(LIBM_SO) $(LIBM_OBJS) 91 | endif 92 | 93 | crypto: $(LIBCRYPTO_OBJS) 94 | ifdef BUILD_STATIC 95 | $(AR) rcv $(LIBCRYPTO_A) $(LIBCRYPTO_OBJS) 96 | endif 97 | ifdef BUILD_SHARED 98 | $(LD) $(LDFLAGS) -shared -soname $(LIBCRYPTO_SO) \ 99 | -o $(LIBCRYPTO_SO) $(LIBCRYPTO_OBJS) 100 | endif 101 | 102 | #CRYPTOFILES = ../src/md5sum.o 103 | #cryptofiles: $(CRYPTOFILES) 104 | # ld -s -o aaa $(CRYPTOFILES) libcrypto.a 105 | 106 | ifdef AOUT 107 | testc: 108 | testm: 109 | else 110 | testc: $(CTESTS) 111 | 112 | # 113 | # Build it with usual libc for now 114 | # 115 | 116 | testm: testm.c 117 | ifdef BUILD_SHARED 118 | $(CC) $(CLEAN_CFLAGS) -o $@-shared $< $(LIBM_SO) 119 | endif 120 | ifdef BUILD_STATIC 121 | $(CC) $(CLEAN_CFLAGS) -o $@-static $< $(LIBM_A) 122 | endif 123 | 124 | endif 125 | 126 | install: 127 | 128 | clean: 129 | rm -f *.o *.a *.so* $(TESTS) *-shared* *-static* 130 | -------------------------------------------------------------------------------- /lib/libc.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 1999-2001 Konstantin Boldyshev 4 | 5 | $Id: libc.h,v 1.3 2001/02/23 12:39:29 konst Exp $ 6 | 7 | Header file for assembly libc, defines functions that: 8 | 1) are not present in usual libc 9 | 2) conflict with our libc 10 | We will use standard libc headers for the rest of functions for now. 11 | */ 12 | 13 | /* 14 | _fastcall() must be always fastcall 15 | */ 16 | 17 | extern void __attribute__ (( __regparm__(1) )) 18 | _fastcall(int); 19 | 20 | #ifdef __FASTCALL__ 21 | #define FASTCALL(x) _fastcall(x) 22 | #else 23 | #define FASTCALL(x) _fastcall(0) 24 | #endif 25 | 26 | extern void __attribute__ (( __noreturn__ )) 27 | exit(int); 28 | 29 | extern long strtol(const char *, char **, int); 30 | 31 | extern volatile int errno; 32 | 33 | /* 34 | extern unsigned strlen(const char *); 35 | extern void *memcpy(void *, const void *, int); 36 | extern void *memset(void *, int, int); 37 | */ 38 | -------------------------------------------------------------------------------- /lib/libc_stub.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 2001 Konstantin Boldyshev 2 | ; 3 | ;$Id: libc_stub.asm,v 1.1 2001/03/01 12:34:55 konst Exp $ 4 | ; 5 | ;hackers' libc stub 6 | ; 7 | ;0.01: 28-Jan-2001 8 | 9 | %include "system.inc" 10 | 11 | CODESEG 12 | 13 | extern main 14 | extern __start_main 15 | 16 | START: 17 | push dword main 18 | jmp __start_main 19 | 20 | END 21 | -------------------------------------------------------------------------------- /lib/rc6.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 1999 Cecchinel Stephan 2 | ; 3 | ;$Id: rc6.asm,v 1.3 2000/12/10 08:20:36 konst Exp $ 4 | ; 5 | ;implementation of RC6 crypto algorythm 6 | ; 7 | ;RC6 algo mainly consists of 3 functions: 8 | ; setkey in_key, length ->>set crypto key of length bits (256) 9 | ; encrypt in_block,out_block ->>encrypt 16 byte block 10 | ; decrypt in_block,out_block ->>decrypt 16 byte block 11 | ; 12 | ; really simple to implement....no? 13 | ; 14 | ;10-Sep-2000 cleanup (KB) 15 | 16 | %include "system.inc" 17 | 18 | CODESEG 19 | 20 | global RC6_Setkey 21 | global RC6_Encrypt 22 | global RC6_Decrypt 23 | 24 | PROC RC6_Setkey, in_key, key_len 25 | 26 | %define a dword[ebp-4] ;local vars on the stack 27 | %define b dword[ebp-8] 28 | %define i dword[ebp-12] 29 | %define j dword[ebp-16] 30 | 31 | pusha 32 | 33 | sub esp,byte 16 34 | 35 | mov edi,l_key 36 | mov dword[edi],0x0b7e15163 37 | xor ecx,ecx 38 | inc ecx 39 | .cpy: 40 | mov eax,dword [-4+edi+ecx*4] 41 | add eax,0x09e3779b9 42 | mov dword [edi+ecx*4],eax 43 | inc ecx 44 | cmp ecx,byte 44 45 | jb .cpy 46 | 47 | xor ecx,ecx 48 | mov esi,in_key 49 | mov edx,key_len 50 | shr edx,5 51 | .cpy1: 52 | mov eax,[esi+ecx*4] 53 | mov [edi+ecx*4],eax 54 | inc ecx 55 | cmp ecx,edx 56 | jb .cpy1 57 | 58 | mov esi,ll ;esi=ll 59 | dec edx ;edx=t=(key_len/32)-1 60 | xor ecx,ecx ;ecx=k=0 61 | mov a,ecx 62 | mov b,ecx 63 | mov i,ecx 64 | mov j,ecx ;a=b=i=j=0 65 | .cpy2: 66 | push ecx 67 | mov ebx,i 68 | mov eax,[edi+ebx*4] 69 | add eax,a 70 | add eax,b 71 | rol eax,3 72 | add b,eax ;b+=a 73 | mov a,eax ;a=rol(l_key[i]+a+b 74 | mov ebx,j 75 | mov eax,dword [esi+ebx*4] 76 | add eax,b 77 | mov ecx,b 78 | rol eax,cl 79 | mov b,eax ;b=rol(ll[j]+b,b) 80 | mov eax,a 81 | mov ebx,i 82 | mov [edi+ebx*4],eax ;l_key[i]=a 83 | mov eax,b 84 | mov ebx,j 85 | mov [esi+ebx*4],eax ;ll[j]=b 86 | mov eax,i 87 | inc eax 88 | cmp eax,byte 43 89 | jnz .s1 90 | xor eax,eax 91 | .s1: 92 | mov i,eax ;i=i+1 %43 93 | 94 | mov eax,j 95 | inc eax 96 | cmp eax,edx 97 | jnz .s2 98 | xor eax,eax 99 | .s2: 100 | mov j,eax 101 | pop ecx 102 | inc ecx 103 | cmp ecx,132 104 | jb .cpy2 105 | mov eax,edi 106 | 107 | add esp,byte 16 108 | popa 109 | ENDP 110 | 111 | 112 | ;--------------------------------------- 113 | ;encrypt: 114 | ; 115 | ; input: edi=in_block 116 | ; esi=out_block 117 | 118 | PROC RC6_Encrypt, in_block, out_block 119 | pusha 120 | mov esi,out_block 121 | mov edi,in_block 122 | push esi 123 | mov esi,l_key 124 | mov eax,[edi] ;a=in_block[0] 125 | mov ebx,[edi+4] 126 | add ebx,[esi] ;b=in_block[1]+l_key[0] 127 | mov ecx,[edi+8] ;c=in_block[2] 128 | mov edx,[edi+12] 129 | add edx,[esi+4] ;d=in_block[3]+l_key[1] 130 | lea ebp,[esi+8] 131 | .boucle: 132 | lea esi,[edx+edx+1] 133 | imul esi,edx 134 | rol esi,5 ;u=rol(d*(d+d+1),5) 135 | 136 | lea edi,[ebx+ebx+1] 137 | imul edi,ebx 138 | rol edi,5 ;t=rol(b*(b+b+1),5) 139 | 140 | push ecx 141 | mov ecx,esi 142 | xor eax,edi 143 | rol eax,cl 144 | add eax,[ebp] ;a=rol(a^t,u)+l_key[i] 145 | pop ecx 146 | 147 | push eax 148 | xchg ecx,eax 149 | mov ecx,edi 150 | xor eax,esi 151 | rol eax,cl 152 | add eax,[ebp+4] ;c=rol(c^u,t)+l_key[i+1] 153 | xchg ecx,eax 154 | pop eax 155 | 156 | push eax 157 | mov eax,ebx 158 | mov ebx,ecx 159 | mov ecx,edx 160 | pop edx 161 | add ebp,byte 8 162 | cmp ebp,(l_key+(42*4)) 163 | jnz .boucle 164 | 165 | pop edi 166 | mov esi,l_key 167 | add eax,[esi+(42*4)] 168 | mov [edi],eax 169 | mov [edi+4],ebx 170 | add ecx,[esi+(43*4)] 171 | mov [edi+8],ecx 172 | mov [edi+12],edx 173 | 174 | popa 175 | ENDP 176 | 177 | ;--------------------------------------- 178 | PROC RC6_Decrypt, in_blk2, out_blk2 179 | 180 | pusha 181 | mov esi,out_blk2 182 | push esi 183 | mov edi,in_blk2 184 | mov esi,l_key 185 | 186 | mov edx,[edi+12] ;d=in_blk[3] 187 | mov ecx,[edi+8] 188 | sub ecx,[esi+(43*4)] ;c=in_blk[2]-l_key[43] 189 | mov ebx,[edi+4] ;b=in_blk[1] 190 | mov eax,[edi] 191 | sub eax,[esi+(42*4)] ;a=in_blk[0]-l_key[42] 192 | lea ebp,[esi+(40*4)] 193 | 194 | .boucle2: 195 | push edx 196 | mov edx,ecx 197 | mov ecx,ebx 198 | mov ebx,eax 199 | pop eax 200 | 201 | lea esi,[edx+edx+1] 202 | imul esi,edx 203 | rol esi,5 ;u=rol(d*(d+d+1),5) 204 | 205 | lea edi,[ebx+ebx+1] 206 | imul edi,ebx 207 | rol edi,5 ;t=rol(b*(b+b+1),5) 208 | 209 | push eax 210 | xchg ecx,eax 211 | mov ecx,edi 212 | sub eax,[ebp+4] 213 | ror eax,cl 214 | xor eax,esi 215 | xchg ecx,eax 216 | pop eax 217 | 218 | push ecx 219 | mov ecx,esi 220 | sub eax,[ebp] 221 | ror eax,cl 222 | xor eax,edi 223 | pop ecx 224 | 225 | sub ebp,byte 8 226 | cmp ebp,l_key 227 | jnz .boucle2 228 | 229 | mov esi,ebp 230 | pop edi 231 | sub edx,[esi+4] 232 | mov [edi+12],edx ;out_blk[3]=d-l_key[1] 233 | mov [edi+8],ecx ;out_blk[2]=c 234 | sub ebx,[esi] 235 | mov [edi+4],ebx ;out_blk[1]=b-l_key[0] 236 | mov [edi],eax ;out_blk[0]=a 237 | 238 | popa 239 | ENDP 240 | 241 | UDATASEG 242 | 243 | l_key resd 45 ;internal RC6 key 244 | ll resd 9 245 | 246 | END 247 | -------------------------------------------------------------------------------- /lib/test1.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 1999-2001 Konstantin Boldyshev 3 | 4 | $Id: test1.c,v 1.4 2001/02/23 12:39:29 konst Exp $ 5 | 6 | test program for assembly libc 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "libc.h" 15 | 16 | static char *fname = "_tst_", 17 | *s = "Hello,world!\nType something, then press [Enter]\n", 18 | buf[100]; 19 | 20 | static int fd, len; 21 | 22 | int main(int argc, char **argv, char **envp) 23 | { 24 | FASTCALL(3); 25 | 26 | len = strlen(s); 27 | 28 | fd = open(fname, O_CREAT | O_RDWR, 0600); 29 | write(fd, s, len); 30 | close(fd); 31 | 32 | fd = open(fname, O_RDONLY); 33 | lseek(fd, 0, SEEK_SET); 34 | len = read(fd, buf, len); 35 | close(fd); 36 | 37 | unlink(fname); 38 | 39 | write(STDOUT_FILENO, buf, len); 40 | 41 | len = read(STDIN_FILENO, buf, 10); 42 | write(STDOUT_FILENO, buf, len); 43 | 44 | return len; 45 | } 46 | -------------------------------------------------------------------------------- /lib/test2.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 1999-2001 Konstantin Boldyshev 3 | 4 | $Id: test2.c,v 1.5 2001/03/18 07:08:25 konst Exp $ 5 | 6 | test program for assembly libc 7 | */ 8 | 9 | #include 10 | //#include because of __strtol_internal 11 | #include 12 | #include 13 | 14 | #include "libc.h" 15 | 16 | extern char *getenv(char *); 17 | 18 | int main(int argc, char **argv, char **envp) 19 | { 20 | char inp[10], tmp[10]; 21 | char *ptmp; 22 | int len; 23 | 24 | FASTCALL(3); 25 | 26 | printf("\n\tprintf() test\nhex: %x, octal: %o, decimal: %d\n", 0x10, 010, 10); 27 | 28 | printf("\n\tstrtol() test\nInput some decimal number: "); 29 | len = read(STDIN_FILENO, inp, 10); 30 | memcpy(tmp, inp, len); 31 | ptmp = &tmp[0] + len - 1; 32 | printf("You have entered %d\n", (int)strtol(&tmp[0], &ptmp, 10)); 33 | 34 | printf("\n\tmemset() test\n"); 35 | memset(tmp, 0, 10); 36 | ptmp = &tmp[0] + 5; 37 | for (len = 9; len > 0; len --) { 38 | memset(tmp, '0'+len, 5); 39 | printf("%d ", (int)strtol(&tmp[0], &ptmp, 10)); 40 | } 41 | 42 | printf("\n\n\tvariable test\n"); 43 | write(-1, NULL, 0); 44 | printf("errno: %d\n", errno); 45 | 46 | printf("\n\tenvironment test\nPress ENTER to print envrionment\n"); 47 | read(STDIN_FILENO, inp, 1); 48 | 49 | len = 0; 50 | while(envp[len]) { 51 | printf("%s\n", envp[len]); 52 | len++; 53 | } 54 | 55 | printf("\n\tgetenv(\"HOME\") test\n%s\n", getenv("HOME")); 56 | 57 | if (argc > 1) { 58 | int i; 59 | printf("\n\targuments test\n"); 60 | for (i = 0; i < argc; i++) printf("%s\n", argv[i]); 61 | } 62 | 63 | printf("\n\tall tests done\n"); 64 | 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /src/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (C) 1999-2006 Konstantin Boldyshev 2 | # 3 | # Makefile for asmutils (GNU make is required) 4 | # 5 | # $Id: Makefile,v 1.64 2006/02/09 07:51:31 konst Exp $ 6 | 7 | #DEBUG = y 8 | 9 | BUILD_SRC = y 10 | 11 | include ../MCONFIG 12 | 13 | FILES = basename cal cat chmod chroot chown cmp cpuinfo cut date dc dd deflate dirname\ 14 | echo env extname factor fromdos grep head hexdump hostname\ 15 | id init kill ln lzss mkdir mknod nice nm nohup od rot13 paste\ 16 | readelf readlink reboot renice scons sleep strings sync\ 17 | tail tar tee tr true uname uuencode wc whoami yes\ 18 | md5sum rmdsum rc6crypt sha1sum idea md5\ 19 | 20 | FILES += readkey less getty \ 21 | ftpd host httpd m_inetd nc netstat ping pop3d proxy scan\ 22 | telnet telnetd wget\ 23 | cp du ls mount mv pwd rm sh test touch watch which write\ 24 | 25 | LINKS = arch cpuspeed domainname false inflate mkfifo more rmdir size sln\ 26 | todos umount usleep halt poweroff\ 27 | 28 | BDIR = bonus/ 29 | 30 | BONUS = $(BDIR)execve $(BDIR)report $(BDIR)asmutils 31 | 32 | ifdef LINUX 33 | FILES += cda2raw chvt dmesg df eject fdisk finger free gi ifconfig\ 34 | killall ksyms lsmod lsusb mesg mkfs.minix ps\ 35 | softdog swapon sysctl truss tty update uptime users 36 | LINKS += ccd deallocvt fingerd killall5 pidof rmmod route swapoff mkswap 37 | BONUS += $(BDIR)leaves $(BDIR)fire256 $(BDIR)mandelbrot $(BDIR)hdragon\ 38 | $(BDIR)window $(BDIR)snake $(BDIR)game 39 | endif 40 | 41 | ifdef FREEBSD 42 | FILES += kldload 43 | LINKS += kldunload kldstat 44 | endif 45 | 46 | all: $(FILES) $(BONUS) links 47 | 48 | links: $(FILES) 49 | -@( mkln() { [ ! -e $$2 ] && [ -x $$1 ] && $(LN) $$1 $$2; };\ 50 | mkln hostname domainname;\ 51 | mkln ln sln;\ 52 | mkln mkdir rmdir;\ 53 | mkln mknod mkfifo;\ 54 | mkln true false;\ 55 | mkln uname arch;\ 56 | mkln cpuinfo cpuspeed;\ 57 | mkln fromdos todos;\ 58 | mkln ifconfig route;\ 59 | mkln swapon swapoff;\ 60 | mkln swapon mkswap;\ 61 | mkln chvt deallocvt;\ 62 | mkln eject ccd;\ 63 | mkln mount umount;\ 64 | mkln reboot halt;\ 65 | mkln reboot poweroff;\ 66 | mkln lsmod rmmod;\ 67 | mkln kldload kldunload;\ 68 | mkln kldload kldstat;\ 69 | mkln killall killall5;\ 70 | mkln killall pidof;\ 71 | mkln sleep usleep;\ 72 | mkln less more;\ 73 | mkln nm size;\ 74 | mkln finger fingerd;\ 75 | mkln deflate inflate;\ 76 | cd $(BDIR); mkln execve regs;\ 77 | ) 78 | 79 | install:$(FILES) 80 | $(MKDIR) $(INSTALLDIR) 81 | $(CP) $(FILES) $(LINKS) $(INSTALLDIR) 82 | 83 | clean: 84 | $(RM) *.o $(FILES) $(LINKS) $(BONUS) $(BDIR)regs 85 | -------------------------------------------------------------------------------- /src/basename.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 1999 Indrek Mandre 2 | ; 3 | ;$Id: basename.asm,v 1.5 2002/03/14 07:12:12 konst Exp $ 4 | ; 5 | ;hackers' basename [GNU replacement] 6 | ; 7 | ;syntax: basename path [suffix] 8 | ; 9 | ;example: basename /bin/basename 10 | ; basename /kala.xxx xxx 11 | ; 12 | ; in case of error exits with code 256, 0 otherwise 13 | ; 14 | ;0.01: 17-Jun-1999 initial release 15 | ;0.02: 04-Jul-1999 bugfixes 16 | ;0.03: 29-Jul-1999 size improvements (KB) 17 | ;0.04: 14-Mar-2002 size improvements (KB) 18 | 19 | %include "system.inc" 20 | 21 | CODESEG 22 | 23 | START: 24 | _mov ebx,1 ;error code 25 | 26 | pop eax 27 | mov edi,eax ;edi holds argument count 28 | dec edi 29 | jz .exit 30 | cmp edi,byte 2 ;must be not more than two arguments 31 | jg .exit 32 | 33 | pop eax ;skip our name 34 | pop eax ;the path 35 | mov ebx,eax ;mark the beginning of path 36 | xor edx,edx 37 | cmp byte [eax],EOL 38 | je .printout 39 | .loopone: 40 | inc eax 41 | cmp byte [eax],EOL 42 | jne .loopone 43 | mov edx,eax ;mark the end 44 | .backwego: 45 | dec eax 46 | cmp eax,ebx 47 | jnl .empty 48 | xor edx,edx 49 | jmps .printout 50 | .empty: 51 | cmp byte [eax],'/' 52 | je .backwego 53 | inc eax 54 | mov edx,eax 55 | .looptwo: 56 | dec eax 57 | cmp byte [eax],'/' 58 | je .endlooptwoinceax 59 | cmp eax,ebx 60 | je .endlooptwo 61 | jmps .looptwo 62 | 63 | ;end of checkinf of suffix 64 | 65 | .goaftersuffixpopeax: 66 | pop eax 67 | .goaftersuffix: 68 | pop edx 69 | pop ecx 70 | 71 | .printout: 72 | mov byte [ecx+edx],__n 73 | inc edx 74 | sys_write STDOUT 75 | xor ebx,ebx 76 | .exit: 77 | sys_exit 78 | 79 | .endlooptwoinceax: 80 | inc eax 81 | 82 | .endlooptwo: 83 | mov ecx,eax 84 | sub edx,eax 85 | dec edi 86 | jz .printout ;we have no suffix to remove 87 | pop eax 88 | push ecx 89 | push edx 90 | add ecx,edx 91 | 92 | ;now we check for suffix 93 | mov ebx,eax ;save start of suffix 94 | 95 | cmp byte [eax],EOL 96 | je .goaftersuffix ;there was nothing in suffix string, so nothin to remove 97 | .suffixloop: 98 | inc eax 99 | cmp byte [eax],EOL 100 | jne .suffixloop 101 | .endsuffixloop: 102 | sub eax,ebx ;we have length of suffix here now 103 | cmp eax,edx ;in case suffix is longer jump out 104 | jge .goaftersuffix 105 | add eax,ebx 106 | 107 | push eax 108 | 109 | ;now comes the comparing part 110 | 111 | .sloop: 112 | dec eax 113 | dec ecx 114 | 115 | mov dl,[eax] 116 | cmp [ecx],dl 117 | jne .goaftersuffixpopeax ;not equal 118 | 119 | cmp eax,ebx 120 | jne .sloop 121 | 122 | ;we got here, it means suffix matched 123 | 124 | pop eax 125 | sub eax,ebx ;we have here the all famous length 126 | pop edx 127 | pop ecx 128 | sub edx,eax ;decrement the length by suffix 129 | jmps .printout ;and print it out 130 | 131 | END 132 | -------------------------------------------------------------------------------- /src/bonus/asmutils.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 1999-2002 Konstantin Boldyshev 2 | ; 3 | ;$Id: asmutils.asm,v 1.6 2006/02/09 07:42:11 konst Exp $ 4 | ; 5 | ;asmutils multicall binary 6 | ; 7 | ;0.03: 17-Jan-2001 initial public release 8 | ;0.04: 06-Jun-2002 fixed startup stack, call for script-writers 9 | 10 | %include "system.inc" 11 | 12 | CODESEG 13 | 14 | names: 15 | 16 | dd "arch", _uname 17 | dd "base", _basename 18 | dd "echo", _echo 19 | dd "fact", _factor 20 | dd "fals", _true 21 | dd "kill", _kill 22 | dd "pwd", _pwd 23 | dd "slee", _sleep 24 | dd "sync", _sync 25 | dd "tee", _tee 26 | dd "true", _true 27 | dd "unam", _uname 28 | dd "yes", _yes 29 | 30 | START: 31 | push eax 32 | pusha 33 | mov esi,[esp + 4*9 + 4] 34 | mov ebx,esi 35 | .n1: 36 | lodsb 37 | or al,al 38 | jnz .n1 39 | .n2: 40 | dec esi 41 | cmp ebx,esi 42 | jz .n3 43 | cmp byte [esi],'/' 44 | jnz .n2 45 | inc esi 46 | .n3: 47 | 48 | xor ebx,ebx 49 | .find_name: 50 | mov eax,[ebx + names] 51 | or eax,eax 52 | jz .exit 53 | cmp eax,[esi] 54 | jz .run_it 55 | add ebx,byte 8 56 | jmps .find_name 57 | 58 | .run_it: 59 | 60 | mov eax,[ebx + names + 4] 61 | mov [esp + 4*8],eax 62 | popa 63 | ret 64 | 65 | .exit: 66 | 67 | sys_write STDOUT, poem, length 68 | sys_exit 0 69 | 70 | ; 71 | ; 72 | ; 73 | 74 | poem db __n 75 | db "this is not a nasty bug",__n 76 | db "this is just a cool loopback",__n 77 | db __n 78 | db __t,"- an ancient assembly poem -",__n 79 | db __t,"(by an ancient assembly poet)",__n 80 | db __n 81 | db "This eventually will be the asmutils multicall binary.",__n 82 | db "The whole idea behind it is that it should be auto-generated",__n 83 | db "from other .asm files (and of course startup code) with some",__n 84 | db "script with no manual adjustments, when other programs will",__n 85 | db "be in a more-or-less usable and reliable state. The day has",__n 86 | db "not come yet, but it is closer with each release. Meanwhile,",__n 87 | db "do not waste your time on improving this source code, better",__n 88 | db "be the one who implements the above described script.",__n,__n 89 | length equ $-poem 90 | 91 | _uname: 92 | _basename: 93 | _echo: 94 | _factor: 95 | _true: 96 | _kill: 97 | _pwd: 98 | _sleep: 99 | _sync: 100 | _tee: 101 | _yes: 102 | 103 | ;write applet name to stdout 104 | pop eax 105 | 106 | pop esi 107 | mov ecx,esi 108 | .n1: 109 | lodsb 110 | or al,al 111 | jnz .n1 112 | .n2: 113 | mov byte [esi - 1],__n 114 | sub esi,ecx 115 | sys_write STDOUT,EMPTY,esi 116 | 117 | sys_exit 1 118 | 119 | END 120 | -------------------------------------------------------------------------------- /src/bonus/game.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leto/asmutils/f8620b115c80d9483047228f53a8aca2aa497c87/src/bonus/game.asm -------------------------------------------------------------------------------- /src/bonus/hdragon.asm: -------------------------------------------------------------------------------- 1 | ; hdragon.asm 2 | ; 3 | ; $Id: hdragon.asm,v 1.1 2006/02/09 07:48:15 konst Exp $ 4 | ; 5 | ; 640x480x8 harter's dragon impl 6 | ; 7 | ; (c) 2k2 Maciej Hrebien 8 | 9 | %include "system.inc" 10 | 11 | %assign MaxX 640 12 | %assign MaxY 480 13 | 14 | %assign NORTH 0 15 | %assign EAST 1 16 | %assign SOUTH 2 17 | %assign WEST 3 18 | 19 | %assign LEFT -1 20 | %assign RIGHT 1 21 | 22 | %assign NEST 16 ; > 16 will cross frame buffer & sigfault ! 23 | %assign COLOR 14 24 | %assign DELAY 0xffff 25 | 26 | CODESEG 27 | 28 | ; al - drawing direction LEFT or RIGHT 29 | ; edx - nestle (how deep the code is) 30 | ; edi - frame buffer ptr 31 | ; esi - direct & pxy ptr 32 | 33 | dragon: 34 | pusha 35 | 36 | or edx,edx ; last nestle ? 37 | jz put_pixel 38 | 39 | dec edx 40 | push eax 41 | 42 | mov al,RIGHT 43 | call dragon 44 | 45 | pop eax 46 | add [esi],al ; chg drawing direction (-/+)90 deg 47 | and [esi],byte 3 48 | 49 | mov al,LEFT 50 | call dragon 51 | 52 | jmp short d_ret 53 | 54 | put_pixel: 55 | 56 | push esi 57 | lodsd 58 | 59 | cmp al,NORTH ; where the next pixel will go ? 60 | je goes_north 61 | cmp al,SOUTH 62 | je goes_south 63 | cmp al,EAST 64 | je go 65 | 66 | push byte -1 ; west 67 | pop eax 68 | jmp short go 69 | 70 | goes_north: 71 | 72 | mov eax,-MaxX 73 | jmp short go 74 | 75 | goes_south: 76 | 77 | mov ax,MaxX 78 | go: 79 | add eax,[esi] ; put the pixel on the proper side 80 | mov [edi + eax],byte COLOR 81 | mov [esi],eax ; save new pixels' position 82 | 83 | pop esi 84 | 85 | _mov ecx,DELAY 86 | delay: loop delay 87 | d_ret: 88 | popa 89 | ret 90 | 91 | ; main routine 92 | 93 | START: 94 | sys_open fb0,O_RDWR 95 | 96 | or eax,eax 97 | js exit 98 | 99 | push eax 100 | 101 | ; sys_mmap 0,MaxX*MaxY,PROT_WRITE,MAP_SHARED,eax,0 102 | sys_mmap EMPTY,MaxX*MaxY,PROT_WRITE,MAP_SHARED,eax,EMPTY 103 | 104 | or eax,eax 105 | js merr 106 | 107 | mov edi,eax 108 | push eax 109 | 110 | mov ecx,MaxX*MaxY ; blank the screen 111 | xor al,al 112 | rep stosb 113 | 114 | pop edi 115 | 116 | push dword MaxX*MaxY*2/3+MaxX/2 ; pxy 117 | push byte NORTH ; direct 118 | mov esi,esp 119 | 120 | ; mov al,RIGHT 121 | inc eax ; RIGHT == 1 && al == 0 !! 122 | _mov edx,NEST 123 | call dragon 124 | 125 | pop eax 126 | pop eax 127 | 128 | sys_munmap edi,MaxX*MaxY 129 | merr: 130 | pop eax 131 | sys_close eax 132 | exit: 133 | sys_exit 134 | 135 | fb0: db "/dev/fb0",0 136 | 137 | END 138 | -------------------------------------------------------------------------------- /src/bonus/mandelbrot.asm: -------------------------------------------------------------------------------- 1 | ; MANDELBROT GENERATOR 2 | ; 3 | ; $Id: mandelbrot.asm,v 1.1 2006/02/09 07:36:07 konst Exp $ 4 | ; 5 | ; Original code by Tenie Remmel & John Eckerdal 6 | ; ported to Linux/framebuffer by Stephan Walter 7 | ; 8 | ; (c) 2002 by Stephan Walter - licensed under the GNU GPL 9 | ; 10 | ; v1.0 2002-06-02 --- First release (175 bytes) 11 | ; 12 | ; 13 | ; Well, it's nothing new, just another Mandelbrot proggie. It uses 14 | ; 640x480x8 fb mode (like all the other asmutils gfx programs). 15 | ; Use Ctrl-C to exit. 16 | ; 17 | ; Color palette is not set. If you run fire256 or X11 before running 18 | ; this program, you'll get different colors. 19 | ; 20 | ; The size of the DOS/INT10h program was 61 bytes, my version has 175 :-( 21 | ; 22 | ; 23 | ; Original file comment: 24 | ;========================================================================== 25 | ;This is a small implementation of a mandelbrot generator. I've found this 26 | ;gem a some time ago in a swedish fido-net meeting as a UUencoded file. All 27 | ;comments have been inserted by me (John Eckerdal). I have tried to give 28 | ;some information about what the program acutally calculates. This 29 | ;information might however be incorrect. 30 | ;The source and a compiled version is available for download (1092 bytes). 31 | ; 32 | ; mandelbrot plotter, 61 bytes - Tenie Remmel 33 | ;========================================================================== 34 | 35 | %include "system.inc" 36 | 37 | %assign SIZE_X 640 38 | %assign SIZE_Y 480 39 | %assign VMEM_SIZE SIZE_X*SIZE_Y 40 | 41 | CODESEG 42 | 43 | START: 44 | sys_open fb, O_RDWR 45 | sys_mmap EMPTY, VMEM_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, eax 46 | mov edi, eax ; we'll use stosb 47 | 48 | _mov ecx, SIZE_Y ; "xor ecx, ecx", "inc ch" is one byte smaller 49 | outer_loop: 50 | _mov esi, SIZE_X 51 | inner_loop: 52 | _mov ebp, 127 ; number of iterations. Can be >127 but then 53 | ; it uses 2 more bytes. >255 makes no sense 54 | ; because this is used for the pixel color. 55 | 56 | xor ebx, ebx ; re := 0 57 | xor edx, edx ; im := 0 58 | 59 | complex_loop: 60 | push edx 61 | mov eax, ebx 62 | sub eax, edx ; eax := re - im 63 | add edx, ebx ; edx := re + im 64 | imul edx ; u := (re-im) * (im+re) = re^2 - im^2 65 | sar eax, 8 ; u := u / 2^8 66 | pop edx 67 | 68 | xchg ebx, eax 69 | 70 | sub ebx, esi ; new_re := u - width 71 | 72 | imul edx 73 | shld edx, eax, 25 ; edx := 2(re * im) / 2^8 74 | 75 | sub edx, ecx ; new_im := 2(rm * im) / 2^8 - height 76 | 77 | test dh,dh ; if j>=256 plot pixel 78 | jg short plot_color 79 | 80 | dec ebp ; next iteration 81 | jnz short complex_loop 82 | 83 | plot_color: 84 | xchg ebp,eax 85 | stosb ; plot pixel 86 | 87 | dec esi 88 | jnz short inner_loop 89 | 90 | loop outer_loop 91 | 92 | schluss: ; of course we should use sys_exit, 93 | jmps schluss ; but this loop is smaller and the 94 | ; picture won't get overridden by the 95 | ; shell prompt. Use Ctrl-C to exit. 96 | 97 | fb db "/dev/fb0" 98 | 99 | END 100 | -------------------------------------------------------------------------------- /src/chmod.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 2000-2002 Konstantin Boldyshev 2 | ; 3 | ;$Id: chmod.asm,v 1.4 2002/10/09 18:04:10 konst Exp $ 4 | ; 5 | ;hackers' chmod 6 | ; 7 | ;syntax: chmod MODE [FILE...] 8 | ; 9 | ;only octal mode strings are suppoted (e.g. 755) 10 | ; 11 | ;0.01: 10-Jan-2000 initial release 12 | ;0.02: 09-Oct-2002 fixed "chmod 4755" bug (KB) 13 | 14 | %include "system.inc" 15 | 16 | CODESEG 17 | 18 | START: 19 | pop ebx 20 | _cmp ebx,3 21 | jb .exit 22 | 23 | pop esi 24 | pop esi 25 | 26 | call parse_mode_string 27 | _cmp eax,-1 28 | jz .exit 29 | 30 | mov ecx,eax 31 | 32 | .next_file: 33 | pop ebx 34 | or ebx,ebx 35 | jz .exit 36 | sys_chmod 37 | jmps .next_file 38 | .exit: 39 | sys_exit eax 40 | 41 | 42 | ; 43 | ; 44 | ; 45 | 46 | ;eax - mode 48 | 49 | parse_mode_string: 50 | 51 | %assign MODE_NONE 00000000b 52 | %assign MODE_XIFX 00000001b 53 | %assign MODE_COPY 00000010b 54 | 55 | push edi 56 | push esi 57 | push edx 58 | push ecx 59 | push ebx 60 | 61 | mov edx,esi 62 | xor ecx,ecx 63 | xor eax,eax 64 | _mov ebx,8 65 | 66 | .next: 67 | mov cl,[esi] 68 | or cl,cl 69 | jz .done_ok 70 | sub cl,'0' 71 | jb .done_err 72 | cmp cl,7 73 | ja .done_err 74 | mul bx 75 | add eax,ecx 76 | inc esi 77 | jmps .next 78 | 79 | .done_ok: 80 | cmp edx,esi 81 | jnz .return 82 | 83 | .done_err: 84 | 85 | %ifdef PARSE_SYMBOLIC_MODESTRING 86 | xor ebp,ebp 87 | mov esi,edx 88 | 89 | .cmp_who: 90 | lodsb 91 | _mov ecx,4 92 | _mov edi,who 93 | call .compare 94 | jc .cmp_what1 95 | or ebp,[who_c + ebx] 96 | jmps cmp_who 97 | 98 | .cmp_what: 99 | lodsb 100 | .cmp_what1: 101 | _mov ecx,3 102 | _mov edi,what 103 | call .compare 104 | jc .cmp_mode1 105 | 106 | .cmp_mode: 107 | lodsb 108 | .cmp_mode1: 109 | _mov ecx,9 110 | _mov edi,mode 111 | call .compare 112 | jc .cmp_done 113 | or ebp, [mode_c + ebx] 114 | .cmp_done: 115 | 116 | %else 117 | xor eax,eax 118 | dec eax 119 | %endif 120 | 121 | .return: 122 | pop ebx 123 | pop ecx 124 | pop edx 125 | pop esi 126 | pop edi 127 | ret 128 | 129 | 130 | %ifdef PARSE_SYMBOLIC_MODESTRING 131 | 132 | .compare: 133 | xor ebx,ebx 134 | .cmp_loop: 135 | cmp al,[edi + ebx] 136 | clc 137 | jz .done 138 | inc ebx 139 | loop .cmp_loop 140 | stc 141 | .done: 142 | ret 143 | 144 | what db "+-=" 145 | mode db "rwxXst" 146 | who db "ugoa" 147 | mode_c dd 0444q,0222q,0111q,0111q,6000q,1000q, 148 | dd 0700q,0070q,0007q 149 | mode_f db MODE_NONE,MODE_NONE,MODE_NONE,MODE_XIFX,MODE_NONE,MODE_NONE 150 | db MODE_COPY,MODE_COPY,MODE_COPY 151 | who_c dd 4700q,2070q,1007q,7777q 152 | 153 | %endif 154 | 155 | END 156 | -------------------------------------------------------------------------------- /src/chown.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 2000 Jonathan Leto 2 | ; 3 | ;$Id: chown.asm,v 1.1 2001/01/21 15:18:46 konst Exp $ 4 | ; 5 | ;hackers' chown 6 | ; 7 | ;syntax: chown uid[.gid] file [ file ] .... 8 | ; 9 | ;returns 0 on success, 1 on error 10 | ;ascii_to_num from strings.asm by Dmitry Bakhvalov 11 | ;strlen from rm.asm by Dmitry Bakhvalov 12 | ; 13 | ; No support for username/group yet 14 | ; No support for recursive or symlink(lchown) either 15 | ; 16 | ; used 255 for MAXPATH, couldn't find constant 17 | ; 18 | ; Version 0.1 - Tue Dec 19 19:30:30 EST 2000 19 | ; 20 | ; All comments/feedback welcome. 21 | 22 | %include "system.inc" 23 | 24 | ;ebp = return code 25 | 26 | CODESEG 27 | 28 | setnogroup: 29 | _mov [gid],dword -1 ; don't change group 30 | ret 31 | 32 | START: 33 | _mov [uid],dword -1 ; won't change 34 | 35 | _mov ebp,0 ; default file descriptor 36 | pop ebx ; argc 37 | dec ebx 38 | pop ebx ; argv[0], program name 39 | jz near .exit ; flag set by dec 40 | 41 | pop esi 42 | call strlen 43 | ;--- make sure doesn't begin with letter 44 | lodsb 45 | 46 | cmp al,byte 0x2f 47 | jle near .exit 48 | 49 | cmp al,byte 0x3a 50 | jge near .exit 51 | 52 | dec esi 53 | ;----------------------------------------- 54 | ;-- if last char in string is period, die 55 | ;-- without this, "chown uid. file" would be interpreted 56 | ;-- as "chown uid.0 file", which is bad 57 | .sane2: 58 | dec edx 59 | inc ebp 60 | cmp [esi+edx],byte '.' 61 | je near .exit 62 | inc edx 63 | dec ebp 64 | ;--------------------------------------- 65 | xor ecx,ecx ; offset in arg of . 66 | push esi ; save orig argument 67 | 68 | .findper: ; find period in string 69 | lodsb ; get byte 70 | inc ecx 71 | cmp ecx,edx 72 | jg .alldone ; no more string 73 | 74 | cmp al,'.' 75 | jne .findper 76 | _mov [foundper],dword 1 ; found it 77 | 78 | .alldone: 79 | _mov [gid],esi ; what's left is gid 80 | dec ecx ; offset starts at 0 81 | pop esi ; get orig argument 82 | _mov [esi+ecx], byte 0x0 ; put null where period was 83 | _mov [uid],esi ; save uid 84 | 85 | _mov esi,[gid] ; change to number 86 | call .ascii_to_num 87 | _mov [gid],eax 88 | 89 | _mov esi,[uid] ; change to number 90 | call .ascii_to_num 91 | _mov [uid],eax 92 | 93 | cmp [foundper],dword 1 94 | je .numbers 95 | call setnogroup 96 | 97 | .numbers: 98 | pop esi ; get file 99 | or esi,esi 100 | jz .exit ; no file given 101 | 102 | _mov [file],esi 103 | 104 | sys_chown [file],[uid],[gid] 105 | jmp .numbers ; get next file 106 | 107 | .exit: 108 | sys_exit ebp ; exit with return value 109 | 110 | ;--------------------------------------- 111 | ; esi = string 112 | ; eax = number 113 | .ascii_to_num: 114 | xor eax,eax ; zero out regs 115 | xor ebx,ebx 116 | .next_digit: 117 | lodsb ; load byte from esi 118 | test al,al 119 | jz .done 120 | sub al,'0' ; '0' is first number in ascii 121 | imul ebx,10 122 | add ebx,eax 123 | jmp .next_digit 124 | .done: 125 | xchg ebx,eax ; ebx=eax,eax=ebx 126 | ret 127 | ;------------------ 128 | ; esi = string 129 | ; edx = strlen 130 | strlen: 131 | push eax 132 | push esi 133 | 134 | xor eax,eax 135 | mov edx,eax 136 | dec edx 137 | .do_strlen: 138 | inc edx 139 | lodsb 140 | test al,al 141 | jnz .do_strlen 142 | 143 | pop esi 144 | pop eax 145 | ret 146 | 147 | UDATASEG 148 | 149 | uid: resd 1 150 | gid: resd 1 151 | file: resd 255 152 | foundper: resd 1 153 | 154 | END 155 | -------------------------------------------------------------------------------- /src/chroot.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 1999 Konstantin Boldyshev 2 | ; 3 | ;$Id: chroot.asm,v 1.4 2002/02/02 08:49:25 konst Exp $ 4 | ; 5 | ;hackers' chroot 6 | ; 7 | ;syntax: chroot directory [command] 8 | ; 9 | ;example: chroot /tmp 10 | ; chroot /mnt lilo 11 | ; 12 | ;Runs command with specified root directory 13 | ;If no command is given, runs /bin/sh 14 | ;You must be root to succeed 15 | ; 16 | ;0.01: 19-Dec-1999 initial release 17 | 18 | %include "system.inc" 19 | 20 | CODESEG 21 | 22 | START: 23 | pop ebp ;get argc 24 | dec ebp ;exit if no args 25 | jz do_exit 26 | 27 | pop ebx 28 | 29 | pop ebx 30 | sys_chroot 31 | or eax,eax 32 | js do_exit 33 | 34 | mov ebx,[esp] ;ebx -- program name (*) 35 | or ebx,ebx 36 | jnz .set_args 37 | mov ebx,shell 38 | .set_args: 39 | mov ecx,esp ;ecx -- arguments (**) 40 | lea edx,[esp+(ebp+1)*4] ;edx -- environment (**) 41 | 42 | sys_execve 43 | 44 | do_exit: 45 | sys_exit eax 46 | 47 | shell db "/bin/sh";,EOL 48 | 49 | END 50 | -------------------------------------------------------------------------------- /src/chvt.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 1999 Indrek Mandre 2 | ; 3 | ;$Id: chvt.asm,v 1.4 2002/03/07 06:16:39 konst Exp $ 4 | ; 5 | ;hackers' chvt/deallocvt 6 | ; 7 | ;0.01: 29-Jul-1999 initial release 8 | ; 9 | ;syntax: chvt N 10 | ; deallocvt [N]... 11 | ; 12 | ;example: chvt 3 13 | ; deallocvt 10 11 12 14 | ; deallocvt 15 | ; 16 | ;Changes current VT/deallocates VTs 17 | 18 | %include "system.inc" 19 | 20 | CODESEG 21 | 22 | atoi: 23 | _mov eax,0 24 | _mov ebx,10 25 | _mov ecx,0 26 | .next: 27 | mov cl,[esi] 28 | sub cl,'0' 29 | jb .done 30 | cmp cl,9 31 | ja .done 32 | mul bx 33 | add eax,ecx 34 | .nextsym: 35 | inc esi 36 | jmp short .next 37 | .done: 38 | ret 39 | 40 | open_ioctl: 41 | sys_open EMPTY,O_RDONLY 42 | test eax,eax 43 | js errorexit 44 | lea edx,[esp-0x10] ;buffer is on the stack 45 | sys_ioctl eax,KDGKBTYPE 46 | or eax,eax 47 | ret 48 | errorexit: 49 | sys_exit_false 50 | 51 | START: 52 | mov ebx,devtty 53 | call open_ioctl 54 | jz .proceed 55 | mov ebx,devconsole 56 | call open_ioctl 57 | jnz errorexit 58 | .proceed: 59 | mov ebp,ebx ;file descriptor 60 | 61 | pop edi 62 | pop esi ;how we are called? 63 | .n1: 64 | lodsb 65 | or al,al 66 | jnz .n1 67 | 68 | cmp dword [esi-5],"chvt" 69 | jnz deallocvt 70 | 71 | cmp edi,byte 2 72 | jnz errorexit 73 | pop esi 74 | or esi,esi 75 | jz do_exit 76 | call atoi 77 | sys_ioctl ebp,VT_ACTIVATE,eax 78 | sys_ioctl EMPTY,VT_WAITACTIVE 79 | do_exit: 80 | sys_exit_true 81 | 82 | deallocvt: 83 | xor eax,eax 84 | dec edi 85 | jz do_dealloc 86 | next_arg: 87 | pop esi 88 | or esi,esi 89 | jz do_exit 90 | call atoi 91 | do_dealloc: 92 | sys_ioctl ebp,VT_DISALLOCATE,eax 93 | jmp short next_arg 94 | 95 | 96 | devtty db "/dev/tty0",EOL 97 | devconsole db "/dev/console",EOL 98 | 99 | END 100 | -------------------------------------------------------------------------------- /src/dc.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 2001 by Joshua Hudson 2 | ; 3 | ;$Id: dc.asm,v 1.1 2001/08/14 18:55:38 konst Exp $ 4 | ; 5 | ;hacker's dc/revp 6 | ; 7 | ;usage: dc expression 8 | ; 9 | ;supports +,-,*,/,%,xor,or,and,neg 10 | ; x ^ | & ~! 11 | ;for debugging, pr will print the top number to stdout 12 | ;du dumps the top of the stack 13 | ; 14 | ;xchg is used frequently to decrease code size 15 | 16 | %include "system.inc" 17 | 18 | CODESEG 19 | 20 | START: 21 | pop ebp 22 | pop eax 23 | _mov edi, stack ; our stack pointer 24 | .next: 25 | dec ebp 26 | jz .done 27 | pop ebx 28 | cmp [ebx], byte '0' 29 | jl .notnum 30 | cmp [ebx], byte '9' 31 | jg .notnum 32 | call .atoi 33 | jmps .next 34 | 35 | .done call .pop 36 | xchg ecx, eax 37 | call .itoa 38 | sys_exit_true 39 | 40 | .pr call .push 41 | call .itoa 42 | jmps .next 43 | 44 | .neg neg eax 45 | jmp .nextrelay 46 | 47 | ; Process all uniary operators 48 | .notnum call .pop 49 | xchg ecx, eax 50 | cmp [ebx], byte 'p' 51 | je .pr 52 | cmp [ebx], byte '!' 53 | je .neg 54 | cmp [ebx], byte '~' 55 | je .neg 56 | cmp [ebx], byte 'n' 57 | je .neg 58 | cmp [ebx], byte 'd' 59 | je .next 60 | ; Process all binary operators 61 | call .pop 62 | xchg ecx, eax 63 | cmp [ebx], byte '+' 64 | je .plus 65 | cmp [ebx], byte '-' 66 | je .minux 67 | cmp [ebx], byte '*' 68 | je .times 69 | cmp [ebx], byte 'x' 70 | je .times 71 | cmp [ebx], byte '/' 72 | je .div 73 | cmp [ebx], byte '%' 74 | je .mod 75 | cmp [ebx], byte 'a' 76 | je .and 77 | cmp [ebx], byte 'o' 78 | je .or 79 | cmp [ebx], byte 'x' 80 | je .xor 81 | cmp [ebx], byte 'e' 82 | je .xor 83 | jmp .bad_op 84 | 85 | .nextrelay: 86 | call .push 87 | jmp .next 88 | 89 | .plus add eax, ecx 90 | jmps .nextrelay 91 | 92 | .minux sub eax, ecx 93 | jmps .nextrelay 94 | 95 | .times xor edx, edx 96 | mul ecx 97 | jmps .nextrelay 98 | 99 | .and and eax, ecx 100 | jmps .nextrelay 101 | 102 | .or or eax, ecx 103 | jmps .nextrelay 104 | 105 | .xor xor eax, ecx 106 | jmps .nextrelay 107 | 108 | .div xor edx, edx 109 | div ecx 110 | jmps .nextrelay 111 | 112 | .mod xor edx, edx 113 | div ecx 114 | xchg edx, eax 115 | jmps .nextrelay 116 | 117 | ;*** itoa: convert eax to number in num_buf and display 118 | .itoa: 119 | xor ecx, ecx 120 | push edi 121 | _mov ebx, 10 122 | _mov edi, num_buf 123 | .itoa_again: 124 | xor edx, edx 125 | div ebx 126 | push edx 127 | inc ecx 128 | or eax, eax 129 | jnz .itoa_again 130 | mov edx, ecx 131 | inc edx 132 | .itoa_pop: 133 | pop eax 134 | add al, '0' 135 | stosb 136 | loop .itoa_pop 137 | mov al, 10 138 | stosb 139 | sys_write STDOUT, num_buf 140 | pop edi 141 | ret 142 | 143 | ;*** atoi: convert [ebx] to number and push 144 | .atoi: 145 | xor eax, eax 146 | xor ecx, ecx 147 | .atoi_next: 148 | mov cl, [ebx] 149 | sub cl, '0' 150 | cmp cl, 0 151 | jl .atoi_done 152 | cmp cl, 9 153 | jg .atoi_done 154 | _mov edx, 10 155 | mul edx ; eax *= 10 156 | add eax, ecx 157 | inc ebx 158 | jmps .atoi_next 159 | .atoi_done: 160 | jmps .push 161 | 162 | ;*** Our small subroutines 163 | .pop cmp edi, stack 164 | jle .stack_underflow 165 | sub edi, byte 4 166 | mov ecx, [edi] 167 | ret 168 | 169 | .push cmp edi, stack + 128 170 | jge .stack_overflow 171 | mov [edi], eax 172 | add edi, byte 4 173 | ret 174 | 175 | .stack_overflow: 176 | _mov ecx, stack_overflow 177 | _mov edx, stack_overflow_len 178 | jmps .stack_message 179 | 180 | .stack_underflow: 181 | _mov ecx, stack_underflow 182 | _mov edx, stack_underflow_len 183 | jmps .stack_message 184 | 185 | .bad_op: 186 | _mov ecx, bad_op 187 | _mov edx, bad_op_len 188 | .stack_message: 189 | sys_write STDERR 190 | sys_exit_false 191 | 192 | ;*** Error messages 193 | 194 | stack_overflow db "Stack overflow", __n 195 | stack_overflow_len equ 15 196 | 197 | stack_underflow db "Stack underflow", __n 198 | stack_underflow_len equ 16 199 | 200 | bad_op db "Bad op", __n 201 | bad_op_len equ 7 202 | 203 | UDATASEG 204 | 205 | stack resd 128 206 | num_buf resb 13 207 | 208 | END 209 | -------------------------------------------------------------------------------- /src/df.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leto/asmutils/f8620b115c80d9483047228f53a8aca2aa497c87/src/df.asm -------------------------------------------------------------------------------- /src/dirname.asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leto/asmutils/f8620b115c80d9483047228f53a8aca2aa497c87/src/dirname.asm -------------------------------------------------------------------------------- /src/dmesg.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 1999 Indrek Mandre 2 | ; 3 | ;$Id: dmesg.asm,v 1.7 2002/03/14 07:12:12 konst Exp $ 4 | ; 5 | ;hackers' dmesg 6 | ; 7 | ;syntax: dmesg [-c] [-n level] 8 | ; 9 | ;example: dmesg 10 | ; dmesg -c 11 | ; dmesg -n 1 12 | ; 13 | ;-c clears the kernel buffer 14 | ;-n set the console log level 15 | ; 16 | ;0.01: 17-Jun-1999 initial release 17 | ;0.02: 04-Jul-1999 fixed bug with 2.0 kernel, removed leading (KB) 18 | ;0.03: 14-Mar-2000 19 | ; fixed the "-c" option bug, 20 | ; empty kernel buffer coredump, 21 | ; added "-n" option 22 | ; by Christopher Li 23 | ; 24 | ; check for unsuccessful sys_syslog, 25 | ; clear buffer *after* print, 26 | ; fast output (buffer-at-once) (KB) 27 | ;0.04: 05-Aug-2000 increased buffer size (KB) 28 | ;0.05: 14-Mar-2002 squeezed one byte (KB) 29 | 30 | %include "system.inc" 31 | 32 | CODESEG 33 | 34 | %assign BUFSIZE 0x8000 35 | 36 | START: 37 | _mov ebp,0 ;-c flag 38 | _mov ebx,3 ;just print the buffer [3] 39 | pop edi ;edi holds argument count 40 | dec edi 41 | jz .forward 42 | pop eax ;our own name 43 | pop eax 44 | cmp word [eax],"-n" 45 | jnz .clear 46 | dec edi 47 | jz .forward 48 | pop ecx ;the log level 49 | xor edx,edx 50 | mov dl, byte [ecx] 51 | sub dl,'0' 52 | jna .forward ;less than 0, skip 53 | cmp dl,8 54 | ja .forward ;more than 8, skip 55 | _mov ebx,8 ;set the console level 56 | jmps .syslog 57 | .clear: 58 | cmp word [eax],"-c" 59 | jnz .forward 60 | inc ebp 61 | .forward: 62 | _mov edx,BUFSIZE 63 | .syslog: 64 | sys_syslog EMPTY,buf 65 | test eax,eax 66 | js .quit 67 | jz .quit 68 | mov edi,buf_new 69 | mov ebx,edi ;save for later use 70 | mov esi,ecx 71 | mov ecx,eax 72 | .write: 73 | lodsb 74 | cmp al,'<' 75 | jnz .store 76 | cmp byte [esi + 1],'>' 77 | jnz .store 78 | lodsw 79 | lodsb 80 | sub ecx,byte 3 81 | .store: 82 | stosb 83 | loopnz .write 84 | 85 | sub edi,ebx 86 | sys_write STDOUT,ebx,edi 87 | 88 | or ebp,ebp 89 | jz .quit 90 | 91 | sys_syslog 4 ;clear the kernel buffer [4] (-c argument) 92 | 93 | .quit: 94 | sys_exit_true 95 | 96 | UDATASEG 97 | 98 | buf resb BUFSIZE 99 | buf_new resb BUFSIZE 100 | 101 | END 102 | -------------------------------------------------------------------------------- /src/echo.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 1999 Konstantin Boldyshev 2 | ; 3 | ;$Id: echo.asm,v 1.5 2000/12/10 08:20:36 konst Exp $ 4 | ; 5 | ;hackers' echo [GNU replacement] 6 | ; 7 | ;syntax: echo [OPTION] [STRING ...] 8 | ; 9 | ;-n do not add newline 10 | ;-e interpretation of the following backslash-escaped characters: 11 | ; \a alert (bell) 12 | ; \b backspace 13 | ; \e escape 14 | ; \c suppress trailing newline 15 | ; \f form feed 16 | ; \n new line 17 | ; \r carriage return 18 | ; \t horizontal tab 19 | ; \v vertical tab 20 | ; \\ backslash 21 | ; \num the character whose ASCII code is NUM (octal). 22 | ;-E explicitly turn off above -e interpretation 23 | ; 24 | ;example: echo -e "\tHello, world!\a" 25 | ; 26 | ;0.01: 17-Jun-1999 initial release 27 | ;0.02: 04-Jul-1999 small bugfixes 28 | ;0.03: 19-Dec-1999 -eE support and full GNU compliance 29 | ;0.04: 08-Feb-2000 \e added ( but what for? :) 30 | ;0.05: 17-Sep-2000 removed trailing '\0' 31 | 32 | 33 | %include "system.inc" 34 | 35 | CODESEG 36 | 37 | %assign BufSize 0x4000 38 | %assign _n 00000001b 39 | %assign _e 00000010b 40 | %assign _E 00000100b 41 | 42 | e_num equ 8 43 | e_asc db "abefnrtv" 44 | e_bin db __a, __b, __e, __f, __n, __r, __t, __v 45 | 46 | START: 47 | _mov edi,Buf 48 | _mov ebp,edi 49 | 50 | pop ebx 51 | dec ebx 52 | jz .final 53 | 54 | pop ebx 55 | 56 | .arguments: 57 | pop ebx 58 | mov esi,ebx 59 | 60 | or esi,esi 61 | jnz .a 62 | 63 | .final: 64 | dec edi 65 | mov edx,edi 66 | sub edx,ebp 67 | or edx,edx 68 | jz .check_n 69 | dec edi 70 | dec edx 71 | 72 | .check_n: 73 | test [flag],byte _n 74 | jnz .write_string 75 | 76 | mov al,__n 77 | stosb 78 | inc edx 79 | 80 | .write_string: 81 | sys_write STDOUT,ebp 82 | 83 | .exit: 84 | sys_exit_true 85 | 86 | .a: 87 | lodsb 88 | cmp al,'-' 89 | jnz .end_of_args 90 | 91 | xor dh,dh ;flag 92 | 93 | .check_args: 94 | lodsb 95 | 96 | or al,al 97 | jnz .switches 98 | or dh,dh 99 | jz .end_of_args 100 | 101 | or [flag],dh 102 | jmp short .arguments 103 | 104 | .switches: 105 | mov dl,_n 106 | cmp al,'n' 107 | jz .found_arg 108 | mov dl,_e 109 | cmp al,'e' 110 | jz .found_arg 111 | mov dl,_E 112 | cmp al,'E' 113 | jz .found_arg 114 | xor dh,dh 115 | jmp short .end_of_args 116 | 117 | .found_arg: 118 | or dh,dl 119 | jmp short .check_args 120 | 121 | ; 122 | ; 123 | ; 124 | 125 | .parse_loop: 126 | 127 | pop ebx 128 | 129 | .end_of_args: 130 | 131 | mov esi,ebx 132 | 133 | or esi,esi 134 | jz .final 135 | 136 | .parse: 137 | lodsb 138 | 139 | xor ebx,ebx 140 | mov dl,[flag] 141 | test dl,_E 142 | jnz .store 143 | test dl,_e 144 | jz .store 145 | 146 | ;escape sequence parsing 147 | 148 | cmp al,'\' 149 | jnz .store 150 | lodsb 151 | cmp al,'\' 152 | jz .store 153 | 154 | cmp al,'c' 155 | jnz .esc 156 | or [flag], byte _n 157 | jmp short .parse 158 | 159 | .esc: 160 | push edi 161 | _mov ecx,e_num 162 | _mov edx,ecx 163 | _mov edi,e_asc 164 | repnz scasb 165 | jnz .octal 166 | 167 | inc ecx 168 | sub edx,ecx 169 | mov al,[e_bin + edx] 170 | pop edi 171 | jmp short .store 172 | 173 | .octal: 174 | pop edi 175 | 176 | push eax 177 | xor edx,edx 178 | mov cx,0x0800 179 | 180 | .next_octal_digit: 181 | cmp al,'0' 182 | jb .done_octal 183 | cmp al,'7' 184 | ja .done_octal 185 | 186 | sub al,'0' 187 | mov dh,al 188 | mov al,dl 189 | mul ch 190 | mov dl,al 191 | add dl,dh 192 | 193 | cmp cl,2 194 | jnz .next_char 195 | mov cl,-1 196 | jmp short .done_octal 197 | 198 | .next_char: 199 | lodsb 200 | inc ecx 201 | jmp short .next_octal_digit 202 | 203 | .no_esc: 204 | push eax 205 | mov al,'\' 206 | stosb 207 | pop eax 208 | 209 | .store: 210 | stosb 211 | or al,al 212 | jnz .parse 213 | or ebx,ebx 214 | jnz .parse 215 | mov al,' ' 216 | stosb 217 | jmp .parse_loop 218 | 219 | .done_octal: 220 | pop eax 221 | 222 | or cl,cl 223 | jz .no_esc 224 | 225 | cmp cl,-1 226 | jz .restore_orig 227 | 228 | dec esi 229 | 230 | .restore_orig: 231 | mov al,dl 232 | or al,al 233 | jnz .store 234 | inc ebx 235 | jmps .store 236 | 237 | UDATASEG 238 | 239 | flag resb 1 240 | Buf resb BufSize 241 | 242 | END 243 | -------------------------------------------------------------------------------- /src/env.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 2000 Edward Popkov 2 | ; 3 | ;$Id: env.asm,v 1.3 2002/02/02 08:49:25 konst Exp $ 4 | ; 5 | ;hackers' env 6 | ; 7 | ;syntax: env 8 | ; 9 | ;0.01: 27-Feb-2000 initial release 10 | 11 | %include "system.inc" 12 | 13 | CODESEG 14 | 15 | START: 16 | pop ebp 17 | .env: 18 | inc ebp 19 | mov esi,[esp + ebp * 4] 20 | test esi,esi 21 | jz do_exit 22 | mov ecx,esi 23 | xor edx,edx 24 | dec edx 25 | .slen: 26 | inc edx 27 | lodsb 28 | test al,al 29 | jnz .slen 30 | mov [esi-1],byte 0xa 31 | inc edx 32 | sys_write STDOUT 33 | jmps .env 34 | 35 | do_exit: 36 | sys_exit_true 37 | 38 | END 39 | -------------------------------------------------------------------------------- /src/extname.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 2000 H-Peter Recktenwald 2 | ; 3 | ;$Id: extname.asm,v 1.3 2000/12/10 08:20:36 konst Exp $ 4 | ; 5 | ;hackers' extname (return extension or postfix of a given filename) 6 | ; 7 | ;syntax: extname { filename | - } [delimiter] 8 | ; "-" instead of filename for input from stdin 9 | ; delimiter is "." by default or, 10 | ; optionally any 1st (and 2nd) char of any length argument stg. 11 | ; 12 | ;if delimiter found: 13 | ; ret. part of basename after and inclusive delimiter or, 14 | ; ret extension not including dlm if arg is double dlm char. 15 | ; for instance, 16 | ; echo $(echo "yesterday was sunday"|extname - \ ) 17 | ; writes 18 | ; sunday 19 | ;if delimiter not found: 20 | ; empty string if no dlm found or only a leading single dlm. 21 | ; for instance, 22 | ; echo $(echo ".yesterday was sunday"|extname -) 23 | ; writes the empty string 24 | ; 25 | ;exitcode: 26 | ; 1 if no argument given, 0 otherwise 27 | ; 28 | ; ------------------------------------------------------------------- ; 29 | ; 30 | ;0.01: 25-mar-2000 initial release 31 | ;0.02: 02-apr-2000 scan basename part only 32 | ;0.03: 14-apr-2000 modified to 33 | ; accept filename from stdin/pipe and to complement `basename`: 34 | ; default and arg single (1st) char as dlm returns the names 35 | ; extension with leading delimiter inclusive, 36 | ; if arg leading 2 chars are same, returnstring is extension 37 | ; only, not including the delimiter char. 38 | ; compile option WITH_DLM can be used to force default and 39 | ; single delimiter chars mode, only. 40 | ; 41 | ; ------------------------------------------------------------------- ; 42 | 43 | %include "system.inc" 44 | 45 | ;override compile options from Makefile: 46 | ; 47 | ;define to saving a few bytes if you'd know for certain that 48 | ; no pathnames will be passed to , e.g always 49 | ; used after "basename", or, if the expected delimiter 50 | ; will be at some position, unknown but always present. 51 | ;%define BASENAME 52 | ;%undef BASENAME 53 | 54 | ;define for alternate behaviour, 55 | ; to force returning xtn with leading delmiter, only. 56 | ;%define WITH_DLM 57 | ;%undef WITH_DLM 58 | 59 | ddir: equ '/' ; filename delimiter (directory marker) 60 | dext: equ '.' ; default extension delimiter 61 | 62 | 63 | CODESEG 64 | 65 | START: 66 | pop ebx 67 | dec ebx 68 | dec ebx 69 | js .j 70 | pop edi ; drop progname 71 | ; try filename from stdin 72 | mov eax,[esp] 73 | cmp byte[eax],'-' 74 | jnz .g ; name not from stdin 75 | mov ecx,fpath 76 | mov [esp],ecx ; overwrite option ptr 77 | push ebx 78 | mov edx,PATH_MAX 79 | sys_read STDIN 80 | test eax,eax 81 | .j: 82 | js .r ;?; neither arg nor input 83 | pop ebx 84 | .g: 85 | mov ah,dext ; default dlm 86 | pop edi ; 1st arg 87 | dec ebx 88 | js .a ; no.. 89 | pop eax ; ..delimiter 90 | mov eax,dword[eax] 91 | cmp ah,al 92 | jz .s ; doubly 93 | mov ah,al 94 | stc 95 | .s: 96 | cmc ; C is flag for double dlm 97 | .a: 98 | rcl eax,1 ; preserve delimiter 99 | ror eax,1 ; store flag to signbit 100 | cld ; scan forward 101 | ; find string 102 | xor ecx,ecx 103 | mov al,cl 104 | dec ecx 105 | repnz scasb 106 | std ; scan back 107 | not ecx 108 | mov edx,ecx 109 | %ifndef BASENAME 110 | ; discriminate basename 111 | mov al,ddir ; dirname delimiter 112 | dec edi 113 | dec edx 114 | repnz scasb 115 | jz .b 116 | dec edi ; full length 117 | .b: 118 | sub edx,ecx ; maxlen 119 | mov ecx,edx 120 | lea edi,[2+edx+edi] ; basename 121 | %endif 122 | mov al,ah ; delimiter 123 | dec edi ; pts to before dlm, if found 124 | dec edx 125 | repnz scasb 126 | jz .f 127 | .n: 128 | mov ecx,edx ; ret empty 129 | inc ecx 130 | .f: 131 | test ecx,ecx 132 | jz .n ;?; ret empty if dlm is leading char of filename 133 | %ifdef WITH_DLM ;compile option: extn with leading dlm mode, only 134 | dec ecx 135 | sub edx,ecx 136 | lea ecx,[edi+1] ; compensate for dlm & 137 | %else 138 | sar eax,31 ; -1 if extn w.o. dlm 139 | dec ecx 140 | sub ecx,eax 141 | sub edx,ecx 142 | lea ecx,[edi+1] ; compensate for dlm & 143 | sub ecx,eax 144 | %endif 145 | mov [ecx+edx],byte __n 146 | inc edx 147 | sys_write STDOUT 148 | xor ebx,ebx 149 | .r: 150 | ; neg ebx ;(can be dispensed with -> exit 255 w.o. args, shorter code) 151 | sys_exit 152 | 153 | UDATASEG 154 | 155 | fpath: resd (PATH_MAX+7)/4 156 | 157 | END 158 | -------------------------------------------------------------------------------- /src/free.asm: -------------------------------------------------------------------------------- 1 | ; Copyright (C) 2002 Thomas M. Ogrisegg 2 | ; 3 | ; free - display system memory usage 4 | ; 5 | ; syntax: 6 | ; free 7 | ; 8 | ; License : GNU General Public License 9 | ; Author : Thomas Ogrisegg 10 | ; E-Mail : tom@rhadamanthys.org 11 | ; Version : 0.5 12 | ; Release-Date : 03/20/02 13 | ; GNU-compatible : no 14 | ; Operatingsystem : Linux/x86 15 | ; 16 | ; $Id: free.asm,v 1.2 2002/06/11 08:45:10 konst Exp $ 17 | 18 | %include "system.inc" 19 | 20 | CODESEG 21 | 22 | ;; <- %eax (number to convert) 23 | ;; -> %edi (output written to (edi)) 24 | ltostr: 25 | _mov ebx, 0x0a 26 | _mov ecx, 0x7 27 | or eax, eax 28 | jnz .Ldiv 29 | mov byte [edi+ecx], '0' 30 | dec ecx 31 | jmps .Lout 32 | .Ldiv: 33 | or eax, eax 34 | jz .Lout 35 | xor edx, edx 36 | idiv ebx 37 | add dl, '0' 38 | mov byte [edi+ecx], dl 39 | dec ecx 40 | jnz .Ldiv 41 | .Lout: 42 | add edi, ecx 43 | inc ecx 44 | std 45 | mov al, ' ' 46 | repnz stosb 47 | cld 48 | _add edi, 0x9 49 | _mov ecx, 0x3 50 | repnz stosb 51 | ret 52 | 53 | START: 54 | sys_write STDOUT, header, headerlen 55 | mov ebp, esp 56 | sys_sysinfo ebp 57 | sub esp, 80 58 | mov edi, esp 59 | mov eax, [ebp+sysinfo.totalram] 60 | shr eax, 0xa ; div 1024 61 | call ltostr 62 | mov eax, [ebp+sysinfo.totalram] 63 | sub eax, [ebp+sysinfo.freeram] 64 | shr eax, 0xa 65 | call ltostr 66 | mov eax, [ebp+sysinfo.freeram] 67 | shr eax, 0xa 68 | call ltostr 69 | mov eax, [ebp+sysinfo.sharedram] 70 | shr eax, 0xa 71 | call ltostr 72 | mov eax, [ebp+sysinfo.bufferram] 73 | shr eax, 0xa 74 | call ltostr 75 | mov byte [edi], __n 76 | mov edi, esp 77 | sys_write STDOUT, edi, 60 78 | sys_write STDOUT, header2, header2len 79 | mov eax, [ebp+sysinfo.totalswap] 80 | shr eax, 0xa 81 | call ltostr 82 | mov eax, [ebp+sysinfo.totalswap] 83 | sub eax, [ebp+sysinfo.freeswap] 84 | shr eax, 0xa 85 | call ltostr 86 | mov eax, [ebp+sysinfo.freeswap] 87 | shr eax, 0xa 88 | call ltostr 89 | mov byte [edi], __n 90 | mov ecx, esp 91 | sys_write STDOUT, EMPTY, 34 92 | sys_exit 0x0 93 | 94 | tab db __t 95 | header db " total used free shared buffers", __n, "Mem: " 96 | headerlen equ $ - header 97 | 98 | header2 db "Swap: " 99 | header2len equ $ - header2 100 | 101 | END 102 | -------------------------------------------------------------------------------- /src/fromdos.asm: -------------------------------------------------------------------------------- 1 | ; Copyright (C) 2001, Tiago Gasiba (ee97034@fe.up.pt) 2 | ; 3 | ; $Id: fromdos.asm,v 1.1 2001/08/19 12:41:59 konst Exp $ 4 | ; 5 | ; hackers' fromdos/todos 6 | ; 7 | ; This program converts ascii text files from DOS/UNIX 8 | ; to UNIX/DOS formats 9 | ; 10 | ; Example of usage: 11 | ; fromdos < text.dos > text.unix 12 | ; todos < text.unix > text.dos 13 | ; 14 | 15 | %include "system.inc" 16 | 17 | CODESEG 18 | NEW_CHAR db 0xd 19 | 20 | START: 21 | pop eax ; argc 22 | dec eax 23 | jnz .saida 24 | pop esi ; argv[0] 25 | .n1: ; how we are called? 26 | lodsb 27 | or al,al 28 | jnz .n1 29 | 30 | _mov ecx,buffer ; save in ecx addr buffer 31 | 32 | .repete: 33 | sys_read STDIN,ecx,1 34 | 35 | test eax,eax 36 | jz .saida 37 | 38 | cmp word [esi-6],'om' ; executing fromdos ??? 39 | je .fromdos 40 | 41 | .todos: ; assume we're executing todos 42 | cmp byte [ecx],0xa ; search for Line Feed 43 | jne .continua 44 | 45 | push ecx 46 | sys_write STDOUT,NEW_CHAR,1 ; insert Carriage Return 47 | pop ecx 48 | 49 | .continua: 50 | sys_write STDOUT,ecx,1 ; write read char 51 | jmp short .repete 52 | 53 | .fromdos: 54 | cmp byte [ecx],0xd ; search for Carriage Return 55 | je .repete 56 | jmp short .continua 57 | 58 | .saida: 59 | sys_exit 0 60 | 61 | UDATASEG 62 | buffer resb 1 63 | 64 | END 65 | -------------------------------------------------------------------------------- /src/getty.asm: -------------------------------------------------------------------------------- 1 | ; Copyright (C) 2002 Thomas M. Ogrisegg 2 | ; 3 | ; getty - show login prompt 4 | ; 5 | ; syntax: 6 | ; getty tty-device 7 | ; 8 | ; License : GNU General Public License 9 | ; Author : Thomas Ogrisegg 10 | ; E-Mail : tom@rhadamanthys.org 11 | ; Version : 1.0 12 | ; Created : 06/06/02 13 | ; 14 | ; $Id: getty.asm,v 1.2 2006/02/09 08:02:57 konst Exp $ 15 | ; 16 | ; This getty (as most others) expects a /bin/login program to 17 | ; do the actual authentication. 18 | ; 19 | 20 | %include "system.inc" 21 | 22 | %ifdef __LINUX__ 23 | %define HAVE_VHANGUP 24 | %define WANT_CLEAR 25 | %endif 26 | 27 | CODESEG 28 | 29 | __issue db "/etc/issue", NULL 30 | __dev db "/dev", NULL 31 | __login db "/bin/login", NULL 32 | __ddash db "--", NULL 33 | __clear db 0x1b,"[H",0x1b,"[J" 34 | 35 | issue: 36 | mov edi, iobuf 37 | sys_open __issue, O_RDONLY 38 | or eax, eax 39 | js near .Lret 40 | mov ebp, eax 41 | push ebp 42 | sys_lseek eax, 0, SEEK_END 43 | or eax, eax 44 | js near .Lret 45 | push eax 46 | push edi 47 | sys_mmap NULL, eax, PROT_READ, MAP_PRIVATE, ebp, 0 48 | pop edi 49 | push eax 50 | or eax, eax 51 | js near .Lret 52 | mov esi, eax 53 | ;; Just like other getty's... 54 | mov al, __n 55 | stosb 56 | .Liloop: 57 | lodsb 58 | or al, al 59 | jz near .Lmapret 60 | cmp al, '\' 61 | jnz near .Lstos 62 | lodsb 63 | cmp al, 's' 64 | jnz .Lnext1 65 | mov eax, uname.sysname 66 | jmp .Lstrcpy 67 | .Lnext1: 68 | cmp al, 'n' 69 | jnz .Lnext2 70 | mov eax, uname.nodename 71 | jmp .Lstrcpy 72 | .Lnext2: 73 | cmp al, 'm' 74 | jnz .Lnext3 75 | mov eax, uname.machine 76 | jmp .Lstrcpy 77 | .Lnext3: 78 | cmp al, 'o' 79 | jnz .Lnext4 80 | mov eax, uname.domainname 81 | jmp .Lstrcpy 82 | .Lnext4: 83 | cmp al, 'r' 84 | jnz .Lnext5 85 | mov eax, uname.release 86 | jmp .Lstrcpy 87 | .Lnext5: 88 | cmp al, 'v' 89 | jnz .Lnext6 90 | mov eax, uname.version 91 | jmp .Lstrcpy 92 | .Lnext6: 93 | cmp al, 'l' 94 | jnz .Lstos 95 | mov eax, [tty] 96 | jmp .Lstrcpy 97 | .Lstrcpy: 98 | push esi 99 | mov esi, eax 100 | .Llabel: 101 | lodsb 102 | stosb 103 | or al, al 104 | jnz .Llabel 105 | dec edi 106 | pop esi 107 | jmp .Liloop 108 | .Lstos: 109 | stosb 110 | jmp .Liloop 111 | .Lmapret: 112 | pop eax 113 | pop ebx 114 | sys_munmap eax, ebx 115 | pop eax 116 | sys_close eax 117 | .Lret: 118 | mov esi, uname.nodename 119 | .Lcopy: 120 | lodsb 121 | stosb 122 | or al, al 123 | jnz .Lcopy 124 | dec edi 125 | .Lcopy2: 126 | mov long [edi], ' log' 127 | mov long [edi+4], 'in: ' 128 | add edi, 8 129 | 130 | ret 131 | 132 | START: 133 | pop ecx 134 | lea eax, [esp+ecx*4+4] 135 | mov [envp], eax 136 | dec ecx 137 | jz near exit 138 | pop esi 139 | pop long [tty] 140 | sys_uname uname 141 | sys_signal SIGHUP, SIG_IGN 142 | %ifdef HAVE_VHANGUP 143 | sys_vhangup 144 | %endif 145 | sys_close STDIN 146 | sys_close STDOUT 147 | sys_close STDERR 148 | sys_chdir __dev 149 | sys_open [tty], O_RDWR 150 | or eax, eax 151 | js near exit 152 | jnz near exit 153 | sys_dup STDIN 154 | sys_dup STDIN 155 | sys_fchmod STDIN, 0600 156 | %ifdef WANT_CLEAR 157 | sys_write STDOUT, __clear, 6 158 | %endif 159 | call issue 160 | ; lea edx, [edi-iobuf] 161 | mov edx,edi 162 | sub edx,iobuf 163 | sys_write STDOUT, iobuf 164 | sys_setsid 165 | sys_read STDIN, iobuf, 0x200 166 | or eax, eax 167 | js exit 168 | mov byte [iobuf+eax-1], 0 169 | push long NULL 170 | push long iobuf 171 | push long __ddash 172 | push long __login 173 | mov edi, esp 174 | sys_execve __login, edi, [envp] 175 | exit: 176 | sys_exit 0 177 | 178 | UDATASEG 179 | issmap ULONG 1 180 | maplen ULONG 1 181 | tty ULONG 1 182 | envp ULONG 1 183 | uname B_STRUC utsname,.sysname,.nodename,.release,.version,.machine,.domainname 184 | iobuf UCHAR 0x200 185 | END 186 | -------------------------------------------------------------------------------- /src/gi.asm: -------------------------------------------------------------------------------- 1 | ; Copyright (C) 2004 by Joshua Hudson 2 | ; 3 | ; $Id: gi.asm,v 1.2 2006/02/18 10:04:00 konst Exp $ 4 | ; 5 | ; asmutils gi 6 | ; 7 | ; gi displays IP address of a given network interface 8 | ; 9 | ; Usage: gi eth0 10 | ; 11 | ; Return value is weird: 12 | ; returns number of chars written including nl 13 | ; return value > 16 is an error 14 | 15 | %include 'system.inc' 16 | CODESEG 17 | 18 | START: 19 | pop eax 20 | pop esi 21 | pop esi 22 | or esi, esi 23 | jz .exit 24 | sys_socket AF_INET, SOCK_DGRAM, IPPROTO_IP 25 | xchg eax, ebx 26 | mov edi, ifreq 27 | mov edx, edi 28 | .copy lodsb 29 | stosb 30 | cmp al, 0 31 | jnz .copy 32 | _mov ecx, SIOCGIFADDR 33 | sys_ioctl 34 | or eax, eax 35 | js .exit 36 | mov edi, ifreq ; Override ioctl buffer 37 | mov ebp, [addr] 38 | push edi 39 | 40 | mov ecx, 4 41 | .nbyte mov eax, ebp 42 | shr ebp, 8 43 | push ecx 44 | and eax, 255 45 | 46 | xor ecx, ecx 47 | _mov ebx, 10 48 | .itoa_l xor edx, edx 49 | div ebx 50 | add dl, '0' 51 | inc ecx 52 | or eax, eax 53 | push edx 54 | jnz .itoa_l 55 | .itoa_p pop eax 56 | stosb 57 | loop .itoa_p 58 | 59 | mov al, '.' 60 | pop ecx 61 | stosb 62 | loop .nbyte 63 | 64 | mov [edi - 1], byte __n 65 | pop ecx 66 | mov edx, edi 67 | sub edx, ecx 68 | sys_write STDOUT 69 | .exit sys_exit eax 70 | 71 | UDATASEG 72 | ifreq resb 16 ; name 73 | flags resb 2 74 | port resb 2 75 | addr resb 2 76 | unused resb 8 77 | END 78 | -------------------------------------------------------------------------------- /src/head.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 2000 Jonathan Leto 2 | ; 3 | ;$Id: head.asm,v 1.4 2002/02/02 08:49:25 konst Exp $ 4 | ; 5 | ;hackers' head 6 | ; 7 | ;syntax: head [-n #] [-c #] file [file] ... 8 | ; 9 | ;return 0 on success, 1 on error 10 | ;ascii_to_num from strings.asm by Dmitry Bakhvalov 11 | ; 12 | ;This is slightly over-commented, hopefully someone can learn from it. 13 | ; 14 | ;Version 0.1 - Sun Dec 10 00:01:52 EST 2000 15 | ;Version 0.2 - Tue Oct 09 12:24:26 EST 2001 - Fixed reading from stdin -JH 16 | 17 | %include "system.inc" 18 | 19 | %assign BUFSIZE 0x2000 20 | 21 | ;ebp = file descriptor 22 | ;edi = return code 23 | 24 | CODESEG 25 | 26 | START: 27 | _mov [chars],dword 0 ; lines by default 28 | _mov [lines],dword 10 ; default to 10 lines 29 | _mov edi,0 ; default return value 30 | _mov ebp,STDIN ; default file descriptor 31 | pop ebx ; argc 32 | dec ebx 33 | pop ebx ; argv[0], program name 34 | jz .read ; read stdin if no args 35 | jmps .nextfile 36 | 37 | .set_chars: 38 | pop esi 39 | call .ascii_to_num 40 | _mov [chars], eax 41 | jmps .nextfile 42 | 43 | .set_num_of_lines: 44 | pop esi 45 | call .ascii_to_num 46 | _mov [lines], eax 47 | jmps .nextfile 48 | 49 | .prepfile: 50 | sys_close ebp ; Close the file discriptor 51 | inc ebp ; If we read stdin, trigger end 52 | .nextfile: 53 | pop ebx ; get next arg 54 | or ebx,ebx 55 | jnz .n2 ; exit if none 56 | .exit: 57 | or ebp, ebp ; If read no files (ebp = STDIN,0) 58 | jz .read ; Read stdin! 59 | sys_exit edi ; exit with return value 60 | .n2: 61 | cmp word [ebx], "-n" 62 | je .set_num_of_lines 63 | 64 | cmp word [ebx], "-c" 65 | je .set_chars 66 | 67 | sys_open ebx,O_RDONLY 68 | xchg ebp,eax 69 | ;_mov ebp,eax ; save fd 70 | test ebp,ebp 71 | jns .read ; successful open is > 0 72 | 73 | .error: 74 | inc edi 75 | jmps .nextfile ; try to open next file 76 | 77 | .read: 78 | _mov ecx,buf 79 | _mov edx,BUFSIZE 80 | .readloop: 81 | sys_read ebp 82 | test eax,eax 83 | js .error ; fd < 0, error 84 | jz .prepfile ; EOF, go to next file 85 | 86 | mov esi,[chars] 87 | test esi,esi 88 | ; cmp [chars],dword 0 89 | jg .print_chars 90 | 91 | xor esi,esi ; set to zero 92 | dec esi ; set to -1 so loop can have inc esi at top 93 | _mov ebx,eax ; keep size of read for test against counter 94 | 95 | .findnewlines: 96 | inc esi 97 | cmp esi,ebx 98 | jg .write 99 | cmp [ecx+esi],byte 0xa ; is it a newline? 100 | jne .findnewlines ; keep looking 101 | 102 | .dec_lines: 103 | dec dword [lines] 104 | mov eax,[lines] 105 | test eax,eax 106 | jnz .findnewlines ; keep finding newlines 107 | 108 | .write: ; found enough newlines 109 | 110 | inc esi ; add one to esi for last newline 111 | .print_chars: 112 | sys_write STDOUT,ecx,esi ; print 113 | jmp .nextfile 114 | 115 | ;--------------------------------------- 116 | ; esi = string 117 | ; eax = number 118 | .ascii_to_num: 119 | xor eax,eax ; zero out regs 120 | xor ebx,ebx 121 | .next_digit: 122 | lodsb ; load byte from esi 123 | test al,al 124 | jz .done 125 | sub al,'0' ; '0' is first number in ascii 126 | imul ebx,10 127 | add ebx,eax 128 | jmp short .next_digit 129 | .done: 130 | xchg ebx,eax ; ebx=eax,eax=ebx 131 | ret 132 | ;--------------------------------------- 133 | 134 | UDATASEG 135 | 136 | lines resd 1 137 | chars resd 1 138 | buf resb BUFSIZE 139 | 140 | END 141 | -------------------------------------------------------------------------------- /src/hostname.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 1999-2001 Konstantin Boldyshev 2 | ; 3 | ;$Id: hostname.asm,v 1.8 2002/02/02 08:49:25 konst Exp $ 4 | ; 5 | ;hackers' hostname/domainname 6 | ; 7 | ;syntax: hostname [name] 8 | ; domainname [name] 9 | ; 10 | ;if name parameter is omited it displays name, else sets it to name 11 | ;you must be root to set host/domain name 12 | ; 13 | ;0.01: 05-Jun-1999 initial release 14 | ;0.02: 17-Jun-1999 size improvements 15 | ;0.03: 04-Jun-1999 domainname added 16 | ;0.04: 18-Sep-1999 elf macros support 17 | ;0.05: 03-Sep-2000 portable utsname, BSD port 18 | ;0.06: 04-Mar-2001 size improvements 19 | ;0.07: 03-Dec-2001 sysctl-based version 20 | 21 | %include "system.inc" 22 | 23 | ;NOTE: sysctl-based version works on Linux as well; 24 | ;however, as sysctl support can be disabled in Linux kernel, 25 | ;sysctl-based version is not used by default on Linux. 26 | 27 | %ifdef __BSD__ 28 | %define USE_SYSCTL 29 | %endif 30 | 31 | CODESEG 32 | 33 | START: 34 | xor edi,edi ;{host|domain}name flag 35 | 36 | pop ebx 37 | pop esi 38 | .n1: 39 | lodsb 40 | or al,al 41 | jnz .n1 42 | cmp dword [esi-9],'host' 43 | jz .n2 44 | inc edi ;we are called as domainname 45 | .n2: 46 | dec ebx 47 | jz .getname ;no parameters, write current name 48 | 49 | pop ebx ;name parameter 50 | 51 | mov esi,ebx ;calculate name length in esi 52 | .n3: 53 | lodsb 54 | or al,al 55 | jnz .n3 56 | sub esi,ebx 57 | dec esi 58 | 59 | %ifdef USE_SYSCTL 60 | 61 | mov eax,kern_hostname_req 62 | dec edi 63 | jnz .sysctl_set 64 | add eax,byte 8 65 | .sysctl_set: 66 | sys_sysctl eax, 2, 0, 0, ebx, esi 67 | 68 | %else 69 | 70 | mov ecx,esi 71 | dec edi 72 | jz .setdomain 73 | sys_sethostname 74 | jmps .done_set 75 | .setdomain: 76 | sys_setdomainname 77 | 78 | %endif 79 | 80 | .done_set: 81 | jmps do_exit 82 | 83 | .getname: 84 | 85 | %ifdef USE_SYSCTL 86 | 87 | mov dword [len],SYS_NMLN*2 88 | mov eax,kern_hostname_req 89 | mov edx,buf 90 | dec edi 91 | jnz .sysctl_get 92 | add eax,byte 8 93 | .sysctl_get: 94 | sys_sysctl eax, 2, edx, len, 0, 0 95 | test eax,eax 96 | js do_exit 97 | mov esi,edx 98 | 99 | %else 100 | 101 | mov esi,h 102 | sys_uname esi 103 | _add esi,utsname.nodename 104 | dec edi 105 | jnz .done_get 106 | _add esi,utsname.domainname-utsname.nodename 107 | 108 | %endif 109 | 110 | .done_get: ;esi should point to name buffer 111 | 112 | xor edx,edx 113 | .strlen: 114 | lodsb 115 | inc edx 116 | or al,al 117 | jnz .strlen 118 | mov byte [esi-1],__n 119 | sub esi,edx 120 | sys_write STDOUT,esi 121 | xor eax,eax 122 | do_exit: 123 | sys_exit eax 124 | 125 | %ifdef USE_SYSCTL 126 | kern_hostname_req: 127 | dd CTL_KERN 128 | dd KERN_HOSTNAME 129 | kern_domainname_req: 130 | dd CTL_KERN 131 | dd KERN_DOMAINNAME 132 | %endif 133 | 134 | UDATASEG 135 | 136 | %ifdef USE_SYSCTL 137 | 138 | len resd 1 139 | buf resb SYS_NMLN*2 140 | 141 | %else 142 | 143 | h B_STRUC utsname,.nodename,.domainname 144 | 145 | %endif 146 | 147 | END 148 | -------------------------------------------------------------------------------- /src/id.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 1999 Dmitry Bakhvalov 2 | ; 3 | ;$Id: id.asm,v 1.6 2001/08/14 18:55:38 konst Exp $ 4 | ; 5 | ;hackers' id 6 | ; 7 | ;0.01: 25-Oct-1999 initial release 8 | ;0.02: 07-Apr-2000 squeezed few bytes (KB) 9 | ;0.03: 11-Aug-2001 added groups=list (JH) 10 | ; 11 | ;syntax: id 12 | ; No options so far. 13 | ; 14 | ; Always returns 0 15 | ; 16 | %include "system.inc" 17 | 18 | CODESEG 19 | 20 | START: 21 | sys_getuid 22 | mov ebx,"uid=" 23 | call print_stuff 24 | 25 | sys_getgid 26 | mov bl,'g' ; ebx="gid=" 27 | call print_stuff 28 | 29 | call .groups 30 | 31 | mov cl,10 ; print "\n" 32 | push ecx 33 | sys_write STDOUT,esp,1 34 | 35 | sys_exit_true 36 | 37 | .groups: ;*** Get GROUPS 38 | sys_getgroups 64, groups 39 | mov ebp, eax 40 | mov dl, 7 ; Looks like a bug, but it works. 41 | mov ecx, gstuff 42 | sys_write STDOUT 43 | 44 | mov esi, groups 45 | or ebp, ebp 46 | jz .nogroups 47 | .forallgroups: 48 | mov edi, num_buf 49 | push edi 50 | mov ax, [esi] 51 | inc esi 52 | inc esi 53 | call bin_to_dec 54 | dec ebp 55 | or ebp, ebp 56 | jz .nocomma 57 | mov al, ',' 58 | stosb 59 | .nocomma: 60 | mov edx, edi 61 | pop ecx 62 | sub edx, ecx 63 | sys_write STDOUT 64 | or ebp, ebp 65 | jnz .forallgroups 66 | .nogroups: 67 | ret 68 | 69 | print_stuff: 70 | pushad 71 | 72 | test eax,eax 73 | js .error 74 | 75 | mov edi,num_buf 76 | push edi ; save num_buf 77 | push ebx ; save "uid=" 78 | call bin_to_dec 79 | mov al,9 80 | stosb 81 | 82 | pop ebx ; restore "uid=" 83 | 84 | push ebx ; put "uid=" on the stack 85 | mov ecx,esp ; point ecx to it 86 | mov dl,4 ; len=4 87 | sys_write STDOUT ; write 88 | pop ebx ; restore stack 89 | 90 | pop esi ; restore num_buf 91 | 92 | mov ecx,esi ; save it in ecx 93 | mov edx,edi 94 | sub edx,ecx 95 | 96 | ; ecx already holds string, edx holds strlen 97 | sys_write STDOUT 98 | 99 | .error: 100 | popad 101 | ret 102 | 103 | bin_to_dec: ; Pointer to num_buf in edi, number in eax 104 | xor ecx,ecx 105 | mov ebx,ecx 106 | mov bl,10 107 | .div_again: 108 | xor edx,edx 109 | div ebx 110 | add dl,'0' 111 | push edx 112 | inc ecx 113 | test eax,eax 114 | jnz .div_again 115 | .keep_popping: 116 | pop eax 117 | stosb 118 | loop .keep_popping 119 | ret 120 | 121 | gstuff db 'groups=' 122 | 123 | UDATASEG 124 | groups: resw 64 125 | num_buf: resb 16 126 | 127 | END 128 | -------------------------------------------------------------------------------- /src/init.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 2001 Karsten Scheibler 2 | ; 3 | ;$Id: init.asm,v 1.4 2002/08/16 15:05:18 konst Exp $ 4 | ; 5 | ;simple init 6 | ; 7 | ;syntax: init 8 | ; 9 | ;example: init 10 | ; 11 | ;0.01: 03-Mar-2001 initial release 12 | ;0.02: 27-Feb-2002 execute rc script on startup (KB) 13 | ;0.03: 19-Jun-2002 wait for rc script to finish (KB) 14 | 15 | %include "system.inc" 16 | 17 | %assign MAX_TTYS 4 18 | 19 | %define TTY_PATH "/dev/tty" 20 | %define SHELL_PATH "/bin/sh" 21 | %define RC_PATH "/etc/rc" 22 | 23 | CODESEG 24 | 25 | START: 26 | sys_fork 27 | test eax, eax 28 | jnz .skip 29 | sys_execve [arguments_rc], arguments_rc, environment 30 | mov ebx,eax 31 | jmp do_exit 32 | .skip: 33 | sys_wait4 eax, NULL, 0, NULL 34 | ;--------------- 35 | ;initialize ttys 36 | ;--------------- 37 | xor dword ebp, ebp 38 | .init_loop: inc dword ebp 39 | call tty_initialize 40 | cmp dword ebp, MAX_TTYS 41 | jb .init_loop 42 | 43 | ;------------------------ 44 | ;wait for child processes 45 | ;------------------------ 46 | 47 | .wait: sys_wait4 0xffffffff, NULL, NULL, NULL 48 | test dword eax, eax 49 | js .wait 50 | 51 | ;----------------------------------------------- 52 | ;find the PID of the child process and respawn a 53 | ;shell process on the right tty 54 | ;----------------------------------------------- 55 | 56 | xor dword ebp, ebp 57 | .respawn_loop: inc dword ebp 58 | cmp dword ebp, MAX_TTYS 59 | ja .wait 60 | cmp dword [pids + 4 * ebp - 4], eax 61 | jne .respawn_loop 62 | call tty_initialize 63 | jmp short .wait 64 | 65 | 66 | tty_initialize: 67 | ;------------------------------------------------ 68 | ;convert the number in ebp to an ASCII character, 69 | ;store it in the tty_path and open this file 70 | ;------------------------------------------------ 71 | 72 | mov dword eax, ebp 73 | cmp byte al, 009h 74 | jbe .ok 75 | mov byte al, 009h 76 | .ok: add byte al, 030h 77 | mov byte [tty_path.number], al 78 | sys_open tty_path, O_RDWR 79 | test dword eax, eax 80 | js near .error 81 | 82 | ;------------------------------------------------- 83 | ;initialize the terminal (maybe not all of this is 84 | ;really necessary) 85 | ;------------------------------------------------- 86 | 87 | mov dword [tty_fd], eax 88 | mov dword ebx, eax 89 | sys_dup2 EMPTY, STDIN 90 | sys_dup2 [tty_fd], STDOUT 91 | sys_dup2 [tty_fd], STDERR 92 | sys_fcntl STDIN, F_SETFL, O_RDONLY 93 | sys_fcntl STDOUT, F_SETFL, O_WRONLY 94 | sys_fcntl STDERR, F_SETFL, O_WRONLY 95 | sys_ioctl [tty_fd], TCGETS, tty_termios 96 | sys_ioctl [tty_fd], TCSETSW, tty_termios 97 | mov dword eax, [tty_fd] 98 | cmp dword eax, STDERR 99 | jbe .skip 100 | sys_close [tty_fd] 101 | .skip: 102 | ;----------------------------------------------------- 103 | ;create a child process and try to execute a shell. 104 | ;if this fails print an error message wait 300 seconds 105 | ;(look at select_timeval) and exit. 106 | ;----------------------------------------------------- 107 | 108 | sys_fork 109 | test dword eax, eax 110 | js .error 111 | jnz .exit 112 | sys_execve [arguments_shell], arguments_shell, environment 113 | test dword eax, eax 114 | jns .terminate 115 | sys_write STDERR, shell_not_found, shell_path_length 116 | sys_select 0, NULL, NULL, NULL, select_timeval 117 | _mov ebx,1 118 | jmps do_exit 119 | 120 | .error: xor dword eax, eax 121 | dec dword eax 122 | .exit: mov dword [pids + 4 * ebp - 4], eax 123 | ret 124 | .terminate: 125 | _mov ebx,0 126 | do_exit: 127 | sys_exit 128 | 129 | 130 | shell_not_found: db "can't find " 131 | shell_path: db SHELL_PATH, 0, 10 132 | shell_path_length: equ $ - shell_not_found 133 | rc_path: db RC_PATH, 0 134 | align 4 135 | arguments_shell: dd shell_path 136 | environment: dd 0 137 | arguments_rc: dd rc_path 138 | dd 0 139 | select_timeval: dd 300 140 | dd 0 141 | 142 | DATASEG 143 | 144 | tty_path: db TTY_PATH 145 | .number: db 0, 0 146 | 147 | UDATASEG 148 | alignb 4 149 | pids: resd MAX_TTYS 150 | tty_fd: resd 1 151 | tty_termios: resd 01000h 152 | 153 | END 154 | -------------------------------------------------------------------------------- /src/kill.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 1999 Bart Hanssens 2 | ; 3 | ;$Id: kill.asm,v 1.1.1.1 2000/01/26 21:19:32 konst Exp $ 4 | ; 5 | ;hackers' kill (util-linux kill replacement) 6 | ; 7 | ;0.01: 04-Jul-1999 initial release 8 | ; 9 | ;syntax: kill signal pid 10 | ; kill -l 11 | ; 12 | ; TODO: add process name 13 | ; add -s 14 | ; add -p 15 | 16 | 17 | ;You can compile two versions - large & small. 18 | ;Large recognizes signal names, small doesnot (only numbers). 19 | 20 | %include "system.inc" 21 | 22 | ; 23 | ;Compile large or small version? 24 | ; 25 | 26 | %define LARGE_KILL 27 | ;%undef LARGE_KILL 28 | 29 | CODESEG 30 | 31 | arg_to_nr: 32 | push ecx 33 | push edi 34 | 35 | xor eax,eax 36 | xor ebx,ebx 37 | xor ecx,ecx 38 | mov edi,10 39 | 40 | mov cl,[esi] 41 | cmp cl,'-' 42 | jne .digit 43 | inc bh ; flag as negative number 44 | inc esi 45 | .next_digit: 46 | mov cl,[esi] 47 | .digit: 48 | sub cl,'0' 49 | jb .done 50 | cmp cl,9 51 | ja .done 52 | mul edi 53 | add eax,ecx 54 | inc bl ; count number of digits 55 | inc esi 56 | jmp short .next_digit 57 | .done: 58 | or bh,bh 59 | je .exit 60 | neg eax 61 | .exit: 62 | pop edi 63 | pop ecx 64 | ret 65 | 66 | %ifdef LARGE_KILL 67 | 68 | %assign MAX_NAME 6 69 | 70 | ; strlen(name), signal, name 71 | 72 | siglist db 3, SIGHUP ,'HUP' 73 | db 3, SIGINT ,'INT' 74 | db 4, SIGQUIT ,'QUIT' 75 | db 3, SIGILL ,'ILL' 76 | db 4, SIGABRT ,'ABRT' 77 | db 3, SIGFPE ,'FPE' 78 | db 4, SIGKILL ,'KILL' 79 | db 4, SIGSEGV ,'SEGV' 80 | db 4, SIGALRM ,'ALRM' 81 | db 4, SIGPIPE ,'PIPE' 82 | db 4, SIGTERM ,'TERM' 83 | db 4, SIGUSR1 ,'USR1' 84 | db 4, SIGUSR2 ,'USR2' 85 | db 4, SIGCHLD ,'CHLD' 86 | db 4, SIGCONT ,'CONT' 87 | db 4, SIGSTOP ,'STOP' 88 | db 4, SIGTSTP ,'TSTP' 89 | db 4, SIGTTIN ,'TTIN' 90 | db 4, SIGTTOU ,'TTOU' 91 | db 4, SIGTRAP ,'TRAP' 92 | db 3, SIGIOT ,'IOT' 93 | db 3, SIGBUS ,'BUS' 94 | db 6, SIGSTKFLT,'STKFLT' 95 | db 3, SIGURG ,'URG' 96 | db 2, SIGIO ,'IO' 97 | db 4, SIGPOLL ,'POLL' 98 | ; db 3, SIGCLD ,'CLD' ;mips only ? 99 | db 4, SIGXCPU ,'XCPU' 100 | db 4, SIGXFSZ ,'XFSZ' 101 | db 6, SIGVTALRM,'VTALRM' 102 | db 4, SIGPROF ,'PROF' 103 | db 3, SIGPWR ,'PWR' 104 | db 5, SIGWINCH ,'WINCH' 105 | db 6, SIGUNUSED,'UNUSED' 106 | db 0 107 | 108 | lf db 10 109 | space db 32 110 | 111 | %endif 112 | 113 | 114 | START: 115 | pop edi 116 | dec edi 117 | %ifdef LARGE_KILL 118 | jz near .exit 119 | %else 120 | jz .exit 121 | %endif 122 | pop esi 123 | 124 | pop esi 125 | mov bl,[esi] 126 | cmp bl,'-' 127 | je .args 128 | mov ecx,SIGTERM ; first argument is pid, use default signal 129 | %ifdef LARGE_KILL 130 | jmp .kill_pid 131 | %else 132 | jmp short .kill_pid 133 | %endif 134 | .args: 135 | 136 | %ifdef LARGE_KILL 137 | inc esi 138 | mov bl,[esi] 139 | cmp bl,'l' 140 | jne .signal 141 | 142 | mov edi,siglist ; show a list of signals 143 | .show_sigs: 144 | cmp byte [edi],0 145 | je .show_done 146 | mov esi,[edi] 147 | and esi,0xf 148 | inc edi 149 | inc edi 150 | sys_write STDOUT, edi, esi 151 | sys_write STDOUT, space, 1 152 | add edi,esi 153 | jmp short .show_sigs 154 | .show_done: 155 | sys_write STDOUT, lf, 1 156 | jmp near .exit 157 | 158 | .signal: 159 | dec edi 160 | je near .exit 161 | call arg_to_nr 162 | or bl,bl ; wasn't a number 163 | je .sig_name 164 | mov ecx,eax 165 | jmp short .sig_ok 166 | 167 | .sig_name: 168 | xor eax,eax ; arg might be a signal name 169 | .store_name: 170 | mov bl,[esi] 171 | or bl,bl 172 | je .stored 173 | mov [signame+eax],bl 174 | cmp al,MAX_NAME - 1 175 | je .start_cmp 176 | inc al 177 | inc esi 178 | jmp short .store_name 179 | .stored: 180 | or al,al 181 | je .exit ; nothing to store 182 | 183 | .start_cmp: 184 | xor ebx,ebx 185 | xor edx,edx 186 | dec edx 187 | dec edx 188 | .prep_next_name: 189 | mov cl,al 190 | xor esi,esi 191 | .next_name: 192 | inc edx 193 | inc edx 194 | add dl,bh 195 | mov bh,[siglist+edx] 196 | or bh,bh 197 | je .exit ; signal name not found 198 | cmp bh,cl ; arg length = signal name length ? 199 | jne .next_name 200 | .cmp_name: 201 | mov bl,[signame+esi] 202 | cmp bl,[siglist+edx+2+esi] 203 | jne .prep_next_name 204 | inc esi 205 | loop .cmp_name 206 | .cmp_done: 207 | mov cl,[siglist+edx+1] ; use signal number 208 | 209 | .sig_ok: 210 | 211 | %else 212 | 213 | ; 214 | ;small kill 215 | ; 216 | 217 | dec edi 218 | je .exit ; we've got a signal but no pid 219 | inc esi 220 | mov bl,[esi] 221 | call arg_to_nr 222 | or bl,bl ; was it a number ? 223 | je .exit 224 | mov ecx,eax 225 | %endif 226 | 227 | .next_pid: 228 | pop esi 229 | 230 | .kill_pid: 231 | call arg_to_nr 232 | or bl,bl 233 | jz .exit 234 | sys_kill eax 235 | dec edi 236 | jnz .next_pid 237 | 238 | .exit: 239 | sys_exit 240 | 241 | %ifdef LARGE_KILL 242 | 243 | UDATASEG 244 | 245 | signame resb MAX_NAME 246 | 247 | %endif 248 | 249 | END 250 | -------------------------------------------------------------------------------- /src/kldload.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 2001 Konstantin Boldyshev 2 | ; 3 | ;$Id: kldload.asm,v 1.1 2001/12/08 16:26:52 konst Exp $ 4 | ; 5 | ;hackers' kldload/kldunload/kldstat (FreeBSD) 6 | ; 7 | ;syntax: kldstat 8 | ; kldload filename 9 | ; kldunload name|id 10 | ; 11 | ;example: kldstat 12 | ; kldload fire_saver 13 | ; kldunload kernel ;) 14 | ; 15 | ;NOTES: 16 | ; 17 | ;There are few differencies from usual kldunload and kldstat: 18 | ;'kldunload' tries to interpret argument as name first, 19 | ;and if that fails, it tries it as id (no -i switch) 20 | ;'kldstat' has a little bit different ouptut formatting. 21 | ;This is not perl or even C, so I tried to KISS. 22 | ; 23 | ;0.01: 08-Dec-2001 initial release 24 | 25 | %include "system.inc" 26 | 27 | CODESEG 28 | 29 | %assign BUFSIZE 0x2000 30 | 31 | stat_title db "Id",__t,"Refs",__t,"Address",__t,__t,"Size",__t,__t,"Name",__n 32 | STAT_TITLE_LEN equ $ - stat_title 33 | 34 | START: 35 | pop ebx 36 | pop esi 37 | .n1: 38 | lodsb 39 | or al,al 40 | jnz .n1 41 | 42 | cmp dword [esi-5],'stat' 43 | jz near .kldstat 44 | cmp word [esi-7],'un' 45 | jz .kldunload 46 | 47 | .kldload: 48 | dec ebx 49 | jz .exit 50 | 51 | pop ebx 52 | 53 | .load: 54 | sys_kldload 55 | 56 | .exit: 57 | sys_exit eax 58 | 59 | ; 60 | ; 61 | ; 62 | 63 | .kldunload: 64 | dec ecx 65 | jz .exit 66 | 67 | pop ebp ;name OR fileid 68 | 69 | sys_kldfind ebp ;first, try it as name 70 | mov ebx,eax 71 | test eax,eax 72 | js .unload 73 | 74 | mov esi,ebp ;then, assume it is fileid 75 | xor eax,eax 76 | xor ebx,ebx 77 | .next_digit: 78 | lodsb 79 | sub al,'0' 80 | jb .done 81 | cmp al,9 82 | ja .done 83 | imul ebx,byte 10 84 | add ebx,eax 85 | jmps .next_digit 86 | .done: 87 | 88 | .unload: ;ebx should contain fileid now 89 | sys_kldunload 90 | jmps .exit 91 | 92 | ; 93 | ; 94 | ; 95 | 96 | .kldstat: 97 | xor ebp,ebp 98 | mov edi,buf 99 | 100 | .s1: 101 | sys_kldnext ebp 102 | or eax,eax 103 | jz .stat_done 104 | 105 | mov ebp,eax 106 | 107 | mov esi,kldstat_buf 108 | mov dword [esi],KLDSTAT_BUF_SIZE 109 | sys_kldstat ebp,esi 110 | 111 | mov eax,[esi+kld_file_stat.id] 112 | _mov ecx,10 113 | call itoa 114 | 115 | mov eax,[esi + kld_file_stat.refs] 116 | call itoa 117 | 118 | mov ax,"0x" 119 | stosw 120 | 121 | mov eax,[esi + kld_file_stat.address] 122 | _mov ecx,0x10 123 | call itoa 124 | 125 | mov ax,"0x" 126 | stosw 127 | 128 | mov eax,[esi + kld_file_stat.size] 129 | call itoa 130 | 131 | add esi,byte kld_file_stat.name 132 | .s2: 133 | lodsb 134 | stosb 135 | or al,al 136 | jnz .s2 137 | mov byte [edi - 1], __n 138 | 139 | jmps .s1 140 | 141 | .stat_done: 142 | xor al,al 143 | stosb 144 | 145 | sys_write STDOUT, stat_title, STAT_TITLE_LEN 146 | 147 | mov esi,buf 148 | mov ecx,esi 149 | .s3: 150 | lodsb 151 | or al,al 152 | jnz .s3 153 | 154 | sub esi,ecx 155 | dec esi 156 | 157 | sys_write STDOUT,EMPTY,esi 158 | 159 | xor eax,eax 160 | jmp .exit 161 | 162 | ;itoa (unsigned long value, char *string, int radix) 163 | ; 164 | ;print 32 bit number as binary,octal,decimal,or hexadecimal value 165 | ; 166 | ; 2 | ; 3 | ;$Id: ln.asm,v 1.3 2000/12/10 08:20:36 konst Exp $ 4 | ; 5 | ;hackers' ln/sln 6 | ; 7 | ;0.01: 29-Jul-1999 initial release 8 | ;0.02: 28-Sep-1999 Added no option check (docwhat@gerf.org) 9 | ;0.03: 10-Sep-2000 merged with sln 10 | ; 11 | ;syntax: ln [-s] target link_name 12 | ; sln src dest 13 | ; 14 | ;example: ln -s vmlinuz-2.2.10 vmlinuz 15 | ; sln aaa bbb 16 | 17 | %include "system.inc" 18 | 19 | CODESEG 20 | 21 | START: 22 | pop ebx ;argc 23 | pop esi ;argv[0] 24 | .n1: ;how we are called? 25 | lodsb 26 | or al,al 27 | jnz .n1 28 | 29 | cmp ebx,byte 3 30 | jb .quit 31 | 32 | pop edi ;target or '-s' 33 | pop ebp ;link_name 34 | 35 | cmp byte [esi-4],'s' 36 | jz .sln 37 | 38 | cmp word [edi],"-s" 39 | jnz .hardlink 40 | pop edi 41 | 42 | .symlink: 43 | sys_symlink ebp,edi 44 | 45 | .quit: 46 | sys_exit eax 47 | 48 | .sln: 49 | xchg ebp,edi 50 | sys_unlink edi 51 | jmps .symlink 52 | 53 | .hardlink: 54 | sys_link edi,ebp 55 | jmps .quit 56 | 57 | END 58 | -------------------------------------------------------------------------------- /src/lsmod.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 1999 Indrek Mandre 2 | ; 3 | ;$Id: lsmod.asm,v 1.6 2002/03/07 06:16:39 konst Exp $ 4 | ; 5 | ;hackers' lsmod/rmmod 6 | ; 7 | ;syntax: lsmod 8 | ; rmmod module... 9 | ; 10 | ;example: rmmod sound ppp 11 | ; 12 | ;0.01: 17-Jun-1999 initial release 13 | ;0.02: 04-Jul-1999 fixed bug with 2.0 kernel 14 | ;0.03: 06-Sep-2000 merged with rmmod (KB) 15 | ;0.04: 04-Dec-2001 sys_query_module when /proc/modules is missing (KB) 16 | 17 | %include "system.inc" 18 | 19 | CODESEG 20 | 21 | %if __KERNEL__ = 20 22 | header db 'Module Pages Used by',__n 23 | %else ;if __KERNEL__ >= 22 24 | header db 'Module Size Used by',__n 25 | %endif 26 | _hlength equ $-header 27 | %assign hlength _hlength 28 | 29 | %assign BUFSIZE 0x2000 30 | 31 | START: 32 | pop ebp 33 | pop esi ;our name 34 | .n1: ;how we are called? 35 | lodsb 36 | or al,al 37 | jnz .n1 38 | cmp word [esi-6],'ls' 39 | jz do_lsmod 40 | 41 | do_rmmod: 42 | dec ebp 43 | jz do_exit ;no arguments - error 44 | 45 | .rmmod_loop: 46 | pop ebx ;take the name of the module 47 | sys_delete_module 48 | test eax,eax 49 | js do_exit 50 | dec ebp 51 | jnz .rmmod_loop 52 | 53 | do_exit: 54 | sys_exit eax 55 | 56 | do_lsmod: 57 | sys_write STDOUT,header,hlength 58 | 59 | sys_open filename, O_RDONLY 60 | test eax, eax 61 | js .query_module 62 | 63 | ; mov ebp, eax 64 | sys_read eax, buf, BUFSIZE 65 | mov edx, eax 66 | 67 | .write: 68 | sys_write STDOUT 69 | ; sys_close ebp 70 | .w2: 71 | jmps do_exit 72 | 73 | .query_module: 74 | sys_query_module NULL, QM_MODULES, buf, BUFSIZE, qret 75 | test eax,eax 76 | js .w2 77 | 78 | mov ecx,[qret] 79 | mov esi,edx 80 | .q0: 81 | lodsb 82 | or al,al 83 | jnz .q0 84 | mov byte [esi - 1],__n 85 | loop .q0 86 | sub esi,edx 87 | mov ecx,edx 88 | mov edx,esi 89 | jmps .write 90 | 91 | filename db "/proc/modules",EOL 92 | 93 | UDATASEG 94 | 95 | qret resd 1 96 | buf resb BUFSIZE 97 | 98 | END 99 | -------------------------------------------------------------------------------- /src/m_inetd.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 2001 by Joshua Hudson 2 | ; 3 | ;$Id: m_inetd.asm,v 1.3 2002/02/02 08:49:25 konst Exp $ 4 | ; 5 | ;m_inetd by Joshua Hudson 08/09/2001 6 | ; 7 | ; Runs as inetd for a single service. 8 | ; Usage: m_inetd uid port /path/to/in.server [i] > /var/run/server.pid 9 | ; 2>/var/log/server 10 | ; 11 | ; Sends PID to standerd out, server errors to standard error (if any) 12 | ; NONSTANDARD: passes ip of connecting machine to in.server if i is passed 13 | 14 | %include "system.inc" 15 | 16 | CODESEG 17 | 18 | START: 19 | pop eax ; Argc 20 | cmp eax, byte 4 ; Receives 3 or 4 arguments 21 | jl fail 22 | cmp eax, byte 5 23 | jg fail 24 | jl nopassip 25 | mov [passip], al ; Client will receive ip-addr as first arg 26 | ; Not testing contents as this is the 27 | ; only meaning of this field 28 | mov [execptrs+4], dword address ; Pass the ip-address 29 | nopassip: 30 | pop ebp ; Program name 31 | ;*** Process uid 32 | pop ebp 33 | call atoi 34 | mov [uid], eax 35 | 36 | ;*** Socket code from httpd.asm 37 | ;*** Process port 38 | pop ebp ; Port 39 | call atoi 40 | push eax ; Will need this later 41 | ; socket(PF_INET, SOCK_STREAM, IPPROTO_TCP) 42 | sys_socket PF_INET, SOCK_STREAM, IPPROTO_TCP 43 | xchg eax, ebp ; Socket 44 | test ebp, ebp 45 | js fail 46 | ; socketopt(socket, SOL_SOCKET, SO_REUSEADDER, &setsockoptvals, 4) 47 | sys_setsockopt ebp, SOL_SOCKET, SO_REUSEADDR, sockoptvals, 4 48 | or eax, eax 49 | jz do_bind 50 | 51 | fail: mov bl, 1 52 | do_exit: 53 | sys_exit 54 | 55 | do_bind: 56 | pop eax 57 | mov [bindsockstruct], dword AF_INET 58 | mov byte [bindsockstruct + 2], ah ; htons port 59 | mov byte [bindsockstruct + 3], al 60 | ; bind (socket, &bindsocketstruct, 16) 61 | sys_bind ebp, bindsockstruct, 16 62 | or eax, eax 63 | jnz fail 64 | 65 | ; listen (s, 0xFF) 66 | sys_listen ebp, 0xFF 67 | or eax, eax 68 | jnz fail 69 | 70 | ;*** Load info onto heap 71 | pop esi 72 | mov edi, application 73 | mov [execptrs], esi ; Install the self-name here 74 | call strccpy 75 | nopathreq: 76 | sys_setuid [uid] ; Run as this user 77 | sys_fork ; Start the program 78 | or eax, eax 79 | jz acceptloop 80 | js near fail 81 | 82 | ; Display child pid to SDTOUT 83 | mov edi, address 84 | push edi 85 | call itoa 86 | pop ecx 87 | mov [edi], byte __n 88 | mov edx, edi 89 | sub edx, ecx 90 | inc edx 91 | sys_write STDOUT 92 | xor bl, bl 93 | jmp do_exit 94 | 95 | ;*** Listen for connections 96 | acceptanother: 97 | sys_close [consock] 98 | sys_wait4 0xffffffff, NULL, WNOHANG, NULL 99 | sys_wait4 100 | acceptloop: 101 | ;accept(socket, struct sockaddr *sockaddress, int *consock) 102 | _mov eax, 16 103 | mov [consock], eax 104 | sys_accept ebp, sockaddress, consock 105 | test eax, eax 106 | js acceptloop 107 | mov [consock], eax 108 | 109 | ;Got a connection: fork process 110 | sys_fork 111 | or eax, eax 112 | jnz acceptanother ; Parent goes back to waiting 113 | 114 | ;**** Child: determine from where and exec 115 | sys_close ebp ; Close the listening socket 116 | xor eax, eax 117 | cmp [passip], byte 0 118 | je activate 119 | mov edi, address 120 | _mov ebp, 4 121 | mov ebx, sockaddress+4 122 | transip: 123 | mov al, [ebx] 124 | inc ebx 125 | push ebx 126 | call itoa 127 | pop ebx 128 | mov [edi], byte "." 129 | inc edi 130 | dec ebp 131 | jnz transip 132 | dec edi 133 | mov [edi], byte 0 134 | ; Connect stdin & stdout 135 | activate: 136 | sys_dup2 [consock], STDIN ; Connect stdin and stdout 137 | sys_dup2 eax, STDOUT ; to socket 138 | sys_execve application, execptrs, emptyenviron 139 | sys_write STDERR, ExecFailed, 12 140 | jmp do_exit ; Failed to exec! 141 | 142 | ExecFailed db "exec failed", __n 143 | 144 | itoa: ; From id.asm 145 | xor ecx,ecx 146 | mov ebx,ecx 147 | mov bl,10 148 | div_again: 149 | xor edx,edx 150 | div ebx 151 | add dl,'0' 152 | push edx 153 | inc ecx 154 | test eax,eax 155 | jnz div_again 156 | keep_popping: 157 | pop eax 158 | stosb 159 | loop keep_popping 160 | ret 161 | 162 | 163 | atoi: xor eax, eax 164 | xor ebx, ebx 165 | _mov ecx, 10 166 | atoi_again: 167 | mov bl, [ebp] 168 | inc ebp 169 | sub bl, '0' 170 | jc atoi_done 171 | cmp bl, 9 172 | jg atoi_done 173 | mul ecx 174 | add eax, ebx 175 | jmps atoi_again 176 | atoi_done: 177 | ret 178 | 179 | strccpy_next: ; I am sure this is the smallest 180 | stosb ; strccpy I have ever seen 181 | strccpy: ; (8 bytes) 182 | lodsb 183 | or al, al 184 | jnz strccpy_next 185 | ret 186 | 187 | ; These two items are here to facilitate compression (I believe tar padds)! 188 | sockoptvals dd 1 ; What does this mean? 189 | emptyenviron dd 0 ; Command gets no environ! 190 | 191 | UDATASEG 192 | 193 | application resd 1024 ; The program to execute 194 | bindsockstruct resd 4 ; Bind the socket here! 195 | address resb 16 ; Target address 196 | sockaddress resb 16 ; Source address in compact form 197 | uid resd 0 ; Run as this uid, union with consock 198 | consock resd 1 ; The connected socket 199 | execptrs resd 3 ; for sys_exec 200 | passip resb 1 ; Set if the ip-addr is to be passed 201 | 202 | END 203 | -------------------------------------------------------------------------------- /src/mesg.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 2001 Thomas M. Ogrisegg 2 | ; 3 | ;$Id: mesg.asm,v 1.4 2002/02/14 13:38:15 konst Exp $ 4 | ; 5 | ;syntax: mesg [y|n] 6 | ; 7 | ;control write access to your terminal 8 | 9 | %include "system.inc" 10 | 11 | %assign BUFSIZE 0x100 12 | 13 | CODESEG 14 | 15 | START: 16 | sys_readlink fd0, buf, BUFSIZE 17 | test eax, eax 18 | js do_exit 19 | 20 | xor eax, eax 21 | sys_stat buf, statbuf 22 | mov eax, [ecx+Stat.st_mode] 23 | add esp, 8 24 | pop ebx 25 | test ebx, ebx 26 | jnz _chmod 27 | 28 | and eax, 16 29 | cmp eax, 16 30 | jnz isn 31 | mov ecx, yes 32 | jmp _write 33 | isn: 34 | mov ecx, no 35 | _write: 36 | sys_write STDOUT, ecx, 5 37 | 38 | do_exit: 39 | sys_exit eax 40 | 41 | _chmod: 42 | cmp byte [ebx], 'n' 43 | jz _no 44 | cmp byte [ebx], 'y' 45 | jnz do_exit 46 | or eax, 16 47 | jmp __do_chmod 48 | _no: 49 | or eax, 16 50 | xor eax, 16 51 | __do_chmod: 52 | sys_chmod buf, eax 53 | jmp do_exit 54 | 55 | yes db "is y", __n 56 | no db "is n", __n 57 | fd0 db "/proc/self/fd/0" 58 | 59 | UDATASEG 60 | 61 | buf resb BUFSIZE 62 | statbuf B_STRUC Stat, .st_mode 63 | 64 | END 65 | -------------------------------------------------------------------------------- /src/mkdir.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 1999-2000 Konstantin Boldyshev 2 | ; 3 | ;$Id: mkdir.asm,v 1.3 2000/02/10 15:07:04 konst Exp $ 4 | ; 5 | ;hackers' mkdir/rmdir 6 | ; 7 | ;0.01: 05-Jun-1999 initial release 8 | ;0.02: 17-Jun-1999 size improvements 9 | ;0.03: 04-Jul-1999 fixed bug with 2.0 kernel, size improvements 10 | ;0.04: 29-Jan-2000 -m & -p support 11 | ; 12 | ;syntax: mkdir [OPTION] DIRECTORY ... 13 | ; rmdir DIRECTORY... 14 | ; 15 | ;-m set permission mode (only octal number) 16 | ;-p create parent directories as needed 17 | ; 18 | ;example: mkdir -p -m 700 this/is/a/very/long/and/useless/directory/tree 19 | ; 20 | ;only octal mode strings are suppoted (f.e. 750) 21 | ;by default directories are created with permissions of 755 22 | ; 23 | ;returns last error number 24 | 25 | %include "system.inc" 26 | 27 | %define MKDIR 0 28 | %define RMDIR 1 29 | 30 | CODESEG 31 | 32 | ; 33 | ;ebp: -p flag 34 | ; 35 | 36 | START: 37 | pop eax 38 | dec eax 39 | jnz .begin 40 | .exit: 41 | sys_exit eax 42 | 43 | .begin: 44 | pop esi 45 | .n1: ;set edi to argv[0] eol 46 | lodsb 47 | or al,al 48 | jnz .n1 49 | mov edi,esi 50 | 51 | _mov ecx,755q 52 | xor ebp,ebp 53 | 54 | .next_arg: 55 | pop esi 56 | push esi 57 | 58 | cmp word [esi],"-p" 59 | jnz .check_m 60 | inc ebp 61 | pop esi 62 | jmp short .next_arg 63 | 64 | .check_m: 65 | cmp word [esi],"-m" 66 | jnz .next_file 67 | 68 | pop esi 69 | pop esi 70 | or esi,esi 71 | jz .exit 72 | 73 | mov edx,esi 74 | xor ecx,ecx 75 | xor eax,eax 76 | _mov ebx,8 77 | 78 | .next: 79 | mov cl,[esi] 80 | sub cl,'0' 81 | jb .done 82 | cmp cl,7 83 | ja .done 84 | mul bl 85 | add eax,ecx 86 | inc esi 87 | jmp short .next 88 | 89 | .done: 90 | cmp edx,esi 91 | jz .exit 92 | or eax,eax 93 | jz .exit 94 | 95 | mov ecx,eax 96 | jmp short .next_arg 97 | 98 | .next_file: 99 | pop ebx 100 | or ebx,ebx 101 | jz .exit 102 | cmp word [edi-6],"rm" 103 | jnz .mkdir 104 | sys_rmdir 105 | jmp short .next_file 106 | 107 | .mkdir: 108 | push edi 109 | 110 | mov dl,1 111 | or ebp,ebp 112 | jz .call 113 | 114 | mov esi,ebx 115 | jmp short .check 116 | 117 | .next_dir: 118 | mov edi,esi 119 | mov [edi], byte 0 120 | .call: 121 | sys_mkdir 122 | or edx,edx 123 | jnz .done_mk 124 | mov [edi], byte '/' 125 | 126 | inc esi 127 | .check: 128 | xor edx,edx 129 | mov edi,esi 130 | mov al,'/' 131 | call strchr 132 | jc .next_dir 133 | inc edx 134 | cmp esi,edi 135 | jnz .next_dir 136 | .done_mk: 137 | pop edi 138 | jmp short .next_file 139 | 140 | ; 141 | ;carry set if character found 142 | ; 143 | 144 | strchr: 145 | push eax 146 | mov ah,al 147 | clc 148 | .next: 149 | lodsb 150 | or al,al 151 | jz .return 152 | cmp al,ah 153 | jnz .next 154 | stc 155 | .return: 156 | dec esi 157 | pop eax 158 | ret 159 | 160 | END 161 | -------------------------------------------------------------------------------- /src/mknod.asm: -------------------------------------------------------------------------------- 1 | ; Copyright (C) 2001 Joshua Hudson 2 | ; 3 | ; $Id: mknod.asm,v 1.2 2001/09/17 09:36:19 konst Exp $ 4 | ; 5 | ; hacker's mknod/mkfifo 6 | ; 7 | ; Usage: mknod [-m mode] name type major minor 8 | ; Type is b block (e.g. /dev/hda1) 9 | ; c character (e.g. /dev/ttyS1) 10 | ; p fifo (e.g. /dev/fifo) 11 | ; 12 | ; Usage: mkfifo name 13 | ; 14 | ; This mknod/mkfifo is GNU compatible 15 | 16 | %include "system.inc" 17 | 18 | CODESEG 19 | 20 | START: 21 | ; Here we load esi with umask and set umask to 0 22 | xor ebx, ebx 23 | sys_umask 24 | mov esi, 0x1B6 25 | xor esi, eax 26 | pop ebx 27 | pop ebx ;argv[0] 28 | check_fifo: ;See if we are being called as mkfifo 29 | inc ebx 30 | cmp byte [ebx], 0 31 | jne check_fifo 32 | dec ebx 33 | cmp byte [ebx], 'o' 34 | je mkfifo 35 | 36 | ; Parse mknod options [ only -m ] 37 | pop ebx 38 | or ebx, ebx 39 | jz bad_args 40 | cmp word [ebx], '-m' 41 | jne mknod_notmode 42 | inc ebx 43 | inc ebx 44 | cmp byte [ebx], 0 45 | jne mknod_setmode 46 | pop ebx 47 | or ebx, ebx 48 | jz bad_args 49 | mknod_setmode: 50 | call setmode 51 | pop ebx 52 | or ebx, ebx 53 | jz bad_args 54 | 55 | mknod_notmode: ; Should have name type major minor 56 | ; Name already in ebx. 57 | pop ebp ; Loaded type 58 | or ebp, ebp 59 | jz bad_args 60 | cmp byte [ebp], 'b' 61 | je block 62 | cmp byte [ebp], 'c' 63 | je char 64 | cmp byte [ebp], 'u' ; 'u' is sometimes used for char !!! 65 | je char 66 | cmp byte [ebp], 'p' 67 | je fifo 68 | jmps bad_args 69 | 70 | ; Got here in processing mkfifo 71 | mkfifo: 72 | pop ebx 73 | or ebx, ebx 74 | jz bad_args 75 | cmp word [ebx], '-m' 76 | jne fifo 77 | inc ebx 78 | inc ebx 79 | cmp [ebx], byte 0 80 | jne mkfifo_setmode 81 | pop ebx 82 | or ebx, ebx 83 | jz bad_args 84 | mkfifo_setmode: 85 | call setmode 86 | pop ebx 87 | or ebx, ebx 88 | jz bad_args 89 | jmps fifo 90 | 91 | bad_args: 92 | sys_write STDERR, BadArgs, BadArgsLen 93 | mov bl, 1 94 | jmp goodbye 95 | 96 | block _mov ecx, S_IFBLK 97 | jmps mknod_ok 98 | char _mov ecx, S_IFCHR 99 | jmps mknod_ok 100 | fifo _mov ecx, S_IFIFO 101 | xor edx, edx 102 | or ecx, esi 103 | jmps mknod_go ; No need for major / minor 104 | 105 | mknod_ok: 106 | or ecx, esi 107 | ; Find major << 8 + minor 108 | pop ebp 109 | or ebp, ebp 110 | jz bad_args 111 | call atoi ; Input in ebp, output in eax 112 | shl eax, 8 113 | xchg eax, edx ; mov edx, eax 114 | pop ebp 115 | or ebp, ebp 116 | jz bad_args 117 | push edx 118 | call atoi 119 | pop edx 120 | add edx, eax 121 | mknod_go: 122 | sys_mknod ; ebx = name, ecx = mode | perm, edx = dev 123 | xchg ebx, eax ; return mknod's error code 124 | goodbye: 125 | sys_exit 126 | 127 | BadArgs db "Usage: mknod [-m mode] NAME TYPE MAJOR MINOR", __n 128 | BadArgsLen equ $-BadArgs 129 | 130 | ; process mode: return in esi 131 | setmode: 132 | xor eax, eax 133 | xor esi, esi 134 | mov cl, 3 135 | .setmode_read: 136 | mov al, [ebx] 137 | inc ebx 138 | sub al, '0' 139 | js .setmode_done 140 | cmp al, 8 141 | jge .setmode_done 142 | shl esi, cl 143 | or esi, eax 144 | jmps .setmode_read 145 | .setmode_done: 146 | ret 147 | 148 | ; Convert string in [ebp] to number in eax 149 | ; Preserve ebx, ecx, edx ! 150 | atoi: 151 | push ebx 152 | push ecx 153 | push edx 154 | xor eax, eax 155 | xor ebx, ebx 156 | atoi_go: 157 | mov bl, [ebp] 158 | inc ebp 159 | sub bl, '0' 160 | js atoi_done 161 | cmp bl, 9 162 | jg atoi_done 163 | xor edx, edx 164 | _mov ecx, 10 165 | mul ecx 166 | add eax, ebx 167 | jmps atoi_go 168 | atoi_done: 169 | pop edx 170 | pop ecx 171 | pop ebx 172 | ret 173 | 174 | ;DEBUG: 175 | ; pusha 176 | ; sys_write STDERR, DEBUGMSG, 6 177 | ; popa 178 | ; ret 179 | ; 180 | ;DEBUGMSG db "DEBUG", __n 181 | 182 | END 183 | -------------------------------------------------------------------------------- /src/mount.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 1999-2002 Konstantin Boldyshev 2 | ; 3 | ;$Id: mount.asm,v 1.7 2002/06/24 16:51:55 konst Exp $ 4 | ; 5 | ;hackers' mount/umount 6 | ; 7 | ;syntax: mount [-o options,[...]] [-t type] device mountpoint 8 | ; umount mountpoint 9 | ; 10 | ;example: mount -o ro,noexec -t vfat /dev/hda1 /c 11 | ; umount /mnt 12 | ; 13 | ;NOTES: 14 | ;(1) mount arguments must be exactly in above written order 15 | ;(2) BSD version requires -t argument 16 | ;(3) only generic mount options are implemented (no fs-specific options) 17 | ;(4) if it still doesn't work, check command line syntax again and goto (1) 18 | ; 19 | ;0.01: 04-Jul-1999 initial release 20 | ;0.02: 19-Feb-2001 added options support & listing of mounted devices (RM) 21 | ;0.03: 10-Dec-2001 rewritten to resemble usual mount, *BSD port (KB) 22 | ;0.04: 24-Jun-2002 try to mount ro/nodev if rw fails (KB) 23 | 24 | %include "system.inc" 25 | 26 | %assign BUFSIZE 0x2000 27 | 28 | CODESEG 29 | 30 | START: 31 | pop ecx ;argc 32 | dec ecx 33 | jz list_mounted 34 | 35 | pop esi 36 | pop ebx 37 | 38 | .n1: ;find out our name 39 | lodsb 40 | or al,al 41 | jnz .n1 42 | cmp byte [esi-7],'u' 43 | jnz mount 44 | 45 | xor ecx,ecx 46 | sys_umount 47 | 48 | do_exit: 49 | sys_exit eax 50 | 51 | ; 52 | ;display /proc/mounts or /etc/mtab 53 | ; 54 | 55 | list_mounted: 56 | 57 | sys_open lname1,O_RDONLY 58 | test eax,eax 59 | jns .l0 60 | sys_open lname2 61 | test eax,eax 62 | js do_exit 63 | .l0: 64 | sys_read eax,buf,BUFSIZE 65 | sys_write STDOUT,EMPTY,eax 66 | xor eax,eax 67 | jmps do_exit 68 | 69 | ; 70 | 71 | mount: 72 | cmp cl,2 73 | jb list_mounted 74 | 75 | cmp word [ebx],"-o" 76 | jnz .m1 77 | 78 | pop ebp ;options to parse 79 | .options: 80 | mov esi,ebp 81 | .o0: 82 | lodsb 83 | cmp al,',' 84 | jz .o1 85 | or al,al 86 | jnz .o0 87 | 88 | inc byte [buf] ;indicate the last option 89 | 90 | .o1: 91 | mov ebx,esi 92 | sub ebx,ebp 93 | dec ebx 94 | 95 | mov ecx,MOUNT_OPTIONS_SIZE ;compare with all options 96 | mov edx,mount_options 97 | .o2: 98 | pusha 99 | mov esi,ebp 100 | mov edi,[edx] 101 | mov ecx,ebx 102 | rep cmpsb 103 | popa 104 | jnz .o3 105 | mov eax,[edx + 4] 106 | or [flag],eax 107 | jmps .onext 108 | .o3: 109 | add edx,byte 8 110 | loop .o2 111 | 112 | .onext: 113 | mov ebp,esi 114 | cmp byte [buf],1 115 | jnz .options 116 | 117 | .m0: 118 | pop ebx 119 | .m1: 120 | mov edx,buf 121 | cmp word [ebx],"-t" 122 | jnz .do_mount 123 | 124 | pop edx ;fstype 125 | pop ebx ;device 126 | 127 | .do_mount: 128 | pop ecx ;mountpoint 129 | 130 | call do_mount 131 | 132 | or dword [flag],MS_RDONLY 133 | call do_mount 134 | and dword [flag],~MS_RDONLY 135 | or dword [flag],MS_NODEV 136 | call do_mount 137 | or dword [flag],MS_RDONLY 138 | call do_mount 139 | jmp do_exit 140 | 141 | do_mount: 142 | %ifdef __BSD__ 143 | mov [buf],ebx ;void *data points to structure, where char* is the first 144 | mov ebx,edx ;fstype 145 | mov esi,buf ;data 146 | mov edx,[flag] ;flags 147 | %else 148 | ;for pre 0.97 version of mount there should be in high word of flags 149 | ;magic MSC_MGC_VAL dont know which kernel need this 150 | mov esi,[flag] 151 | xor edi,edi 152 | %endif 153 | sys_mount 154 | test eax,eax 155 | jns near do_exit 156 | ret 157 | 158 | mount_options: 159 | 160 | dd .ro, MS_RDONLY 161 | dd .nosuid, MS_NOSUID 162 | dd .nodev, MS_NODEV 163 | dd .noexec, MS_NOEXEC 164 | dd .sync, MS_SYNCHRONOUS 165 | dd .remount, MS_REMOUNT 166 | dd .noatime, MS_NOATIME 167 | 168 | MOUNT_OPTIONS_SIZE equ (($ - mount_options) / 8) 169 | 170 | .ro db "ro",EOL 171 | .nosuid db "nosuid",EOL 172 | .nodev db "nodev",EOL 173 | .noexec db "noexec",EOL 174 | .sync db "sync",EOL 175 | .remount db "remount",EOL 176 | .noatime db "noatime",EOL 177 | 178 | lname1 db "/proc/mounts",EOL 179 | lname2 db "/etc/mtab",EOL 180 | 181 | UDATASEG 182 | 183 | flag resd 1 184 | buf resb BUFSIZE 185 | 186 | END 187 | -------------------------------------------------------------------------------- /src/mv.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 2000 Dmitry Bakhvalov 2 | ; 3 | ;$Id: mv.asm,v 1.4 2002/02/02 08:49:25 konst Exp $ 4 | ; 5 | ;hackers' mv 6 | ; 7 | ;syntax: mv source dest, or 8 | ; mv source... directory 9 | ; 10 | ;No options are supported by now 11 | ; 12 | ;If someone really feels like he needs more of the original GNU mv's 13 | ;options - just ask me or better yet add 'em yourself :) 14 | ; 15 | ;Send me any feedback,suggestions,additional code, etc. 16 | 17 | %include "system.inc" 18 | CODESEG 19 | START: 20 | pop ecx ; get argc 21 | cmp ecx,byte 3 ; must have at least 3 args 22 | jl near invalid_args 23 | 24 | pop eax ; skip argv[0] 25 | dec ecx ; dont count argv[0] 26 | 27 | dec ecx ; last argument's index 28 | xor edi,edi ; eax=NULL 29 | xchg edi,[esp+ecx*4] ; argv[last_arg]=NULL 30 | jmp short args_loop 31 | 32 | move_file: 33 | call mv 34 | args_loop: 35 | pop esi ; get nex arg 36 | test esi,esi ; no more? 37 | jnz move_file 38 | 39 | no_more_args: 40 | invalid_args: 41 | sys_exit_true ; exit 42 | 43 | 44 | ; mv files 45 | ; esi - source file; edi - dest file/dir 46 | ; carry = 1 if error 47 | 48 | mv: 49 | pushad 50 | 51 | call is_dir ; is our dest a dir 52 | jnz .just_move ; it's a file. move now 53 | 54 | push edi ; save target 55 | 56 | call strlen ; get src len 57 | mov ax,0x002f ; al='/',ah=0 58 | mov ecx,edx ; save strlen 59 | dec edx ; last char 60 | mov edi,esi ; edi=src 61 | add edi,edx ; edi points to the lats char 62 | cmp byte [edi],al ; is it a '/' 63 | jnz .no_slash ; nope 64 | mov byte [edi],ah ; remove '/' 65 | .no_slash: 66 | std ; backward scanning 67 | repne scasb ; look for first '/' 68 | cld ; forward scanning 69 | jnz .slash_not_found ; 70 | inc edi ; correct edi 71 | 72 | .slash_not_found: 73 | inc edi ; correct edi 74 | mov ebp,esi ; save esi 75 | mov esi,edi ; esi=corrected scasb result 76 | pop edi ; restore original dest 77 | 78 | mov edx,esi ; edx=src filename 79 | mov esi,edi ; esi=dst dir name 80 | mov edi,buf ; edi=tmp buf 81 | call full_name ; make full name: "dst_dir/filename" 82 | mov esi,ebp ; restore original src 83 | 84 | .just_move: 85 | sys_rename esi, edi 86 | 87 | popad 88 | ret 89 | 90 | ; 91 | ; ----------------------------- procedures ------------------------------------ 92 | ; 93 | 94 | 95 | ; edi - tmp buf, esi - dir, edx - file 96 | ; 97 | full_name: 98 | pushad 99 | call strcpy 100 | call fix_slash 101 | mov esi,edx 102 | call strcat 103 | popad 104 | ret 105 | 106 | ; edi=file name 107 | ; - 108 | fix_slash: 109 | push edx 110 | push esi 111 | 112 | mov esi,edi 113 | call strlen 114 | dec edx 115 | 116 | mov ax,0x002F 117 | cmp byte [edi+edx],al 118 | jz .ok 119 | 120 | inc edx 121 | mov word [edi+edx],ax 122 | .ok: 123 | pop esi 124 | pop edx 125 | ret 126 | 127 | 128 | ; edi = file name 129 | ; zero flag = 1 if dir; carry flag=1 if file doesnt exists 130 | is_dir: 131 | pushad 132 | 133 | sys_stat edi,stat_buf 134 | test eax,eax 135 | js .error 136 | 137 | movzx eax,word [stat_buf.st_mode] 138 | mov ebx,40000q 139 | and eax,ebx 140 | cmp eax,ebx 141 | clc ; file exists 142 | jmp .popit 143 | .error: 144 | stc ; if file doesnt exist set 145 | ; carry flag 146 | .popit: 147 | popad 148 | ret 149 | 150 | 151 | ; esi=string 152 | ; edx=strlen 153 | strlen: 154 | push eax 155 | push esi 156 | 157 | cld 158 | xor eax,eax 159 | mov edx,eax 160 | dec edx 161 | .do_strlen: 162 | inc edx 163 | lodsb 164 | test al,al 165 | jnz .do_strlen 166 | 167 | pop esi 168 | pop eax 169 | ret 170 | 171 | 172 | ; esi=source edi=dest 173 | ; - 174 | strcpy: 175 | pushad 176 | 177 | call strlen 178 | inc edx ; copy NULL too 179 | mov ecx,edx 180 | rep movsb 181 | 182 | popad 183 | ret 184 | 185 | 186 | ; esi=source edi=dest 187 | ; - 188 | strcat: 189 | pushad 190 | 191 | xchg esi,edi 192 | call strlen 193 | 194 | xchg esi,edi 195 | add edi,edx 196 | 197 | call strlen 198 | inc edx ; copy NULL byte too 199 | mov ecx,edx 200 | rep movsb ; copy 201 | 202 | popad 203 | ret 204 | 205 | 206 | UDATASEG 207 | 208 | stat_buf B_STRUC Stat,.st_mode 209 | 210 | buf: resb 4096 211 | buf_size equ $-buf 212 | 213 | END 214 | -------------------------------------------------------------------------------- /src/nc.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 1999 Cecchinel Stephan 2 | ; 3 | ;$Id: nc.asm,v 1.4 2000/12/10 08:20:36 konst Exp $ 4 | ; 5 | ;hackers' netcat 6 | ; 7 | ;syntax: nc -l port ip port get input from port, output to ip port 8 | ; nc -l port get input from port, output to STDOUT 9 | ; nc ip port get input from STDIN, output to ip port 10 | ; 11 | ;ip is in form xxx.xxx.xxx.xxx only numeric (no DNS lookup) 12 | ; 13 | ;0.01: 27-Dec-1999 initial release (CS) 14 | ;0.02: 10-Sep-2000 heavy rewrite, size improvements, 15 | ; portability fixes and cleanup (KB) 16 | 17 | %include "system.inc" 18 | 19 | CODESEG 20 | 21 | START: 22 | _mov ebp,STDIN 23 | _mov edi,STDOUT 24 | 25 | pop ebx 26 | pop ebx 27 | pop esi 28 | test esi,esi 29 | jz near .read 30 | 31 | mov ebx,sa 32 | mov dword [ebx],AF_INET 33 | 34 | cmp word [esi],"-l" 35 | jnz near .writesock 36 | 37 | .readsock: 38 | 39 | ;first we create socket 40 | 41 | call createsocket 42 | 43 | ;then we bind to port 44 | 45 | pop esi ;next arg, port to listen 46 | call StrToLong ;convert ascii to int 47 | mov byte [ebx+2],dh 48 | mov byte [ebx+3],dl 49 | 50 | mov esi,eax 51 | sys_bind esi,sa,16 52 | test eax,eax 53 | js near .exit 54 | 55 | sys_listen esi,0xff 56 | 57 | ;accept incoming connection 58 | 59 | sys_accept esi,arg1,arg2 60 | mov ebp,eax 61 | 62 | pop esi 63 | test esi,esi 64 | jz .read 65 | 66 | .writesock: 67 | 68 | call createsocket 69 | mov edi,eax 70 | 71 | ;inet_aton: convert ascii xxx.xxx.xxx.xxx ip notation 72 | ; to network oriented 32 bit number 73 | ;input: esi: ascii string 74 | ;ouput: edi: to store 32 bit number 75 | 76 | lea ebx,[sa+4] 77 | _mov ecx,4 78 | .conv: call StrToLong 79 | mov [ebx],dl 80 | inc ebx 81 | loop .conv 82 | 83 | pop esi ;take next arg (port) 84 | call StrToLong ;convert to int 85 | mov byte[ebx+2-8],dh ;store port in network order 86 | mov byte[ebx+3-8],dl 87 | 88 | sys_connect edi,sa,16 89 | test eax,eax 90 | js .exit 91 | 92 | .read: 93 | mov esi,buffer 94 | sys_read ebp,esi,1024 95 | test eax,eax 96 | js .exit 97 | jz .exit 98 | sys_write edi,esi,eax 99 | jmps .read 100 | 101 | .exit: 102 | quit: 103 | sys_exit 104 | 105 | createsocket: 106 | push ebx 107 | sys_socket PF_INET,SOCK_STREAM,IPPROTO_TCP 108 | test eax,eax 109 | js quit 110 | pop ebx 111 | ret 112 | 113 | ;convert ascii decimal string to 32 bit number 114 | ;input: esi point to ascii 115 | ;return: edx=32 bit number 116 | 117 | StrToLong: 118 | push eax 119 | xor eax,eax 120 | xor edx,edx 121 | .next: 122 | lodsb 123 | sub al,'0' 124 | jb .ret 125 | add edx,edx 126 | lea edx,[edx+edx*4] 127 | add edx,eax 128 | jmps .next 129 | .ret: 130 | pop eax 131 | ret 132 | 133 | UDATASEG 134 | 135 | sa resb 0x10 136 | buffer resb 1024 137 | 138 | arg1 resb 0x20 139 | arg2 resd 1 140 | 141 | END 142 | -------------------------------------------------------------------------------- /src/nice.asm: -------------------------------------------------------------------------------- 1 | ; Copyright (c) 2001, 2002 Thomas M. Ogrisegg 2 | ; 3 | ; $Id: nice.asm,v 1.2 2002/02/14 13:38:15 konst Exp $ 4 | ; 5 | ; nice - invoke a utility with an altered system scheduling priority 6 | ; 7 | ; syntax: 8 | ; nice [-n priority|-priority] utility [arguments] 9 | ; 10 | ; License : GNU General Public License 11 | ; Author : Thomas Ogrisegg 12 | ; E-Mail : tom@rhadamanthys.org 13 | ; Version : 1.0 14 | ; SuSV2-Compliant : yes 15 | ; GNU-compatible : no 16 | ; 17 | ; Exit-Codes: 18 | ; 127: utility could not be executed 19 | ; 20 | 21 | %include "system.inc" 22 | 23 | CODESEG 24 | 25 | _atoi: 26 | xor eax, eax 27 | xor edx, edx 28 | .LSpace: 29 | lodsb 30 | cmp al, 0x21 31 | jng .LSpace 32 | .Lfe2: 33 | cmp al, 47 34 | jng .Lout 35 | cmp al, 58 36 | jg .Lout 37 | sub al, '0' 38 | add edx, eax 39 | lodsb 40 | cmp al, 47 41 | jng .Lout 42 | cmp al, 58 43 | jg .Lout 44 | imul edx, 0xa 45 | jmp .Lfe2 46 | .Lout: 47 | mov eax, edx 48 | ret 49 | 50 | START: 51 | pop ecx 52 | lea ebp, [esp+ecx*4] 53 | add ebp, 4 54 | cmp ecx, 1 55 | jz near error 56 | pop esi 57 | pop esi 58 | lodsb 59 | cmp al, '-' 60 | jnz near run_default 61 | 62 | lodsb 63 | dec esi 64 | cmp al, 'n' 65 | jnz .Ldo_atoi 66 | pop esi 67 | 68 | .Ldo_atoi: 69 | call _atoi 70 | 71 | priority: 72 | sys_setpriority 0, 0, eax 73 | 74 | ;; The SuSV2 says that the utility must be invoked even if the setpriority ;; 75 | ;; syscall fails. GNU nice handles this different, but this implementation ;; 76 | ;; follows the SuSV2-description, so we do not check the return value. ;; 77 | 78 | 79 | ;; execvp - search the environment variable PATH for the program specified ;; 80 | ;; on top of the stack and try to execute it. ;; 81 | ;; Attention: If the space on the current stack-frame is insufficient to ;; 82 | ;; hold the current $PATH environment variable, the program may crash with ;; 83 | ;; a segmentation fault 84 | 85 | xor ecx, ecx 86 | .Lexecvp: 87 | mov esi, [ebp+ecx*4] 88 | or esi, esi 89 | jz near error 90 | lodsd 91 | inc ecx 92 | cmp eax, 'PATH' 93 | jnz .Lexecvp 94 | lodsb 95 | cmp al, '=' 96 | jnz .Lexecvp 97 | xor eax, eax 98 | xor ecx, ecx 99 | dec ecx 100 | mov edi, esi 101 | repnz scasb 102 | mov edx, ecx 103 | xor ecx, ecx 104 | dec ecx 105 | mov edi, [esp] 106 | repnz scasb 107 | add ecx, edx 108 | 109 | .Lexecv_next: 110 | lea edi, [esp+ecx] 111 | .Lcopy_loop: 112 | lodsb 113 | cmp al, ':' 114 | jz .Lpath_end 115 | stosb 116 | or al, al 117 | jnz .Lcopy_loop 118 | 119 | .Lpath_end: 120 | push esi 121 | mov esi, [esp+4] 122 | mov al, '/' 123 | stosb 124 | 125 | .Lcopy_loop2: 126 | lodsb 127 | stosb 128 | or al, al 129 | jnz .Lcopy_loop2 130 | lea ebx, [esp+ecx+4] 131 | mov edi, ecx 132 | pop esi 133 | sys_execve ebx, esp, ebp 134 | mov ecx, edi 135 | jmp .Lexecv_next 136 | sys_exit 0x0 137 | 138 | error: 139 | sys_exit 127 140 | 141 | run_default: 142 | sub esp, 4 143 | mov eax, 0xa 144 | jmp priority 145 | 146 | END 147 | -------------------------------------------------------------------------------- /src/nohup.asm: -------------------------------------------------------------------------------- 1 | ; Copyright (C) 2001, 2002 Thomas M. Ogrisegg 2 | ; 3 | ; $Id: nohup.asm,v 1.2 2002/02/14 13:38:15 konst Exp $ 4 | ; 5 | ; nohup - invoke a utility immun to hangups 6 | ; 7 | ; syntax: 8 | ; nohup utility [arguments] 9 | ; 10 | ; License : GNU General Public License 11 | ; Author : Thomas Ogrisegg 12 | ; E-Mail : tom@rhadamanthys.org 13 | ; Version : 1.0 14 | ; SuSV2-Compliant : yes 15 | ; GNU-compatible : yes 16 | ; 17 | ; Exit-Codes: 18 | ; 1: nohup.out could not be created, or insufficient arguments were given. 19 | ; 127: utility could not be executed 20 | ; 21 | 22 | %include "system.inc" 23 | 24 | CODESEG 25 | 26 | _error: 27 | sys_exit 0x1 28 | 29 | check_term: 30 | push eax 31 | sys_ioctl eax, TCGETS, termbuf 32 | pop ebx 33 | or eax, eax 34 | js .Lreturn 35 | sys_close ebx 36 | sys_dup [nfd] 37 | .Lreturn: 38 | ret 39 | 40 | START: 41 | pop ecx 42 | lea ebp, [esp+ecx*4] 43 | add ebp, 4 44 | add esp, 4 45 | dec ecx 46 | jz _error 47 | 48 | sys_signal SIGHUP, SIG_IGN 49 | 50 | sys_open nohup, O_CREAT | O_RDWR | O_APPEND, 0x180 ; = 0600 51 | or eax, eax 52 | jns .Lno_openerr 53 | 54 | xor ecx, ecx 55 | .Lsrch_home: 56 | mov esi, [ebp+ecx*4] 57 | inc ecx 58 | lodsd 59 | cmp eax, 'HOME' 60 | jnz .Lsrch_home 61 | lodsb 62 | cmp al, '=' 63 | jnz .Lsrch_home 64 | sys_chdir esi 65 | sys_open nohup, O_CREAT | O_RDWR | O_APPEND, 0x180 ; = 0600 66 | or eax, eax 67 | js near _error 68 | 69 | .Lno_openerr: 70 | mov [nfd], eax 71 | 72 | mov eax, 1 73 | call check_term 74 | mov eax, 2 75 | call check_term 76 | 77 | sys_close [nfd] 78 | 79 | ;; execvp - search the environment variable PATH for the program specified ;; 80 | ;; on top of the stack. ;; 81 | ;; Attention: If the space on the current stack-frame is insufficient to ;; 82 | ;; hold the current $PATH environment variable, the program may crash with ;; 83 | ;; a segmentation fault 84 | 85 | xor ecx, ecx 86 | .Lexecvp: 87 | mov esi, [ebp+ecx*4] 88 | or esi, esi 89 | jz near _error 90 | lodsd 91 | inc ecx 92 | cmp eax, 'PATH' 93 | jnz .Lexecvp 94 | lodsb 95 | cmp al, '=' 96 | jnz .Lexecvp 97 | xor eax, eax 98 | xor ecx, ecx 99 | dec ecx 100 | mov edi, esi 101 | repnz scasb 102 | mov edx, ecx 103 | xor ecx, ecx 104 | dec ecx 105 | mov edi, [esp] 106 | repnz scasb 107 | add ecx, edx 108 | 109 | .Lexecv_next: 110 | lea edi, [esp+ecx] 111 | .Lcopy_loop: 112 | lodsb 113 | cmp al, ':' 114 | jz .Lpath_end 115 | stosb 116 | or al, al 117 | jnz .Lcopy_loop 118 | 119 | .Lpath_end: 120 | push esi 121 | mov esi, [esp+4] 122 | mov al, '/' 123 | stosb 124 | 125 | .Lcopy_loop2: 126 | lodsb 127 | stosb 128 | or al, al 129 | jnz .Lcopy_loop2 130 | lea ebx, [esp+ecx+4] 131 | mov edi, ecx 132 | pop esi 133 | sys_execve ebx, esp, ebp 134 | mov ecx, edi 135 | jmp .Lexecv_next 136 | sys_exit 0x0 137 | 138 | nohup db "nohup.out" 139 | 140 | UDATASEG 141 | termbuf B_STRUC termios 142 | nfd LONG 1 143 | END 144 | -------------------------------------------------------------------------------- /src/paste.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 2001 Joshua Hudson 2 | ; 3 | ;$Id: paste.asm,v 1.1 2001/07/20 07:04:18 konst Exp $ 4 | ; 5 | ;hacker's paste 6 | ; 7 | ;syntax: paste [-d delim] file file [file ...] 8 | ; 9 | ;return 0 on success, nonzero on error 10 | ; 11 | ;Can handle 1024 files 12 | ; 13 | ;Extend, optimize as you like, but please maintain help and error message. 14 | 15 | %include "system.inc" 16 | 17 | CODESEG 18 | 19 | ; ebp = argc, next file descriptor 20 | ; esi = last file descriptor 21 | ; edi = argv[n], file handle 22 | ; ebx = buf count 23 | 24 | numfiles equ 1024 25 | bufsize equ 1024 26 | 27 | START: 28 | pop ebp ; argc 29 | dec ebp 30 | jz .useage ; no args 31 | xor esi, esi 32 | pop edi ; argv[0] 33 | mov byte [delim], __t ; Default delimionator is TAB 34 | 35 | .nextarg: 36 | pop edi ; get next argument 37 | cmp word [edi], '-d' 38 | je .setdelim ; delimionator 39 | sys_open edi,O_RDONLY 40 | test eax,eax 41 | js .fail ; failed to open file 42 | mov dword [desc+esi], eax 43 | add esi, 4 44 | .checkarg: 45 | dec ebp 46 | jnz .nextarg ; get the next argument 47 | or esi, esi 48 | jz .useage ; must be at least 1 file 49 | jmps .go 50 | 51 | .setdelim: 52 | dec ebp 53 | jz .useage 54 | pop edi 55 | mov cl, byte [edi] 56 | mov byte [delim], cl 57 | jmps .checkarg 58 | 59 | .useage: 60 | mov ecx, useage 61 | mov esi, dword [useagel] 62 | sys_write STDERR, ecx, esi 63 | .error: 64 | xor edi, edi 65 | inc edi 66 | .exit: 67 | sys_exit edi 68 | 69 | .fail: 70 | mov ecx, fail 71 | mov esi, dword [faill] 72 | sys_write STDERR, ecx, esi 73 | jmp .error 74 | 75 | 76 | .go: ; Begin reading from files 77 | mov dword [files], esi 78 | xor ebx, ebx 79 | mov dword [bufptr], ebx 80 | xor ebp, ebp 81 | mov edi, dword [desc] 82 | .nextread: 83 | mov ecx, dword [desc+ebp] 84 | or ecx, ecx 85 | jz .nextfile 86 | mov eax, char 87 | .readone: 88 | mov ecx, char 89 | xor edx, edx 90 | inc edx 91 | sys_read edi,ecx,edx ; read next byte 92 | test eax, eax 93 | js .fail 94 | jz .eof 95 | mov al, byte [char] 96 | cmp al, __n 97 | je .nextfile 98 | call .pushbuf ; place al on bufer 99 | jmp .readone 100 | 101 | .eof: 102 | sub dword [files], 4 103 | jz .done ; zero-out desc 104 | ; eax is zero 105 | mov dword [desc + ebp], eax 106 | 107 | .nextfile: 108 | add ebp, 4 109 | cmp ebp, esi 110 | je .lastfile 111 | mov edi, dword [desc + ebp] 112 | mov al, byte [delim] 113 | call .pushbuf 114 | jmp .nextread 115 | 116 | .lastfile: 117 | mov al, __n 118 | call .pushbuf 119 | call .flushbuf 120 | xor ebp, ebp 121 | mov edi, dword [desc + ebp] 122 | jmp .nextread 123 | 124 | .done: 125 | xor eax, eax ; No need to flush buffer 126 | sys_exit eax 127 | 128 | ; .pushbuf: place al on buffer 129 | .pushbuf: 130 | mov ebx, dword [bufptr] 131 | mov byte [buf + ebx], al 132 | inc ebx 133 | cmp ebx, bufsize 134 | je .flushbufi 135 | mov dword [bufptr], ebx 136 | ret 137 | .flushbuf: 138 | mov ebx, dword [bufptr] 139 | .flushbufi: 140 | mov eax, buf 141 | sys_write STDOUT, eax, ebx 142 | xor ebx,ebx 143 | mov dword [bufptr], ebx 144 | ret 145 | 146 | ;*** DEBUGGING: NO BUFFER *** 147 | ; mov byte [buf], al 148 | ; mov eax, buf 149 | ; mov ebx, 1 150 | ; sys_write STDOUT, eax, ebx 151 | ; ret 152 | 153 | ; THIS IS IN THE CODE SEGMENT 154 | useage db "paste [-d delim] file file [file ...]", __n, 0 155 | useagel dd 38 156 | fail db "Unable to read input file", __n, 0 157 | faill dd 26 158 | 159 | UDATASEG 160 | 161 | buf resb bufsize 162 | desc resd numfiles 163 | bufptr resd 1 164 | files resd 1 165 | char resb 1 166 | delim resb 1 167 | 168 | END 169 | 170 | -------------------------------------------------------------------------------- /src/ping.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 2001 Jani Monoses 2 | ; 3 | ;$Id: ping.asm,v 1.2 2001/07/20 07:04:18 konst Exp $ 4 | ; 5 | ;hackers' ping 6 | ; 7 | ;syntax: ping xxx.xxx.xxx.xxx 8 | ; only IP numbers (no hostnames) 9 | ; no parameters (yet) 10 | ; 11 | ;Very simple ping program 12 | ;sends a minimal ICMP ECHO_REQUEST packet (8 bytes) 13 | ;and exits on receiving whatever seems to be a reply to it 14 | ;or after a hardcoded 5 second interval 15 | ; 16 | ;must be run as root or made setuid root (uses SOCKET_RAW) 17 | 18 | %include "system.inc" 19 | 20 | 21 | CODESEG 22 | 23 | ; This is what the ICMP header looks like 24 | ; and this is all we send - 20 bytes long IP header + 8 bytes ICMP 25 | ; a reply to this request should have the TYPE 26 | ; field set to 0 (ECHO_REPLY) and the rest look the same 27 | ; The packet has a precomputed valid checksum for itself 28 | ; 29 | ; 30 | ; 0 31 31 | ; |TYPE | CODE | CHECKSUM | 32 | ; | ID | SEQ | 33 | 34 | 35 | icmp_packet db 08, 00, 0xf7, 0xff, 00, 00, 00, 00 36 | ;icmp_packet_len equ $-icmp_packet 37 | 38 | repl db ' is alive!', 10 39 | ;repl_len equ $-repl 40 | 41 | ;these are defined here instead of letting NASM calculate them with $-... 42 | ;in order to save 2 * 3 bytes in the code. 43 | 44 | %assign icmp_packet_len 8 45 | %assign repl_len 11 46 | %assign TIMEOUT 5 ;default timeout for select() 47 | 48 | START: 49 | pop ebx ;get argument count 50 | dec ebx 51 | jz near .exit ;if no args bail out 52 | pop ebx ;arg 0 - program name 53 | pop esi ;arg 1 - IP number 54 | 55 | push byte repl_len ;push args for sys_writev 56 | push dword repl ;(reply message) 57 | 58 | 59 | mov edi, sockaddr_in 60 | call .ip2int ;fill in sin_addr.s_addr 61 | mov dword[edi], AF_INET | (IPPROTO_IP << 16);fill in sin_family and sin_port 62 | 63 | push edx ;more args for sys_writev 64 | push esi ;(IP number) 65 | 66 | sys_socket AF_INET, SOCK_RAW, IPPROTO_ICMP ;create raw socket 67 | test eax,eax 68 | js near .exit 69 | 70 | mov ebp, eax ;save socket descriptor 71 | 72 | sys_sendto ebp, icmp_packet, icmp_packet_len , 0, edi, 16 ;send echo request 73 | test eax,eax 74 | js .exit 75 | 76 | 77 | mov byte[timeout], TIMEOUT ;timeout in seconds for select 78 | 79 | .recvloop: 80 | 81 | bts [read_fdset],ebp ;FD_SET 82 | inc ebp 83 | sys_select ebp,read_fdset,0,0,timeout 84 | or eax,eax ;timed out ? 85 | jz .exit 86 | 87 | dec ebp 88 | mov edi,recv_packet 89 | sys_recvfrom ebp, edi, 28, 0, 0, 0 ;get packet from network 90 | cmp byte[edi+20], 0 ;is it an ECHO_REPLY? 91 | jne .recvloop 92 | 93 | ; arguments are already on the stack for sys_writev 94 | 95 | sys_writev STDOUT, esp, 2 96 | .exit: 97 | sys_exit eax 98 | 99 | ;function ip2int - converts IP number in dotted 4 notation pointed to by esi, to int32 in edx 100 | 101 | .ip2int: 102 | xor eax,eax 103 | xor edx,edx 104 | xor ecx,ecx 105 | .cc: 106 | xor ebx,ebx 107 | .c: 108 | mov al,[esi+edx] 109 | inc edx 110 | sub al,'0' 111 | jb .next 112 | imul ebx,byte 10 113 | add ebx,eax 114 | jmp short .c 115 | .next: 116 | mov [edi+ecx+4],bl 117 | inc ecx 118 | cmp ecx, byte 4 119 | jne .cc 120 | ret 121 | 122 | UDATASEG 123 | 124 | timeout: resb 8 125 | read_fdset resb 2 126 | sockaddr_in: resb 16 ;sizeof struct sockaddr_in 127 | recv_packet: resb 20 ;ip header size(20) + icmp header size(8) 128 | 129 | END 130 | -------------------------------------------------------------------------------- /src/proxy.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 2002 Indrek Mandre 2 | ; 3 | ;$Id: proxy.asm,v 1.1 2002/03/08 18:59:41 konst Exp $ 4 | ; 5 | ;A hacker's proxy server. 6 | ; 7 | ;syntax: proxy localport remoteip remoteport 8 | ; 9 | ;You could place it in a firewall or other places to route traffic. 10 | ;I tested it using netscape. I pointed the proxy to a HTTP proxy 11 | ;server and configured Netscape to use the local address. Worked 12 | ;like a charm. 13 | ; 14 | ;The only minus here is that it creates two processes for every 15 | ;connection. So watch out your process count. 16 | 17 | %include "system.inc" 18 | 19 | CODESEG 20 | 21 | setsockoptvals dd 1,0,0,0 22 | 23 | START: 24 | pop ebp 25 | cmp ebp,byte 4 ;exactly 3 arguments must be there 26 | jne false_exit 27 | pop esi ;argv[0] 28 | 29 | pop esi ;local port 30 | call str2long 31 | mov edi,ebx 32 | 33 | pop esi 34 | call inet_addr 35 | mov [remsockstruct+4],edx 36 | 37 | pop esi ;remote port 38 | call str2long 39 | xchg bh,bl 40 | shl ebx,16 41 | mov bl,AF_INET ;if (AF_INET > 0xff) mov bx,AF_INET 42 | mov [remsockstruct],ebx 43 | 44 | ; arguments processed now: create socket, setsockopt reuseddr and 45 | ; proceed to binding 46 | 47 | mov ebx,edi 48 | xchg bh,bl ;now save port number into bindsock struct 49 | shl ebx,16 50 | mov bl,AF_INET ;if (AF_INET > 0xff) mov bx,AF_INET 51 | mov [sockstruct],ebx 52 | 53 | .begin: 54 | sys_socket PF_INET,SOCK_STREAM,IPPROTO_TCP 55 | mov ebp,eax ;socket descriptor 56 | 57 | sys_setsockopt ebp,SOL_SOCKET,SO_REUSEADDR,setsockoptvals,4 58 | jmp do_bind 59 | 60 | false_exit: 61 | _mov ebx,1 62 | real_exit: 63 | sys_exit 64 | 65 | ; convert string @ esi to internet address, place it into edx 66 | ; ruined registers: edi, eax, ebx, edx 67 | inet_addr: 68 | xor edx,edx 69 | mov ecx,4 70 | .ipconv: 71 | call str2long 72 | mov dl,bl 73 | ror edx,8 74 | loop .ipconv 75 | ret 76 | 77 | ; convert string @ esi to short (word) and place it into ebx 78 | ; destroyed: esi, eax and ebx 79 | str2long: 80 | xor eax,eax 81 | xor ebx,ebx 82 | .n1: 83 | lodsb 84 | sub al,'0' 85 | jb .n2 86 | cmp al,9 87 | ja .n2 88 | imul ebx,byte 10 89 | add ebx,eax 90 | jmps .n1 91 | .n2: 92 | ret 93 | 94 | ; main program continues here, we do bind 95 | 96 | do_bind: 97 | sys_bind ebp,sockstruct,16 98 | ; this is the only place worth error checking 99 | or eax,eax 100 | jnz false_exit 101 | 102 | sys_listen ebp,5 ;listen(s, 5) 103 | ; this should always succeed 104 | 105 | ;fork after everything is done and exit main process 106 | sys_fork 107 | or eax,eax 108 | jz acceptloop 109 | 110 | true_exit: 111 | _mov ebx,0 112 | jmps real_exit 113 | 114 | acceptloop: 115 | mov [structlen],byte 16 116 | sys_accept ebp,filebuf,structlen 117 | test eax,eax 118 | js acceptloop 119 | mov edi,eax ;our descriptor 120 | 121 | sys_wait4 0xffffffff,NULL,WNOHANG,NULL 122 | sys_wait4 123 | 124 | sys_fork ;we now fork, child goes his own way, daddy goes back to accept 125 | or eax,eax 126 | jz .childrun 127 | sys_close edi 128 | _jmp acceptloop 129 | 130 | ; Child code starts here, source descriptor is in EDI 131 | ; We have to open connection to the darling remote system and 132 | ; proxy data. sounds simple? it sure ain't. 133 | .childrun: 134 | 135 | ; at first create a socket, ignoring errors, if there are any 136 | ; we run into them later anyway 137 | sys_socket PF_INET,SOCK_STREAM,IPPROTO_TCP 138 | mov esi,eax ;socket descriptor 139 | ; now we have to connect that socket to remote host :) 140 | sys_connect esi,remsockstruct,16 141 | or eax,eax 142 | jz .goon 143 | ; if connect failed, @sys_exit automagically kernel closes connection 144 | sys_exit 145 | .goon: 146 | ; Now the situation is this: EDI = source, ESI = destination :))) 147 | ; What we do is we fork again and each reads from themselves and 148 | ; writes into theother. waste of processes? yes. easy hack? yes!!! 149 | sys_fork 150 | or eax,eax 151 | jz .papa 152 | 153 | xchg edi,esi ; the child just exchanges the descrptors :) 154 | 155 | .papa: 156 | sys_read esi,filebuf,0x2000 157 | cmp eax,0 158 | jng .exit 159 | sys_write edi,filebuf,eax 160 | jmps .papa 161 | .exit: 162 | ; shutdown also the other socket, so we'll end up cleaned, no childs hanging 163 | sys_shutdown edi,1 164 | jmp true_exit 165 | 166 | UDATASEG 167 | 168 | remoteadd resd 1 169 | remoteport resd 1 170 | 171 | sockstruct resd 4 172 | remsockstruct resd 4 173 | 174 | filebuf resb 0x2000 175 | 176 | structlen resb 1 177 | 178 | END 179 | -------------------------------------------------------------------------------- /src/pwd.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 1999-2002 Konstantin Boldyshev 2 | ;Copyright (C) 1999 Yuri Ivliev 3 | ; 4 | ;$Id: pwd.asm,v 1.9 2002/03/14 17:42:08 konst Exp $ 5 | ; 6 | ;hackers' pwd 7 | ; 8 | ;syntax: pwd 9 | ; 10 | ;0.01: 05-Jun-1999 initial release (KB) 11 | ;0.02: 17-Jun-1999 size improvements (KB) 12 | ;0.03: 04-Jul-1999 Linux 2.0 stat-based part added (YI) 13 | ;0.04: 18-Sep-1999 elf macros support (KB) 14 | ;0.05: 17-Dec-1999 size improvements (KB) 15 | ;0.06: 08-Feb-2000 (KB) 16 | ;0.07: 21-Aug-2000 STAT_PWD define (KB) 17 | ;0.08: 14-Mar-2002 bugfixes, syscall optimization, and portability fixes 18 | ; in stat-based version (KB) 19 | 20 | %include "system.inc" 21 | 22 | %ifdef __LINUX__ 23 | %if __KERNEL__ <= 20 24 | %define STAT_PWD 25 | %endif 26 | %endif 27 | 28 | %ifdef __OPENBSD__ 29 | %define STAT_PWD ;no getcwd :( 30 | %endif 31 | 32 | %assign PATHSIZE 0x100 33 | %assign BUFSIZE 0x1000 34 | 35 | CODESEG 36 | 37 | START: 38 | 39 | %ifdef STAT_PWD 40 | 41 | %assign lBackPath 0x00000040 42 | 43 | ;;getting root's inode and block device 44 | sys_lstat Root.path,st ;get stat for root 45 | mov eax,[ecx+Stat.st_dev] 46 | mov [Root.st_dev],eax 47 | mov eax,[ecx+Stat.st_ino] 48 | mov [Root.st_ino],eax 49 | ;;data initialization 50 | mov ebp,BackPath ;ebp - current position in BackPath 51 | mov dword [ebp],'./' ;we are starting from current dir 52 | mov edi,path+PATHSIZE-1 ;edi - current position in Path - 1 53 | mov byte [edi], __n ;NL at the end of Path 54 | dec edi 55 | ;;the begin of up to root loop 56 | .up: 57 | sys_lstat BackPath,st ;get stat for current location 58 | test eax,eax 59 | js .exit 60 | mov byte [edi],'/' 61 | dec edi 62 | mov eax,[ecx+Stat.st_dev] 63 | cmp eax,[Root.st_dev] ;is our block device roots'? 64 | jne .continue ;no 65 | mov eax,[ecx+Stat.st_ino] 66 | cmp eax,[Root.st_ino] ;is our inode roots'? 67 | jne .continue ;no 68 | ;;the begin of exit pwd 69 | inc edi ;yes, pwd comptete 70 | mov esi,path+PATHSIZE-2 71 | mov edx,esi 72 | sub edx,edi ;is "/" our current dir? 73 | jz .print ;yes 74 | mov byte [esi],__n ;no, remove leading slash 75 | dec edx 76 | .print: 77 | inc edx 78 | inc edx 79 | sys_write STDOUT,edi ;print work dir 80 | .exit: 81 | sys_exit_true ;and go out 82 | ;; the end of exit pwd 83 | .continue: 84 | mov dword [ebp],'../' ;move current location up 85 | lea ebp,[ebp+3] 86 | mov ax,[ecx+Stat.st_dev] 87 | mov [Dev],ax ;save block device for prev location 88 | mov eax,[ecx+Stat.st_ino] 89 | mov [Inode],eax ;save inode for prev location 90 | sys_open BackPath,O_RDONLY ;open current location 91 | test eax,eax 92 | js .exit 93 | mov edx,eax 94 | ;; start of get directory entry loop 95 | .get_de: 96 | mov ebx,edx 97 | %ifdef __BSD__ 98 | sys_getdirentries EMPTY,buf,BUFSIZE,st ;get current dirent 99 | %else 100 | sys_getdents EMPTY,buf,BUFSIZE ;get current dirent 101 | %endif 102 | test eax,eax 103 | jle near .exit 104 | mov [de_num],eax ;save dirents size 105 | mov edx,ebx 106 | mov esi,ecx ;esi - pointer to dirent 107 | .next_de: 108 | ;concatenate current location and current dirent name 109 | ;;;; mov ecx,ebp 110 | ;;;; lea ebx,[esi+dirent.d_name] 111 | mov ebx,ebp 112 | xor ecx,ecx 113 | .next.d_name.1: 114 | ;;;; mov al,[ebx] 115 | ;;;; inc ebx 116 | mov al,[esi+ecx+dirent.d_name] 117 | ;;;; mov [ecx],al 118 | mov [ebx+ecx],al 119 | inc ecx 120 | or al,al 121 | jnz .next.d_name.1 122 | sys_lstat BackPath,st ;get stat for current dirent 123 | test eax,eax 124 | js near .exit 125 | mov ax,[ecx+Stat.st_dev] 126 | cmp ax,[Dev] ;is this block device ours' 127 | jne .done_de ;no, try next dirent 128 | mov eax,[ecx+Stat.st_ino] 129 | cmp eax,[Inode] ;is this inode ours' 130 | jne .done_de ;no, try next dirent 131 | ;; the end of get directory entry loop 132 | sys_close edx ;close current location 133 | mov [ebp],al 134 | lea esi,[esi+dirent.d_name] 135 | ;;;; mov ebx,esi 136 | xor ecx,ecx 137 | .next.d_name.2: 138 | ;;;; inc esi 139 | ;;;; cmp al,[esi] 140 | inc ecx 141 | cmp al,[esi+ecx] 142 | jc .next.d_name.2 143 | ;;;; mov ecx,esi 144 | ;;;; sub ecx,ebx 145 | ;;;; dec esi 146 | lea esi,[esi+ecx-1] 147 | std 148 | rep movsb 149 | jmp .up 150 | 151 | .done_de: 152 | movzx ecx,word [esi+dirent.d_reclen] 153 | add esi,ecx 154 | sub [de_num],ecx 155 | jg .next_de 156 | jmp .get_de 157 | 158 | ;; the end of up to root loop 159 | 160 | Root.path db '/',EOL 161 | 162 | %else 163 | 164 | sys_getcwd path,PATHSIZE 165 | 166 | mov esi,ebx 167 | xor edx,edx 168 | .next: 169 | inc edx 170 | lodsb 171 | or al,al 172 | jnz .next 173 | mov byte [esi-1],__n 174 | sub esi,edx 175 | sys_write STDOUT,esi 176 | sys_exit_true 177 | %endif 178 | 179 | 180 | UDATASEG 181 | 182 | path resb PATHSIZE ;path buffer 183 | 184 | %ifdef STAT_PWD 185 | 186 | BackPath CHAR lBackPath ;back path buffer 187 | 188 | Dev UINT 1 189 | Root.st_dev UINT 1 190 | Inode UINT 1 191 | Root.st_ino UINT 1 192 | 193 | st B_STRUC Stat,.st_dev,.st_ino 194 | 195 | de_num resd 1 196 | buf resb 0x1000 197 | 198 | %endif 199 | 200 | END 201 | -------------------------------------------------------------------------------- /src/readkey.asm: -------------------------------------------------------------------------------- 1 | ; Copyright (C) 2001, Tiago Gasiba (ee97034@fe.up.pt) 2 | ; 3 | ; $Id: readkey.asm,v 1.3 2002/02/02 08:49:25 konst Exp $ 4 | ; 5 | ; hacker's readkey 6 | ; 7 | ; This program reads a keystroke and returns the key code 8 | ; in hex. It can be useful when writting script files. 9 | 10 | %include "system.inc" 11 | 12 | CODESEG 13 | 14 | hex db '0123456789abcdef' 15 | 16 | do_ioctl: 17 | sys_ioctl STDIN 18 | ret 19 | 20 | START: 21 | _mov edx,oldtermios 22 | push edx 23 | push dword TCGETS 24 | pop ecx 25 | sub sp,byte 4 26 | call do_ioctl 27 | 28 | pop ecx 29 | _mov edx,newtermios 30 | push edx 31 | call do_ioctl 32 | 33 | and dword [newtermios+termios.c_lflag],~(ICANON|ECHO|ISIG) 34 | 35 | _mov ecx,TCSETS 36 | pop edx 37 | push ecx 38 | call do_ioctl 39 | 40 | _mov eax,0 41 | mov dword [newtermios],eax ; clean buffer ; ####### 42 | sys_read STDIN,newtermios,4 ; read keystroke 43 | 44 | pop ecx 45 | pop edx 46 | call do_ioctl 47 | 48 | _mov ecx,8 ; convert number to ascii (hex) 49 | _mov esi,oldtermios+7 50 | _mov edx,dword [newtermios] 51 | _mov ebx,hex 52 | .outro: 53 | mov eax,edx 54 | 55 | and al,0xf 56 | xlatb 57 | mov byte [esi],al 58 | dec esi 59 | shr edx,4 60 | loop .outro 61 | 62 | mov byte [oldtermios+8],0xa 63 | mov word [prefix],"0x" 64 | 65 | sys_write STDOUT,prefix,11 ; write string 66 | 67 | sys_exit 0 68 | 69 | UDATASEG 70 | 71 | prefix: 72 | resb 2 73 | 74 | oldtermios: 75 | B_STRUC termios,.c_iflag,.c_oflag 76 | newtermios: 77 | B_STRUC termios,.c_iflag,.c_oflag 78 | 79 | END 80 | -------------------------------------------------------------------------------- /src/readlink.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 2001 by Joshua Hudson 2 | ; 3 | ;$Id: readlink.asm,v 1.1 2001/08/14 18:55:38 konst Exp $ 4 | ; 5 | ;usage: readlink symlink [...] 6 | 7 | %include "system.inc" 8 | 9 | CODESEG 10 | 11 | START: 12 | pop ebp 13 | pop eax ; Program name 14 | .next: 15 | dec ebp 16 | jz .done 17 | _mov edx, 1024 18 | _mov ecx, buf 19 | pop ebx ; Path name 20 | sys_readlink 21 | test eax, eax 22 | jc .next 23 | xchg edx, eax ; one byte smaller than mov 24 | mov [buf + edx], byte __n 25 | inc edx 26 | sys_write STDOUT, buf 27 | jmps .next 28 | .done sys_exit_true 29 | 30 | UDATASEG 31 | 32 | buf resb 1025 33 | 34 | END 35 | -------------------------------------------------------------------------------- /src/reboot.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 1999-2002 Konstantin Boldyshev 2 | ; 3 | ;$Id: reboot.asm,v 1.5 2002/02/02 08:49:25 konst Exp $ 4 | ; 5 | ;hackers' reboot/halt/poweroff 6 | ; 7 | ;syntax: reboot [-p] [-f] 8 | ; halt [-p] 9 | ; poweroff 10 | ; 11 | ;-p try to do poweroff (as if called as 'poweroff') 12 | ;-f do actual reboot (bypass shutdown sequence) 13 | ; 14 | ;0.01: 04-Jul-1999 initial release 15 | ;0.02: 23-Dec-2001 added "-p" option, try to talk to init, BSD port 16 | ; 17 | ;WARNING: 18 | ; 19 | ;BSD is smart enough to care about things on sys_reboot, while Linux is not. 20 | ;Linux users -- this is actual reboot/halt/poweroff, it cares not 21 | ;about runlevels and "correct" shutdown. You have been warned. 22 | ;So that your day may not be ruined, Linux version of 'reboot' tries to tell 23 | ;init to invoke "correct" usual reboot sequence (*only* if called as 'reboot'), 24 | ;waits 5 seconds (so that it can be terminated), and reboots system; 25 | ;so, if it was not terminated during these 5 seconds, you are unlucky. 26 | ;This "safety" step is bypassed by '-f' option. 27 | 28 | %include "system.inc" 29 | 30 | CODESEG 31 | 32 | %ifdef __LINUX__ 33 | %if __SYSCALL__=__S_KERNEL__ 34 | %define LINUX_REBOOT 35 | %endif 36 | %endif 37 | 38 | 39 | START: 40 | xor edi,edi 41 | pop ebp ;argc 42 | 43 | pop esi 44 | .n1: 45 | lodsb 46 | or al,al 47 | jnz .n1 48 | 49 | ;default action is reboot 50 | %ifdef LINUX_REBOOT 51 | _mov ebx,LINUX_REBOOT_MAGIC1 52 | _mov ecx,LINUX_REBOOT_MAGIC2 53 | _mov edx,LINUX_REBOOT_CMD_RESTART 54 | %else 55 | _mov ebx,RB_AUTOBOOT 56 | %else 57 | %endif 58 | 59 | .next: 60 | dec ebp 61 | jz .done 62 | 63 | pop eax 64 | cmp word [eax],"-p" 65 | jz .poweroff 66 | cmp word [eax],"-f" 67 | jnz .done 68 | inc edi 69 | jmps .next 70 | 71 | .done: 72 | 73 | .n2: 74 | cmp dword [esi-5],'halt' ;halt 75 | jnz .n3 76 | 77 | %ifdef LINUX_REBOOT 78 | _mov edx,LINUX_REBOOT_CMD_HALT 79 | %else 80 | _mov ebx,RB_HALT 81 | %else 82 | %endif 83 | jmps .halt 84 | 85 | .n3: 86 | cmp word [esi-3],'ff' ;poweroff 87 | jnz .n4 88 | 89 | .poweroff: 90 | %ifdef LINUX_REBOOT 91 | _mov edx,LINUX_REBOOT_CMD_POWER_OFF 92 | %else 93 | _mov ebx,RB_HALT|RB_POWEROFF 94 | %else 95 | %endif 96 | 97 | .halt: 98 | 99 | %ifdef LINUX_REBOOT ;make sure that CTRL+ALT+DEL is enabled 100 | push edx 101 | sys_reboot EMPTY,EMPTY,LINUX_REBOOT_CMD_CAD_ON 102 | pop edx 103 | %endif 104 | 105 | .reboot: 106 | sys_reboot 107 | 108 | .exit: 109 | sys_exit eax 110 | 111 | .n4: 112 | %ifdef LINUX_REBOOT 113 | or edi,edi ;check for -f 114 | jnz .reboot ;let the show begin 115 | 116 | pusha 117 | sys_kill 1,SIGINT ;try to kill them all 118 | sys_nanosleep t ;and await our death 119 | popa 120 | sys_sync 121 | jmps .reboot ;oops, init, you're late 122 | 123 | t I_STRUC timespec 124 | .tv_sec _LONG 5 125 | .tv_nsec _LONG 0 126 | I_END 127 | 128 | %else 129 | 130 | jmps .reboot 131 | 132 | %endif 133 | 134 | END 135 | -------------------------------------------------------------------------------- /src/renice.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 2001 Jonathan Leto 2 | ; 3 | ;$Id: renice.asm,v 1.1 2001/01/21 15:18:46 konst Exp $ 4 | ; 5 | ;hackers' renice 6 | ; 7 | ;syntax: renice priority pid [ pid ... ] 8 | ; 9 | ;Version 0.1 - Thu Jan 04 12:54:59 EST 2001 10 | ; 11 | ;All comments/feedback welcome. 12 | 13 | %include "system.inc" 14 | 15 | CODESEG 16 | 17 | usage db "usage: renice priority pid",__n 18 | _usagelen equ $-usage 19 | %assign usagelen _usagelen 20 | 21 | START: 22 | pop ebx ; argc 23 | dec ebx 24 | pop ebx ; argv[0], program name 25 | jz .usage 26 | 27 | pop esi 28 | test esi,esi 29 | jz .exit_err 30 | call .ascii_to_num 31 | _mov [prio],eax ; priority 32 | 33 | pop esi 34 | test esi,esi 35 | jz .exit_err 36 | .nextarg: 37 | call .ascii_to_num 38 | _mov [pid],eax ; pid 39 | 40 | sys_setpriority PRIO_PROCESS,[pid],[prio] 41 | pop esi 42 | test esi,esi 43 | jnz .nextarg 44 | _mov ebx,0 45 | .exit: 46 | sys_exit 47 | .usage: 48 | sys_write STDOUT,usage,usagelen 49 | .exit_err: 50 | _mov ebx,1 51 | jmps .exit 52 | 53 | ;--------------------------------------- 54 | ; esi = string 55 | ; eax = number 56 | .ascii_to_num: 57 | push esi 58 | xor eax,eax ; zero out regs 59 | xor ebx,ebx 60 | 61 | cmp [esi], byte '-' 62 | jnz .next_digit 63 | lodsb 64 | 65 | .next_digit: 66 | lodsb ; load byte from esi 67 | test al,al 68 | jz .done 69 | sub al,'0' ; '0' is first number in ascii 70 | imul ebx,10 71 | add ebx,eax 72 | jmp .next_digit 73 | 74 | .done: 75 | xchg ebx,eax 76 | pop esi 77 | cmp [esi], byte '-' 78 | jz .done_neg 79 | ret 80 | .done_neg: 81 | neg eax ;if first char is -, negate 82 | ret 83 | ;--------------------------------------- 84 | 85 | UDATASEG 86 | pid: resd 1 87 | prio: resd 1 88 | 89 | END 90 | -------------------------------------------------------------------------------- /src/rot13.asm: -------------------------------------------------------------------------------- 1 | ; Copyright (c) 2001 Thomas M. Ogrisegg 2 | ; 3 | ; $Id: rot13.asm,v 1.3 2002/02/14 13:38:15 konst Exp $ 4 | ; 5 | ; Enc/Decrypt strings by rotating characters (with 13). 6 | ; Often used in Usenet articles 7 | ; 8 | ; syntax: rot13 9 | 10 | %include "system.inc" 11 | 12 | %assign BUFSIZE 80 13 | 14 | CODESEG 15 | 16 | START: 17 | sub esp, BUFSIZE ;84 18 | 19 | IOLoop: 20 | sys_read STDIN, esp, BUFSIZE ;84 21 | or eax, eax 22 | jz do_exit 23 | mov ebp, eax 24 | mov ecx, eax 25 | mov esi, esp 26 | mov edi, esi 27 | jmp xloop 28 | rotloop: 29 | stosb 30 | dec ecx 31 | jz _out 32 | xloop: 33 | lodsb 34 | cmp al, 'A' 35 | jnge rotloop 36 | cmp al, 'z' 37 | jg rotloop 38 | cmp al, 'Z' 39 | jng ok 40 | cmp al, 'a' 41 | jnge rotloop 42 | ok: 43 | cmp al, 'M' 44 | jng lower 45 | cmp al, 'Z' 46 | jng over 47 | cmp al, 'm' 48 | jng lower 49 | cmp al, 'z' 50 | jng over 51 | jmp rotloop 52 | lower: ; %al == a-m, A-M 53 | add al, 13 54 | jmp rotloop 55 | over: ; %al == n-z, N-Z 56 | sub al, 13 57 | jmp rotloop 58 | 59 | _out: 60 | sys_write STDOUT, esp, ebp 61 | jmp IOLoop 62 | do_exit: 63 | sys_exit eax 64 | 65 | END 66 | -------------------------------------------------------------------------------- /src/scons.asm: -------------------------------------------------------------------------------- 1 | ; Copyright (c) 2002 Thomas M. Ogrisegg 2 | ; 3 | ; scons - serial terminal 4 | ; 5 | ; syntax: 6 | ; scons serialdevice (e.g. /dev/ttyS1) 7 | ; 8 | ; License : GNU General Public License 9 | ; Author : Thomas Ogrisegg 10 | ; E-Mail : tom@rhadamanthys.org 11 | ; Version : 0.8 12 | ; Created : 03/15/02 13 | ; 14 | ; $Id: scons.asm,v 1.2 2002/08/16 15:07:08 konst Exp $ 15 | 16 | %include "system.inc" 17 | 18 | %assign IOBUF_SIZE 100 19 | 20 | CODESEG 21 | 22 | init db __r, __n 23 | 24 | quit: 25 | sys_ioctl STDIN, TCSETS, term 26 | sys_exit 0x42 27 | 28 | START: 29 | pop ecx 30 | dec ecx 31 | jz near .syntax_error 32 | pop esi 33 | pop esi 34 | sys_signal SIGQUIT, quit 35 | sys_open esi, O_RDWR | O_NOCTTY 36 | or eax, eax 37 | js near .open_error 38 | mov [fd], eax 39 | sys_ioctl eax, TCGETS, esp 40 | %ifdef __LINUX__ 41 | and long [esp+termios.c_cflag], ~(CBAUD | CBAUDEX);~B38400 42 | or long [esp+termios.c_cflag], B9600 ;B38400 43 | %else 44 | mov dword [esp+termios.c_cflag], B9600 45 | %endif 46 | sys_ioctl [fd], TCSETS, esp 47 | sys_ioctl STDIN, TCGETS, term 48 | sys_ioctl STDIN, TCGETS, esp 49 | lea edi, [esp+termios.c_cc] 50 | mov ecx, NCCS 51 | xor eax, eax 52 | repnz stosb 53 | mov byte [esp+termios.c_cc+VQUIT], 0x1c 54 | and dword [esp+termios.c_lflag], ~(ECHO | ICANON) 55 | sys_ioctl STDIN, TCSETS, esp 56 | sys_write [fd], init, 2 57 | .Lread_write: 58 | push long 0x00000001 59 | push long STDIN 60 | push long 0x00000001 61 | push long [fd] 62 | .Lnext: 63 | mov edi, esp 64 | sys_poll edi, 2, 100000 65 | test long [esp+4], 0x00010000 66 | jz .Lread_in 67 | test long [esp+0xc], 0x00010000 68 | jz .Lexit2 69 | jmp .Lnext 70 | .Lread_in: 71 | sys_read STDIN, iobuf, IOBUF_SIZE 72 | sys_write [fd], iobuf, eax 73 | jmp .Lnext 74 | .Lexit2: 75 | sys_read [fd], iobuf, IOBUF_SIZE 76 | sys_write STDOUT, iobuf, eax 77 | jmp .Lnext 78 | 79 | .open_error: 80 | sys_write STDOUT, openerr, opelen 81 | sys_exit 0x1 82 | 83 | .syntax_error: 84 | sys_write STDOUT, syntax, synlen 85 | sys_exit 0x2 86 | 87 | syntax db "$@ serialdevice (e.g. /dev/ttyS0)", __n 88 | synlen equ $ - syntax 89 | openerr db "Error opening serial device", __n 90 | opelen equ $ - openerr 91 | 92 | UDATASEG 93 | iobuf UCHAR IOBUF_SIZE 94 | fd LONG 1 95 | term B_STRUC termios,.c_cflag,.c_lflag,.c_cc 96 | END 97 | -------------------------------------------------------------------------------- /src/sleep.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 1999-2001 Konstantin Boldyshev 2 | ; 3 | ;$Id: sleep.asm,v 1.7 2002/03/07 11:13:32 konst Exp $ 4 | ; 5 | ;hackers' sleep/usleep [GNU replacement] 6 | ; 7 | ;syntax: sleep number[nsmhd]... 8 | ; usleep usec 9 | ; 10 | ;n - nanoseconds 11 | ;s - seconds 12 | ;m - minutes 13 | ;h - hours 14 | ;d - days 15 | ; 16 | ;example: sleep 1 2 3s 17 | ; 18 | ;NOTE: this utility has nanoseconds suffix extension 19 | ; in addition to usual GNU sleep suffixes 20 | ; 21 | ;0.01: 17-Jun-1999 initial release 22 | ;0.02: 03-Jul-1999 sleep is now using sys_nanosleep 23 | ;0.03: 18-Sep-1999 elf macros support 24 | ;0.04: 22-Jan-2001 nanoseconds support 25 | ;0.05: 07-Mar-2002 usleep support (IM) 26 | 27 | %include "system.inc" 28 | 29 | CODESEG 30 | 31 | one_ms db '1', 0 32 | 33 | START: 34 | pop esi 35 | pop esi 36 | 37 | ; Find out whether sleep or usleep was called 38 | .n1: 39 | lodsb 40 | or al,al 41 | jnz .n1 42 | cmp byte [esi-7],'u' 43 | jnz .args 44 | ; We have 'usleep', sleeping in microseconds 45 | mov ch,1 46 | pop esi 47 | push esi 48 | or esi,esi 49 | jnz .n2 50 | ;no arguments given, default is to sleep 1 microseconds 51 | mov esi,one_ms 52 | .n2: 53 | push byte 0 ;force single argument 54 | push esi 55 | 56 | .args: 57 | pop esi 58 | or esi,esi 59 | jz .toexit 60 | mov edi,esi 61 | 62 | xor eax,eax 63 | xor ebx,ebx 64 | xor edx,edx 65 | .next_digit: 66 | lodsb 67 | sub al,'0' 68 | jb .done 69 | cmp al,9 70 | ja .done 71 | imul ebx,byte 10 72 | add ebx,eax 73 | adc edx,byte 0 74 | jmps .next_digit 75 | .done: 76 | mov eax,ebx 77 | test edx,edx 78 | jnz .ok 79 | test eax,eax 80 | .toexit: 81 | jz do_exit 82 | .ok: 83 | _mov ebx,1 84 | 85 | or ch,ch 86 | jz .nousleep 87 | 88 | ; now nanosleep can take arguments only up to 999999 microseconds, 89 | ; that means we have to divide and conquer 90 | mov ebx, 1000000 91 | div ebx 92 | xchg eax,edx 93 | mov ecx,edx 94 | mov ebx,1000 95 | mul ebx 96 | mov edx,ecx 97 | xchg eax,edx 98 | jmps .set_sleep2 99 | 100 | .nousleep: 101 | mov cl,byte [esi - 1] 102 | 103 | test cl,cl 104 | jz .set_sleep 105 | .s: 106 | cmp cl,'s' 107 | jz .set_sleep2 108 | .m: 109 | _mov ebx,60 110 | cmp cl,'m' 111 | jz .set_sleep 112 | .h: 113 | _mov ebx,60*60 114 | cmp cl,'h' 115 | jz .set_sleep 116 | .d: 117 | _mov ebx,60*60*24 118 | cmp cl,'d' 119 | jz .set_sleep 120 | cmp cl,'n' 121 | jnz do_exit 122 | xchg eax,edx 123 | jmps .set_sleep2 124 | .set_sleep: 125 | mul ebx 126 | .set_sleep2: 127 | mov ebx,t 128 | .nanosleep: 129 | mov dword [ebx],eax 130 | mov dword [ebx+4],edx 131 | .do_sleep: 132 | sys_nanosleep EMPTY,NULL 133 | jmp .args 134 | 135 | do_exit: 136 | sys_exit eax 137 | 138 | UDATASEG 139 | 140 | t B_STRUC timespec 141 | 142 | END 143 | -------------------------------------------------------------------------------- /src/softdog.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 1999-2001 Konstantin Boldyshev 2 | ; 3 | ;$Id: softdog.asm,v 1.6 2002/02/02 08:49:25 konst Exp $ 4 | ; 5 | ;hackers' softdog (software watchdog) 6 | ; 7 | ;syntax: softdog [PERIOD] 8 | ; 9 | ;PERIOD (in seconds) - kick period, if missing use default of 10 10 | ; 11 | ;example: softdog 12 | ; softdog 15 13 | ; 14 | ;0.01: 04-Jul-1999 initial release 15 | ;0.02: 29-Jul-1999 fixed bug with sys_open 16 | ;0.03: 18-Sep-1999 elf macros support 17 | ;0.04: 22-Jan-2001 minor size improvement 18 | 19 | %include "system.inc" 20 | 21 | %assign DEFPERIOD 10 ;default period 22 | %assign MAXPERIOD 60 ;maximum kernel margin 23 | 24 | CODESEG 25 | 26 | ;ebp - period 27 | 28 | START: 29 | _mov ebp,DEFPERIOD 30 | pop esi 31 | dec esi 32 | jz .start 33 | pop esi 34 | pop esi 35 | 36 | xor eax,eax 37 | xor ebx,ebx 38 | .next_digit: 39 | lodsb 40 | sub al,'0' 41 | jb .done 42 | cmp al,9 43 | ja .done 44 | imul ebx,byte 10 45 | add ebx,eax 46 | jmps .next_digit 47 | .done: 48 | or ebx,ebx ;zero? 49 | jz .start 50 | _mov eax,MAXPERIOD 51 | cmp ebx,eax ;if more than max - set max 52 | jb .start0 53 | mov ebx,eax 54 | .start0: 55 | mov ebp,ebx 56 | .start: 57 | mov [t.tv_sec],ebp 58 | 59 | sys_open softdog,O_WRONLY 60 | mov ebp,eax 61 | test eax,eax 62 | js .exit 63 | 64 | sys_fork 65 | or eax,eax 66 | jz .child 67 | .exit: 68 | sys_exit 69 | 70 | .child: 71 | sys_write ebp,softdog,1 72 | sys_nanosleep t,NULL 73 | jmps .child 74 | 75 | softdog db '/dev/watchdog',EOL 76 | 77 | UDATASEG 78 | 79 | t B_STRUC timespec,.tv_sec 80 | 81 | END 82 | -------------------------------------------------------------------------------- /src/strings.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 1999 Dmitry Bakhvalov 2 | ; 3 | ;$Id: strings.asm,v 1.3 2000/04/07 18:36:01 konst Exp $ 4 | ; 5 | ;hackers' strings 6 | ; 7 | ;0.01: 18-Oct-1999 initial release 8 | ;0.02: 19-Oct-1999 size optimizations 9 | ; 10 | ;syntax: strings [option] [file, file, file...] 11 | ; The only supported option by now is -n. 12 | ; See strings manpage to find out more about this cool option :) 13 | ; 14 | ; If no file is given stdin is used. 15 | ; 16 | ; returns -1 on error, 0 on success 17 | ; 18 | ; If someone really feels like he needs more of the original GNU strings' 19 | ; options - just ask me or better yet add 'em yourself :) 20 | ; 21 | ; Send me any feedback,suggestions,additional code, etc. 22 | ; 23 | 24 | %include "system.inc" 25 | 26 | CODESEG 27 | 28 | START: 29 | pop eax ; get argc 30 | dec eax 31 | jz set_filehandle ; read from stdin (eax=0) 32 | 33 | pop eax ; get argv[0] 34 | get_next_arg: 35 | pop ebx 36 | test ebx,ebx 37 | jz near no_more_args 38 | 39 | cmp word [ebx],"-n" 40 | jnz just_open_it 41 | 42 | pop esi 43 | call ascii_to_bin 44 | mov [n],eax 45 | 46 | jmp get_next_arg 47 | 48 | 49 | just_open_it: 50 | sys_open EMPTY,O_RDONLY 51 | test eax,eax 52 | js near error 53 | 54 | set_filehandle: 55 | mov ebp,eax 56 | read_file: 57 | sys_read ebp,buf,buf_size 58 | test eax,eax 59 | js near error 60 | jz get_next_arg 61 | 62 | mov esi,ecx ; esi=ecx=buf 63 | mov ecx,eax ; ecx=bites read 64 | xor edx,edx ; edx will hold a number of 65 | ; printable chars 66 | xor eax,eax 67 | 68 | next_char: 69 | lodsb 70 | cmp al,' ' 71 | jl not_an_ascii 72 | cmp al,'~' 73 | jg not_an_ascii 74 | test ah,ah 75 | jnz inc_counter 76 | inc ah 77 | mov [pointer],esi 78 | inc_counter: 79 | inc edx 80 | loop next_char 81 | jmp read_file 82 | not_an_ascii: 83 | test ah,ah 84 | jz near count_this_char 85 | cmp edx,[n] 86 | jl reset_flags 87 | 88 | push ecx ; save counter 89 | 90 | mov ecx,[pointer] 91 | dec ecx 92 | sys_write STDOUT 93 | 94 | sys_write STDOUT, cr, 1 95 | 96 | pop ecx ; restore counter 97 | reset_flags: 98 | xor eax,eax ; reset ascii flag (ah) 99 | xor edx,edx ; reset ascii counter 100 | count_this_char: 101 | dec ecx 102 | jnz near next_char 103 | jmp read_file 104 | 105 | error: 106 | xor ebx,ebx 107 | dec ebx 108 | jmp do_exit 109 | no_more_args: 110 | xor ebx,ebx 111 | do_exit: 112 | sys_exit 113 | 114 | 115 | ; esi = string 116 | ; eax = bin number 117 | ascii_to_bin: 118 | xor eax,eax 119 | xor ebx,ebx 120 | .next_digit: 121 | lodsb 122 | test al,al 123 | jz .done 124 | sub al,'0' 125 | imul ebx,10 126 | add ebx,eax 127 | jmp .next_digit 128 | .done: 129 | xchg ebx,eax 130 | ret 131 | 132 | DATASEG 133 | 134 | cr: db 10 135 | n: dd 4 136 | 137 | UDATASEG 138 | 139 | pointer: resd 1 140 | buf: resb 4096 141 | buf_size equ $-buf 142 | 143 | END 144 | -------------------------------------------------------------------------------- /src/swapon.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 1999 Konstantin Boldyshev 2 | ;Copyright (C) 2002 Thomas M. Ogrisegg 3 | ; 4 | ;$Id: swapon.asm,v 1.3 2002/03/21 08:33:21 konst Exp $ 5 | ; 6 | ;hackers' swapon/swapoff/mkswap 7 | ; 8 | ;syntax: swapon device ... 9 | ; 10 | ;example: swapon /dev/hda9 /dev/hda10 11 | ; swapoff /dev/hda5 12 | ; mkswap /dev/hda8 13 | ; 14 | ;0.01: 04-Jul-1999 initial release 15 | ;0.02: 18-Mar-2002 mkswap extnesion for Linux 2.2+ (TO) 16 | 17 | %include "system.inc" 18 | 19 | CODESEG 20 | 21 | START: 22 | pop esi 23 | pop esi 24 | .n1: 25 | lodsb 26 | or al,al 27 | jnz .n1 28 | .next_file: 29 | pop ebx 30 | or ebx,ebx 31 | jz .exit 32 | cmp word [esi-7],'mk' 33 | jz .mkswap 34 | cmp word [esi-3],'ff' 35 | jnz .swapon 36 | 37 | .swapoff: 38 | sys_swapoff 39 | jmps .next_file 40 | 41 | .swapon: 42 | sys_swapon 43 | jmps .next_file 44 | 45 | .mkswap: 46 | sys_open EMPTY,O_RDWR 47 | test eax,eax 48 | js .exit 49 | mov ebp,eax 50 | sys_lseek ebp,0,SEEK_END 51 | test eax,eax 52 | jns .do_mkswap 53 | 54 | .error: 55 | sys_write STDERR,error,errlen 56 | .exit: 57 | sys_exit eax 58 | 59 | .do_mkswap: 60 | mov edi, eax 61 | shr edi, 0xc 62 | dec edi 63 | sys_lseek ebp,0x400,SEEK_SET 64 | test eax,eax 65 | js .error 66 | push byte 0x1 67 | mov ecx,esp 68 | sys_write ebp,EMPTY,4 69 | push edi 70 | mov ecx,esp 71 | sys_write ebp,EMPTY,4 72 | sys_lseek ebp,0xff6,SEEK_SET 73 | sys_write ebp,signature,siglen 74 | test eax,eax 75 | js .error 76 | sys_close ebp 77 | xor eax,eax 78 | jmps .exit 79 | 80 | signature db "SWAPSPACE2" 81 | siglen equ $ - signature 82 | error db "i/o error.", __n 83 | errlen equ $ - error 84 | 85 | END 86 | -------------------------------------------------------------------------------- /src/sync.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 1999-2000 Konstantin Boldyshev 2 | ; 3 | ;$Id: sync.asm,v 1.2 2000/02/10 15:07:04 konst Exp $ 4 | ; 5 | ;hackers' sync 6 | ; 7 | ;0.01: 05-Jun-1999 initial release 8 | ;0.02: 17-Jun-1999 size improvements 9 | ;0.03: 07-Feb-2000 portable way :) 10 | ; 11 | ;syntax: sync 12 | 13 | %include "system.inc" 14 | 15 | CODESEG 16 | 17 | START: 18 | sys_sync 19 | sys_exit eax 20 | 21 | END 22 | -------------------------------------------------------------------------------- /src/sysctl.asm: -------------------------------------------------------------------------------- 1 | ; Copyright (C) 2002 Thomas M. Ogrisegg 2 | ; 3 | ; $Id: sysctl.asm,v 1.1 2002/02/14 17:46:22 konst Exp $ 4 | ; 5 | ; sysctl - configure kernel parameters at runtime 6 | ; 7 | ; syntax: 8 | ; sysctl [-n] [-w variable=value] [-p filename] 9 | ; 10 | ; License : GNU General Public License 11 | ; Author : Thomas Ogrisegg 12 | ; E-Mail : tom@rhadamanthys.org 13 | ; Version : 0.7 14 | ; SUSV2-Compliant : not in SUSV2 15 | ; GNU-compatible : not yet 16 | ; 17 | 18 | %include "system.inc" 19 | 20 | %assign BUF_SIZE 0xf000 21 | 22 | CODESEG 23 | 24 | START: 25 | pop ecx 26 | dec ecx 27 | jz near _exit 28 | sys_chdir proc_sys 29 | pop esi 30 | xor ebp, ebp 31 | 32 | argv_loop: 33 | pop esi 34 | or esi, esi 35 | jz near _exit 36 | xor ecx, ecx 37 | lodsb 38 | cmp al, '-' 39 | jnz near show_value 40 | lodsb 41 | cmp al, 'n' 42 | jz add_n 43 | cmp al, 'w' 44 | jz near set_value 45 | cmp al, 'p' 46 | jz read_config 47 | opt_error: 48 | sys_write STDOUT, uo, ul 49 | sys_exit 0x1 50 | 51 | uo db "Unknown option", __n 52 | ul equ $ - uo 53 | 54 | add_n: inc ebp 55 | jmp argv_loop 56 | 57 | read_config: 58 | pop esi 59 | or esi, esi 60 | jz .Lopen_other 61 | sys_open esi, O_RDONLY 62 | jmp .Lnext 63 | .Lopen_other: 64 | sys_open syscconf, O_RDONLY 65 | .Lnext: 66 | mov edx, eax 67 | push edx 68 | sys_lseek eax, 0, SEEK_END 69 | or eax, eax 70 | js near _error 71 | pop edx 72 | sys_mmap NULL, eax, PROT_READ | PROT_WRITE, MAP_PRIVATE, edx, 0x0 73 | or eax, eax 74 | js near _error 75 | mov esi, eax 76 | .Lcheck_loop: 77 | lodsb 78 | cmp al, ';' 79 | jz .Lnext_line 80 | cmp al, '#' 81 | jz .Lnext_line 82 | or al, al 83 | jz .Lexit 84 | cmp al, ' ' 85 | jng .Lcheck_loop 86 | jmp .Lout 87 | .Lnext_line: 88 | lodsb 89 | or al, al 90 | jz .Lout 91 | cmp al, __n 92 | jnz .Lnext_line 93 | jmp .Lcheck_loop 94 | .Lout: 95 | dec esi 96 | mov edi, buffer 97 | call do_next_value 98 | jmp .Lcheck_loop 99 | .Lexit: 100 | sys_exit 0x0 101 | 102 | set_value: 103 | pop esi 104 | or esi, esi 105 | jz near _exit 106 | mov edi, buffer 107 | do_next_value: 108 | lodsb 109 | cmp al, '.' 110 | jz .Lstos_slash 111 | cmp al, '=' 112 | jz .Lnext 113 | cmp al, ' ' 114 | jng .Lnext 115 | stosb 116 | or al, al 117 | jnz do_next_value 118 | jmp opt_error 119 | .Lstos_slash: 120 | mov al, '/' 121 | stosb 122 | jmp do_next_value 123 | .Lnext: 124 | dec esi 125 | xor eax, eax 126 | stosb 127 | .Lnext1: 128 | lodsb 129 | or al, al 130 | jz near .Lout 131 | cmp al, '=' 132 | jnz .Lnext1 133 | 134 | .Lnext1_half: 135 | lodsb 136 | cmp al, ' ' 137 | jng .Lnext1_half 138 | 139 | dec esi 140 | mov ecx, edi 141 | xor edx, edx 142 | .Lnext2: 143 | lodsb 144 | inc edx 145 | cmp al, ' ' 146 | jng .Lnext3 147 | cmp al, ';' 148 | jz .Lnext3 149 | cmp al, '#' 150 | jz .Lnext3 151 | stosb 152 | jmp .Lnext2 153 | .Lnext3: 154 | xor eax, eax 155 | stosb 156 | push ecx 157 | sys_open buffer, O_RDWR 158 | or eax, eax 159 | jns .Lall_rights 160 | sys_write STDOUT, noperm, nopermlen 161 | .Lall_rights: 162 | pop ecx 163 | dec edx 164 | sys_write eax, ecx, edx 165 | .Lout: 166 | jmp argv_loop 167 | 168 | show_value: 169 | dec esi 170 | mov edi, buffer 171 | .Lcopy_loop: 172 | lodsb 173 | cmp al, '.' 174 | jz .Lstos_slash 175 | stosb 176 | or al, al 177 | jnz .Lcopy_loop 178 | jmp .Lnext 179 | .Lstos_slash: 180 | mov al, '/' 181 | stosb 182 | jmp .Lcopy_loop 183 | .Lnext: 184 | sys_open buffer, O_RDONLY 185 | or eax, eax 186 | js _error 187 | sys_read eax, buffer, BUF_SIZE 188 | sys_write STDOUT, buffer, eax 189 | sys_exit 0x0 190 | 191 | _error: 192 | sys_exit 0x1 193 | 194 | _exit: 195 | sys_exit 0xff 196 | 197 | proc_sys db "/proc/sys/", EOL 198 | syscconf db "/etc/sysctl.conf", EOL 199 | 200 | ig db " = " 201 | 202 | noperm db "Could not write to key", __n, EOL 203 | nopermlen equ $ - noperm 204 | 205 | UDATASEG 206 | buffer UCHAR BUF_SIZE 207 | END 208 | -------------------------------------------------------------------------------- /src/tail.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 2001 Jani Monoses 2 | ; 3 | ;$Id: tail.asm,v 1.5 2002/08/15 16:08:33 konst Exp $ 4 | ; 5 | ;hackers' tail 6 | ; 7 | ;syntax: tail [-n lines] [FILE] 8 | ; tail -n CHARSc [FILE] 9 | ; 10 | ;Revision history: 11 | ; 0.1 Initial revision (JM) 12 | ; 0.2 Added support for -n CHARSc (JH) 13 | 14 | %include "system.inc" 15 | 16 | %assign BUFSIZE 0x4000 ;16K - max guarranteed size of tail 17 | 18 | CODESEG 19 | START: 20 | mov esi, $ + 1 ; important! esi must be readable 21 | mov byte [lines],10 ;default line count 22 | _mov ebp,STDIN ;default input file 23 | pop ecx ;argc 24 | dec ecx 25 | jz .go ;if no args assume defaults 26 | pop ebx 27 | pop ebx 28 | ; cmp byte[ebx],'+' ; tail+ (maybe later... ) 29 | ; je plus ; if someone wants to implement this 30 | cmp byte[ebx],"-" ; Not an option 31 | jne .file 32 | mov esi, ebx 33 | inc esi 34 | cmp byte[esi],"n" ;option or filename? 35 | jne .firstchar 36 | pop esi ;line count 37 | 38 | ;put line count from ascii representation in ebx 39 | .firstchar: 40 | xor ebx,ebx 41 | xor eax,eax 42 | .nextchar: 43 | lodsb 44 | sub al,'0' 45 | jb .endconvert 46 | cmp al, 9 47 | jg .endconvert 48 | imul ebx,byte 10 49 | add ebx,eax 50 | jmp short .nextchar 51 | .endconvert: 52 | mov [lines],ebx 53 | ; dec ecx ;eat two args 54 | ; dec ecx 55 | ; jz .go ;no file name: assume STDIN 56 | pop ebx ;file name (last argument) 57 | or ebx, ebx 58 | jz .go ;no file name: assume STDIN 59 | .file: 60 | sys_open ebx,O_RDONLY 61 | test eax,eax 62 | js near dexit 63 | mov ebp,eax ;save file descriptor 64 | 65 | ;if regular file seek to last BUFSIZE bytes.Especially good for large files. 66 | .go: 67 | sys_fstat ebp,statbuf 68 | test dword[statbuf.st_mode],S_IFREG 69 | jz .gogo ;if !regular file 70 | mov ebx,[statbuf.st_size] 71 | sub ebx,BUFSIZE 72 | jbe .gogo ;or size < BUFSIZE 73 | sys_lseek ebp,ebx,SEEK_SET 74 | .gogo: ;just read 75 | mov ecx,buf 76 | dec esi 77 | cmp [esi], byte 'c' 78 | je tailchar 79 | 80 | ;reads the input in BUFSIZE sized chunks 81 | ;and moves the buffers to prevent overflow 82 | .readinput: 83 | sys_read ebp,ecx,BUFSIZE 84 | test eax,eax 85 | js dexit 86 | jz writebuffer 87 | add ecx,eax 88 | cmp ecx,safety 89 | jle .readinput 90 | push dword .readinput ; False call! 91 | 92 | bufcopy: 93 | push ecx 94 | mov edi,buf 95 | mov esi,buf2 96 | sub ecx,esi 97 | rep movsb 98 | pop ecx 99 | sub ecx,BUFSIZE 100 | ret 101 | 102 | dexit: 103 | sys_exit 104 | 105 | ;walk through the buffer from end to beginning and stop 106 | ;when enough newlines are encountered 107 | writebuffer: 108 | cmp ecx,buf 109 | jz dexit 110 | mov edx,ecx 111 | mov ebx,[lines] 112 | inc ebx 113 | dec ecx 114 | 115 | .nl: 116 | dec ebx 117 | jz .tail 118 | .searchnl: 119 | dec ecx 120 | cmp ecx,buf ;start of buffer reached? 121 | jz .endbuf 122 | cmp byte[ecx],10 ;is it a newline char ? 123 | jz .nl 124 | jmp short .searchnl 125 | .tail: 126 | inc ecx 127 | .endbuf: 128 | sub edx,ecx 129 | sys_write STDOUT,ecx,edx 130 | jmps dexit 131 | 132 | ;read from the buffer to find the last [lines] bytes 133 | tailchar: 134 | mov ecx, buf 135 | mov ebx, ebp 136 | _mov edx, BUFSIZE 137 | .read: 138 | sys_read 139 | or eax, eax 140 | js dexit 141 | jz .write 142 | add ecx, eax 143 | cmp ecx, safety 144 | jb .read 145 | call bufcopy 146 | jmps .read 147 | 148 | .write: 149 | mov edx, [lines] 150 | sub ecx, edx ; ECX = read back 151 | mov eax, buf ; EAX = start of buffer 152 | cmp ecx, eax ; Check for undeflow 153 | jnb .wwrite 154 | xchg eax, ecx ; ECX = start of buffer 155 | sub eax, ecx ; EAX = -underflowsize 156 | add edx, eax ; output size to total buf size 157 | .wwrite: 158 | sys_write STDOUT 159 | jmp dexit 160 | 161 | UDATASEG 162 | lines resd 1 163 | buf resb BUFSIZE 164 | buf2 resb BUFSIZE 165 | safety resb BUFSIZE 166 | statbuf B_STRUC Stat,.st_mode,.st_size 167 | END 168 | -------------------------------------------------------------------------------- /src/tee.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 1999 Konstantin Boldyshev 2 | ; 3 | ;$Id: tee.asm,v 1.6 2002/02/02 08:49:25 konst Exp $ 4 | ; 5 | ;hackers' tee [GNU replacement] 6 | ; 7 | ;syntax: tee [-ai] [file...] 8 | ; 9 | ;-a append to files instead of overwriting 10 | ;-i ignore interrupt signals 11 | ; 12 | ;returns error count 13 | ; 14 | ;Note that this tee can handle about 1000 specified files only, 15 | ;however it is more than enough. 16 | ; 17 | ;0.01: 04-Jul-1999 initial release 18 | ;0.02: 27-Jul-1999 files are created with permissions of 664 19 | ;0.03: 20-Aug-2000 "-i" bugfix, sys_sigaction instead of sys_signal (TH) 20 | 21 | %include "system.inc" 22 | 23 | %assign BUFSIZE 0x2000 24 | 25 | CODESEG 26 | 27 | ;ebp - return code 28 | 29 | START: 30 | mov edi,handles 31 | xor ebp,ebp 32 | 33 | pop ebx 34 | dec ebx 35 | pop ebx 36 | jz open_done ;if no args - write to STDOUT only 37 | 38 | _mov ecx,O_CREAT|O_WRONLY|O_TRUNC 39 | pop ebx 40 | mov esi,ebx 41 | lodsb 42 | cmp al,'-' 43 | jnz open_2 44 | .scan: 45 | lodsb 46 | or al,al 47 | jz open_files 48 | cmp al,'a' 49 | jnz .i 50 | _mov ecx,O_CREAT|O_WRONLY|O_APPEND 51 | jmps .scan 52 | .i: 53 | cmp al,'i' 54 | jnz near do_exit 55 | push ecx 56 | sys_sigaction SIGPIPE,sa_struct,NULL ;sys_signal SIGPIPE,SIG_IGN 57 | sys_sigaction SIGINT ;sys_signal SIGINT 58 | pop ecx 59 | jmps .scan 60 | 61 | open_files: 62 | pop ebx ;pop filename pointer 63 | or ebx,ebx 64 | jz open_done ;exit if no more agrs 65 | open_2: 66 | sys_open EMPTY,EMPTY,664q 67 | test eax,eax 68 | jns open_ok 69 | inc ebp 70 | jmps open_files 71 | open_ok: 72 | stosd 73 | jmps open_files 74 | 75 | open_done: 76 | xor eax,eax 77 | stosd 78 | read_loop: 79 | sys_read STDIN,buf,BUFSIZE 80 | test eax,eax 81 | js read_error 82 | jz close 83 | sys_write STDOUT,EMPTY,eax ;write to STDOUT 84 | 85 | mov esi,handles 86 | .write_loop: 87 | lodsd 88 | or eax,eax 89 | jz read_loop 90 | sys_write eax 91 | jmps .write_loop 92 | read_error: 93 | inc ebp 94 | 95 | close: 96 | ; mov esi,handles 97 | ;.close_loop: 98 | ; lodsd 99 | ; or eax,eax 100 | ; jz do_exit 101 | ; sys_close eax 102 | ; jmp short .close_loop 103 | 104 | do_exit: 105 | sys_exit ebp 106 | 107 | ;dirty hack which works in our case 108 | sa_struct dd SIG_IGN,0,0,0 109 | 110 | UDATASEG 111 | 112 | buf resb BUFSIZE 113 | 114 | ;well, here is our malloc() :-) 115 | handles resd 1 116 | 117 | END 118 | -------------------------------------------------------------------------------- /src/touch.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 2000 Jonathan Leto 2 | ; 3 | ;$Id: touch.asm,v 1.5 2002/02/02 12:33:38 konst Exp $ 4 | ; 5 | ;hackers' touch 6 | ; 7 | ;syntax: touch [-c] file [file] ... 8 | ; 9 | ; All comments/feedback welcome. 10 | ; 11 | ;0.01: 20-Dec-2000 initial release 12 | ;0.02: 02-Feb-2002 various fixes and improvements (KB) 13 | 14 | %include "system.inc" 15 | 16 | CODESEG 17 | 18 | do_exit: 19 | sys_exit 0 20 | 21 | START: 22 | pop eax 23 | pop eax 24 | xor edi,edi ;-c flag 25 | dec edi 26 | .next0: 27 | inc edi 28 | .next: 29 | pop eax 30 | or eax,eax 31 | jz do_exit 32 | 33 | .continue: 34 | cmp word [eax],'-c' 35 | jz .next0 36 | .create: 37 | mov ebp,eax 38 | test eax,eax 39 | jns .touchfile 40 | 41 | or edi,edi 42 | jnz .touchfile 43 | 44 | ; create new file 45 | sys_open ebp,O_RDWR|O_CREAT,0666q 46 | 47 | .touchfile: 48 | %ifdef __BSD__ 49 | sys_utimes ebp,NULL 50 | %else 51 | sys_utime ebp,NULL 52 | %endif 53 | 54 | jmps .next 55 | 56 | END 57 | -------------------------------------------------------------------------------- /src/true.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) Indrek Mandre 2 | ; 3 | ;$Id: true.asm,v 1.6 2002/03/07 06:16:39 konst Exp $ 4 | ; 5 | ;hackers' true/false 6 | ; 7 | ;syntax: true 8 | ; false 9 | ; 10 | ;0.01: 17-Jun-1999 initial release 11 | ;0.02: 04-Jul-1999 fixed bug with 2.0 kernel (KB) 12 | ;0.03: 20-Sep-1999 size improvements (KB) 13 | ;0.04: 05-Jan-2001 even more size improvements ;) (KB) 14 | ;0.05 29-Aug-2001 even more, more size improvements ;)) [two bytes] (RM) 15 | 16 | %include "system.inc" 17 | 18 | CODESEG 19 | 20 | START: 21 | pop esi 22 | pop esi 23 | .n1: ; how we are called? 24 | lodsb 25 | or al,al 26 | jnz .n1 27 | xor ebx,ebx 28 | shr byte [esi-5],1 29 | rcl ebx,1 30 | ; cmp byte [esi-5],'t' 31 | ; jz .exit 32 | ; inc ebx 33 | .exit: 34 | sys_exit 35 | 36 | END 37 | -------------------------------------------------------------------------------- /src/tty.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 2000 Konstantin Boldyshev 2 | ; 3 | ;$Id: tty.asm,v 1.2 2002/02/02 08:49:25 konst Exp $ 4 | ; 5 | ;hackers' tty 6 | ; 7 | ;syntax: tty 8 | ; 9 | ;0.01: 21-Mar-2000 initial release 10 | 11 | %include "system.inc" 12 | 13 | %assign BUFSIZE 0x1000 14 | 15 | CODESEG 16 | 17 | START: 18 | sys_readlink fd0, buf, BUFSIZE 19 | test eax,eax 20 | js do_exit 21 | 22 | inc eax 23 | mov edx,eax 24 | mov esi,ecx 25 | .next: 26 | lodsb 27 | or al,al 28 | jnz .next 29 | mov byte [esi-1],__n 30 | 31 | sys_write STDOUT 32 | 33 | do_exit: 34 | sys_exit eax 35 | 36 | fd0 db "/proc/self/fd/0" ;,EOL 37 | 38 | UDATASEG 39 | 40 | buf resb BUFSIZE 41 | 42 | END 43 | -------------------------------------------------------------------------------- /src/uname.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 1999-2001 Konstantin Boldyshev 2 | ; 3 | ;$Id: uname.asm,v 1.9 2002/02/02 08:49:25 konst Exp $ 4 | ; 5 | ;hackers' uname/arch [GNU replacement] 6 | ; 7 | ;syntax: uname [-snrvma] 8 | ; arch (same as uname -m) 9 | ; 10 | ;-s os name (default) 11 | ;-n network nodename 12 | ;-r os release 13 | ;-v os version 14 | ;-m machine (hardware) type 15 | ;-p processor (supported only in sysctl based version) 16 | ;-a all the above information 17 | ; 18 | ;0.01: 17-Jun-1999 initial release 19 | ;0.02: 03-Jul-1999 arch support 20 | ;0.03: 18-Sep-1999 elf macros support 21 | ;0.04: 03-Sep-2000 portable utsname 22 | ;0.05: 22-Oct-2000 sysctl based part (TH), 23 | ; size improvemets (KB) 24 | ;0.06: 04-Mar-2001 use B_STRUC (KB) 25 | ;0.07: 03-Dec-2001 various sysctl fixes on BSD (KB) 26 | 27 | %include "system.inc" 28 | 29 | %ifdef __BSD__ 30 | %define USE_SYSCTL 31 | %endif 32 | 33 | %assign SYSNAME 00000001b 34 | %assign NODENAME 00000010b 35 | %assign RELEASE 00000100b 36 | %assign VERSION 00001000b 37 | %assign MACHINE 00010000b 38 | %assign PROCESSOR 00100000b 39 | 40 | %ifdef USE_SYSCTL 41 | %assign BUF_LEN 128 42 | %assign ARGC 6 43 | %else 44 | %assign ARGC 5 45 | %endif 46 | 47 | CODESEG 48 | 49 | keys db "snrvmp" 50 | lf db __n 51 | 52 | ; 53 | ;edi - switches flag 54 | ; 55 | 56 | START: 57 | pop ebx 58 | pop esi 59 | dec ebx 60 | jnz args 61 | 62 | mov dl,SYSNAME ;default 63 | .n1: ;how we are called? 64 | lodsb 65 | or al,al 66 | jnz .n1 67 | cmp dword [esi-5],'arch' 68 | jnz get_uname 69 | mov dl,MACHINE ;we are called as arch 70 | jmps get_uname 71 | 72 | args: 73 | pop esi 74 | lodsb 75 | cmp al,'-' 76 | jnz near do_exit 77 | 78 | .inner_stage: 79 | lodsb 80 | or al,al 81 | jz .check 82 | .scan_other: 83 | _mov ecx,ARGC 84 | _mov edi,keys 85 | mov ebp,edi 86 | repnz scasb 87 | jnz .a 88 | dec edi 89 | sub edi,ebp 90 | mov ecx,edi 91 | bts edx,ecx 92 | jmps .inner_stage 93 | .a: 94 | cmp al,'a' 95 | jnz near do_exit 96 | mov dl,SYSNAME|NODENAME|RELEASE|VERSION|MACHINE|PROCESSOR 97 | jmps .inner_stage 98 | 99 | .check: 100 | or dl,dl 101 | jz near do_exit 102 | 103 | dec ebx 104 | jnz args 105 | 106 | get_uname: 107 | 108 | _mov ecx,ARGC 109 | mov edi,edx 110 | 111 | %ifdef USE_SYSCTL 112 | 113 | _mov ebp,req_start 114 | 115 | %else 116 | 117 | sys_uname h 118 | mov ebp,ebx 119 | 120 | %endif 121 | 122 | .printinfo: 123 | shr edi, 1 124 | jnc .skip 125 | 126 | push ecx 127 | 128 | mov ecx,space 129 | cmp [ecx],byte 0 130 | jz .first_entry 131 | sys_write STDOUT,space,1 132 | .first_entry: 133 | mov [ecx],byte 0x20 134 | 135 | %ifdef USE_SYSCTL 136 | 137 | mov dword [oldlenp], BUF_LEN 138 | pusha 139 | mov ebx,ebp 140 | sys_sysctl EMPTY, 2, buffer, oldlenp, 0, 0 141 | test eax,eax 142 | js .skip_write 143 | mov eax,[oldlenp] 144 | dec eax 145 | sys_write STDOUT, buffer, eax 146 | .skip_write: 147 | popa 148 | 149 | %else 150 | 151 | mov esi,ebp 152 | xor edx,edx 153 | .next: 154 | lodsb 155 | inc edx 156 | or al,al 157 | jnz .next 158 | sub esi,edx 159 | dec edx 160 | 161 | sys_write STDOUT,esi 162 | 163 | %endif 164 | 165 | pop ecx 166 | 167 | .skip: 168 | %ifdef USE_SYSCTL 169 | _add ebp,8 170 | %else 171 | _add ebp,SYS_NMLN 172 | %endif 173 | loop .printinfo 174 | 175 | do_exit: 176 | sys_write EMPTY, lf, 1 177 | sys_exit 0 178 | 179 | 180 | %ifdef USE_SYSCTL 181 | req_start: 182 | kern_ostype_req: 183 | dd CTL_KERN 184 | dd KERN_OSTYPE 185 | kern_hostname_req: 186 | dd CTL_KERN 187 | dd KERN_HOSTNAME 188 | kern_osrelease_req: 189 | dd CTL_KERN 190 | dd KERN_OSRELEASE 191 | kern_osversion_req: 192 | dd CTL_KERN 193 | dd KERN_VERSION 194 | hw_machine_req: 195 | dd CTL_HW 196 | dd HW_MACHINE 197 | hw_model_req: 198 | dd CTL_HW 199 | dd HW_MODEL 200 | req_end: 201 | %endif 202 | 203 | UDATASEG 204 | 205 | space resb 1 206 | 207 | %ifdef USE_SYSCTL 208 | 209 | oldlenp DWORD 1 210 | buffer CHAR BUF_LEN 211 | 212 | %else 213 | 214 | h B_STRUC utsname,.sysname,.nodename,.release,.version,.machine,.domainname 215 | 216 | %endif 217 | 218 | END 219 | -------------------------------------------------------------------------------- /src/update.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 1999-2001 Konstantin Boldyshev 2 | ; 3 | ;$Id: update.asm,v 1.6 2002/02/02 08:49:25 konst Exp $ 4 | ; 5 | ;hackers' update 6 | ; 7 | ;initial version was based on "updated" 8 | ;by Sander van Malssen 9 | ; 10 | ;syntax: update [PERIOD] 11 | ; 12 | ;PERIOD (in seconds) - flush period, if missing use default of 30 13 | ; 14 | ;example: update 15 | ; update 60 16 | ; 17 | ;0.01: 05-Jun-1999 initial release 18 | ;0.02: 17-Jun-1999 period parameter added 19 | ;0.03: 04-Jul-1999 fixed bug with 2.0 kernel,removed MAXPERIOD, 20 | ; sys_nanosleep instead of SIGALRM 21 | ;0.04: 18-Sep-1999 elf macros support 22 | ;0.05: 22-Jan-2001 minor size improvement 23 | 24 | %include "system.inc" 25 | 26 | %assign PERIOD 30 ;default flush interval in seconds 27 | 28 | CODESEG 29 | 30 | ;ebp - flush period 31 | 32 | START: 33 | _mov ebp,PERIOD 34 | pop esi 35 | dec esi 36 | jz .start 37 | pop esi 38 | pop esi 39 | 40 | ;convert string to integer 41 | 42 | xor eax,eax 43 | xor ebx,ebx 44 | .next_digit: 45 | lodsb 46 | sub al,'0' 47 | jb .done 48 | cmp al,9 49 | ja .done 50 | imul ebx,byte 10 51 | add ebx,eax 52 | jmps .next_digit 53 | .done: 54 | or ebx,ebx ;this check can be removed if sure 55 | jz .start 56 | mov ebp,ebx 57 | .start: 58 | mov [t.tv_sec],ebp 59 | sys_fork 60 | test eax,eax 61 | jz .child 62 | sys_exit 63 | 64 | .child: 65 | sys_bdflush 1,0 66 | sys_nanosleep t ;,NULL 67 | jmps .child 68 | 69 | UDATASEG 70 | 71 | t B_STRUC timespec,.tv_sec 72 | 73 | END 74 | -------------------------------------------------------------------------------- /src/uptime.asm: -------------------------------------------------------------------------------- 1 | ; Copyright (c) 2002 Thomas M. Ogrisegg 2 | ; 3 | ; uptime - show system uptime 4 | ; 5 | ; syntax: 6 | ; uptime 7 | ; 8 | ; License : GNU General Public License 9 | ; Author : Thomas Ogrisegg 10 | ; E-Mail : tom@rhadamanthys.org 11 | ; Version : 1.0 12 | ; SuSV2-Compliant : not in SUSV2 (why?) 13 | ; GNU-compatible : yes 14 | ; 15 | ; $Id: uptime.asm,v 1.2 2002/06/11 08:45:10 konst Exp $ 16 | 17 | %include "system.inc" 18 | 19 | CODESEG 20 | 21 | %assign UTMP_RECSIZE utmp_size 22 | 23 | %macro mdiv 1 24 | xor edx, edx 25 | _mov ebx, %1 26 | idiv ebx 27 | %endmacro 28 | 29 | ltostr1: 30 | xor edx, edx 31 | _mov ebx, 0xa 32 | idiv ebx 33 | or eax, eax 34 | jz .Lnext 35 | add al, '0' 36 | stosb 37 | .Lnext: 38 | lea eax, [edx+'0'] 39 | stosb 40 | ret 41 | 42 | ltostr2: 43 | xor edx, edx 44 | _mov ebx, 0xa 45 | idiv ebx 46 | add al, '0' 47 | stosb 48 | lea eax, [edx+'0'] 49 | stosb 50 | ret 51 | 52 | average: 53 | shr eax, 0x5 54 | _add eax, 0xa 55 | push eax 56 | sar eax, 0xb 57 | call ltostr1 58 | mov al, '.' 59 | stosb 60 | pop eax 61 | and eax, 0x7ff 62 | imul eax, eax, 100 63 | sar eax, 0xb 64 | call ltostr2 65 | ret 66 | 67 | START: 68 | mov ebx, esp 69 | sys_gettimeofday EMPTY, NULL 70 | mov eax, [ebx] 71 | mov edi, buf+1 72 | mov byte [edi-1], ' ' 73 | xor ebp, ebp 74 | mdiv 31536000 75 | mov eax, edx 76 | mdiv 86400 77 | mov eax, edx 78 | mdiv 3600 79 | cmp eax, 0xc 80 | jng .pm 81 | sub eax, 0xc 82 | inc ebp 83 | .pm: 84 | push edx 85 | call ltostr1 86 | mov al, ':' 87 | stosb 88 | pop eax 89 | mdiv 60 90 | call ltostr2 91 | or ebp, ebp 92 | mov ax, 'am' 93 | jz .Lam 94 | mov ax, 'pm' 95 | .Lam: 96 | stosw 97 | mov eax, ' up' 98 | stosd 99 | mov ax, ' ' 100 | stosw 101 | mov ebx, esp 102 | sys_sysinfo 103 | mov eax, [ebx] ; uptime 104 | mdiv 31536000 105 | mov eax, edx 106 | mdiv 86400 107 | push edx 108 | or eax, eax 109 | jz .Lnext2 110 | call ltostr1 111 | mov eax, ' day' 112 | stosd 113 | mov eax, 's, ' 114 | stosd 115 | .Lnext2: 116 | pop eax 117 | mdiv 3600 118 | push edx 119 | call ltostr1 120 | mov al, ':' 121 | stosb 122 | pop eax 123 | mdiv 60 124 | call ltostr2 125 | mov ax, ', ' 126 | stosw 127 | xor ebp, ebp 128 | sys_open utmpfile, O_RDONLY 129 | or eax, eax 130 | js .Lno_utmp 131 | mov [ufd], eax 132 | sub esp, UTMP_RECSIZE 133 | .Lread_next: 134 | mov ecx, esp 135 | sys_read [ufd], EMPTY, UTMP_RECSIZE 136 | cmp long [esp+utmp.ut_type], USER_PROCESS 137 | jnz .Lnext 138 | inc ebp 139 | .Lnext: 140 | or eax, eax 141 | jnz .Lread_next 142 | .Lno_utmp: 143 | add esp, UTMP_RECSIZE 144 | mov eax, ebp 145 | call ltostr1 146 | mov long [edi+0x00], ' use' 147 | mov long [edi+0x04], 'rs, ' 148 | mov long [edi+0x08], 'load' 149 | mov long [edi+0x0c], ' ave' 150 | mov long [edi+0x10], 'rage' 151 | mov word [edi+0x15], ': ' 152 | add edi, 0x17 153 | mov eax, [esp+sysinfo.loads] 154 | call average 155 | mov ax, ', ' 156 | stosw 157 | mov eax, [esp+sysinfo.loads+4] 158 | call average 159 | mov ax, ', ' 160 | stosw 161 | mov eax, [esp+sysinfo.loads+8] 162 | call average 163 | mov al, __n 164 | stosb 165 | sys_write STDOUT, buf, 80 166 | sys_exit eax 167 | 168 | utmpfile db _PATH_UTMP, EOL 169 | 170 | UDATASEG 171 | 172 | buf UCHAR 80 173 | ufd ULONG 1 174 | 175 | END 176 | -------------------------------------------------------------------------------- /src/users.asm: -------------------------------------------------------------------------------- 1 | ; Copyright (C) 2003 Jorge Contreras A. 2 | ; 3 | ; $Id: users.asm,v 1.1 2006/02/09 07:56:56 konst Exp $ 4 | ; 5 | ; hackers` users v0.1 26/02/2003 21:00 6 | ; 7 | ; Programmer : Jorge Contreras A. (X3r0r) 8 | ; License : GNU General Public License. 9 | ; syntax : users [utmp file] 10 | ; Arguments are not obligatories. 11 | ; Description: Output who is currently logged in according utmp file. 12 | ; Note : Sorry for my poor english. 13 | ; Country : Chile 14 | ; Bugs : Maybe a lot.. :( 15 | 16 | %include "system.inc" 17 | 18 | %define ENDL 0x0a 19 | %define EOL 0x0 20 | 21 | CODESEG 22 | START: 23 | pop ebx 24 | dec bl 25 | dec bl 26 | jz use_args 27 | _mov edx, utmp_path 28 | jmp near ok 29 | use_args: 30 | pop edx 31 | pop edx 32 | ok: 33 | sys_open edx, O_RDONLY 34 | push eax ;; The Descriptor into the Stack. 35 | inc eax 36 | inc eax 37 | jz end 38 | read_entries: 39 | sys_read [esp], utmpbuf, utmp_size ;; We won some bytes. :) 40 | test eax, eax 41 | jz entries_done 42 | xor byte [utmpbuf.ut_type], USER_PROCESS 43 | jnz read_entries 44 | sys_write STDOUT, utmpbuf.ut_user, UT_NAMESIZE 45 | sys_write STDOUT, space, 1 46 | jmp near read_entries 47 | entries_done: 48 | sys_write STDOUT, newline, 1 49 | end: 50 | sys_close [esp] 51 | sys_exit 0 52 | 53 | ; Strings are here... 54 | 55 | utmp_path db _PATH_UTMP, EOL 56 | space db " " 57 | newline db ENDL 58 | 59 | UDATASEG 60 | utmpbuf B_STRUC utmp,.ut_type,.ut_user 61 | END 62 | -------------------------------------------------------------------------------- /src/watch.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 2001 Rudolf Marek , 2 | ; 3 | ;$Id: watch.asm,v 1.2 2001/09/24 16:49:19 konst Exp $ 4 | ; 5 | ;hackers' watch 6 | ; 7 | ;syntax: watch -n [sec] --interval=[sec] filename_to_execute its_args 8 | ; 9 | ;0.01: 16-Sep-2001 initial release 10 | ; 11 | ;NOTE: welcome to a stack-magic world :) 12 | 13 | %include "system.inc" 14 | 15 | %assign DEFAULT_SLEEP 2 16 | 17 | CODESEG 18 | 19 | 20 | START: 21 | pop esi 22 | pop esi 23 | pop eax 24 | or eax,eax 25 | jz near .help 26 | xchg eax,ebp 27 | sys_write STDOUT,erase_screen,4 28 | xchg ebp,ebx 29 | cmp word [ebx],'-n' 30 | jz near .interval_change 31 | cmp dword [ebx],'--in' 32 | jz near .separate_interval 33 | ; xor ebp,ebp ;put there a default 34 | ; inc ebp 35 | ; inc ebp 36 | push byte DEFAULT_SLEEP 37 | pop ebp 38 | .args_done: 39 | push ebx 40 | mov ecx,esp 41 | mov esi,esp 42 | .find_env: 43 | lodsd 44 | or eax,eax 45 | jnz .find_env 46 | ;esi start of env ecx start of args, ebx filename 47 | push ebx 48 | push ecx 49 | push esi 50 | .fork_it: 51 | pop edx 52 | pop ecx 53 | pop ebx 54 | sys_fork 55 | test eax,eax 56 | jnz .wait 57 | sys_execve EMPTY,EMPTY,EMPTY 58 | jmp .error 59 | .wait: 60 | push ebx 61 | push ecx 62 | push edx 63 | sys_wait4 0xffffffff,NULL,NULL,NULL ;Wait utill child die ... 64 | mov edi,esp 65 | push byte 0 66 | push ebp 67 | mov esi,esp 68 | push byte 0 69 | push byte 0 70 | mov ecx,esp 71 | sys_nanosleep esi,EMPTY 72 | mov esp,edi 73 | sys_write STDOUT,erase_screen,4 74 | jmp .fork_it 75 | 76 | .interval_change: 77 | pop esi 78 | call .atoi 79 | pop ebx 80 | jmp .args_done 81 | .separate_interval: 82 | xchg ebx,esi 83 | .find_eq: 84 | lodsb 85 | or al,al 86 | jz .error 87 | cmp al,'=' 88 | jnz .find_eq 89 | call .atoi 90 | pop ebx 91 | jmp .args_done 92 | 93 | .help: sys_write STDOUT,help,help_len 94 | jmps .exit 95 | .error: sys_write STDOUT,error,error_len 96 | .exit: sys_exit 255 97 | 98 | .atoi: ; 'borrowed' from mknod.asm, which has (had?) been borrowed from jonathan leto's chown :-)) 99 | xor eax,eax 100 | xor ebp,ebp 101 | .next: 102 | lodsb ; argument is in esi 103 | test al,al 104 | jz .done 105 | sub al,'0' 106 | imul ebp,10 107 | add ebp,eax 108 | jmps .next 109 | .done: 110 | ret ; return value is in ebp 111 | 112 | erase_screen db 0x1b,"[2J" 113 | help db "watch [args] exec_name exec_args - exec a program periodically, showing output",__n 114 | db "fullscreen. By default, the prog. is run every 2 sec; use -n or --interval=",__n 115 | db "to specify a different interval.",__n 116 | help_len equ $-help 117 | error db "Execve failed ...",__n 118 | error_len equ $-error 119 | 120 | END 121 | -------------------------------------------------------------------------------- /src/wget.asm: -------------------------------------------------------------------------------- 1 | ; Copyright (c) 2002 Thomas M. Ogrisegg 2 | ; 3 | ; wget - HTTP client 4 | ; 5 | ; syntax: 6 | ; wget ip-address remote-filename 7 | ; 8 | ; License : GNU General Public License 9 | ; Author : Thomas Ogrisegg 10 | ; E-Mail : tom@rhadamanthys.org 11 | ; Version : 0.3 12 | ; Created : 03/16/02 13 | ; SUSV2-compliant : not in SUSV2 14 | ; GNU-compatible : no 15 | ; 16 | ; TODO: Add resume support, more options, DNS-resolver, ftp-client 17 | ; and URL-parsing 18 | ; 19 | ; $Id: wget.asm,v 1.2 2002/06/16 14:19:58 konst Exp $ 20 | 21 | %include "system.inc" 22 | 23 | %assign BUF_SIZ 0x2000 ; Tune this to improve performance 24 | 25 | CODESEG 26 | 27 | START: 28 | pop ecx 29 | pop esi 30 | pop esi 31 | pop ebp 32 | cmp ecx,byte 3 33 | jne near .exit 34 | sys_socket AF_INET, SOCK_STREAM, IPPROTO_TCP 35 | test eax, eax 36 | js near .exit 37 | mov [sockfd], eax 38 | push word 0x5000 ; port 80 (big-endian) 39 | push word AF_INET 40 | mov edi, esp 41 | call ip2int 42 | sys_connect [sockfd], edi, 0x10 43 | test eax, eax 44 | jnz near .exit 45 | mov esi, ebp 46 | sub esp, BUF_SIZ 47 | mov long [esp], 'GET ' 48 | lea edi, [esp+4] 49 | xor ecx, ecx 50 | mov al, '/' 51 | .Lstrcpy: 52 | inc ecx 53 | stosb 54 | lodsb 55 | or al, al 56 | jnz .Lstrcpy 57 | mov al, ' ' 58 | stosb 59 | mov long [edi], 'HTTP' 60 | mov long [edi+4], '/1.0' 61 | mov long [edi+8], 0xa0d0a0d 62 | add ecx, 0x11 63 | sys_write [sockfd], esp, ecx 64 | sys_read [sockfd], esp, BUF_SIZ 65 | cmp long [esp], 'HTTP' 66 | jnz .exit 67 | cmp long [esp+9], '200 ' 68 | jnz .exit 69 | mov edi, esp 70 | mov ecx, eax 71 | mov edx, eax 72 | mov al, __r 73 | .Lloop: 74 | repnz scasb 75 | or ecx, ecx 76 | jz .exit 77 | cmp word [edi-1], 0xa0a 78 | jz .open 79 | cmp long [edi-1], 0xa0d0a0d 80 | jnz .Lloop 81 | .open: 82 | add edi, 0x3 83 | push ecx 84 | sys_open ebp, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR 85 | test eax, eax 86 | js .exit 87 | mov [destfd], eax 88 | pop eax 89 | sub eax, 0x3 90 | .Lnloop: 91 | sys_write [destfd], edi, eax 92 | mov edi, esp 93 | sys_read [sockfd], edi, BUF_SIZ 94 | or eax, eax 95 | jnz .Lnloop 96 | .exit: 97 | sys_exit 0x0 98 | 99 | ;; stolen copied from ping.asm 100 | ip2int: 101 | xor eax,eax 102 | xor edx,edx 103 | xor ecx,ecx 104 | .cc: 105 | xor ebx,ebx 106 | .c: 107 | mov al,[esi+edx] 108 | inc edx 109 | sub al,'0' 110 | jb .next 111 | imul ebx,byte 10 112 | add ebx,eax 113 | jmp .c 114 | .next: 115 | mov [edi+ecx+4],bl 116 | inc ecx 117 | cmp ecx, byte 4 118 | jne .cc 119 | ret 120 | 121 | UDATASEG 122 | sockfd LONG 1 123 | destfd LONG 1 124 | END 125 | -------------------------------------------------------------------------------- /src/which.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 2001 by Joshua Hudson 2 | ; 3 | ;$Id: which.asm,v 1.5 2002/02/02 08:49:25 konst Exp $ 4 | ; 5 | ;hacker's which 6 | ; 7 | ;usage: which command [command ...] 8 | ; 9 | ;fails when uid != euid 10 | 11 | %include "system.inc" 12 | 13 | CODESEG 14 | 15 | START: 16 | 17 | ;*** Find PATH= in environment (most code from env.asm) 18 | pop ebp 19 | mov edx, ebp 20 | xor eax, eax ; [found] = 1, error 21 | inc eax 22 | mov [found], eax 23 | .env: 24 | inc ebp 25 | mov esi, [esp + ebp * 4] 26 | or esi, esi 27 | jz .lastpath ; If no PATH, everything must have / 28 | cmp [esi], dword 'PATH' ; Is this the PATH= environ 29 | jne .env 30 | cmp [esi+4], byte '=' 31 | jne .env 32 | 33 | ;**** Found PATH=, now parse 34 | mov ebp, edx 35 | add esi, 5 36 | mov ebx, pathptr 37 | mov cl, 64 38 | .nextpath: 39 | mov al, [esi] 40 | or al, al 41 | jz .lastpath 42 | cmp al, ':' ; Skip blank entries 43 | jne .notempty 44 | inc esi 45 | jmp .nextpath 46 | .notempty: 47 | mov [ebx], esi ; Index entries 48 | add ebx, byte 4 49 | .nextposn: 50 | inc esi ; Block off entries 51 | mov al, [esi] 52 | or al, al 53 | jz .lastpath 54 | cmp al, ':' 55 | jne .nextposn 56 | mov [esi], byte 0 57 | inc esi 58 | dec cl 59 | jnz .nextpath 60 | .lastpath: 61 | pop eax ; Remove program name 62 | ; from stack 63 | ;*** Get UID, GID 64 | sys_getuid 65 | mov [uid], eax 66 | sys_getgid 67 | mov [gid], eax 68 | 69 | ;*** Get GROUPS 70 | sys_getgroups 64, groups 71 | mov [ngroups], eax 72 | 73 | ; For each command argument 74 | .nextarg: 75 | dec ebp 76 | jz .done 77 | pop edi ; edi = command to test 78 | mov [current], edi 79 | push ebp 80 | call .which 81 | pop ebp 82 | jmp .nextarg 83 | 84 | .done mov ebx, [found] 85 | sys_exit 86 | 87 | ;******* .which: determine if the argument in [current] can be run from PATH= 88 | ; May destroy all registers 89 | .which: 90 | mov ebp, pathptr 91 | mov esi, [current] 92 | .findslash: ; If contains any slashes, 93 | lodsb ; do not use PATH 94 | or al, al 95 | jz .chwhich 96 | cmp al, '/' 97 | jne .findslash 98 | mov ebp, zero 99 | mov edi, pathbuf 100 | jmps .noneedslash 101 | .chwhich: ; For each path, 102 | mov esi, [ebp] 103 | or esi, esi 104 | jz near .whdone 105 | mov al, [esi] 106 | or al, al 107 | jz near .whdone 108 | mov edi, pathbuf 109 | call .strccpy ; Copy into buffer 110 | dec edi 111 | mov al, '/' ; Append / if necessary 112 | cmp [edi], al 113 | je .noneedslash 114 | stosb 115 | .noneedslash: 116 | mov esi, [current] 117 | call .strccpy 118 | 119 | ;*** NOW STAT the file 120 | sys_stat pathbuf, sts ; This stat follows symlinks 121 | neg eax 122 | jc near .nextwhich ; If we can't stat it, we can't 123 | ; execute it 124 | mov ecx, [sts.st_mode - 2] 125 | shr ecx, 28 126 | and ecx, byte ~4 127 | jz near .nextwhich ; Can't execute a directory 128 | ;*** Check permissions 129 | mov eax, [sts.st_mode] 130 | and eax, byte 73 ; mode 0111 131 | jz .notfound 132 | mov ebx, [uid] ; If an execute bit is set, 133 | or ebx, ebx 134 | jnz .notroot ; root can execute it 135 | .found: 136 | xor eax, eax 137 | mov [found], eax 138 | mov al, __n 139 | stosb 140 | mov edx, edi 141 | sub edx, pathbuf 142 | sys_write STDOUT, pathbuf 143 | .whdone: 144 | ret 145 | 146 | .notroot: 147 | cmp bx, [sts.st_uid] ; Can it be executed 148 | jne .group ; as the user? 149 | and eax, byte 64 ; mode 0100 150 | jnz .found 151 | jmp .notfound 152 | .group: 153 | mov cx, [sts.st_gid] ; As the group? 154 | cmp ecx, [gid] 155 | je .thegroup 156 | mov edx, [ngroups] 157 | mov ebx, groups 158 | .nextgroup: 159 | cmp cx, word [ebx] 160 | je .thegroup 161 | inc ebx 162 | inc ebx 163 | dec edx 164 | jnz .nextgroup 165 | and eax, byte 1 ; as the world? 166 | jnz .found 167 | jmp .notfound 168 | .thegroup: 169 | and eax, byte 010 170 | jnz .found 171 | .notfound: 172 | .nextwhich: 173 | add ebp, 4 174 | jmp .chwhich 175 | 176 | 177 | 178 | .strccpy: ; *** copy string esi to edi 179 | lodsb ;esi 180 | stosb ;edi 181 | or al, al 182 | jnz .strccpy 183 | ret 184 | 185 | ;.DEBUG: ; Display a debugging message 186 | ; pusha 187 | ; mov ecx, DEBUG_MESSAGE 188 | ; mov edx, [DEBUG_MESSAGE_LEN] 189 | ; sys_write STDERR 190 | ; popa 191 | ; ret 192 | ; 193 | ;DEBUG_MESSAGE db "DEBUG", __n 194 | ;DEBUG_MESSAGE_LEN dd 6 195 | 196 | UDATASEG 197 | 198 | uid resd 1 ; The user's uid 199 | gid resd 1 ; The user's gid 200 | ngroups resd 1 ; The number of groups the user is in 201 | groups resd 64 ; Those groups 202 | pathptr resd 64 ; We process 64 paths from ENV 203 | zero resd 2 ; Always zero 204 | pathbuf resb 1024 ; 1k for the /path/to/filename buffer 205 | found resd 1 ; Set to 0 when first entry is found 206 | current resd 1 ; The current command pointer 207 | 208 | sts: 209 | %ifdef __BSD__ 210 | B_STRUC Stat,.st_ino,.st_mode,.st_nlink,.st_uid,.st_gid,.st_rdev,.st_mtime,.st_size,.st_blocks 211 | %else 212 | B_STRUC Stat,.st_ino,.st_mode,.st_nlink,.st_uid,.st_gid,.st_rdev,.st_size,.st_blocks,.st_mtime 213 | %endif 214 | 215 | END 216 | -------------------------------------------------------------------------------- /src/whoami.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 2001 Tiago Gasiba 2 | ; 3 | ;$Id: whoami.asm,v 1.2 2002/03/14 18:25:57 konst Exp $ 4 | ; 5 | ;hacker's whoami 6 | ; 7 | ;syntax: whoami 8 | ; 9 | ;TODO: 10 | ; - UID not found in /etc/passwd 11 | ; - read() doesn't read all file at once 12 | ; - optimize SPEED and SIZE (algorithm??) 13 | 14 | %include "system.inc" 15 | 16 | %assign BUFFERLEN 20 17 | %assign MAXSTRLEN 200 18 | 19 | %assign STACK_FRAME_SIZE 16 20 | 21 | %define FSIZE esp+12 22 | %define FD esp+8 23 | %define UID esp+4 24 | %define BEG_DATA esp 25 | 26 | CODESEG 27 | 28 | START: 29 | mov ebp,esp ;create stack frame 30 | 31 | _sub esp,STACK_FRAME_SIZE 32 | ; sys_brk 33 | mov dword [BEG_DATA],_end ;save beg. of data 34 | 35 | sys_getuid 36 | mov [UID],eax 37 | 38 | sys_open file,O_RDONLY 39 | test eax,eax 40 | js near .exit 41 | mov [FD],eax ;save file descrp. 42 | 43 | sys_lseek [FD],0,SEEK_END 44 | mov [FSIZE],eax 45 | 46 | sys_lseek [FD],0,SEEK_SET 47 | 48 | mov eax,[BEG_DATA] 49 | add eax,[FSIZE] 50 | inc eax 51 | sys_brk eax 52 | mov eax,[BEG_DATA] 53 | mov byte [eax],__n 54 | 55 | mov eax,[BEG_DATA] 56 | inc eax 57 | sys_read [FD],eax,[FSIZE] 58 | ; FIXME FIXME FIXME 59 | ; have we read all??? 60 | 61 | sys_close [FD] 62 | 63 | ; search for name 64 | cld 65 | mov edi,[BEG_DATA] 66 | mov ecx,[FSIZE] 67 | 68 | .outro: 69 | mov al,':' 70 | times 2 repne scasb 71 | mov esi,edi 72 | repne scasb 73 | dec edi 74 | mov byte [edi],0 75 | call ascii2uint 76 | cmp eax,[UID] 77 | je .encontrado 78 | mov al,__n 79 | repne scasb 80 | jmps .outro 81 | 82 | .encontrado: 83 | std 84 | mov al,__n 85 | mov edi,esi 86 | repne scasb 87 | inc edi 88 | inc edi 89 | push edi 90 | mov al,':' 91 | cld 92 | repne scasb 93 | dec edi 94 | mov word [edi],0x000a 95 | pop esi 96 | 97 | call strlen 98 | 99 | sys_write STDOUT,esi,eax 100 | .exit: 101 | mov esp,ebp ; destroy stack frame 102 | sys_exit 0 103 | 104 | ;-------------------------------------------------- 105 | ; Function : ascii2uint 106 | ; Description : converts an ASCIIZ number to uint 107 | ; Needs : esi - pointer to string 108 | ; Gives : eax - converted number 109 | ; Destroys : eax 110 | ;-------------------------------------------------- 111 | ascii2uint: 112 | pusha 113 | _mov eax,0 ; initialize sum 114 | _mov ebx,0 ; zero digit 115 | .repete: 116 | mov bl,[esi] ; get digit 117 | test bl,bl 118 | jz .exit ; are we done ? 119 | and bl,~0x30 ; ascii digit -> bin digit 120 | imul eax,10 ; prepare next conversion 121 | add eax,ebx 122 | inc esi ; next digit 123 | jmps .repete 124 | .exit: 125 | mov [esp+28],eax ; save eax 126 | popa 127 | ret 128 | 129 | ;----------------------------------------------------- 130 | ; function : strlen 131 | ; objective : returns the length of a string 132 | ; needs : esi - pointer to stringz 133 | ; returns : eax - string length 134 | ; destroys : eax 135 | ;----------------------------------------------------- 136 | strlen: 137 | pusha 138 | cld 139 | _mov ecx,MAXSTRLEN 140 | mov edi,esi 141 | _mov eax,0 142 | repne scasb 143 | _mov eax,MAXSTRLEN 144 | sub eax,ecx 145 | dec eax 146 | mov [esp+28],eax 147 | popa 148 | ret 149 | 150 | file db "/etc/passwd",0 151 | 152 | UDATASEG ; to be able to brk() 153 | 154 | END 155 | -------------------------------------------------------------------------------- /src/write.asm: -------------------------------------------------------------------------------- 1 | ; Copyright (C) 2001 Thomas M. Ogrisegg 2 | ; 3 | ; write utility 4 | ; 5 | ; usage: write user [tty] 6 | ; 7 | ; BUGS/TODO: 8 | ; Improve diagnostic messages 9 | ; using mmap would be smarter... 10 | ; 11 | ; 06/07/02: added printing of username on the target terminal (TO) 12 | ; 13 | ; $Id: write.asm,v 1.4 2002/06/11 08:41:06 konst Exp $ 14 | 15 | %include "system.inc" 16 | 17 | %assign BUFLEN 0x100 18 | 19 | CODESEG 20 | 21 | usage: 22 | sys_write STDOUT, helptxt, helplen 23 | sys_exit 0x1 24 | 25 | START: 26 | pop ecx 27 | cmp ecx, byte 3 28 | jg usage 29 | cmp ecx, byte 1 30 | jz usage 31 | 32 | lea esi, [esp+ecx*4+4] 33 | search_user: 34 | lodsd 35 | or eax, eax 36 | jz .Lout 37 | cmp long [eax], 'USER' 38 | jnz search_user 39 | add eax, 5 40 | cmp byte [eax-1], '=' 41 | jnz search_user 42 | mov [user], eax 43 | .Lout: 44 | 45 | pop eax 46 | pop esi 47 | mov edi, esi 48 | pop long [ttyname] 49 | 50 | push esi 51 | mov ecx, 32 52 | mov edx, ecx 53 | xor eax, eax 54 | repnz scasb 55 | sub ecx, edx 56 | not ecx 57 | test ecx, ecx 58 | jz near error ; exit 59 | push ecx 60 | 61 | sys_open utmpfile, O_RDONLY, 0 62 | mov [fd], eax 63 | 64 | sys_chdir devdir 65 | 66 | _loop: 67 | sys_read [fd], utmpbuf, utmp_size 68 | or eax, eax 69 | jz near error ; exit 70 | lea edi, [utmpbuf+utmp.ut_user] 71 | mov esi, [esp+4] 72 | mov ecx, [esp] 73 | repz cmpsb 74 | or ecx, ecx 75 | jnz _loop 76 | 77 | do_write: 78 | lea ebx, [utmpbuf+utmp.ut_line] 79 | mov esi, [ttyname] 80 | or esi, esi 81 | jz next_write 82 | mov edi, ebx 83 | mov ecx, 6 84 | repz cmpsb 85 | 86 | or ecx, ecx 87 | jnz _loop 88 | 89 | next_write: 90 | sys_open ebx, O_WRONLY 91 | cmp eax, 0 92 | jg Next 93 | mov ecx, [ttyname] 94 | or ecx, ecx 95 | jz _loop 96 | jmp noperm 97 | Next: 98 | mov [ttyfd], eax 99 | 100 | mov edi, buffer 101 | mov esi, message 102 | mov ecx, messagelen 103 | repnz movsb 104 | mov esi, [user] 105 | or esi, esi 106 | jz .Lnext 107 | .Llabel: 108 | lodsb 109 | stosb 110 | or al, al 111 | jnz .Llabel 112 | mov byte [edi], __n 113 | ; lea ecx, [edi-buffer] 114 | mov ecx, edi 115 | sub ecx, buffer 116 | sys_write [ttyfd], buffer, ecx 117 | .Lnext: 118 | sys_write [ttyfd], beep, beeplen 119 | 120 | io_loop: 121 | sys_read STDIN, buffer, BUFLEN 122 | _mov ebx,[ttyfd] 123 | test eax, eax 124 | jz eof 125 | sys_write EMPTY, buffer, eax 126 | jmps io_loop 127 | 128 | eof: 129 | _mov ecx,EOF 130 | _mov edx,eoflen 131 | jmps do_exit 132 | 133 | noperm: 134 | _mov ebx,STDERR 135 | _mov ecx,perm 136 | _mov edx,permlen 137 | jmps do_exit 138 | 139 | error: 140 | _mov ebx,STDERR 141 | _mov ecx,nologin 142 | _mov edx,nologlen 143 | 144 | do_exit: 145 | sys_write 146 | sys_exit 0x0 147 | 148 | helptxt db "Usage: write user [ttyname]", __n 149 | helplen equ $ - helptxt 150 | 151 | nologin db "User not logged in or permission denied", __n 152 | nologlen equ $ - nologin 153 | 154 | perm db "Permission denied", __n 155 | permlen equ $ - perm 156 | 157 | utmpfile db _PATH_UTMP, EOL 158 | devdir db "/dev", EOL 159 | 160 | EOF db "EOF", __n 161 | eoflen equ $ - EOF 162 | 163 | message db "Message from " 164 | messagelen equ $ - message 165 | beep db 0x1B, 0x5B, 0x6D, 0x1B, 0x5B, 0x34, 0x6C, 0x07, __n 166 | beeplen equ $ - beep 167 | 168 | UDATASEG 169 | ttyname ULONG 1 170 | user ULONG 1 171 | fd ULONG 1 172 | ttyfd ULONG 1 173 | utmpbuf B_STRUC utmp 174 | buffer UCHAR BUFLEN 175 | END 176 | -------------------------------------------------------------------------------- /src/yes.asm: -------------------------------------------------------------------------------- 1 | ;Copyright (C) 1999 Indrek Mandre 2 | ; 3 | ;$Id: yes.asm,v 1.6 2002/03/26 05:24:27 konst Exp $ 4 | ; 5 | ;hackers' yes [GNU replacement] 6 | ; 7 | ;syntax: yes [string...] 8 | ; 9 | ;example: yes string1 string2 string3 10 | ; yes 11 | ; yes onlyonestring 12 | ; 13 | ;Concatenates all strings, the resulting string can be 0xfff bytes long 14 | ; 15 | ;0.01: 17-Jun-1999 initial release 16 | ;0.02: 04-Jul-1999 fixed bug with 2.0 kernel (KB) 17 | ;0.03: 14-Mar-2002 size improvements (KB) 18 | 19 | %include "system.inc" 20 | 21 | CODESEG 22 | 23 | %assign BUFSIZE 0x1000 24 | 25 | START: 26 | pop ebp ;ebp holds argument count 27 | pop eax ;we ignore our own name 28 | 29 | mov edi,buf 30 | mov edx,edi 31 | 32 | dec ebp 33 | jnz .nextarg ;take arguments and cat them to out buf 34 | 35 | mov al,'y' 36 | stosb 37 | inc ebp 38 | ; jmps .startinfiniteprint 39 | 40 | .endofstring: 41 | dec ebp 42 | jz .startinfiniteprint ;print what we've got so far 43 | 44 | mov al,' ' 45 | stosb 46 | 47 | .nextarg: 48 | pop esi ;pop the string 49 | .back: 50 | lodsb 51 | or al,al ;end of string? 52 | jz .endofstring 53 | stosb 54 | cmp edi,buf + BUFSIZE - 2 ;end of our dear buf? 55 | jl .back ;in that case just print out what we got 56 | 57 | .startinfiniteprint: 58 | mov al,__n ;concatenate \n 59 | stosb 60 | sub edi,edx ;length of final string 61 | .myloop: 62 | sys_write STDOUT,buf,edi 63 | jmps .myloop 64 | 65 | ;.exit: 66 | ; sys_exit 67 | 68 | UDATASEG 69 | 70 | buf resb BUFSIZE ;our internal buffer size 71 | 72 | END 73 | --------------------------------------------------------------------------------