157
157
" of a container can be registered.\n"
160
(u64Cmd & USAGE_DUMPHDINFO) ?
161
" dumphdinfo <filepath>\n"
162
" Prints information about the image at the given location.\n"
160
165
(u64Cmd & USAGE_LISTPARTITIONS) ?
161
166
" listpartitions -rawdisk <diskname>\n"
162
167
" Lists all partitions on <diskname>.\n"
440
int rc = RTStrToInt64Ex(argv[2], NULL, 0, &offDelta);
445
int irc = RTStrToInt64Ex(argv[2], NULL, 0, &offDelta);
442
447
return errorArgument(argv[0], "Failed to read delta '%s', rc=%Rrc\n", argv[2], rc);
449
454
/* ModuleAddress */
452
int rc = RTStrToUInt64Ex(argv[4], NULL, 0, &ModuleAddress);
457
int irc = RTStrToUInt64Ex(argv[4], NULL, 0, &ModuleAddress);
454
459
return errorArgument(argv[0], "Failed to read module address '%s', rc=%Rrc\n", argv[4], rc);
460
int rc = RTStrToUInt64Ex(argv[5], NULL, 0, &ModuleSize);
465
int irc = RTStrToUInt64Ex(argv[5], NULL, 0, &ModuleSize);
462
467
return errorArgument(argv[0], "Failed to read module size '%s', rc=%Rrc\n", argv[5], rc);
469
474
HRESULT hrc = NewUniqueKey(machine, "VBoxInternal/DBGF/loadsyms", KeyStr);
470
475
if (SUCCEEDED(hrc))
471
hrc = SetString(machine, "VBoxInternal/DBGF/loadsyms", KeyStr, "Filename", pszFilename);
476
hrc = SetString(machine, "VBoxInternal/DBGF/loadsyms", KeyStr.c_str(), "Filename", pszFilename);
472
477
if (SUCCEEDED(hrc) && argc >= 3)
473
hrc = SetInt64(machine, "VBoxInternal/DBGF/loadsyms", KeyStr, "Delta", offDelta);
478
hrc = SetInt64(machine, "VBoxInternal/DBGF/loadsyms", KeyStr.c_str(), "Delta", offDelta);
474
479
if (SUCCEEDED(hrc) && argc >= 4)
475
hrc = SetString(machine, "VBoxInternal/DBGF/loadsyms", KeyStr, "Module", pszModule);
480
hrc = SetString(machine, "VBoxInternal/DBGF/loadsyms", KeyStr.c_str(), "Module", pszModule);
476
481
if (SUCCEEDED(hrc) && argc >= 5)
477
hrc = SetUInt64(machine, "VBoxInternal/DBGF/loadsyms", KeyStr, "ModuleAddress", ModuleAddress);
482
hrc = SetUInt64(machine, "VBoxInternal/DBGF/loadsyms", KeyStr.c_str(), "ModuleAddress", ModuleAddress);
478
483
if (SUCCEEDED(hrc) && argc >= 6)
479
hrc = SetUInt64(machine, "VBoxInternal/DBGF/loadsyms", KeyStr, "ModuleSize", ModuleSize);
484
hrc = SetUInt64(machine, "VBoxInternal/DBGF/loadsyms", KeyStr.c_str(), "ModuleSize", ModuleSize);
481
486
return FAILED(hrc);
490
495
RTPrintf("Error code %Rrc at %s(%u) in function %s\n", rc, RT_SRC_POS_ARGS);
493
static int handleSetHDUUID(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
498
static int CmdSetHDUUID(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
495
500
/* we need exactly one parameter: the image file */
505
510
/* just try it */
506
511
char *pszFormat = NULL;
507
int rc = VDGetFormat(argv[0], &pszFormat);
512
int rc = VDGetFormat(NULL, argv[0], &pszFormat);
508
513
if (RT_FAILURE(rc))
510
515
RTPrintf("Format autodetect failed: %Rrc\n", rc);
519
524
vdInterfaceErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR);
520
525
vdInterfaceErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR;
521
526
vdInterfaceErrorCallbacks.pfnError = handleVDError;
527
vdInterfaceErrorCallbacks.pfnMessage = NULL;
523
529
rc = VDInterfaceAdd(&vdInterfaceError, "VBoxManage_IError", VDINTERFACETYPE_ERROR,
524
530
&vdInterfaceErrorCallbacks, NULL, &pVDIfs);
550
556
return RT_FAILURE(rc);
560
static int handleVDMessage(void *pvUser, const char *pszFormat, ...)
564
va_start(args, pszFormat);
565
int rc = RTPrintfV(pszFormat, args);
570
static int CmdDumpHDInfo(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
572
/* we need exactly one parameter: the image file */
575
return errorSyntax(USAGE_SETHDUUID, "Not enough parameters");
579
char *pszFormat = NULL;
580
int rc = VDGetFormat(NULL, argv[0], &pszFormat);
583
RTPrintf("Format autodetect failed: %Rrc\n", rc);
587
PVBOXHDD pDisk = NULL;
589
PVDINTERFACE pVDIfs = NULL;
590
VDINTERFACE vdInterfaceError;
591
VDINTERFACEERROR vdInterfaceErrorCallbacks;
592
vdInterfaceErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR);
593
vdInterfaceErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR;
594
vdInterfaceErrorCallbacks.pfnError = handleVDError;
595
vdInterfaceErrorCallbacks.pfnMessage = handleVDMessage;
597
rc = VDInterfaceAdd(&vdInterfaceError, "VBoxManage_IError", VDINTERFACETYPE_ERROR,
598
&vdInterfaceErrorCallbacks, NULL, &pVDIfs);
601
rc = VDCreate(pVDIfs, &pDisk);
604
RTPrintf("Error while creating the virtual disk container: %Rrc\n", rc);
609
rc = VDOpen(pDisk, pszFormat, argv[0], VD_OPEN_FLAGS_NORMAL, NULL);
612
RTPrintf("Error while opening the image: %Rrc\n", rc);
620
return RT_FAILURE(rc);
553
623
static int partRead(RTFILE File, PHOSTPARTITIONS pPart)
555
625
uint8_t aBuffer[512];
753
823
return errorSyntax(USAGE_LISTPARTITIONS, "Mandatory parameter -rawdisk missing");
756
int vrc = RTFileOpen(&RawFile, rawdisk.raw(), RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE);
826
int vrc = RTFileOpen(&RawFile, rawdisk.raw(), RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE);
757
827
if (RT_FAILURE(vrc))
759
829
RTPrintf("Error opening the raw disk: %Rrc\n", vrc);
873
943
fRelative = true;
874
944
#endif /* RT_OS_DARWIN */
876
int vrc = RTFileOpen(&RawFile, rawdisk.raw(), RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE);
946
int vrc = RTFileOpen(&RawFile, rawdisk.raw(), RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE);
877
947
if (RT_FAILURE(vrc))
879
949
RTPrintf("Error opening the raw disk '%s': %Rrc\n", rawdisk.raw(), vrc);
1200
1270
&& pszMBRFilename)
1202
1272
RTFILE MBRFile;
1203
vrc = RTFileOpen(&MBRFile, pszMBRFilename, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE);
1273
vrc = RTFileOpen(&MBRFile, pszMBRFilename, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE);
1204
1274
if (RT_FAILURE(vrc))
1206
1276
RTPrintf("Cannot open replacement MBR file '%s' specified with -mbr: %Rrc\n", pszMBRFilename, vrc);
1226
1296
vdInterfaceErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR);
1227
1297
vdInterfaceErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR;
1228
1298
vdInterfaceErrorCallbacks.pfnError = handleVDError;
1299
vdInterfaceErrorCallbacks.pfnMessage = NULL;
1230
1301
vrc = VDInterfaceAdd(&vdInterfaceError, "VBoxManage_IError", VDINTERFACETYPE_ERROR,
1231
1302
&vdInterfaceErrorCallbacks, NULL, &pVDIfs);
1283
ComPtr<IHardDisk> hardDisk;
1354
ComPtr<IMedium> hardDisk;
1284
1355
CHECK_ERROR(aVirtualBox, OpenHardDisk(filename, AccessMode_ReadWrite, false, Bstr(""), false, Bstr(""), hardDisk.asOutParam()));
1335
1406
vdInterfaceErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR);
1336
1407
vdInterfaceErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR;
1337
1408
vdInterfaceErrorCallbacks.pfnError = handleVDError;
1409
vdInterfaceErrorCallbacks.pfnMessage = NULL;
1339
1411
int vrc = VDInterfaceAdd(&vdInterfaceError, "VBoxManage_IError", VDINTERFACETYPE_ERROR,
1340
1412
&vdInterfaceErrorCallbacks, NULL, &pVDIfs);
1416
1488
vdInterfaceErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR);
1417
1489
vdInterfaceErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR;
1418
1490
vdInterfaceErrorCallbacks.pfnError = handleVDError;
1491
vdInterfaceErrorCallbacks.pfnMessage = NULL;
1420
1493
int vrc = VDInterfaceAdd(&vdInterfaceError, "VBoxManage_IError", VDINTERFACETYPE_ERROR,
1421
1494
&vdInterfaceErrorCallbacks, NULL, &pVDIfs);
1434
1507
if (fWriteToStdOut)
1437
vrc = RTFileOpen(&outFile, Utf8Str(dst).raw(), RTFILE_O_OPEN | RTFILE_O_CREATE | RTFILE_O_WRITE | RTFILE_O_DENY_ALL);
1510
vrc = RTFileOpen(&outFile, Utf8Str(dst).raw(), RTFILE_O_WRITE | RTFILE_O_CREATE | RTFILE_O_DENY_ALL);
1438
1511
if (RT_FAILURE(vrc))
1440
1513
VDCloseAll(pDisk);
1580
1653
vdInterfaceErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR);
1581
1654
vdInterfaceErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR;
1582
1655
vdInterfaceErrorCallbacks.pfnError = handleVDError;
1656
vdInterfaceErrorCallbacks.pfnMessage = NULL;
1584
1658
vrc = VDInterfaceAdd(&vdInterfaceError, "VBoxManage_IError", VDINTERFACETYPE_ERROR,
1585
1659
&vdInterfaceErrorCallbacks, NULL, &pVDIfs);
1591
1665
if (srcformat.isEmpty())
1593
1667
char *pszFormat = NULL;
1594
vrc = VDGetFormat(Utf8Str(src).raw(), &pszFormat);
1668
vrc = VDGetFormat(NULL, Utf8Str(src).raw(), &pszFormat);
1595
1669
if (RT_FAILURE(vrc))
1597
1671
RTPrintf("No file format specified and autodetect failed - please specify format: %Rrc\n", vrc);
1702
1776
//if (!strcmp(pszCmd, "unloadsyms"))
1703
1777
// return CmdUnloadSyms(argc - 1 , &a->argv[1]);
1704
1778
if (!strcmp(pszCmd, "sethduuid") || !strcmp(pszCmd, "setvdiuuid"))
1705
return handleSetHDUUID(a->argc - 1, &a->argv[1], a->virtualBox, a->session);
1779
return CmdSetHDUUID(a->argc - 1, &a->argv[1], a->virtualBox, a->session);
1780
if (!strcmp(pszCmd, "dumphdinfo"))
1781
return CmdDumpHDInfo(a->argc - 1, &a->argv[1], a->virtualBox, a->session);
1706
1782
if (!strcmp(pszCmd, "listpartitions"))
1707
1783
return CmdListPartitions(a->argc - 1, &a->argv[1], a->virtualBox, a->session);
1708
1784
if (!strcmp(pszCmd, "createrawvmdk"))