コード例 #1
0
ファイル: engine.cpp プロジェクト: mklauber/python-ssdeep
bool display_result(state *s, const TCHAR * fn, const char * sum)
{
  // Only spend the extra time to make a Filedata object if we need to
  if (MODE(mode_match_pretty) or MODE(mode_match) or MODE(mode_directory))
  {
    Filedata * f;

    try 
    {
      f = new Filedata(fn, sum);
    } 
    catch (std::bad_alloc)
    {
      fatal_error("%s: Unable to create Filedata object in engine.cpp:display_result()", __progname);
    }

    if (MODE(mode_match_pretty)) 
    {
      if (match_add(s,f))
	print_error_unicode(s,fn,"Unable to add hash to set of known hashes");
    }
    else
    {
      // This block is for MODE(mode_match) or MODE(mode_directory)
      match_compare(s,f);

      if (MODE(mode_directory))
	if (match_add(s,f))
	  print_error_unicode(s,
			      fn,
			      "Unable to add hash to set of known hashes");
    }
  }
  else
  {
    // No special options selected. Display the hash for this file
    if (s->first_file_processed)
    {
      print_status("%s", OUTPUT_FILE_HEADER);
      s->first_file_processed = false;
    }

    printf ("%s,\"", sum);
    display_filename(stdout,fn,TRUE);
    print_status("\"");
  }

  return false;
}
コード例 #2
0
ファイル: match.cpp プロジェクト: chrisoei/ssdeep
bool match_load(state *s, const char *fn)
{
  if (NULL == s or NULL == fn)
    return true;

  if (sig_file_open(s,fn))
    return true;

  bool status;

  do 
  {
    Filedata * f; 
    status = sig_file_next(s,&f);
    if (not status)
    {
      if (match_add(s,f))
      {
	// One bad hash doesn't mean this load was a failure.
	// We don't change the return status because match_add failed.
	print_error(s,"%s: unable to insert hash", fn);
	break;
      }
    }
  } while (not sig_file_end(s));

  sig_file_close(s);

  return false;
}
コード例 #3
0
ファイル: trace_tree.c プロジェクト: hchunhui/pop
static int emit_rule(struct xswitch *sw, struct flow_table *ft,
		     struct trace_tree *tree, struct match *ma, int priority,
		     struct action *ac_pi)
{
	int i;
	struct trace_tree_L *tl;
	struct trace_tree_V *tv;
	struct trace_tree_T *tt;
	struct trace_tree_D *td;
	struct trace_tree_G *tg;

	struct msgbuf *msg;
	struct match *maa;
	struct action *a;
	char buf[128], buf2[128];

	struct expr *move_expr;
	switch(tree->type) {
	case TT_L:
		tl = (struct trace_tree_L *)tree;
		match_dump(ma, buf, 128);
		action_dump(tl->ac, buf2, 128);
		xdebug("tid %d: %2d, %s, %s\n",
		       flow_table_get_tid(ft), priority, buf, buf2);
		if(tl->index == -1) {
			tl->index = flow_table_get_entry_index(ft);
			msg = msg_flow_entry_add(ft, tl->index, priority, ma, tl->ac);
		} else {
			msg = msg_flow_entry_mod(ft, tl->index, priority, ma, tl->ac);
		}
		xswitch_send(sw, msg);
		return priority + 1;
	case TT_V:
		tv = (struct trace_tree_V *)tree;
		for(i = 0; i < tv->num_branches; i++) {
			maa = match_copy(ma);
			match_add(maa,
				  tv->name,
				  tv->branches[i].value,
				  value_from_64(0xffffffffffffffffull));
			priority = emit_rule(sw, ft, tv->branches[i].tree, maa, priority, ac_pi);
			match_free(maa);
		}
		return priority;
	case TT_T:
		tt = (struct trace_tree_T *)tree;
		priority = emit_rule(sw, ft, tt->f, ma, priority, ac_pi);
		maa = match_copy(ma);
		match_add(maa,
			  tt->name,
			  tt->value,
			  value_from_64(0xffffffffffffffffull));
		action_dump(ac_pi, buf, 128);
		xdebug("tid %d: %2d, BARRIER, %s\n",
		       flow_table_get_tid(ft), priority, buf);
		if(tt->barrier_index == -1) {
			tt->barrier_index = flow_table_get_entry_index(ft);
			msg = msg_flow_entry_add(ft, tt->barrier_index, priority, maa, ac_pi);
		} else {
			msg = msg_flow_entry_mod(ft, tt->barrier_index, priority, maa, ac_pi);
		}
		xswitch_send(sw, msg);
		priority = emit_rule(sw, ft, tt->t, maa, priority + 1, ac_pi);
		match_free(maa);
		return priority;
	case TT_G:
		tg = (struct trace_tree_G *)tree;
		if(tg->ft == NULL) {
			int tid = sw->next_table_id++;
			// add a new table
			tg->ft = header_make_flow_table(tg->new_spec, tid);
			msg = msg_flow_table_add(tg->ft);
			xswitch_send(sw, msg);
			init_entry(sw, tg->ft);
		}
		// insert GOTO_TABLE into orig table
		a = action();
		if(tg->old_spec)
			move_expr = header_get_length(tg->old_spec);
		else
			move_expr = expr_value(0);
		expr_generate_action(move_expr, tg->old_spec, tg->ft, tg->stack_base, a);

		match_dump(ma, buf, 128);
		action_dump(a, buf2, 128);
		xdebug("tid %d: %2d, %s, %s\n",
		       flow_table_get_tid(ft), priority, buf, buf2);

		if(tg->index == -1) {
			tg->index = flow_table_get_entry_index(ft);
			msg = msg_flow_entry_add(ft, tg->index, priority, ma, a);
		} else {
			msg = msg_flow_entry_mod(ft, tg->index, priority, ma, a);
		}
		xswitch_send(sw, msg);
		action_free(a);

		maa = match();
		emit_rule(sw, tg->ft, tg->t, maa, 1, ac_pi);
		match_free(maa);
		return priority + 1;
	case TT_D:
		td = (struct trace_tree_D *)tree;
		return emit_rule(sw, ft, td->t, ma, priority, ac_pi);
	case TT_E:
		return priority;
	}
	assert(0);
}
コード例 #4
0
ファイル: trace_tree.c プロジェクト: hchunhui/pop
static int json_printer_ft(char *buf, int pos,
			   struct trace_tree *tree, struct match *ma, int *priority,
			   struct action *ac_pi, struct header *h)
{
	int i;
	struct trace_tree_L *tl;
	struct trace_tree_V *tv;
	struct trace_tree_T *tt;
	struct trace_tree_D *td;
	struct trace_tree_G *tg;

	struct match *maa;
	struct action *a;
	char buf2[128];

	struct expr *move_expr;
	switch(tree->type) {
	case TT_L:
		tl = (struct trace_tree_L *)tree;
		pos = json_printer_fe(buf, pos, *priority, h, ma, tl->ac);
		(*priority)++;
		return pos;
	case TT_V:
		tv = (struct trace_tree_V *)tree;
		for(i = 0; i < tv->num_branches; i++) {
			maa = match_copy(ma);
			match_add(maa,
				  tv->name,
				  tv->branches[i].value,
				  value_from_64(0xffffffffffffffffull));
			pos = json_printer_ft(buf, pos, tv->branches[i].tree, maa, priority, ac_pi, h);
			match_free(maa);
		}
		return pos;
	case TT_T:
		tt = (struct trace_tree_T *)tree;
		pos = json_printer_ft(buf, pos, tt->f, ma, priority, ac_pi, h);
		maa = match_copy(ma);
		match_add(maa,
			  tt->name,
			  tt->value,
			  value_from_64(0xffffffffffffffffull));
		pos = json_printer_fe(buf, pos, *priority, h, maa, ac_pi);
		(*priority)++;
		pos = json_printer_ft(buf, pos, tt->t, maa, priority, ac_pi, h);
		match_free(maa);
		return pos;
	case TT_G:
		tg = (struct trace_tree_G *)tree;
		// insert GOTO_TABLE into orig table
		a = action();
		if(tg->old_spec)
			move_expr = header_get_length(tg->old_spec);
		else
			move_expr = expr_value(0);
		expr_generate_action(move_expr, tg->old_spec, tg->ft, tg->stack_base, a);

		action_dump(a, buf2, 128);
		pos = json_printer_fe(buf, pos, *priority, h, ma, a);
		action_free(a);
		(*priority)++;
		return pos;
	case TT_D:
		td = (struct trace_tree_D *)tree;
		return json_printer_ft(buf, pos, td->t, ma, priority, ac_pi, h);
	case TT_E:
		return pos;
	}
	assert(0);
}
コード例 #5
0
ファイル: test-bus-match.c プロジェクト: arthur-c/systemd
int main(int argc, char *argv[]) {
    struct bus_match_node root = {
        .type = BUS_MATCH_ROOT,
    };

    _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
    _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
    enum bus_match_node_type i;
    sd_bus_slot slots[19];
    int r;

    r = sd_bus_open_system(&bus);
    if (r < 0)
        return EXIT_TEST_SKIP;

    assert_se(match_add(slots, &root, "arg2='wal\\'do',sender='foo',type='signal',interface='bar.x',", 1) >= 0);
    assert_se(match_add(slots, &root, "arg2='wal\\'do2',sender='foo',type='signal',interface='bar.x',", 2) >= 0);
    assert_se(match_add(slots, &root, "arg3='test',sender='foo',type='signal',interface='bar.x',", 3) >= 0);
    assert_se(match_add(slots, &root, "arg3='test',sender='foo',type='method_call',interface='bar.x',", 4) >= 0);
    assert_se(match_add(slots, &root, "", 5) >= 0);
    assert_se(match_add(slots, &root, "interface='quux.x'", 6) >= 0);
    assert_se(match_add(slots, &root, "interface='bar.x'", 7) >= 0);
    assert_se(match_add(slots, &root, "member='waldo',path='/foo/bar'", 8) >= 0);
    assert_se(match_add(slots, &root, "path='/foo/bar'", 9) >= 0);
    assert_se(match_add(slots, &root, "path_namespace='/foo'", 10) >= 0);
    assert_se(match_add(slots, &root, "path_namespace='/foo/quux'", 11) >= 0);
    assert_se(match_add(slots, &root, "arg1='two'", 12) >= 0);
    assert_se(match_add(slots, &root, "member='waldo',arg2path='/prefix/'", 13) >= 0);
    assert_se(match_add(slots, &root, "member=waldo,path='/foo/bar',arg3namespace='prefix'", 14) >= 0);
    assert_se(match_add(slots, &root, "arg4has='pi'", 15) >= 0);
    assert_se(match_add(slots, &root, "arg4has='pa'", 16) >= 0);
    assert_se(match_add(slots, &root, "arg4has='po'", 17) >= 0);
    assert_se(match_add(slots, &root, "arg4='pi'", 18) >= 0);

    bus_match_dump(&root, 0);

    assert_se(sd_bus_message_new_signal(bus, &m, "/foo/bar", "bar.x", "waldo") >= 0);
    assert_se(sd_bus_message_append(m, "ssssas", "one", "two", "/prefix/three", "prefix.four", 3, "pi", "pa", "po") >= 0);
    assert_se(bus_message_seal(m, 1, 0) >= 0);

    zero(mask);
    assert_se(bus_match_run(NULL, &root, m) == 0);
    assert_se(mask_contains((unsigned[]) {
        9, 8, 7, 5, 10, 12, 13, 14, 15, 16, 17
    }, 11));