-
Notifications
You must be signed in to change notification settings - Fork 1
/
membrick.py
2202 lines (1902 loc) · 100 KB
/
membrick.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import functools
import inspect
import json
import re
import copy
import ida_search
import idaapi
import idautils
import idc
from idc import BADADDR
from idc import SEARCH_NOSHOW, SEARCH_NEXT, SEARCH_DOWN, SEARCH_CASE, DEMNAM_FIRST
# from underscoretest import _
from exectools import _import
# from sfida.sf_common import isStringish
# from sfida.sf_is_flags import IsFuncHead, HasUserName
# from sfida.sf_string_between import string_between
# retrace = lambda ea, *a, **k: unpatch_func(ea)
from exectools import make_refresh
refresh_membrick = make_refresh(os.path.abspath(__file__))
refresh = make_refresh(os.path.abspath(__file__))
def trim_paren(hooka):
while hooka and hooka[0] == '(' and hooka[-1] == ')':
hooka = hooka[1:-1]
print("hooka: {}".format(hooka))
return hooka
# https://stackoverflow.com/questions/3749512/python-group-by
from functools import reduce # import needed for python3; builtin in python2
from collections import defaultdict
def groupBy(seq, func):
return reduce(lambda grp, val: grp[func(val)].append(val) or grp, seq, defaultdict(list))
def _double_questions(pattern):
return pattern.lower().strip().replace('??', '?').replace('?', '??').rstrip(' ?')
def check_patterns(s=None):
if s is None:
for fn in """david/DirectX11.cpp
features/hotkeys.cpp
HookCheckSomeThingy.cpp
HookChecksummers.cpp
HookCPedDictCrash.cpp
HookCrewKick.cpp
HookFatalError1.cpp
HookHook.cpp
HookInvalidObjectCrash.cpp
HookNetArray.cpp
HookNetworkBail.cpp
HookOzark13.cpp
HookPoolSlots.cpp
HookScriptVM.cpp
HookSpeedupNetCat.cpp
HookSpeedupStrlen.cpp
HookSync1.cpp
HookWriteQword.cpp
Patches.cpp
PlayerTracker/PlayerTrackerSession.cpp
Scripting/Hooking.cpp
Scripting/Hooking.h
WolfSniff.cpp""".split('\n'):
check_patterns(file_get_contents('e:/git/pokey/src/' + fn))
return
s2 = []
for line in s.split('\n'):
s2.append(string_between('//', '', line, repl='', inclusive=1))
s = ''.join(s2).replace('{', ';{').split(';')
del s2
for line in s:
line = re.sub(r'if \([a-zA-Z0-9 ]+\)', '', line)
line = string_between('if (', ')', line, greedy=1, retn_all_on_fail=1)
hooka = string_between('HOOKA(', ')', line, greedy=1)
if not hooka:
hooka = string_between('MAKE_CLASS_FUNCTION_NO_ARGS(', ')', line, greedy=1)
if not hooka:
hooka = string_between('MAKE_CLASS_FUNCTION(', ')', line, greedy=1)
try:
spl = paren_split(hooka, strip=',', rtrim=1)
except Exception as e:
print("Exception: {} {}\nLine: {}".format(type(e), str(e), line))
continue
if len(spl) > 2:
spl[0] = trim_paren(spl[0])
reconstitute = []
components = paren_split(spl[0], '.', strip='.', rtrim=1)
pattern = string_between('("', '")', components[0])
if not pattern:
continue
pattern = re.sub(r'"\s+"', '', pattern)
hook = spl[1].strip()
# devstr = string_between('("', '")', spl[3])
m = mem(pattern)
if m.valid():
reconstitute.append('mem("{}")'.format(m.pattern))
for component in components[1:]:
method = string_between('', '(', component)
if not method.startswith('as<'):
arguments = string_between('(', ')', component, greedy=1)
try:
argument = int(arguments, base=0)
except ValueError:
print("{}: invalid argument: {}: {}".format(hook, method, arguments))
m.errored = True
break
method_attr = getattr(m, method, None)
if callable(method_attr):
m = method_attr(argument)
if not m.valid():
print("{}: failed argument: {}: {}".format(hook, method, arguments))
break
reconstitute.append('{}({})'.format(method, argument))
if m.valid():
print("{}: pattern succeeded: {}: {} type('{}')".format(hook, '.'.join(reconstitute), describe_target(m.value()), idc.get_type(m.value()) ))
else:
print("{}: pattern failed: {}: {}".format(hook, pattern, hex(FindInSegments(pattern))))
else:
pass
# print("line(spl): {}: {}".format(len(spl), line))
def joaat_memory(ea, length, hash = 0x4C11DB7):
string = idc.get_bytes(ea, length)
for b in string:
hash = (hash + b) * 1025 & 0xFFFFFFFF
hash = (hash >> 6 ^ hash)
hash = (hash * 9) & 0xFFFFFFFF
return (hash >> 11 ^ hash) * 32769 & 0xFFFFFFFF
def isStringish(o):
return isinstance(o, (string_type, byte_type))
def can_call(fn):
return fn in globals() and callable(globals()[fn])
if not idc or not can_call('refresh_start'):
try:
long_type = long
except:
long_type = int
elif can_call('refresh_start'):
# from di import destart
# from helpers import UnPatch
pass
def MakeUniqueLabel(name, ea=BADADDR):
fnLoc = idc.get_name_ea_simple(name)
if fnLoc == BADADDR or fnLoc == ea:
return name
fmt = "%s_%%i" % name
for i in range(65535):
tmpName = fmt % i
fnLoc = idc.get_name_ea_simple(tmpName)
if fnLoc == BADADDR or fnLoc == ea:
return tmpName
print("[warn] failed to make unique label for {:x} last try: {}".format(ea, tmpName))
return ""
def nameIfContainsElse(ea, match, name, fullname):
fnName = label
if fnName and ~fnName.find(match) and not ~fnName.find(fullname):
fnName = "{}_{}".format(fnName, name)
else:
fnName = fullname
return fnName
def MemLabelAddressPlus(ea, name, rename_old=False, force=False, replace=False):
force = force or rename_old or replace
if ea < idc.BADADDR:
fnLoc = LocByName(name)
if fnLoc == BADADDR:
return MakeNameEx(ea, name, idc.SN_NOWARN)
elif fnLoc == ea:
return True
if force:
MakeNameEx(fnLoc, "", idc.SN_AUTO | idc.SN_NOWARN)
Wait()
return MakeNameEx(ea, name, idc.SN_NOWARN)
name = MakeUniqueLabel(name, ea)
return MakeNameEx(ea, name, idc.SN_NOWARN)
else:
print("0x0%0x: Couldn't label %s, BADADDR" % (ea, name))
return False
def ensure_decl(name, decl, size=None):
if not has_decl(name, size)[0]:
idc.parse_decls(decl, idc.PT_SILENT)
def find_checksummers1():
strucText = """
typedef unsigned char uint8_t;
typedef int int32_t;
typedef unsigned int uint32_t;
struct arxan_range
{
uint32_t start;
uint32_t len;
};
"""
ensure_decl('arxan_range', strucText)
def predicate_checksummers(ea):
o_rel = 3
o_abs = 14
# o_base = -8 # may not find
rel = mem(ea).add(o_rel).rip(4).val()
abso = idc.get_qword(mem(ea).add(o_abs).rip(4).val())
# base = idc.get_qword(mem(ea).add(o_base).rip(4).val())
if rel == abso: # and base == idc.get_name_ea_simple("__ImageBase"):
mem(abso).label("ArxanCheck_{}".format(long_to_words(abso - ida_ida.cvar.inf.min_ea)))
if idc.get_wide_byte(ea + 81) == 0xe8:
mem(ea).add(82).rip(4).label('ArxanGetNextRange').type("void __fastcall f(uint8_t **guide, arxan_range *range);")
mem(ea).add(o_abs).rip(4).label('pArxanChecksum_AbsAddressSelf')
# mem(ea).add(o_base).rip(4).label('__ImageBase')
# MakeUnknown(ea, 82 + 4 + 5, DELIT_DELNAMES)
return abso
else:
print("rel: {:x}, abso: {:x}".format(rel, abso))
return False
pattern = '48 31 C0 0F 1F 84 00 00 00 00 00 0F 1F 84 00 00 00 00 00 66 0F 1F 44 00 00'
if can_call('UnPatch'):
for e in FindInSegments(pattern, 'any', None):
UnPatch(e, e+75//3)
# pattern = '38 48 8d 05 ?? ?? ?? ?? 48 89 45 18 48 8b 05 ?? ?? ?? ?? 48 f7 d8 48 03'
pattern = '48 8d 05 ?? ?? ?? ?? 48 89 45 18 48 8b 05 ?? ?? ?? ?? 48 f7 d8'
return [e for e in FindInSegments(pattern, 'any', None, predicate=predicate_checksummers)]
def find_checksummers2():
def predicate_checksummers(ea):
o_rel = 13
o_abs = 3
rel = mem(ea).add(o_rel).rip(4).val()
abso = idc.get_qword(mem(ea).add(o_abs).rip(4).val())
# fnName = nameIfContainsElse(abso, "Arxan", "Mutator", "ArxanMutator")
if rel == abso:
# mem(ea).add(o_abs).rip(4).label("p{}_AbsAddressSelf".format(fnName))
# mem(ea).add(o_rel).rip(4).label(fnName)
# mem(abso).label(fnName)
mem(abso).label("ArxanCheck_{}".format(long_to_words(abso - ida_ida.cvar.inf.min_ea)))
return abso
else:
print("rel: {:x}, abso: {:x}".format(rel, abso))
return False
pattern = '48 8b 05 ?? ?? ?? ?? 48 f7 d8 48 8d 15 ?? ?? ?? ?? 48 8d 04 02'
return [e for e in FindInSegments(pattern, 'any', None, predicate=predicate_checksummers)]
def find_checksummers3():
def predicate_checksummers(ea):
o_rel = 3
o_abs = 14
rel = mem(ea).add(o_rel).rip(4).val()
abso = idc.get_qword(mem(ea).add(o_abs).rip(4).val())
# fnName = nameIfContainsElse(abso, "Arxan", "Decider", "ArxanDecider")
if rel == abso:
# mem(ea).add(o_abs).rip(4).label("p{}_AbsAddressSelf".format(fnName))
# mem(ea).add(o_rel).rip(4).label(fnName)
# mem(abso).label(fnName)
mem(abso).label("ArxanCheck_{}".format(long_to_words(abso - ida_ida.cvar.inf.min_ea)))
return abso
else:
print("{:x}: rel: {:x}, abso: {:x}".format(ea, rel, abso))
return False
pattern = '48 8D 05 ?? ?? ?? ?? 48 89 45 ?? 48 8B 05 ?? ?? ?? ?? 48 F7 D8'
return [e for e in FindInSegments(pattern, 'any', None, predicate=predicate_checksummers)]
def find_checksummers6():
"""
48 8b 05 ?? ?? ?? ??
48 89 45 68
48 8d 05 ?? ?? ?? ??
48 89 45 48
48 8b 05 ?? ?? ?? ??
48 f7 d8
48 03 45 48
48 89 45 48
48 8b 45 48
48 8b 05 ?? ?? ?? ??
48 89 45 ??
48 8d 05 ?? ?? ?? ??
48 89 45 ??
48 8b 05 ?? ?? ?? ??
48 f7 d8
48 03 45 ??
48 89 45 ??
48 8b 45 ??
"""
"""
00 48 8B 05 9A 28 35 01 mov rax, cs:o_imagebase_189
07 48 89 45 68 mov [rbp+68h], rax
11 48 8D 05 B1 E2 6A 00 lea rax, ArxanChecksumCallsGetNextRange_235
18 48 89 45 48 mov [rbp+48h], rax
22 48 8B 05 E2 5C 8A FD mov rax, cs:o_arxanchecksumcallsgetnextrange_235
29 48 F7 D8 neg rax
32 48 03 45 48 add rax, [rbp+48h]
36 48 89 45 48 mov [rbp+48h], rax
40 48 8B 45 48 mov rax, [rbp+48h]
"""
def predicate_checksummers(ea):
o_rel = 14
o_abs = 25
rel = mem(ea).add(o_rel).rip(4).val()
abso = idc.get_qword(mem(ea).add(o_abs).rip(4).val())
# fnName = nameIfContainsElse(abso, "Arxan", "Decider", "ArxanDecider")
if rel == abso:
# mem(ea).add(o_abs).rip(4).label("p{}_AbsAddressSelf".format(fnName))
# mem(ea).add(o_rel).rip(4).label(fnName)
# mem(abso).label(fnName)
mem(abso).label("ArxanCheck_{}".format(long_to_words(abso - ida_ida.cvar.inf.min_ea)))
return abso
else:
print("{:x}: rel: {:x}, abso: {:x}".format(ea, rel, abso))
mem(rel).label("ArxanCheck_{}".format(long_to_words(abso - ida_ida.cvar.inf.min_ea)))
return rel
return False
pattern = '48 8b 05 ?? ?? ?? ?? 48 89 45 ?? 48 8d 05 ?? ?? ?? ?? 48 89 45'
return [e for e in FindInSegments(pattern, 'any', None, predicate=predicate_checksummers)]
def find_trace_hooks():
patterns=[
# Hook Tracing
"0f b6 00 0f b6 c0 83 f8 49 0f 85",
"0f b6 40 01 25 f8 00 00 00 3d b8 00 00 00 0f 85",
"0f b6 40 01 48 8b 95 ?? ?? ?? ?? 0f b6 52 0b 33 c2 a8 07 0f 84",
"0f b6 40 01 48 8b 95 ?? ?? ?? ?? 0f b6 52 0c 33 c2 a8 07 0f 85",
"0f b6 40 0a 0f b6 c0 3d ff 00 00 00 0f 85",
"0f b6 40 0a 0f b6 c0 83 f8 41 0f 85",
"0f b6 40 0b 0f b6 c0 3d ff 00 00 00 0f 85",
"0f b6 40 0b 25 f8 00 00 00 3d e0 00 00 00 0f 85",
"0f b6 40 0c 25 f8 00 00 00 3d e0 00 00 00 0f 85",
# Hook Detection
"80 39 ff 74 0e 8a 01 04 17 41 3a c5 76 05 80 39 90",
]
return [FindInSegments(x) for x in patterns]
def find_checksummers4():
patterns = ['D3 E0 33 45 ?? 89 45 ?? 8B 45 ?? E9']
def find_checksummers5():
__ImageBase = ida_ida.cvar.inf.min_ea
struany = """
typedef unsigned char uint8_t;
typedef int int32_t;
typedef unsigned int uint32_t;
struct arxan_range
{
uint32_t start;
uint32_t len;
};
"""
ensure_decl('arxan_range', struany)
def predicate_checksummers(ea):
return False
o_rel = 4
o_abs = 15
o_base = -7
rel = mem(ea).add(o_rel).rip(4).val()
abso = idc.get_qword(mem(ea).add(o_abs).rip(4).val())
base = idc.get_qword(mem(ea).add(o_base).rip(4).val())
if rel == abso and base == __ImageBase:
mem(abso).label("ArxanCheck_{}".format(long_to_words(abso - ida_ida.cvar.inf.min_ea)))
if idc.get_wide_byte(ea + 81) == 0xe8:
mem(ea).add(82).rip(4).label('ArxanGetNextRange').type("void __fastcall f(uint8_t **guide, arxan_range *range);")
mem(ea).add(o_abs).rip(4).label('pArxanChecksum_AbsAddressSelf')
mem(ea).add(o_base).rip(4).label('__ImageBase')
# MakeUnknown(ea, 82 + 4 + 5, DELIT_DELNAMES)
return abso
else:
print("rel: {:x}, abso: {:x}".format(rel, abso))
return False
# any:143c81200 b8 sub_143ADEB2E 48 8d 05 ?? ?? ?? ?? lea rax, [sub_143ADEB2E]
# any:143c81207 b8 sub_143ADEB2E 48 89 45 ?? mov [rbp+0x18], rax
# any:143c8120b b8 sub_143ADEB2E 48 8b 05 ?? ?? ?? ?? mov rax, [off_140D09274]
# any:143c81212 b8 sub_143ADEB2E 48 f7 d8 neg rax
# = '38 48 8d 05 ?? ?? ?? ?? 48 89 45 18 48 8b 05 ?? ?? ?? ?? 48 f7 d8 48 03'
pattern = "48 8d 05 ?? ?? ?? ?? 48 89 45 ?? 48 8b 05 ?? ?? ?? ?? 48 f7 d8"
# which is the same as checksummer original, with a few bytes trimmed on either side.
return [e for e in FindInSegments(pattern, 'any', None, predicate=predicate_checksummers)]
def find_set_return_addresses():
patterns = ['55 48 83 ec 30 48 8d 6c 24 20 48 89 4d 20 48 89 55 28 8b 05']
results = []
for ea in FindInSegments(patterns, 'any'):
ForceFunction(ea)
SetType(ea, "int sub(uint8_t *imagebase, void *arg_0_ptr);")
MemLabelAddressPlus(ea, 'SetReturnAddressTo_{:x}'.format(0x100000000 | idc.get_wide_dword(mem(ea + 0x14).rip(4).val())))
results.append(ea)
return results
def find_lame_memcpys():
patterns = [
'55 48 83 ec 20 48 8d 6c 24 20 48 89 4d 10 48 89 55 18 44 89 45 20 8b 45 20 83 f8 04 0f 82'
# '48 89 6c 24 f8 48 8d 64 24 f8 48 83 ec 20 48 8d 6c 24 20 48 89 4d 10 48 89 55 18 44 89 45 20 8b 45 20 83 f8 04 48 89 6c 24 f8 48 8d 64 24 f8 48 bd 0d',
# '48 8d 64 24 f8 48 89 2c 24 48 83 ec 20 48 8d 6c 24 20 48 89 4d 10 48 89 55 18 44 89 45 20 8b 45 20 83 f8 04 0f 82 ?? ?? ?? ?? e9',
# '55 0f 1f 84 00 00 00 00 00 48 83 ec 20 48 8d 6c 24 20 48 89 4d 10 48 89 55 18 44 89 45 20 8b 45 20 83 f8 04 0f 82 ?? ?? ?? ?? e9',
# '55 48 83 ec 20 48 8d 6c 24 20 48 89 4d 10 48 89 55 18 44 89 45 20 8b 45 20 83 f8 04 0f 82 ?? ?? ?? ?? e9',
]
patterns = [x[0:38] for x in patterns]
results = []
for ea in FindInSegments(patterns, 'any'):
# if idc.get_wide_byte(ea) == 0x48:
# # short pattern
# fnStart = '; '.join([str(x).lower() for x in der(ea)][0:10])
# keyInsns = ['lea rbp, [rsp+0x20]', 'mov [rbp+0x10], rcx', 'mov [rbp+0x18], rdx', 'mov [rbp+0x20], r8d', 'mov eax, [rbp+0x20]']
# found = 0
# for k in keyInsns:
# if k in fnStart:
# found += 1
# if found < 3:
# continue
ForceFunction(ea)
results.append(ea)
# MemLabelAddressPlus(ea, "ArxanMemcpy")
# idc.add_func(ea)
# MemLabelAddressPlus(ea, 'ArxanMemcpy')
# Remove "FAR PROC" attribute and set "BP frame"
if True:
MemLabelAddressPlus(ea, 'ArxanMemcpy')
idc.set_func_flags(ea, (idc.get_func_flags(ea) | 0x10) & ~0x22)
idc.SetType(ea, "void f(uint8_t *dst, uint8_t *src, uint32_t len);") \
or idc.SetType(ea, "void f(BYTE *dst, BYTE *src, unsigned int len);")
refFuncName = FuncRefsTo(ea)
if len(refFuncName) == 1:
for ref in refFuncName:
ref_ea = GetFuncStart(ref)
if not IsSameFunc(ea, eax(ref_ea)):
if HasAnyName(ref_ea):
if not HasUserName(eax(ref_ea)) and idc.get_name(ref_ea, ida_name.GN_VISIBLE).startswith('sub_'):
LabelAddressPlus(eax(ref_ea), "ArxanCallsMemcpy")
else:
suffix = re.sub(r'^[a-zA-Z]+', '', idc.get_name(ref_ea)) # string_between('_', '', mainName)
MemLabelAddressPlus(ea, suffix + 'ArxanMemcpy')
return results
def find_checksum_workers():
# does bad things
patterns = [[
# start sigs
'55 48 83 ec 40 48 8d 6c 24 20 48 89 4d 30 48 89 55 38 33 c0 89 45 08 89',
'48 8d 64 24 f8 48 89 2c 24 48 83 ec 40 48 8d 6c 24 20 48 89 4d 30 48 89 55 38',
], [
# middle sigs
'48 83 c2 01 48 8b 4d 30 48 89 11 3d 80 00 00 00',
'48 8b 45 30 48 8b 00 0f b6 00 83 e0 7f 8b 55 08 89 d1 d3 e0',
'83 45 08 07 48 8b 45 30 48 8b 00 0f b6 00 0f b6 c0']]
results = []
for ea in FindInSegments(patterns[0], 'any'):
results.append(ea)
# MemLabelAddressPlus(ea, "ArxanMemcpy")
if not IsFuncHead(ea):
if not ForceFunction(ea):
print("{:x} ArxanGetNextRange Couldn't ForceFunction".format(ea))
MemLabelAddressPlus(ea, 'ArxanGetNextRange')
# LabelAddressPlus(ea, 'ArxanGetNextRange')
# Remove "FAR PROC" attribute and set "BP frame"
idc.set_func_flags(ea, (idc.get_func_flags(ea) | 0x10) & ~2)
idc.SetType(ea, "void __fastcall f(uint8_t **guide, arxan_range *range);")
refFuncName = FuncRefsTo(ea)
for ref in refFuncName:
if not HasUserName(ref):
MemLabelAddressPlus(idc.get_name_ea_simple(ref), "ArxanChecksumCallsGetNextRange")
return results
def find_decrypted_loadlibs():
# pattern = '55 48 83 ec 20 48 8d 6c 24 20 48 89 4d 10 48 89 55 18 44 89 45 20 8b 45 20 83 f8 04 0f 82 ?? ?? ?? ?? e9 ?? ?? ?? ??'
# pattern = '48 89 85 ?? ?? 00 00 48 8b 85 ?? ?? 00 00 0f b6 00 48 0f be c0 85 c0 0f 84'
pattern = "55 48 81 ec ?? ?? 00 00 48 8d 6c 24 ?? 48 89 9d ?? ?? 00 00"
for ea in [e for e in FindInSegments(pattern, 'any')]:
print(hex(ea))
if can_call('retrace'):
ForceFunction(ea)
if 0:
try:
retrace(ea)
except RelocationTerminalError as e:
print("Exception: RelocationTerminalError: {}".format(e.args))
LabelAddressPlus(ea, 'potential_ciphered_loadlib')
def find_arxan_mutators():
# pattern = '55 48 83 ec 20 48 8d 6c 24 20 48 89 4d 10 48 89 55 18 44 89 45 20 8b 45 20 83 f8 04 0f 82 ?? ?? ?? ?? e9 ?? ?? ?? ??'
# pattern = '48 89 85 ?? ?? 00 00 48 8b 85 ?? ?? 00 00 0f b6 00 48 0f be c0 85 c0 0f 84'
patterns = [
"55 48 81 ec c0 00 00 00 48 8d 6c 24 20 48 89 8d b0 00 00 00 48 c7 45 58 00 00 00 00 48 8d 85 b8 00 00 00 48 89 45 60 48 8b 45 60 48 8b 00 48 83 f8 18",
"48 ?? ?? ?? ?? 48 ?? ?? ?? 48 81 EC A0 00 00 00 48 8D 6C 24 20 48 89 5D ?? 48 89 8D 90 00 00 00 48 C7 45 ?? ?? ?? ?? ?? 48 8D 85 98 00 00 00 48 89 45 ?? 48 8B 45 ?? 48 8B 00 48 83 F8 18 55 48 BD ?? ?? ?? ?? 01 00 00 00 48 87 2C 24 52 53 48 8B 54 24 10 48 BB ?? ?? ?? ?? 01 00 00 00 48 0F 45 D3 48 89 54 24 10 5B 5A C3",
"48 ?? ?? ?? ?? 48 ?? ?? ?? ?? 48 81 EC A0 00 00 00 48 8D 6C 24 20 48 89 5D ?? 48 89 8D 90 00 00 00 48 C7 45 ?? ?? ?? ?? ?? 48 8D 85 98 00 00 00 48 89 45 ?? 48 8B 45 ?? 48 8B 00 48 83 F8 18 55 48 BD ?? ?? ?? ?? 01 00 00 00 48 87 2C 24 52 53 48 8B 54 24 10 48 BB ?? ?? ?? ?? 01 00 00 00 48 0F 45 D3 48 89 54 24 10 5B 5A C3",
]
results = []
for pattern in patterns:
for ea in [e for e in FindInSegments(pattern, 'any')]:
results.append(ea)
print(hex(ea))
LabelAddressPlus(ea, "ArxanCheck_{}".format(long_to_words(ex - ida_ida.cvar.inf.min_ea)))
return results
def find_vortex():
patterns = [ "C1 E2 04 8D 04 42 8B 55 ?? C1 E2 07 03 C2 8B 55 ?? C1 E2 08 03 C2 8B 55 ?? C1 E2 18 03 C2 03 45" ]
results = []
for pattern in patterns:
for ea in [e for e in FindInSegments(pattern, 'any')]:
results.append(ea)
fnloc = GetFuncStart(ea)
if HasUserName(fnloc):
fnname = GetFuncName(fnloc)
if fnname.startswith("Arxan"):
if 'Vortex' not in fnname:
LabelAddressPlus(fnloc, fnname.replace('Arxan', 'ArxanVortex'))
continue
LabelAddressPlus(ea, 'OrphanedArxanVortex')
return results
def find_setreturn():
results = []
for ea in _.flatten(FuncRefsTo(FunctionsMatching('SetReturnAddressTo'))):
results.append(ea)
fnloc = eax(ea)
if HasUserName(fnloc):
fnname = GetFuncName(fnloc)
if fnname.startswith("Arxan"):
if 'SetsReturn' not in fnname:
LabelAddressPlus(fnloc, fnname.replace('Arxan', 'ArxanSetsReturn'))
continue
LabelAddressPlus(fnloc, 'OrphanedArxanSetsReturn')
return results
def find_antidebug():
results = []
s = FuncRefsTo(['GetCurrentProcess', 'FreeLibrary', 'CloseHandle', 'AddVectoredExceptionHandler', 'RemoveVectoredExceptionHandler', 'SetUnhandledExceptionFilter'])
for ea in set(s[0]).intersection(s[4]):
results.append(ea)
fnloc = eax(ea)
if HasUserName(fnloc):
fnname = GetFuncName(fnloc)
if fnname.startswith("Arxan"):
if 'AntiDebug' not in fnname:
LabelAddressPlus(fnloc, fnname.replace('Arxan', 'ArxanAntiDebug'))
continue
LabelAddressPlus(fnloc, 'OrphanedArxanAntiDebug')
return results
def find_rolls():
patterns = [ '51 8b 4d ?? d3 45 ?? 59', '51 8B 8D ?? ?? ?? ?? D3 85 ?? ?? ?? ?? 59']
results = []
for pattern in patterns:
for ea in [e for e in FindInSegments(pattern, 'any')]:
results.append(ea)
fnloc = GetFuncStart(ea)
if HasUserName(fnloc):
fnname = GetFuncName(fnloc)
if fnname.startswith("Arxan"):
if 'Roll' not in fnname:
LabelAddressPlus(fnloc, fnname.replace('Arxan', 'ArxanRoll'))
continue
LabelAddressPlus(ea, 'OrphanedArxanRoll')
return results
def fix_obfu_scan():
patched = []
for ea in [e for e in FindInSegments('48 8D 64 24 F8 48 89 2C 24', 'any')]:
obfu._patch(ea)
patched.append(ea)
for ea in [e for e in FindInSegments('48 89 6C 24 F8 48 8D 64 24 F8', 'any')]:
obfu._patch(ea)
obfu._patch(ea)
patched.append(ea)
for ea in _.uniq(patched):
obfu._patch(ea)
EaseCode(ea, noExcept=1, forceStart=1)
def fix_old_balances():
patterns = [
# '48 8d 64 24 f8 48 89 2c 24 48 8d 2d 76 31 ff ff 48 87 2c 24 55 48 8d 2d 30 5a 48 00 48 87 2c 24 c3',
'48 8d 64 24 f8 48 89 2c 24 48 8d 2d ?? ?? ?? ?? 48 87 2c 24 55 48 8d 2d ?? ?? ?? ?? 48 87 2c 24 c3',
# 'e8 47 5a 48 00 e9 7c 31 ff ff 0f 1f 84 00 00 00 00 00 0f 1f 84 00 00 00 00 00 0f 1f 80 00 00 00 00',
# 'e8 ?? ?? ?? ?? e9 ?? ?? ?? ?? 0f 1f 84 00 00 00 00 00 0f 1f 84 00 00 00 00 00 0f 1f 80 ?? ?? ?? ??')
'48 89 6c 24 f8 48 8d 64 24 f8 48 8d 2d ?? ?? ?? ?? 48 87 2c 24 55 48 8d 2d ?? ?? ?? ?? 48 87 2c 24 c3'
]
for pattern in patterns:
for ea in [e for e in FindInSegments(pattern, 'any')]:
print("test: {:x}".format(ea))
MyMakeUnknown(ea, 99 // 3, DELIT_EXPAND)
m = membrick_memo(ea, pattern=pattern)
# asm = nassemble(ea, "call 0x{:x}; jmp 0x{:x}".format(m.add(72//3).rip(4).ea, m.add(36//3).rip(4).ea))
asm = nassemble(ea, "call 0x{:x}; jmp 0x{:x}".format(m.autorip(1).ea, m.autorip(0).ea))
PatchBytes(ea, asm, "BalanceJump")
PatchNops(ea + 10, (1 + len(pattern)) // 3 - 10, "BalanceJumpSpare")
if not IsCode_(ea):
EaseCode(ea, (1 + len(pattern)) // 3, forceStart=1)
fix_location_plus_2(ea, code=1)
fix_location_plus_2(ea + 5, code=1)
if IsFunc_(ea + 10):
if IsSameFunc(ea + 10, ea - 10):
ZeroFunction(ea - 10)
else:
SetFuncEnd(ea + 10, ea + 10)
fix_obfu_scan()
def find_judges(count=3, notcode=None):
# pattern = '55 48 83 ec 20 48 8d 6c 24 20 48 89 4d 10 48 89 55 18 44 89 45 20 8b 45 20 83 f8 04 0f 82 ?? ?? ?? ?? e9 ?? ?? ?? ??'
# pattern = '48 89 85 ?? ?? 00 00 48 8b 85 ?? ?? 00 00 0f b6 00 48 0f be c0 85 c0 0f 84'
patterns = [
"6a 10 48 f7 c4 0f 00 00 00 0f 85 ?? ?? ?? ?? e9",
"68 10 00 00 00 48 f7 c4 0f 00 00 00 0f 85 ?? ?? ?? ?? e9",
"6a 10 e8 ?? ?? ?? ?? 48 8d 64 24 08 0f 1f 00 e9"
]
notcode = A(notcode)
results = []
for pattern in patterns:
for ea in [e for e in FindInSegments(pattern, 'any')]:
if not IsCode_(ea) or not IsCode_(idc.prev_not_tail(ea)):
print("not code: {:#x}".format(ea))
notcode.append(ea)
continue
while IsFlow(ea):
ea = idc.prev_not_tail(ea)
n = 0
prev = prev_insn_match(ea, idaapi.NN_call, (idc.o_near, 0), comment='call Balance_')
while prev:
ea = prev
n += 1
prev = prev_insn_match(ea, idaapi.NN_call, (idc.o_near, 0), comment='call The*')
# dprint("[debug] ea, n")
print("[debug] ea: {}, n: {}".format(ahex(ea), ahex(n)))
if n == count:
results.append(ea)
return results
def process_notcode(l):
for ea in l:
ea = idc.prev_not_tail(ea)
while not IsCode_(ea):
ea = idc.prev_not_tail(ea)
try:
EaseCode(idc.next_not_tail(ea), forceStart=1)
except AdvanceFailure:
pass
def find_checksummers_from_balances():
# pattern = '55 48 83 ec 20 48 8d 6c 24 20 48 89 4d 10 48 89 55 18 44 89 45 20 8b 45 20 83 f8 04 0f 82 ?? ?? ?? ?? e9 ?? ?? ?? ??'
# pattern = '48 89 85 ?? ?? 00 00 48 8b 85 ?? ?? 00 00 0f b6 00 48 0f be c0 85 c0 0f 84'
patterns = [
"6A 10 48 F7 C4 0F 00 00 00 0F 85 ?? ?? ?? ?? E9",
"68 10 00 00 00 48 F7 C4 0F 00 00 00 0F 85 ?? ?? ?? ?? E9",
"6a 10 e8 ?? ?? ?? ?? 48 8d 64 24 08 0f 1f 00 e9"
]
results = []
balances = []
for pattern in patterns:
for ea in [e for e in FindInSegments(pattern, 'any')]:
try:
r = AdvanceToMnemEx(ea, term=('call', 'retn'), inclusive=1, ease=1)
sti = CircularList(r)
# push 0x10 test rsp, 0xf jnz sub_143BE71D6 push 0x18 sub rsp, 8 call ArxanCheck_owe_bound_alert
m = sti.multimatch([
r'(.*)**?',
r'push.*0x10',
r'test rsp, 0xf',
r'jnz .*',
r'push.*0x18',
r'(add|sub) rsp, .*',
# r'(mov|lea).*r[sb]p.*r[sb]p',
# r'(mov|lea).*r[sb]p.*r[sb]p',
# r'lea rbp, \[rel ({jmp}\w+)]',
# r'xchg \[rsp], rbp',
# r'push rbp',
# r'lea rbp, \[rel ({call}\w+)]',
# r'xchg \[rsp], rbp',
# r'retn?',
# r'(.*)**',
r'call ({call}\w+)',
]) or sti.multimatch([
# r'(.*)**?',
r'push 0x10',
r'call ({call}\w+)',
# r'lea rsp, \[rsp[+]8\]',
# r'(.*)**',
])
target = None
if not m:
print("no multimatch: {}".format(" ".join([str(x) for x in sti.as_list()])))
else:
target = m['call'][0]
print("find_checksummers_from_balances.multimatch: {}".format(target))
if target or r and r.insns:
if r.insns:
print("find_checksummers_from_balances.r.insns: {}".format(r.insns[-1]))
insns_target = string_between(' ', '', str(r.insns[-1]))
print("found check: {} {}".format(ahex(eax(target)), ahex(eax(insns_target))))
if not IsCode_(target):
EaseCode(ea, forceStart=1)
if isUnconditionalJmpOrCall(eax(target)):
print(" isUnconditionalJmpOrCall")
continue
results.append(eax(target))
if not HasUserName(eax(target)):
LabelAddressPlus(eax(target), "ArxanCheck_{}".format(long_to_words(eax(target) - ida_ida.cvar.inf.min_ea)))
# Find start of balance
while IsFlow(ea):
ea = idc.prev_not_tail(ea)
prev = prev_insn_match(ea, idaapi.NN_call, (idc.o_near, 0), comment='call Balance_')
if prev:
# if IsFunc_(ea) and IsFuncHead(GetChunkStart(ea)):
LabelAddressPlus(ea, "Balance_{}".format(long_to_words(eax(target) - ida_ida.cvar.inf.min_ea)), force=1)
balances.append(ea)
except AdvanceFailure:
pass
ida_retrace(balances, zero=1, smart=1, extend=0, noDone=1, func=1)
return results # , balances
def find_rbp_frame():
patterns = ["55 48 81 ec ?? ?? 00 00 48 8d 6c 24 ??",
"55 48 83 EC ?? 48 8D 6C 24 ??",
"48 89 6c 24 f8 48 8d 64 24 f8 48 81 ec ?? ?? 00 00 48 8d 6c 24 ??",
"48 89 6c 24 f8 48 8d 64 24 f8 48 83 EC ?? 48 8D 6C 24 ??"
]
# b1180
# any:0000000143ADEB2E 000 48 89 6C 24 F8 mov [rsp+var_8], rbp ; [PatchBytes] mov/lea->push order swap: rbp
# any:0000000143ADEB2E ; [PatchBytes] lea rsp, qword ptr [rsp-8]; mov [rsp], rbp
# any:0000000143ADEB33 000 48 8D 64 24 F8 lea rsp, [rsp-8]
# any:0000000143ADEB38 008 48 81 EC ?? ?? 00 00 sub rsp, 0B0h
# any:0000000143ADEB3F 0B8 48 8D 6C 24 20 lea rbp, [rsp+20h]
results = []
for pattern in patterns:
for ea in FindInSegments(pattern, 'any'):
ea = idc.get_item_head(ea)
next_ea = ea + (len(pattern) + 1) // 3
ida_disasm = idc.generate_disasm_line(next_ea, idc.GENDSM_FORCE_CODE)
mnem = string_between('', ' ', ida_disasm)
print(hex(ea), ida_disasm)
TagAddress([ea], "rbp_frame")
results.append(ea)
return results
def find_stack_align_adjust():
# .text:0000000143765941 6A 10 push 10h
# .text:0000000143765943 48 F7 C4 0F 00 00 00 test rsp, 0Fh
# .text:000000014376594A 0F 85 ?? ?? ?? ?? jnz loc_1438E5D8C
# .text:0000000143765950 E9 51 BF 5C FD jmp loc_140D318A6
# .text:0000000143765941 6A 10 push 10h
# .text:0000000143765943 E8 ?? ?? ?? ?? call ArxanCheck_mama_dive_orgy
# .text:0000000143765948 48 8D 64 24 08 lea rsp, [rsp+8]
# .text:000000014376594D 0F 1F 00 nop dword ptr [rax]
# .text:0000000143765950 E9 51 BF 5C FD jmp loc_140D318A6
patterns = ["6a 10 48 f7 c4 0f 00 00 00 0f 85 ?? ?? ?? ?? e9", "6a 10 e8 ?? ?? ?? ?? 48 8d 64 24 08 0f 1f 00 e9"]
results = FindInSegments(patterns, 'any')
starts = []
for ea in results:
# print(hex(ea), idc.generate_disasm_line(ea, idc.GENDSM_FORCE_CODE))
# if HasUserName(ea): LabelAddressPlus(ea, '')
if debug: print("find_stack_align_adjust: 0x{:x}".format(ea))
fnStart = destart(ea, 0xa8)
if fnStart is None:
print("[find_stack_align_adjust] couldn't trace back from {:x}".format(ea))
continue
length = ea - fnStart
if False:
while diida(fnStart - 1).startswith("push"):
fnStart -= 1
if not fnStart:
continue
while idc.get_wide_byte(fnStart - 1) == 0x41 or idc.get_wide_byte(fnStart - 2) == 0x41:
if idc.get_wide_byte(fnStart - 2) == 0x41:
fnStart -= 2
if idc.get_wide_byte(fnStart - 1) == 0x41:
fnStart -= 1
if IsTail(fnStart):
print("[find_stack_align_adjust] shifting to head of {:x}".format(fnStart))
fnStart = idc.get_item_head(fnStart)
if length > 48:
# ForceFunction(fnStart)
print(hex(fnStart), hex(ea), idc.generate_disasm_line(fnStart, idc.GENDSM_FORCE_CODE))
push_count, new_ea, unused2 = CountConsecutiveMnem(fnStart, ["push", "pushf", "pushfq"])
if push_count > 8 or diida(new_ea) == 'test rsp, 0xf':
# TagAddress([fnStart], "stack_align")
starts.append(fnStart)
else:
print("[find_stack_align_adjust] skipping short function (length: {})".format(length))
return starts
# if can_call('retrace'):
# if not IsFuncHead(fnStart):
# ForceFunction(fnStart)
# ZeroFunction(fnStart)
# try:
# retrace(fnStart)
# except RelocationTerminalError as e:
# print("Exception: RelocationTerminalError: {}".format(e.args))
def find_imagebase_offsets():
base = ida_ida.cvar.inf.min_ea
r = xrefs_to(base)
un = [x for x in r if Qword(x) == base]
for x in un:
LabelAddressPlus(x, 'o_imagebase')
# del retrace
# def retrace(ea, *args, **kwargs):
# global retrace_later
# retrace_later.add(ea)
#
# retrace_later = set()
# sprint = print
def find_all_checksummers():
cs = find_checksummers0()
cs.extend( find_checksummers1() )
cs.extend( find_checksummers1() )
cs.extend( find_checksummers2() )
cs.extend( find_checksummers4() )
cs.extend( find_checksummers5() )
cs.extend( find_checksummers3() )
cs.extend( find_checksummers6() )
return cs
def find_shifty_stuff():
results = {}
setglobal('shifty', results)
idc.batch(0)
print("find_shifty_stuff()")
pp(obfu)
print("{}".format("arxan_mutators"))
# print("{}".format("rbp_frame"))
# results['rbp'] = find_rbp_frame()
r = {}
print("cs0")
cs0 = find_checksummers_from_balances(); print("checksummers_0: {}".format(hex(cs0)))
print("cs1")
cs1 = find_checksummers1(); print("checksummers: {}".format(hex(cs1)))
print("cs2")
cs2 = find_checksummers2(); print("checksummers2: {}".format(hex(cs2)))
print("cs4")
cs4 = find_checksummers4(); print("checksummers4: {}".format(hex(cs4)))
print("cs5")
cs5 = find_checksummers5(); print("checksummers5: {}".format(hex(cs5)))
print("cs3")
cs3 = find_checksummers3(); print("checksummers3: {}".format(hex(cs3)))
print("cs6")
cs6 = find_checksummers6(); print("checksummers6: {}".format(hex(cs6)))
results['cs'] = [cs0, cs1, cs2, cs3, cs4, cs5, cs6]
# print("checksummers...")
# print([idc.get_func_name(x) for x in r])
# LabelManyAddresses(r, "ArxanChecksumTest", force=1)
# retrace_list(r)
print("{}".format("lame_memcpys"))
results['memcpy'] = find_lame_memcpys()
# retrace_list(r)
# results['csworkers'] = find_checksum_workers()
# retrace_list(r)
# print("{}".format("decrypted_loadlibs"))
# find_decrypted_loadlibs()
print("{}".format("stack_align_adjust"))
results['balance'] = []
# results['balance'] = find_stack_align_adjust()
print("{}".format("imagebase_offsets"))
find_imagebase_offsets()
if False:
for ea in [GetFuncStart(x) for x in FindInSegments("8b 05 ?? ?? ?? ?? 0f af 05 ?? ?? ?? ?? 8b 15 ?? ?? ?? ??")]:
AddTag(ea, "seldom")
# LabelManyAddresses(results['cs'][0], "ArxanCheckFunction__0", force=1)
# LabelManyAddresses(results['cs'][0], "ArxanCheckFunction__1", force=1)
# LabelManyAddresses(results['cs'][1], "ArxanCheckFunction__2", force=1)
# LabelManyAddresses(results['cs'][2], "ArxanCheckFunction__3", force=1)
# LabelManyAddresses(results['csworkers'], "ArxanGetNextRange", force=1)
for ea in results['balance']:
if not ean(ea).startswith('ArxanBalance'):
LabelAddressPlus(ea, 'ArxanBalance')
# LabelManyAddresses(results['balance'], "ArxanBalance", force=1)
for ea in results['balance']:
Commenter(ea, 'line').remove('[DENY JMP]')
LabelManyAddresses(results['memcpy'], "ArxanMemcpy", force=1)
results['rol'] = find_rolls()
results['setret'] = find_setreturn()
results['vortex'] = find_vortex()
results['setra'] = find_set_return_addresses()
return results
def DoesFuncReturn(ea=None):
"""
DoesFuncReturn
@param ea: linear address
"""
ea = eax(ea)
return ida_funcs.func_does_return(ea)
def IsFarFunc(ea=None):
"""
Is function FAR
calls idc.get_func_flags(ea) & 0x22
@param ea: linear address
@return combination of FUNC_FAR - 0x02 and FUNC_USERFAR - 0x20
"""
ea = eax(ea)
return idc.get_func_flags(ea) & 0x22
def SetFarFunc(ea=None, flags=None):
"""
Is function FAR
calls idc.set_func_flags(ea) & 0x22
@param ea: linear address
@return: !=0 - ok
"""
ea = eax(ea)
if not flags:
flags = 0
elif flags and flags & 0x22 == 0:
flags = 0x22
return idc.set_func_flags(ea, (idc.get_func_flags(ea) & ~0x22) | flags & 0x22)
def FixFarFuncs():
[SetFarFunc(x, 0) for x in Functions() if IsFarFunc(x)]
def StripTags(s):
return string_between("_$.", "$", s, repl='', greedy=1)
def TagGetTagSubstring(s):
return string_between("_$.", "$", s, greedy=1)
def HasTags(s):
return "_$." in s
def TagRemoveSubstring(s):
# for tag in TagGetTagSubstring(s):
r = string_between("_$.", "$", s, greedy=0, inclusive=1, repl='')
return r
def TagAddSubstring(s, t):
r = s + t
return r
def TagGetTagsFromSubstring(s):
tags = [x for x in TagGetTagSubstring(s).split('.') if x]
if not tags:
return []
return list(set(tags))