From edf36beba802de9a3618ba9e056a9fe7f04643c8 Mon Sep 17 00:00:00 2001 From: xwings Date: Thu, 1 Sep 2022 13:47:44 +0800 Subject: [PATCH] renew code for picohttpd --- examples/rootfs | 2 +- examples/src/linux/picohttpd/Makefile | 17 +++++++++-------- examples/src/linux/picohttpd/main.c | 16 ++++++++++++++-- tests/test_elf_multithread.py | 10 +++++----- 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/examples/rootfs b/examples/rootfs index 15c8d8428..54756aecf 160000 --- a/examples/rootfs +++ b/examples/rootfs @@ -1 +1 @@ -Subproject commit 15c8d842876d709f013e4e42643d5d605cddbac9 +Subproject commit 54756aecffddc8b22843ddcb8a92afd1b0e545a3 diff --git a/examples/src/linux/picohttpd/Makefile b/examples/src/linux/picohttpd/Makefile index b83222f41..8cd91a626 100644 --- a/examples/src/linux/picohttpd/Makefile +++ b/examples/src/linux/picohttpd/Makefile @@ -1,19 +1,20 @@ -all: server arm_server +all: x64_server arm_server clean: @rm -rf *.o - @rm -rf server + @rm -rf x64_server @rm -rf arm_server + @rm -rf armeb_server -server: main.o httpd.o - gcc -o server $^ +x64_server: main.o httpd.o + gcc -o x64_server $^ @rm -rf *.o -main.o: main.c httpd.h - gcc -c -o main.o main.c +x64_main.o: main.c httpd.h + gcc -c -o x64_main.o main.c -httpd.o: httpd.c httpd.h - gcc -c -o httpd.o httpd.c +x64_httpd.o: httpd.c httpd.h + gcc -c -o x64_httpd.o httpd.c arm_server: arm_main.o arm_httpd.o arm-linux-gnueabi-gcc-10 -o arm_server $^ diff --git a/examples/src/linux/picohttpd/main.c b/examples/src/linux/picohttpd/main.c index 0a0fb2520..60f9bc3aa 100644 --- a/examples/src/linux/picohttpd/main.c +++ b/examples/src/linux/picohttpd/main.c @@ -1,8 +1,20 @@ #include "httpd.h" -int main(int c, char** v, int argc, const char **argv) +#define PORT_DEFAULT "12913" + +int main(int argc, const char **argv) { - serve_forever("12913"); + const char *PORT; + + if (argc < 2) { + PORT = PORT_DEFAULT; + } else { + PORT = argv[1]; + } + + fprintf(stderr, "port is %s.\n", PORT); + + serve_forever(PORT); return 0; } diff --git a/tests/test_elf_multithread.py b/tests/test_elf_multithread.py index 443f63acc..fc7a62f3a 100644 --- a/tests/test_elf_multithread.py +++ b/tests/test_elf_multithread.py @@ -352,7 +352,7 @@ def check_write(ql, write_fd, write_buf, write_count, *args, **kw): except: pass - ql = Qiling(["../examples/rootfs/armeb_linux/bin/armeb_udp_test","20009"], "../examples/rootfs/armeb_linux", multithread=True) + ql = Qiling(["../examples/rootfs/armeb_linux/bin/armeb_udp_test","20010"], "../examples/rootfs/armeb_linux", multithread=True) ql.os.set_syscall("write", check_write, QL_INTERCEPT.ENTER) ql.run() @@ -362,7 +362,7 @@ def check_write(ql, write_fd, write_buf, write_count, *args, **kw): def test_http_elf_linux_x8664(self): def picohttpd(): - ql = Qiling(["../examples/rootfs/x8664_linux/bin/picohttpd"], "../examples/rootfs/x8664_linux", multithread=True, verbose=QL_VERBOSE.DEBUG) + ql = Qiling(["../examples/rootfs/x8664_linux/bin/picohttpd","12911"], "../examples/rootfs/x8664_linux", multithread=True, verbose=QL_VERBOSE.DEBUG) ql.run() @@ -371,12 +371,12 @@ def picohttpd(): time.sleep(1) - f = os.popen("curl http://127.0.0.1:12913") + f = os.popen("curl http://127.0.0.1:12911") self.assertEqual("httpd_test_successful", f.read()) def test_http_elf_linux_arm(self): def picohttpd(): - ql = Qiling(["../examples/rootfs/arm_linux/bin/picohttpd"], "../examples/rootfs/arm_linux", multithread=True, verbose=QL_VERBOSE.DEBUG) + ql = Qiling(["../examples/rootfs/arm_linux/bin/picohttpd","12912"], "../examples/rootfs/arm_linux", multithread=True, verbose=QL_VERBOSE.DEBUG) ql.run() @@ -385,7 +385,7 @@ def picohttpd(): time.sleep(1) - f = os.popen("curl http://127.0.0.1:12913") + f = os.popen("curl http://127.0.0.1:12912") self.assertEqual("httpd_test_successful", f.read()) def test_http_elf_linux_armeb(self):