/** * Yasm style. * * @param pState The disassembler state. */ static void MyDisasYasmFormatter(PMYDISSTATE pState) { char szTmp[256]; #if 0 /* a very quick hack. */ strcpy(szTmp, RTStrStripL(strchr(pState->szLine, ':') + 1)); char *psz = strrchr(szTmp, '['); *psz = '\0'; RTStrStripR(szTmp); psz = strstr(szTmp, " ptr "); if (psz) memset(psz, ' ', 5); char *pszEnd = strchr(szTmp, '\0'); while (pszEnd - &szTmp[0] < 71) *pszEnd++ = ' '; *pszEnd = '\0'; #else size_t cch = DISFormatYasmEx(&pState->Dis, szTmp, sizeof(szTmp), DIS_FMT_FLAGS_STRICT | DIS_FMT_FLAGS_ADDR_RIGHT | DIS_FMT_FLAGS_ADDR_COMMENT | DIS_FMT_FLAGS_BYTES_RIGHT | DIS_FMT_FLAGS_BYTES_COMMENT | DIS_FMT_FLAGS_BYTES_SPACED, NULL, NULL); Assert(cch < sizeof(szTmp)); while (cch < 71) szTmp[cch++] = ' '; szTmp[cch] = '\0'; #endif RTPrintf(" %s ; %s", szTmp, pState->szLine); }
/** * Disassembles one instruction; only fully disassembly an instruction if it matches the filter criteria * * @returns VBox error code * @param uInstrAddr Pointer to the structure to disassemble. * @param enmCpuMode The CPU mode. * @param pfnCallback The byte fetcher callback. * @param uFilter Instruction filter. * @param pDis Where to return the disassembled instruction info. * @param pcbInstr Where to store the size of the instruction. NULL is * allowed. * @param pszOutput Storage for disassembled instruction. * @param cbOutput Size of the output buffer. * * @todo Define output callback. */ DISDECL(int) DISInstrToStrEx(RTUINTPTR uInstrAddr, DISCPUMODE enmCpuMode, PFNDISREADBYTES pfnReadBytes, void *pvUser, uint32_t uFilter, PDISSTATE pDis, uint32_t *pcbInstr, char *pszOutput, size_t cbOutput) { /* Don't filter if formatting is desired. */ if (uFilter != DISOPTYPE_ALL && pszOutput && cbOutput) uFilter = DISOPTYPE_ALL; int rc = DISInstrEx(uInstrAddr, enmCpuMode, uFilter, pfnReadBytes, pvUser, pDis, pcbInstr); if (RT_SUCCESS(rc) && pszOutput && cbOutput) { size_t cch = DISFormatYasmEx(pDis, pszOutput, cbOutput, DIS_FMT_FLAGS_BYTES_LEFT | DIS_FMT_FLAGS_BYTES_BRACKETS | DIS_FMT_FLAGS_BYTES_SPACED | DIS_FMT_FLAGS_RELATIVE_BRANCH | DIS_FMT_FLAGS_ADDR_LEFT, NULL /*pfnGetSymbol*/, NULL /*pvUser*/); if (cch + 2 <= cbOutput) { pszOutput[cch++] = '\n'; pszOutput[cch] = '\0'; } } return rc; }