Advertisement
captmicro

Unknown

Oct 23rd, 2010
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.61 KB | None | 0 0
  1. #include "main.h"
  2.  
  3. int main(int argc, char *argv[])
  4. {
  5.     if (argc != 2)
  6.     {
  7.         printf("Useage: CaptMicroSteamFriendsLockTest.exe [your_id]\n");
  8.         return 1;
  9.     }
  10.  
  11.     BYTE issf = IsSteamFriend(argv[1], "captmicro");
  12.     if (issf == 0) MessageBoxA(0, "You are friends with Capt. Micro\n", 0, 0);
  13.     else MessageBoxA(0, "You are NOT friends with Capt. Micro\n", 0, 0);
  14.  
  15.     return 0;
  16. }
  17.  
  18. BYTE IsSteamFriend(char *id1, char *id2)
  19. {
  20.     _URLDownloadToCacheFileA URL_D2CFA = NULL;
  21.     HMODULE urlmon = LoadLibraryA("urlmon.dll");
  22.     if (urlmon == NULL) return 2;
  23.     URL_D2CFA = (_URLDownloadToCacheFileA)GetProcAddress(urlmon, "URLDownloadToCacheFileA");
  24.     if (URL_D2CFA == NULL) return 3;
  25.  
  26.     char *url = NULL;
  27.     url = (char*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 7+22+lstrlenA(id1)+8+10);
  28.     lstrcpyA(url, "http://"); lstrcatA(url, "steamcommunity.com/id/");
  29.     lstrcatA(url, id1); lstrcatA(url, "/friends");
  30.  
  31.     char *cfile = NULL;
  32.     cfile = (char*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, MAX_PATH+10);
  33.     if (cfile == NULL)
  34.     {
  35.         HeapFree(GetProcessHeap(), 0, cfile);
  36.         HeapFree(GetProcessHeap(), 0, url);
  37.         return 4;
  38.     }
  39.  
  40.     HRESULT dres = URL_D2CFA(NULL, url, cfile, MAX_PATH, 0, NULL);
  41.     if (dres != S_OK || FAILED(dres))
  42.     {
  43.         HeapFree(GetProcessHeap(), 0, cfile);
  44.         HeapFree(GetProcessHeap(), 0, url);
  45.         return 5;
  46.     } HeapFree(GetProcessHeap(), 0, url);
  47.  
  48.     DWORD attr = GetFileAttributesA(cfile);
  49.     if (attr == INVALID_FILE_ATTRIBUTES) { HeapFree(GetProcessHeap(), 0, cfile); return 6; }
  50.  
  51.     HANDLE file = CreateFileA(cfile, FILE_GENERIC_READ, FILE_SHARE_READ,
  52.         NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  53.     HeapFree(GetProcessHeap(), 0, cfile);
  54.     if (file == NULL && GetLastError() == ERROR_FILE_NOT_FOUND) return 7;
  55.  
  56.     DWORD size = GetFileSize(file, NULL);
  57.     if (size == 0) { CloseHandle(file); return 8; }
  58.  
  59.     char *data = NULL; DWORD bytesRead = 0;
  60.     data = (char*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size+10);
  61.     BOOL rfret = ReadFile(file, data, size, &bytesRead, NULL);
  62.     if (rfret == FALSE) { HeapFree(GetProcessHeap(), 0, data); CloseHandle(file); return 9; }
  63.     if (lstrlenA(data) == 0) { HeapFree(GetProcessHeap(), 0, data); CloseHandle(file); return 10; }
  64.  
  65.     char *findstr = NULL;
  66.     findstr = (char*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 7+22+lstrlenA(id2)+10);
  67.     if (findstr == NULL) { HeapFree(GetProcessHeap(), 0, data); CloseHandle(file); return 11; }
  68.     lstrcpyA(url, "http://"); lstrcatA(url, "steamcommunity.com/id/"); lstrcatA(url, id2);
  69.  
  70.     char *sfound = _IsSteamFriend_strstr(data, findstr);
  71.     HeapFree(GetProcessHeap(), 0, findstr);
  72.     if (sfound == 0) { HeapFree(GetProcessHeap(), 0, data); CloseHandle(file); return 12; }
  73.     else { HeapFree(GetProcessHeap(), 0, data); CloseHandle(file); return 0; }
  74.  
  75.     HeapFree(GetProcessHeap(), 0, data);
  76.     CloseHandle(file);
  77.     return 1;
  78. }
  79. char *_IsSteamFriend_strchr(char *s, char c)
  80. {
  81.     char *ptr = s;
  82.     while (*ptr != 0 && *ptr != c) ptr++;
  83.     return ((*ptr == c) ? ptr : 0);
  84. }
  85. int _IsSteamFriend_strncmp(char *s1, char *s2, unsigned long n)
  86. {
  87.     char *str1 = s1; char *str2 = s2;
  88.     if (n == 0) return 0;
  89.     while (n-- > 0 && *str1 == *str2)
  90.         { if (n == 0 || *s1 == 0) return 0; str1++; str2++; }
  91.     unsigned char u1 = (*(unsigned char*)str1);
  92.     unsigned char u2 = (*(unsigned char*)str2);
  93.     return ((u1 < u2) ? -1 : (u1 > u2));
  94. }
  95. char *_IsSteamFriend_strstr(char *h, char *n)
  96. {
  97.     char *haystack = h; char *needle = n;
  98.     if (*needle == 0) return haystack;
  99.     unsigned long nlen = 0; nlen = lstrlenA(needle);
  100.     for (; (haystack =_IsSteamFriend_strchr(haystack, *needle)) != 0; haystack++)
  101.         if (_IsSteamFriend_strncmp(haystack, needle, nlen) == 0)
  102.             return haystack;
  103.     return 0;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement