1
0
Fork 0

Merge branch 'development' into patch000000a7

This commit is contained in:
torusrxxx 2020-10-20 15:44:07 +08:00
commit aeee6b4277
No known key found for this signature in database
GPG Key ID: A795C73A0F1CFADD
12 changed files with 98 additions and 12 deletions

View File

@ -17,6 +17,8 @@
0x40010008 DBG_CONTROL_BREAK
0x40010009 DBG_COMMAND_EXCEPTION
0x4001000A DBG_PRINTEXCEPTION_WIDE_C
0x40080201 EXCEPTION_RO_ORIGINATEERROR
0x40080202 EXCEPTION_RO_TRANSFORMERROR
0x406D1388 MS_VC_EXCEPTION
0x80000001 EXCEPTION_GUARD_PAGE
0x80000002 EXCEPTION_DATATYPE_MISALIGNMENT

View File

@ -520,4 +520,17 @@ bool cbInstrDbdecompress(int argc, char* argv[])
}
dprintf_untranslated("Decompressed '%s'\n", argv[1]);
return true;
}
}
bool cbInstrDebugFlags(int argc, char* argv[])
{
if(argc < 2)
{
dprintf_untranslated("Usage: DebugFlags 0xFFFFFFFF\n");
return false;
}
auto debugFlags = DbgValFromString(argv[1]);
dbgsetdebugflags(debugFlags);
dprintf_untranslated("DebugFlags = 0x%08X\n", debugFlags);
return true;
}

View File

@ -14,4 +14,5 @@ bool cbInstrBriefcheck(int argc, char* argv[]);
bool cbInstrFocusinfo(int argc, char* argv[]);
bool cbInstrFlushlog(int argc, char* argv[]);
bool cbInstrAnimateWait(int argc, char* argv[]);
bool cbInstrDbdecompress(int argc, char* argv[]);
bool cbInstrDbdecompress(int argc, char* argv[]);
bool cbInstrDebugFlags(int argc, char* argv[]);

View File

@ -95,6 +95,7 @@ HANDLE mProcHandle;
HANDLE mForegroundHandle;
duint mRtrPreviousCSP = 0;
HANDLE hDebugLoopThread = nullptr;
DWORD dwDebugFlags = 0;
static duint dbgcleartracestate()
{
@ -402,6 +403,11 @@ bool dbgdeletedllbreakpoint(const char* mod, DWORD type)
return true;
}
void dbgsetdebugflags(DWORD flags)
{
dwDebugFlags = flags;
}
bool dbghandledllbreakpoint(const char* mod, bool loadDll)
{
EXCLUSIVE_ACQUIRE(LockDllBreakpoints);
@ -1730,6 +1736,34 @@ static void cbLoadDll(LOAD_DLL_DEBUG_INFO* LoadDll)
cookie.HandleNtdllLoad(bIsAttached);
if(settingboolget("Misc", "TransparentExceptionStepping"))
exceptionDispatchAddr = DbgValFromString("ntdll:KiUserExceptionDispatcher");
//set debug flags
if(dwDebugFlags != 0)
{
SHARED_ACQUIRE(LockModules);
auto info = ModInfoFromAddr(duint(base));
if(info->symbols->isOpen())
{
dprintf(QT_TRANSLATE_NOOP("DBG", "Waiting until ntdll.dll symbols are loaded...\n"));
info->symbols->waitUntilLoaded();
SymbolInfo LdrpDebugFlags;
if(info->symbols->findSymbolByName("LdrpDebugFlags", LdrpDebugFlags, true))
{
if(MemWrite(info->base + LdrpDebugFlags.rva, &dwDebugFlags, sizeof(dwDebugFlags)))
dprintf(QT_TRANSLATE_NOOP("DBG", "Set LdrpDebugFlags to 0x%08X successfully!\n"), dwDebugFlags);
else
dprintf(QT_TRANSLATE_NOOP("DBG", "Failed to write to LdrpDebugFlags\n"));
}
else
{
dprintf(QT_TRANSLATE_NOOP("DBG", "Symbol 'LdrpDebugFlags' not found!\n"));
}
}
else
{
dprintf(QT_TRANSLATE_NOOP("DBG", "Failed to find LdrpDebugFlags (you need to load symbols for ntdll.dll)\n"));
}
}
}
dprintf(QT_TRANSLATE_NOOP("DBG", "DLL Loaded: %p %s\n"), base, DLLDebugFileName);

View File

@ -81,6 +81,7 @@ bool dbggetwintext(std::vector<std::string>* winTextList, const DWORD dwProcessI
void dbgtracebrowserneedsupdate();
bool dbgsetdllbreakpoint(const char* mod, DWORD type, bool singleshoot);
bool dbgdeletedllbreakpoint(const char* mod, DWORD type);
void dbgsetdebugflags(DWORD flags);
void cbStep();
void cbRtrStep();

View File

@ -309,23 +309,34 @@ bool isunicodestring(const WString & data)
extern "C" __declspec(dllexport) bool isasciistring(const unsigned char* data, int maxlen)
{
int len = 0;
char* safebuffer = new char[maxlen];
if(!safebuffer)
return false;
for(const char* p = (const char*)data; *p; len++, p++)
{
if(len >= maxlen)
break;
safebuffer[p - (const char*)data] = *p;
}
if(len < 2 || len + 1 >= maxlen)
if(len < 2)
{
delete[] safebuffer;
return false;
}
safebuffer[len - 1] = 0; // Mark the end of string
if((maxlen % 2) == 0 && (safebuffer[maxlen - 2] & 0x80))
safebuffer[maxlen - 2] = 0; // Keep DBCS strings from being chopped in the middle
String data2;
WString wdata2;
// Convert to and from Unicode
wdata2 = StringUtils::LocalCpToUtf16((const char*)data);
wdata2 = StringUtils::LocalCpToUtf16(safebuffer);
delete[] safebuffer;
if(wdata2.size() < 2)
return false;
data2 = StringUtils::Utf16ToLocalCp(wdata2);
if(data2.size() > maxlen || data2.size() < 2)
if(data2.size() < 2)
return false;
// Is the data exactly representable in both ANSI and Unicode?
if(memcmp(data2.c_str(), data, data2.size()) != 0)
@ -339,23 +350,32 @@ extern "C" __declspec(dllexport) bool isasciistring(const unsigned char* data, i
extern "C" __declspec(dllexport) bool isunicodestring(const unsigned char* data, int maxlen)
{
int len = 0;
wchar_t* safebuffer = new wchar_t[maxlen];
if(!safebuffer)
return false;
for(const wchar_t* p = (const wchar_t*)data; *p; len += sizeof(wchar_t), p++)
{
if(len >= maxlen)
break;
safebuffer[p - (const wchar_t*)data] = *p;
}
if(len < 2 * sizeof(wchar_t) || len + 1 >= maxlen)
if(len < 2 * sizeof(wchar_t))
{
delete[] safebuffer;
return false;
}
safebuffer[len / sizeof(wchar_t) - 1] = 0; // Mark the end of string
String data2;
WString wdata2;
// Convert to and from ANSI
data2 = StringUtils::Utf16ToLocalCp((const wchar_t*)data);
data2 = StringUtils::Utf16ToLocalCp(safebuffer);
delete[] safebuffer;
if(data2.size() < 2)
return false;
wdata2 = StringUtils::LocalCpToUtf16(data2);
if(wdata2.size() / sizeof(wchar_t) > maxlen || wdata2.size() < 2)
if(wdata2.size() < 2)
return false;
// Is the data exactly representable in both ANSI and Unicode?
if(memcmp(wdata2.c_str(), data, wdata2.size() * sizeof(wchar_t)) != 0)
@ -371,7 +391,7 @@ bool disasmispossiblestring(duint addr, STRING_TYPE* type)
unsigned char data[60];
memset(data, 0, sizeof(data));
duint bytesRead = 0;
if(!MemReadUnsafe(addr, data, sizeof(data) - 3, &bytesRead) && bytesRead < 2)
if(!MemReadUnsafe(addr, data, sizeof(data), &bytesRead) && bytesRead < 2)
return false;
if(isasciistring(data, sizeof(data)))
{

View File

@ -124,7 +124,12 @@ public:
virtual bool cancelLoading()
{
return false;
return false; // Stub
}
virtual void waitUntilLoaded()
{
// Stub
}
// Get the symbol at the specified address, will return false if not found.

View File

@ -97,6 +97,12 @@ bool SymbolSourceDIA::cancelLoading()
return true;
}
void SymbolSourceDIA::waitUntilLoaded()
{
while(isLoading())
Sleep(10);
}
template<size_t Count>
static bool startsWith(const char* str, const char(&prefix)[Count])
{

View File

@ -110,6 +110,8 @@ public:
virtual bool cancelLoading() override;
virtual void waitUntilLoaded() override;
virtual bool findSymbolExact(duint rva, SymbolInfo & symInfo) override;
virtual bool findSymbolExactOrLower(duint rva, SymbolInfo & symInfo) override;

View File

@ -444,6 +444,7 @@ static void registercommands()
dbgcmdnew("flushlog", cbInstrFlushlog, false); //flush the log
dbgcmdnew("AnimateWait", cbInstrAnimateWait, true); //Wait for the debuggee to pause.
dbgcmdnew("dbdecompress", cbInstrDbdecompress, false); //Decompress a database.
dbgcmdnew("DebugFlags", cbInstrDebugFlags, false); //Set ntdll LdrpDebugFlags
};
bool cbCommandProvider(char* cmd, int maxlen)

View File

@ -353,7 +353,7 @@ void MemoryMapView::ExecCommand()
for(int i : getSelection())
{
QString specializedCommand = command;
specializedCommand.replace(QChar('$'), getCellContent(i, 0)); // $ -> Base address
specializedCommand.replace(QChar('$'), ToHexString(getCellUserdata(i, 0))); // $ -> Base address
DbgCmdExec(specializedCommand);
}
}

View File

@ -143,7 +143,7 @@ void ThreadView::ExecCommand()
for(int i : getSelection())
{
QString specializedCommand = command;
specializedCommand.replace(QChar('$'), getCellContent(i, 1)); // $ -> Thread Id
specializedCommand.replace(QChar('$'), ToHexString(getCellUserdata(i, 1))); // $ -> Thread Id
DbgCmdExec(specializedCommand);
}
}
@ -195,6 +195,7 @@ void ThreadView::updateThreadList()
else
setCellContent(i, 0, ToDecString(threadList.list[i].BasicInfo.ThreadNumber));
setCellContent(i, 1, QString().sprintf(tidFormat, threadList.list[i].BasicInfo.ThreadId));
setCellUserdata(i, 1, threadList.list[i].BasicInfo.ThreadId);
setCellContent(i, 2, ToPtrString(threadList.list[i].BasicInfo.ThreadStartAddress));
setCellContent(i, 3, ToPtrString(threadList.list[i].BasicInfo.ThreadLocalBase));
setCellContent(i, 4, ToPtrString(threadList.list[i].ThreadCip));