diff --git a/src/Client.cc b/src/Client.cc index b536894e..164f24a2 100644 --- a/src/Client.cc +++ b/src/Client.cc @@ -36,7 +36,7 @@ bool Client::send(string&& data) { } if (this->crypt_out.get()) { - this->crypt_out->encrypt(const_cast(data.data()), data.size()); + this->crypt_out->encrypt(data.data(), data.size()); } struct evbuffer* buf = bufferevent_get_output(this->bev); diff --git a/src/ProxyServer.cc b/src/ProxyServer.cc index ca807c96..d2950e44 100644 --- a/src/ProxyServer.cc +++ b/src/ProxyServer.cc @@ -67,7 +67,7 @@ void ProxyServer::send_to_end(const std::string& data, bool to_server) { PSOEncryption* crypt = to_server ? this->server_output_crypt.get() : this->client_output_crypt.get(); if (crypt) { string crypted_data = data; - crypt->encrypt(const_cast(crypted_data.data()), crypted_data.size()); + crypt->encrypt(crypted_data.data(), crypted_data.size()); evbuffer_add(buf, crypted_data.data(), crypted_data.size()); } else { evbuffer_add(buf, data.data(), data.size()); @@ -274,21 +274,19 @@ void ProxyServer::receive_and_process_commands(bool from_server) { } string command(command_size, '\0'); - ssize_t bytes = evbuffer_remove(source_buf, - const_cast(command.data()), command_size); + ssize_t bytes = evbuffer_remove(source_buf, command.data(), command_size); if (bytes < static_cast(command_size)) { throw logic_error("enough bytes available, but could not remove them"); } //log(INFO, "[ProxyServer-debug] read command (%zX bytes)", bytes); // overwrite the header with the already-decrypted header - memcpy(const_cast(command.data()), input_header, this->header_size); + memcpy(command.data(), input_header, this->header_size); //log(INFO, "[ProxyServer-debug] received encrypted command with pre-decrypted header"); //print_data(stderr, command); if (source_crypt) { - source_crypt->decrypt( - const_cast(command.data() + this->header_size), + source_crypt->decrypt(command.data() + this->header_size, command_size - this->header_size); } @@ -346,7 +344,7 @@ void ProxyServer::receive_and_process_commands(bool from_server) { } ReconnectCommandArgs* args = reinterpret_cast( - const_cast(command.data() + this->header_size)); + command.data() + this->header_size); memset(&this->next_destination, 0, sizeof(this->next_destination)); struct sockaddr_in* sin = reinterpret_cast( &this->next_destination); @@ -378,7 +376,7 @@ void ProxyServer::receive_and_process_commands(bool from_server) { // reencrypt and forward the command if (dest_buf) { if (dest_crypt) { - dest_crypt->encrypt(const_cast(command.data()), command.size()); + dest_crypt->encrypt(command.data(), command.size()); } //log(INFO, "[ProxyServer-debug] sending encrypted command"); //print_data(stderr, command); diff --git a/src/ProxyShell.cc b/src/ProxyShell.cc index 27bb46f8..0de56b6a 100644 --- a/src/ProxyShell.cc +++ b/src/ProxyShell.cc @@ -54,7 +54,7 @@ commands:\n\ if (data.size() == 0) { throw invalid_argument("no data given"); } - uint16_t* size_field = reinterpret_cast(const_cast(data.data() + 2)); + uint16_t* size_field = reinterpret_cast(data.data() + 2); *size_field = data.size(); log(INFO, "%s (from proxy):", to_client ? "server" : "client"); @@ -78,7 +78,7 @@ commands:\n\ } data.push_back('\0'); data.resize((data.size() + 3) & (~3)); - uint16_t* size_field = reinterpret_cast(const_cast(data.data() + 2)); + uint16_t* size_field = reinterpret_cast(data.data() + 2); *size_field = data.size(); log(INFO, "client (from proxy):"); diff --git a/src/Quest.cc b/src/Quest.cc index dd8d90ea..90fa4fd1 100644 --- a/src/Quest.cc +++ b/src/Quest.cc @@ -366,7 +366,7 @@ string Quest::decode_gci(const string& filename) { "GCI file is truncated before download quest header (have 0x%zX bytes)", data.size())); } PSODownloadQuestHeader* h = reinterpret_cast( - const_cast(data.data() + 0x2080)); + data.data() + 0x2080); h->byteswap(); string compressed_data_with_header = data.substr(0x2088, h->size); @@ -385,8 +385,8 @@ string Quest::decode_gci(const string& filename) { if (compressed_data_with_header.size() < sizeof(DecryptedHeader)) { throw runtime_error("GCI file compressed data truncated during header"); } - DecryptedHeader* dh = reinterpret_cast(const_cast( - compressed_data_with_header.data())); + DecryptedHeader* dh = reinterpret_cast( + compressed_data_with_header.data()); if (dh->unknown1 || dh->unknown2 || dh->unknown4) { throw runtime_error("GCI file appears to be encrypted"); } @@ -476,8 +476,7 @@ vector> QuestIndex::filter(GameVersion version, static string create_download_quest_file(const string& compressed_data, size_t decompressed_size) { string data(8, '\0'); - auto* header = reinterpret_cast(const_cast( - compressed_data.data())); + auto* header = reinterpret_cast(data.data()); header->size = decompressed_size + sizeof(PSODownloadQuestHeader); header->encryption_seed = random_object(); data += compressed_data; @@ -487,7 +486,7 @@ static string create_download_quest_file(const string& compressed_data, // TODO: for DC quests, do we use DC encryption? PSOPCEncryption encr(header->encryption_seed); - encr.encrypt(const_cast(data.data() + sizeof(PSODownloadQuestHeader)), + encr.encrypt(data.data() + sizeof(PSODownloadQuestHeader), data.size() - sizeof(PSODownloadQuestHeader)); return data; } @@ -498,7 +497,7 @@ shared_ptr Quest::create_download_quest(const string& file_basename) cons } string decompressed_bin = prs_decompress(*this->bin_contents()); - void* data_ptr = const_cast(decompressed_bin.data()); + void* data_ptr = decompressed_bin.data(); switch (this->version) { case GameVersion::DC: reinterpret_cast(data_ptr)->is_download = 0x01; diff --git a/src/ReceiveCommands.cc b/src/ReceiveCommands.cc index 771aa323..a236e0f8 100644 --- a/src/ReceiveCommands.cc +++ b/src/ReceiveCommands.cc @@ -2220,27 +2220,27 @@ void process_command(shared_ptr s, shared_ptr c, if (c->version == GameVersion::BB) { data_to_print.resize(size + 8); PSOCommandHeaderBB* header = reinterpret_cast( - const_cast(data_to_print.data())); + data_to_print.data()); header->command = command; header->flag = flag; header->size = size + 8; - memcpy(const_cast(data_to_print.data() + 8), data, size); + memcpy(data_to_print.data() + 8, data, size); } else if (c->version == GameVersion::PC) { data_to_print.resize(size + 4); PSOCommandHeaderPC* header = reinterpret_cast( - const_cast(data_to_print.data())); + data_to_print.data()); header->command = command; header->flag = flag; header->size = size + 4; - memcpy(const_cast(data_to_print.data() + 4), data, size); + memcpy(data_to_print.data() + 4, data, size); } else { // DC/GC data_to_print.resize(size + 4); PSOCommandHeaderDCGC* header = reinterpret_cast( - const_cast(data_to_print.data())); + data_to_print.data()); header->command = command; header->flag = flag; header->size = size + 4; - memcpy(const_cast(data_to_print.data() + 4), data, size); + memcpy(data_to_print.data() + 4, data, size); } print_data(stderr, data_to_print); } diff --git a/src/SendCommands.cc b/src/SendCommands.cc index c5a7ef12..fe567872 100644 --- a/src/SendCommands.cc +++ b/src/SendCommands.cc @@ -360,8 +360,8 @@ void send_guild_card_chunk_bb(shared_ptr c, size_t chunk_index) { } string contents(8, '\0'); - *reinterpret_cast(const_cast(contents.data())) = 0; - *reinterpret_cast(const_cast(contents.data() + 4)) = chunk_index; + *reinterpret_cast(contents.data()) = 0; + *reinterpret_cast(contents.data() + 4) = chunk_index; contents.append(reinterpret_cast(&c->player.guild_cards + chunk_offset), data_size); @@ -469,7 +469,7 @@ static void send_large_message_pc_patch_bb(shared_ptr c, uint8_t command u16string data; if (include_header) { data.resize(sizeof(LargeMessageOptionalHeader) / sizeof(char16_t)); - *reinterpret_cast(const_cast(data.data())) = + *reinterpret_cast(data.data()) = {0, from_serial_number}; } data += text; @@ -483,7 +483,7 @@ static void send_large_message_dc_gc(shared_ptr c, uint8_t command, string data; if (include_header) { data.resize(sizeof(LargeMessageOptionalHeader) / sizeof(char)); - *reinterpret_cast(const_cast(data.data())) = + *reinterpret_cast(data.data()) = {0, from_serial_number}; } data += encode_sjis(text); @@ -2025,7 +2025,7 @@ void send_ep3_card_list_update(shared_ptr c) { auto file_data = file_cache.get("system/ep3/cardupdate.mnr"); string data("\0\0\0\0", 4); - *reinterpret_cast(const_cast(data.data())) = file_data->size(); + *reinterpret_cast(data.data()) = file_data->size(); data += *file_data; data.resize((data.size() + 3) & ~3); @@ -2049,7 +2049,7 @@ void send_ep3_map_list(shared_ptr l) { auto file_data = file_cache.get("system/ep3/maplist.mnr"); string data(16, '\0'); - PSOSubcommand* subs = reinterpret_cast(const_cast(data.data())); + PSOSubcommand* subs = reinterpret_cast(data.data()); subs[0].dword = 0x000000B6; subs[1].dword = (23 + file_data->size()) & 0xFFFFFFFC; subs[2].dword = 0x00000040; @@ -2065,7 +2065,7 @@ void send_ep3_map_data(shared_ptr l, uint32_t map_id) { auto file_data = file_cache.get(filename); string data(12, '\0'); - PSOSubcommand* subs = reinterpret_cast(const_cast(data.data())); + PSOSubcommand* subs = reinterpret_cast(data.data()); subs[0].dword = 0x000000B6; subs[1].dword = (19 + file_data->size()) & 0xFFFFFFFC; subs[2].dword = 0x00000041; @@ -2168,7 +2168,7 @@ void send_server_time(shared_ptr c) { gmtime_r(&t_secs, &t_parsed); string time_str(128, 0); - size_t len = strftime(const_cast(time_str.data()), time_str.size(), + size_t len = strftime(time_str.data(), time_str.size(), "%Y:%m:%d: %H:%M:%S.000", &t_parsed); if (len == 0) { throw runtime_error("format_time buffer too short"); diff --git a/src/Server.cc b/src/Server.cc index 4f1c7b0a..f9557638 100644 --- a/src/Server.cc +++ b/src/Server.cc @@ -184,7 +184,7 @@ void Server::receive_and_process_commands(shared_ptr c) { size_t new_bytes = evbuffer_get_length(buf); new_bytes &= ~(header_size - 1); // only read in multiples of header_size c->recv_buffer.resize(existing_bytes + new_bytes); - void* recv_ptr = const_cast(c->recv_buffer.data() + existing_bytes); + void* recv_ptr = c->recv_buffer.data() + existing_bytes; if (evbuffer_remove(buf, recv_ptr, new_bytes) != static_cast(new_bytes)) { throw runtime_error("some bytes could not be read from the receive buffer"); } diff --git a/src/Shell.cc b/src/Shell.cc index 6228a4d9..c62d4151 100644 --- a/src/Shell.cc +++ b/src/Shell.cc @@ -57,7 +57,7 @@ void Shell::read_stdin() { } string command(2048, '\0'); - if (!fgets(const_cast(command.data()), command.size(), stdin)) { + if (!fgets(command.data(), command.size(), stdin)) { if (!any_command_read) { // ctrl+d probably; we should exit fputc('\n', stderr); diff --git a/src/Text.hh b/src/Text.hh index 47848a9e..bd895c1e 100644 --- a/src/Text.hh +++ b/src/Text.hh @@ -72,6 +72,6 @@ size_t add_color_inplace(T* a) { template void add_color_inplace(std::basic_string& a, size_t header_bytes) { - size_t count = add_color_inplace(const_cast(a.data() + header_bytes)); + size_t count = add_color_inplace(a.data() + header_bytes); a.resize(count + header_bytes); }