Example #1
0
static PyObject *
dbgbp_GetCommand(PyDebugBreakpointObject *self)
{
    HRESULT hr;
    PSTR Buffer = NULL;
    ULONG CommandSize;
    PyObject *ret = NULL;

    if (self->bp == NULL)
        return err_nobp();
    hr = self->bp->GetCommand(NULL, 0, &CommandSize);
    if (hr != S_OK && hr != S_FALSE)
        return err_dbgeng(hr);
    Buffer = (PSTR)PyMem_Malloc(CommandSize * sizeof(*Buffer));
    if (Buffer == NULL) {
        PyErr_NoMemory();
        return NULL;
    }
    if ((hr = self->bp->GetCommand(Buffer, CommandSize, NULL)) != S_OK) {
        err_dbgeng(hr);
    }
    else {
        ret = Py_BuildValue("s", Buffer);
    }

    if (Buffer) PyMem_Free(Buffer);
    return ret;
}
Example #2
0
static PyObject *
dbgbp_GetOffsetExpression(PyDebugBreakpointObject *self)
{
    HRESULT hr;
    PSTR Buffer = NULL;
    ULONG ExpressionSize;
    PyObject *ret = NULL;

    if (self->bp == NULL)
        return err_nobp();

    hr = self->bp->GetOffsetExpression(NULL, 0, &ExpressionSize);
    if (hr != S_OK && hr != S_FALSE)
            return err_dbgeng(hr);

    Buffer = (PSTR)PyMem_Malloc(ExpressionSize + 2);
    if (Buffer == NULL) {
        PyErr_NoMemory();
        return NULL;
    }
    if ((hr = self->bp->GetOffsetExpression(Buffer, 
                    ExpressionSize, NULL)) != S_OK)
    {
        PyMem_Free(Buffer);
        return err_dbgeng(hr);
    }

    ret = Py_BuildValue("s", Buffer);
    PyMem_Free(Buffer);
    return ret;
}
Example #3
0
static int 
dbgadv_init(PyObject *oself, PyObject *args, PyObject *kwds)
{
    HRESULT hr;
    PyDebugAdvancedObject *self = (PyDebugAdvancedObject *)oself;
    PyDebugClientObject *client = NULL;
    IDebugAdvanced2 *debugAdvanced = NULL;
    static char *kwlist[] = {"client", NULL};

    if (self->adv) {
        self->adv->Release();
        self->adv = NULL;
    }

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!:DebugAdvanced",
                kwlist, &PyDebugClientType, &client))
        return -1;
    if (client->client == NULL) {
        err_noclient();
        return -1;
    }
    if ((hr = client->client->QueryInterface(__uuidof(IDebugAdvanced2),
                    (void **)&debugAdvanced)) != S_OK)
    {
        err_dbgeng(hr);
        return -1;
    }

    self->adv = debugAdvanced;
    return 0;
}
Example #4
0
static PyObject *
dbgadv_SetThreadContext(PyDebugAdvancedObject *self, PyObject *args)
{
    HRESULT hr;
    ULONG Type;
    PVOID Context;
    ULONG ContextSize;
    PyObject *ctx;

    if (self->adv == NULL)
        return err_noadv();
    if (!PyArg_ParseTuple(args, "IO:SetThreadContext", &Type, &ctx))
        return NULL;
    if (Type == IMAGE_FILE_MACHINE_I386) {
        if (!PyObject_TypeCheck(ctx, &PyContext32Type))
            return PyErr_Format(PyExc_TypeError, "context must be Context32");
        ContextSize = sizeof(CONTEXT32);
        Context = &(((PyContext32Object *)ctx)->ctx);
    }
    else if (Type == IMAGE_FILE_MACHINE_AMD64) {
        if (!PyObject_TypeCheck(ctx, &PyContext64Type))
            return PyErr_Format(PyExc_TypeError, "context must be Context64");
        ContextSize = sizeof(CONTEXT64);
        Context = &(((PyContext64Object *)ctx)->ctx);
    }
    else {
        return PyErr_Format(PyExc_TypeError, "Invalid processor type");
    }
    if ((hr = self->adv->SetThreadContext(Context, ContextSize)) != S_OK)
        return err_dbgeng(hr);
    Py_RETURN_NONE;
}
Example #5
0
static PyObject *
dbgbp_GetFlags(PyDebugBreakpointObject *self)
{
    ULONG Flags;
    HRESULT hr;

    if (self->bp == NULL)
        return err_nobp();
    if ((hr = self->bp->GetFlags(&Flags)) != S_OK)
        return err_dbgeng(hr);
    return Py_BuildValue("I", Flags);
}
Example #6
0
static PyObject *
dbgbp_GetCurrentPassCount(PyDebugBreakpointObject *self)
{
    HRESULT hr;
    ULONG Count;

    if (self->bp == NULL)
        return err_nobp();
    if ((hr = self->bp->GetCurrentPassCount(&Count)) != S_OK)
        return err_dbgeng(hr);
    return Py_BuildValue("I", Count);
}
Example #7
0
static PyObject *
dbgbp_GetType(PyDebugBreakpointObject *self)
{
    ULONG BreakType;
    ULONG ProcType;
    HRESULT hr;

    if (self->bp == NULL)
        return err_nobp();
    if ((hr = self->bp->GetType(&BreakType, &ProcType)) != S_OK)
        return err_dbgeng(hr);
    return Py_BuildValue("II", BreakType, ProcType);
}
Example #8
0
static PyObject *
dbgbp_SetCommand(PyDebugBreakpointObject *self, PyObject *args)
{
    HRESULT hr;
    PCSTR Command;

    if (self->bp == NULL)
        return err_nobp();
    if (!PyArg_ParseTuple(args, "s:SetCommand", &Command))
        return NULL;
    if ((hr = self->bp->SetCommand(Command)) != S_OK)
        return err_dbgeng(hr);
    Py_RETURN_NONE;
}
Example #9
0
static PyObject *
dbgbp_RemoveFlags(PyDebugBreakpointObject *self, PyObject *args)
{
    ULONG Flags;
    HRESULT hr;

    if (self->bp == NULL)
        return err_nobp();
    if (!PyArg_ParseTuple(args, "I:RemoveFlags", &Flags))
        return NULL;
    if ((hr = self->bp->RemoveFlags(Flags)) != S_OK)
        return err_dbgeng(hr);
    Py_RETURN_NONE;
}
Example #10
0
static PyObject *
dbgbp_SetPassCount(PyDebugBreakpointObject *self, PyObject *args)
{
    HRESULT hr;
    ULONG Count;

    if (self->bp == NULL)
        return err_nobp();
    if (!PyArg_ParseTuple(args, "I:SetPassCount", &Count))
        return NULL;
    if ((hr = self->bp->SetPassCount(Count)) != S_OK)
        return err_dbgeng(hr);
    Py_RETURN_NONE;
}
Example #11
0
static PyObject *
dbgbp_SetOffsetExpression(PyDebugBreakpointObject *self, PyObject *args)
{
    HRESULT hr;
    PSTR Expression;

    if (self->bp == NULL)
        return err_nobp();
    if (!PyArg_ParseTuple(args, "s:SetOffsetExpression", &Expression))
        return NULL;
    if ((hr = self->bp->SetOffsetExpression(Expression)) != S_OK)
        return err_dbgeng(hr);
    Py_RETURN_NONE;
}
Example #12
0
static PyObject *
dbgbp_GetMatchThreadId(PyDebugBreakpointObject *self)
{
    HRESULT hr;
    ULONG Id;

    if (self->bp == NULL)
        return err_nobp();
    if ((hr = self->bp->GetMatchThreadId(&Id)) != S_OK) {
        if (hr == E_NOINTERFACE)
            return err_nointerface("No specific thread has been set for this "
                "breakpoint. Any thread can trigger the breakpoint.");
        else
            return err_dbgeng(hr);
    }
    return Py_BuildValue("I", Id);
}
Example #13
0
static PyObject *
dbgbp_GetDataParameters(PyDebugBreakpointObject *self)
{
    HRESULT hr;
    ULONG Size;
    ULONG AccessType;

    if (self->bp == NULL)
        return err_nobp();
    if ((hr = self->bp->GetDataParameters(&Size, &AccessType)) != S_OK) {
        if (hr == E_NOINTERFACE)
            return err_nointerface("The breakpoint is not a processor breakpoint");
        else
            return err_dbgeng(hr);
    }
    return Py_BuildValue("II", Size, AccessType);
}
Example #14
0
static PyObject *
dbgbp_GetParameters(PyDebugBreakpointObject *self)
{
    HRESULT hr;
    DEBUG_BREAKPOINT_PARAMETERS bbp;
    PyDebugBreakPointParametersObject *obj;

    if (self->bp == NULL)
        return err_nobp();
    if ((hr = self->bp->GetParameters(&bbp)) != S_OK)
        return err_dbgeng(hr);

    obj = (PyDebugBreakPointParametersObject *)PyObject_CallObject(
            (PyObject *)&PyDebugBreakPointParametersType, NULL);
    obj->bpp = bbp;
    return Py_BuildValue("N", obj);
}
Example #15
0
static PyObject *
dbgbp_SetDataParameters(PyDebugBreakpointObject *self, PyObject *args)
{
    HRESULT hr;
    ULONG Size;
    ULONG AccessType;
    if (self->bp == NULL)
        return err_nobp();
    if (!PyArg_ParseTuple(args, "II:SetDataParameters", &Size, &AccessType))
        return NULL;
    if ((hr = self->bp->SetDataParameters(Size, AccessType)) != S_OK) {
        if (hr == E_NOINTERFACE)
            return err_nointerface("The breakpoint is not a processor breakpoint");
        else
            return err_dbgeng(hr);
    }
    Py_RETURN_NONE;
}
Example #16
0
static PyObject *
dbgbp_GetOffset(PyDebugBreakpointObject *self)
{
    ULONG64 Offset;
    HRESULT hr;

    if (self->bp == NULL)
        return err_nobp();
    if ((hr = self->bp->GetOffset(&Offset)) != S_OK) {
        if (hr == E_NOINTERFACE)
            return err_nointerface("The breakpoint is deferred and does "
                "not currently specify a location in the target's memory "
                "address space.");
        else
            return err_dbgeng(hr);
    }
    return Py_BuildValue("K", Offset);
}
Example #17
0
static PyObject *
dbgadv_GetThreadContext(PyDebugAdvancedObject *self, PyObject *args)
{
    HRESULT hr;
    PyObject *ret = NULL;
    ULONG Type;
    ULONG ContextSize;
    PVOID Context;
    CONTEXT32 ctx32;
    CONTEXT64 ctx64;

    if (self->adv == NULL)
        return err_noadv();
    if (!PyArg_ParseTuple(args, "I:GetThreadContext", &Type))
        return NULL;
    if (Type == IMAGE_FILE_MACHINE_I386) {
        ContextSize = sizeof(CONTEXT32);
        Context = (PVOID)&ctx32;
    }
    else if (Type == IMAGE_FILE_MACHINE_AMD64) {
        ContextSize = sizeof(CONTEXT64);
        Context = (PVOID)&ctx64;
    }
    else {
        return PyErr_Format(PyExc_TypeError, "Invalid processor type");
    }

    if ((hr = self->adv->GetThreadContext(Context, ContextSize)) != S_OK)
        return err_dbgeng(hr);

    if (Type == IMAGE_FILE_MACHINE_I386) {
        ret = PyObject_CallObject((PyObject *)&PyContext32Type, NULL);
        if (ret == NULL)
            Py_RETURN_NONE;
        ((PyContext32Object *)ret)->ctx = ctx32;
    }
    else {
        ret = PyObject_CallObject((PyObject *)&PyContext64Type, NULL);
        if (ret == NULL)
            Py_RETURN_NONE;
        ((PyContext64Object *)ret)->ctx = ctx64;
    }
    return Py_BuildValue("N", ret);
}
Example #18
0
static PyObject *
dbgbp_SetOffset(PyDebugBreakpointObject *self, PyObject *args)
{
    ULONG64 Offset;
    HRESULT hr;
    PyObject *retval;

    if (self->bp == NULL)
        return err_nobp();
    if (!PyArg_ParseTuple(args, "K:SetOffset", &Offset))
        return NULL;
    hr = self->bp->SetOffset(Offset);
    if (hr == S_OK)
        retval = Py_True;
    else if (hr == E_UNEXPECTED)
        retval = Py_False;
    else
        return err_dbgeng(hr);

    return Py_BuildValue("O", retval);
}
Example #19
0
static PyObject *
dbgbp_SetMatchThreadId(PyDebugBreakpointObject *self, PyObject *args)
{
    HRESULT hr;
    ULONG Id;

    if (self->bp == NULL)
        return err_nobp();
    if (!PyArg_ParseTuple(args, "I:SetMatchThreadId", &Id))
        return NULL;
    if ((hr = self->bp->SetPassCount(Id)) != S_OK) {
        if (hr == E_NOINTERFACE)
            return err_nointerface("The thread that Thread specifies could "
                "not be found.");
        else if (hr == E_INVALIDARG)
            return err_invalidarg("The target is in a kernel and the "
                "breakpoint is a processor breakpoint. Processor breakpoints "
                "cannot be limited to threads in kernel mode.");
        else
            return err_dbgeng(hr);
    }
    Py_RETURN_NONE;
}