예제 #1
0
파일: login.c 프로젝트: GrayMissing/lwqq
/**
 * I hacked the javascript file named comm.js, which received from tencent
 * server, and find that f**k tencent has changed encryption algorithm
 * for password in webqq3 . The new algorithm is below(descripted with javascript):
 * var M=C.p.value; // M is the qq password 
 * var I=hexchar2bin(md5(M)); // Make a md5 digest
 * var H=md5(I+pt.uin); // Make md5 with I and uin(see below)
 * var G=md5(H+C.verifycode.value.toUpperCase());
 * 
 * @param pwd User's password
 * @param vc Verify Code. e.g. "!M6C"
 * @param uin A string like "\x00\x00\x00\x00\x54\xb3\x3c\x53", NB: it
 *        must contain 8 hexadecimal number, in this example, it equaled
 *        to "0x0,0x0,0x0,0x0,0x54,0xb3,0x3c,0x53"
 * 
 * @return Encoded password on success, else NULL on failed
 */
static char *lwqq_enc_pwd(const char *pwd, const char *vc, const char *uin)
{
	int i;
	int uin_byte_length;
	char buf[128] = {0};
	unsigned char sig[32];
	char _uin[9] = {0};

	if (!pwd || !vc || !uin) {
		lwqq_log(LOG_ERROR, "Null parameterment\n");
		return NULL;
	}


	/* Calculate the length of uin (it must be 8?) */
	uin_byte_length = strlen(uin) / 4;

	/**
	 * Ok, parse uin from string format.
	 * "\x00\x00\x00\x00\x54\xb3\x3c\x53" -> {0,0,0,0,54,b3,3c,53}
	 */
	for (i = 0; i < uin_byte_length ; i++) {
		char u[5] = {0};
		char tmp;
		strncpy(u, uin + i * 4 + 2, 2);

		errno = 0;
		tmp = strtol(u, NULL, 16);
		if (errno) {
			return NULL;
		}
		_uin[i] = tmp;
	}
	/* Equal to "var I=hexchar2bin(md5(M));" */
	md5_buffer(pwd,strlen(pwd),sig);
	memcpy(buf,sig,sizeof(sig));

	/* Equal to "var H=md5(I+pt.uin);" */
	memcpy(buf + 16, _uin, uin_byte_length);
	md5_buffer(buf, 16 + uin_byte_length, sig);
	md5_sig_to_string(sig,buf,sizeof(buf));

	/* Equal to var G=md5(H+C.verifycode.value.toUpperCase()); */
	snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%s", vc);
	upcase_string(buf, strlen(buf));

	md5_buffer(buf, strlen(buf), sig);
	md5_sig_to_string(sig,buf,sizeof(buf));
	upcase_string(buf, strlen(buf));

	/* OK, seems like every is OK */
	return s_strdup(buf);
}
예제 #2
0
int append_table(TABLE **list, char *table_name_in, int multiplicity)
{
  TABLE *table;
  TABLE *item = (TABLE *)calloc(1, sizeof(TABLE));
  char table_name[256];
  int is_this = 0;

  if( strcmp( table_name_in, "THIS" ) == 0) {
    upcase_string( table_name, lc_name );
    strcat( table_name, "_THIS" );
    is_this = 1;
  }
  else {
    strcpy( table_name, table_name_in );
  }

  if (!item)
    return SYSTEM_ERROR;
  item->next = NULL;
  item->multiplicity = multiplicity;
  item->is_this = is_this;
  if (table_name) {
    if (!(item->name = (char *)malloc(strlen(table_name) + 1)))
      return SYSTEM_ERROR;
    strcpy(item->name, table_name);
    if (!(item->lc_name = (char *)malloc(strlen(item->name) + 1)))
      return SYSTEM_ERROR;
    downcase_string(item->lc_name, item->name);
  }
  else {
    free(item);
    fprintf(stderr, "NULL table name in append_table().\n");
    return BAD_DATA_ERROR;
  }
  if (*list == NULL)
    *list = item;
  else {
    for (table = *list; table->next; table = table->next)
      ;
    table->next = item;
  }
  return OK;
}