-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
restructuring to include ffi and not be a program
- Loading branch information
1 parent
20f6fbf
commit f0725b9
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package main | ||
|
||
/* | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
static inline void c_print(const char* s) { | ||
printf("%s\n", s); | ||
fflush(stdout); | ||
} | ||
*/ | ||
import "C" | ||
import ( | ||
"github.com/Shuffle/indicator-parser/go/parser" | ||
) | ||
|
||
//export ParseIOC | ||
func ParseIOC(value *C.char, typesJSON *C.char) *C.char { | ||
goValue := C.GoString(value) | ||
result := parser.ParseIndicatorToJSON(goValue) | ||
return C.CString(result) | ||
} | ||
|
||
func main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package parser | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
ioc "github.com/Shuffle/indicator-parser/go/ioc" | ||
) | ||
|
||
var logger *log.Logger | ||
|
||
func init() { | ||
logFile, err := os.OpenFile("ioc_parser.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) | ||
if err != nil { | ||
panic(err) | ||
} | ||
logger = log.New(logFile, "", log.LstdFlags) | ||
} | ||
|
||
func logPrint(s string) { | ||
logger.Println(s) | ||
fmt.Println(s) | ||
} | ||
|
||
// ParseIndicator parses an IOC string and returns the results | ||
func ParseIndicator(value string) []ioc.Indicator { | ||
return ioc.Parse(value, []ioc.IndicatorType{}) | ||
} | ||
|
||
// ParseIndicatorToJSON parses an IOC string and returns the results as JSON | ||
func ParseIndicatorToJSON(value string) string { | ||
results := ParseIndicator(value) | ||
jsonData, err := json.Marshal(results) | ||
if err != nil { | ||
logPrint(fmt.Sprintf("Error marshaling results: %v", err)) | ||
return "[]" | ||
} | ||
return string(jsonData) | ||
} |