Markus Rechberger / C
StartSeite | MarkusRechberger/ | Neues | TestSeite | ForumSeite | Teilnehmer | Kategorien | Index | Hilfe | Einstellungen | Ändern


9 Seiten:Datum der letzten Änderung
MarkusRechberger/C/ResolveFilename16. April 2005 18:26
MarkusRechberger/C/libdvdread9. April 2005 18:15
MarkusRechberger/C/regex7. April 2005 14:52
MarkusRechberger/C/CoreDump4. April 2005 10:53
MarkusRechberger/C/Semaphoren5. März 2005 21:52
MarkusRechberger/C/Obstack24. Februar 2005 21:27
MarkusRechberger/C/ThreadQueues21. Februar 2005 22:19
MarkusRechberger/C/imlib226. Januar 2005 10:40
MarkusRechberger/C/DotConf26. Januar 2005 10:35


Another nice thought from izik about reverse engineering using {LD PRELOAD}?



Durch das nach rechts shiften von foo wird der ganze wert durch 2 dividiert, durch links shiften wird das ganze *2 multipliziert

#include <stdio.h>

int main(){
        int foo=28;
        printf("foo/2 = %d\n",foo>>1);
        printf("foo*2 = %d\n",foo<<1);
}, Wiederholung Grundlagen Datenverarbeitung!

Bitgröße eines Datentyps in structs

> What's the meaning of the following definition:
> int a:8;
> thanks

This declaration creates an 8-bit integer.  This syntax is only used within
structures for defining bit fields.
struct Anything
    unsigned int   condition_code:4;
    unsigned int   operation_code:4;
    unsigned int   offset:8;

#include <stdio.h>

struct test{
        unsigned int foo:1;

int main(){
        struct test mare;;
} is 1 in that case

segfault vs alles ok


 GCC no longer accepts the -fwritable-strings  option. Use named character arrays when you need a writable string.


"Markus" ist ohne -fwriteable-strings schreibgeschützt

#include <stdio.h>

int main(){
        char *foo="Markus";

/devel/c/aufgabe42$ gcc -fwritable-strings  test.c -o test
/devel/c/aufgabe42$ ./test
/devel/c/aufgabe42$ gcc test.c -o test
/devel/c/aufgabe42$ ./test
Segmentation fault


Eine Object file gegen ein Shared Library linken

ld -dynamic-linker /lib/ /usr/lib/ -o test test.o


aus der c mailing list:

printf("\e[0m\e[2J\e[1;1H"); /* ]]] */

It's ascii control character. 2J means clear the screen and 1;1H set the cursor position

Another way to do it:
   char *area[100], bp[2048] ;

   tgetent( bp, getenv( "TERM" )) ;
   puts( tgetstr( "cl", area )) ;


{LD PRELOAD}? erlaubt eine Überlagerung von Funktionen in Libraries,...

Beispiel: main.c
#include <dlfcn.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdarg.h>

int fprintf(FILE *stream, const char *format,...){
        va_list testing;
        int retval;
        printf("-- ACCESSING FPRINTF WRAPPER!! --\n");
        va_start (testing, format);
        printf("-- HIJACKED --\n");
libtool --mode=link gcc -shared -{D REENTRANT}? main.c -o

#include <stdio.h>

int main(){
make test

# export LD_PRELOAD=`pwd`/
# ./test

in diesem Fall könnte man auch Pointer Functions einsetzen zu bestimmten Funktionen, die Adresse des nächsten Symbols kann jeweils mit dlsym({RTLD NEXT}?,"symbol") ausgelesen werden..


auch wenn ich's sogut wie nie benötige...

#include <stdio.h>

int testing(void){
        printf("this is a testfunc!\n");

int main(){
        int (*test)(void);

make main


schon wieder beinahe vergessen..

       #include <ctype.h>

       int isalnum(int c);
       int isalpha(int c);
       int isascii(int c);
       int isblank(int c);
       int iscntrl(int c);
       int isdigit(int c);
       int isgraph(int c);
       int islower(int c);
       int isprint(int c);
       int ispunct(int c);
       int isspace(int c);
       int isupper(int c);
       int isxdigit(int c);

#include <stdio.h>

  float a1=1.0;
  float a2=2.0;

  printf(" \n");
  printf(" Size of Float > %d \n", sizeof(float) );
  printf(" Size of Int   > %d \n", sizeof(int) );
  printf(" \n");

  printf(" CASE 1 : f-f > %f - %f \n\n", a1, a2);
  printf(" CASE 2 : f-d > %f - %d \n\n", a1, a2);
  printf(" CASE 3 : d-f > %d - %f \n\n", a1, a2);
  printf(" CASE 4 : d-d > %d - %d \n\n", a1, a2);


Size of Float > 4
Size of Int   > 4

CASE 1 : f-f > 1.000000 - 2.000000

CASE 2 : f-d > 1.000000 - 0

CASE 3 : d-f > 0 - 0.000000

CASE 4 : d-d > 0 - 1072693248

test.c:4: warning: return type defaults to `int'
test.c: In function `main':
test.c:15: warning: int format, double arg (arg 3)
test.c:16: warning: int format, double arg (arg 2)
test.c:18: warning: int format, double arg (arg 2)
test.c:18: warning: int format, double arg (arg 3)
test.c:20: warning: control reaches end of non-void function

it seems to be a feature in C.
[ from another mailing list:

The text from the ISO 1999 standard in is:

6 If the expression that denotes the called function has a type that
 not include a prototype, the integer promotions are performed on each
 argument, and arguments that have type float are promoted to
 double. These are called the default argument promotions. [...]

7 If the expression that denotes the called function has a type that
 include a prototype, the arguments are implicitly converted, as if by
 assignment, to the types of the corresponding parameters, taking the
 type of each parameter to be the unqualified version of its declared
 type. The ellipsis notation in a function prototype declarator causes
 argument type conversion to stop after the last declared parameter.
 default argument promotions are performed on trailing arguments.

also check glibc's manual (may be out of date ??):

Large file support



praktisch um größere Projekte nach funktionen/.. zu durchsuchen

Embed perl within C

perldoc perlembed
perldoc perlxs
perldoc perlapi

is what you will need to embed your Perl program in C. as a simple example,
the following embeds a Perl script,, into a C program test.c.
test.c simply runs a regexp and extract the emails address that it finds in

$email = ',';

#-- the following is for demo puprose, don't use this
#-- for extracting email address out of a string. you
#-- can embed any Perl code you want here instead.
@emails = $email =~ /([^,]+@[^,]+)/g;


the following C program will embed the above Perl script and prints
out the email address in @emails:

#include <EXTERN.h>
#include <perl.h>

static PerlInterpreter* perl;
static AV *emails;

int main(int argc,char** argv){

        int x;
        STRLEN y;

        perl = perl_alloc();

        // get @emails in
        emails = get_av("emails",0);

        // av_len(emails) is the same as $#emails
        for(x = 0; x <= av_len(emails); x++){

                // av_fetch(emails,x,0) is the same as $emails[$x]
                SV* email = *av_fetch(emails,x,0);

                // SvPV(email,y) "converts" an array element to a string
                printf("email %d is: %s\n",x+1,SvPV(email,y));



to compile this C program, you will need to know how Perl is build
in your machine, the following usually does the trick:

[panda]# gcc test.c -o test `perl -MExtUtils::Embed -e ccopts -e ldops`

finally, to test your executable:

[panda]# ./test

assuming is in the same directory as test.c, you will see: 

the arrow operator

The symbol -> is known as the ``arrow operator''. The arrow operator can be used with pointers to struct variables and objects. The expression


is simply another way of writing


21:19 < bniemczyk> revenger: and don't cast malloc
21:19 < bniemczyk> btw
21:19 < bniemczyk> revenger: #include <stdlib.h>
21:20 < bniemczyk> to get rid of the warning you were getting that led you to believe you should cast it
21:20 < bniemczyk> also, i'm betting you wanted to make it so that la->test would be changed after a call to function
21:20 < Manny> bniemczyk: what's wrong with casting malloc?
21:20 < bniemczyk> the way you are doing it won't
21:20 < bniemczyk> Manny: it hides the error of not including stdlib.h

StartSeite | MarkusRechberger/ | Neues | TestSeite | ForumSeite | Teilnehmer | Kategorien | Index | Hilfe | Einstellungen | Ändern
Text dieser Seite ändern (zuletzt geändert: 31. Juli 2005 21:32 (diff))
Suchbegriff: gesucht wird
im Titel
im Text