├── ADEGrab.rc ├── adegrab.ico ├── resource.h ├── adegrab.h ├── .gitignore ├── ADEGrab.sln ├── ADEGrab.vcxproj.filters ├── ADEGrab.vcxproj ├── README.md ├── adegrab.c └── LICENSE /ADEGrab.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stufus/ADEGrab/HEAD/ADEGrab.rc -------------------------------------------------------------------------------- /adegrab.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stufus/ADEGrab/HEAD/adegrab.ico -------------------------------------------------------------------------------- /resource.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stufus/ADEGrab/HEAD/resource.h -------------------------------------------------------------------------------- /adegrab.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "resource.h" 7 | 8 | #define CM_TRAY WM_USER+3 9 | #define ADEGRAB_IDENTIFIER TEXT("ADEGrab v1.0") 10 | #define MAX_BUFFER_SIZE 250 11 | 12 | typedef struct _ADMemInject { 13 | LVITEM li; 14 | TCHAR buffer[MAX_BUFFER_SIZE + 1]; 15 | } ADMemInject; 16 | 17 | #define NTDDI_VERSION NTDDI_WIN2K 18 | #define NTDDI_VERSION NTDDI_WINXP 19 | #define NTDDI_VERSION NTDDI_VISTA -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | *.obj 5 | *.elf 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Libraries 12 | *.lib 13 | *.a 14 | *.la 15 | *.lo 16 | 17 | # Shared objects (inc. Windows DLLs) 18 | *.dll 19 | *.so 20 | *.so.* 21 | *.dylib 22 | 23 | # Executables 24 | *.exe 25 | *.out 26 | *.app 27 | *.i*86 28 | *.x86_64 29 | *.hex 30 | 31 | # Debug files 32 | *.dSYM/ 33 | 34 | Debug/* 35 | Release/* 36 | *.log 37 | *.aps 38 | *.exe 39 | *.idb 40 | *.ipch 41 | *.lib 42 | *.obj 43 | *.sdf 44 | *.suo 45 | *.tlog 46 | 47 | *.user 48 | -------------------------------------------------------------------------------- /ADEGrab.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.31101.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ADEGrab", "ADEGrab.vcxproj", "{34DFD355-8C40-40C2-9B08-D568068532D0}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {34DFD355-8C40-40C2-9B08-D568068532D0}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {34DFD355-8C40-40C2-9B08-D568068532D0}.Debug|Win32.Build.0 = Debug|Win32 16 | {34DFD355-8C40-40C2-9B08-D568068532D0}.Release|Win32.ActiveCfg = Release|Win32 17 | {34DFD355-8C40-40C2-9B08-D568068532D0}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /ADEGrab.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | 26 | 27 | Resource Files 28 | 29 | 30 | 31 | 32 | Resource Files 33 | 34 | 35 | 36 | 37 | Source Files 38 | 39 | 40 | -------------------------------------------------------------------------------- /ADEGrab.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {34DFD355-8C40-40C2-9B08-D568068532D0} 15 | ADEGrab 16 | 17 | 18 | 19 | Application 20 | true 21 | v120 22 | Unicode 23 | 24 | 25 | Application 26 | false 27 | v120 28 | true 29 | Unicode 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | Level3 45 | Disabled 46 | true 47 | 48 | 49 | true 50 | 51 | 52 | 53 | 54 | Level3 55 | MaxSpeed 56 | true 57 | true 58 | true 59 | 60 | 61 | true 62 | true 63 | true 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ADEGrab 2 | Anyone who has used the Sysinternals AD Explorer tool will know that it is very useful, especially for rapid offline analysis of an AD structure which, for example, has been acquired during a penetration test in order to gain situational awareness. 3 | 4 | One of the unfortunate limitations of AD Explorer is that you cannot copy/paste or select the results from the Search Container. ADEGrab circumvents this problem by reading the contents of the ListView control and copying to clipboard or saving to a file, which should allow testers to parse this information or use it as part of other tools. 5 | 6 | # Internals 7 | Initially, I wrote a DLL to hook the windows messages to AD Explorer's ListView control; my plan was simply to intercept the LVM_INSERTITEM message and read the lParam->pszText item in the LVITEM struct. However, it seems that they chose to set pszText to LPSTR_TEXTCALLBACK and use notify messages to actually set the text. It would be more complicated to hook those messages because it would involve intercepting WM_NOTIFY messages, identifying LVN_GETDISPINFO requests and intercepting the responses. 8 | 9 | A simpler method is to send windows messages such as LVM_GETITEM to the ListView control in order to extract the data, column by column. However, processes cannot write to other process' memory, meaning that it was not as simple as simply sending LVM_GETITEM. The way that I chose to deal with this is to read and write directly from AD Explorer's memory. 10 | 11 | When attempting to capture the listbox contents, ADEGrab: 12 | 13 | 1. Attempts to retrieve a handle to the Search Container SysListView32 control (i.e. the results list). 14 | 2. Retrieve a couple of handles (thread and process) of the instance of AD Explorer that owns the control above and gain read/write access to the process. 15 | 3. Sends the LVM_GETITEMCOUNT message to the ListView control to retrieve the number of items in the list. 16 | 4. Calculate the amount of buffer space needed to store everything. On the assumption that each 'cell' will be no more than 250 characters in length, calculate 2*(number+2). The +2 is for the \r\n linefeed characters, and the multiplication by 2 is because we are retrieving Unicode characters. 17 | 5. Working on the same assumption that we are going to retrieve a maximum of 250 characters on each cell, allocate a block of memory to store a LVITEM struct with a (250*2)+1 byte buffer below it. 250*2 because it is unicode, and the +1 for the null terminator. In order to keep this simple, I created a struct called ADMemInject that has two items; an LVITEM and a suitably sized TCHAR buffer. 18 | 19 | The reason for this is the way that interacting with ListView controls actually works. In order to retrieve an item from a ListView control, you need to send it an LVM_GETITEM message, with lParam pointing to an LVITEM struct that contains details on which item to receive. The key component here is the iItem variable, which is the zero-indexed item position to receive. When the ListView receives that message, it will go to the cell at the iItem'th position and, providing the flags such as mask are set correctly, it will copy the text into the buffer that pszText points to. 20 | However, processes cannot usually access memory belonging to other processes, so you cannot simply create a buffer using malloc/calloc or similar, because that would be created inside ADEGrab's process. I therefore used VirtualAlloc to create a block of memory inside AD Explorer's process (that's why #2 was necessary), copied the ADMemInject struct into it and made sure that the pszText parameter pointed to the block of memory immediately after the struct. The idea is that the ListView control will read the struct and copy the item's text to the memory directly 'after' the LVITEM struct itself. 21 | 22 | 6. Copy the local variable to AD Explorer's buffer and send the LVM_GETITEM message. This will cause AD Explorer's ListView to write the cell contents to its own buffer, which is allowed. 23 | 7. Read that block of memory back into ADEGrab's process. This will always be safe because we allocated the memory block; it gave us a virtual memory address inside AD Explorer's process, so we can safely interact with it as much as we like until we release the handle or AD Explorer closes. 24 | 8. Append the text to the complete buffer, with the terminating \r\n. 25 | 26 | Once each item has been retrieved from the ListView control, the handles are closed and the relevant memory freed. We now have a large Unicode buffer with a newline-separated list of every item that has been retrieved from the ListView control. ADEGrab now performs two optional activities. 27 | 28 | 1. If the Clipboard menu option is ticked, ADEGrab converts the buffer to ANSI and copies it to clipboard. 29 | 2. If the Log File menu option is ticked, ADEGrab opens "adegrab.log" and appends the ANSI buffer to it. 30 | 31 | It then displays a balloon tip (in the system tray) to the user, informing them of the captured data. 32 | 33 | # Usage 34 | - Load AD Explorer and connect to the domain that you wish to browse. 35 | - Load the 'Search Container' (i.e. Search for something). 36 | - Execute ADEGrab. If you minimise it, it will go to the tray. 37 | - Double-click the tray icon, right-click the tray icon and select 'Capture' or press the 'Capture' button on the GUI. ADEGrab will retrieve the first column of the Search results and display it on the main GUI. If 'Capture to Clipboard' is selected, ADEGrab will convert the results from Unicode to ANSI and save them to the clipboard. 38 | - If 'Capture to Log File' is selected, ADEGrab will convert the results from Unicode to ANSI and append them to 'adegrab.log'. 39 | 40 | Primarily, I use it by minimising ADEGrab to the tray, double-clicking it whenever I want to save the results and then pasting into whatever file I want. This works across VMs (tested on VirtualBox) as long as VirtualBox tools are installed and Clipboard is set to bidirectional. 41 | 42 | Note that ADEGrab opens and closes all handles on each capture attempt. This means that it does not matter whether you load ADEGrab first, or AD Explorer first, or whether you close or open them. 43 | 44 | # Downloads 45 | 46 | AD Explorer v1.44 can be downloaded at https://download.sysinternals.com/files/AdExplorer.zip 47 | Homepage: https://technet.microsoft.com/en-GB/sysinternals/bb963907.aspx 48 | 49 | The ADEGrab binary can be downloaded at https://github.com/stufus/ADEGrab/releases/download/v1.00/ADEGrab.zip. Grab the source, check it and recompile it if you are worried about executing an untrusted binary. 50 | SHA256 (ADEGrab.zip) = 6860b91288eb796a2721b66158cfa668f4f108cac0faa3e5e00a35012a05f3fb 51 | SHA512 (ADEGrab.zip) = 5636d84e608e9e90986b43d740fe043bea6223cce02aedd1927353f946e9600419e3d42f3de5bc8673618ec60038e7d 52 | 53 | # Building 54 | 55 | If you want to compile and run it yourself, just open ADEGrab.sln in Visual Studio 2013 (I used VS2013 Community Edition). You will need to ensure that it is compiled using Unicode rather than ANSI (it will compile but not function correctly in ANSI mode because AD Explorer is Unicode). For those old-timers out there, this is oldschool C (ish) code; no .NET in sight. I've nothing against C# by the way; I'm just not a C# coder and there is something I like about C and Win32 APIs. 56 | 57 | There are a whole bunch of compiler warnings, mainly because I have not casted variables properly. This is because this started as a quick and dirty project. 58 | 59 | # Further Development 60 | 61 | Additional functionality that I will stabilise and release will include: 62 | - Optionally grab all columns from the Search Container. 63 | - Optionally choose the output file. 64 | - Fix the compiler warnings. 65 | 66 | # Disclaimer 67 | 68 | This was a tool that I put together in an evening in order to solve a problem. It has not been thoroughly tested against every possible scenario, but is a handy tool if you are in this position. 69 | 70 | # Further Reading 71 | 72 | https://labs.mwrinfosecurity.com/blog/memory-allocation-how-injecting-into-your-own-tools-might-help-you-compromise-a-windows-domain/ 73 | -------------------------------------------------------------------------------- /adegrab.c: -------------------------------------------------------------------------------- 1 | #include "adegrab.h" 2 | 3 | NOTIFYICONDATA ico = { 0 }; 4 | HINSTANCE hInstance; 5 | HMENU popup, popup_sub; 6 | 7 | void addLog(HWND hDlg, TCHAR *message) { 8 | SYSTEMTIME lt; 9 | TCHAR buf[400] = { 0 }; 10 | 11 | GetLocalTime(<); 12 | StringCbPrintf((STRSAFE_LPSTR) &buf, 400, TEXT("[%02d/%02d/%02d %02d:%02d:%02d.%d] %s"), lt.wDay, lt.wMonth, lt.wYear, lt.wHour, lt.wMinute, lt.wSecond, lt.wMilliseconds, message); 13 | SendDlgItemMessage(hDlg, LIST_LOG, LB_ADDSTRING, 0, (LPARAM)&buf); 14 | } 15 | 16 | void trayIcon(HWND hDlg) { 17 | ico.cbSize = sizeof(NOTIFYICONDATA); 18 | ico.uID = 0; 19 | ico.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; 20 | StringCchCopy(ico.szTip, ARRAYSIZE(ico.szTip), ADEGRAB_IDENTIFIER); 21 | ico.hWnd = hDlg; 22 | ico.uCallbackMessage = CM_TRAY; 23 | ico.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(ICO_MAINICON)); 24 | Shell_NotifyIcon(NIM_ADD, &ico); 25 | } 26 | 27 | void trayMessage(HWND hDlg, TCHAR *title, TCHAR *msg) { 28 | NOTIFYICONDATA ni = { 0 }; 29 | ni.cbSize = sizeof(NOTIFYICONDATA); 30 | ni.uID = 0; 31 | ni.hWnd = hDlg; 32 | ni.uFlags = NIF_INFO; 33 | StringCchCopy(ni.szInfo, ARRAYSIZE(ni.szInfo), msg); 34 | StringCchCopy(ni.szInfoTitle, ARRAYSIZE(ni.szInfoTitle), title); 35 | ni.uCallbackMessage = CM_TRAY; 36 | ni.dwInfoFlags = NIIF_INFO; 37 | ni.uTimeout = 5; 38 | Shell_NotifyIcon(NIM_MODIFY, &ni); 39 | } 40 | 41 | void performADExplorerCapture(HWND hDlg, HMENU menu) { 42 | MENUITEMINFO mi = { 0 }; 43 | HANDLE hFile; 44 | TCHAR log[300]; 45 | DWORD dwWritten; 46 | 47 | HWND ADExplorer; 48 | HWND ADExplorerListView; 49 | int counter; 50 | int itemCount; 51 | int maxchars; 52 | ADMemInject LVQuery; 53 | DWORD processId; 54 | DWORD threadId; 55 | HGLOBAL hClipboardMem; 56 | 57 | HANDLE remoteProcess; 58 | DWORD remoteMemory; 59 | DWORD err; 60 | 61 | TCHAR *completebuffer_unicode = NULL; 62 | int cbansi_size = NULL; 63 | char *completebuffer_ansi = NULL; 64 | 65 | mi.cbSize = sizeof(MENUITEMINFO); 66 | mi.fMask = MIIM_STATE; 67 | 68 | // Retrieve the encompassing window 69 | if (ADExplorer = FindWindowExW(NULL, NULL, TEXT("#32770"), TEXT("Search Container"))) { 70 | 71 | // Now retrieve the handle of the specific listview 72 | if (ADExplorerListView = FindWindowExW(ADExplorer, NULL, TEXT("SysListView32"), TEXT("List1"))) { 73 | 74 | // Update log 75 | StringCbPrintf((STRSAFE_LPWSTR) &log, 300, TEXT("Found AD Explorer listbox (Handle: %d)."), ADExplorerListView); 76 | addLog(hDlg, (TCHAR *) &log); 77 | 78 | // Now get the process Id and thread ID of the AD Explorer process 79 | if (threadId = GetWindowThreadProcessId(ADExplorerListView, &processId)) { 80 | 81 | // Obtain privileges that we will need to write to its memory 82 | if (remoteProcess = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE, FALSE, processId)) { 83 | 84 | StringCbPrintf(&log, 300, TEXT("Opened AD Explorer process (Handle: %d)."), remoteProcess); 85 | addLog(hDlg, (TCHAR *) &log); 86 | 87 | // Make sure there are some items in the listview 88 | if (itemCount = ListView_GetItemCount(ADExplorerListView)) { 89 | 90 | StringCbPrintf(&log, 300, TEXT("Found %d item(s)."), itemCount); 91 | addLog(hDlg, (TCHAR *) &log); 92 | 93 | // Allocate the main buffer which is (num_items * max size) + \r\n 94 | maxchars = 2 + (itemCount*MAX_BUFFER_SIZE); 95 | completebuffer_unicode = calloc(sizeof(TCHAR), maxchars); 96 | 97 | StringCbPrintf(&log, 300, TEXT("Temporary buffer is %d char(s) (%d byte(s))."), maxchars, sizeof(TCHAR)*maxchars); 98 | addLog(hDlg, (TCHAR *) &log); 99 | 100 | // Allocate memory in remote process in the format [LVITEM][TCHAR String][NULL] 101 | remoteMemory = (DWORD)VirtualAllocEx(remoteProcess, NULL, sizeof(LVQuery), MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); 102 | 103 | for (counter = 0; counter < itemCount; counter++) { 104 | 105 | // Loop through the items retrieving each one. Note that we explicitly clear the memory between 106 | // each iteration because LVM_GETITEM updates the struct and it is cleaner to start with a "blank" one each time. 107 | // Fill in the local listitem struct to perform the query 108 | SecureZeroMemory((PVOID)&LVQuery, sizeof(LVQuery)); 109 | LVQuery.li.cchTextMax = MAX_BUFFER_SIZE; 110 | LVQuery.li.pszText = (LPWSTR)remoteMemory + sizeof(LVQuery.li); 111 | LVQuery.li.mask = LVIF_TEXT | LVIF_COLUMNS; 112 | LVQuery.li.iSubItem = 0; 113 | LVQuery.li.iItem = counter; 114 | 115 | // Write the listitem struct to AD Explorer's memory 116 | WriteProcessMemory(remoteProcess, (LPVOID)remoteMemory, &LVQuery, sizeof(LVQuery), NULL); 117 | 118 | // Request the text from the ListView control 119 | SendMessage(ADExplorerListView, LVM_GETITEM, NULL, remoteMemory); 120 | 121 | // Read from the process - retrieve the initial LVITEM and then retrieve the buffer 122 | // It is necessary to do this twice because there is no guarantee that the result is written to the buffer that we offered 123 | ReadProcessMemory(remoteProcess, (LPVOID)remoteMemory, &(LVQuery.li), sizeof(LVQuery.li), NULL); 124 | ReadProcessMemory(remoteProcess, (LPVOID)LVQuery.li.pszText, &(LVQuery.buffer), sizeof(LVQuery.buffer), NULL); 125 | 126 | // Add the string to the main buffer 127 | if (strlen(LVQuery.buffer)) { 128 | StringCbCat(completebuffer_unicode, maxchars, LVQuery.buffer); 129 | StringCbCat(completebuffer_unicode, maxchars, TEXT("\r\n")); 130 | } 131 | 132 | } 133 | 134 | // Set the "console" box with the final string 135 | SetDlgItemText(hDlg, EDIT_CAPTURED, completebuffer_unicode); 136 | 137 | // Only do the processing below if there was actually an item 138 | if (itemCount) { 139 | 140 | // Display the balloon tip 141 | StringCbPrintf(&log, 300, TEXT("Captured %d result(s) from AD Explorer."), itemCount); 142 | trayMessage(hDlg, ADEGRAB_IDENTIFIER, &log); 143 | 144 | // Convert to ANSI from Unicode 145 | cbansi_size = WideCharToMultiByte(CP_UTF8, NULL, completebuffer_unicode, -1, completebuffer_ansi, 0, NULL, NULL); 146 | completebuffer_ansi = calloc(sizeof(CHAR), cbansi_size); 147 | if (cbansi_size && WideCharToMultiByte(CP_UTF8, NULL, completebuffer_unicode, -1, completebuffer_ansi, cbansi_size, NULL, NULL)) { 148 | StringCbPrintf(&log, 300, TEXT("Converted %d characters to ANSI (multibyte) from Unicode."), cbansi_size); 149 | addLog(hDlg, (TCHAR *) &log); 150 | } 151 | 152 | // Write to clipboard? 153 | GetMenuItemInfo(menu, MAKEINTRESOURCE(ID_ADEGRAB_CAPTURETOCLIPBOARD), FALSE, &mi); 154 | if (mi.fState & MFS_CHECKED) { 155 | hClipboardMem = GlobalAlloc(GMEM_MOVEABLE, cbansi_size); 156 | memcpy(GlobalLock(hClipboardMem), completebuffer_ansi, cbansi_size); 157 | GlobalUnlock(hClipboardMem); 158 | OpenClipboard(hDlg); 159 | EmptyClipboard(); 160 | if (SetClipboardData(CF_TEXT, hClipboardMem)) { 161 | StringCbPrintf(&log, 300, TEXT("Written %d characters to clipboard."), cbansi_size); 162 | addLog(hDlg, (TCHAR *) &log); 163 | } 164 | CloseClipboard(); 165 | } 166 | 167 | // Save to file? 168 | GetMenuItemInfo(menu, MAKEINTRESOURCE(ID_ADEGRAB_CAPTURETOLOGFILE), FALSE, &mi); 169 | if (mi.fState & MFS_CHECKED) { 170 | if (hFile = CreateFile(TEXT("adegrab.log"), FILE_GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)) { 171 | SetFilePointer(hFile, 0, NULL, FILE_END); 172 | WriteFile(hFile, completebuffer_ansi, cbansi_size-1, &dwWritten, NULL); 173 | StringCbPrintf(&log, 300, TEXT("Written %d byte(s) to output file."), dwWritten); 174 | CloseHandle(hFile); 175 | } 176 | else { 177 | StringCbPrintf(&log, 300, TEXT("Unable to open output file (Error %d)."), GetLastError()); 178 | } 179 | addLog(hDlg, (TCHAR *) &log); 180 | } 181 | 182 | } 183 | 184 | // Clean up 185 | free(completebuffer_ansi); 186 | free(completebuffer_unicode); 187 | VirtualFreeEx(remoteProcess, (LPVOID)remoteMemory, (SIZE_T) NULL, MEM_RELEASE); 188 | CloseHandle(remoteProcess); 189 | } 190 | 191 | } 192 | } 193 | } else { 194 | addLog(hDlg, TEXT("Unable to find ListView handle inside Search Container window.")); 195 | } 196 | } else { 197 | addLog(hDlg, TEXT("Unable to find Search Container window.")); 198 | } 199 | 200 | } 201 | 202 | // Message loop for main box 203 | int CALLBACK mainDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { 204 | POINT coords = { 0 }; 205 | MENUITEMINFO mi = { 0 }; 206 | 207 | switch (msg) { 208 | 209 | case WM_COMMAND: 210 | switch (LOWORD(wParam)) { 211 | 212 | // Buttons 213 | case BTN_CAPTURE: 214 | performADExplorerCapture(hDlg, popup); 215 | break; 216 | 217 | case BTN_QUIT: 218 | SendMessage(hDlg, WM_DESTROY, NULL, NULL); 219 | break; 220 | 221 | // Menu options 222 | case ID_ADEGRAB_RESTORE: 223 | SendMessage(hDlg, WM_SYSCOMMAND, SC_RESTORE, NULL); 224 | break; 225 | 226 | case ID_ADEGRAB_EXIT: 227 | SendMessage(hDlg, WM_DESTROY, NULL, NULL); 228 | break; 229 | 230 | case ID_ADEGRAB_CAPTURE: 231 | performADExplorerCapture(hDlg, popup); 232 | break; 233 | 234 | case ID_ADEGRAB_CAPTURETOCLIPBOARD: 235 | case ID_ADEGRAB_CAPTURETOLOGFILE: 236 | mi.cbSize = sizeof(MENUITEMINFO); 237 | mi.fMask = MIIM_STATE; 238 | GetMenuItemInfo(popup, LOWORD(wParam), FALSE, &mi); 239 | if (mi.fState & MFS_CHECKED) { 240 | mi.fState &= ~MFS_CHECKED; 241 | } else if (!(mi.fState & MFS_CHECKED)) { 242 | mi.fState |= MFS_CHECKED; 243 | } 244 | SetMenuItemInfo(popup, LOWORD(wParam), FALSE, &mi); 245 | break; 246 | 247 | default: 248 | return FALSE; 249 | } 250 | break; 251 | 252 | case WM_SYSCOMMAND: 253 | switch (wParam) { 254 | case SC_MINIMIZE: 255 | ShowWindow(hDlg, SW_HIDE); 256 | break; 257 | case SC_RESTORE: 258 | ShowWindow(hDlg, SW_SHOW); 259 | break; 260 | default: 261 | return FALSE; 262 | } 263 | break; 264 | 265 | case WM_CLOSE: 266 | SendMessage(hDlg, WM_DESTROY, NULL, NULL); 267 | break; 268 | 269 | case WM_DESTROY: 270 | Shell_NotifyIcon(NIM_DELETE, &ico); 271 | DestroyMenu(popup); 272 | EndDialog(hDlg, NULL); 273 | break; 274 | 275 | case WM_INITDIALOG: 276 | popup = LoadMenu(hInstance, MAKEINTRESOURCE(MNU_MAIN)); 277 | popup_sub = GetSubMenu(popup, 0); 278 | trayIcon(hDlg); 279 | SetMenu(hDlg, popup); 280 | ShowWindow(hDlg, SW_SHOWNORMAL); 281 | addLog(hDlg, ADEGRAB_IDENTIFIER); 282 | break; 283 | 284 | case CM_TRAY: 285 | if (wParam == 0) { 286 | switch (lParam) { 287 | case WM_LBUTTONDBLCLK: 288 | performADExplorerCapture(hDlg, popup); 289 | break; 290 | 291 | case WM_RBUTTONUP: 292 | GetCursorPos(&coords); 293 | SetForegroundWindow(hDlg); 294 | TrackPopupMenuEx(popup_sub, TPM_RIGHTALIGN, coords.x, coords.y, hDlg, NULL); 295 | PostMessage(hDlg, WM_NULL, NULL, NULL); 296 | break; 297 | } 298 | } 299 | break; 300 | 301 | default: 302 | return FALSE; 303 | break; 304 | } 305 | 306 | return TRUE; 307 | } 308 | 309 | // Entrypoint 310 | int APIENTRY WinMain(_In_ HINSTANCE hInst, 311 | _In_opt_ HINSTANCE hPrevInstance, 312 | _In_ LPTSTR lpCmdLine, 313 | _In_ int nCmdShow) { 314 | UNREFERENCED_PARAMETER(hPrevInstance); 315 | UNREFERENCED_PARAMETER(lpCmdLine); 316 | 317 | hInstance = hInst; 318 | 319 | DialogBoxParam(hInst, MAKEINTRESOURCE(DLG_MAIN), NULL, &mainDlgProc, NULL); 320 | ExitProcess((UINT) NULL); 321 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | 341 | --------------------------------------------------------------------------------