BOOL CFileControlTool::GetName( HANDLE handle,LPTSTR str, DWORD processId ) { WORD type = 0; if ( !GetHandleType( handle, type, processId ) ) return FALSE; return GetNameByType( handle, type, str, processId ); }
int loadCEServerExtension(HANDLE hProcess) { printf("loadCEServerExtension\n"); if (GetHandleType(hProcess) == htProcesHandle ) { PProcessData p=(PProcessData)GetPointerFromHandle(hProcess); if (p->isDebugged) { printf("this process id being debugged\n"); //make sure this is executed by the debugger thread if (p->debuggerThreadID!=pthread_self()) { printf("Not the debugger thread. Switching...\n"); //tell the debugger thread to do this int result=0; #pragma pack(1) struct { uint8_t command; uint32_t pHandle; } lx; #pragma pack() lx.command=CMD_LOADEXTENSION; lx.pHandle=hProcess; if (pthread_mutex_lock(&debugsocketmutex) == 0) { sendall(p->debuggerClient, &lx, sizeof(lx), 0); WakeDebuggerThread(); recvall(p->debuggerClient, &result, sizeof(result), MSG_WAITALL); printf("Returned from debugger thread. Result:%d\n", result); pthread_mutex_unlock(&debugsocketmutex); } return result; } else printf("This is the debugger thread\n"); } if (p->hasLoadedExtension==0) { char modulepath[256], modulepath2[256]; int l; memset(modulepath, 0, 256); memset(modulepath2, 0, 256); char *mp; l=readlink("/proc/self/exe", modulepath2, 256); if (l!=-1) { modulepath2[l]=0; printf("modulepath2=%s\n", modulepath2); sscanf(modulepath2,"%s", modulepath); //sometimes it has a (deleted) text after it printf("modulepath=%s\n", modulepath); mp=dirname(modulepath); printf("after dirname: %s\n", mp); strcpy(modulepath, mp); strcat(modulepath, "/libceserver-extension.so"); printf("modulepath = %s\n", modulepath); } else { strcpy(modulepath, "libceserver-extension.so"); } if (p->isDebugged) { printf("This process is being debugged. Checking if it's already loaded\n"); pthread_mutex_lock(&p->extensionMutex); p->hasLoadedExtension=openExtension(p->pid, &p->extensionFD); pthread_mutex_unlock(&p->extensionMutex); } // else if (p->hasLoadedExtension) printf("The extension is already loaded\n"); { pthread_mutex_lock(&p->extensionMutex); if (p->hasLoadedExtension==0) //still 0 { if (p->neverForceLoadExtension==0) { printf("Calling loadExtension\n"); p->hasLoadedExtension=loadExtension(p->pid, modulepath, p->isDebugged); } if (p->hasLoadedExtension) p->hasLoadedExtension=openExtension(p->pid, &p->extensionFD); } pthread_mutex_unlock(&p->extensionMutex); } } else printf("Already loaded\n"); return p->hasLoadedExtension; } else { printf("Invalid handle type"); return 0; } }