x.h
===
int add(int a, int b);
a.c
===
#include "x.h"
extern int extra;
int main()
{
int a = 9;
int b = 8;
int c;
c = add(9, 8) + extra;
return 0;
}
b.c
===
#include "x.h"
int extra = 9;
int add(int a, int b)
{
return a+b;
}
start.S
=======
.globl _start
_start:
call main
movl $1, %eax
xorl %ebx, %ebx
int $0x80
Now do
~/# gcc -c -nostdlib a.c
~/# gcc -c -nostdlib b.c
~/# gcc -c -nostdlib start.S
~/# ld -o test a.o b.o start.o
Your executable test is ready!!
Source: https://blogs.oracle.com/ksplice/entry/hello_from_a_libc_free
Good example showing how to create a Position Independent Executable (PIE).
We can create a Position Independent Executable (PIE) using -fPIE compiler option and -pie linker option of gcc.
A nice example collected from net.
aslr.c
======
#include <stdio.h>
static void foo() {}
static int bar = 5;
int main(void)
{
int baz = 5;
printf("function: %p, library function: %p, data: %p, stack: %p\n", foo, &printf, &bar, &baz);
return 0;
}
=======
Now do
$ gcc -o aslr aslr.c; for i in $(seq 1 10); do ./aslr; done
$ gcc -fPIE -o aslr aslr.c; for i in $(seq 1 10); do ./aslr; done
$ gcc -fPIE -pie -o aslr aslr.c; for i in $(seq 1 10); do ./aslr; done
and see what you get!!
Source: https://wiki.archlinux.org/index.php/DeveloperWiki:Security
A nice example collected from net.
aslr.c
======
#include <stdio.h>
static void foo() {}
static int bar = 5;
int main(void)
{
int baz = 5;
printf("function: %p, library function: %p, data: %p, stack: %p\n", foo, &printf, &bar, &baz);
return 0;
}
=======
Now do
$ gcc -o aslr aslr.c; for i in $(seq 1 10); do ./aslr; done
$ gcc -fPIE -o aslr aslr.c; for i in $(seq 1 10); do ./aslr; done
$ gcc -fPIE -pie -o aslr aslr.c; for i in $(seq 1 10); do ./aslr; done
and see what you get!!
Source: https://wiki.archlinux.org/index.php/DeveloperWiki:Security
When 'clear' command doesn't clean the whole terminal window.
We can use 'reset' command to clean the whole terminal window.
C statement execution time in microseconds
#include <sys/time.h>
=====================
struct timeval tv1, tv2;
gettimeofday(&tv1, NULL);
//put c statements here
gettimeofday(&tv2, NULL);
printf ("Total time = %lld microseconds\n", ((long long)tv2.tv_sec*(long long)1000000+(long long)tv2.tv_usec) - ((long long)tv1.tv_sec*(long long)1000000+(long long)tv1.tv_usec));
=====================
struct timeval tv1, tv2;
gettimeofday(&tv1, NULL);
//put c statements here
gettimeofday(&tv2, NULL);
printf ("Total time = %lld microseconds\n", ((long long)tv2.tv_sec*(long long)1000000+(long long)tv2.tv_usec) - ((long long)tv1.tv_sec*(long long)1000000+(long long)tv1.tv_usec));
Sort directories based on human readable size
# du --max-depth=3 . | sort -n | cut -f 2 | while read file_name; do du -sh $file_name; done;
Subscribe to:
Posts (Atom)