From c98158b460dd20749c79fd28e9874e717af43979 Mon Sep 17 00:00:00 2001 From: RipleyTom Date: Fri, 17 Mar 2023 13:43:23 +0100 Subject: [PATCH] Add buf_to_hexstring --- Utilities/StrFmt.cpp | 20 ++++++++++ Utilities/StrUtil.h | 9 +++++ rpcs3/Emu/Cell/Modules/sceNp.cpp | 43 +++------------------- rpcs3/Emu/Cell/lv2/sys_net.cpp | 17 +-------- rpcs3/Emu/Cell/lv2/sys_usbd.cpp | 42 ++------------------- rpcs3/Emu/NP/np_dnshook.cpp | 18 +-------- rpcs3/rpcs3qt/recvmessage_dialog_frame.cpp | 4 +- 7 files changed, 43 insertions(+), 110 deletions(-) diff --git a/Utilities/StrFmt.cpp b/Utilities/StrFmt.cpp index 66d421977f..a2a5573a1b 100644 --- a/Utilities/StrFmt.cpp +++ b/Utilities/StrFmt.cpp @@ -214,6 +214,26 @@ void fmt_class_string>::format(std::string& out, u64 arg) out.append(obj.cbegin(), obj.cend()); } +template <> +void fmt_class_string::format(std::string& out, u64 arg) +{ + const auto& _arg = get_object(arg); + const std::vector buf(_arg.buf, _arg.buf + _arg.len); + out.reserve(out.size() + (buf.size() * 3)); + static constexpr char hex[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; + + for (usz index = 0; index < buf.size(); index++) + { + out += hex[buf[index] >> 4]; + out += hex[buf[index] & 15]; + + if (((index + 1) % 16) == 0) + out += '\n'; + else + out += ' '; + } +} + void format_byte_array(std::string& out, const uchar* data, usz size) { if (!size) diff --git a/Utilities/StrUtil.h b/Utilities/StrUtil.h index 456a0634d3..40208c3a57 100644 --- a/Utilities/StrUtil.h +++ b/Utilities/StrUtil.h @@ -177,4 +177,13 @@ namespace fmt std::string to_lower(const std::string& string); bool match(const std::string& source, const std::string& mask); + + struct buf_to_hexstring + { + buf_to_hexstring(const u8* buf, usz len) + : buf(buf), len(len) {} + + const u8* buf; + usz len; + }; } diff --git a/rpcs3/Emu/Cell/Modules/sceNp.cpp b/rpcs3/Emu/Cell/Modules/sceNp.cpp index 5aa5534337..7ae3704948 100644 --- a/rpcs3/Emu/Cell/Modules/sceNp.cpp +++ b/rpcs3/Emu/Cell/Modules/sceNp.cpp @@ -986,25 +986,7 @@ error_code sceNpBasicSendMessageGui(vm::cptr msg, sys_ msg_data.data.assign(msg->data.get_ptr(), msg->data.get_ptr() + msg->size); } - if (sceNp.trace) - { - std::string datrace; - const char hex[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; - - const u8* buf = msg->data.get_ptr(); - - for (u32 index = 0; index < msg->size; index++) - { - if ((index % 16) == 0) - datrace += '\n'; - - datrace += hex[(buf[index] >> 4) & 15]; - datrace += hex[(buf[index]) & 15]; - datrace += ' '; - } - - sceNp.trace("Message Data: %s", datrace); - } + sceNp.trace("Message Data:\n%s", fmt::buf_to_hexstring(msg->data.get_ptr(), msg->size)); bool result = false; @@ -1103,7 +1085,7 @@ error_code sceNpBasicRecvMessageAttachment(sys_memory_container_t containerId) return CELL_OK; } -error_code sceNpBasicRecvMessageAttachmentLoad(ppu_thread& ppu, SceNpBasicAttachmentDataId id, vm::ptr buffer, vm::ptr size) +error_code sceNpBasicRecvMessageAttachmentLoad(SceNpBasicAttachmentDataId id, vm::ptr buffer, vm::ptr size) { sceNp.warning("sceNpBasicRecvMessageAttachmentLoad(id=%d, buffer=*0x%x, size=*0x%x)", id, buffer, size); @@ -1135,6 +1117,7 @@ error_code sceNpBasicRecvMessageAttachmentLoad(ppu_thread& ppu, SceNpBasicAttach return SCE_NP_BASIC_ERROR_INVALID_DATA_ID; } + // Not sure about this // nph.clear_message_selected(id); const auto msg_pair = opt_msg.value(); @@ -1144,24 +1127,7 @@ error_code sceNpBasicRecvMessageAttachmentLoad(ppu_thread& ppu, SceNpBasicAttach const u32 size_to_copy = std::min(static_cast(msg.data.size()), orig_size); memcpy(buffer.get_ptr(), msg.data.data(), size_to_copy); - if (sceNp.trace) - { - std::string datrace; - const char hex[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; - - const u8* buf = static_cast(buffer.get_ptr()); - for (u32 index = 0; index < size_to_copy; index++) - { - if ((index % 16) == 0) - datrace += '\n'; - - datrace += hex[(buf[index] >> 4) & 15]; - datrace += hex[(buf[index]) & 15]; - datrace += ' '; - } - - sceNp.trace("Message Data received: %s", datrace); - } + sceNp.trace("Message Data received:\n%s", fmt::buf_to_hexstring(static_cast(buffer.get_ptr()), size_to_copy)); *size = size_to_copy; if (size_to_copy < msg.data.size()) @@ -1236,6 +1202,7 @@ error_code sceNpBasicRecvMessageCustom(u16 mainType, u32 recvOptions, sys_memory nph.set_message_selected(att_data->data.id, chosen_msg_id); + // Is this sent if used from home menu but not from sceNpBasicRecvMessageCustom, not sure // sysutil_send_system_cmd(CELL_SYSUTIL_NP_INVITATION_SELECTED, 0); nph.queue_basic_event(to_add); diff --git a/rpcs3/Emu/Cell/lv2/sys_net.cpp b/rpcs3/Emu/Cell/lv2/sys_net.cpp index 641bd5c1da..9a547a7a0a 100644 --- a/rpcs3/Emu/Cell/lv2/sys_net.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_net.cpp @@ -334,22 +334,7 @@ void lv2_socket::save(utils::serial& ar, bool save_only_this_class) void sys_net_dump_data(std::string_view desc, const u8* data, s32 len) { - if (sys_net_dump.trace) - { - auto data_dump = fmt::format("%s:\n", desc); - const char hex[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; - - for (s32 index = 0; index < len; index++) - { - if ((index % 16) == 0) - data_dump += '\n'; - - data_dump += hex[(data[index] >> 4) & 15]; - data_dump += hex[(data[index]) & 15]; - data_dump += ' '; - } - sys_net.trace("%s", data_dump); - } + sys_net_dump.trace("%s:%s", desc, fmt::buf_to_hexstring(data, len)); } error_code sys_net_bnet_accept(ppu_thread& ppu, s32 s, vm::ptr addr, vm::ptr paddrlen) diff --git a/rpcs3/Emu/Cell/lv2/sys_usbd.cpp b/rpcs3/Emu/Cell/lv2/sys_usbd.cpp index 9f41f0702e..05e69fd0c8 100644 --- a/rpcs3/Emu/Cell/lv2/sys_usbd.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_usbd.cpp @@ -28,20 +28,8 @@ template <> void fmt_class_string::format(std::string& out, u64 arg) { const auto& transfer = get_object(arg); - - std::string datrace; - const char hex[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; - const int data_start = transfer.type == LIBUSB_TRANSFER_TYPE_CONTROL ? LIBUSB_CONTROL_SETUP_SIZE : 0; - - for (int index = data_start; index < data_start + transfer.actual_length; index++) - { - datrace += hex[transfer.buffer[index] >> 4]; - datrace += hex[(transfer.buffer[index]) & 15]; - datrace += ' '; - } - - fmt::append(out, "TR[r:%d][sz:%d] => %s", +transfer.status, transfer.actual_length, datrace); + fmt::append(out, "TR[r:%d][sz:%d] => %s", +transfer.status, transfer.actual_length, fmt::buf_to_hexstring(&transfer.buffer[data_start], transfer.actual_length)); } struct UsbLdd @@ -951,20 +939,9 @@ error_code sys_usbd_transfer_data(ppu_thread& ppu, u32 handle, u32 id_pipe, vm:: if (sys_usbd.trace && request) { sys_usbd.trace("RequestType:0x%x, Request:0x%x, wValue:0x%x, wIndex:0x%x, wLength:0x%x", request->bmRequestType, request->bRequest, request->wValue, request->wIndex, request->wLength); + if ((request->bmRequestType & 0x80) == 0 && buf && buf_size != 0) - { - std::string datrace; - const char hex[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; - - for (u32 index = 0; index < buf_size; index++) - { - datrace += hex[(buf[index] >> 4) & 15]; - datrace += hex[(buf[index]) & 15]; - datrace += ' '; - } - - sys_usbd.trace("Control sent: %s", datrace); - } + sys_usbd.trace("Control sent:\n%s", fmt::buf_to_hexstring(buf.get_ptr(), buf_size)); } auto& usbh = g_fxo->get>(); @@ -1023,19 +1000,8 @@ error_code sys_usbd_transfer_data(ppu_thread& ppu, u32 handle, u32 id_pipe, vm:: { // If output endpoint if (!(pipe.endpoint & 0x80)) - { - std::string datrace; - const char hex[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; + sys_usbd.trace("Write Int(s: %d):\n%s", buf_size, fmt::buf_to_hexstring(buf.get_ptr(), buf_size)); - for (u32 index = 0; index < buf_size; index++) - { - datrace += hex[buf[index] >> 4]; - datrace += hex[buf[index] & 15]; - datrace += ' '; - } - - sys_usbd.trace("Write Int(s: %d) :%s", buf_size, datrace); - } pipe.device->interrupt_transfer(buf_size, buf.get_ptr(), pipe.endpoint, &transfer); } diff --git a/rpcs3/Emu/NP/np_dnshook.cpp b/rpcs3/Emu/NP/np_dnshook.cpp index 84a12bf45e..b1ce2b196d 100644 --- a/rpcs3/Emu/NP/np_dnshook.cpp +++ b/rpcs3/Emu/NP/np_dnshook.cpp @@ -102,22 +102,8 @@ namespace np s32 dnshook::analyze_dns_packet(s32 s, const u8* buf, u32 len) { std::lock_guard lock(mutex); - if (dnshook_log.trace) - { - std::string datrace; - const char hex[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; - - for (u32 index = 0; index < len; index++) - { - if ((index % 16) == 0) - datrace += '\n'; - - datrace += hex[(buf[index] >> 4) & 15]; - datrace += hex[(buf[index]) & 15]; - datrace += ' '; - } - dnshook_log.trace("DNS REQUEST: %s", datrace); - } + + dnshook_log.trace("DNS REQUEST:\n%s", fmt::buf_to_hexstring(buf, len)); struct dns_header { diff --git a/rpcs3/rpcs3qt/recvmessage_dialog_frame.cpp b/rpcs3/rpcs3qt/recvmessage_dialog_frame.cpp index be9d3782d9..d358659302 100644 --- a/rpcs3/rpcs3qt/recvmessage_dialog_frame.cpp +++ b/rpcs3/rpcs3qt/recvmessage_dialog_frame.cpp @@ -83,9 +83,9 @@ bool recvmessage_dialog_frame::Exec(SceNpBasicMessageMainType type, SceNpBasicMe connect(btn_accept, &QAbstractButton::clicked, this, [&accept_or_deny]() { accept_or_deny(SCE_NP_BASIC_MESSAGE_ACTION_ACCEPT); }); - connect(btn_deny, &QAbstractButton::clicked, this, [&accept_or_deny]() + connect(btn_deny, &QAbstractButton::clicked, this, [&accept_or_deny]() { accept_or_deny(SCE_NP_BASIC_MESSAGE_ACTION_DENY); }); - connect(btn_cancel, &QAbstractButton::clicked, this, [m_dialog=this->m_dialog]() + connect(btn_cancel, &QAbstractButton::clicked, this, [this]() { m_dialog->close(); }); connect(this, &recvmessage_dialog_frame::signal_new_message, this, &recvmessage_dialog_frame::slot_new_message);