in the name of zero

April 9, 2006

holy week’s a comin’

(supposed to be yesterday’s post)

the weather has been dangling on two extremes for two days now, at least i feel it is. rain in the morning brings welcome cold air. i like how it makes me wanna hug my pillow so much (i imagine steph huggin her pillow tight too while i’m at it). and the coldness also makes the bed more comfortable and soft for some reason. but the temperature begins to rise come first sunshine with it’s peak (day time high) around late noon - one to two pm. the weather is soo hot, i can feel my scrotum perspiring. adding to the heat are the random blackouts we’re having. it occured to me that i haven’t gone outside the house for many many days now. so i went outside our yard to get some fresh air. the electricity came back after a few hours. just in the nick of time too, since i was already at my limit. i bought coke, some ice, and cranked the electric fan up to level three.

i did some bits of c programming a few minutes after. i start now, with yet another basic examples. syscall in check. ptrace(). finished two programs, an asm prog that prints a string and quits, and a c prog that traces the asm program’s execution. here goes nothing..


asm file traceme.asm

        global _start
section .text
_start
        mov edx, namelen
        mov ecx, hername
        mov ebx, 0x1
        mov eax, 0x4
        int 0x80 
	
        xor eax, eax
        inc eax
        dec ebx
        int 0x80 
	
section .data
        hername db 'stephanie', 0xa, 0x0
        namelen equ $-hername

t1.c

#include <sys/ptrace.h>
#include <linux/user.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/reg.h>
#include <unistd.h>
#include <stdio.h>
	
int main(int argc, char **argv)
{
        pid_t cpid;
        int st;
        int entry = 0;
	
        struct user_regs_struct ureg;
	
        cpid = fork();
	
        if(!cpid) {
                ptrace(PTRACE_TRACEME);
                execl("./traceme", "traceme", NULL);
        } else {
                while (1) {
                        wait(&st);
	
                        if (WIFEXITED(st)) break;
	
                        ptrace(PTRACE_GETREGS, cpid, NULL, &ureg);
	
                        if (entry) {
                                printf("entering systemcall %ld...\n", ureg.orig_eax);
                                entry=0;
                        } else {
                                printf("systemcall %ld returns %ld\n", ureg.orig_eax, ureg.eax);
                                entry = 1;
                        }
	
                        ptrace(PTRACE_SYSCALL, cpid, NULL, NULL);
                }
        }
        return 0;
}

the output

steph@heaven ~/git/null/c/ptrace $ ./t1
systemcall 11 returns 0
entering systemcall 4...
stephanie
systemcall 4 returns 11
entering systemcall 1...

well, that was pretty basic. i hope to cover more topics on ptrace() during the holy week, familiarize myself more on it and its related literature. this article for instance, is really worth an experiment. i’m searching for topics similar to it while i’m typing this now actually.

this is niel, signing off.

Comments »

The URI to TrackBack this entry is: http://gnurbs.blogsome.com/2006/04/09/holy-weeks-a-comin-2/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>


Get free blog up and running in minutes with Blogsome | Theme designs available here