Пример #1
0
static struct conf_entry * entry_lookup(struct conf_entry * section, const char *name)
{
	struct conf_entry *entry;
	int ret;
	char * rem;

	if ((name == NULL) || (*name == '\0')) {
		DBG(DBG_WARNING, "name invalid");
		return NULL;
	}

	if ((entry = section) == NULL) {
		DBG(DBG_WARNING, "section invalid");
		return NULL;
	}

	while (entry->name != NULL) {

		if ((ret = strtokcmp(name, entry->name, '/', &rem)) >= 0) {

			if (ret == 0)
				return entry;

			if (entry->type != CONF_TYPE(CONF_SECTION)) {
				return NULL;
			}

			return entry_lookup((struct conf_entry *)entry->p, rem);
		}
		entry++;
	}

	DBG(DBG_WARNING, "name not found");
	return NULL;
}
Пример #2
0
static struct conf_entry * section_lookup(struct conf_entry * section, const char *name)
{
	struct conf_entry * entry;

	DBG(DBG_INFO, "loking for \"%s\" at section 0x%p", name, section);

	if ((entry = entry_lookup(section, name)) == NULL) {
		return entry;
	}

	if (entry->type != CONF_TYPE(CONF_SECTION)) {
		return NULL;
	}

	return (struct conf_entry *) entry->p;
}
Пример #3
0
int conf_entry_set(struct conf_entry * section, const char *name, const char *value)
{
	struct conf_entry *entry;

	entry = entry_lookup(section, name);
	if (entry == NULL)
		return -1;

	/* Assuming NULL set as a stub configuration. */
	if (value == NULL)
		value = NULL_STRING;
	
	if (entry->type->t_set(entry, value))
		return 0;

	return -1;
}
Пример #4
0
int conf_entry_get(struct conf_entry * section, const char *name, char *value)
{
	struct conf_entry *entry;

	if (value == NULL)
		return -1;

	entry = entry_lookup(section, name);
	if (entry == NULL)
		return -1;

	if (entry->type->t_get(entry, value))
		return 0;
	else {
		strcpy(value, NULL_STRING);
		return 0;
	}

	return -1;
}
Пример #5
0
static int
translate_file(const char *cpath, size_t offset, char *toString)
{
    size_t base = 0;
    LIST_MEMBER *pentry = NULL;
    int res = 0;
    char *path, *dpath;

    dpath = path = convert_path(cpath);
    if (!path)
        return 1;

    // The path could be absolute:
    if (get_ImageBase(path, &base))
    {
        pentry = entry_lookup(&cache, path);
        if (pentry)
        {
            path = pentry->path;
            base = pentry->ImageBase;
            if (base == INVALID_BASE)
            {
                l2l_dbg(1, "No, or invalid base address: %s\n", path);
                res = 2;
            }
        }
        else
        {
            l2l_dbg(1, "Not found in cache: %s\n", path);
            res = 3;
        }
    }

    if (!res)
    {
        res = process_file(path, offset, toString);
    }

    free(dpath);
    return res;
}
Пример #6
0
static int
handle_address_cmd(FILE *outFile, char *arg)
{
    PLIST_MEMBER plm;
    char Image[NAMESIZE];
    DWORD Offset;
    int cnt;
    char *s;

    if(( s = strchr(arg, ':') ))
    {
        *s = ' ';
        if ( (cnt = sscanf(arg,"%20s %x", Image, &Offset)) == 2)
        {
            if (( plm = entry_lookup(&cache, Image) ))
            {
                if (plm->RelBase != INVALID_BASE)
					esclog(outFile, "Address: 0x%lx\n", plm->RelBase + Offset)
                else
                    esclog(outFile, "Relocated base missing for '%s' ('mod' will update)\n", Image);
            }
            else
                esclog(outFile, "Image '%s' not found\n", Image);
        }
Пример #7
0
int conf_parse(uint8_t * buf, struct conf_entry * root)
{
	struct conf_entry * section;
	struct conf_entry * entry;
	uint8_t * cp = buf;
	char token[512];
	int skip_section = 0;
	int count = 0;;
	int line = 0;
	int pos;
	int c;

	section = root;

	for (;;) {
		/* ---------------------------------------------------------
		   locate the next section, ignoring empty and comment lines */
		line++;
		DBG(DBG_MSG, "line %3d", line);

		/* skip spaces */
		do { c = *cp++; } while ((c == ' ') || (c == '\t'));

		if (c == '\0')
			break;

		if (c == '\n') {
			DBG(DBG_MSG, "empty line");
			continue;
		}

		if (c == '#') {
			DBG(DBG_MSG, "comment");
			do {
				c = *cp++;
				if (c == '\0')
					goto end;
			} while (c != '\n');
			continue;	
		}

		if (c == '[') {
			skip_section = 0;

			/* skip spaces */
			do { c = *cp++; } while ((c == ' ') || (c == '\t'));

			/* section name must start with a letter */
			if (!isalpha(c)) {
				DBG(DBG_ERROR, "line %d: expecting alphabetic character", 
					line);
				return -1;
			}

			/* read the section name */
			pos = 0;
			do { 
				token[pos++] = c;	
				c = *cp++; 
			} while (isalnum(c) || (c == '_') || (c == '/'));
			token[pos] = '\0';	

			/* skip spaces, if any */
			while ((c == ' ') || (c == '\t')) { c = *cp++; };

			if (c != ']') {
				DBG(DBG_ERROR, "line %d: expecting ]", line);
				return -1;
			}

			/* skip spaces */
			do { c = *cp++; } while ((c == ' ') || (c == '\t'));

			if (c == '#') {
				/* ignore to the end of line */
				DBG(DBG_MSG, "comment");
				do {
					c = *cp++;
					if (c == '\0')
						goto end;
				} while (c != '\n');
			} 

			if (c != '\n') {
				DBG(DBG_ERROR, "line %d: expecting EOL", line);
				return -1;
			}

			DBG(DBG_MSG, "section_lookup: '%s'", token);

			if ((section = section_lookup(root, token)) == NULL) {
				DBG(DBG_WARNING, "invalid section: '%s'", token);
				skip_section = 1;
			}
			continue;
		}

		if (skip_section) {
			DBG(DBG_MSG, "skiping");
			do {
				c = *cp++;
				if (c == '\0')
					goto end;
			} while (c != '\n');
			continue;	
		}
			
		/* ---------------------------------------------------------
		   read the section content 
		   -------------------------------------------------------- */

		/* entry name must start with a letter */
		if (!isalpha(c)) {
			DBG(DBG_ERROR, "line %d: expecting alphabetic character", line);
			return -1;
		}

		/* read the entry name */
		pos = 0;
		do { 
			token[pos++] = c;	
			c = *cp++; 
		} while (isalnum(c) || (c == '.') || (c == '-') || (c == '_'));
		token[pos] = '\0';	

		/* skip spaces, if any */
		while ((c == ' ') || (c == '\t')) { c = *cp++; };

		if (c != '=') {
			DBG(DBG_ERROR, "line %d: expecting =", line);
			return -1;
		}

		if ((entry = entry_lookup(section, token)) == NULL) {
			DBG(DBG_WARNING, "invalid entry: '%s.%s'", section->name, token);
			/* ignore to the end of line */
			do {
				c = *cp++;
				if (c == '\0')
					goto end;
			} while (c != '\n');
			continue;
		}

		/* skip spaces */
		do { c = *cp++; } while ((c == ' ') || (c == '\t'));

		/* read the entry value */
		pos = 0;
		do { 
			token[pos++] = c;	
			c = *cp++; 
		} while ((c != '\n') && (c != '\0'));
		token[pos] = '\0';	

		/* set the variable */
		if (entry->type->t_set(entry, token))
			count++;
		else
			DBG(DBG_WARNING, "line %d: '%s': decode error.", line, entry->name);
	}
end:
	return 0;
}