@@ -15,6 +15,7 @@ Module Name:
1515--*/
1616
1717#include " uefiext.h"
18+ #include < vector>
1819
1920UEFI_ENV gUefiEnv = DXE;
2021ULONG g_TargetMachine;
@@ -244,8 +245,7 @@ uefiext_init (
244245}
245246
246247// Used to capture output from debugger commands
247- CHAR mOutput [0x2000 ];
248- ULONG mOutputOffset = 0 ;
248+ std::vector<std::string> mResponses = { };
249249
250250class OutputCallbacks : public IDebugOutputCallbacks {
251251public:
@@ -270,9 +270,7 @@ class OutputCallbacks : public IDebugOutputCallbacks {
270270 }
271271
272272 STDMETHOD (Output)(THIS_ ULONG Mask, PCSTR Text) {
273- strcpy_s (mOutput + mOutputOffset , sizeof (mOutput ) - mOutputOffset , Text);
274- mOutputOffset += strlen (Text);
275- mOutputOffset = min (mOutputOffset , sizeof (mOutput )); // Ensure we don't overflow the buffer.
273+ mResponses .push_back (std::string (Text));
276274 return S_OK;
277275 }
278276};
@@ -286,9 +284,17 @@ ExecuteCommandWithOutput (
286284 )
287285{
288286 PDEBUG_OUTPUT_CALLBACKS Callbacks;
287+ static CHAR *Output = NULL ;
288+ SIZE_T Offset;
289+ SIZE_T Length;
290+
291+ // To avoid complexity of tracking a shifting buffer, easier to just lazily free here.
292+ if (Output != NULL ) {
293+ free (Output);
294+ Output = NULL ;
295+ }
289296
290- mOutputOffset = 0 ;
291- ZeroMemory (mOutput , sizeof (mOutput ));
297+ mResponses .clear ();
292298
293299 Client->GetOutputCallbacks (&Callbacks);
294300 Client->SetOutputCallbacks (&mOutputCallback );
@@ -298,7 +304,21 @@ ExecuteCommandWithOutput (
298304 DEBUG_EXECUTE_DEFAULT
299305 );
300306 Client->SetOutputCallbacks (Callbacks);
301- return mOutput ;
307+
308+ Length = 0 ;
309+ for (const auto &str : mResponses ) {
310+ Length += str.length ();
311+ }
312+
313+ Output = (CHAR *)malloc (Length + 1 );
314+ Offset = 0 ;
315+ for (const auto &str : mResponses ) {
316+ memcpy (Output + Offset, str.c_str (), str.length ());
317+ Offset += str.length ();
318+ }
319+
320+ Output[Offset] = ' \0 ' ;
321+ return Output;
302322}
303323
304324PSTR
@@ -313,6 +333,7 @@ MonitorCommandWithOutput (
313333 ULONG Mask;
314334 PCSTR Preamble = " Target command response: " ;
315335 PCSTR Ending = " exdiCmd:" ;
336+ PCSTR Ok = " OK\n " ;
316337
317338 if (Offset == 0 ) {
318339 sprintf_s (Command, sizeof (Command), " .exdicmd target:0:%s" , MonitorCommand);
@@ -334,5 +355,13 @@ MonitorCommandWithOutput (
334355 *strstr (Output, Ending) = 0 ;
335356 }
336357
358+ // If it has the OK string appended to the end, remove it
359+ if (strlen (Output) > strlen (Ok)) {
360+ size_t Offset = strlen (Output) - strlen (Ok);
361+ if (strcmp (Output + Offset, Ok) == 0 ) {
362+ strcpy_s (Output + Offset, strlen (Ok) + 1 , " \n " );
363+ }
364+ }
365+
337366 return Output;
338367}
0 commit comments