/** \brief Deletes a variable. \param Name The name of the variable to delete. Cannot be null. \param DelSystem true to allow deleting system variables. \return true if the variable was deleted successfully, false otherwise. */ bool vardel(const char* Name, bool DelSystem) { EXCLUSIVE_ACQUIRE(LockVariables); String name_; if(*Name != '$') name_ = "$"; name_ += Name; auto found = variables.find(name_); if(found == variables.end()) //not found return false; if(found->second.alias.length()) { // Release the lock (potential deadlock here) EXCLUSIVE_RELEASE(); return vardel(found->second.alias.c_str(), DelSystem); } if(!DelSystem && found->second.type != VAR_USER) return false; found = variables.begin(); while(found != variables.end()) { auto del = found; found++; if(found->second.name == String(Name)) variables.erase(del); } return true; }
void ThreadCreate(CREATE_THREAD_DEBUG_INFO* CreateThread) { THREADINFO curInfo; memset(&curInfo, 0, sizeof(THREADINFO)); curInfo.ThreadNumber = ThreadGetCount(); curInfo.Handle = INVALID_HANDLE_VALUE; curInfo.ThreadId = ((DEBUG_EVENT*)GetDebugData())->dwThreadId; curInfo.ThreadStartAddress = (duint)CreateThread->lpStartAddress; curInfo.ThreadLocalBase = (duint)CreateThread->lpThreadLocalBase; // Duplicate the debug thread handle -> thread handle DuplicateHandle(GetCurrentProcess(), CreateThread->hThread, GetCurrentProcess(), &curInfo.Handle, 0, FALSE, DUPLICATE_SAME_ACCESS); // The first thread (#0) is always the main program thread if(curInfo.ThreadNumber <= 0) strcpy_s(curInfo.threadName, "Main Thread"); // Modify global thread list EXCLUSIVE_ACQUIRE(LockThreads); threadList.insert(std::make_pair(curInfo.ThreadId, curInfo)); EXCLUSIVE_RELEASE(); // Notify GUI GuiUpdateThreadView(); }
void ModClear() { EXCLUSIVE_ACQUIRE(LockModules); modinfo.clear(); EXCLUSIVE_RELEASE(); // Tell the symbol updater SymUpdateModuleList(); }
void ThreadClear() { EXCLUSIVE_ACQUIRE(LockThreads); // Close all handles first for(auto & itr : threadList) CloseHandle(itr.second.Handle); // Empty the array threadList.clear(); // Update the GUI's list EXCLUSIVE_RELEASE(); GuiUpdateThreadView(); }
void ThreadExit(DWORD ThreadId) { EXCLUSIVE_ACQUIRE(LockThreads); // Erase element using native functions auto itr = threadList.find(ThreadId); if(itr != threadList.end()) { CloseHandle(itr->second.Handle); threadList.erase(itr); } EXCLUSIVE_RELEASE(); GuiUpdateThreadView(); }
bool cbCheckWatchdog(int argc, char* argv[]) { EXCLUSIVE_ACQUIRE(LockWatch); bool watchdogTriggered = false; for(auto j = watchexpr.begin(); j != watchexpr.end(); ++j) { std::pair<unsigned int, WatchExpr*> i = *j; i.second->watchdogTriggered = false; duint intVal = i.second->getIntValue(); watchdogTriggered |= i.second->watchdogTriggered; } EXCLUSIVE_RELEASE(); if(watchdogTriggered) GuiUpdateWatchViewAsync(); varset("$result", watchdogTriggered ? 1 : 0, false); return true; }
bool ModUnload(uint Base) { EXCLUSIVE_ACQUIRE(LockModules); // Find the iterator index const auto found = modinfo.find(Range(Base, Base)); if(found == modinfo.end()) return false; // Unload everything from TitanEngine StaticFileUnloadW(nullptr, false, found->second.Handle, found->second.FileMapSize, found->second.MapHandle, found->second.FileMapVA); // Remove it from the list modinfo.erase(found); EXCLUSIVE_RELEASE(); // Update symbols SymUpdateModuleList(); return true; }
/** \brief Sets a variable by name. \param Name The name of the variable. Cannot be null. \param Value The new value. Cannot be null. \param ReadOnly true to set read-only variables (like $hProcess etc.). \return true if the variable was set correctly, false otherwise. */ bool varset(const char* Name, VAR_VALUE* Value, bool ReadOnly) { EXCLUSIVE_ACQUIRE(LockVariables); String name_; if(*Name != '$') name_ = "$"; name_ += Name; auto found = variables.find(name_); if(found == variables.end()) //not found return false; if(found->second.alias.length()) { // Release the lock (potential deadlock here) EXCLUSIVE_RELEASE(); return varset(found->second.alias.c_str(), Value, ReadOnly); } if(!ReadOnly && (found->second.type == VAR_READONLY || found->second.type == VAR_HIDDEN)) return false; varsetvalue(&found->second, Value); return true; }
bool ModLoad(uint Base, uint Size, const char* FullPath) { // // Handle a new module being loaded // // TODO: Do loaded modules always require a path? if(!Base || !Size || !FullPath) return false; MODINFO info; // Copy the module path in the struct strcpy_s(info.path, FullPath); // Break the module path into a directory and file name char dir[MAX_PATH] = ""; char file[MAX_MODULE_SIZE] = ""; strcpy_s(dir, FullPath); _strlwr(dir); char* fileStart = strrchr(dir, '\\'); if(fileStart) { strcpy_s(file, fileStart + 1); *fileStart = '\0'; } //calculate module hash from full file name info.hash = ModHashFromName(file); // Copy the extension into the module struct { char* extensionPos = strrchr(file, '.'); if(extensionPos) { strcpy_s(info.extension, extensionPos); extensionPos[0] = '\0'; } } // Copy the name to the module struct strcpy_s(info.name, file); // Module base address/size info.base = Base; info.size = Size; // Process module sections info.sections.clear(); WString wszFullPath = StringUtils::Utf8ToUtf16(FullPath); if(StaticFileLoadW(wszFullPath.c_str(), UE_ACCESS_READ, false, &info.Handle, &info.FileMapSize, &info.MapHandle, &info.FileMapVA)) { // Get the entry point info.entry = GetPE32DataFromMappedFile(info.FileMapVA, 0, UE_OEP) + info.base; // Enumerate all PE sections int sectionCount = (int)GetPE32DataFromMappedFile(info.FileMapVA, 0, UE_SECTIONNUMBER); for(int i = 0; i < sectionCount; i++) { MODSECTIONINFO curSection; curSection.addr = GetPE32DataFromMappedFile(info.FileMapVA, i, UE_SECTIONVIRTUALOFFSET) + info.base; curSection.size = GetPE32DataFromMappedFile(info.FileMapVA, i, UE_SECTIONVIRTUALSIZE); const char* sectionName = (const char*)GetPE32DataFromMappedFile(info.FileMapVA, i, UE_SECTIONNAME); // Escape section name when needed strcpy_s(curSection.name, StringUtils::Escape(sectionName).c_str()); // Add entry to the vector info.sections.push_back(curSection); } } // Add module to list EXCLUSIVE_ACQUIRE(LockModules); modinfo.insert(std::make_pair(Range(Base, Base + Size - 1), info)); EXCLUSIVE_RELEASE(); SymUpdateModuleList(); return true; }