diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 242546cf4b73559697cf29631960da43c8b604af..f4c7f2c32646329127298f81b16a11f2c2c04e42 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -94,6 +94,7 @@ test-bins-arm64: - ./cicd_testing/elfdep.sh - ./cicd_testing/go_tests.sh - ./cicd_testing/rust_tests.sh + - ./cicd_testing/libc_test.sh diff --git a/cicd_testing/libc_test.sh b/cicd_testing/libc_test.sh new file mode 100755 index 0000000000000000000000000000000000000000..14f5fe3e0d0b91f7b3507992168ff154bd8d2cf1 --- /dev/null +++ b/cicd_testing/libc_test.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -e +set -x + +cd /tmp/peasoup_test +export IDAROOT=$CICD_MODULE_WORK_DIR/idapro71 +export IDASDK=$CICD_MODULE_WORK_DIR/idapro71_sdk +source set_env_vars + +cd $PEASOUP_HOME/tests/libc/ +./test_libc.sh diff --git a/irdb-libs/ir_builders/fill_in_indtargs.cpp b/irdb-libs/ir_builders/fill_in_indtargs.cpp index 5c449ef6356e81f81bcec66b853ba9bb81da5ca5..d653b4025d2bc01558e4f3b2d27ff8674694ad83 100644 --- a/irdb-libs/ir_builders/fill_in_indtargs.cpp +++ b/irdb-libs/ir_builders/fill_in_indtargs.cpp @@ -3915,10 +3915,10 @@ V2: const auto scoop_contents = scoop->getContents().c_str(); const auto symsize = ptrsize == 8 ? sizeof(Elf64_Sym) : ptrsize == 4 ? sizeof(Elf32_Sym) - : throw domain_error("Cannot detect ptr size -> ELF symbol mapping"); + : throw domain_error("Cannot detect ptr size -> ELF symbol mapping"); auto table_entry_no = 0U; - for (auto i = 0U; i + symsize < scoop->getSize(); i += symsize, table_entry_no++) + for (auto i = 0U; i + symsize <= scoop->getSize(); i += symsize, table_entry_no++) { int addr_offset = 0; VirtualOffset_t vo = 0; diff --git a/irdb-libs/third_party/capstone b/irdb-libs/third_party/capstone index 1d230532840a37ac032c6ab80128238fc930c6c1..d5141c04785678535c7792eddc21f146186e639f 160000 --- a/irdb-libs/third_party/capstone +++ b/irdb-libs/third_party/capstone @@ -1 +1 @@ -Subproject commit 1d230532840a37ac032c6ab80128238fc930c6c1 +Subproject commit d5141c04785678535c7792eddc21f146186e639f diff --git a/tests/libc/hello.c b/tests/libc/hello.c new file mode 100644 index 0000000000000000000000000000000000000000..469c20bec1a312b3faf70c79b9e8d0a755204af0 --- /dev/null +++ b/tests/libc/hello.c @@ -0,0 +1,5 @@ +#include <stdio.h> +int main() { + printf("Hello world\n"); + return 0; +} diff --git a/tests/libc/test_libc.sh b/tests/libc/test_libc.sh new file mode 100755 index 0000000000000000000000000000000000000000..cefd2939bdf96173324b375965735c8db4412cb3 --- /dev/null +++ b/tests/libc/test_libc.sh @@ -0,0 +1,31 @@ +#!/bin/bash + + +main() +{ + set -e + set -x + + # calc some names + local libc=$(ldd $(which ls)|grep libc|cut -d'>' -f2|cut -d'(' -f1) + local libc_short=$(basename $libc) + local libc_zipr=$(basename $libc).zipr + + # run zipr + $PSZ $libc $libc_zipr + + # move the zir'd libc to the right name. All subsequent commands + # now run with the zipr'd libc + mv $libc_zipr $libc_short + + # invoke gcc + gcc hello.c || exit 1 + ./a.out || exit 1 + + # invoke zipr on ls -- using zipr'd libc. + $PSZ $(which ls) ls.zipr || exit 1 + ls.zipr -lhrSR || exit 1 +} + +main "$@" + diff --git a/zipr/src/zipr.cpp b/zipr/src/zipr.cpp index 0363678f3b80b617b8be8fded8b0bfb3ff201050..c4862f24bf05790613d9f5082f291d5e4ea9d733 100644 --- a/zipr/src/zipr.cpp +++ b/zipr/src/zipr.cpp @@ -360,7 +360,7 @@ void ZiprImpl_t::CreateExecutableScoops(const std::map<RangeAddress_t, int> &ord // setup a scoop for this section. // zero init is OK, after zipring we'll update with the right bytes. - const auto text_name = count == 1 ? string(".text") : string(".zipr_text_")+to_string(count++); + const auto text_name = count++ == 0u ? string(".text") : string(".zipr_text_")+to_string(count); const auto text_contents = string(text_end->getVirtualOffset() - text_start->getVirtualOffset()+1, '\x00'); const auto text_scoop = m_firp->addNewDataScoop(text_name, text_start, text_end, nullptr, 5 /*R-X*/, false, text_contents);