From 6209fe0c27a5557c20ff6350a94f6e074e0285dc Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Fri, 16 Nov 2018 22:20:09 -0500 Subject: software_keyboard: Push buffer size to offset 0x4 in output data --- src/core/hle/service/am/applets/applets.h | 4 +++- src/core/hle/service/am/applets/software_keyboard.cpp | 18 +++++++++++++----- src/core/hle/service/am/applets/software_keyboard.h | 5 ++++- 3 files changed, 20 insertions(+), 7 deletions(-) (limited to 'src/core/hle/service/am/applets') diff --git a/src/core/hle/service/am/applets/applets.h b/src/core/hle/service/am/applets/applets.h index 7fbaaf2f3..1ffa09420 100644 --- a/src/core/hle/service/am/applets/applets.h +++ b/src/core/hle/service/am/applets/applets.h @@ -22,6 +22,7 @@ class IStorage; namespace Applets { using AppletStorageProxyFunction = std::function; +using AppletStateProxyFunction = std::function; class Applet { public: @@ -34,7 +35,8 @@ public: virtual ResultCode GetStatus() const = 0; virtual void ReceiveInteractiveData(std::shared_ptr storage) = 0; virtual void Execute(AppletStorageProxyFunction out_data, - AppletStorageProxyFunction out_interactive_data) = 0; + AppletStorageProxyFunction out_interactive_data, + AppletStateProxyFunction state) = 0; bool IsInitialized() const { return initialized; diff --git a/src/core/hle/service/am/applets/software_keyboard.cpp b/src/core/hle/service/am/applets/software_keyboard.cpp index 66b34d5ac..bb28a2e8d 100644 --- a/src/core/hle/service/am/applets/software_keyboard.cpp +++ b/src/core/hle/service/am/applets/software_keyboard.cpp @@ -69,7 +69,7 @@ bool SoftwareKeyboard::TransactionComplete() const { } ResultCode SoftwareKeyboard::GetStatus() const { - return RESULT_SUCCESS; + return status; } void SoftwareKeyboard::ReceiveInteractiveData(std::shared_ptr storage) { @@ -92,7 +92,8 @@ void SoftwareKeyboard::ReceiveInteractiveData(std::shared_ptr storage) } void SoftwareKeyboard::Execute(AppletStorageProxyFunction out_data, - AppletStorageProxyFunction out_interactive_data) { + AppletStorageProxyFunction out_interactive_data, + AppletStateProxyFunction state) { if (complete) return; @@ -102,6 +103,7 @@ void SoftwareKeyboard::Execute(AppletStorageProxyFunction out_data, this->out_data = out_data; this->out_interactive_data = out_interactive_data; + this->state = state; frontend.RequestText([this](std::optional text) { WriteText(text); }, parameters); } @@ -110,6 +112,7 @@ void SoftwareKeyboard::WriteText(std::optional text) { std::vector output(SWKBD_OUTPUT_BUFFER_SIZE); if (text.has_value()) { + status = RESULT_SUCCESS; if (config.text_check) { const auto size = static_cast(text->size() * 2 + 4); std::memcpy(output.data(), &size, sizeof(u32)); @@ -117,9 +120,12 @@ void SoftwareKeyboard::WriteText(std::optional text) { output[0] = 1; } - std::memcpy(output.data() + 4, text->data(), - std::min(text->size() * 2, SWKBD_OUTPUT_BUFFER_SIZE - 4)); + const auto size = static_cast(text->size()); + std::memcpy(output.data() + 4, &size, sizeof(u32)); + std::memcpy(output.data() + 8, text->data(), + std::min(text->size() * 2, SWKBD_OUTPUT_BUFFER_SIZE - 8)); } else { + status = ResultCode(-1); complete = true; out_data(IStorage{output}); return; @@ -127,6 +133,8 @@ void SoftwareKeyboard::WriteText(std::optional text) { complete = !config.text_check; - (complete ? out_data : out_interactive_data)(IStorage{output}); + out_data(IStorage{output}); + out_interactive_data(IStorage{output}); + state(); } } // namespace Service::AM::Applets diff --git a/src/core/hle/service/am/applets/software_keyboard.h b/src/core/hle/service/am/applets/software_keyboard.h index b08bff3d7..9629f6408 100644 --- a/src/core/hle/service/am/applets/software_keyboard.h +++ b/src/core/hle/service/am/applets/software_keyboard.h @@ -55,7 +55,8 @@ public: ResultCode GetStatus() const override; void ReceiveInteractiveData(std::shared_ptr storage) override; void Execute(AppletStorageProxyFunction out_data, - AppletStorageProxyFunction out_interactive_data) override; + AppletStorageProxyFunction out_interactive_data, + AppletStateProxyFunction state) override; void WriteText(std::optional text); @@ -64,9 +65,11 @@ private: std::u16string initial_text; bool complete = false; std::vector final_data; + ResultCode status = ResultCode(-1); AppletStorageProxyFunction out_data; AppletStorageProxyFunction out_interactive_data; + AppletStateProxyFunction state; }; } // namespace Service::AM::Applets -- cgit v1.2.3