@@ -15,6 +15,7 @@ Module Name:
15
15
--*/
16
16
17
17
#include " uefiext.h"
18
+ #include < vector>
18
19
19
20
UEFI_ENV gUefiEnv = DXE;
20
21
ULONG g_TargetMachine;
@@ -244,8 +245,7 @@ uefiext_init (
244
245
}
245
246
246
247
// Used to capture output from debugger commands
247
- CHAR mOutput [0x2000 ];
248
- ULONG mOutputOffset = 0 ;
248
+ std::vector<std::string> mResponses = { };
249
249
250
250
class OutputCallbacks : public IDebugOutputCallbacks {
251
251
public:
@@ -270,9 +270,7 @@ class OutputCallbacks : public IDebugOutputCallbacks {
270
270
}
271
271
272
272
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));
276
274
return S_OK;
277
275
}
278
276
};
@@ -286,9 +284,17 @@ ExecuteCommandWithOutput (
286
284
)
287
285
{
288
286
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
+ }
289
296
290
- mOutputOffset = 0 ;
291
- ZeroMemory (mOutput , sizeof (mOutput ));
297
+ mResponses .clear ();
292
298
293
299
Client->GetOutputCallbacks (&Callbacks);
294
300
Client->SetOutputCallbacks (&mOutputCallback );
@@ -298,7 +304,21 @@ ExecuteCommandWithOutput (
298
304
DEBUG_EXECUTE_DEFAULT
299
305
);
300
306
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;
302
322
}
303
323
304
324
PSTR
@@ -313,6 +333,7 @@ MonitorCommandWithOutput (
313
333
ULONG Mask;
314
334
PCSTR Preamble = " Target command response: " ;
315
335
PCSTR Ending = " exdiCmd:" ;
336
+ PCSTR Ok = " OK\n " ;
316
337
317
338
if (Offset == 0 ) {
318
339
sprintf_s (Command, sizeof (Command), " .exdicmd target:0:%s" , MonitorCommand);
@@ -334,5 +355,13 @@ MonitorCommandWithOutput (
334
355
*strstr (Output, Ending) = 0 ;
335
356
}
336
357
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
+
337
366
return Output;
338
367
}
0 commit comments