此断点当前不会被命中:Dll调试

时间:2017-08-21 12:08:37

标签: c++ debugging dll c-strings

我有一个用/ mt编译的dll。 dll导出一个函数'main',我从cmd调用rundll32。此函数将从我包含的标题中调用另一个函数,该标题应该包含存储在Environment下的注册表中的一些设置。想象一下我在做什么,这里有一些代码:

DLL:主

#include "..\Header.h"

extern "C" void APIEXP WINAPI main(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow){
    char *parentPath = nullptr;
    size_t sz;
    DWORD buffSize;
    block;  //this is a messagebox
    buffSize = sizeof(client.pc_name);

    if (!GetComputerNameA(client.pc_name, &buffSize)) strcpy(client.pc_name, "");
    if (!GetUserNameA(client.user_name, &buffSize)) strcpy(client.user_name, "");
    client.os_time = time(0);
    client.version = Version;
    client.os_version = Exe_version;
    TextSetting("pc_description", client.pc_description);
    TextSetting("custom_name", client.custom_name);
}

标题

LPSTR TextSetting(LPSTR setting,LPSTR buff) {
    //Returns all data in buff
    DWORD type, sz;
    msg("dll: ","function called");

    if (RegGetValueA(HKEY_CURRENT_USER,"Environment", setting, RRF_RT_REG_SZ | RRF_RT_REG_MULTI_SZ, &type, (LPBYTE)buff, &sz) != ERROR_SUCCESS) {
        buff[0] = 0;
        msg("sdsv: ", "err");
        return buff;
    }

    return buff;
}
LPSTR con(LPSTR dest, LPSTR a, LPSTR b, LPSTR c) {
    //c is optional and default: ""
    strcpy(dest, a);
    strcat(dest, b);
    strcat(dest, c);

    return dest;
}
VOID msg(LPSTR app,LPSTR a) {
    char temp_buffer[2048];
    con(temp_buffer , app,a, "\n");
    OutputDebugStringA(temp_buffer);
}

上面显示的代码非常有效:这里的兴趣点是主要的TextSetting。它按原样检索数据。但是当我从TextSetting中删除msg("dll: ","function called");时,它只是给出一个错误(返回代码不是ERROR_SUCCESS)。此外,我甚至无法调试该函数。当我将调试器附加到rundll32进程时,我在TextSettings中的if语句上设置的断点给出了标题中提到的警告。

这是有效的: enter image description here

这很奇怪: enter image description here

我发现了一些额外的事情: 它可以工作,如果我调用msg或con函数(看起来像con中使用的str *函数使代码工作)。更进一步:如果我只在if语句之前使用strcpy和strcat,我也会工作。我不知道问题是什么(可能是一些缓冲区溢出奇迹般地修复了if语句中使用的代码?)

1 个答案:

答案 0 :(得分:4)

RegGetValue API函数期望最后一个参数是缓冲区的大小。 你在那里传递一个未初始化的变量。 这可能是它在发布/调试之间有不同行为的原因。 RegGetValue