Skip to content

Commit

Permalink
Fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
thqby committed May 9, 2024
1 parent 1ed75e4 commit b227710
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 26 deletions.
8 changes: 2 additions & 6 deletions source/Debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,7 @@ void Object::DebugWriteProperty(IDebugProperties *aDebugger, int aPage, int aPag
i++; // Count it even if it wasn't within the current page.
}
// For each field in the requested page...
for (int j = page_start - i; i < page_end && (index_t)j < mFields.Length(); ++i, ++j)
for (int j = page_start ? page_start - i : 0; i < page_end && (index_t)j < mFields.Length(); ++i, ++j)
{
Object::FieldType &field = mFields[j];
ExprTokenType value;
Expand Down Expand Up @@ -3043,11 +3043,7 @@ void Debugger::PropertyWriter::_WriteProperty(ExprTokenType &aValue, IObject *aI
if (mError)
return;
PropertyInfo prop(mProp.fullname, mProp.value.buf);
if (aInvokee)
{
aInvokee->AddRef();
prop.invokee = aInvokee;
}
prop.invokee = aInvokee;
// Find the property's "relative" name at the end of the buffer:
prop.name = mProp.fullname.GetString() + mNameLength;
if (*prop.name == '.')
Expand Down
2 changes: 1 addition & 1 deletion source/Debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ class Debugger
int mMaxPropertyData = 1024, mMaxChildren = 20, mMaxDepth = 2;

HookType mDisabledHooks = 0;
bool mProcessingCommands;
bool mProcessingCommands = false;


enum PropertyType
Expand Down
12 changes: 8 additions & 4 deletions source/lib/DllCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1212,13 +1212,17 @@ BIF_DECL(BIF_DllCall)
LPCSTR result = (LPCSTR)return_value.Pointer;
#else
LPCWSTR result = (LPCWSTR)return_value.Pointer;
if (result && return_attrib.type == DLL_ARG_U8STR)
result = CStringWCharFromChar((LPCSTR)return_value.Pointer, -1, CP_UTF8).DetachBuffer();
#endif
if (result && *result)
{
#ifdef UNICODE // Perform the translation:
CStringWCharFromChar result_buf(result, -1, return_attrib.type == DLL_ARG_U8STR ? CP_UTF8 : 0);
#else
CStringCharFromWChar result_buf(result, -1, return_attrib.type == DLL_ARG_U8STR ? CP_UTF8 : 0);
CStringCharFromWChar result_buf(result);
if (return_attrib.type == DLL_ARG_U8STR)
free(result);
#endif
// Store the length of the translated string first since DetachBuffer() clears it.
aResultToken.marker_length = result_buf.GetLength();
Expand Down Expand Up @@ -1355,9 +1359,9 @@ BIF_DECL(BIF_DllCall)
// passed_by_address for all other types. However, it must be used carefully since
// there's no way for Str* to know how or whether the function requires the string
// to be freed (e.g. by calling CoTaskMemFree()).
if (this_dyna_param.ptr != p_str_or_obj[arg_count])
if (!output_var.AssignString((LPTSTR)this_dyna_param.ptr))
aResultToken.SetExitResult(FAIL);
if (this_dyna_param.ptr != output_var.Contents(FALSE)
&& !output_var.AssignString((LPTSTR)this_dyna_param.ptr))
aResultToken.SetExitResult(FAIL);
break;
case DLL_ARG_xSTR: // AStr* on Unicode builds and WStr* on ANSI builds.
case DLL_ARG_U8STR:
Expand Down
33 changes: 18 additions & 15 deletions source/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7456,19 +7456,21 @@ Var* Script::LoadVarFromWinApi(LPTSTR aFuncName)
LeaveCriticalSection(&g_Critical);
}
// WinApi and #DllImport are always global functions
auto *aCurrent_func = g->CurrentFunc;
auto aFuncNameLength = _tclen(aFuncName);
g->CurrentFunc = NULL;
auto aFuncNameLength = _tcslen(aFuncName);
TCHAR parameter[1024] = { 0 }; // Should be enough room for any dll function definition
memcpy(parameter, aFuncName, aFuncNameLength * sizeof(TCHAR));
parameter[aFuncNameLength] = L',';
parameter[aFuncNameLength] = ',';

// parameterlow is used to find the function definition
char parameterlowercase[MAX_PATH] = { '\\' };
char parameterlowercase[MAX_PATH] = { '\\',0 };
#ifdef UNICODE
WideCharToMultiByte(CP_ACP, 0, aFuncName, (int)aFuncNameLength, &parameterlowercase[1], (int)aFuncNameLength + 1, 0, 0);
#else
memcpy(&parameterlowercase[1], aFuncName, aFuncNameLength);
#endif
CharLowerA(parameterlowercase);
parameterlowercase[aFuncNameLength + 1] = L',';
parameterlowercase[aFuncNameLength + 2] = L'\0';
parameterlowercase[aFuncNameLength + 1] = ',';
parameterlowercase[aFuncNameLength + 2] = '\0';
LPSTR found;
if (found = strstr(g_hWinAPIlowercase, parameterlowercase))
{
Expand All @@ -7483,15 +7485,15 @@ Var* Script::LoadVarFromWinApi(LPTSTR aFuncName)
}
MultiByteToWideChar(CP_UTF8, 0, found + 1, (int)aFuncNameLength + 1, aDest, (int)aFuncNameLength * sizeof(TCHAR) + sizeof(TCHAR));
// Override _ in the end of definition (ahk function like SendMessage, Sleep, Send, SendInput ...
if (*(aFuncName + aFuncNameLength - 1) == L'_')
if (*(aFuncName + aFuncNameLength - 1) == '_')
{
*(aDest + aFuncNameLength - 1) = L',';
*(aDest + aFuncNameLength) = L'\0';
*(aDest + aFuncNameLength - 1) = ',';
*(aDest + aFuncNameLength) = '\0';
aDest = aDest + aFuncNameLength;
}
else
{
*(aDest + aFuncNameLength) = L',';
*(aDest + aFuncNameLength) = ',';
aDest = aDest + aFuncNameLength + 1;
}
_tcscpy(aDest, _T(" ="));
Expand All @@ -7502,17 +7504,18 @@ Var* Script::LoadVarFromWinApi(LPTSTR aFuncName)
*aDest = (*found);
aDest++;
}
if (*(--aDest) == _T('*') || *aDest == _T('p') || *aDest == _T('P'))
if (*(--aDest) == '*' || *aDest == 'p' || *aDest == 'P')
*t = *aDest, t--, aDest--;
*t = *aDest, t--, aDest--;
if (*aDest == _T('u') || *aDest == _T('U'))
if (*aDest == 'u' || *aDest == 'U')
*t = *aDest, aDest--;
*(aDest + 1) = _T('\0');
*(aDest + 1) = '\0';
auto aCurrent_func = g->CurrentFunc;
g->CurrentFunc = nullptr;
Var* var = LoadDllFunction(parameter);
g->CurrentFunc = aCurrent_func;
return var;
}
g->CurrentFunc = aCurrent_func;
return NULL;
}

Expand Down

0 comments on commit b227710

Please sign in to comment.