pinktrace  Version 0.1.3
decode.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2010, 2011 Ali Polatel <alip@exherbo.org>
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. The name of the author may not be used to endorse or promote products
00014  *    derived from this software without specific prior written permission.
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00017  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00018  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00019  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00020  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00021  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00022  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00023  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00025  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  */
00027 
00028 #ifndef PINKTRACE_GUARD_DECODE_H
00029 #define PINKTRACE_GUARD_DECODE_H 1
00030 
00031 /**
00032  * \file
00033  * \brief Pink's system call decoders
00034  *
00035  * \ingroup g_decode
00036  **/
00037 
00038 #include <stdbool.h>
00039 #include <sys/types.h>
00040 
00041 #include <pinktrace/bitness.h>
00042 #include <pinktrace/gcc.h>
00043 #include <pinktrace/socket.h>
00044 
00045 #ifdef __cplusplus
00046 extern "C" {
00047 #endif /* __cplusplus */
00048 
00049 /**
00050  * Get the data in argument arg and place it in dest.
00051  *
00052  * \ingroup g_decode
00053  *
00054  * \param pid Process ID of the child whose argument is to be received.
00055  * \param bitness Bitness of the child
00056  * \param ind The index of the argument (0-5, see #PINK_MAX_INDEX)
00057  * \param dest Pointer to store the data
00058  * \param len Length of the data
00059  **/
00060 bool
00061 pink_decode_simple(pid_t pid, pink_bitness_t bitness, unsigned ind, void *dest, size_t len) PINK_GCC_ATTR((nonnull(4)));
00062 
00063 /**
00064  * Get the string argument and place it in dest.
00065  *
00066  * \ingroup g_decode
00067  *
00068  * \attention On FreeBSD this function is equivalent to pink_decode_simple().
00069  *
00070  * \param pid Process ID of the child whose argument is to be received.
00071  * \param bitness Bitness of the child
00072  * \param ind The index of the argument (0-5, see #PINK_MAX_INDEX)
00073  * \param dest Pointer to store the string
00074  * \param len Length of the string
00075  *
00076  * \return true on success, false on failure and sets errno accordingly.
00077  **/
00078 bool
00079 pink_decode_string(pid_t pid, pink_bitness_t bitness, unsigned ind, char *dest, size_t len) PINK_GCC_ATTR((nonnull(4)));
00080 
00081 /**
00082  * Like pink_decode_string() but allocates the string itself.
00083  *
00084  * \ingroup g_decode
00085  *
00086  * \return The path on success, NULL on failure and sets errno
00087  * accordingly.
00088  **/
00089 char *
00090 pink_decode_string_persistent(pid_t pid, pink_bitness_t bitness, unsigned ind) PINK_GCC_ATTR((malloc));
00091 
00092 /**
00093  * Decode the requested member of a NULL-terminated string array.
00094  *
00095  * \ingroup g_decode
00096  *
00097  * \param pid Process ID of the child
00098  * \param bitness Bitness of the child
00099  * \param arg The address of the argument, see pink_util_get_arg()
00100  * \param ind The index of the string in the array
00101  * \param dest Pointer to store the string
00102  * \param len Length of the string
00103  * \param nil If non-NULL, specifies the address of a boolean which can be
00104  * used to determine whether the member at the requested index is NULL or not.
00105  *
00106  * \return true on success, false on failure and sets errno accordingly.
00107  *
00108  * \since 0.0.3
00109  **/
00110 bool
00111 pink_decode_string_array_member(pid_t pid, pink_bitness_t bitness, long arg, unsigned ind, char *dest, size_t len, bool *nil) PINK_GCC_ATTR((nonnull(5)));
00112 
00113 /**
00114  * Like pink_decode_string_array_member() but allocates the string itself.
00115  *
00116  * \ingroup g_decode
00117  *
00118  * \attention If the array member is NULL, this function returns NULL but doesn't
00119  * modify errno. Check errno after the call to distinguish between success and
00120  * failure for a NULL return.
00121  *
00122  * \param pid Process ID of the child
00123  * \param bitness Bitness of the child
00124  * \param arg The address of the argument, see pink_util_get_arg()
00125  * \param ind The index of the string in the array
00126  *
00127  * \return The string on success, NULL on failure and sets errno accordingly.
00128  *
00129  * \since 0.0.3
00130  **/
00131 char *
00132 pink_decode_string_array_member_persistent(pid_t pid, pink_bitness_t bitness, long arg, unsigned ind) PINK_GCC_ATTR((malloc));
00133 
00134 #if defined(PINKTRACE_LINUX) || defined(DOXYGEN)
00135 /**
00136  * Decode the socket call and place it in call.
00137  *
00138  * \ingroup g_decode
00139  *
00140  * \note Availability: Linux
00141  * \note This function decodes the socketcall(2) system call on some
00142  * architectures. On others it's equivalent to pink_util_get_syscall().
00143  *
00144  * \see pink_socket_subcall_t
00145  *
00146  * \param pid Process ID of the child whose argument is to be received
00147  * \param bitness Bitness of the child
00148  * \param subcall The pointer to store the decoded socket call
00149  *
00150  * \return true on success, false on failure and sets errno accordingly.
00151  **/
00152 bool
00153 pink_decode_socket_call(pid_t pid, pink_bitness_t bitness, long *subcall) PINK_GCC_ATTR((nonnull(3)));
00154 
00155 /**
00156  * Get the socket file descriptor in argument arg and place it in fd.
00157  *
00158  * \ingroup g_decode
00159  *
00160  * \note Availability: Linux
00161  * \note This function decodes the socketcall(2) system call on some
00162  * architectures.
00163  *
00164  * \param pid Process ID of the child whose argument is to be received.
00165  * \param bitness Bitness of the child
00166  * \param ind The index of the argument (Only 0 makes sense)
00167  * \param fd The pointer to store the socket file descriptor
00168  *
00169  * \return true on success, false on failure and sets errno accordingly.
00170  **/
00171 bool
00172 pink_decode_socket_fd(pid_t pid, pink_bitness_t bitness, unsigned ind, long *fd) PINK_GCC_ATTR((nonnull(4)));
00173 #endif /* defined(PINKTRACE_LINUX)... */
00174 
00175 /**
00176  * Get the socket address and place it in paddr.
00177  *
00178  * \ingroup g_decode
00179  *
00180  * \note This function decodes the socketcall(2) system call on some
00181  * architectures.
00182  *
00183  * \note If the address argument of the system call was NULL, this function
00184  * returns true and sets addr->family to -1.
00185  *
00186  * \param pid Process ID of the child whose argument is to be received.
00187  * \param bitness Bitness of the child
00188  * \param ind The index of the argument. One of:
00189  *  - 1 (for connect, bind etc.)
00190  *  - 4 (for sendto)
00191  * \param fd The pointer to store the socket file descriptor that resides in
00192  * argument one with index zero. Set this to NULL if you don't need the file
00193  * descriptor to be decoded.
00194  * \param paddr The pointer to store the decoded socket address
00195  *
00196  * \return true on success, false on failure and sets errno accordingly.
00197  **/
00198 bool
00199 pink_decode_socket_address(pid_t pid, pink_bitness_t bitness, unsigned ind, long *fd, pink_socket_address_t *paddr) PINK_GCC_ATTR((nonnull(5)));
00200 
00201 #ifdef __cplusplus
00202 }
00203 #endif /* __cplusplus */
00204 
00205 #endif /* !PINKTRACE_GUARD_DECODE_H */