Exemple #1
0
static void			exec_strace(pid_t pid,
					    int sys,
					    int was_sys,
					    long ret)
{
  struct user_regs_struct	reg;

  while (ptrace(PTRACE_SINGLESTEP, pid, NULL, NULL) != -1)
    {
      my_wait(pid);
      if (ptrace(PTRACE_GETREGS, pid, NULL, ((void *)(&reg))) != -1)
	{
	  if ((ret = ptrace(PTRACE_PEEKTEXT, pid, ((void *)(reg.rip)), NULL))
	      == -1)
	    exit(dprintf(2, "ptrace(PREACE_PEEKTEXT Failed\n"));
	  else
	    {
	      if (was_sys == 1 && ((was_sys -= 1) == 0))
		print_ret(&g_arg[sys], reg.rax, pid);
	      else
		{
		  ret &= 0x000000000000ffff;
		  if ((ret == 0x050FU || ret == 0x80CDU || ret == 0x340FU)
		      && ((++was_sys) == 1))
		    moulitrixdecon(&sys, reg, pid);
		}
	    }
	}
    }
}
void
produce(void) {
  num_t i = 0;
  num_t len = 1 << n;
  for (; i < len; i++) {
    num_t mi = 0;
    num_t ok = 1;
    for (; mi < m && ok; mi++) {
      printf("%llX", i);
      printf(" %llX", mem[mi].act);
      printf(" %llX,", mem[mi].rej);
      printf(" %s", (mem[mi].act & i) != 0 ? "t" : "f");
      printf(" %s\n", (mem[mi].rej & i) == 0 ? "t" : "f");
      fflush(stdout);
      if ((mem[mi].act & i) != 0 || (mem[mi].rej != 0 && (mem[mi].rej & i) == 0)) {
        // it's ok
      } else {
        ok = 0;
      }
    }
    if (ok) {
      print_ret(i);
      return;
    } else {
      //print_ret(i);
    }
  }
  printf("NO\n");
}
static void
handle_sigtrap(struct child *son)
{
	long scno, ret;
	const char *scname;

	/* We get this event twice, one at entering a
	 * system call and one at exiting a system
	 * call. */
	if (son->insyscall) {
		if (!pink_util_get_return(son->pid, &ret))
			err(1, "pink_util_get_return");
		if (son->inexecve) {
			son->inexecve = false;
			if (ret == 0) { /* execve was successful */
				/* Update bitness */
				son->bitness = pink_bitness_get(son->pid);
				if (son->bitness == PINK_BITNESS_UNKNOWN)
					err(1, "pink_bitness_get");
				printf(" = 0 (Updating the bitness of child %i to %s mode)\n",
					son->pid, pink_bitness_name(son->bitness));
				son->printret = false;
				return;
			}
		}
		son->insyscall = false;
		if (!son->printret) {
			son->printret = true;
			return;
		}
		/* Exiting the system call, print the
		 * return value. */
		putchar(' ');
		print_ret(ret);
		putchar('\n');
	}
	else {
		son->insyscall = true;
		/* Get the system call number and call
		 * the appropriate decoder. */
		if (!pink_util_get_syscall(son->pid, son->bitness, &scno))
			err(1, "pink_util_get_syscall");
		scname = pink_name_syscall(scno, son->bitness);
		assert(scname != NULL);

		if (!strcmp(scname, "execve"))
			son->inexecve = true;

		if (!strcmp(scname, "open"))
			decode_open(son->pid, son->bitness);
		else if (!strcmp(scname, "execve"))
			decode_execve(son->pid, son->bitness);
		else if (!strcmp(scname, "bind") || !strcmp(scname, "connect"))
			decode_socketcall(son->pid, son->bitness, scname);
		else
			printf("%s()", scname);
	}
}
/* Parse a message action. */
int
dm_message_parse(const char *caller, struct dm_msg *msg, void *context,
		 int argc, char **argv)
{
	int hit = 0;
	size_t l1 = strlen(*argv), l_hit = 0;
	struct dm_msg_spec *s, *s_hit = NULL,
			   *s_end = msg->specs + msg->num_specs;

	if (argc < 2)
		return -EINVAL;

	for (s = msg->specs; s < s_end; s++) {
		size_t l2 = strlen(s->cmd);

		if (!strnicmp(*argv, s->cmd, min(l1, l2))) {
			hit++;
			l_hit = l2;
			s_hit = s;
		}
	}

	msg->ret = 0;
	if (!hit || l1 > l_hit)	/* No hit or message string too long. */
		set_bit(dm_msg_ret_undef, &msg->ret);
	else if (hit > 1)	/* Ambiguous message. */
		set_bit(dm_msg_ret_ambiguous, &msg->ret);
	else if (argc - 2 != s_hit->args->num_args) {
		set_bit(dm_msg_ret_undef, &msg->ret);
		set_bit(dm_msg_ret_argcount, &msg->ret);
	}

	if (msg->ret)
		goto bad;

	msg->action = 0;
	msg->spec = s_hit;
	set_bit(s_hit->action, &msg->action);
	message_options_parse(msg, --argc, ++argv);

	if (!msg->ret)
		return msg->spec->f(msg, context);

   bad:
	print_ret(caller, msg->ret);
	return -EINVAL;
}
static void
handle_syscall(struct child *son)
{
	long scno;
	const char *scname;

	/* We get this event twice, one at entering a
	 * system call and one at exiting a system
	 * call. */
	if (son->insyscall) {
		/* Exiting the system call, print the
		 * return value. */
		son->insyscall = false;
		putchar(' ');
		print_ret(son->pid);
		putchar('\n');
	}
	else {
		/* Get the system call number and call
		 * the appropriate decoder. */
		son->insyscall = true;
		if (!pink_util_get_syscall(son->pid, son->bitness, &scno)) {
			perror("pink_util_get_syscall");
			return;
		}
		scname = pink_name_syscall(scno, son->bitness);
		if (!scname)
			printf("%ld()", scno);
		else if (!strcmp(scname, "open"))
			decode_open(son->pid, son->bitness);
		else if (!strcmp(scname, "execve"))
			decode_execve(son->pid, son->bitness);
		else if (!strcmp(scname, "socketcall") || !strcmp(scname, "bind") || !strcmp(scname, "connect"))
			decode_socketcall(son->pid, son->bitness, scname);
		else
			printf("%s()", scname);
	}
}
Exemple #6
0
/**
 * This test HyperSQL client uses the ODBC DSN "tstdsn" to connect up to a
 * HyperSQL server.  Just configure your own DSN to use the HyperSQL ODBC
 * driver, specifying the HyperSQL server host name, database name, user,
 * password, etc.
 *
 * Sample C program accessing HyperSQL.
 *
 * ODBC C API ref at
 *  http://msdn.microsoft.com/en-us/library/ms714562(VS.85).aspx .
 * Summary of functions at
 *  http://msdn.microsoft.com/en-us/library/ms712628(VS.85).aspx
 *
 * To build on UNIX with unixODBC:<PRE><CODE>
 *     gcc -lodbc -o sample sample.c
 * </CODE></PRE>
 *
 * To build in Windows with MSVC++ (Express variant is free):<PRE><CODE>
 *      cl /nologo /D _WINDOWS /D ODBCVER=0x0351 /c sample.c
 *      link odbc32.lib /nologo /machine:x86 sample.obj /out:sample.exe
 * </CODE></PRE>
 *
 * @author Blaine Simpson (blaine dot simpson at admc dot com)
 */
int main(int argc, char** argv) {
    SQLRETURN odbcret;
    SQLHENV sqlhenv;
    SQLHENV conn;
    SQLHSTMT stmt;
    char *cp;
    long in_idval;
    const int cstrmax = 100;
    char *in_vcval = malloc(cstrmax);
    long out_idval;
    char *out_vcval = malloc(cstrmax);
    char *out_etimeval = malloc(cstrmax);
    SQLLEN ntsval = SQL_NTS;
    int detect;

    // I. CONNECT
    odbcret = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &sqlhenv);
    if (odbcret != SQL_SUCCESS && odbcret != SQL_SUCCESS_WITH_INFO)
        return print_ret("Failed to allocate an ODBC environment handle", 1);

    odbcret =
        SQLSetEnvAttr(sqlhenv, SQL_ATTR_ODBC_VERSION, (void*) SQL_OV_ODBC3, 0);
    if (odbcret != SQL_SUCCESS && odbcret != SQL_SUCCESS_WITH_INFO)
        return print_ret("Failed to set ODBC version 3.0", 2);

    odbcret = SQLAllocHandle(SQL_HANDLE_DBC, sqlhenv, &conn);
    if (odbcret != SQL_SUCCESS && odbcret != SQL_SUCCESS_WITH_INFO)
        return print_ret("Failed to allocate an ODBC connection handle", 3);

    odbcret = SQLSetConnectAttr(
            conn, SQL_ATTR_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF, 0);
    if (odbcret != SQL_SUCCESS && odbcret != SQL_SUCCESS_WITH_INFO)
        return print_ret("Failed to allocate an ODBC connection handle", 3);
    // May also want to set timeout values in the same way

    // Can override the DSN-defined user name and/or password here:
    detect = detectOdbcFailure(
            SQLConnect(conn, (SQLCHAR*) "tstdsn", SQL_NTS, (SQLCHAR*) NULL, 0,
                (SQLCHAR*) NULL, 0),
            conn, "Connection failure");
    if (detect) return detect;


    // II. PREPARE OBJECTS FOR USE
    detect = detectOdbcFailure(
            SQLAllocHandle(SQL_HANDLE_STMT, conn, &stmt), conn,
            "Failed to allocate an ODBC statement handle");
    if (detect) return detect;

    // Just using this char pointer because some non-ANSI compilers won't let
    // us declare a char array/pointer here.
    cp = "DROP TABLE tsttbl IF EXISTS";
    detect = detectOdbcFailure(SQLExecDirect(stmt, cp, SQL_NTS), conn,
            "DROP statement failed");
    if (detect) return detect;

    // Some recent change to the HyperSQL server or to unixODBC
    // has made this commit necessary, at least on UNIX.  Some other
    // transaction control command would probably be more
    // appropriate here.
    detect = detectOdbcFailure(SQLEndTran(SQL_HANDLE_DBC, conn, SQL_COMMIT),
            conn, "COMMIT failed");
    if (detect) return detect;

    cp = "CREATE TABLE tsttbl(\n\
    id BIGINT generated BY DEFAULT AS IDENTITY,\n\
    vc VARCHAR(20),\n\
    entrytime TIMESTAMP DEFAULT current_timestamp NOT NULL\n\
)";
    detect = detectOdbcFailure(SQLExecDirect(stmt, cp, SQL_NTS), conn,
            "CREATE TABLE statement failed");
    if (detect) return detect;

    detect = detectOdbcFailure(SQLCloseCursor(stmt), conn,
            "Failed to close Cursor for re-use");
    if (detect) return detect;


    // III. INSERT DATA
    // Non-parameter INSERT
    cp = "INSERT INTO tsttbl (id, vc) values (1, 'one')";
    detect = detectOdbcFailure(SQLExecDirect(stmt, cp, SQL_NTS), conn,
            "1st Insertion failed");
    if (detect) return detect;

#ifdef _WINDOWS
    // TODO:  PROBLEM with Parameterized INPUT in Windows (works fine on UNIX).
    // For some reason, even if we are do a Prepare/Execute (and our
    // driver is set to always use server-side Preparation), the client side
    // is doing the substitution... and doing a bad Lob of it too.
    // Therefore, we do all INSERTs statically for Windows here:
    cp = "INSERT INTO tsttbl (id, vc) values (2, 'two')";
    detect = detectOdbcFailure(SQLExecDirect(stmt, cp, SQL_NTS), conn,
            "2nd Insertion failed");
    if (detect) return detect;
    cp = "INSERT INTO tsttbl (id, vc) values (3, 'three')";
    detect = detectOdbcFailure(SQLExecDirect(stmt, cp, SQL_NTS), conn,
            "3rd Insertion failed");
    if (detect) return detect;
    cp = "INSERT INTO tsttbl (id, vc) values (4, 'four')";
    detect = detectOdbcFailure(SQLExecDirect(stmt, cp, SQL_NTS), conn,
            "4th Insertion failed");
    if (detect) return detect;
    cp = "INSERT INTO tsttbl (id, vc) values (5, 'five')";
    detect = detectOdbcFailure(SQLExecDirect(stmt, cp, SQL_NTS), conn,
            "5th Insertion failed");
    if (detect) return detect;
#else
    // Parameterized INSERT
    cp = "INSERT INTO tsttbl (id, vc) values (?, ?)";
    detect = detectOdbcFailure(SQLPrepare(stmt, (SQLCHAR*) cp, SQL_NTS), conn,
        "Preparation of Insertion stmt failed");
    if (detect) return detect;
    detect = detectOdbcFailure(
            SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_BIGINT,
            0, 0, &in_idval, 0, NULL), conn,
            "Bind of 'id' input failed");
    if (detect) return detect;
    detect = detectOdbcFailure(
            SQLBindParameter(stmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR,
            20, 0, in_vcval, cstrmax, &ntsval), conn,
            "Bind of 'vc' input failed");
    if (detect) return detect;

    in_idval = 2;
    strcpy(in_vcval, "two");
    detect = detectOdbcFailure(SQLExecute(stmt), conn,
            "Insertion of 2nd row failed");
    if (detect) return detect;
    in_idval = 3;
    strcpy(in_vcval, "three");
    detect = detectOdbcFailure(SQLExecute(stmt), conn,
            "Insertion of 3rd row failed");
    if (detect) return detect;
    in_idval = 4;
    strcpy(in_vcval, "four");
    detect = detectOdbcFailure(SQLExecute(stmt), conn,
            "Insertion of 4th row failed");
    if (detect) return detect;
    in_idval = 5;
    strcpy(in_vcval, "five");
    detect = detectOdbcFailure(SQLExecute(stmt), conn,
            "Insertion of 5th row failed");
    if (detect) return detect;
#endif

    detect = detectOdbcFailure(SQLEndTran(SQL_HANDLE_DBC, conn, SQL_COMMIT),
            conn, "COMMIT failed");
    if (detect) return detect;
    
    detect = detectOdbcFailure(SQLCloseCursor(stmt), conn,
            "Failed to close Cursor for re-use");
    if (detect) return detect;


    // IV. QUERIES
    // Non-Parameter QUERY
    cp = "SELECT * FROM tsttbl WHERE id < 3";
    detect = detectOdbcFailure(SQLExecDirect(stmt, cp, SQL_NTS), conn,
            "Non-parameter query failed");
    // Would return SQL_NO_DATA if no rows inserted.
    // Don't need to bind until before fetches are performed.
    if (detect) return detect;
    detect = detectOdbcFailure(
            SQLBindCol(stmt, 1, SQL_C_SLONG, &out_idval, 0, NULL), conn,
            "Bind of 'id' output failed");
    if (detect) return detect;
    detect = detectOdbcFailure(
            SQLBindCol(stmt, 2, SQL_C_CHAR, out_vcval, cstrmax, &ntsval),
            conn, "Bind of 'vc' output failed");
    if (detect) return detect;
    detect = detectOdbcFailure(
            SQLBindCol(stmt, 3, SQL_C_CHAR, out_etimeval, cstrmax, &ntsval),
            conn, "Bind of 'entrytime' output failed");
    if (detect) return detect;

    while ((odbcret = SQLFetch(stmt)) != SQL_NO_DATA) {
        if (detectOdbcFailure(odbcret, conn, "Fetch failed")) return detect;
        printf("%dl|%s|%s\n", out_idval, out_vcval, out_etimeval);
    }
    
    detect = detectOdbcFailure(SQLCloseCursor(stmt), conn,
            "Failed to close Cursor for re-use");
    if (detect) return detect;

#if _WINDOWS
    // Input parameters not working on Windows.  See comment above.
    cp = "SELECT * FROM tsttbl WHERE id > 3";
    detect = detectOdbcFailure(SQLExecDirect(stmt, cp, SQL_NTS), conn,
            "Non-parameter query failed");
    // Would return SQL_NO_DATA if no rows inserted.
    // Don't need to bind until before fetches are performed.
    if (detect) return detect;
    detect = detectOdbcFailure(
            SQLBindCol(stmt, 1, SQL_C_SLONG, &out_idval, 0, NULL), conn,
            "Bind of 'id' output failed");
    if (detect) return detect;
    detect = detectOdbcFailure(
            SQLBindCol(stmt, 2, SQL_C_CHAR, out_vcval, cstrmax, &ntsval),
            conn, "Bind of 'vc' output failed");
    if (detect) return detect;
    detect = detectOdbcFailure(
            SQLBindCol(stmt, 3, SQL_C_CHAR, out_etimeval, cstrmax, &ntsval),
            conn, "Bind of 'entrytime' output failed");
    if (detect) return detect;

    while ((odbcret = SQLFetch(stmt)) != SQL_NO_DATA) {
        if (detectOdbcFailure(odbcret, conn, "Fetch failed")) return detect;
        printf("%dl|%s|%s\n", out_idval, out_vcval, out_etimeval);
    }
#else

    // Parameterized QUERY
    cp = "SELECT * FROM tsttbl WHERE id > ?";
    detect = detectOdbcFailure(SQLPrepare(stmt, (SQLCHAR*) cp, SQL_NTS), conn,
        "Preparation of Query stmt failed");
    if (detect) return detect;
    in_idval = 3;
    detect = detectOdbcFailure(
            SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_BIGINT,
            0, 0, &in_idval, 0, NULL), conn,
            "Bind of 'id' input failed");
    if (detect) return detect;
    detect = detectOdbcFailure(SQLExecute(stmt), conn,
            "Parameterized query failed");
    // Would return SQL_NO_DATA if no rows selected
    // Don't need to bind until before fetches are performed.
    if (detect) return detect;
    detect = detectOdbcFailure(
            SQLBindCol(stmt, 1, SQL_C_SLONG, &out_idval, 0, NULL), conn,
            "Bind of 'id' output failed");
    if (detect) return detect;
    detect = detectOdbcFailure(
            SQLBindCol(stmt, 2, SQL_C_CHAR, out_vcval, cstrmax, &ntsval),
            conn, "Bind of 'vc' output failed");
    if (detect) return detect;
    detect = detectOdbcFailure(
            SQLBindCol(stmt, 3, SQL_C_CHAR, out_etimeval, cstrmax, &ntsval),
            conn, "Bind of 'entrytime' output failed");
    if (detect) return detect;
#endif

    while ((odbcret = SQLFetch(stmt)) != SQL_NO_DATA) {
        if (detectOdbcFailure(odbcret, conn, "Fetch failed")) return detect;
        printf("%dl|%s|%s\n", out_idval, out_vcval, out_etimeval);
    }
    
    detect = detectOdbcFailure(SQLCloseCursor(stmt), conn,
            "Failed to close Cursor");
    if (detect) return detect;

    SQLDisconnect(conn);
    SQLFreeHandle(SQL_HANDLE_DBC, conn);
    SQLFreeHandle(SQL_HANDLE_ENV, sqlhenv);
    //return print_ret("Success", 0);
    return 0;
}