예제 #1
0
파일: symbol.c 프로젝트: psilord/manifold
/* take all of the symbols in the list, and concatenate them together producing
	a higher dimensional symbol. */
Symbol* symbol_abstract(Symbol **list, int num)
{
	int i, j;
	int tindex;
	Symbol *abstraction;
	int abstraction_dimension = 0;

	/* figure out what the newly created symbol's abstraction dimension is
		going to be. */
	for (i = 0; i < num; i++)
	{
		abstraction_dimension += list[i]->dim;
	}
	
	/* make it */
	abstraction = symbol_init(abstraction_dimension);

	/* perform the merge */
	tindex = 0;
	/* copy each piece out of the list into the abstraction symbol preserving
		the order of the list in the abstraction symbol */
	for (i = 0; i < num; i++)
	{
		for (j = 0; j < list[i]->dim; j++)
		{
			abstraction->vec[tindex] = list[i]->vec[j];
			tindex++;
		}
	}

	return abstraction;
}
예제 #2
0
const char* get_symbol_str(const char* symname)
{
    char*       tmp;
    const char* ret;

    if (!symname) return "(nil)";
    if (globals.do_demangle)
    {
        parsed_symbol   symbol;

        symbol_init(&symbol, symname);
        if (!symbol_demangle(&symbol))
            ret = symname;
        else if (symbol.flags & SYM_DATA)
        {
            ret = tmp = dump_want_n(strlen(symbol.arg_text[0]) + 1);
            if (tmp) strcpy(tmp, symbol.arg_text[0]);
        }
        else
        {
            unsigned int i, len, start = symbol.flags & SYM_THISCALL ? 1 : 0;

            len = strlen(symbol.return_text) + 3 /* ' __' */ +
                strlen(symbol_get_call_convention(&symbol)) + 1 /* ' ' */+
                strlen(symbol.function_name) + 1 /* ')' */;
            if (!symbol.argc || (symbol.argc == 1 && symbol.flags & SYM_THISCALL))
                len += 4 /* "void" */;
            else for (i = start; i < symbol.argc; i++)
                len += (i > start ? 2 /* ", " */ : 0 /* "" */) + strlen(symbol.arg_text[i]);
            if (symbol.varargs) len += 5 /* ", ..." */;
            len += 2; /* ")\0" */

            ret = tmp = dump_want_n(len);
            if (tmp)
            {
                sprintf(tmp, "%s __%s %s(",
                        symbol.return_text,
                        symbol_get_call_convention(&symbol),
                        symbol.function_name);
                if (!symbol.argc || (symbol.argc == 1 && symbol.flags & SYM_THISCALL))
                    strcat(tmp, "void");
                else for (i = start; i < symbol.argc; i++)
                {
                    if (i > start) strcat(tmp, ", ");
                    strcat(tmp, symbol.arg_text[i]);
                }
                if (symbol.varargs) strcat(tmp, ", ...");
                strcat(tmp, ")");
            }
        }
        symbol_clear(&symbol);
    }
    else ret = symname;
    return ret;
}
예제 #3
0
Symbol Formula(Symbol* text, Symbol ends)
{
    symbol_init();
    ///s_Parser_analyze = Parser_analyze;
#ifdef PARSER_DEBUG
    Parser_test();
    return 0x00;
#else
    Parser p;
    Parser_Init(&p, text, ends, 0);
    return Parser_analyze(&p);
#endif
}
예제 #4
0
파일: symbol.c 프로젝트: psilord/manifold
Symbol* symbol_copy(Symbol *sym)
{
	int i;
	Symbol *newsym;

	newsym = symbol_init(sym->dim);

	for (i = 0; i < sym->dim; i++)
	{
		newsym->vec[i] = sym->vec[i];
	}
	
	return newsym;
}
예제 #5
0
파일: compile.c 프로젝트: algassimou/cool
static int keywords_scope_init () {

  if (st_create_scope(tableSymbole) == -1)
    return -1 ;

  keywords_scope = st_current_scope(tableSymbole);

  int cpt = 0;
  char *key = keywords[cpt] ;
  Symbol *sym;
  int *val;

  while(key != NULL) {
    val = malloc (sizeof(int));
    assert(val);

    switch (cpt) {
    case 0: /*class*/ *val = CLASS;  break ;
    case 1: /*case*/  *val = CASE; break ;
    case 2: /*else*/  *val = ELSE; break ;
    case 3: /*esac*/ *val = ESAC;  break ;
    case 4: /*false*/ *val = FALSE; break ;
    case 5: /*fi*/  *val = FI; break ;
    case 6: /*if*/ *val = IF; break ;
    case 7: /*in*/ *val = IN; break ;
    case 8: /*inherits*/ *val = INHERITS; break ;
    case 9: /*isvoid*/ *val = ISVOID; break ;
    case 10: /*let*/ *val = LET; break ;
    case 11: /*loop*/ *val = LOOP; break ;
    case 12: /*new*/ *val = NEW; break ;
    case 13: /*not*/ *val = NOT; break ;
    case 14: /*pool*/ *val = POOL; break ;
    case 15: /*then*/ *val = THEN; break ;
    case 16: /*true*/ *val = TRUE; break ;
    case 17: /*while*/ *val = WHILE; break ;
    }
 
    // create and init symbole
    sym = symbol_create();
    symbol_init(sym, free);
    sym -> id = key;
    sym -> val = val;
    sym -> scope = keywords_scope;

    if (st_add_symbol(tableSymbole, sym) == -1)
      return -1;

    key = keywords[++cpt];
  }
}
예제 #6
0
void monitor_init(HMODULE module_handle)
{
    // Sends crashes to the process rather than showing error popup boxes etc.
    SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT |
        SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);

    config_t cfg;
    config_read(&cfg);

    // Required to be initialized before any logging starts.
    mem_init();

    // Initialize capstone without our custom allocator as it is
    // not available yet.
    hook_init(module_handle);

    pipe_init(cfg.pipe_name);
    native_init();

    // Re-initialize capstone with our custom allocator which is now
    // accessible after native_init().
    hook_init2();

    misc_init(module_handle, cfg.shutdown_mutex);
    misc_set_hook_library(&monitor_hook);
    diffing_init(cfg.hashes_path, cfg.diffing_enable);

    log_init(cfg.logpipe);
    ignore_init();

    sleep_init(cfg.first_process, cfg.force_sleep_skip, cfg.startup_time);

    unhook_init_detection(cfg.first_process);

    hide_module_from_peb(module_handle);

    symbol_init(module_handle);

    // Should be the last as some of the other initialization routines extract
    // the image size, EAT pointers, etc while the PE header is still intact.
    destroy_pe_header(module_handle);

    misc_set_monitor_options(cfg.track, cfg.mode);
}
예제 #7
0
파일: symbol.c 프로젝트: jkkm/latrace
struct lt_symbol* lt_symbol_bind(struct lt_config_shared *cfg,
				void *ptr, const char *name)
{
	static struct lt_symbol *sym = NULL;
	struct lt_symbol *s = NULL;
	void *val;

	PRINT_VERBOSE(cfg, 1, "checking %s(%p)\n", name, ptr);

	/* symbol already added */
	s = lt_symbol_get(cfg, ptr, name);
	if (s) {
		PRINT_VERBOSE(cfg, 1, "found %s, ptr %p, sym %p\n",
				name, sym->ptr, sym);
		return s;
	}

	if (!sym) {
		sym = malloc(sizeof(*sym));
		if (!sym)
			return NULL;
	}

	bzero(sym, sizeof(*sym));
	sym->ptr  = ptr;
	sym->name = name;

	/* do we care about this symbol? */
	if (symbol_init(cfg, sym, name))
		return NULL;

	/* we do, let's add it */
	val = tsearch((void *) sym, &root, compare);
	if (!val)
		return NULL;

	/* symbol properly added */
	s = (*(void**) val);

	PRINT_VERBOSE(cfg, 1, "added %s, ptr %p, sym %p\n",
			name, sym->ptr, sym);
	sym = NULL;
	return s;
}
예제 #8
0
파일: slq.c 프로젝트: psilord/manifold
/* BEGIN SLQline implementation */
SLQline* slqline_init(int slid, int width, int dim)
{
	SLQline *slql;
	int i;

	slql = (SLQline*)xmalloc(sizeof(SLQline) * 1);

	slql->slid = slid;
	slql->width = width;
	slql->line = (Symbol**)xmalloc(sizeof(Symbol*) * slql->width);
	for (i = 0; i < width; i++)
	{
		slql->line[i] = symbol_init(dim);
		symbol_zero(slql->line[i]);
	}

	slql->next = NULL;

	return slql;
}
예제 #9
0
/** Entry point of the program
 * @param argc count of arguments, will always be at least 1
 * @param argv array of parameters to program argv[0] is the name of
 * the program, so additional parameters will begin at index 1.
 * @return 0 the Linux convention for success.
 */
int main (int argc, char* argv[]) {
  char line[MAX_LINE_LENGTH];
  int  count, addr;
  char *cmd, *name;
  sym_table_t* symTab;

  if (argc != 2)
    usage();

  symTab = symbol_init(atoi(argv[1]));

  while (fgets(line, sizeof(line), stdin) != NULL) {
    char *cr = strchr(line ,'\n'); /* get rid of trailing \n, if any */

    if (cr)
      *cr = '\0';

    cmd = strtok(line, delim);

    if (! cmd)
      continue;

    if (strcmp(cmd, "add") == 0) {
      name = nextToken();
      addr = nextInt();
      printf("%s\n", (symbol_add(symTab, name, addr) ? "OK" : "Duplicate"));
    }
    else if (strcmp(cmd, "count") == 0) {
      count = 0;
      symbol_iterate(symTab, countSymbols, &count);
      printf("symbol count: %d\n", count);
    }
    else if ((strcmp(cmd, "exit") == 0) || (strcmp(cmd, "quit") == 0)) {
      break;
    }
    else if (strcmp(cmd, "get") == 0) {
      name = nextToken();
      printResult(symbol_find_by_name(symTab, name), stdout);
    }
    else if (strcmp(cmd, "help") == 0) {
      help();
    }
    else if (strcmp(cmd, "label") == 0) {
      addr = nextInt();
      printf("label at addr %d '%s'\n", addr,
             symbol_find_by_addr(symTab, addr));
    }
    else if (strcmp(cmd, "list") == 0) {
      symbol_iterate(symTab, printResult, stdout);
    }
    else if (strcmp(cmd, "reset") == 0) {
      symbol_reset(symTab);
    }
    else if (strcmp(cmd, "search") == 0) {
      int hash, index;
      name              = nextToken();
      struct node* node = symbol_search(symTab, name, &hash, &index);
      printf("symbol '%s' hash: %d index: %d is %s in symbol table\n", name,
             hash, index, (node ? "" : "NOT"));
    }
    else {
      help();
    }
  }

  symbol_term(symTab); /* can check for memory leaks now */

  return 0;
}
예제 #10
0
파일: input.c 프로젝트: psilord/manifold
/* initialize the table to read convert printable ascii characters into 
	symbols of arbitrary(but constant) dimension */
Input* input_init(unsigned short dimension)
{
	int i;
	Input *inp;
	int sum;
	int count;

	inp = (Input*)xmalloc(sizeof(Input) * 1);
	inp->dim = dimension;
	inp->printable = 0;

	/* count how many printable characters there are */
	sum = 0;
	for(i = 0; i < 256; i++)
	{
		if (isprint(i))
		{
			sum++;
		}
	}
	
	/* set up the translation table */
	count = 0;
	for(i = 0; i < 256; i++)
	{
		inp->xlt[i].c = i;

		/* only make symbols for printable characters */
		if (isprint(i))
		{
			inp->xlt[i].sym = symbol_init(inp->dim);
			/* each symbol is going to interpolate from (nearly) zero 
				to one based upon how many printable
				characters there were. This prevents
				two characters from having the same
				symbol vector if I were to use random
				symbols. Also, because of the fact that
				the characters are actually grouped
				near to each other in ascii means
				that the interpolant will mimic the
				distance function between printable
				characters. This means S is near to T
				in the interpolant space. zero is left
				unused as I'm going to use it as a
				"unification" number in the math*/

			symbol_set_all(inp->xlt[i].sym, 
				((float)count+1.0) / (float)sum);

			inp->printable++;
			count++;
		}
		else
		{
			inp->xlt[i].sym = NULL;
		}
	}

	printf("Initialized %d printable characters.\n", inp->printable);
	return inp;
}
예제 #11
0
void asm_init (void) {
  infoHead = infoTail = currInfo = NULL; 
  tokens_init();
  lc3_sym_tab = symbol_init(0); 
}
예제 #12
0
파일: symbol.c 프로젝트: gregory144/clarity
symbol_table_t* symbol_create_scope(symbol_table_t* parent) {
  symbol_table_t* scope = symbol_init();
  scope->parent = parent;
  return scope;
}