How to intercept system calls in JVM?

Hi, everyone. I am looking for a way to intercept system calls in JVM, a way do something like ptrace does in Linux. Because I wanna log all function calls a specified application made, and I may modify the arguments and the return value.
And then i search the internet but nothing found except this article:
[  http://java.sun.com/developer/technicalArticles/Programming/jvmti/#Authors|  http://java.sun.com/developer/technicalArticles/Programming/jvmti/#Authors]
It's seems that JVMTI is a perfect tools to manipulate Java VM and i can achieve my goal with it. I download the sample code you written and modify a bit to adopt my environment (I use Linux and Sun JDK 6). It works well.
And then I add a function to get stacktrace like the case in your article. I also read the sample code in JVMIT Refenerce, but it doesn't work.
So, I am puzzled. I wanna know is there any way to intercept system calls in JVM? If JVMTI can do it, is there any tutorial or sample code to review? And, is that possible to use this way in J2ME?
Thanks a lot :)
Best Regard.

jschell wrote:
Nelly_Zeltser wrote:
I do not know if there are any tools similar to solaris truss is available to trace system and library calls in j2me world.Well, I want to trace the jvm system calls to OS (UNIX), not java.Are you using j2me?No, to say more I'm not "using" java at all. My program (written on C) just monitors all system calls from another program that I define as the parameter.
It may not be java. It may be any program:for example my simple .o file made by myself.
Can we continue this topic at [http://forums.sun.com/thread.jspa?messageID=10746765&#10746765|http://forums.sun.com/thread.jspa?messageID=10746765&#10746765]
I've written my shared library and defined LD_PRELOAD. But it doesn't help, cuz JVM, afaik, uses LD_PRELOAD for its own purposes, so
I can't use my shared library.That of course is not what the poster of this thread wanted to do.

Similar Messages

  • Solaris 10: intercepting system calls

    Hello,
    I have a problem: I don't manage to intercept system calls (as described in this document http://packetstormsecurity.org/groups/thc/slkm-1.0.html). Is it because solaris 10 doesn't use the syscall table ?
    Another problem that I have is that I don't manage to perform a simple printf() on the screen when I use a load my kernel module. Has someone got an explanation ?
    In fact I need to intercept some syscall like SYS_open, SYS_read, ... to perform custom actions. Do you have another way to do this ?
    Thanks in advance for you help.

    BTW, I'm running 64-bit Solaris as a VirtualBox (3.0.10) guest VM on a 32-bit WinXP host.

  • How to make system call to execute command line in JAVA?

    Hi,
    I am new in JAVA. How to make system call to execute the following command line in JAVA in LINUX environment.
    rpm -qa jdkIn C programming, use as such:
    system ("rpm -qa jdk");
    How about JAVA?
    Thanks.

    Runtime.getRuntime().exec. But first read this:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • How to use system call in assembler

    I write codes to display the dictionary using C,
    and it can run well,and then I want to use system call
    in assembler to realize the same function ,but it doesn't
    display the dictionary,how to correct it?
    Look:
    //C
    #include <stdio.h>
    int main()
    char *name[2];
    name[0]="/bin/ls";
    name[1]=NULL;
    execve(name[0],name,NULL);
    return 0;
    //Assembler
    .data
    msg:.string "/bin/ls"
    .text
    .global _start
    _start:
    movl $0xb,%eax
    movl $msg,%ebx
    mov $msg,%ecx
    movl $0,%edx
    int $0x80
    movl $1,%eax
    movl $0,%ebx
    int $0x80

    If you compile with -Wwrite-strings, as I like to do for new code, you'll notice it warns about assigning the address of read-only memory to a plain char *. You might want to declare name as follows to avoid accidentally trying to modify it:
    char const *name[2];
    But as for your question. The execve system call requires a pointer to a list (array) of pointers to strings in %ecx. You are passing it a pointer to a single string, which means it will try to interpret the string ("/bin/ls")as a series of pointers to strings, with potentially disastrous (and certainly weird) results.
    Last edited by Trent (2012-12-28 15:31:38)

  • How to make system call remotely?

    i am working on client- server application i want to execute a system call on cllient machine from server how should i do it?

    If by "system call" you mean Runtime.exec(), then
    Runtime.getRuntime().exec(theCommand)The command needs to be sent from the client. And read this:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • How to access system calls from java program?

    i am having a doubt regarding accessing system calls from a Java program like accessing unix system calls from a c program.

    Runtime.getRuntime().exec("line command here");
    example:
    Runtime.getRuntime().exec("ls -la");

  • How to intercept RMI calls over JRMP?

    Hi,
    I would like intercept calls over RMI/JRMP to pass contextual data between client and server. I was able to do it for IIOP using Portable Interceptor but could not find any solution for JRMP.
    Is there any other way to implicitly pass data between client and server?
    Thanks,
    Kapil

    Not in JRMP. See JERI in the Jini project for an extensible protocol.
    If you want full-strength RMI proxying see http://www.rmiproxy.com and contact me via the links there for more information on recently-developed products that address this need.
    Esmond Pitt

  • How to intercept "System.exit"?

    I am writing a large GUI application that optionally spawns other GUI threads. These spawned threads are special-purpose text editors. It is important that the editor knows when it is about to be closed, so that it can prompt the user to save a modified file.
    The editors are based upon javax.swing.JFrame, and I have overridden the "windowClosing" method of a WindowAdapter to check file status and prompt when necessary. This method performs as desired when I close the editor window manually. However, when I close the main application (which calls System.exit(0) ), the editor frames also close without any invocation of my windowClosing method.
    Is there any way the dependent editor JFrame can be alerted that the virtual machine is about to be ended? I could probably keep a list in my main application of all the dependent processes that need to be cleanly ended, but it would be much simpler (and so much more object-oriented) if the dependent thread could take care of itself!

    MarkHausman wrote:
    As you suggested, I posted this question on the Swing forum.
    For those who are interested: the Swing solution I was offered was to make use of the static function Frame.getFrames(). This allows access to all frames launched by an application. By putting this call in my main shutdown method, I can identify all spawned editor frames and call each one's shutdown method.
    This is not as satisfying as my original desire, to have the spawned frame recognize when the VM is about to close, but it is easy enough to implement that I am going with it.And why wouldn't addShutdownHook() work?

  • Native System Calls

    How are native system calls done in Java?

    after reading the JNI tutorial, i think this is way to much to do just to perform a simple system call. anyone else know a simpler way to call up an executable program? linux or windows... it doesnt matter

  • How to get the size of physical memory by using system call ?

    how to get the size of physical memory by using system call ?What system call can be used for me to get the size of physical memor? thanks.

    %vmstat 3
    procs memory page disk faults cpu
    r b w swap free re mf pi po fr de sr s0 -- -- -- in sy cs us sy id
    0 0 0 3025816 994456 4 19 6 0 0 0 0 8 0 0 0 459 253 139 1 1 99
    0 0 0 2864688 777408 0 2 0 0 0 0 0 3 0 0 0 428 134 175 0 1 99
    0 0 0 2864688 777408 0 0 0 0 0 0 0 7 0 0 0 448 112 166 0 0 100
    one interesting observation about vmstat I found out is (mostly on Solaris)
    the first line of information always off chart, so I usually do a few interval to get constant result.
    if you use linux
    just
    cat /proc/meminfo

  • How can I use system call in kernel loadable module?

    Hi,
    I want to use system call (shmat, mmap,...) in kernel module.
    When kernel module is loaded, it cause system error (undefined symbol name 'shmat', 'mmap').
    How can I use system call in kernel module ?
    Thanks in advance.
    david joo

    You cannot use system calls in the kernel modules.
    Read 'Writing Device Drivers' answerbook - it lists the set of interfaces (known as DDI/DDK) that are supposed to be used instead.
    Hope this helps...
    --I.

  • How to add new system call in solaris ?

    Hi,
    I want to add new system call in solaris. please inform me steps for adding new system call in solaris.
    Thanks in advance,
    Mahantesh.

    Here's a Solaris 7 example I know there are others ...
    http://access1.sun.com/cgi-bin/rinfo2html?267899.faq
    I haven't seen a good example of how to support both the 32 and 63-bit environment.

  • Ownload the 30 day Captivate 8 trial. The download obviously didn't work and it's now stuck going nowhere in my system, calling itself "Resume Download etc". I've looked at all the trouble shooting pages to no avail. Anyone know how I can find a real pers

    I've just opened an Adobe ID and tried to download the 30 day Captivate 8 trial. The download obviously didn't work and it's now stuck going nowhere in my system, calling itself "Resume Download etc". I've looked at all the trouble shooting pages to no avail. Anyone know how I can find a real person to talk to about this?

    Try downloading the offline installer from http://prodesigntools.com/adobe-captivate-8-direct-download-links.html
    Make sure you follow the Very Important Instructions on that page.
    You can Contact Customer Care - click on the Still need help? button to talk or chat with an agent.

  • How to get swap size by using system call?

    How can I get the size of swap.What system call or library Routines can be used? please help me.

    Hi,
    Threre's an interface called swap_ctl by wich you can get more information related to virtual memory. Here's an example:
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <sys/stat.h>
    #include <sys/swap.h>
    #include <sys/param.h>
    int
    main(int argc, char*argv[])
    swaptbl_t *st;
    int swap_count, i;
    long long swap_total=0, swap_avail=0;
    long pgsize_in_kbytes = sysconf(_SC_PAGE_SIZE) / 1024L;
    if ((swap_count=swapctl(SC_GETNSWP, NULL)) == -1)
    perror("swapctl(SC_GETNSWP)"), exit(-1);
    if (swap_count == 0)
    (void)printf("No swap files/partitions allocated\n"), exit(0);
    * Although it's not particularly clear in the documentation, you're
    * responsible for creating a variable length structure (ie. the
    * array is within the struct rather than being pointed to
    * by the struct). Also, it is necessary for you to allocate space
    * for the path strings (see /usr/include/sys/swap.h).
    st = (swaptbl_t*)malloc(sizeof(int) + swap_count * sizeof(struct swapent));
    if (st == NULL)
    perror(argv[0]), exit(-1);
    st->swt_n = swap_count;
    for (i=0; i < swap_count; i++) {
    if ((st->swt_ent.ste_path = (char*)malloc(MAXPATHLEN)) == NULL)
    perror(argv[0]), exit(-1);
    if ((swap_count=swapctl(SC_LIST, (void*)st)) == -1)
    perror("swapctl(SC_LIST)"), exit(-1);
    for (i=0; i < swap_count; i++) {
    swap_total += st->swt_ent.ste_pages * pgsize_in_kbytes;
    swap_avail += st->swt_ent.ste_free * pgsize_in_kbytes;
    (void)printf("Total swap = %lld available swap = %lld\n",
    swap_total, swap_avail);
    return 0;
    There's a very interesting document about Solaris Kernel/Performance Stats available at http://www.idiom.com/~gford/admin/howto/perf.html. Very interesting.
    Hope this helps

  • How to get physical memory by using system call ?

    how to get physical memory by using system call ?What system call can I use.thanks

    Use sysconf(3C) with SCPHYS_PAGES

Maybe you are looking for

  • Substitution variable Issue

    How to call substitution variable from calculation script?

  • Civil Identity Number Format Mask

    Dears, I Need to change the Format Mask for the Civil Identity Number In The People Enter And Maintain Form Any Idea How Can I Do That ? Thanks in Advance. BR,

  • Can I have separate Style Formatting for viewing and sending emails?

    Hey All I was just wondering if it was possible to have separate style settings for viewing emails sent to you and sending emails to others. Basically I want to set up a kind of style template for all my outgoing emails but I don't necessarily want m

  • Adjustments & Web Gallery

    When creating a web gallery the images that I have made adjustments to are not visible, only the master image is in the web gallery. I have selected the adjustment versions but none of them translate to the gallery. Please help.

  • System partition

    Hi, Could any body help, regarding how to make system partition. I have 3000N200 B2G model. Also I would like to downgrade to windows XP. Is it possilble in this model. Please help me. Thanks Shan