コード例 #1
0
ファイル: rgp.c プロジェクト: rollrat/old-library
/*
	@설명: 부호없는 32비트 16진수를 가져옮
	@ptr [IN] : 분석중인 문자열의 포인터
	-
	@return : 추출된 숫자
*/
static u32 RgpMakeHex(const char *ptr)
{
    const char *_Ptr = ptr;
    int g = 0;
    for (; *_Ptr != 'h'; _Ptr++)
        g *= 16, g += ('0' <= *_Ptr  && *_Ptr  <= '9') ? (*_Ptr & 0xf) : (_to_lower(*_Ptr)  - 'a' + 0xa);
    return g;
}
コード例 #2
0
ファイル: string.c プロジェクト: rollrat/old-library
char * _strlwr_asc(
	char * str
	)
{
	char * ptr = str;

	while( *ptr )
		*ptr++ = _to_lower(str);

	return ptr;
}
コード例 #3
0
ファイル: keymanage.c プロジェクト: peiyukuang/cryptsetup
static void LUKS_fix_header_compatible(struct luks_phdr *header)
{
	/* Old cryptsetup expects "sha1", gcrypt allows case insensistive names,
	 * so always convert hash to lower case in header */
	_to_lower(header->hashSpec, LUKS_HASHSPEC_L);

	/* ECB mode does not use IV but dmcrypt silently allows it.
	 * Drop any IV here if ECB is used (that is not secure anyway).*/
	if (!strncmp(header->cipherMode, "ecb-", 4)) {
		memset(header->cipherMode, 0, LUKS_CIPHERMODE_L);
		strcpy(header->cipherMode, "ecb");
	}
}
コード例 #4
0
ファイル: string.c プロジェクト: rollrat/old-library
int _to_xdigit(
	int ch
	)
{
	int ret;

	if (_isdigit(ch))
		ret = ch - '0';
	else if (_isxdigit(ch))
		ret = _to_lower(ch) - 'a' + 0xa;

	return ret;
}
コード例 #5
0
ファイル: costume.c プロジェクト: rollrat/old-library
	BOOL __costume_internal_if_factor(const pcostumex cxlist)
	{
		BOOL ret = 0;
		if(*_costume_ict == '(') {
			_costume_ict++;
			ret = __costume_internal_if_and_or(cxlist);
			_costume_ict++;
		} else if (_isnumeric(*_costume_ict)) {
			if(*_costume_ict == '0') {
				if(*++_costume_ict == 'x') { // only lower
					_costume_ict++;
					while(TRUE) {
						if(_isnumeric(*_costume_ict)) {
							ret = ret * 16 + *_costume_ict - '0';
							_costume_ict++;
						} else if (_isalpha(*_costume_ict)) {
							ret = ret * 16 + _to_lower(*_costume_ict) - 'a';
							_costume_ict++;
						} else {
							break;
						}
					}
				} else {
					while(_isnumeric(*_costume_ict)) {
						ret = ret * 8 + *_costume_ict++ - '0';
					}
				}
			} else {
				while(_isnumeric(*_costume_ict)) {
					ret = ret * 10 + *_costume_ict++ - '0';
				}
			}
		} else if (_isalpha(*_costume_ict) || *_costume_ict == '_') {
			char _temp[20] = {0,}; // find temp
			int count;
			pcostumex tmp;

			for (count = 0; _isalnumub((int)(*_costume_ict)); _costume_ict++, count++)
				_temp[count] = *_costume_ict;
			_temp[count] = 0;

			if (NULL == (tmp = _costume_find_variable(cxlist, _temp)))
				return -1; // error

			ret = (BOOL)tmp->data;
		}
		return ret;
	}
コード例 #6
0
int convert_page_simple(char *tmp, char *buf, int len, const char *key)
{
	int tmp_pos = 0;
	int word_total = 0;
	split_t sp;
	word_t word[_MAX_WORD_TOTAL];

	word_total = fetch_word_from_key(word, _MAX_WORD_TOTAL, sp, key);

	for (int i = 0; i < len; i++) {
		if (buf[i] == '<') {
			for (; i < len && buf[i] != '>'; i++) {
				tmp[tmp_pos++] = buf[i];
			}
			tmp[tmp_pos++] = buf[i];
			continue;
		}

		for (int w = 0; w < word_total; w++) {
			word_t *t = &word[w];
			if (t->val[0] == _to_lower(buf[i]) && strncasecmp(t->val, buf + i, t->val_len) == 0) {
				if (_is_mutil_byte(buf[i]) || (!_is_a2z(buf[i + t->val_len])
							&& (i == 0 || (i > 0 && !_is_a2z(buf[i - 1]))))) {
					_copy_to_tmp(_RED_FONT_START, sizeof(_RED_FONT_START) - 1);
					_copy_to_tmp(t->val, t->val_len);
					_copy_to_tmp(_RED_FONT_END, sizeof(_RED_FONT_END) - 1);
					i += t->val_len - 1;
					goto out;
				}
			}
		}
		tmp[tmp_pos++] = buf[i];
out:
		;
	}

	tmp[tmp_pos] = 0;

	return tmp_pos;
}
コード例 #7
0
int convert_page(char *tmp, char *buf, int len, const char *key)
{
	int word_total = 0;
	split_t sp;
	word_t word[_MAX_WORD_TOTAL];
	int find_total = 0;

	word_total = fetch_word_from_key(word, _MAX_WORD_TOTAL, sp, key);

	len = delete_html_tag(tmp, buf, len);
	memcpy(buf, tmp, len);

	for (int i = 0; i < word_total; i++) {
		word_t *t = &word[i];
		for (int j = 0; j < len; j++) {
			if (t->val[0] == _to_lower(buf[j]) && strncasecmp(buf + j, t->val, t->val_len) == 0) {
				if (_is_mutil_byte(buf[j]) || (!_is_a2z(buf[j + t->val_len])
							&& (j == 0 || (j > 0 && !_is_a2z(buf[j - 1]))))) {
					t->total = 1;
					t->pos = j;
					find_total++;
					break;
				}
			}
		}
	}

	int tmp_pos = 0;
	int find_pos = 0;

#ifdef DEBUG 
	for (int i = 0; i < word_total; i++) {
		word_t *t = &word[i];
		printf("word:%s, pos: %d\n", t->val, t->pos);
	}
#endif

	qsort(word, word_total, sizeof(word_t), _cmp_word_pos);


	int mb_count = 0;

	for (int i = word[0].pos - 1; i >= 0; i--) {
		if (word[0].pos - i > 80) {
			for (; i >= 0; i--) {
				if (_is_mutil_byte(buf[i])) {
					mb_count++;
					if (mb_count % _WFI_CHECK_WORD_LEN == 0)
						break;
				} else if (!_is_a2z(buf[i])) {
					break;
				}
			}
			find_pos = i;
			break;
		}

		if (_is_mutil_byte(buf[i]))
			mb_count++;

		if (buf[i] == '\n') {
			find_pos = i;
			break;
		}
	}

	_copy_to_tmp(buf + find_pos, word[0].pos - find_pos);

	for (int i = 0; i < word_total; i++) {
		word_t *t = &word[i];
		word_t *last = &word[i - 1];
		if (i > 0) {
			int found = 0;
			mb_count = 0;
			for (int j = last->pos + last->val_len; j < t->pos; j++) {
				if (j - (last->pos + last->val_len) > 80) {
					for (; j < t->pos; j++) {
						tmp[tmp_pos++] = buf[j];
						if (_is_mutil_byte(buf[j])) {
							mb_count++;
							if (mb_count % _WFI_CHECK_WORD_LEN == 0)
								break;
						} else if (!_is_a2z(buf[j])) {
							break;
						}
					}
					tmp[tmp_pos++] = '#';
					tmp[tmp_pos++] = ' ';
					found = 1;
					break;
				}
				if (buf[j] == '\n') {
					found = 1;
					break;
				}
				if (_is_mutil_byte(buf[j]))
					mb_count++;
				tmp[tmp_pos++] = buf[j];
			}

			if (found == 1) {
				find_pos = 0;
				mb_count = 0;
				for (int j = t->pos - 1; j >= 0; j--) {
					if (t->pos - j > 80) {
						for (; j >= 0; j--) {
							if (_is_mutil_byte(buf[j])) {
								mb_count++;
								if (mb_count % _WFI_CHECK_WORD_LEN == 0)
									break;
							} else if (!_is_a2z(buf[j]))
								break;
						}
						find_pos = j;
						break;
					}
					if (buf[j] == '\n') {
						find_pos = j + 1;
						tmp[tmp_pos++] = '#';
						tmp[tmp_pos++] = ' ';
						break;
					}
					if (_is_mutil_byte(buf[j]))
						mb_count++;
				}
				for (int j = find_pos; j < t->pos; j++) {
					tmp[tmp_pos++] = buf[j];
				}
			}
		}
		_copy_to_tmp(_RED_FONT_START, sizeof(_RED_FONT_START) - 1);
		_copy_to_tmp(t->val, t->val_len);
		_copy_to_tmp(_RED_FONT_END, sizeof(_RED_FONT_END) - 1);
	}

	word_t *next = &word[word_total - 1];

	mb_count = 0;
	for (int i = next->pos + next->val_len; i < len; i++) {
		if (i - (next->pos + next->val_len) > 80) {
			for (; i < len; i++) {
				tmp[tmp_pos++] = buf[i];
				if (_is_mutil_byte(buf[i])) {
					mb_count++;
					if (mb_count % _WFI_CHECK_WORD_LEN == 0)
						break;
				} else if (!_is_a2z(buf[i]))
					break;
			}
			break;
		}
		tmp[tmp_pos++] = buf[i];
		if (buf[i] == '\n')
			break;
		if (_is_mutil_byte(buf[i]))
			mb_count++;
	}

	tmp[tmp_pos] = 0;
	
	return tmp_pos;
}
コード例 #8
0
ファイル: keymanage.c プロジェクト: kleopatra999/cryptsetup
static void LUKS_fix_header_compatible(struct luks_phdr *header)
{
	/* Old cryptsetup expects "sha1", gcrypt allows case insensistive names,
	 * so always convert hash to lower case in header */
	_to_lower(header->hashSpec, LUKS_HASHSPEC_L);
}
コード例 #9
0
ファイル: rgp.c プロジェクト: rollrat/old-library
/*
	@설명: 오퍼랜드에 들어갈 수 있는 부분을 조사
	@str [IN] : 분석중인 문자열의 포인터
	-
	@return: 레지스터 형식의 포인터
*/
PREGISTER ParseRegister(const char *str)
{
    PREGISTER reg = ((PREGISTER) malloc (sizeof(REGISTER)));
    const char *ptr = str;
    int ch;
    BOOL no_check_end;

    no_check_end = FALSE;
    reg->type = reg->bit = 0;

    //
    //	레지스터 연산자가 아닐 경우 숫자를 확인함
    //
    if (*ptr != REGISTER_DELIMITER) {
        no_check_end = TRUE;
        goto SYMBOL;
    }

    //
    //	참조형 레지스터형식 확인
    //
    if (*++ptr == '[') {
        reg->bit = 32;
        reg->type |= REGISTER_TYPE_REFERENCE;
        RgpSkipFunc(&ptr, _isspace); // 공백제거
        ptr++;
    }

    //
    //	32bit
    //
    if (_to_lower(*ptr) == 'e') {

        reg->bit = 32;
        ptr++;

    } else if (_isnumeric(*ptr) && reg->type & REGISTER_TYPE_REFERENCE) {

        //
        //	레지스터보다 숫자가 먼저 나온 형식 / 현 버전에서는 비정규 형식이므로 오류
        //
        return NULL;

    } else {

        //
        //	참조형 레지스터에 16bit 레지스터를 대입했을 경우
        //
        if (reg->type & REGISTER_TYPE_REFERENCE)
            return NULL;

        reg->bit = 16;
    }

    //
    //	레지스터의 정보를 얻어옮
    //
    reg->reg_type = _Hash_Registers[_to_lower(*ptr++)][_to_lower(*ptr++)];

    RgpSkipFunc(&ptr, _isspace); // 공백제거

    //
    //	일반 레지스터 형식이거나 단순참조레지스터 형식이면
    //	더 이상 분석할 필요가 없으니 그냥 반환
    //
    if (!reg->type || *ptr == ']')
        return reg;

SYMBOL:
    if (*ptr == '+' || *ptr == '-') {
        reg->type |= REGISTER_TYPE_OPERATOR;
        reg->num_sign = *ptr;
    }
    else if (*ptr == '*')
        reg->type |= REGISTER_TYPE_MULTIPLE;

    //
    //	숫자만 처리할 경우
    //
    else if (no_check_end == TRUE) {
        reg->type |= REGISTER_TYPE_OPERATOR;
        ch = reg->num_sign = '+';
    } else

        //
        //	문법 처리 오류
        //
        return NULL;


    /* 연산자 건너뛰기 */
    if(no_check_end == FALSE)
        ch = *ptr++;
    RgpSkipFunc(&ptr, _isspace); // 공백제거

    //
    //	+, -, * 연산처리
    //
    if (_isnumeric(*ptr)) {
        const char *p = ptr;

        //
        //	숫자와 매치되는 경우 숫자 마지막에 붙은 h, o를 통하여
        //	16진수와 8진수를 가려야한다.
        //
        RgpSkipFunc(&p, _isxdigit);

        //
        //	해당 진수에 맞는 숫자를 가져와 연산자 처리 순서에 맞게 넣음
        //
        if( ch == '*' ) {
            if (*p == 'o')
                reg->sib_type = RgpMakeOct(ptr);
            else if (*p == 'h')
                reg->sib_type = RgpMakeHex(ptr);
            else
                reg->sib_type = RgpMakeDec(ptr);
        } else {
            if (*p == 'o')
                reg->num_type = RgpMakeOct(ptr);
            else if (*p == 'h')
                reg->num_type = RgpMakeHex(ptr);
            else
                reg->num_type = RgpMakeDec(ptr);
        }

        //
        //	기호 건너뛰기
        //
        if (*p == 'o' || *p == 'h')
            ptr = p + 1;
        else
            ptr = p;

    } else {

        //
        //	숫자가 아니면 변수이므로 변수를 저장한다
        //

    }

    RgpSkipFunc(&ptr, _isspace); // 공백제거

    //
    //	참조가 끝나지 않았다면 무언가 연산할 것이 남아있으므로
    //
    if (*ptr != ']' && !no_check_end)
        goto SYMBOL;

    return reg;
}