-
Notifications
You must be signed in to change notification settings - Fork 1
/
zmqclient.py
760 lines (675 loc) · 25.6 KB
/
zmqclient.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
import re
import idc
import idaapi
# import Commenter
# Commenter = commenter.Commenter
# from commenter import Commenter
from idc import *
import idautils, os, sys, re, json, zmq
import socket as Socket
import zmq
from datetime import datetime
import time
from exectools import execfile, make_refresh
from superglobals import getglobal
from underscoretest import _
# requirements
# from itertools import islice
# sf_is_flags
abort_file = os.path.dirname(os.path.abspath(__file__)) + '/.abort'
refresh_zmqclient = make_refresh(os.path.abspath(__file__))
noExists = True
noUnmatched = False
pending_functions = []
def days_between(d1, d2):
d1 = datetime.strptime(d1, "%Y-%m-%d")
d2 = datetime.strptime(d2, "%Y-%m-%d")
return abs((d2 - d1).days)
# Commenter = _require("commenter").Commenter
zmqfake = False
port = "5558"
host = "gf.local"
host = "localhost"
remote_version = ''
local_version = idc.GetIdbPath().split('\\')[2]
socket = getglobal('_zmq_socket', None, _set=1)
remote_version = 'unknown'
def zmq_connect():
global context, socket, zmlog
# global context, socket, zmlog
if hasattr(globals(), 'context') and not context.closed:
context.destroy()
zmq.Context().destroy()
if zmqfake:
remote_version = 'fake'
return
context = zmq.Context()
zmclient.context = context
print("Connecting to server...")
socket = context.socket(zmq.REQ)
socket.connect("tcp://%s:%s" % (host, port))
socket.RCVTIMEO = 90000
socket.SNDTIMEO = 5000
socket.setsockopt(zmq.LINGER, 1000)
remote_version = 'unknown'
def EA():
return ScreenEA()
def GetFuncStart(ea):
"""
Determine a new function boundaries
@param ea: address inside the new function
@return: if a function already exists, then return its end address.
If a function end cannot be determined, the return BADADDR
otherwise return the end address of the new function
"""
func = idaapi.get_func(ea)
if not func:
return BADADDR
return func.start_ea
def GetFuncEnd(ea):
"""
Determine a new function boundaries
@param ea: address inside the new function
@return: if a function already exists, then return its end address.
If a function end cannot be determined, the return BADADDR
otherwise return the end address of the new function
"""
func = idaapi.get_func(ea)
if not func:
return BADADDR
return func.end_ea
def VtableRefsTo(ea):
result = []
for xref in XrefsTo(ea, 0):
if isinstance(xref.frm, int):
if get_segm_name(xref.frm) == '.rsrc':
result.append(xref.frm)
# print(xref.type, XrefTypeName(xref.type), 'from', hex(xref.frm), 'to', hex(xref.to))
return result
def GetFuncSize(ea):
return GetFuncEnd(ea) - GetFuncStart(ea)
def IsChunked(ea):
# return idc.get_fchunk_attr(address, FUNCATTR_START) < BADADDR
return len(list(idautils.Chunks(ea))) > 1
def mark(ea, comment):
c = Commenter(ea, 'func')
if not c.exists(comment):
c.add(comment)
def check(ea, comment):
c = Commenter(ea, 'func')
return c.exists(comment)
def check_re(ea, comment):
c = Commenter(ea, 'func')
return [c for c in c.matches(comment)]
def byteify(input):
"""
Turns JSON data into ASCII
"""
if isinstance(input, dict):
return {byteify(key): byteify(value)
for key, value in input.items()}
elif isinstance(input, (list, set, tuple)):
return [byteify(element) for element in input]
elif isString(input):
return asBytesRaw(input)
else:
return input
def unbyteify(input):
"""
Turns JSON data into ASCII
"""
if isinstance(input, dict):
return {unbyteify(key): unbyteify(value)
for key, value in input.items()}
elif isinstance(input, (list, set, tuple)):
return [unbyteify(element) for element in input]
elif isBytes(input):
return asStringRaw(input)
else:
return input
def zmq_sleep():
try:
sleep_time_total = 10000
sleep_time_interval = 100
sleep_times = sleep_time_total / sleep_time_interval
for r in sleep_times:
idc.qsleep(sleep_time_interval)
if os.path.exists(abort_file):
print("W: .abort found, stopping")
sys.exit()
except KeyboardInterrupt:
print("W: interrupt received, stopping")
sys.exit()
def zrequest_exists(j):
global zmqfake
if zmqfake:
return False
request = asString(json.dumps(j)) # .encode('ascii')
retries = 4
while retries:
try:
socket.send_string(request, zmq.NOBLOCK)
except KeyboardInterrupt:
print("W: interrupt received, stopping")
sys.exit()
except zmq.error.Again as e:
print("zmq.error.Again: {}".format(str(e)));
zmq_sleep()
retries = retries - 1
continue
# except Exception as e:
# print("Exception!!!!")
# print(str(e))
# return 0
break
if retries:
retries = 3
while retries:
if os.path.exists(abort_file):
print("Aborted due to presence of {}".format(abort_file))
raise Exception("Aborted")
try:
message = socket.recv()
# print("Received reply: [ %s ]" % message)
except zmq.error.Again as e:
print("zmq.error.Again: {}".format(str(e)));
zmq_sleep()
retries = retries - 1
continue
except KeyboardInterrupt:
print("W: interrupt received, stopping")
sys.exit()
# except Exception as e:
# print("Exception!!!!")
# print(str(e))
# return 0
break
try:
try:
p = json.loads(message)
if isinstance(p, str):
p = json.loads(p)
return p
except json.decoder.JSONDecodeError as e:
print("JSONDecodeError: {} reading {} @{}".format(e.msg, e.doc, e.pos))
raise e
# p = byteify(json.loads(message.decode('ascii')))
# print(p)
# if type(p['exists']) is int:
# return p['version']
except:
pass
return False
if 'pf' not in globals():
def pf(a):
return a
pfh = pf
def zrequest(j):
request = asBytes(json.dumps(j).replace('Concurrency::details::HardwareAffinity', 'void*')) # .encode('ascii')
retries = 10
while retries:
retries = retries - 1
try:
if debug: print("retry #{} message:\n{}\n".format(retries, pfh(asString(request))))
if os.path.exists(abort_file):
print("Aborted due to presence of {}".format(abort_file))
raise Exception("Aborted")
socket.send(request, zmq.NOBLOCK)
# except Exception as e:
# print("Exception!!!!")
# print(str(e))
# return 0
except KeyboardInterrupt:
print("W: interrupt received, stopping")
sys.exit()
except zmq.error.InterruptedSystemCall as e:
print("interupted system call: {}".format(str(e)))
raise()
except zmq.error.Again as e:
print("zmq.error.Again: {}".format(str(e)));
continue
except zmq.error.ContextTerminated as e:
print("context terminated: {}".format(str(e)))
raise
except zmq.error.ZMQError as e:
print("zmqerror: {}".format(str(e)))
raise
break
if retries:
retries = 10
while retries:
retries = retries - 1
print("zrequest: waiting for response")
try:
message = socket.recv()
if not message:
print("W: message was {}".format(type(message)))
return 0
except KeyboardInterrupt:
print("W: interrupt received, stopping")
return 0
except zmq.error.Again as e:
print("zmq.error.Again: {}".format(str(e)));
continue
# print("Received reply: [ %s ]" % message)
try:
try:
p = json.loads(message)
except json.decoder.JSONDecodeError as e:
print("JSONDecodeError: {} reading {} @{}".format(e.msg, e.doc, e.pos))
return None
raise e
# print(p)
# if type(p['label']) is str:
# mark(ea, "[PATTERN;AKA:%s] '%s'" % (p['version'], p['label']));
# # c = Commenter(p, 'func')
# # commentMarker = "aka: %s" % name
# # if not c.exists(commentMarker):
# # c.add(commentMarker)
# if type(p['decl']) is str:
# mark(ea, "[PATTERN;DECL:%s] '%s'" % (p['version'], p['decl']));
return p
# if type(p['matches']) is int:
# return p['matches']
# if p['matches'] > 1:
# return p['matches']
except KeyboardInterrupt:
print("W: interrupt received, stopping")
sys.exit()
# except:
# print("exception sending")
# pass
return 0
else:
return -1
def ignore_function_name(fnName):
if re.match(r'^(SYSTEM|APP|AUDIO|BRAIN|CAM|CLOCK|CUTSCENE|DATAFILE|DECORATOR|DLC|ENTITY|EVENT|FILES|FIRE|GRAPHICS|HUD|INTERIOR|ITEMSET|LOADING|LOCALE|MISC|NETCASH|MOBILE|NETSHOP|NETWORK|OBJECT|PAD|PATHFIND|PED|PHYSICS|PLAYER|RECORDING|RENDERING|SCRIPT|SHAPETEST|SOCIALCLUB|STATS|STREAMING|\
TASK|VEHICLE|WATER|WEAPON|ZONE|NATIVE)(::|__)',
fnName, re.I):
return True
if 'Arxan' in fnName:
return True
if 'FromNative' in fnName:
return True
if 'BACK' in fnName:
return True
if (False
or not fnName
or len(fnName) < 2
or re.match(r".*arxan", fnName, re.I)
or re.match(r".*_BACK_", fnName)
or fnName.find('::m_') > -1
or fnName.find( "$" ) > -1
or fnName[0] == "$"
or fnName[0] == "_"
or fnName[0] == "?"
or fnName[0:2] == "j_"
or fnName.find('unknown_libname_') > -1
or re.match(r"^jJSub", fnName)
or re.match(r"\?", fnName)
or re.match(r"(::_0x|___0x)", fnName)
or len(VtableRefsTo(eax(fnName))) > 0
or (idc.get_type(eax(fnName)) and '#' in idc.get_type(eax(fnName)))
or re.match(r".*_impl[_0-9]+$", fnName, re.IGNORECASE)
):
return True
return False
def has_uniq_sig(ea=None):
"""
has_uniq_sig
@param ea: linear address
"""
ea = eax(ea)
fnStart = GetFuncStart(ea)
fnEnd = GetFuncEnd(ea)
if IsChunked(fnStart):
return False
pattern = " ".join(make_sig(get_bytes_chunked(fnStart, fnEnd, 128), fnStart))
# pattern = pattern[0:(3*64)-1]
if isInt(sig_reducer(pattern, quick=1)):
return False
return True
def prepend_search(ea):
global pending_functions
pending_functions.append(ea)
def add_alt_matches(ea):
subs = []
for x in xrefs_to(ea):
if HasUserName(x) and has_uniq_sig(x):
prepend_search(x)
break
if len(subs):
# This doesn't guarantee it will be picked up later, but it might be
return
for x in xrefs_to(ea):
if not HasUserName(x) and has_uniq_sig(x):
prepend_search(x)
subs.append(x)
break
def sig_maker_auto_zmq(ea, colorise=False, force=False, special=False):
global noExists
global noUnmatched
global remote_version
_exists = 0
ignore_existing_pattern = 0
fnName = GetFunctionName(ea)
fnStart = LocByName(fnName)
fnEnd = FindFuncEnd(fnStart)
fnFlags = idaapi.get_flags(fnStart)
pattern = ""
# if idaapi.has_dummy_name(fnFlags) or not idaapi.has_any_name(fnFlags) or fnName.find('::') > -1 or fnName.find('NATIVES') == 0 or fnName[0] == "$" or fnName[0] == "?" or fnName.find('_BACK_') > -1 or fnName.find('unknown_libname_') > -1 or re.match(r"^jJSub", fnName) != None:
if not force:
# dprint("[sigmaker] fnName")
if debug: print("[sigmaker] fnName:{}".format(fnName))
if not special:
if idaapi.has_dummy_name(fnFlags) \
or not idaapi.has_any_name(fnFlags) \
or IsChunked(fnStart) \
or ignore_function_name(fnName):
# print("%s: skipping" % (fnName))
return
if len(VtableRefsTo(ea)) > 0:
print(("%s: skipping vtable functions" % fnName))
return
if Byte(ea) == 0xe9:
if debug: print(("%s: skipping thunk" % fnName))
return
if check(ea, "[PATTERN;MULTIPLE]"):
print("%s: skipping marked multiple" % fnName)
# if colorise:
# SetColor(fnStart, CIC_FUNC, DEFCOLOR)
# return
if colorise:
if check_re(ea, r"\[PATTERN;UNMATCHED:" + remote_version):
SetColor(fnStart, CIC_FUNC, 0x0088ff)
print(("%s: skipping unmatched" % fnName))
return
return
pattern = r"\[PATTERN;(EXISTS|MULTIPLE|UNMATCHED):" + remote_version
if noExists:
pattern = pattern.replace('EXISTS', 'XEXISTSX')
if noUnmatched:
pattern = pattern.replace('UNMATCHED', 'XUNMATCHEDX')
_exists = False
# quick hack to allow only updating already existing things (e.g. if xfer crashed)
# if remote_version != 'unknown' and not check_re(ea, r"\[PATTERN;(EXISTS):" + remote_version):
# print("%s: skipping on remote " % fnName + " (doesn't exist))")
# return
if check_re(ea, r"\[PATTERN;(E____S|MULTIPLE|UNMATCHED):" + remote_version):
# if check_re(ea, r"\[PATTERN;UNMATCHED:" + remote_version):
for x in check_re(ea, r"\[PATTERN;(E____S|MULTIPLE|UNMATCHED):" + remote_version):
print("%s: skipping on remote " % fnName + " (" + string_between('PATTERN;', ':', x) + ")")
return
# if check_re(ea, r"\[PATTERN;(XXXXXX|MULTIPLE|UNMATCHED):" + remote_version):
# print("%s: skipping previously tried" % fnName)
# return
pattern = ""
rv = check_re(ea, r"\[PATTERN;SHORTEST:")
for r in rv:
if debug: print(("found existing pattern comment: %s" % r))
m = re.match(r"\[PATTERN;SHORTEST:\w+] '(.*)'", r)
if m:
pattern = m.group(1)
if debug: print(("found existing pattern: %s" % pattern))
break
# print("%s: skipping previously processed" % fnName)
# return
# XXX
if remote_version and False:
if check_re(ea, r"\[PATTERN[^]]+:" + remote_version):
print("comment says sent; skipping")
return
# if not remote_version and not special:
if True:
desc = TagRemoveSubstring(fnName)
rv = zrequest_exists({'cmd':'aob', 'pattern':[], 'description':desc, 'address':ea, 'decl':''})
if rv and isinstance(rv, object):
# (b'{"cmd": "aob", "pattern": [], "description": "pureVirtualFunctionPtr",
# "address": 5368713216, "decl": "", "_exists": 1}')
if 'version' in rv:
remote_version = rv['version']
# XXX
if 'exists' in rv and rv['exists'] == 1 and 'address' in rv:
_address = rv['address']
if debug: print("type address: {}".format(type(_address)))
_exists = _address
if debug: print("type address: {}".format(type(_exists)))
if debug: print("_exists: {:x} {:x}".format(rv['address'], _exists))
if debug: print(("\n\n\n%s: already _exists on target" % fnName))
# XXX
# mark(ea, "[PATTERN;EXISTS:%s]" % (remote_version));
if not _exists:
# XXX
# return
if check_re(ea, r"\[PATTERN;MULTIPLE"):
for c in check_re(ea, r"\[PATTERN;MULTIPLE"):
qualifier = string_between(':', ']', c)
elapsed = ''
version = ''
if qualifier:
try:
r = time.strptime(qualifier, '%Y-%m-%d')
elapsed = (datetime.now() - datetime(r[0], r[1], r[2])).total_seconds() / 86400
except ValueError:
pass
if not elapsed:
version = qualifier
print("pattern;multiple: {}, {}".format(elapsed, version))
return
# return
# pattern = " ".join(make_sig(get_bytes_chunked(fnStart, fnEnd, 24), fnStart, fnEnd))
# pattern = pattern[0:(3*64)-1]
# if len(pattern) < (3 * 6) or pattern[0:2] == "e9":
# return
# rv = zrequest({'cmd':'aob', 'pattern':pattern, 'description':fnName, 'address':ea})
# if rv == 0:
# raise Exception("error")
# if rv > 1:
_old_globals=[]
_subs = []
_globals = []
if not _exists and (ignore_existing_pattern or len(pattern) == 0):
if debug: print(("%s: making pattern" % fnName))
# this will make subs or globals or smth
# get_instructions_chunked(fnStart, fnEnd, 1024, _globals = _old_globals)
# _subs = sig_subs(fnStart, filter=lambda fnLoc, fnName: not ignore_function_name(fnName))
_globals = sig_globals(fnStart, fullFuncTypes=True)
pattern = " ".join(make_sig(get_bytes_chunked(fnStart, fnEnd, 128), fnStart))
# pattern = pattern[0:(3*64)-1]
pattern = sig_reducer(pattern, quick=1)
if isinstance(pattern, str):
mark(ea, "[PATTERN;SHORTEST:%s] '%s'" % (time.strftime('%Y-%m-%d'), pattern));
elif isinstance(pattern, int):
if pattern != 1:
if debug: print(("%s: multiple matches (%d)" % (fnName, pattern)))
add_alt_matches(fnStart)
return
# rl = []
# for r in [24, 36, 48]:
# res = sig_maker_ex(ea, chunk=r, quick=0, comment=1)
# if res:
# rl.extend(res)
# if not rl: # res:
# mark(ea, "[PATTERN;MULTIPLE:%s]" % time.strftime('%Y-%m-%d'));
# return
# pattern = rl
else:
if debug: print(("%s: %s: make_sig returned: %s (probably no matches)" % (ea, fnName, pattern)))
else:
print(("%s: %s: make_sig returned unexpected type: %s" % (ea, fnName, type(pattern))))
if zmqfake:
return
# ea = idaapi.get_screen_ea()
if _exists:
pattern = ''
try:
# cfunc = idaapi.decompile(ea)
# str(cfunc).split("\n")
func_def = decompile_function(ea)
if not func_def:
decl = idc.get_type(ea)
else:
decl = [x for x in func_def if len(x) and not x[0] == '/'][0]
# dprint("[decl] decl")
if debug: print("[decl] decl:{}".format(decl))
# if len(pattern) < (3 * 6) or pattern[0:2] == "e9":
# return
export_types = ''
while True:
# dprint("[debug] _globals")
if debug: print("[debug] _globals:{}".format(_globals))
if special and not HasUserName(ea) and idc.get_func_name(ea).startswith('sub_'):
desc = "_" + idc.get_func_name(ea)
else:
desc = TagRemoveSubstring(fnName)
_globals = sig_globals(fnStart, fullFuncTypes=True)
# added to try and stop SetType(ea, 'int __fastcall(arg, arg') -- i.e. no func name
# # untested
for _g in _globals:
if _g['type'].endswith(')'):
_g['type'] = _g['type'].replace('void (*)(', 'void (*) fun1(')
# dprint("[sig_maker_auto_zmq] _g")
if debug: print("[sig_maker_auto_zmq] _g:{}".format(_g['type']))
req = {'cmd':'aob', 'version':local_version,
'pattern':pattern, 'description':desc, 'address':_exists or ea,
'decl':decl, 'globals':_globals, 'subs':[],
'types':export_types}
rv = zrequest(req)
if not isinstance(rv, dict):
print(("typeof rv is %s" % type(rv)))
return
# byteify(rv)
raise Exception("error")
matches = rv['matches']
remote_version = rv['version']
if debug: print(("%s: %i matches" % (fnName, matches)))
if 'request_type' in rv:
types = rv['request_type']
print("remote has request type definitions for: {}".format(types))
if types:
for t in _.uniq(types):
if t != 'void':
et = my_print_decls(t)
if not et:
print("**** Type Error ****\n{}\n".format(t))
return
try:
export_types += my_print_decls(t)
except TypeError:
print("**** Type Error ****\n{}\n".format(t))
return
continue
if matches == 0:
mark(ea, "[PATTERN;UNMATCHED:%s]" % (remote_version))
elif matches == 1:
mark(ea, "[PATTERN;EXISTS:%s]" % (remote_version))
elif matches > 1:
mark(ea, "[PATTERN;MULTIPLE:%s]" % (remote_version))
break
except KeyboardInterrupt:
print("W: interrupt received, stopping")
sys.exit()
except ida_hexrays.DecompilationFailure :
print(("%s: DecompilationFailure: 0x0%0x" % (fnName, ea)))
def sig_maker_all(pattern=None, colorise=False, flags=0):
global pending_functions
skip = 0
numLocs = len(list(idautils.Functions()))
count = 0
lastPercent = 0
# print(("locs: %i" % numLocs))
iter = idautils.Functions() # idc.get_segm_attr(EA(, SEGATTR_START)), idc.get_segm_attr(EA(, SEGATTR_END))):
while True:
special = 0
if pending_functions:
ea = pending_functions.pop()
special = 1
else:
if pattern:
fnName = ''
while pattern and not re.match(pattern, fnName, flags=flags):
ea = next(iter)
fnName = idc.get_func_name(ea)
print('matched pattern with {}'.format(fnName))
else:
ea = next(iter)
# if ea < 0x1412c16b8:
# continue
if not HasUserName(ea):
continue
fnName = idc.get_func_name(ea)
if debug: print('function {}...'.format(fnName))
if getglobal('m', None, list) and getglobal('l', None, list):
if ea in globals()['m'] or ea in globals()['l']:
continue
if idc.get_segm_name(ea) != '.text':
continue
if os.path.exists(abort_file):
print("Aborted due to presence of {}".format(abort_file))
raise Exception("Aborted")
count = count + 1
fnName = GetTrueName(ea)
if ea >= 0x1412c16b8:
skip = 0
if skip:
if not fnName.startswith('sub_') and '_' not in fnName:
print("skipping: %s" % fnName)
continue
fnFlags = idaapi.get_flags(ea)
if not special and (idc.get_segm_name(ea) != '.text' or IsChunked(ea) or GetFuncSize(ea) < 6 or idaapi.has_dummy_name(fnFlags) or not idaapi.has_any_name(fnFlags)): # or "_impl" in fnName or fnName.startswith("implsub"): # fnName.find('::') > -1 or fnName.find('__') > -1 or fnName.find('BACK') > -1:
# print("skipping: %s" % fnName)
pass
else:
percent = (100 * count) // numLocs
# if percent > lastPercent:
# print("%i%%" % percent)
lastPercent = percent
# print("\n%s (%i%%)" % (fnName, percent))
sig_maker_auto_zmq(ea, colorise=colorise, special=special)
def testport():
with Socket.socket(Socket.AF_INET, Socket.SOCK_STREAM) as s:
result = s.connect_ex((host, port))
if result == 0:
print('socket is open')
else:
print('socket is closed, error: {}'.format(result))
return result
def test(port = 5558):
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.connect("tcp://{}:{}".format(host, port))
socket.RCVTIMEO = 5000
socket.SNDTIMEO = 5000
socket.send_string("test", zmq.NOBLOCK)
message = socket.recv()
print(("%s" % message))
def term(port = 5558):
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.connect("tcp://{}:{}".format(host, port))
socket.RCVTIMEO = 5000
socket.SNDTIMEO = 5000
socket.send(asBytes('{"cmd":"term"}'))
message = socket.recv()
print(("%s" % message))
def ping(port = 5558):
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.connect("tcp://{}:{}".format(host, port))
socket.RCVTIMEO = 5000
socket.SNDTIMEO = 5000
socket.send(asBytes('{"cmd":"ping"}'))
message = socket.recv()
print(("%s" % message))
def zmclient(pattern=None, _host=None, _port=None, flags=0):
global host
if _host:
host = _host
global port
if _port:
port = _port
zmq_connect()
ping()
ping()
ping()
sig_maker_all(pattern, flags=flags)