Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "main.h"
- int main(int argc, char *argv[])
- {
- if (argc != 2)
- {
- printf("Useage: CaptMicroSteamFriendsLockTest.exe [your_id]\n");
- return 1;
- }
- BYTE issf = IsSteamFriend(argv[1], "captmicro");
- if (issf == 0) MessageBoxA(0, "You are friends with Capt. Micro\n", 0, 0);
- else MessageBoxA(0, "You are NOT friends with Capt. Micro\n", 0, 0);
- return 0;
- }
- BYTE IsSteamFriend(char *id1, char *id2)
- {
- _URLDownloadToCacheFileA URL_D2CFA = NULL;
- HMODULE urlmon = LoadLibraryA("urlmon.dll");
- if (urlmon == NULL) return 2;
- URL_D2CFA = (_URLDownloadToCacheFileA)GetProcAddress(urlmon, "URLDownloadToCacheFileA");
- if (URL_D2CFA == NULL) return 3;
- char *url = NULL;
- url = (char*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 7+22+lstrlenA(id1)+8+10);
- lstrcpyA(url, "http://"); lstrcatA(url, "steamcommunity.com/id/");
- lstrcatA(url, id1); lstrcatA(url, "/friends");
- char *cfile = NULL;
- cfile = (char*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, MAX_PATH+10);
- if (cfile == NULL)
- {
- HeapFree(GetProcessHeap(), 0, cfile);
- HeapFree(GetProcessHeap(), 0, url);
- return 4;
- }
- HRESULT dres = URL_D2CFA(NULL, url, cfile, MAX_PATH, 0, NULL);
- if (dres != S_OK || FAILED(dres))
- {
- HeapFree(GetProcessHeap(), 0, cfile);
- HeapFree(GetProcessHeap(), 0, url);
- return 5;
- } HeapFree(GetProcessHeap(), 0, url);
- DWORD attr = GetFileAttributesA(cfile);
- if (attr == INVALID_FILE_ATTRIBUTES) { HeapFree(GetProcessHeap(), 0, cfile); return 6; }
- HANDLE file = CreateFileA(cfile, FILE_GENERIC_READ, FILE_SHARE_READ,
- NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
- HeapFree(GetProcessHeap(), 0, cfile);
- if (file == NULL && GetLastError() == ERROR_FILE_NOT_FOUND) return 7;
- DWORD size = GetFileSize(file, NULL);
- if (size == 0) { CloseHandle(file); return 8; }
- char *data = NULL; DWORD bytesRead = 0;
- data = (char*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size+10);
- BOOL rfret = ReadFile(file, data, size, &bytesRead, NULL);
- if (rfret == FALSE) { HeapFree(GetProcessHeap(), 0, data); CloseHandle(file); return 9; }
- if (lstrlenA(data) == 0) { HeapFree(GetProcessHeap(), 0, data); CloseHandle(file); return 10; }
- char *findstr = NULL;
- findstr = (char*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 7+22+lstrlenA(id2)+10);
- if (findstr == NULL) { HeapFree(GetProcessHeap(), 0, data); CloseHandle(file); return 11; }
- lstrcpyA(url, "http://"); lstrcatA(url, "steamcommunity.com/id/"); lstrcatA(url, id2);
- char *sfound = _IsSteamFriend_strstr(data, findstr);
- HeapFree(GetProcessHeap(), 0, findstr);
- if (sfound == 0) { HeapFree(GetProcessHeap(), 0, data); CloseHandle(file); return 12; }
- else { HeapFree(GetProcessHeap(), 0, data); CloseHandle(file); return 0; }
- HeapFree(GetProcessHeap(), 0, data);
- CloseHandle(file);
- return 1;
- }
- char *_IsSteamFriend_strchr(char *s, char c)
- {
- char *ptr = s;
- while (*ptr != 0 && *ptr != c) ptr++;
- return ((*ptr == c) ? ptr : 0);
- }
- int _IsSteamFriend_strncmp(char *s1, char *s2, unsigned long n)
- {
- char *str1 = s1; char *str2 = s2;
- if (n == 0) return 0;
- while (n-- > 0 && *str1 == *str2)
- { if (n == 0 || *s1 == 0) return 0; str1++; str2++; }
- unsigned char u1 = (*(unsigned char*)str1);
- unsigned char u2 = (*(unsigned char*)str2);
- return ((u1 < u2) ? -1 : (u1 > u2));
- }
- char *_IsSteamFriend_strstr(char *h, char *n)
- {
- char *haystack = h; char *needle = n;
- if (*needle == 0) return haystack;
- unsigned long nlen = 0; nlen = lstrlenA(needle);
- for (; (haystack =_IsSteamFriend_strchr(haystack, *needle)) != 0; haystack++)
- if (_IsSteamFriend_strncmp(haystack, needle, nlen) == 0)
- return haystack;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement