Exemplo n.º 1
0
static void ExtractFileFromResource(HMODULE hImage, DWORD resId, LPCTSTR path)
{
    g_Log.Debug(_T("Extracting resource %d to \"%s\"..."), resId, path);
    HRSRC hDbghelpRes = FindResource(hImage, MAKEINTRESOURCE(resId), RT_RCDATA);
    if (!hDbghelpRes)
        throw runtime_error("failed to find file in resources");

    HGLOBAL hDbghelpGlobal = LoadResource(hImage, hDbghelpRes);
    if (!hDbghelpGlobal)
        throw runtime_error("failed to load file from resources");

    CAtlFile hFile(CreateFile(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL));
    if (hFile == INVALID_HANDLE_VALUE)
        throw runtime_error("failed to create file");

    if (FAILED(hFile.Write(LockResource(hDbghelpGlobal), SizeofResource(hImage, hDbghelpRes))))
        throw runtime_error("failed to write file");
}
Exemplo n.º 2
0
std::unique_ptr<Response> Response::CreateResponse(const ns1__Response& response, Log& log)
{
    std::unique_ptr<Response> result;
    if (SOAP_TYPE_ns1__HaveSolutionResponse == response.soap_type())
    {
        log.Debug(_T("\thas solution"));
        const ns1__HaveSolutionResponse& resp = static_cast<const ns1__HaveSolutionResponse&>(response);
        std::unique_ptr<HaveSolutionResponse> res(new HaveSolutionResponse);
        res->askConfirmation = resp.askConfirmation;
        res->type = resp.type;
        log.Debug(_T("\t\ttype\t%d"), res->type);
        if (resp.url)
        {
            res->url = resp.url->c_str();
            log.Debug(_T("\t\tURL\t%ls"), res->url.c_str());
        }
        if (resp.exe)
        {
            res->exe.assign(resp.exe->__ptr, resp.exe->__ptr + resp.exe->__size);
            log.Debug(_T("\t\thas EXE, size\t%d"), res->exe.size());
        }
        result = std::move(res);
    }
    else if (SOAP_TYPE_ns1__NeedSymbolsThenMiniDumpResponse == response.soap_type() || SOAP_TYPE_ns1__NeedMiniDumpResponse == response.soap_type())
    {
        result.reset(new NeedMiniDumpResponse);
    }
    else if (SOAP_TYPE_ns1__NeedFullDumpResponse == response.soap_type())
    {
        const ns1__NeedFullDumpResponse& resp = static_cast<const ns1__NeedFullDumpResponse&>(response);
        std::unique_ptr<NeedFullDumpResponse> res(new NeedFullDumpResponse);

        res->restrictedDumpType = resp.restrictedDumpType;
        res->attachUserInfo = resp.attachUserInfo;

        result = std::move(res);
    }
    else if (SOAP_TYPE_ns1__NeedMoreInfoResponse == response.soap_type())
    {
        const ns1__NeedMoreInfoResponse& resp = static_cast<const ns1__NeedMoreInfoResponse&>(response);
        std::unique_ptr<NeedMoreInfoResponse> res(new NeedMoreInfoResponse);
        if (resp.infoModule && resp.infoModule->__size > 0)
            res->infoModule.assign(resp.infoModule->__ptr, resp.infoModule->__ptr + resp.infoModule->__size);
        else
            res->infoModule.clear();
        if (resp.infoModuleCfg)
            res->infoModuleCfg = resp.infoModuleCfg->c_str();
        else
            res->infoModuleCfg = L"";
        result = std::move(res);
    }
    else if (SOAP_TYPE_ns1__StopResponse == response.soap_type())
    {
        result.reset(new StopResponse);
    }
    else if (SOAP_TYPE_ns1__ErrorResponse == response.soap_type())
    {
        const ns1__ErrorResponse& resp = static_cast<const ns1__ErrorResponse&>(response);
        std::unique_ptr<ErrorResponse> res(new ErrorResponse);
        res->error = *resp.error;
        log.Debug(_T("\terror\t\"%ls\""), res->error.c_str());
        result = std::move(res);
    }
    else
    {
        throw std::runtime_error("unknown response type");
    }

    if (response.clientID)
    {
        result->clientID = *response.clientID;
        log.Debug(_T("\tCliendID = \"%ls\""), result->clientID.c_str());
    }
    result->problemID = response.problemID ? *response.problemID : 0;
    result->dumpGroupID = response.dumpGroupID ? *response.dumpGroupID : 0;
    result->dumpID = response.dumpID ? *response.dumpID : 0;
    log.Debug(_T("\tproblemID = %d, dumpGroupID = %d, dumpID = %d"), result->problemID, result->dumpGroupID, result->dumpID);
    if (response.urlToProblem)
    {
        result->urlToProblem = *response.urlToProblem;
        log.Debug(_T("\tURL to problem = \"%ls\""), result->urlToProblem.c_str());
    }
    else
    {
        result->urlToProblem = L"";
    }
    if (response.context && response.context->__size > 0)
        result->context.assign(response.context->__ptr, response.context->__ptr + response.context->__size);
    else
        result->context.clear();

    return result;
}