Skip to content

Commit 981f73e

Browse files
1 parent e924a70 commit 981f73e

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

yara-java/src/test/java/com/virustotal/yara/YaraJavaTests.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.io.IOException;
1010
import java.lang.foreign.Arena;
1111
import java.lang.foreign.MemorySegment;
12-
import java.net.URL;
1312
import java.nio.ByteBuffer;
1413
import java.nio.charset.StandardCharsets;
1514
import java.nio.file.Files;
@@ -147,6 +146,31 @@ public void testYaraCompilerGetSaveAndDestroyRules(){
147146
}
148147
}
149148

149+
@Test
150+
public void testYaraScannerCreateAndDestroy(){
151+
try (Arena arena = Arena.openConfined()){
152+
MemorySegment yaraRulesFilename$ = arena.allocateUtf8String(YARA_RULES_BIN_DOC_DIR + "/yara-rules.yara.bin"); // char*
153+
MemorySegment yaraRules$$ = arena.allocate(C_POINTER); // YR_RULES**
154+
155+
int loaded = yr_rules_load(yaraRulesFilename$, yaraRules$$);
156+
Assertions.assertEquals(ERROR_SUCCESS(), loaded);
157+
158+
MemorySegment yaraRules$ = yaraRules$$.get(C_POINTER, 0); // YR_RULES*
159+
160+
MemorySegment yaraScanner$$ = arena.allocate(C_POINTER); // YR_SCANNER**
161+
162+
int scannerCreated = yr_scanner_create(yaraRules$, yaraScanner$$);
163+
Assertions.assertEquals(ERROR_SUCCESS(), scannerCreated);
164+
165+
MemorySegment yaraScanner$ = yaraScanner$$.get(C_POINTER, 0); // YR_SCANNER*
166+
167+
int rulesDestroyed = yr_rules_destroy(yaraRules$);
168+
Assertions.assertEquals(ERROR_SUCCESS(), rulesDestroyed);
169+
170+
yr_scanner_destroy(yaraScanner$);
171+
}
172+
}
173+
150174
@AfterAll
151175
public static void finish() {
152176
int finalized = yr_finalize();

0 commit comments

Comments
 (0)