Skip to content

Commit c2ee977

Browse files
authored
Merge pull request #4 from UncoderIO/gui-update-1
Detect parser feature
2 parents f5249a0 + 0f9303b commit c2ee977

File tree

8 files changed

+55
-3
lines changed

8 files changed

+55
-3
lines changed

uncoder-os/src/components/FileUploader/InputEditorFileUploadButton/useInputEditorFileUploadButton.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useDispatch } from 'react-redux';
22
import { Dispatch } from '@reduxjs/toolkit';
33
import { setText } from '../../../reduxData/inputEditor';
44
import { useInfoProvider } from '../../Info';
5+
import { useDetectParserByText } from '../../../hooks';
56

67
export const FILE_TYPES_ALLOWED_FOR_UPLOAD = [
78
'text/csv',
@@ -14,6 +15,7 @@ export const MAX_FILE_SIZE_FOR_UPLOAD = 3 * 1024 * 1024;
1415
export const useInputEditorFileUploadButton = () => {
1516
const dispatch = useDispatch<Dispatch<any>>();
1617
const { showErrorMessage, showSuccessMessage } = useInfoProvider();
18+
const { detectParser } = useDetectParserByText();
1719
const uploadHandler = async (file: File) => {
1820
if (!file) {
1921
return;
@@ -34,6 +36,7 @@ export const useInputEditorFileUploadButton = () => {
3436

3537
const fileContent = await file.text();
3638
dispatch(setText(fileContent));
39+
detectParser(fileContent);
3740
showSuccessMessage('File uploaded successfully');
3841
};
3942

uncoder-os/src/components/TextEditor/InputTextEditor/InputTextEditor.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import './InputTextEditor.sass';
66

77
export const InputTextEditor: FC = () => {
88
const {
9-
inputText, mode, onChangeInputText, onFocusInputText,
9+
inputText,
10+
mode,
11+
onChangeInputText,
12+
onFocusInputText,
13+
onPasteInputText,
1014
} = useInputEditor();
1115

1216
return (
@@ -18,6 +22,7 @@ export const InputTextEditor: FC = () => {
1822
name="ua-text-editor-input"
1923
onChange={onChangeInputText}
2024
onFocus={onFocusInputText}
25+
onPaste={onPasteInputText}
2126
/>
2227
</div>
2328
);

uncoder-os/src/components/TextEditor/InputTextEditor/useInputEditor.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import ace from 'ace-builds';
1010
import 'ace-builds/src-noconflict/ext-language_tools';
1111
import { loadSuggesterData, suggesterSelector } from '../../../reduxData/suggester';
1212
import { useEditorSuggestion } from '../useEditorSuggestion';
13+
import { useDetectParserByText } from '../../../hooks';
1314

1415
const defineMode = (parser: string) => {
1516
if (['sigma', 'roota'].includes(parser)) {
@@ -27,6 +28,7 @@ export const useInputEditor = () => {
2728
const { text: inputText, platformCode: parser, changed } = useSelector(inputEditorSelector);
2829
const suggestionData = useSelector(suggesterSelector);
2930
const { languageCompleter } = useEditorSuggestion(suggestionData);
31+
const { detectParser } = useDetectParserByText();
3032

3133
useEffect(() => {
3234
const langTools = ace.require('ace/ext/language_tools');
@@ -54,11 +56,16 @@ export const useInputEditor = () => {
5456
dispatch(setText(''));
5557
};
5658

59+
const onPasteInputText = (value: string) => {
60+
detectParser(value);
61+
};
62+
5763
return {
5864
isIoc: parser === 'ioc',
5965
inputText,
6066
mode: defineMode(parser),
6167
onChangeInputText,
6268
onFocusInputText,
69+
onPasteInputText,
6370
};
6471
};

uncoder-os/src/components/TextEditor/TextEditor.sass

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
background-color: $darkHighlight
1818
.ace_scrollbar
1919
z-index: 0
20-
&.ace_scrollbar-v
20+
&.ace_scrollbar-v,
21+
&.ace_scrollbar-h
2122
+scrollbars
2223
.ace_folding-enabled
2324
.ace_gutter-cell

uncoder-os/src/constants/templates.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,12 @@ uuid:`,
6161
{
6262
name: TemplatesKeys.MinimalSigma,
6363
value: `title: sigma title
64+
description:
65+
references:
66+
-
6467
logsource:
6568
#service:
66-
category:
69+
category:
6770
product: windows
6871
detection:
6972
selection:

uncoder-os/src/hooks/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export { useHandleClickOutside } from './useHandleClickOutside';
2+
export * from './useDetectParserByText';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './useDetectParserByText';
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { useDispatch } from 'react-redux';
2+
import { Dispatch } from '@reduxjs/toolkit';
3+
import { setPlatformCode } from '../../reduxData/inputEditor';
4+
5+
const isSigma = (text: string): boolean => {
6+
return text.includes('title:') && text.includes('logsource:') && text.includes('detection:');
7+
};
8+
9+
const isRoota = (text: string): boolean => {
10+
return text.includes('name:') && text.includes('mitre-attack:') && text.includes('detection:');
11+
};
12+
export const useDetectParserByText = () => {
13+
const dispatch = useDispatch<Dispatch<any>>();
14+
const detectParser = (text: string) => {
15+
if (isRoota(text)) {
16+
dispatch(setPlatformCode('roota'));
17+
return;
18+
}
19+
20+
if (isSigma(text)) {
21+
dispatch(setPlatformCode('sigma'));
22+
return;
23+
}
24+
25+
dispatch(setPlatformCode('ioc'));
26+
};
27+
28+
return {
29+
detectParser,
30+
};
31+
};

0 commit comments

Comments
 (0)