SHORT CFreeLists::FindList(CString strFileName) { SHORT nCurFile; CString strShortFileName; LoadFileList(); strShortFileName = GetShortFileName(strFileName); for(nCurFile=0;nCurFile < m_FileList.GetNumFiles();nCurFile++) { if(m_FileList.GetFileName(nCurFile).CompareNoCase(strShortFileName)==0) return nCurFile + 1; // Match } return -1; }
SHORT CFreeLists::CreateList(CString strFileName) { SHORT nNewEntry; CString strShortFileName; SHORT nHandle; strShortFileName = GetShortFileName(strFileName); LoadFileList(); nHandle = FindList(strShortFileName); if(nHandle >= 0) return nHandle; // Assert if trying to create list that already exists ASSERT(nHandle < 0); nNewEntry = m_FileList.AddEntry(strShortFileName) + 1; SaveFileList(); return nNewEntry; }
void Packer::Pack(const LstFile &aLstFileIn, const std::string &aFileOut) { FILE *fIn, *fOut; if (fopen_s(&fOut, aFileOut.c_str(), "wb") || !fOut) { throw Error("Failed to create file " + aFileOut); } fprintf(fOut, "%c", (unsigned char)alg); //записываем в выходной файл вид алгоритма, на основании которого идет архивация WriteInt(fOut, aLstFileIn.size()); //записываем в выходной файл количество файлов для архивации for (LstFile::const_iterator it = aLstFileIn.begin(); it != aLstFileIn.end(); ++it) { time_t tBegin = time(0); if (fopen_s(&fIn, (*it).c_str(), "rb") || !fIn) { throw Error("Failed to open file " + *it); } std::string shortFName = GetShortFileName(*it); fprintf(fOut, "%c", (unsigned char)shortFName.size()); //записываем в выходной файл размер имени архивируемого файла for (unsigned int i = 0; i < shortFName.size(); ++i) //записываем в выходной файл имя архивируемого файла { fprintf(fOut, "%c", shortFName[i]); } //Определяем размер файла fseek(fIn, 0, SEEK_END); unsigned int fSize = ftell(fIn); fseek(fIn, 0, SEEK_SET); Printer pr; pr.PrintText("Compression " + *it + ": 0%"); _Pack(fIn, fOut, fSize, pr); pr.PrintPercent(100); pr.PrintText("\n"); fclose(fIn); } fclose(fOut); }
std::string ExecuteProcess(const std::string& file, std::vector<std::string> args) { // "The first argument, by convention, should point to // the filename associated with the file being executed." // NOTE: // spaces in the first argument or quoted file paths // are not supported on Windows, so translate <file> // to a short path there args.insert(args.begin(), GetShortFileName(file)); // "The array of pointers must be terminated by a NULL pointer." // --> include one extra argument string and leave it NULL std::vector<char*> processArgs(args.size() + 1, NULL); std::string execError; for (size_t a = 0; a < args.size(); ++a) { const std::string& arg = args[a]; const size_t argSize = arg.length() + 1; STRCPY_T(processArgs[a] = new char[argSize], argSize, arg.c_str()); } #ifdef WIN32 #define EXECVP _execvp #else #define EXECVP execvp #endif if (EXECVP(args[0].c_str(), &processArgs[0]) == -1) { LOG("[%s] error: \"%s\" %s (%d)", __FUNCTION__, args[0].c_str(), (execError = strerror(errno)).c_str(), errno); } #undef EXECVP for (size_t a = 0; a < args.size(); ++a) { delete[] processArgs[a]; } return execError; }
wchar_t* GetShortFileNameEx(LPCWSTR asLong, BOOL abFavorLength/*=TRUE*/) { if (!asLong) return NULL; int nSrcLen = lstrlenW(asLong); //-V303 wchar_t* pszLong = lstrdup(asLong); int nMaxLen = nSrcLen + MAX_PATH; // "короткое" имя может более MAX_PATH wchar_t* pszShort = (wchar_t*)calloc(nMaxLen, sizeof(wchar_t)); //-V106 wchar_t* pszResult = NULL; wchar_t* pszSrc = pszLong; //wchar_t* pszDst = pszShort; wchar_t* pszSlash; wchar_t* szName = (wchar_t*)malloc((MAX_PATH+1)*sizeof(wchar_t)); bool lbNetwork = false; int nLen, nCurLen = 0; if (!pszLong || !pszShort || !szName) goto wrap; // Если путь сетевой (или UNC?) пропустить префиксы/серверы if (pszSrc[0] == L'\\' && pszSrc[1] == '\\') { // пропуск первых двух слешей pszSrc += 2; // формат "диска" не поддерживаем \\.\Drive\... if (pszSrc[0] == L'.' && pszSrc[1] == L'\\') goto wrap; // UNC if (pszSrc[0] == L'?' && pszSrc[1] == L'\\') { pszSrc += 2; if (pszSrc[0] == L'U' && pszSrc[1] == L'N' && pszSrc[2] == L'C' && pszSrc[3] == L'\\') { // UNC\Server\share\... pszSrc += 4; //-V112 lbNetwork = true; } // иначе - ожидается диск } // Network (\\Server\\Share\...) else { lbNetwork = true; } } if (pszSrc[0] == 0) goto wrap; if (lbNetwork) { pszSlash = wcschr(pszSrc, L'\\'); if (!pszSlash) goto wrap; pszSlash = wcschr(pszSlash+1, L'\\'); if (!pszSlash) goto wrap; pszShort[0] = L'\\'; pszShort[1] = L'\\'; pszShort[2] = 0; _wcscatn_c(pszShort, nMaxLen, pszSrc, (pszSlash-pszSrc+1)); // память выделяется calloc! //-V303 //-V104 } else { // <Drive>:\path... if (pszSrc[1] != L':') goto wrap; if (pszSrc[2] != L'\\' && pszSrc[2] != 0) goto wrap; pszSlash = pszSrc + 2; _wcscatn_c(pszShort, nMaxLen, pszSrc, (pszSlash-pszSrc+1)); // память выделяется calloc! } nCurLen = lstrlenW(pszShort); while (pszSlash && (*pszSlash == L'\\')) { pszSrc = pszSlash; pszSlash = wcschr(pszSrc+1, L'\\'); if (pszSlash) *pszSlash = 0; if (!GetShortFileName(pszLong, MAX_PATH+1, szName, abFavorLength)) goto wrap; nLen = lstrlenW(szName); if ((nLen + nCurLen) >= nMaxLen) goto wrap; //pszShort[nCurLen++] = L'\\'; pszShort[nCurLen] = 0; _wcscpyn_c(pszShort+nCurLen, nMaxLen-nCurLen, szName, nLen); nCurLen += nLen; if (pszSlash) { *pszSlash = L'\\'; pszShort[nCurLen++] = L'\\'; // память выделяется calloc! } } nLen = lstrlenW(pszShort); if ((nLen > 0) && (pszShort[nLen-1] == L'\\')) pszShort[--nLen] = 0; if (nLen <= MAX_PATH) { pszResult = pszShort; pszShort = NULL; goto wrap; } wrap: if (szName) free(szName); if (pszShort) free(pszShort); if (pszLong) free(pszLong); return pszResult; }
INT_PTR CALLBACK DlgSkinEditorOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_DESTROY: { if (object_clipboard) mir_free_and_nill(object_clipboard); break; } case WM_WINDOWPOSCHANGED: { WINDOWPOS * wp=(WINDOWPOS *)lParam; if (lParam && wp->flags&SWP_SHOWWINDOW) { if (glOtherSkinWasLoaded) { TreeView_DeleteAllItems(GetDlgItem(hwndDlg,IDC_OBJECT_TREE)); FillObjectTree(hwndDlg,IDC_OBJECT_TREE,"$$*"); glSkinWasModified=0; glOtherSkinWasLoaded=FALSE; } } break; } case WM_INITDIALOG: { TranslateDialogDefault(hwndDlg); FillObjectTree(hwndDlg,IDC_OBJECT_TREE,"$$*"); { //Fill types combo int i=0; for (i=0; i<SIZEOF(TYPES); i++) SendDlgItemMessage(hwndDlg,IDC_TYPE,CB_ADDSTRING,0,(LPARAM)TranslateTS(TYPES[i])); } { //Fill fit combo int i=0; for (i=0; i<SIZEOF(FITMODES); i++) SendDlgItemMessage(hwndDlg,IDC_FIT,CB_ADDSTRING,0,(LPARAM)TranslateTS(FITMODES[i])); } //SPIN Ranges { SendDlgItemMessage(hwndDlg,IDC_SPIN_ALPHA,UDM_SETRANGE,0,MAKELONG(255,0)); SendDlgItemMessage(hwndDlg,IDC_SPIN_ALPHA,UDM_SETPOS,0,MAKELONG(255,0)); SendDlgItemMessage(hwndDlg,IDC_SPIN_TOP,UDM_SETRANGE,0,MAKELONG(900,0)); SendDlgItemMessage(hwndDlg,IDC_SPIN_LEFT,UDM_SETRANGE,0,MAKELONG(900,0)); SendDlgItemMessage(hwndDlg,IDC_SPIN_BOTTOM,UDM_SETRANGE,0,MAKELONG(900,0)); SendDlgItemMessage(hwndDlg,IDC_SPIN_RIGHT,UDM_SETRANGE,0,MAKELONG(900,0)); SendDlgItemMessage(hwndDlg,IDC_SPIN_POSLEFT,UDM_SETRANGE,0,MAKELONG(1000,0)); SendDlgItemMessage(hwndDlg,IDC_SPIN_POSTOP,UDM_SETRANGE,0,MAKELONG(1000,0)); SendDlgItemMessage(hwndDlg,IDC_SPIN_WIDTH,UDM_SETRANGE,0,MAKELONG(1000,0)); SendDlgItemMessage(hwndDlg,IDC_SPIN_HEIGHT,UDM_SETRANGE,0,MAKELONG(1000,0)); } EnableGroup(hwndDlg,GetDlgItem(hwndDlg,IDC_GROUP_1),FALSE); EnableGroup(hwndDlg,GetDlgItem(hwndDlg,IDC_ST_COLOUR),FALSE); EnableGroup(hwndDlg,GetDlgItem(hwndDlg,IDC_ST_ALPHA),FALSE); EnableGroup(hwndDlg,GetDlgItem(hwndDlg,IDC_GROUP_2),FALSE); EnableGroup(hwndDlg,GetDlgItem(hwndDlg,IDC_GROUP_3),FALSE); EnableWindow(GetDlgItem(hwndDlg,IDC_PASTE),FALSE); EnableWindow(GetDlgItem(hwndDlg,IDC_COPY),FALSE); glSkinWasModified=0; glOtherSkinWasLoaded=FALSE; break; } case WM_COMMAND: { if (LOWORD(wParam)==IDC_TYPE) { if (HIWORD(wParam)==CBN_SELCHANGE) { int i=SendDlgItemMessage(hwndDlg,IDC_TYPE,CB_GETCURSEL,(WPARAM)0,(LPARAM)0); //if (IsWindowEnabled(GetDlgItem(hwndDlg,IDC_TYPE))) SetAppropriateGroups(hwndDlg,i); if (GetFocus()==GetDlgItem(hwndDlg,IDC_TYPE)) SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); UpdateInfo(hwndDlg); break; } } else if (LOWORD(wParam)==IDC_COPY) { if (HIWORD(wParam)==BN_CLICKED) { if (object_clipboard) mir_free_and_nill(object_clipboard); object_clipboard=NULL; { OPT_OBJECT_DATA *sd=NULL; HTREEITEM hti=TreeView_GetSelection(GetDlgItem(hwndDlg,IDC_OBJECT_TREE)); if (hti!=0) { TVITEM tvi={0}; tvi.hItem=hti; tvi.mask=TVIF_HANDLE|TVIF_PARAM; TreeView_GetItem(GetDlgItem(hwndDlg,IDC_OBJECT_TREE),&tvi); sd=(OPT_OBJECT_DATA*)(tvi.lParam); } if (sd && sd->szValue) object_clipboard=mir_strdup(sd->szValue); } EnableWindow(GetDlgItem(hwndDlg,IDC_PASTE),object_clipboard!=NULL); return 0; } } else if (LOWORD(wParam)==IDC_PASTE) { if (HIWORD(wParam)==BN_CLICKED) { if (object_clipboard) SetControls(hwndDlg, object_clipboard); SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); UpdateInfo(hwndDlg); return 0; } } else if (LOWORD(wParam)==IDC_COLOR) { SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); UpdateInfo(hwndDlg); } else if (LOWORD(wParam)==IDC_BROWSE) { if (HIWORD(wParam)==BN_CLICKED) { { char str[MAX_PATH]={0}; OPENFILENAMEA ofn={0}; char filter[512]={0}; int res=0; ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; ofn.hwndOwner = hwndDlg; ofn.hInstance = NULL; ofn.lpstrFilter = "Images (*.png,*.jpg,*.bmp,*.gif,*.tga)\0*.png;*.jpg;*.jpeg;*.bmp;*.gif;*.tga\0All files (*.*)\0*.*\0\0"; ofn.Flags = (OFN_FILEMUSTEXIST | OFN_HIDEREADONLY); SendDlgItemMessageA(hwndDlg,IDC_FILE,WM_GETTEXT,(WPARAM)SIZEOF(str),(LPARAM)str); if (str[0]=='\0' || strchr(str,'%')) { ofn.Flags|=OFN_NOVALIDATE; str[0]='\0'; } else { ske_GetFullFilename(str,str,(char*)0,TRUE); } ofn.lpstrFile = str; ofn.nMaxFile = SIZEOF(str); ofn.nMaxFileTitle = MAX_PATH; ofn.lpstrDefExt = "*.*"; // { // DWORD tick=GetTickCount(); res=GetOpenFileNameA(&ofn); // if(!res) // if (GetTickCount()-tick<100) // { // res=GetOpenFileNameA(&ofn); // if(!res) break; // } // else break; //} if (res) { GetShortFileName(ofn.lpstrFile); SendDlgItemMessageA(hwndDlg,IDC_FILE,WM_SETTEXT,(WPARAM)0,(LPARAM)ofn.lpstrFile); SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); UpdateInfo(hwndDlg); } } } } else if (LOWORD(wParam)==IDC_FILE) { if (HIWORD(wParam) == EN_CHANGE) { fileChanged=TRUE; if ((HWND)lParam != GetFocus()) { GetFileSizes(hwndDlg); fileChanged=FALSE; } } else if (HIWORD(wParam) == EN_KILLFOCUS) { if (fileChanged) { GetFileSizes(hwndDlg); fileChanged=FALSE; } } } else if (( (LOWORD(wParam)==IDC_E_TOP ||LOWORD(wParam)==IDC_E_BOTTOM ||LOWORD(wParam)==IDC_E_LEFT ||LOWORD(wParam)==IDC_E_RIGHT ||LOWORD(wParam)==IDC_E_X ||LOWORD(wParam)==IDC_E_Y ||LOWORD(wParam)==IDC_E_W ||LOWORD(wParam)==IDC_E_H ||LOWORD(wParam)==IDC_EDIT_ALPHA ) && HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus())) { return 0; } else if (LOWORD(wParam)!=IDC_EDIT1) { SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); UpdateInfo(hwndDlg); } //check (LOWORD(wParam)) //SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; } case WM_NOTIFY: switch (((LPNMHDR)lParam)->idFrom) { case IDC_OBJECT_TREE: { //Save existed object //Change to new object NMTREEVIEWA * nmtv = (NMTREEVIEWA *) lParam; if (!nmtv) return 0; if (nmtv->hdr.code==TVN_SELCHANGEDA || nmtv->hdr.code==TVN_SELCHANGEDW) { if (nmtv->itemOld.lParam) { OPT_OBJECT_DATA * dataOld=(OPT_OBJECT_DATA*)nmtv->itemOld.lParam; if (dataOld->szValue) { mir_free_and_nill(dataOld->szValue); dataOld->szValue=MadeString(hwndDlg); } } if (nmtv->itemNew.lParam) { OPT_OBJECT_DATA * data=(OPT_OBJECT_DATA*)nmtv->itemNew.lParam; char buf[255]; mir_snprintf(buf,SIZEOF(buf),"%s=%s",data->szName, data->szValue); SendDlgItemMessageA(hwndDlg,IDC_EDIT1,WM_SETTEXT,0,(LPARAM)buf); SetControls(hwndDlg,data->szValue); EnableWindow(GetDlgItem(hwndDlg,IDC_COPY),TRUE); EnableWindow(GetDlgItem(hwndDlg,IDC_PASTE),object_clipboard!=NULL); } else { SendDlgItemMessageA(hwndDlg,IDC_EDIT1,WM_SETTEXT,0,(LPARAM)""); SetControls(hwndDlg,NULL); EnableWindow(GetDlgItem(hwndDlg,IDC_COPY),FALSE); EnableWindow(GetDlgItem(hwndDlg,IDC_PASTE),FALSE); } } else if (nmtv->hdr.code==TVN_DELETEITEMA) { OPT_OBJECT_DATA * dataOld=(OPT_OBJECT_DATA*)nmtv->itemOld.lParam; if (dataOld) { if (dataOld->szName) mir_free_and_nill(dataOld->szName); if (dataOld->szPath) mir_free_and_nill(dataOld->szPath); if (dataOld->szTempValue) mir_free_and_nill(dataOld->szTempValue); if (dataOld->szValue) mir_free_and_nill(dataOld->szValue); } } return 0; } case 0: switch (((LPNMHDR)lParam)->code) { case PSN_APPLY: if (!glOtherSkinWasLoaded) //store only if skin is same { StoreTreeToDB(GetDlgItem(hwndDlg,IDC_OBJECT_TREE),SKIN); //ReloadSkin ske_LoadSkinFromDB(); pcli->pfnClcBroadcast( INTM_RELOADOPTIONS,0,0); Sync(CLUIFrames_OnClistResize_mod,0,0); ske_RedrawCompleteWindow(); Sync(CLUIFrames_OnClistResize_mod, (WPARAM)0, (LPARAM)0); { HWND hwnd=pcli->hwndContactList; RECT rc={0}; GetWindowRect(hwnd, &rc); Sync(CLUIFrames_OnMoving,hwnd,&rc); } return TRUE; } else return TRUE; } break; } } return FALSE; }
void CCOF2ELF<ELFSTRUCTURES>::MakeSymbolTable() { // Convert subfunction: Make symbol table and string tables int isym; // current symbol table entry int numaux; // Number of auxiliary entries in source record int OldSectionIndex; // Index into old section table. 1-based int NewSectionIndex; // Index into new section table. 0-based const int WordSize = sizeof(NewFileHeader.e_entry) * 8; // word size 32 or 64 bits TELF_Symbol sym; // Temporary symbol table record const char * name1; // Name of section or main record // Pointer to old symbol table union { SCOFF_SymTableEntry * p; // Symtab entry pointer int8 * b; // Used for increment } OldSymtab; // Make the first record empty NewSections[symtab].Push(0, sizeof(TELF_Symbol)); // Make first string table entries empty NewSections[strtab] .PushString(""); NewSections[stabstr].PushString(""); // Loop twice through source symbol table to get local symbols first, global symbols last // Loop 1: Look for local symbols only OldSymtab.p = SymbolTable; // Pointer to source symbol table for (isym = 0; isym < this->NumberOfSymbols; isym += numaux+1, OldSymtab.b += SIZE_SCOFF_SymTableEntry*(numaux+1)) { if (OldSymtab.b >= Buf() + DataSize) { err.submit(2040); break; } // Number of auxiliary records belonging to same symbol numaux = OldSymtab.p->s.NumAuxSymbols; if (numaux < 0) numaux = 0; if (OldSymtab.p->s.StorageClass != COFF_CLASS_EXTERNAL && OldSymtab.p->s.StorageClass != COFF_CLASS_WEAK_EXTERNAL) { // Symbol is local // Reset destination entry memset(&sym, 0, sizeof(sym)); // Binding sym.st_bind = STB_LOCAL; // Get first aux record if numaux > 0 //SCOFF_SymTableEntryAux * sa = (SCOFF_SymTableEntryAux *)(OldSymtab.b + SIZE_SCOFF_SymTableEntry); // Symbol name name1 = this->GetSymbolName(OldSymtab.p->s.Name); // Symbol value sym.st_value = OldSymtab.p->s.Value; // Get section OldSectionIndex = OldSymtab.p->s.SectionNumber; // 1-based index into old section table NewSectionIndex = 0; // 0-based index into old section table if (OldSectionIndex > 0 && OldSectionIndex <= this->NSections) { // Subtract 1 from OldSectionIndex because NewSectIndex[] is zero-based while OldSectionIndex is 1-based // Get new section index from translation table NewSectionIndex = NewSectIndex[OldSectionIndex-1]; } if (NewSectionIndex == COFF_SECTION_REMOVE_ME) { continue; // Section has been removed. Remove symbol too } sym.st_shndx = (uint16)NewSectionIndex; // Check symbol type if (OldSymtab.p->s.StorageClass == COFF_CLASS_FILE) { // This is a filename record if (numaux > 0 && numaux < 20) { // Get filename from subsequent Aux records. // Remove path from filename because the path makes no sense on a different platform. const char * filename = GetShortFileName(OldSymtab.p); // Put file name into string table and debug string table sym.st_name = NewSections[strtab].PushString(filename); NewSections[stabstr].PushString(filename); } // Attributes for filename record sym.st_shndx = (uint16)SHN_ABS; sym.st_type = STT_FILE; sym.st_bind = STB_LOCAL; sym.st_value = 0; } else if (numaux && OldSymtab.p->s.StorageClass == COFF_CLASS_STATIC && OldSymtab.p->s.Value == 0 && OldSymtab.p->s.Type != 0x20) { // This is a section definition record sym.st_name = 0; name1 = 0; sym.st_type = STT_SECTION; sym.st_bind = STB_LOCAL; sym.st_value = 0; // aux record contains length and number of relocations. Ignore aux record } else if (OldSymtab.p->s.SectionNumber < 0) { // This is an absolute or debug symbol sym.st_type = STT_NOTYPE; sym.st_shndx = (uint16)SHN_ABS; } else if (OldSymtab.p->s.Type == 0 && OldSymtab.p->s.StorageClass == COFF_CLASS_FUNCTION) { // This is a .bf, .lf, or .ef record following a function record // Contains line number information etc. Ignore this record continue; } else if (OldSymtab.p->s.SectionNumber <= 0) { // Unknown sym.st_type = STT_NOTYPE; } else { // This is a local data definition record sym.st_type = STT_OBJECT; // The size is not specified in COFF record, // so we may give it an arbitrary size: // sym.size = 4; } // Put symbol name into string table if we have not already done so if (sym.st_name == 0 && name1) { sym.st_name = NewSections[strtab].PushString(name1); } // Put record into new symbol table NewSections[symtab].Push(&sym, sizeof(sym)); // Insert into symbol translation table NewSymbolIndex[isym] = NewSections[symtab].GetLastIndex(); } // End if not external } // End loop 1 // Finished with local symbols // Make index to first global symbol NewSectionHeaders[symtab].sh_info = NewSections[symtab].GetLastIndex() + 1; // Loop 2: Look for global symbols only OldSymtab.p = SymbolTable; // Pointer to source symbol table for (isym = 0; isym < NumberOfSymbols; isym += numaux+1, OldSymtab.b += SIZE_SCOFF_SymTableEntry*(numaux+1)) { // Number of auxiliary records belonging to same symbol numaux = OldSymtab.p->s.NumAuxSymbols; if (numaux < 0) numaux = 0; if (OldSymtab.p->s.StorageClass == COFF_CLASS_EXTERNAL || OldSymtab.p->s.StorageClass == COFF_CLASS_WEAK_EXTERNAL) { // Symbol is global (public or external) // Reset destination entry memset(&sym, 0, sizeof(sym)); // Binding sym.st_bind = STB_GLOBAL; if (OldSymtab.p->s.StorageClass == COFF_CLASS_WEAK_EXTERNAL) sym.st_bind = STB_WEAK; // Get first aux record if numaux > 0 SCOFF_SymTableEntry * sa = (SCOFF_SymTableEntry*)(OldSymtab.b + SIZE_SCOFF_SymTableEntry); // Symbol name name1 = GetSymbolName(OldSymtab.p->s.Name); // Symbol value sym.st_value = OldSymtab.p->s.Value; // Get section OldSectionIndex = OldSymtab.p->s.SectionNumber; // 1-based index into old section table NewSectionIndex = 0; // 0-based index into old section table if (OldSectionIndex > 0 && OldSectionIndex <= NSections) { // Subtract 1 from OldSectionIndex because NewSectIndex[] is zero-based while OldSectionIndex is 1-based // Get new section index from translation table NewSectionIndex = NewSectIndex[OldSectionIndex-1]; } if (NewSectionIndex == COFF_SECTION_REMOVE_ME) { continue; // Section has been removed. Remove symbol too } if ((int16)OldSectionIndex == COFF_SECTION_ABSOLUTE) { NewSectionIndex = SHN_ABS; } sym.st_shndx = (uint16)NewSectionIndex; // Check symbol type if (OldSymtab.p->s.SectionNumber < 0) { // This is an absolute or debug symbol sym.st_type = STT_NOTYPE; } else if (OldSymtab.p->s.Type == COFF_TYPE_FUNCTION && OldSymtab.p->s.SectionNumber > 0) { // This is a function definition record sym.st_type = STT_FUNC; if (numaux) { // Get size from aux record sym.st_size = sa->func.TotalSize; } if (sym.st_size == 0) { // The size is not specified in the COFF file. // We may give it an arbitrary size: // sym.size = 1; } } else if (OldSymtab.p->s.SectionNumber <= 0) { // This is an external symbol sym.st_type = STT_NOTYPE; } else { // This is a data definition record sym.st_type = STT_OBJECT; // Symbol must have a size. The size is not specified in COFF record, // so we just give it an arbitrary size sym.st_size = 4; } // Put symbol name into string table if we have not already done so if (sym.st_name == 0 && name1) { sym.st_name = NewSections[strtab].PushString(name1); } // Put record into new symbol table NewSections[symtab].Push(&sym, sizeof(sym)); // Insert into symbol translation table NewSymbolIndex[isym] = NewSections[symtab].GetLastIndex(); } // End if external } // End loop 2 }
BOOL PsGetProcessMappedModules(HANDLE ProcessHandle, MODULE_INFO *Entries, SIZE_T NumOfEntries, PSIZE_T RealNumOfEntries) { SIZE_T moduleOffset = 0; SIZE_T moduleCounter = 0; MEMORY_BASIC_INFORMATION memBasicInfo; LPVOID baseAddress = NULL; SIZE_T queryResult; SIZE_T returnLength; do { queryResult = VirtualQueryEx(ProcessHandle, baseAddress, &memBasicInfo, sizeof(memBasicInfo)); if (!queryResult) { break; } if (memBasicInfo.Type == MEM_IMAGE && baseAddress == memBasicInfo.AllocationBase) { moduleCounter++; if (moduleOffset >= NumOfEntries) { baseAddress = (LPVOID)((uintptr_t)baseAddress + memBasicInfo.RegionSize); continue; } DWORD Result = PsGetImageFileNameEx(ProcessHandle, baseAddress, Entries[moduleOffset].ModulePath, MAX_PATH, &returnLength); Entries[moduleOffset].ModuleHandle = (HMODULE)baseAddress; GetShortFileName(Entries[moduleOffset].ModulePath, Entries[moduleOffset].ModuleName, MAX_PATH); moduleOffset++; } baseAddress = (LPVOID)((uintptr_t)baseAddress + memBasicInfo.RegionSize); } while (TRUE); if (RealNumOfEntries) { *RealNumOfEntries = moduleCounter; } if (moduleCounter > NumOfEntries) { return FALSE; } return TRUE; }
BOOL PsGetModulesByProcessHandle(HANDLE ProcessHandle, MODULE_INFO *Entries, SIZE_T NumOfEntries, PSIZE_T RealNumOfEntries) { BOOL result; HMODULE *modules; DWORD needSize; SIZE_T moduleOffset = 0; SIZE_T moduleCounter = 0; if (!RealNumOfEntries) { return FALSE; } modules = (HMODULE*)AllocMem(sizeof(HMODULE) * NumOfEntries); if (!modules) { return FALSE; } result = EnumProcessModulesEx(ProcessHandle, modules, (DWORD)(sizeof(HMODULE) * NumOfEntries), &needSize, LIST_MODULES_ALL); if (!result) { DeallocMem(modules); return FALSE; } *RealNumOfEntries = needSize / sizeof(HMODULE); do { result = FALSE; moduleCounter++; if (moduleOffset >= NumOfEntries) { continue; } Entries[moduleOffset].ModuleHandle = modules[moduleOffset]; GetModuleFileNameEx(ProcessHandle, modules[moduleOffset], Entries[moduleOffset].ModulePath, MAX_PATH); GetShortFileName(Entries[moduleOffset].ModulePath, Entries[moduleOffset].ModuleName, MAX_PATH); result = moduleCounter < (*RealNumOfEntries); moduleOffset++; } while (result); DeallocMem(modules); *RealNumOfEntries = moduleCounter; if (moduleCounter > NumOfEntries) { return FALSE; } return TRUE; }
//=========================================================================== //=========================================================================== //=========================================================================== //=========================================================================== void AddNewFileToMainMenu(TPopupMenu *PopupMenu, AnsiString FileName, TNotifyEvent NotifyEvent) { TRegistry *Reg = new TRegistry; bool FirstInput = false; bool FileExist = false; int Counter = 0; int posFileNameInMenu = -1; AnsiString appName = ExtractFileName(Application->ExeName); appName.SetLength(appName.Length() - 4); try { Reg->RootKey = HKEY_LOCAL_MACHINE; /// ---- Находитться в Uses Windows Reg->OpenKey("Software\\Digital Systems & Technologies\\" + appName, true); //create a new key >> .ext //------------------- if (FileName == "Load") { for ( int i = 0; i < CountFileName; i++){ FileNameStackArray[i] = ""; FileNameStackArray[i] = Reg->ReadString("FileName"+IntToStr(i+1)); if (FileNameStackArray[i] != "") { Counter = Counter + 1; addMenuItem (Counter, PopupMenu, "&"+IntToStr(Counter) + ". " + GetShortFileName(FileNameStackArray[i]), NotifyEvent); FirstInput = true; } } if (FirstInput) addMenuItem (Counter + 1,PopupMenu,"-", NULL); } else { // --- Проверка на повтор файла ----------- for ( int i = 0; i < CountFileName; i++) if (FileName == FileNameStackArray[i]) { FileExist = true; FileNameStackArray[i] = ""; posFileNameInMenu = i; } // -------- Если файл уже существует то удаляем его из списка, сортируем список if (FileExist) { for ( int i = posFileNameInMenu; i < CountFileName - 1; i++ ) { FileNameStackArray[i] = FileNameStackArray[i+1]; } FileNameStackArray[CountFileName - 1] = ""; } // ----- Добавляем в "Стек" --------- for ( int i = CountFileName - 1; i > 0; i--) if (FileNameStackArray[i-1].data() != NULL) FileNameStackArray[i] = FileNameStackArray[i-1]; FileNameStackArray[0] = FileName; // ---- Удаляю все файлы с менюхи --------- for ( int i = PopupMenu->Items->Count-1; i >= 0; i--) if (PopupMenu->Items->Items[i]->Name[1] == 'F') delete PopupMenu->Items->Items[i]; // ---- Добавляю новые файлы в менюху ------ Counter = 0; for ( int i = 0; i < CountFileName - 1; i++ ) { if (FileNameStackArray[i] != "") { Counter = Counter + 1; addMenuItem (Counter, PopupMenu, "&" + IntToStr(Counter) + ". " + GetShortFileName(FileNameStackArray[i]), NotifyEvent); } } // ---- Добавляю черту ------ addMenuItem (Counter + 1,PopupMenu,"-", NULL); } // ---- Записываю в Реестр ------- for ( int i = 0; i < CountFileName; i++) Reg->WriteString("FileName" + IntToStr(i+1), FileNameStackArray[i]); //------------------- Reg->CloseKey(); } __finally { delete Reg; } }