Example #1
0
void add_symbol (address a, char *name, add_symbol_params *params)
{
    module *m=params->m;
    rbtree *symtbl=m->symbols;
    oassert(symtbl && "symbols=NULL in module");
    MemoryCache *mc=params->mc;

    if (one_time_int3_bp_re && params->t==SYM_TYPE_PE_EXPORT && module_adr_in_executable_section (m, a))
    {
        strbuf sb=STRBUF_INIT;
        strbuf_addstr (&sb, get_module_name(m));
        strbuf_addc (&sb, '!');
        strbuf_addstr (&sb, name);

        if (regexec (one_time_int3_bp_re, sb.buf, 0, NULL, 0)==0)
            set_onetime_INT3_BP(a, params->p, m, name, mc);

        strbuf_deinit (&sb);
    };

    if (dump_seh && string_is_ends_with (name, "security_cookie"))
    {
        m->security_cookie_adr=a;
        m->security_cookie_adr_known=true;
        if (symbol_c_debug)
            L ("%s() got address of security_cookie (0x" PRI_REG_HEX ") for %s!%s\n", __FUNCTION__, a, get_module_name(m), name);
    };

    bool dump_symbol=false;
    if (dump_all_symbols_re)
    {
        strbuf sb=STRBUF_INIT;
        strbuf_addstr (&sb, get_module_name(m));
        strbuf_addc (&sb, '!');
        strbuf_addstr (&sb, name);

        if (regexec (dump_all_symbols_re, sb.buf, 0, NULL, 0)==0)
            dump_symbol=true;

        strbuf_deinit (&sb);
    };

    if (dump_symbol || (dump_all_symbols_re==NULL && dump_all_symbols))
    {
        dump_PID_if_need(params->p);
        L("New symbol. Module=[%s], address=[0x" PRI_ADR_HEX "], name=[%s]\n", get_module_name(m), a, name);
    };

    symbol *new_sym=create_symbol(params->t, name);
    symbol *first_sym=(symbol*)rbtree_lookup(symtbl, (void*)a);

    if (first_sym)
        new_sym->next=first_sym; // insert at beginning of list

    rbtree_insert(symtbl, (void*)a, (void*)new_sym);
};
Example #2
0
static int 
tokenize(varnam *handle, 
         const char *input, 
         struct strbuf *string)
{
    const char *text,  *remaining;
    int matchpos = 0, counter = 0;
    struct varnam_internal *vi;       
    struct strbuf *lookup;
    struct token *temp = NULL, *last = NULL;

    vi = handle->internal;
    lookup = vi->lookup;

    text = input;
    while( *text != '\0' ) 
    {
        strbuf_addc( lookup, *text );
        ++counter;

        temp = find_token( handle, lookup->buffer );
        if (temp) {
            last = temp;
            matchpos = counter;
            if( last->children <= 0 ) break;
        }
        else if( !can_find_token( handle, last, lookup->buffer )) { 
            break;
        }
        ++text;
    }

    if (last) 
    {
        resolve_token(handle, last, string);
        remaining = input + matchpos;
        set_last_token (handle, last);
    }
    else {
        if(lookup->buffer[0] != '_')
            strbuf_addc( string, lookup->buffer[0] );
        remaining = input + 1;
        set_last_token (handle, NULL);
    }

    strbuf_clear (lookup);
    if( strlen( remaining ) > 0 )
        return tokenize( handle, remaining, string );

    return VARNAM_SUCCESS;
}
Example #3
0
void strbuf_addc_C_escaped (strbuf *s, char c, bool treat_any_as_binary)
{
	if (treat_any_as_binary)
		strbuf_addf (s, "\\x%02X", (unsigned char)c);
	else
	{
		switch (c)
		{
		case '\n':
			strbuf_addstr (s, "\\n");
			break;
		case '\r':
			strbuf_addstr (s, "\\r");
			break;
		case '"':
			strbuf_addstr (s, "\\\"");
			break;
		case '\\':
			strbuf_addstr (s, "\\\\");
			break;
		default:
			if (c>0 && c<0x20)
				strbuf_addf (s, "\\x%02X", c);
			else
				strbuf_addc (s, c);
			break;
		};
	};
};
Example #4
0
static strbuf*
sanitize_word (varnam *handle, const char *word)
{
    size_t i;
    bool is_special = false;
    strbuf *string, *to_remove;

    string = get_pooled_string (handle);
    to_remove = get_pooled_string (handle);

    strbuf_add (string, word);

    for (i = 0; i < string->length; i++)
    {
        is_special = is_special_character (string->buffer[i]);
        if (is_special)
            strbuf_addc (to_remove, string->buffer[i]);
        else
            break;
    }

    strbuf_remove_from_first (string, strbuf_to_s (to_remove));

    strbuf_clear (to_remove);
    for (i = string->length - 1; i >= 0; i--)
    {
        is_special = is_special_character (string->buffer[i]);
        if (is_special)
            strbuf_addc (to_remove, string->buffer[i]);
        else
            break;
    }

    strbuf_remove_from_last (string, strbuf_to_s (to_remove));
    language_specific_sanitization (string);

    /* Remove trailing ZWNJ and leading ZWJ */
    strbuf_remove_from_first (string, ZWNJ());
    strbuf_remove_from_last (string, ZWNJ());
    strbuf_remove_from_first (string, ZWJ());

    return string;
}
Example #5
0
char *
htmlent_decode(const char *html)
{
  bool in_ent = false;
  struct strbuf *buf = strbuf_init();
  struct strbuf *ent = strbuf_init();
  char *res;
  const char *dec;
  
  while (*html) {
    char c = *html++;
    
    if (in_ent) {
      strbuf_addc(ent, c);
      
      if (c == ';') {
        char *ent_cstr = strbuf_cstr(ent);
        strbuf_clear(ent);
        
        in_ent = false;
        dec = htmlent_table_lookup_dec(ent_cstr);
        amz_free(ent_cstr);
        
        if (dec != NULL)
          strbuf_add(buf, dec);
      }
      
      continue;
    } else if (c == '&') {
      in_ent = true;
      strbuf_addc(ent, c);
      continue;
    }
    
    strbuf_addc(buf, c);
  }
  
  res = strbuf_cstr(buf);
  strbuf_free(buf);
  strbuf_free(ent);
  
  return res;
}
Example #6
0
// replace %substring% to environment variable, if possible
void env_vars_expansion(strbuf *sb, char** env)
{
	oassert(env!=NULL);
	for (int i=0; env[i]; i++)
	{
		char *s=DSTRDUP (env[i], "env");
		char *s1=strtok (s, "=");
		char *s2=strtok (NULL, "=");
		strbuf percented_env_var=STRBUF_INIT;
		strbuf_addc (&percented_env_var, '%');
		strbuf_addstr (&percented_env_var, s1);
		strbuf_addc (&percented_env_var, '%');

		strbuf_replace_if_possible (sb, percented_env_var.buf, s2);

		strbuf_deinit(&percented_env_var);
		DFREE(s);
	};
};
Example #7
0
void strbuf_addstr_range_be (strbuf *sb, const char *s, unsigned begin, unsigned end)
{
	int i;

	oassert (begin<end);

	// FIXME: to be optimized

	for (i=begin; i<end; i++)
		strbuf_addc (sb, s[i]); 
};
Example #8
0
void strbuf_add_space_if_not_empty (strbuf* out)
{
	if (out->strlen)
		strbuf_addc (out, ' ');
};