int
main(int argc, char *argv[])
{
	int x = 0xffffffff;
	uint8_t *a = (uint8_t *)"Man";
	uint8_t *b = (uint8_t *)"Ma";
	uint8_t *c = (uint8_t *)"M";
	uint8_t *words = (uint8_t *)
		"Man is distinguished, not only by his reason, but by this singular passion from "
		"other animals, which is a lust of the mind, that by a perseverance of delight "
		"in the continued and indefatigable generation of knowledge, exceeds the short "
		"vehemence of any carnal pleasure.";
	uint8_t *matasano = (uint8_t *)
		"\x49\x27\x6d\x20\x6b\x69\x6c\x6c\x69\x6e\x67\x20\x79\x6f\x75\x72"
		"\x20\x62\x72\x61\x69\x6e\x20\x6c\x69\x6b\x65\x20\x61\x20\x70\x6f"
		"\x69\x73\x6f\x6e\x6f\x75\x73\x20\x6d\x75\x73\x68\x72\x6f\x6f\x6d";
	uint32_t len;
	uint8_t *s;

	s = base64_encode((uint8_t *)&x, 4, &len);
	printf("%s\n", bytes_to_string(s, len));
	s = base64_encode(a, 3, &len);
	printf("%s\n", bytes_to_string(s, len));
	s = base64_encode(b, 2, &len);
	printf("%s\n", bytes_to_string(s, len));
	s = base64_encode(c, 1, &len);
	printf("%s\n", bytes_to_string(s, len));
	s = base64_encode(words, strlen((char*)words), &len);
	printf("%s\n", bytes_to_string(s, len));
	s = base64_encode(matasano, strlen((char*)matasano), &len);
	printf("%s\n", bytes_to_string(s, len));

	return 0;
}
Ejemplo n.º 2
0
void SocketLogger::print() const
{
	std::cout << "scope           read (bytes)  written (bytes)  read bandw.  write bandw.       time\n";
	std::cout << "-----------------------------------------------------------------------------------\n";

	for(auto const &rec: m_closed_records)
	{
		std::chrono::duration<double> elapsed_secs = rec.end - rec.start;
		double bps_read = (rec.bytes_read * 8) / elapsed_secs.count();
		double bps_written = (rec.bytes_written * 8) / elapsed_secs.count();

		std::cout
			<< std::left << std::setw(15) << rec.scope << " " << std::right
			<< std::setprecision(3)
			<< std::setw(12) << bytes_to_string(rec.bytes_read) << "  "
			<< std::setw(15) << bytes_to_string(rec.bytes_written) << "  "
			<< std::setw(11) << bps_to_string(bps_read) << "  "
			<< std::setw(11) << bps_to_string(bps_written) << "  "
			<< std::setw(10) << elapsed_secs.count() << "s\n";
	}

	std::cout << std::flush;
}
Ejemplo n.º 3
0
void
test_bytes_to_string() {
  equal("100b", bytes_to_string(100));
  equal("1kb", bytes_to_string(KB));
  equal("1mb", bytes_to_string(MB));
  equal("5mb", bytes_to_string(MB * 5));
  equal("1gb", bytes_to_string(GB));
  equal("5gb", bytes_to_string((long long) GB * 5));
}
Ejemplo n.º 4
0
INT_PTR CAimProto::SetAvatar(WPARAM, LPARAM lParam)
{
	TCHAR *szFileName = (TCHAR*)lParam;

	if (m_state != 1)
		return 1;

	if (szFileName == NULL) {
		aim_ssi_update(m_hServerConn, m_seqno, true);
		aim_delete_avatar_hash(m_hServerConn, m_seqno, 1, 1, m_avatar_id_sm);
		aim_delete_avatar_hash(m_hServerConn, m_seqno, 1, 12, m_avatar_id_lg);
		aim_ssi_update(m_hServerConn, m_seqno, false);

		avatar_request_handler(NULL, NULL, 0);
	}
	else {
		char hash[16], hash1[16], *data, *data1 = NULL;
		unsigned short size, size1 = 0;

		if (!get_avatar_hash(szFileName, hash, &data, size)) {
			mir_free(hash);
			return 1;
		}

		rescale_image(data, size, data1, size1);

		if (size1) {
			mir_md5_state_t state;
			mir_md5_init(&state);
			mir_md5_append(&state, (unsigned char*)data1, size1);
			mir_md5_finish(&state, (unsigned char*)hash1);

			mir_free(m_hash_lg); m_hash_lg = bytes_to_string(hash, sizeof(hash));
			mir_free(m_hash_sm); m_hash_sm = bytes_to_string(hash1, sizeof(hash1));

			aim_ssi_update(m_hServerConn, m_seqno, true);
			aim_set_avatar_hash(m_hServerConn, m_seqno, 1, 1, m_avatar_id_sm, 16, hash1);
			aim_set_avatar_hash(m_hServerConn, m_seqno, 1, 12, m_avatar_id_lg, 16, hash);
			aim_ssi_update(m_hServerConn, m_seqno, false);
		}
		else {
			mir_free(m_hash_lg); m_hash_lg = NULL;
			mir_free(m_hash_sm); m_hash_sm = bytes_to_string(hash, sizeof(hash1));

			aim_ssi_update(m_hServerConn, m_seqno, true);
			aim_set_avatar_hash(m_hServerConn, m_seqno, 1, 1, m_avatar_id_sm, 16, hash);
			aim_delete_avatar_hash(m_hServerConn, m_seqno, 1, 12, m_avatar_id_lg);
			aim_ssi_update(m_hServerConn, m_seqno, false);
		}

		avatar_request_handler(NULL, NULL, 0);

		avatar_up_req *req = new avatar_up_req(data, size, data1, size1);
		ForkThread(&CAimProto::avatar_upload_thread, req);

		TCHAR tFileName[MAX_PATH];
		TCHAR *ext = _tcsrchr(szFileName, '.');
		get_avatar_filename(NULL, tFileName, _countof(tFileName), ext);
		int fileId = _topen(tFileName, _O_CREAT | _O_TRUNC | _O_WRONLY | O_BINARY, _S_IREAD | _S_IWRITE);
		if (fileId < 0) {
			char errmsg[512];
			mir_snprintf(errmsg, "Cannot store avatar. File '%s' could not be created/overwritten", tFileName);
			ShowPopup(errmsg, ERROR_POPUP);
			return 1;
		}
		_write(fileId, data, size);
		_close(fileId);
	}
	return 0;
}