perl - FreeBSD::i386::Ptrace released! : 404 Blog Not Found (original) (raw)

�������餢�ä��餤���ʤȻפäƤ����ΤǤ�����������äƤߤ�Ȥ��ä��������㤤�ޤ�����ɬ�פ�ȯ������ȤϤ褯���ä���ΤǤ���

���Ȥ��С����ۤ�t/pstrace.pl�Ϥ���ʴ����Ǥ���

#!/usr/local/bin/perl use strict; use warnings; use FreeBSD::i386::Ptrace; use FreeBSD::i386::Ptrace::Syscall;

die "$0 prog args ..." unless @ARGV; my $pid = fork(); die "fork failed:$!" if !defined($pid); if ($pid == 0){ pt_trace_me; exec @ARGV; }else{ wait; # for exec; my $count = 0; # odd on entry, even on exit my ($call, $retval); while(pt_syscall($pid) == 0){ last if wait == -1; if (++$count & 1){ call=ptgetcall(call = pt_getcall(call=ptgetcall(pid); }else{ retval=ptgetcall(retval = pt_getcall(retval=ptgetcall(pid); my name=name = name=SYS{$call} || 'unknown'; warn "$name -> $retval"; } } } warn $count/2," system calls issued"; }

���������ư���ޤ���

% /bin/ls Changes Makefile.PL README t MANIFEST Ptrace.xs lib % perl -Mbib t/pstrace.pl /bin/ls __sysctl -> 0 at t/pstrace.pl line 25. mmap -> 671588352 at t/pstrace.pl line 25. ...... ioctl -> 0 at t/pstrace.pl line 25. Changes Makefile.PL README t write -> 31 at t/pstrace.pl line 25. MANIFEST Ptrace.xs lib write -> 23 at t/pstrace.pl line 25. ....... sigprocmask -> 0 at t/pstrace.pl line 25. exit -> -1077941784 at t/pstrace.pl line 25. 92 system calls issued at t/pstrace.pl line 29.

�ޤ���t/rperl.t��Ȥ��ȡ�����Υ����ƥॳ�����ػߤ��Ĥ�Ǥ�դ� perl script ��¹ԤǤ��ޤ����ե�����̾����ꤷ�ʤ���硢ɸ�����Ϥ��饽�������ɤ�Τ� perl �Ȱ��Ǥ����ޤ���STDIN��STDERR��ʬ���ƥ���ץ��㡼���Ƥ���ޤ���

perl -Mblib t/rperl.pl use LWP::Simple; print get("http://example.com/");

stdout

Example Web Page

You have reached this web page by typing "example.com", "example.net", or "example.org" into your web browser.

These domain names are reserved for use in documentation and are not available for registration. See RFC 2606, Section 3.

stderr

% perl -Mblib t/rperl.pl webserver.pl

5641 killed: SYS_bind banned.

stdout

stderr

Use of uninitialized value in pack at /tmp/xmls1atH43 line 4. Use of uninitialized value in pack at /tmp/xmls1atH43 line 4. Use of uninitialized value in pack at /tmp/xmls1atH43 line 4. Use of uninitialized value in pack at /tmp/xmls1atH43 line 4.

�Ȥ����櫓�ǡ�FreeBSD�򤪻Ȥ��Τߤʤ��󡢤������Dz�Ŭ�� perl hacking �򤪳ڤ��ߤ��������ޤ���

Dan the (Perl|FreeBSD) Monger

NAME FreeBSD::i386::Ptrace - Ptrace for FreeBSD-i386

VERSION Id:Ptrace.pm,v0.12009/03/1412:45:27dankogaiExpdankogaiId: Ptrace.pm,v 0.1 2009/03/14 12:45:27 dankogai Exp dankogai Id:Ptrace.pm,v0.12009/03/1412:45:27dankogaiExpdankogai

SYNOPSIS # simple strace in perl use strict; use warnings; use FreeBSD::i386::Ptrace; use FreeBSD::i386::Ptrace::Syscall; die "$0 prog args ..." unless @ARGV; my $pid = fork(); die "fork failed:$!" if !defined($pid); if ($pid == 0){ # son pt_trace_me; exec @ARGV; }else{ mom wait; # for exec; my $count = 0; # odd on enter, even on leave my ($call, $retval);
while(pt_syscall($pid) == 0){ last if wait == -1; if (++$count & 1){ call=ptgetcall(call = pt_getcall(call=ptgetcall(pid); }else{ retval=ptgetcall(retval = pt_getcall(retval=ptgetcall(pid); my name=name = name=SYS{$call} || 'unknown'; warn "$name -> $retval";

        }
    }
    warn $count/2," system calls issued";
  }

EXPORT "ptrace", "pt_trace_me", "pt_attach", "pt_detach", "pt_syscall" "pt_getcall" "pt_kill" and PT_* constants.

for %SYS, use <FreeBSD::i386::Ptrace::Syscall>.

FUNCTIONS ptrace($request, pid,pid, pid,addr, $data) A thin wrapper to "2" in ptrace.

       #include <sys/types.h>
       #include <sys/ptrace.h>
       int
       ptrace(int request, pid_t pid, caddr_t addr, int data);

  All arguments are integer from perl.

pt_trace_me()
  Shortand for "ptrace(PT_TRACE_ME, 0, 0, 0)".

pt_attach($pid)
  Shortand for "ptrace(PT_ATTACH, pid, 0, 0)".

pt_detach($pid)
  Shortand for "ptrace(PT_DETACH, pid, 0, 0)".

pt_syscall($pid)
  Shortand for "ptrace(PT_SYSCALL, pid, 1, 0)". Unlike Linux the 3rd
  argument must be 1 or it loops infinitely.

  Note PT_SYSCALL is invoked both on entry to and return from the system
  call. See "SYNOPSIS" to see how to switch between them.

pt_getcall($pid)
  Returns the value of EAX register which holds the system call NUMBER
  on entry and the return value on return.
  "FreeBSD::i386::Ptrace::Syscall" and use %SYS.

    my $call = pt_getcall(pid);
    my <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi><mi>a</mi><mi>m</mi><mi>e</mi><mo>=</mo></mrow><annotation encoding="application/x-tex">name = %SYS{</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.4306em;"></span><span class="mord mathnormal">nam</span><span class="mord mathnormal">e</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span></span></span></span>call};

pt_kill($pid)
  Shortand for "ptrace(PT_KILL, $pid, 0, 0"; "ptrace", "pt_trace_me",
  "pt_attach", "pt_detach", "pt_syscall" "pt_getcall" "pt_kill" and PT_*
  constants.

AUTHOR Dan Kogai, ""

BUGS Please report any bugs or feature requests to "bug-freebsd-i386-ptrace at rt.cpan.org", or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=FreeBSD-i386-Ptrace. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT You can find documentation for this module with the perldoc command.

    perldoc FreeBSD::i386::Ptrace

You can also look for information at:

* RT: CPAN's request tracker
    <http://rt.cpan.org/NoAuth/Bugs.html?Dist=FreeBSD-i386-Ptrace>

* AnnoCPAN: Annotated CPAN documentation
    <http://annocpan.org/dist/FreeBSD-i386-Ptrace>

* CPAN Ratings
    <http://cpanratings.perl.org/d/FreeBSD-i386-Ptrace>

* Search CPAN
    <http://search.cpan.org/dist/FreeBSD-i386-Ptrace>

ACKNOWLEDGEMENTS Sys::Ptrace

COPYRIGHT & LICENSE Copyright 2009 Dan Kogai, all rights reserved.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.