Ejemplo n.º 1
0
static BOOL CALLBACK EnumSymbols(PSYMBOL_INFO SymInfo, ULONG SymbolSize, PVOID UserContext)
{
    SYMBOLINFO curSymbol;
    memset(&curSymbol, 0, sizeof(SYMBOLINFO));

    curSymbol.addr = (duint)SymInfo->Address;
    curSymbol.decoratedSymbol = (char*)BridgeAlloc(strlen(SymInfo->Name) + 1);
    curSymbol.undecoratedSymbol = (char*)BridgeAlloc(MAX_SYM_NAME);
    strcpy_s(curSymbol.decoratedSymbol, strlen(SymInfo->Name) + 1, SymInfo->Name);

    // Skip bad ordinals
    if(strstr(SymInfo->Name, "Ordinal"))
    {
        // Does the symbol point to the module base?
        if(SymInfo->Address == SymInfo->ModBase)
            return TRUE;
    }

    // Convert a mangled/decorated C++ name to a readable format
    if(!SafeUnDecorateSymbolName(SymInfo->Name, curSymbol.undecoratedSymbol, MAX_SYM_NAME, UNDNAME_COMPLETE))
    {
        BridgeFree(curSymbol.undecoratedSymbol);
        curSymbol.undecoratedSymbol = nullptr;
    }
    else if(!strcmp(curSymbol.decoratedSymbol, curSymbol.undecoratedSymbol))
    {
        BridgeFree(curSymbol.undecoratedSymbol);
        curSymbol.undecoratedSymbol = nullptr;
    }

    SYMBOLCBDATA* cbData = (SYMBOLCBDATA*)UserContext;
    cbData->cbSymbolEnum(&curSymbol, cbData->user);
    return TRUE;
}
Ejemplo n.º 2
0
void MakeSigDialogInit(HWND hwndDlg)
{
	//
	// Get the debugger window's selection
	//
	SELECTIONDATA selection;

	if (!GuiSelectionGet(GUI_DISASSEMBLY, &selection))
		return;

	//
	// Generate the signature
	//
	SIG_DESCRIPTOR *desc = GenerateSigFromCode(selection.start, selection.end);

	if (!desc)
		return;

	//
	// SIG_DESCRIPTOR -> String
	//
	char *data = nullptr;
	char *mask = nullptr;

	switch (Settings::LastType)
	{
	case SIG_CODE:	DescriptorToCode(desc, &data, &mask);	break;
	case SIG_IDA:	DescriptorToIDA(desc, &data);			break;
	case SIG_PEID:	DescriptorToPEiD(desc, &data);			break;
	case SIG_CRC:	DescriptorToCRC(desc, &data, &mask);	break;
	}

	BridgeFree(desc);

	//
	// Set the edit box text and clean up
	//
	if (data)
	{
		SetWindowText(GetDlgItem(hwndDlg, IDC_SIGMAKE_EDIT1), data);
		BridgeFree(data);
	}

	if (mask)
	{
		SetWindowText(GetDlgItem(hwndDlg, IDC_SIGMAKE_EDIT2), mask);
		BridgeFree(mask);
	}
}
Ejemplo n.º 3
0
void CallStackView::updateCallStack()
{
    DBGCALLSTACK callstack;
    memset(&callstack, 0, sizeof(DBGCALLSTACK));
    if(!DbgFunctions()->GetCallStack)
        return;
    DbgFunctions()->GetCallStack(&callstack);
    setRowCount(callstack.total);
    for(int i = 0; i < callstack.total; i++)
    {
        QString addrText = ToPtrString(callstack.entries[i].addr);
        setCellContent(i, 0, addrText);
        addrText = ToPtrString(callstack.entries[i].to);
        setCellContent(i, 1, addrText);
        if(callstack.entries[i].from)
        {
            addrText = ToPtrString(callstack.entries[i].from);
            setCellContent(i, 2, addrText);
        }
        setCellContent(i, 3, callstack.entries[i].comment);
    }
    if(callstack.total)
        BridgeFree(callstack.entries);
    reloadData();
}
Ejemplo n.º 4
0
void XrefBrowseDialog::setup(duint address, QString command)
{
    if(mXrefInfo.refcount)
    {
        BridgeFree(mXrefInfo.references);
        mXrefInfo.refcount = 0;
    }
    mCommand = command;
    mAddress = address;
    mPrevSelectionSize = 0;
    ui->listWidget->clear();
    if(DbgXrefGet(address, &mXrefInfo))
    {
        char disasm[GUI_MAX_DISASSEMBLY_SIZE] = "";
        setWindowTitle(QString(tr("xrefs at %1")).arg(ToHexString(address)));
        for(duint i = 0; i < mXrefInfo.refcount; i++)
        {
            if(GuiGetDisassembly(mXrefInfo.references[i].addr, disasm))
                ui->listWidget->addItem(disasm);
            else
                ui->listWidget->addItem("???");
        }
        ui->listWidget->setCurrentRow(0);
    }
    ui->listWidget->setFocus();
}
Ejemplo n.º 5
0
AnalysisPass::AnalysisPass(uint VirtualStart, uint VirtualEnd, BBlockArray & MainBlocks) : m_MainBlocks(MainBlocks)
{
    assert(VirtualEnd > VirtualStart);

    // Internal class data
    m_VirtualStart = VirtualStart;
    m_VirtualEnd = VirtualEnd;
    m_InternalMaxThreads = 0;

    // Read remote instruction data to local memory
    m_DataSize = VirtualEnd - VirtualStart;
    m_Data = (unsigned char*)emalloc(m_DataSize, "AnalysisPass:m_Data");

    if(!MemRead(VirtualStart, m_Data, m_DataSize))
    {
        BridgeFree(m_Data);
        assert(false);
    }
}
Ejemplo n.º 6
0
BRIDGE_IMPEXP bool BridgeSettingRead(int* errorLine)
{
    if(errorLine)
        *errorLine = 0;
    bool success = false;
    std::string iniData;
    HANDLE hFile = CreateFileW(szIniFile, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr);
    if(hFile != INVALID_HANDLE_VALUE)
    {
        DWORD fileSize = GetFileSize(hFile, nullptr);
        if(fileSize)
        {
            unsigned char utf8bom[] = { 0xEF, 0xBB, 0xBF };
            char* fileData = (char*)BridgeAlloc(sizeof(utf8bom) + fileSize + 1);
            DWORD read = 0;
            if(ReadFile(hFile, fileData, fileSize, &read, nullptr))
            {
                success = true;
                if(!memcmp(fileData, utf8bom, sizeof(utf8bom)))
                    iniData.assign(fileData + sizeof(utf8bom));
                else
                    iniData.assign(fileData);
            }
            BridgeFree(fileData);
        }
        CloseHandle(hFile);
    }
    if(success)  //if we failed to read the file, the current settings are better than none at all
    {
        EnterCriticalSection(&csIni);
        int errline = 0;
        success = settings.Deserialize(iniData, errline);
        if(errorLine)
            *errorLine = errline;
        LeaveCriticalSection(&csIni);
    }
    return success;
}
Ejemplo n.º 7
0
XrefBrowseDialog::~XrefBrowseDialog()
{
    delete ui;
    if(mXrefInfo.refcount)
        BridgeFree(mXrefInfo.references);
}
Ejemplo n.º 8
0
FunctionPass::~FunctionPass()
{
    if(m_FunctionInfo)
        BridgeFree(m_FunctionInfo);
}
Ejemplo n.º 9
0
void MakeSigDialogConvert(HWND hwndDlg, SIGNATURE_TYPE To, SIGNATURE_TYPE From)
{
	//
	// Don't convert if destination and source types are the same
	//
	if (To == From)
		return;

	int dataLen = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_SIGMAKE_EDIT1)) + 1;
	int maskLen = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_SIGMAKE_EDIT2)) + 1;

	char *data = (char *)BridgeAlloc(dataLen);
	char *mask = (char *)BridgeAlloc(maskLen);

	GetWindowText(GetDlgItem(hwndDlg, IDC_SIGMAKE_EDIT1), data, dataLen);
	GetWindowText(GetDlgItem(hwndDlg, IDC_SIGMAKE_EDIT2), mask, maskLen);

	//
	// Convert string(s) to the incoming raw code descriptor
	//
	SIG_DESCRIPTOR *inDesc = nullptr;

	switch (From)
	{
	case SIG_CODE:	inDesc = DescriptorFromCode(data, mask);	break;
	case SIG_IDA:	inDesc = DescriptorFromIDA(data);			break;
	case SIG_PEID:	inDesc = DescriptorFromPEiD(data);			break;
	case SIG_CRC:	inDesc = DescriptorFromCRC(data);			break;
	}

	//
	// Free temporary allocations
	//
	BridgeFree(data);
	BridgeFree(mask);

	data = nullptr;
	mask = nullptr;

	//
	// Convert raw code to destination strings
	//
	switch (To)
	{
	case SIG_CODE:	DescriptorToCode(inDesc, &data, &mask);	break;
	case SIG_IDA:	DescriptorToIDA(inDesc, &data);			break;
	case SIG_PEID:	DescriptorToPEiD(inDesc, &data);		break;
	case SIG_CRC:	DescriptorToCRC(inDesc, &data, &mask);	break;
	}

	//
	// Update dialog
	//
	SetWindowText(GetDlgItem(hwndDlg, IDC_SIGMAKE_EDIT1), data ? data : "");
	SetWindowText(GetDlgItem(hwndDlg, IDC_SIGMAKE_EDIT2), mask ? mask : "");

	if (data)
		BridgeFree(data);

	if (mask)
		BridgeFree(mask);

	BridgeFree(inDesc);
}
Ejemplo n.º 10
0
void MakeSigDialogExecute(HWND hwndDlg)
{
	int dataLen = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_SIGMAKE_EDIT1)) + 1;
	int maskLen = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_SIGMAKE_EDIT2)) + 1;

	char *data = (char *)BridgeAlloc(dataLen);
	char *mask = (char *)BridgeAlloc(maskLen);

	GetWindowText(GetDlgItem(hwndDlg, IDC_SIGMAKE_EDIT1), data, dataLen);
	GetWindowText(GetDlgItem(hwndDlg, IDC_SIGMAKE_EDIT2), mask, maskLen);

	//
	// Convert the string to a code descriptor
	//
	SIG_DESCRIPTOR *desc = nullptr;

	switch (Settings::LastType)
	{
	case SIG_CODE:	desc = DescriptorFromCode(data, mask);	break;
	case SIG_IDA:	desc = DescriptorFromIDA(data);			break;
	case SIG_PEID:	desc = DescriptorFromPEiD(data);		break;
	case SIG_CRC:	desc = DescriptorFromCRC(data);			break;
	}

	//
	// Scan
	//
	std::vector<duint> results;
	PatternScan(desc, results);

	//
	// Log it in the GUI
	//
	GuiReferenceDeleteAllColumns();
	GuiReferenceAddColumn(20, "Address");
	GuiReferenceAddColumn(100, "Disassembly");
	GuiReferenceSetRowCount((int)results.size());
	GuiReferenceSetProgress(0);

	int i = 0;
	for (auto& match : results)
	{
		DISASM_INSTR inst;
		DbgDisasmAt(match, &inst);

		char temp[32];
		sprintf_s(temp, "%p", (PVOID)match);

		GuiReferenceSetCellContent(i, 0, temp);
		GuiReferenceSetCellContent(i++, 1, inst.instruction);
	}

	_plugin_logprintf("Found %d references(s)\n", results.size());
	GuiReferenceSetProgress(100);
	GuiUpdateAllViews();

	//
	// Cleanup
	//
	BridgeFree(data);
	BridgeFree(mask);
	BridgeFree(desc);
}