Cvirtual_binary shp_file_write(const byte* s, int cx, int cy, int c_images) { Cvirtual_binary d; const byte* r = s; byte* w = d.write_start(sizeof(t_shp_ts_header) + (sizeof(t_shp_ts_image_header) + cx * cy) * c_images); t_shp_header& header = *reinterpret_cast<t_shp_header*>(w); header.c_images = c_images; header.unknown1 = 0; header.unknown2 = 0; header.cx = cx; header.cy = cy; header.unknown3 = 0; w += sizeof(t_shp_header); int* index = reinterpret_cast<int*>(w); w += 8 * (c_images + 2); for (int i = 0; i < c_images; i++) { *index++ = 0x80000000 | w - d.data(); *index++ = 0; w += encode80(r, w, cx * cy); r += cx * cy; } *index++ = w - d.data(); *index++ = 0; *index++ = 0; *index++ = 0; d.size(w - d.data()); return d; }
Cvirtual_binary Cxif_key::vdata(bool fast) const { Cvirtual_binary d; int size = get_size(); int external_size = get_external_size(); if (fast) { t_xif_header_fast& header = *reinterpret_cast<t_xif_header_fast*>(d.write_start(sizeof(t_xif_header_fast) + size + external_size)); header.id = file_id; header.version = file_version_fast; header.size_uncompressed = 0; header.size_compressed = size; header.size_external = external_size; byte* w = d.data_edit() + sizeof(t_xif_header_fast); save(w); external_save(w); assert(d.data_end() == w); return d; } Cvirtual_binary s; byte* w = s.write_start(size); save(w); unsigned long cb_d = s.size() + (s.size() + 999) / 1000 + 12; t_xif_header_fast& header = *reinterpret_cast<t_xif_header_fast*>(d.write_start(sizeof(t_xif_header_fast) + cb_d + external_size)); compress(d.data_edit() + sizeof(t_xif_header_fast), &cb_d, s.data(), s.size()); w = d.data_edit() + sizeof(t_xif_header_fast) + cb_d; external_save(w); header.id = file_id; header.version = file_version_fast; header.size_uncompressed = size; header.size_compressed = cb_d; header.size_external = external_size; d.size(sizeof(t_xif_header_fast) + cb_d + external_size); return d; }
int Caud_file::extract_as_wav(const string& name) { Cvirtual_binary d = decode(); if (!d.data()) return 1; Cfile32 f; int error = f.open(name, GENERIC_WRITE); if (error) return error; int cb_sample = get_cb_sample(); int cs_remaining = get_c_samples(); t_wav_header header; memset(&header, 0, sizeof(t_wav_header)); header.file_header.id = wav_file_id; header.file_header.size = sizeof(header) - sizeof(header.file_header) + (cs_remaining << 1); header.form_type = wav_form_id; header.format_chunk.header.id = wav_format_id; header.format_chunk.header.size = sizeof(header.format_chunk) - sizeof(header.format_chunk.header); header.format_chunk.formattag = 1; header.format_chunk.c_channels = 1; header.format_chunk.samplerate = get_samplerate(); header.format_chunk.byterate = cb_sample * get_samplerate(); header.format_chunk.blockalign = cb_sample; header.format_chunk.cbits_sample = cb_sample << 3; header.data_chunk_header.id = wav_data_id; header.data_chunk_header.size = cb_sample * cs_remaining; error = f.write(&header, sizeof(t_wav_header)); return error ? error : f.write(d); }
Cvirtual_binary Cbig_file_write::write() { int cb_header = sizeof(t_big_header); int cb_d = sizeof(t_big_header); for (auto& i : m_index) { cb_header += sizeof(t_big_index_entry) + i.first.length() + 1; cb_d += sizeof(t_big_index_entry) + i.first.length() + 1 + i.second.size(); } Cvirtual_binary d; byte* w = d.write_start(cb_d); t_big_header& header = *reinterpret_cast<t_big_header*>(w); header.id = big_id; header.size = d.size(); header.mc_files = reverse(m_index.size()); header.mcb_header = reverse(cb_header); byte* w2 = w + cb_header; w += sizeof(t_big_header); for (auto& i : m_index) { t_big_index_entry& e = *reinterpret_cast<t_big_index_entry*>(w); e.offset = reverse(w2 - d.data()); e.size = reverse(i.second.size()); w += sizeof(t_big_index_entry); memcpy(w, i.first.c_str(), i.first.length() + 1); w += i.first.length() + 1; w2 += i.second.read(w2); } assert(w2 == d.data_end()); return d; }
void Cdlg_login::add_game(const string& reg_key, ::t_game game, int gsku) { Creg_key key; string serial; if (ERROR_SUCCESS == key.open(HKEY_LOCAL_MACHINE, reg_key, KEY_READ)) key.query_value("Serial", serial); if (serial.size() == 22) { Cvirtual_binary s; s.load(xcc_dirs::get_dir(game) + "woldata.key"); for (int i = 0, j = 0; i < s.size(); i++, j++) { if (j == serial.length()) j = 0; serial[j] = (262 - s.data()[i] + serial[j]) % 10 + '0'; } } else serial.clear(); t_game e; e.gsku = gsku; e.serial = serial; m_game.SetItemData(m_game.AddString(game_name[game]), m_games.size()); m_games.push_back(e); }
int Cxif_key::load_key(const byte* data, int size) { const byte* read_p = data; const t_xif_header_fast& header = *reinterpret_cast<const t_xif_header_fast*>(read_p); if (size < sizeof(t_xif_header_old) || header.id != file_id || header.version != file_version_old && header.version != file_version_new && header.version != file_version_fast) return 1; int error = 0; if (header.version == file_version_old) { read_p += sizeof(t_xif_header_old) - 4; load_old(read_p); error = size != read_p - data; } else { unsigned long cb_d = header.size_uncompressed; if (cb_d) { Cvirtual_binary d; if (header.version == file_version_new) error = Z_OK != uncompress(d.write_start(cb_d), &cb_d, data + sizeof(t_xif_header_old), size - sizeof(t_xif_header_old)); else { if (memcmp(data + sizeof(t_xif_header_fast), "BZh", 3)) error = Z_OK != uncompress(d.write_start(cb_d), &cb_d, data + sizeof(t_xif_header_fast), header.size_compressed); else error = BZ_OK != BZ2_bzBuffToBuffDecompress(reinterpret_cast<char*>(d.write_start(cb_d)), reinterpret_cast<unsigned int*>(&cb_d), const_cast<char*>(reinterpret_cast<const char*>(data + sizeof(t_xif_header_fast))), header.size_compressed, 0, 0); } // d.export("c:/temp/xif data.bin"); if (!error) { read_p = d.data(); load_new(read_p); error = read_p != d.data_end(); if (header.version == file_version_fast && !error) { read_p = data + sizeof(t_xif_header_fast) + header.size_compressed; load_external(read_p); error = size != read_p - data; } } } else { read_p = data + (header.version == file_version_fast ? sizeof(t_xif_header_fast) : sizeof(t_xif_header_old)); load_new(read_p); load_external(read_p); error = size != read_p - data; } } return error; }
int mix_database::load() { if (!td_list.empty() || !ra_list.empty() || !ts_list.empty()) return 0; Cvirtual_binary f; if (f.load(xcc_dirs::get_data_dir() + "global mix database.dat") || f.size() < 16) return 1; const char* data = reinterpret_cast<const char*>(f.data()); read_list(game_td, data); read_list(game_ra, data); read_list(game_ts, data); read_list(game_ra2, data); if (0) { ofstream log_f("c:\\log.txt"); for (auto& i : ts_list) log_f << i.second.name << '\t' << i.second.description << endl; } return 0; char name[12] = "scg00ea.bin"; const char char1[] = "bgjm"; const char char2[] = "ew"; const char char3[] = "abc"; for (int i = 0; i < 2; i++) { if (i) strcpy(name + 8, "ini"); for (int j = 0; j < 4; j++) { name[2] = char1[j]; for (int k = 0; k < 100; k++) { memcpy(name + 3, nwzl(2, k).c_str(), 2); for (int l = 0; l < 2; l++) { name[5] = char2[l]; for (int m = 0; m < 3; m++) { name[6] = char3[m]; mix_database::add_name(game_td, name, ""); mix_database::add_name(game_ra, name, ""); mix_database::add_name(game_ts, name, ""); } } } } } return 0; }
int Cvxl_file::extract_as_pcx(const Cfname& name, t_file_type ft, const t_palet _palet) const { t_palet palet; memcpy(palet, _palet, sizeof(t_palet)); convert_palet_18_to_24(palet); const t_vxl_section_tailer& section_tailer = *get_section_tailer(0); const int cx = section_tailer.cx; const int cy = section_tailer.cy; const int cz = section_tailer.cz; Cvirtual_binary s; for (int i = 0; i < cz; i++) { memset(s.write_start(cx * cy), 0, cx * cy); int j = 0; for (int y = 0; y < cy; y++) { for (int x = 0; x < cx; x++) { const byte* r = get_span_data(0, j); if (r) { int z = 0; while (z < cz) { z += *r++; int c = *r++; while (c--) { if (i == z) s.data_edit()[x + cx * y] = *r; r += 2; z++; } r++; } } j++; } } Cfname t = name; t.set_title(name.get_ftitle() + " " + nwzl(4, i)); int error = image_file_write(t, ft, s.data(), palet, cx, cy); if (error) return error; } return 0; }
static int copy_block(Cfile32& s, int s_p, Cfile32& d, int d_p, int size) { Cvirtual_binary buffer; while (size) { int cb_buffer = min(size, 4 << 20); s.seek(s_p); if (int e = s.read(buffer.write_start(cb_buffer), cb_buffer)) return e; d.seek(d_p); if (int e = d.write(buffer.data(), cb_buffer)) return e; s_p += cb_buffer; d_p += cb_buffer; size -= cb_buffer; } return 0; }
Cvirtual_binary Cxif_key::export_bz() const { Cvirtual_binary d; int size = get_size(); int external_size = get_external_size(); Cvirtual_binary s; byte* w = s.write_start(size); save(w); unsigned int cb_d = s.size() + (s.size() + 99) / 100 + 600; t_xif_header_fast& header = *reinterpret_cast<t_xif_header_fast*>(d.write_start(sizeof(t_xif_header_fast) + cb_d + external_size)); if (BZ_OK != BZ2_bzBuffToBuffCompress(reinterpret_cast<char*>(d.data_edit() + sizeof(t_xif_header_fast)), &cb_d, const_cast<char*>(reinterpret_cast<const char*>(s.data())), s.size(), 9, 0, 0)) return Cvirtual_binary(); w = d.data_edit() + sizeof(t_xif_header_fast) + cb_d; external_save(w); header.id = file_id; header.version = file_version_fast; header.size_uncompressed = size; header.size_compressed = cb_d; header.size_external = external_size; d.size(sizeof(t_xif_header_fast) + cb_d + external_size); return d; }
void Cconnection::read(const std::string& v) { #ifndef NDEBUG std::cout << v << std::endl; #endif if (m_server->config().m_log_access) { static std::ofstream f("xbt_tracker_raw.log"); f << m_server->time() << '\t' << inet_ntoa(m_a.sin_addr) << '\t' << ntohs(m_a.sin_port) << '\t' << v << std::endl; } Ctracker_input ti; size_t e = v.find('?'); if (e == std::string::npos) e = v.size(); else { size_t a = e + 1; size_t b = v.find(' ', a); if (b == std::string::npos) return; while (a < b) { size_t c = v.find('=', a); if (c++ == std::string::npos) break; size_t d = v.find_first_of(" &", c); if (d == std::string::npos) break; ti.set(v.substr(a, c - a - 1), uri_decode(v.substr(c, d - c))); a = d + 1; } } if (!ti.m_ipa || !is_private_ipa(m_a.sin_addr.s_addr)) ti.m_ipa = m_a.sin_addr.s_addr; std::string torrent_pass0; size_t a = 4; if (a < e && v[a] == '/') { a++; if (a + 1 < e && v[a + 1] == '/') a += 2; if (a + 32 < e && v[a + 32] == '/') { torrent_pass0 = v.substr(a, 32); a += 33; if (a + 40 < e && v[a + 40] == '/') a += 41; } } std::string h = "HTTP/1.0 200 OK\r\n"; Cvirtual_binary s; bool gzip = true; switch (a < v.size() ? v[a] : 0) { case 'a': if (!ti.valid()) break; gzip = false; if (0) s = Cbvalue().d(bts_failure_reason, bts_banned_client).read(); else { std::string error = m_server->insert_peer(ti, false, m_server->find_user_by_torrent_pass(torrent_pass0, ti.m_info_hash)); s = error.empty() ? m_server->select_peers(ti) : Cbvalue().d(bts_failure_reason, error).read(); } break; case 'd': if (m_server->config().m_debug) { gzip = m_server->config().m_gzip_debug; h += "Content-Type: text/html; charset=us-ascii\r\n"; s = Cvirtual_binary(m_server->debug(ti)); } break; case 's': if (v.size() >= 7 && v[6] == 't') { gzip = m_server->config().m_gzip_debug; h += "Content-Type: text/html; charset=us-ascii\r\n"; s = Cvirtual_binary(m_server->statistics()); } else if (m_server->config().m_full_scrape || ti.m_compact || !ti.m_info_hash.empty()) { gzip = m_server->config().m_gzip_scrape && !ti.m_compact && ti.m_info_hash.empty(); s = m_server->scrape(ti); } break; } if (s.empty()) { if (!ti.m_peer_id.empty() || m_server->config().m_redirect_url.empty()) h = "HTTP/1.0 404 Not Found\r\n"; else { h = "HTTP/1.0 302 Found\r\n" "Location: " + m_server->config().m_redirect_url + (ti.m_info_hash.empty() ? "" : "?info_hash=" + uri_encode(ti.m_info_hash)) + "\r\n"; } } else if (gzip) { Cvirtual_binary s2 = xcc_z::gzip(s); #ifndef NDEBUG static std::ofstream f("xbt_tracker_gzip.log"); f << m_server->time() << '\t' << v[5] << '\t' << s.size() << '\t' << s2.size() << std::endl; #endif if (s2.size() + 24 < s.size()) { h += "Content-Encoding: gzip\r\n"; s = s2; } } h += "\r\n"; #ifdef WIN32 m_write_b.resize(h.size() + s.size()); memcpy(m_write_b.data_edit(), h.data(), h.size()); s.read(m_write_b.data_edit() + h.size()); int r = m_s.send(m_write_b); #else boost::array<iovec, 2> d; d[0].iov_base = const_cast<char*>(h.data()); d[0].iov_len = h.size(); d[1].iov_base = const_cast<unsigned char*>(s.data()); d[1].iov_len = s.size(); msghdr m; m.msg_name = NULL; m.msg_namelen = 0; m.msg_iov = const_cast<iovec*>(d.data()); m.msg_iovlen = d.size(); m.msg_control = NULL; m.msg_controllen = 0; m.msg_flags = 0; int r = sendmsg(m_s, &m, MSG_NOSIGNAL); #endif if (r == SOCKET_ERROR) { if (WSAGetLastError() != WSAECONNRESET) std::cerr << "send failed: " << Csocket::error2a(WSAGetLastError()) << std::endl; } else if (r != h.size() + s.size()) { #ifndef WIN32 if (r < h.size()) { m_write_b.resize(h.size() + s.size()); memcpy(m_write_b.data_edit(), h.data(), h.size()); s.read(m_write_b.data_edit() + h.size()); } else { m_write_b = s; r -= h.size(); } #endif m_r = m_write_b; m_r += r; } if (m_r.empty()) m_write_b.clear(); }
Cvirtual_binary vxl_decode4(const byte* s, int cb_d) { Cvirtual_binary d; const byte* r = s; const t_vxl4_header& s_header = *reinterpret_cast<const t_vxl4_header*>(r); const int c_sections = s_header.c_sections; r += sizeof(t_vxl4_header); byte* w = d.write_start(cb_d ? cb_d : 1 << 20); t_vxl_header& header = *reinterpret_cast<t_vxl_header*>(w); strcpy(header.id, vxl_id); header.one = 1; header.c_section_headers = c_sections; header.c_section_tailers = c_sections; header.unknown = 0x1f10; w += sizeof(t_vxl_header); t_vxl_section_header* d_section_header = reinterpret_cast<t_vxl_section_header*>(w); t_vxl_section_tailer* section_tailer = new t_vxl_section_tailer[c_sections]; w += sizeof(t_vxl_section_header) * c_sections; byte* body_start = w; for (int i = 0; i < c_sections; i++) { const t_vxl4_section_header& section_header = *reinterpret_cast<const t_vxl4_section_header*>(r); const int cx = section_header.cx; const int cy = section_header.cy; const int cz = section_header.cz; strcpy(d_section_header->id, section_header.id); d_section_header->section_i = section_header.section_i; d_section_header->one = 1; d_section_header->zero = 0; d_section_header++; __int32* span_start_list = reinterpret_cast<__int32*>(w); section_tailer[i].span_start_ofs = w - body_start; w += 4 * cx * cy; __int32* span_end_list = reinterpret_cast<__int32*>(w); section_tailer[i].span_end_ofs = w - body_start; w += 4 * cx * cy; section_tailer[i].span_data_ofs = w - body_start; section_tailer[i].scale = section_header.scale; section_tailer[i].x_min_scale = section_header.x_min_scale; section_tailer[i].y_min_scale = section_header.y_min_scale; section_tailer[i].z_min_scale = section_header.z_min_scale; section_tailer[i].x_max_scale = section_header.x_max_scale; section_tailer[i].y_max_scale = section_header.y_max_scale; section_tailer[i].z_max_scale = section_header.z_max_scale; section_tailer[i].cx = section_header.cx; section_tailer[i].cy = section_header.cy; section_tailer[i].cz = section_header.cz; section_tailer[i].unknown = section_header.unknown; r += sizeof(t_vxl4_section_header); byte* span_data_start = w; for (int j = 0; j < cx * cy; j++) { byte* span_start = w; int z = 0; while (z < cz) { int z_inc = *r++; if (z_inc == cz) break; z += *w++ = z_inc; int count = *w++ = *r++; int c = count; while (c--) { *w++ = *r++; *w++ = *r++; z++; } *w++ = count; } if (span_start == w) { span_start_list[j] = -1; span_end_list[j] = -1; } else { span_start_list[j] = span_start - span_data_start; span_end_list[j] = w - span_data_start - 1; } } } header.size = w - body_start; memcpy(w, section_tailer, sizeof(t_vxl_section_tailer) * c_sections); delete[] section_tailer; w += sizeof(t_vxl_section_tailer) * c_sections; assert(!cb_d || d.size() == w - d.data()); return cb_d ? d : Cvirtual_binary(d.data(), w - d.data()); }
Cvirtual_binary vxl_file_write(const Cxif_key& s) { Cvirtual_binary d; byte* w = d.write_start(1 << 20); const Cxif_key& header_key = s.open_key_read(vi_header); const Cxif_key& body_key = s.open_key_read(vi_body); int c_sections = body_key.c_keys(); int* span_start_list_ofs = new int[c_sections]; int* span_end_list_ofs = new int[c_sections]; int* span_data_ofs = new int[c_sections]; t_vxl_header& header = *reinterpret_cast<t_vxl_header*>(w); strcpy(header.id, vxl_id); header.one = 1; header.c_section_headers = c_sections; header.c_section_tailers = c_sections; header.unknown = 0x1f10; const Cxif_key& palet_key = header_key.open_key_read(vi_palet); int i; for (i = 0; i < 256; i++) { const Cxif_key& palet_entry_key = palet_key.open_key_read(i); header.palet[i].r = palet_entry_key.get_value_int(vi_red); header.palet[i].g = palet_entry_key.get_value_int(vi_green); header.palet[i].b = palet_entry_key.get_value_int(vi_blue); } w += sizeof(t_vxl_header); for (i = 0; i < c_sections; i++) { const Cxif_key& section_key = body_key.open_key_read(i); const Cxif_key& section_header_key = section_key.open_key_read(vi_header); t_vxl_section_header& section_header = *reinterpret_cast<t_vxl_section_header*>(w); strcpy(section_header.id, section_header_key.get_value_string(vi_id).c_str()); section_header.section_i = i; section_header.one = 1; section_header.zero = 0; w += sizeof(t_vxl_section_header); } byte* body_start = w; for (i = 0; i < c_sections; i++) { const Cxif_key& section_key = body_key.open_key_read(i); const Cxif_key& section_body_key = section_key.open_key_read(vi_body); const Cxif_key& section_tailer_key = section_key.open_key_read(vi_tailer); const int cx = section_tailer_key.get_value_int(vi_cx); const int cy = section_tailer_key.get_value_int(vi_cy); const int cz = section_tailer_key.get_value_int(vi_cz); __int32* span_start_list = reinterpret_cast<__int32*>(w); span_start_list_ofs[i] = w - body_start; w += 4 * cx * cy; __int32* span_end_list = reinterpret_cast<__int32*>(w); span_end_list_ofs[i] = w - body_start; w += 4 * cx * cy; byte* span_data_start = w; span_data_ofs[i] = w - body_start; int span_i = 0; for (int y = 0; y < cy; y++) { const Cxif_key& yi = section_body_key.open_key_read(y); for (int x = 0; x < cx; x++) { byte* span_start = w; const Cxif_key& xi = yi.open_key_read(x); int z = 0; for (auto& i : xi.m_keys) { int z_inc = i.first - z; z = i.first + 1; *w++ = z_inc; *w++ = 1; *w++ = i.second.get_value_int(vi_color); *w++ = i.second.get_value_int(vi_surface_normal); *w++ = 1; } if (span_start == w) { span_start_list[span_i] = -1; span_end_list[span_i] = -1; } else { if (z != cz) { *w++ = cz - z; *w++ = 0; *w++ = 0; } span_start_list[span_i] = span_start - span_data_start; span_end_list[span_i] = w - span_data_start - 1; } span_i++; } } } header.size = w - body_start; for (i = 0; i < c_sections; i++) { const Cxif_key& section_key = body_key.open_key_read(i); const Cxif_key& section_tailer_key = section_key.open_key_read(vi_tailer); t_vxl_section_tailer& section_tailer = *reinterpret_cast<t_vxl_section_tailer*>(w); section_tailer.span_start_ofs = span_start_list_ofs[i]; section_tailer.span_end_ofs = span_end_list_ofs[i]; section_tailer.span_data_ofs = span_data_ofs[i]; section_tailer.scale = 0; for (int ty = 0; ty < 3; ty++) { for (int tx = 0; tx < 4; tx++) section_tailer.transform[ty][tx] = 0; } section_tailer.x_min_scale = section_tailer_key.get_value_int(vi_x_min) / 1000000.0; section_tailer.y_min_scale = section_tailer_key.get_value_int(vi_y_min) / 1000000.0; section_tailer.z_min_scale = section_tailer_key.get_value_int(vi_z_min) / 1000000.0; section_tailer.x_max_scale = section_tailer_key.get_value_int(vi_x_max) / 1000000.0; section_tailer.y_max_scale = section_tailer_key.get_value_int(vi_y_max) / 1000000.0; section_tailer.z_max_scale = section_tailer_key.get_value_int(vi_z_max) / 1000000.0; section_tailer.cx = section_tailer_key.get_value_int(vi_cx); section_tailer.cy = section_tailer_key.get_value_int(vi_cy); section_tailer.cz = section_tailer_key.get_value_int(vi_cz); section_tailer.unknown = 2; w += sizeof(t_vxl_section_tailer); } delete[] span_data_ofs; delete[] span_end_list_ofs; delete[] span_start_list_ofs; d.size(w - d.data()); return d; }