diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b2dd1bfb693f81baee5d0f2bf47c82b8d27b5b10..1a3a2754b63b77d23b701a0d98d1ed2c4829277b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -145,3 +145,34 @@ xform-cat-centos75: variables: OS: 'centos75' +# +# elfdep test +# + +# template +.elfdep: &elfdep + stage: test + script: + - ./cicd_tests/elfdep.sh + +elfdep-ubuntu18: + <<: *elfdep + tags: + - ubuntu18 + variables: + OS: 'ubuntu18' + +elfdep-ubuntu16: + <<: *elfdep + tags: + - ubuntu16 + variables: + OS: 'ubuntu16' + +elfdep-centos75: + <<: *elfdep + tags: + - centos75 + variables: + OS: 'centos75' + diff --git a/cicd_tests/elfdep.sh b/cicd_tests/elfdep.sh new file mode 100755 index 0000000000000000000000000000000000000000..9ba43c87cd0d7e134e0a9b54f5278e6faed9c0c7 --- /dev/null +++ b/cicd_tests/elfdep.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -e +set -x + +cd $CICD_MODULE_WORK_DIR/peasoup_umbrella +source set_env_vars + +cd $SECURITY_TRANSFORMS_HOME/libElfDep/test/ +./test-elfdep.sh diff --git a/libElfDep/src/elfdep.cpp b/libElfDep/src/elfdep.cpp index e673fe8039acaa8ee425f4737e5042d301cfd256..b2d3bcd12aa27aa127cc17d37752994473f38f5a 100644 --- a/libElfDep/src/elfdep.cpp +++ b/libElfDep/src/elfdep.cpp @@ -206,6 +206,7 @@ Instruction_t* ElfDependencies_t::ElfDependenciesImpl_t<T_Elf_Sym,T_Elf_Rela,T_E newinsn->GetRelocations().insert(newreloc); getFileIR()->GetRelocations().insert(newreloc); + newinsn->GetAddress()->SetFileID(getFileIR()->GetFile()->GetBaseID()); return newinsn; } diff --git a/libElfDep/test/SConscript b/libElfDep/test/SConscript index e07d67e74ee3ab43ca4acdfd671107c86bed4eea..e457589bcc480f365b4b5f164a57f68de53be2ba 100644 --- a/libElfDep/test/SConscript +++ b/libElfDep/test/SConscript @@ -32,7 +32,7 @@ files=Glob( Dir('.').srcnode().abspath+"/edt*.cpp") pgm="edt.exe" LIBPATH="$SECURITY_TRANSFORMS_HOME/lib" -LIBS=Split("stars "+ myenv.subst('$BASE_IRDB_LIBS')+ " IRDB-core pqxx BeaEngine_s_d transform MEDSannotation EXEIO pebliss ElfDep") +LIBS=Split("stars "+ myenv.subst('$BASE_IRDB_LIBS')+ " IRDB-core libIRDB-cfg libIRDB-util.so pqxx capstone transform MEDSannotation EXEIO pebliss ElfDep") myenv=myenv.Clone(CPPPATH=Split(cpppath)) pgm=myenv.Program(pgm, files, LIBPATH=LIBPATH, LIBS=LIBS) install=myenv.Install("$SECURITY_TRANSFORMS_HOME/plugins_install/", pgm) diff --git a/libElfDep/test/edt.cpp b/libElfDep/test/edt.cpp index 12e1ea24f4bbab211770e2bebe8589d88c9886f6..77cff3e41f288bc2d67fe976f0beb5e8a449b2a0 100644 --- a/libElfDep/test/edt.cpp +++ b/libElfDep/test/edt.cpp @@ -41,23 +41,23 @@ int ElfDep_Tester_t::execute() // insert the instrumentation auto tmp=insert_loc; - (void)insertAssemblyBefore(getFileIR(),tmp," push rdi") ; - tmp= insertAssemblyAfter(getFileIR(), tmp," push rsi ") ; - tmp= insertAssemblyAfter(getFileIR(), tmp," push rdx") ; - tmp= insertAssemblyAfter(getFileIR(), tmp," push rcx ") ; - tmp= insertAssemblyAfter(getFileIR(), tmp," push r8 ") ; - tmp= insertAssemblyAfter(getFileIR(), tmp," push r9 ") ; - tmp= insertAssemblyAfter(getFileIR(), tmp," call 0 ", edpcb) ; - tmp= insertAssemblyAfter(getFileIR(), tmp," L1: mov rcx, [rel L1]"); + (void)insertAssemblyBefore(tmp," push rdi") ; + tmp= insertAssemblyAfter(tmp," push rsi ") ; + tmp= insertAssemblyAfter(tmp," push rdx") ; + tmp= insertAssemblyAfter(tmp," push rcx ") ; + tmp= insertAssemblyAfter(tmp," push r8 ") ; + tmp= insertAssemblyAfter(tmp," push r9 ") ; + tmp= insertAssemblyAfter(tmp," call 0 ", edpcb) ; + tmp= insertAssemblyAfter(tmp," L1: mov rcx, [rel L1]"); auto got_insn=tmp; - tmp= insertAssemblyAfter(getFileIR(), tmp," inc dword [rcx]"); - tmp= insertAssemblyAfter(getFileIR(), tmp," call 0", edpcb); - tmp= insertAssemblyAfter(getFileIR(), tmp," pop r9"); - tmp= insertAssemblyAfter(getFileIR(), tmp," pop r8"); - tmp= insertAssemblyAfter(getFileIR(), tmp," pop rcx"); - tmp= insertAssemblyAfter(getFileIR(), tmp," pop rdx"); - tmp= insertAssemblyAfter(getFileIR(), tmp," pop rsi"); - tmp= insertAssemblyAfter(getFileIR(), tmp," pop rdi"); + tmp= insertAssemblyAfter(tmp," inc dword [rcx]"); + tmp= insertAssemblyAfter(tmp," call 0", edpcb); + tmp= insertAssemblyAfter(tmp," pop r9"); + tmp= insertAssemblyAfter(tmp," pop r8"); + tmp= insertAssemblyAfter(tmp," pop rcx"); + tmp= insertAssemblyAfter(tmp," pop rdx"); + tmp= insertAssemblyAfter(tmp," pop rsi"); + tmp= insertAssemblyAfter(tmp," pop rdi"); // map the load to point at the GOT entry. diff --git a/libElfDep/test/test-elfdep.sh b/libElfDep/test/test-elfdep.sh new file mode 100755 index 0000000000000000000000000000000000000000..39ac850f75d329f0223c1f2e177835917710a161 --- /dev/null +++ b/libElfDep/test/test-elfdep.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +TMP_ORIG=/tmp/testelfdep.ls.orig.$$ +TMP_ORIG2=/tmp/testelfdep.ls.orig.2.$$ +TMP_ELFDEP=/tmp/testelfdep.ls.elfdep.$$ + +cleanup_files() +{ + rm /tmp/testelfdep.ls* >/dev/null 2>&1 +} + +cleanup() +{ + echo "************" + echo "test failed." + echo "************" + + cleanup_files + exit 1 +} + + +# make sure xforms are built +scons || cleanup + +$PSZ /bin/ls ./xxx -c move_globals=on -o move_globals:--elftables -c edt=on || cleanup + +/bin/ls /tmp > $TMP_ORIG || cleanup + +./xxx /tmp > $TMP_ELFDEP || cleanup + +echo "Verify external vars was overwritten" +grep "var = 0" $TMP_ELFDEP || cleanup +grep "var = 1" $TMP_ELFDEP || cleanup + +echo "Verify same output" +grep -v "var =" $TMP_ELFDEP > $TMP_ORIG2 +diff $TMP_ORIG2 $TMP_ELFDEP + +cleanup_files + +echo +echo "test passed." +echo diff --git a/libElfDep/test/testit.sh b/libElfDep/test/testit.sh deleted file mode 100755 index 051b6c0133b5fc47f9a961516065161c9533ccdb..0000000000000000000000000000000000000000 --- a/libElfDep/test/testit.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -cleanup() -{ - echo "************" - echo "test failed." - echo "************" - exit 1 -} - - -# make sure xforms are built -scons || cleanup - -$PSZ /bin/ls ./xxx -c move_globals=on -o move_globals:--elftables -c edt=on || cleanup - -/bin/ls /tmp || cleanup -./xxx /tmp || cleanup - -echo -echo "test passed." -echo diff --git a/libcapstone b/libcapstone index a6b87b7bc31499b9ec538701b438f7a60e9dda38..9408c0de4f3a4b2a3cc1cac3f22219301c561400 160000 --- a/libcapstone +++ b/libcapstone @@ -1 +1 @@ -Subproject commit a6b87b7bc31499b9ec538701b438f7a60e9dda38 +Subproject commit 9408c0de4f3a4b2a3cc1cac3f22219301c561400