From 2bafaf4ec354e57ffdbde8725fbcb6746bb94c63 Mon Sep 17 00:00:00 2001 From: Wesley Shields Date: Mon, 12 Aug 2019 03:07:58 -0400 Subject: [PATCH] Add dotnet tests. (#1109) Add some tests for the dotnet module, which uses the smallest .NET binary I had laying around that exercises a fair bit of the code. In particular it has a resource, guids, assembly information and a couple of other things that make for good tests. --- Makefile.am | 6 ++ ...4f7a4147347a7a97271370583586c9e587fd396171 | Bin 0 -> 3584 bytes tests/test-dotnet.c | 67 ++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 tests/data/0ca09bde7602769120fadc4f7a4147347a7a97271370583586c9e587fd396171 create mode 100644 tests/test-dotnet.c diff --git a/Makefile.am b/Makefile.am index 0240331e..8fce57cd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -86,6 +86,12 @@ test_dex_SOURCES = tests/test-dex.c tests/util.c test_dex_LDADD = libyara/.libs/libyara.a endif +if DOTNET_MODULE +check_PROGRAMS+=test-dotnet +test_dotnet_SOURCES = tests/test-dotnet.c tests/util.c +test_dotnet_LDADD = libyara/.libs/libyara.a +endif + # man pages man1_MANS = yara.man yarac.man diff --git a/tests/data/0ca09bde7602769120fadc4f7a4147347a7a97271370583586c9e587fd396171 b/tests/data/0ca09bde7602769120fadc4f7a4147347a7a97271370583586c9e587fd396171 new file mode 100644 index 0000000000000000000000000000000000000000..edb040c76b860fae2ddf3a0e5cfe4c84d8afce1b GIT binary patch literal 3584 zcmeHJdu$X%82`2}+9DMqB99ujv_+)la(&Z;>Rnr)Kxu2QZHn^f-rdqJ?A=~=_n=oE zUL++J4WWUki48&&5Cwy=Mj${y5E3E}V-z%Eh!_=Zr~+aHwf<(V*B&iFP5ejVw>RH> zuldb4-^|Y5+$T3sG!ez1_4E+!MbF5_`Q2F%?xgYilc+P{RLWkV{8UO!lVXTIU2D`O zkLZ%TUdaB+=!?RtasFa~XJW(7h ztbrD$gNbN1G{!`9QK7sc@%&j&K{VJaR}j`^Yb6@afBk*0%3?wBz;!Ue21r(jfz&{B z-$2{n(M4cK#Kl7|i_k5m+-yR3$AZDf*NMC%NhE5p=!Wisk>_TEz&0up7%I#*i!Q4g z0(q_tFfyzGi6gEU*4xO&>I!1HMNuq0n}QOe4hh^!bXE+Vi7NELUfbQerw?9U{-R~; z#qU2`A2-f=BYE3t-8c66xSdy9%?I^~Unl3B*|ybOQoF9YCjXmrWn@o$`23D@ZEGr8 z7MxzYud5~Bb6u`!uK2avRdz;tY4+PuIWPNW&at*M{&GN_=l-&7g1m9U<){3Ut~LKy zvbXFfm#uca@^f}q>#fOK*G~CeYK!Vba;Hyr9}>{Fqp6O7Vags$wQOj9-6b1+Qnf6( zWj#~$7%oj$6=$YcC+miyd5f|wR`z6yC4SZP>vEA-_M5t-W{OpQr>eN-$blMdsq8Is z78FQ%uDtxL!kk>$I<+u$@MM0ksd(h@><-zC+~X>HDf_XUiygCz1!7r;wrv?pBF|co zUBE1{q=H{ZOI?jafv{<4sSZ@P()`(8@_HmR>4yj72+qfFp2GQ~oM&-vp`mn~EEvo9IL=c!&)_@F6nAf z#_5a&7iLskIrnM8nD;xQZYEEjlQ!{ceoElVZ^oLBw0$d1md`km@MfZ?@SPi@f}KNK zrR4U!mZlvG8+NanxBF1bBZrUAe)Nd&n9Taexi|E=i-6@;cBctIl}HDUg1b=$rk56z#{FsRXi*Kk608RN5}An8poM5p zOd3E1F!USSW`ID4X(VDo?cm2T|awGx=CA)}o?*5_zB#HIa{&08xX*M}9uP3Vf3S zz;e(saGhtU!K))rmaT={Kw)Qe5?@O>tc@JG1V}!NWmRbex``N(&%^Sl?6tFsu{^@n zXWGA$Pbsfg73R^9qaXR2*y-D=_E$A4;}~|V)4)g%c1^{K#D9!~W#9WGhW>9f +#include +#include +#include +#include "util.h" + +int main(int argc, char** argv) +{ + char *top_srcdir = getenv("TOP_SRCDIR"); + if (top_srcdir) + chdir(top_srcdir); + + yr_initialize(); + + assert_true_rule_file( + "import \"dotnet\" \ + rule test { \ + condition: \ + dotnet.assembly.name == \"hpjsoaputility.Sv.resources\" \ + }", + "tests/data/0ca09bde7602769120fadc4f7a4147347a7a97271370583586c9e587fd396171"); + + assert_true_rule_file( + "import \"dotnet\" \ + rule test { \ + condition: \ + dotnet.number_of_resources == 1 and \ + dotnet.resources[0].offset == 724 and \ + dotnet.resources[0].length == 180 and \ + dotnet.resources[0].name == \"hpjsoaputility.XmlStreamSoapExtension.pt.resources\" \ + }", + "tests/data/0ca09bde7602769120fadc4f7a4147347a7a97271370583586c9e587fd396171"); + + assert_true_rule_file( + "import \"dotnet\" \ + rule test { \ + condition: \ + dotnet.number_of_guids == 1 and \ + dotnet.guids[0] == \"3764d539-e21a-4366-bc7c-b56fa67efbb0\" \ + }", + "tests/data/0ca09bde7602769120fadc4f7a4147347a7a97271370583586c9e587fd396171"); + + assert_true_rule_file( + "import \"dotnet\" \ + rule test { \ + condition: \ + dotnet.number_of_streams == 5 and \ + dotnet.streams[0].name == \"#~\" and \ + dotnet.streams[1].name == \"#Strings\" and \ + dotnet.streams[2].name == \"#US\" and \ + dotnet.streams[3].name == \"#GUID\" and \ + dotnet.streams[4].name == \"#Blob\" \ + }", + "tests/data/0ca09bde7602769120fadc4f7a4147347a7a97271370583586c9e587fd396171"); + + assert_true_rule_file( + "import \"dotnet\" \ + rule test { \ + condition: \ + dotnet.module_name == \"hpjsoaputility.Sv.resources.dll\" and \ + dotnet.version == \"v2.0.50727\" \ + }", + "tests/data/0ca09bde7602769120fadc4f7a4147347a7a97271370583586c9e587fd396171"); + + yr_finalize(); + return 0; +}