wolfie's homepage
e-mail:mpolacek@redhat.comjabber:
phata@jabber.czirc:
wolfie, #fit on IRCnetFIT: records, course, wis, ftp
Interests:
- GNU Toolchain (libraries, compiler, linker, debugger)
ELF- women
null | 500 albums | 1001 albums
(OLD) Stuff that matters
– behold--most of this is old and by no means perfect– log of these source codes
– use
gcc -std=gnu99 -D_GNU_SOURCE -D_FORTIFY_SOURCE=2 -Wall -Wextra -O2 -march=native– COPYING
– INSTALL
– mmap scheme
– virtual address space layout, another
– gcc optimization table
– toolchain – view the whole process of compilation
– measuring the (un)likely macros
– linux-gate [CZECH]
– instrument-functions
– something about GCC printf optimization
– ELF notes
– fiddling with return address
– using grep
– introduction to
autoconf and automake is here. With libtool.– startup code compliant to the ELF i386 ABI with nice explanations. Taken from
glibc.– a word about errno
– a word about MALLOC_PERTURB_
– creating and inserting linux kernel module
– compiling GCC from scratch
– create a file system in a file within the current file system
– just strace output of
int main() {} program– using mudflap
– a mail about aliasing from Krister Walfridsson
– automated git update bash script
– creating static and dynamic libraries using
gcc [CZECH]– writing small ELF executable
– something about
DCE and CSE, pure and const functions
Linux utilities- ionice.c – get/set program io scheduling class and priority
- plmalloc.c – a simple memory allocator. PL stands for Pretty Lame. Example of usage.
- namei.c – follow a pathname until a terminal point is found
- mcookie.c – generator of random numbers for xauth
- blockdev.c – call block device ioctls from the command line
- dmesg.c – print out the contents of the kernel ring buffer
- size.c – bare bones implementation of the size utility
- rev.c – reverse lines of a file or files. Need rework.
- printenv.c – print environment variables
- showkey.c – examine the codes sent by the keyboard
- run algorithm for a certain amount of time
- a simple FIFO implementation
- error handler
- vlceksay.c – a cowsay modification
- sudoku
-
- a console application to generate 9x9 sudoku
- NB: old and ugly :)
- sudoku.c
- sudoku.h
- Makefile
- sudoku.tar.gz
Linux Kernel Modules- hello.c – simple hello module
- chardev.c – create a char device. Sample session here
- kthread.c – simple kernel thread
- constructor.c – demonstration of constructor and destructor attributes
- noreturn.c
– example of
__attribute__ ((__noreturn__)), compile with-Wall - check_birth_number.c – checks, if birth certificate number is valid, using label as value
- get_glibc_version.c – get glibc version
- concat.c – concatenate arbitrarily many strings
- untab.c – convert tabs to spaces
- format_string_attack.c
– demonstration of format string attack using
printf()
ELF
- don't forget to link with
-lelf - elf_pathnames.c – display a list of pathnames of the shared objects
- elf_filetype.c – get file type
- elf_header.c – print the ELF Executable Header
- elf_prg_header.c – print the ELF Program Header Tables
- elf_print_sections.c – print the names of ELF sections
- do NOT use gcc optimizations or use -O0
- AT&T syntax:
op-name src dest - assign.c – assign a value to another value
- add.c – add two numbers
- multiply.c – multiply two numbers
- string.c – string routines
- direct_call.c – example of direct function call from inline assembly
- cpuid.c
– get Vendor ID using
CPUIDopcode
- fork_more.c – creating a few processes
- fork.c
– example of
forkfunction - vfork.c
– example of
vforkfunction - exit_status.c
– example of
exitstatuses - avoid_zombie.c – avoid zombie procesess by calling fork twice
- race_cond.c – program with a race condition
- race_cond_fixed.c – program with a race condition [FIXED]
- exec.c
– example of
execfunctions - acct.c
– program to generate accounting data using
acctfunction. Run as root, delete file `acct_log' afterwards - examine_acct_log.c – print selected fields from system's accounting file (acct_log)
- times.c – time and execute all command-line arguments
- orphaned_pgroup.c – creating an orphaned process group
- memdup.c – duplicate memory block
- dynarr.c – dynamic arrays
- memswap.c – swap contents of two memory blocks
- mallinfo.c – examining the mallinfo structure
- memory_hooks.c – example of memory allocation hooks
- catch_signal.c
– catch
SIGUSR1orSIGUSR2, display bunny or cow :-) - signal_sets.c – example of signal sets
- raise.c
– example of
raise() - sigsetjmp.c
– example of signal masks,
sigsetjmp()andsiglongjmp() - sigsuspend.c
– protecting a critical region from a signal with
sigsuspend() - sigsuspend2.c
– using
sigsuspend()to wait for a global variable to be set - psignal.c
– example of
psignal()
- arrays_n_pointers.c – arrays and pointers addresses
- findfunc.c –
calling function via
char *(pointers to functions) - arr_of_p_to_func.c – array of pointers to functions
- array_subscripting.c – array subscripting in C
- can_seek.c – test whether stdin is capable of seeking
- file_hole.c – create a file with a hole in it
- print_file_flags.c – print file flags for specified descriptor
- readv.c – example of scatter read
- print_type.c – print type of a given file
- umask.c
– example of
umaskfunction - chmod.c
– example of
chmodfunction - access.c
– example of
accessfunction - ls.c – list all the files in a directory
- unlink.c – open a file and then unlink it
- utime.c
– example of
utimefunction - count_file_types.c – recursively descend a directory hierarchy, counting file types
- tree_walk.c
– walk through a directory tree, using
ftw() - tree_walk2.c
– walk through a directory tree, using
nftw() - size_of_dev.c – get size in bytes of block device
- print_dev_value.c
– print
st_devandst_rdevvalues - print_buffering.c – print buffering for various standard I/O streams
- tmpfile.c
– demonstrate
mkstempandtmpfilefunctions - tempnam.c
– demonstrate
tempnamfunction
- different approaches to copy a file
- copy_blk.c
– copy file using
fread()andfwrite() - copy_char.c
– copy file using
getchar()andputchar() - copy_fstr.c
– copy file using
fgets()andfputs() - copy_getc.c
– copy file using
getc()andputc() - copy_pipe.c – copy file using pipe
- copy_raw.c
– copy file using
read()andwrite() - copy_raw2.c
– copy file using
read()andwrite()with buffer
ptrace- intro.c
– example of
ptrace()syscall - fetch_regs.c – fetch register values
- trace_ls.c
– tracing
write(2)when issuedls(1) - trace_pid.c – tracing running process
- reverse_write.c
– reverse the input passed to
write(2) - single-step.c – single step through the code
- stackloc.c – approximate location of the stack
- stack_align.c – test of stack align at i386
libcurl- Compile with
-lcurl - curl_download.c
– download a webpage using
libcurl. - curl_sepheaders.c – download a webpage, separate header and body
- daytime_server.c – daytime server, listens on port 1337
- daytime_client.c – daytime client
- pthread_create.c – create a thread
- pthread_create2.c – create two threads
- pthread_evens.c – compute even numbers in a thread
- pthread_detached.c – creating a detached thread, fragment only
- pthread_cs.c – critical section in a thread, fragment only
- pthread_tsd.c – per-thread log files implemented with TSD
- pthread_cleanup.c – demonstrating a thread cleanup handler, fragment only
- pthread_tsd.c – per-thread log files implemented with TSD
- mutex.c – example of pthread mutexes
- spin.c – example of pthread spinlocks
- barrier.c – example of pthread barriers
- pcleanup.c – another example of pthread cleanup handlers
- atfork.c
– example of
pthread_atfork(3P) - pthread_attrsd.c – example of thread attributes object
- cancel.c – example of thread cancellation
- LCG.c
– simple linear congruent generator using
rand(). Sample output. - monte_carlo.c – compute Pi using Monte Carlo method. Sample output.
- mersenne_twister.c – Mersenne Twister algorithm for generation pseudorandom numbers. Sample output.
Other stuff- time.c
– when
will
time_t's wrap around? - setjmp.c – non local jumps
- memory.c – how much memory can you allocate?
- exploit.c – stack exploit
- varg_list.c – variable argument list example
- getopt.c
– parsing arguments using
getopt() - pipe.c – creating a pipe
- dangling.c – the dangling else problem
- ctype_test.c
– testing the
ctype.hheader - limits.c
– basic properties of
limits.h - mmap.c
– the
mmap()system call example - sysinfo.c – display system info
- byte_order.c – determine byte order on system
- uname.c – get the name of the current system
- getusername.c – get the name of the current user
- strftime.c – playing around with time
- rand_r.c
– print 10 random numbers using
rand_r - dlfcn.c
– wrapper for
malloc()/free()using<dlfcn.h>. Compile with-ldl - getuid.c – get an user ID
- posix_version.c – display POSIX version
- atexit.c
– example of
atexit()function - readterm.c – reading from the terminal
- readkey.c – reading from the terminal in noncanonical mode. End with q/Q.
- shell-like.c – read commands from stdin and execute them
- show_error.c – demonstrate strerror and perror
- sysconf.c – print some of limits using sysconf
- syscall.c – example of indirect system call
- auxv.c
– get
AT_SYSINFOfrom ELF auxiliary vector - linux_version.c – display linux version
- fd-bench.c – check the cost of opening a file descriptor
- tlb_miss.c – TLB miss measurement on x86 CPUs. Run as root, SIGSEGV otherwise.
- setjmp_test_vars.c – effect of longjmp on various types of variables
- rlimits.c – print the current resource limits
- fmemopen.c
– example of
fmemopen()/open_memstream()functions - backtrace.c – example of backtraces
- memset.c
– implementation of memset using
Duff's device - obstacks.c – example of obstacks
- aio.c
– example of asynchronous read using
aio_read() - rpmatch.c
– example of
rpmatch(3) - dlmath.c – dynamically load the math library
- atomic.c – playing with kernel's atomic operations
- vt.c – display the character and screen attributes under the cursor of the 2nd VT
- getpwuid.c
– example of
getpwuid()andgetgrgid() - hsearch.c
– example of hash table using
hsearch() - bswap.c
– example of
bswap_*() - bogo.c – computing the BogoMIPS value on x86
- timerfd.c
– example of
timerfd*(2)-- timers that notify via file fds - eventfd.c
– example of
eventfd(2)-- create a file descriptor for event notification - shm.c
– example of POSIX
shm_*()functions - sem1.c
– example of POSIX
sem_*()functions - sem2.c
– example of POSIX
sem_*()functions - swapcontext.c
– example of
swapcontext(3) - popen.c
– example of
popen(3) - rprintf.c
– customizing
printf(3) - bsearch.c
– example of
bsearch(3) - subopt.c
– example of
subopt(3) - hash.c – example of various hash string functions
- mincore.c – print out which blocks of the file are cached
Hello World programs- hello1.c
– common
Hello Worldprogram - hello2.c
- compile with
gcc -ffreestanding -nostartfiles hello2.c -o hello2 - smaller executable file than `hello1'
- links with the same DSOs (Dynamic Shared Objects)
- uses the dynamic linker:
$ readelf -l hello2 | grep INTERP > /dev/null && echo yes || echo no yes $ file -b hello2 ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV),
dynamically linked (uses shared libs), not stripped
- compile with
- hello3.c
- compile with
gcc -ffreestanding -nostartfiles hello3.c -o hello3 - now we have indirect syscalls
- links with the same DSOs (Dynamic Shared Objects)
- still uses the dynamic linker:
$ readelf -l hello3 | grep INTERP > /dev/null && echo yes || echo no yes $ file -b hello3 ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV),
dynamically linked (uses shared libs), not stripped
- compile with
- hello4.c
- compile with
gcc -ffreestanding -nostartfiles -nostdlib hello4.c -o hello4 - using
__asm__ - no shared libraries => no dynamic linking:
$ readelf -l hello4 | grep INTERP > /dev/null && echo yes || echo no no $ file -b hello4 ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV),
statically linked, not stripped - empty data segment:
$ size hello4 | cut -f2 | tail -1 0
- compile with
- howto
- gnu ftp
- compile with
-lncurses - color_nc.c – example
- wtf1.c
– what does '
x = sizeof(int) * p' mean?
Makefiles
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
$ Sat Dec 4 12:16:41 CET 2010