Skip to content

Commit 8f99a55

Browse files
committed
added values transfrom
1 parent 53d5c01 commit 8f99a55

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

uncoder-core/app/translator/core/models/field.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ def value(self) -> Union[int, str, StrValue, list[Union[int, str, StrValue]]]:
6060
return self.values[0]
6161
return self.values
6262

63+
@value.setter
64+
def value(self, new_value: Union[int, str, StrValue, list[Union[int, str, StrValue]]]) -> None:
65+
self.values = []
66+
self.__add_value(new_value)
67+
6368
def __add_value(self, value: Optional[Union[int, str, StrValue, list, tuple]]) -> None:
6469
if value and isinstance(value, (list, tuple)):
6570
for v in value:

uncoder-core/app/translator/platforms/palo_alto/renders/cortex_xsiam.py

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121

2222
from app.translator.const import DEFAULT_VALUE_TYPE
2323
from app.translator.core.custom_types.values import ValueType
24+
from app.translator.core.mapping import SourceMapping
25+
from app.translator.core.models.field import FieldValue, Keyword
26+
from app.translator.core.models.identifier import Identifier
2427
from app.translator.core.models.platform_details import PlatformDetails
2528
from app.translator.core.render import BaseQueryFieldValue, PlatformQueryRender
2629
from app.translator.core.str_value_manager import StrValue
@@ -34,6 +37,16 @@
3437
)
3538
from app.translator.platforms.palo_alto.str_value_manager import cortex_xql_str_value_manager
3639

40+
SOURCE_MAPPING_TO_FIELD_VALUE_MAP = {
41+
"windows_registry_event": {
42+
"EventType": {
43+
"SetValue": "REGISTRY_SET_VALUE",
44+
"DeleteValue": "REGISTRY_DELETE_VALUE",
45+
"CreateKey": "REGISTRY_CREATE_KEY",
46+
}
47+
}
48+
}
49+
3750

3851
class CortexXQLFieldValue(BaseQueryFieldValue):
3952
details: PlatformDetails = cortex_xql_query_details
@@ -51,12 +64,6 @@ def _get_value_type(field_name: str, value: Union[int, str, StrValue], value_typ
5164

5265
@staticmethod
5366
def _wrap_str_value(value: str) -> str:
54-
if value == "SetValue":
55-
return '"REGISTRY_SET_VALUE"'
56-
if value == "DeleteValue":
57-
return '"REGISTRY_DELETE_VALUE"'
58-
if value == "CreateKey":
59-
return '"REGISTRY_CREATE_KEY"'
6067
return f'"{value}"'
6168

6269
def equal_modifier(self, field: str, value: DEFAULT_VALUE_TYPE) -> str:
@@ -178,3 +185,29 @@ def process_raw_log_field(self, field: str, field_type: str) -> Optional[str]:
178185
def generate_prefix(self, log_source_signature: CortexXQLLogSourceSignature, functions_prefix: str = "") -> str:
179186
functions_prefix = f"{functions_prefix} | " if functions_prefix else ""
180187
return f"{functions_prefix}{log_source_signature}"
188+
189+
def apply_token(self, token: Union[FieldValue, Keyword, Identifier], source_mapping: SourceMapping) -> str:
190+
if (
191+
isinstance(token, FieldValue)
192+
and source_mapping.source_id in SOURCE_MAPPING_TO_FIELD_VALUE_MAP
193+
and token.field.source_name in SOURCE_MAPPING_TO_FIELD_VALUE_MAP[source_mapping.source_id]
194+
):
195+
values_to_update = []
196+
token_values = token.values
197+
for token_value in token_values:
198+
if (
199+
isinstance(token_value, str)
200+
and token_value
201+
in SOURCE_MAPPING_TO_FIELD_VALUE_MAP[source_mapping.source_id][token.field.source_name]
202+
):
203+
values_to_update.append(
204+
SOURCE_MAPPING_TO_FIELD_VALUE_MAP[source_mapping.source_id][token.field.source_name][
205+
token_value
206+
]
207+
)
208+
else:
209+
values_to_update.append(token_value)
210+
if values_to_update != token_values:
211+
token.value = values_to_update
212+
213+
return super().apply_token(token=token, source_mapping=source_mapping)

0 commit comments

Comments
 (0)