-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRTTI_Reverse_Lookup.lua
More file actions
1610 lines (1302 loc) · 41.1 KB
/
RTTI_Reverse_Lookup.lua
File metadata and controls
1610 lines (1302 loc) · 41.1 KB
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
if syntaxcheck then return end
local function autoUntick()
if memrec then
local mr = memrec
local t = createTimer(nil, false)
t.Interval = 1
t.OnTimer = function(timer)
timer.destroy()
if mr then mr.Active = false end
end
t.Enabled = true
end
end
local function safeDestroy(o)
if o and o.destroy then
pcall(function() o.destroy() end)
end
end
local TRACEBACK = (debug and debug.traceback) or function(err) return tostring(err) end
local UNPACK = table.unpack or unpack
local ok, err = xpcall(function()
local function ensureTargetAttached()
local pid = 0
if type(getOpenedProcessID) == "function" then
local okPid, value = pcall(getOpenedProcessID)
if okPid then
pid = tonumber(value) or 0
end
end
if pid ~= 0 then
return true
end
pcall(function()
messageDialog(
'No target process is attached.\n\n' ..
'Select the target process first, then run the script again.',
mtWarning,
mbOK
)
end)
return false
end
if not ensureTargetAttached() then
return
end
local is64 = targetIs64Bit()
local pointersize = is64 and 8 or 4
local scantype = is64 and vtQword or vtDword
local maxaddr = is64 and 0xffffffffffffffff or 0xffffffff
local tdNameOffset = is64 and 0x10 or 0x08
local colSignature = is64 and 1 or 0
local processBase = getAddress(process)
local processSize = getModuleSize(process)
local processEnd = processBase + processSize - 1
---------------------------------------------------------
-- HELPERS
---------------------------------------------------------
local function normalizePtr(v)
if v == nil then return nil end
-- x86 CE can hand back signed pointer-like values
if (not is64) and v < 0 then
return v + 0x100000000
end
return v
end
local function readAsciiZ(addr, maxlen)
local t = readBytes(addr, maxlen, true)
if not t then return nil end
local out = {}
for i=1,#t do
if t[i] == 0 then break end
out[#out+1] = string.char(t[i])
end
return table.concat(out)
end
local function getSections(modBase)
local mz = readSmallInteger(modBase)
if mz ~= 0x5A4D then return nil end
local e_lfanew = readInteger(modBase + 0x3C)
if not e_lfanew then return nil end
local nt = modBase + e_lfanew
local pe = readInteger(nt)
if pe ~= 0x00004550 then return nil end
local numSections = readSmallInteger(nt + 6)
local sizeOptional = readSmallInteger(nt + 20)
local optMagic = readSmallInteger(nt + 24)
-- PE32 = 0x10B
-- PE32+ = 0x20B
if optMagic ~= 0x10B and optMagic ~= 0x20B then
return nil
end
local sec = nt + 24 + sizeOptional
local out = {}
for i=1,numSections do
local name = readAsciiZ(sec, 8) or ""
local virtualSize = readInteger(sec + 8) or 0
local virtualAddress = readInteger(sec + 12) or 0
local rawSize = readInteger(sec + 16) or 0
local characteristics = readInteger(sec + 36) or 0
local size = virtualSize
if rawSize > size then size = rawSize end
if size > 0 then
out[#out+1] = {
name = name,
base = modBase + virtualAddress,
finish = modBase + virtualAddress + size - 1,
characteristics = characteristics
}
end
sec = sec + 40
end
return out
end
local function getModuleSections(mod)
if mod == nil then return nil end
if mod.sections ~= nil then return mod.sections end
mod.sections = getSections(mod.base)
return mod.sections
end
local function isWritableSection(sec)
if sec == nil then return false end
local ch = sec.characteristics or 0
-- IMAGE_SCN_MEM_WRITE = 0x80000000
if ch < 0 then return true end
if ch >= 0x80000000 then return true end
return false
end
local function isDataLikeSection(name)
local s = (name or ""):lower()
return s:find("^%.data") ~= nil or s:find("^%.bss") ~= nil
end
local function addUnique(list, map, value)
if value == nil then return end
if map[value] then return end
map[value] = true
table.insert(list, value)
end
local function addUniqueRange(list, map, base, finish, modulename, secname)
if base == nil or finish == nil then return end
local key = string.format("%x:%x", base, finish)
if map[key] then return end
map[key] = true
table.insert(list, {
base = base,
finish = finish,
module = modulename or "?",
section = secname or "?"
})
end
local function shiftHeld()
return isKeyPressed(VK_SHIFT)
end
local function buildModuleList()
local out = {}
local seen = {}
if type(enumModules) == "function" then
local mods = enumModules()
if type(mods) == "table" then
for i=1,#mods do
local me = mods[i]
local name = me.Name or me.name or me.ModuleName or me.modulename or me[1]
local base = me.Address or me.address or me.BaseAddress or me.base
local size = me.Size or me.size
if name ~= nil then
if base == nil then base = getAddress(name) end
if size == nil then size = getModuleSize(name) end
base = normalizePtr(base)
if name and base and size and not seen[base] then
seen[base] = true
table.insert(out, {
name = name,
base = base,
size = size,
finish = base + size - 1
})
end
end
end
elseif mods and mods.Count then
for i=0,mods.Count-1 do
local name = mods[i]
local base = normalizePtr(getAddress(name))
local size = getModuleSize(name)
if name and base and size and not seen[base] then
seen[base] = true
table.insert(out, {
name = name,
base = base,
size = size,
finish = base + size - 1
})
end
end
safeDestroy(mods)
end
end
if #out == 0 then
table.insert(out, {
name = process,
base = processBase,
size = processSize,
finish = processEnd
})
end
table.sort(out, function(a,b) return a.base < b.base end)
return out
end
local function findModuleByAddress(modules, addr)
addr = normalizePtr(addr)
if addr == nil then return nil end
for i=1,#modules do
local m = modules[i]
if addr >= m.base and addr <= m.finish then
return m
end
end
return nil
end
local function findModuleByBase(modules, base)
base = normalizePtr(base)
if base == nil then return nil end
for i=1,#modules do
if modules[i].base == base then
return modules[i]
end
end
return nil
end
local function getModuleInfoByAddressFallback(addr)
addr = normalizePtr(addr)
if addr == nil then return nil end
if not inModule(addr) then return nil end
local s = getNameFromAddress(addr, true, false, false)
if not s then return nil end
local modulename = s:match("^[^+]+")
if not modulename or modulename == "" then
return nil
end
local base = normalizePtr(getAddress(modulename))
local size = getModuleSize(modulename)
if not base or not size then
return nil
end
return {
name = modulename,
base = base,
size = size,
finish = base + size - 1
}
end
local function getOrCreateModuleByAddress(modules, addr)
local m = findModuleByAddress(modules, addr)
if m then return m end
local fm = getModuleInfoByAddressFallback(addr)
if fm == nil then return nil end
local existing = findModuleByBase(modules, fm.base)
if existing then return existing end
table.insert(modules, fm)
table.sort(modules, function(a,b) return a.base < b.base end)
return fm
end
local function formatAddress(modules, addr)
addr = normalizePtr(addr)
if addr == nil or addr == 0 then
return "0"
end
local m = findModuleByAddress(modules, addr)
if m then
return string.format('%x "%s"+%x', addr, m.name, addr - m.base)
end
return string.format("%x", addr)
end
local function collectQuickRanges(moduleList)
local out = {}
local seen = {}
for i=1,#moduleList do
local mod = moduleList[i]
local secs = getModuleSections(mod)
if secs ~= nil then
local foundDataLike = false
local foundWritable = false
for j=1,#secs do
local sec = secs[j]
if isDataLikeSection(sec.name) then
addUniqueRange(out, seen, sec.base, sec.finish, mod.name, sec.name)
foundDataLike = true
end
end
if not foundDataLike then
for j=1,#secs do
local sec = secs[j]
if isWritableSection(sec) then
addUniqueRange(out, seen, sec.base, sec.finish, mod.name, sec.name)
foundWritable = true
end
end
end
if not foundDataLike and not foundWritable then
addUniqueRange(out, seen, mod.base, mod.finish, mod.name, "(whole module)")
end
else
addUniqueRange(out, seen, mod.base, mod.finish, mod.name, "(whole module)")
end
end
return out
end
local function pulseUI(timeout)
pcall(function() processMessages() end)
pcall(function() checkSynchronize(timeout or 0) end)
end
local CANCELLED = {}
local function checkCancelled(state)
if state and state.cancelRequested then
error(CANCELLED, 0)
end
end
---------------------------------------------------------
-- SCAN UI
---------------------------------------------------------
local function createProgressDialog(title, state)
local form = createForm(false)
form.Caption = title or 'Scanning...'
form.Width = 640
form.Height = 160
form.Position = poScreenCenter
form.BorderStyle = bsDialog
form.KeyPreview = true
pcall(function() form.BorderIcons = '[]' end)
local MARGIN = 10
local GAP = 8
local BUTTON_W = 100
local lblPhase = createLabel(form)
lblPhase.Caption = 'Starting...'
lblPhase.Left = MARGIN
lblPhase.Top = GAP
local lblDetail = createLabel(form)
lblDetail.Caption = ''
lblDetail.Left = MARGIN
lblDetail.Top = lblPhase.Top + lblPhase.Height + GAP
lblDetail.Width = form.ClientWidth - MARGIN * 2
lblDetail.Height = lblDetail.Height * 2
lblDetail.AutoSize = false
pcall(function() lblDetail.WordWrap = true end)
lblDetail.Anchors = '[akLeft, akTop, akRight]'
local pb = createProgressBar(form)
pb.Left = MARGIN
pb.Top = lblDetail.Top + lblDetail.Height + GAP
pb.Width = form.ClientWidth - MARGIN * 2
pb.Min = 0
pb.Max = 1000
pb.Position = 0
pb.Anchors = '[akLeft, akTop, akRight]'
local lblInfo = createLabel(form)
lblInfo.Caption = ''
lblInfo.Left = MARGIN
lblInfo.Top = pb.Top + pb.Height + GAP / 2
local bottomPanel = createPanel(form)
bottomPanel.Align = alBottom
bottomPanel.BevelOuter = bvNone
local buttonPanel = createPanel(bottomPanel)
buttonPanel.BevelOuter = bvNone
local btnCancel = createButton(buttonPanel)
btnCancel.Caption = 'Cancel'
btnCancel.Left = 0
btnCancel.Width = BUTTON_W
buttonPanel.Width = btnCancel.Width
buttonPanel.Height = btnCancel.Height
bottomPanel.Height = buttonPanel.Height + GAP * 2
local function centerButtonPanel()
buttonPanel.Left = math.floor((bottomPanel.Width - buttonPanel.Width) / 2)
buttonPanel.Top = math.floor((bottomPanel.Height - buttonPanel.Height) / 2)
end
bottomPanel.OnResize = centerButtonPanel
local dlg = {}
function dlg.requestCancel()
if state.cancelRequested then return end
state.cancelRequested = true
lblPhase.Caption = 'Cancel requested...'
lblDetail.Caption = 'The current memscan step must finish first.'
lblInfo.Caption = ''
btnCancel.Enabled = false
end
function dlg.checkCancelled()
checkCancelled(state)
end
function dlg.setStatus(phase, detail)
if phase ~= nil then
lblPhase.Caption = phase
end
if detail ~= nil then
lblDetail.Caption = detail
end
end
function dlg.setProgress(current, total, results)
if current ~= nil and total ~= nil and total > 0 then
local pos = math.floor((current * pb.Max) / total)
if pos < 0 then pos = 0 end
if pos > pb.Max then pos = pb.Max end
pb.Position = pos
if results ~= nil then
lblInfo.Caption = string.format('%d / %d (%d result%s)', current, total, results, results == 1 and '' or 's')
else
lblInfo.Caption = string.format('%d / %d', current, total)
end
else
pb.Position = 0
if results ~= nil then
lblInfo.Caption = string.format('%d result%s', results, results == 1 and '' or 's')
else
lblInfo.Caption = ''
end
end
end
btnCancel.OnClick = function(sender)
dlg.requestCancel()
end
form.OnKeyDown = function(sender, key)
if key == VK_ESCAPE then
dlg.requestCancel()
key = 0
end
end
form.OnCloseQuery = function(sender, canClose)
dlg.requestCancel()
canClose = false
end
form.show()
centerButtonPanel()
pulseUI()
dlg.form = form
return dlg
end
local function runWithProgress(title, fn)
local state = { cancelRequested = false }
local dlg = createProgressDialog(title, state)
local result = nil
local okRun, runErr = xpcall(function()
result = fn(state, dlg)
end, function(e)
if e == CANCELLED then return e end
return TRACEBACK(e)
end)
safeDestroy(dlg.form)
if not okRun then
return false, nil, runErr
end
return true, result, nil
end
---------------------------------------------------------
-- RESPONSIVE MEMSCAN WAIT
---------------------------------------------------------
local function withMemScan(fn)
local s = createMemScan()
local fl = createFoundList(s)
local out = nil
local okRun, runErr = xpcall(function()
out = { fn(s, fl) }
end, function(e)
if e == CANCELLED then return e end
return TRACEBACK(e)
end)
pcall(function() fl.deinitialize() end)
safeDestroy(fl)
safeDestroy(s)
if not okRun then
error(runErr, 0)
end
return UNPACK(out or {})
end
local function scanCollect(scan, fl, startScanFn, state, dlg, phase, detail)
pcall(function() fl.deinitialize() end)
checkCancelled(state)
if dlg then
dlg.setStatus(phase, detail)
dlg.setProgress(0, 1, 0)
end
local scanDone = false
scan.OnScanDone = function(memscan)
scanDone = true
end
scan.newScan()
startScanFn()
while not scanDone do
if dlg then
local gp = nil
pcall(function()
gp = scan.getProgress()
end)
if type(gp) == "table" then
dlg.setProgress(gp.CurrentlyScanned, gp.TotalAddressesToScan, gp.ResultsFound)
end
end
pulseUI(10)
end
-- Per CE docs, still finish with waitTillDone() after OnScanDone
scan.waitTillDone()
scan.OnScanDone = nil
checkCancelled(state)
fl.initialize()
local out = {}
for i=1,fl.Count do
out[#out+1] = tonumber(fl[i-1],16)
end
return out
end
local function scanValue(scan, fl, vartype, value, startaddr, stopaddr, protection, alignment, alignParam, state, dlg, phase, detail)
value = normalizePtr(value)
return scanCollect(scan, fl, function()
scan.firstScan(
soExactValue,
vartype,
rtRounded,
string.format("%x", value),
'',
startaddr,
stopaddr,
protection,
alignment,
alignParam,
true,
true,
false,
true
)
end, state, dlg, phase, detail)
end
local function scanStringValue(scan, fl, value, startaddr, stopaddr, protection, alignment, alignParam, state, dlg, phase, detail)
return scanCollect(scan, fl, function()
scan.firstScan(
soExactValue,
vtString,
rtRounded,
value,
'',
startaddr,
stopaddr,
protection,
alignment,
alignParam,
false,
true,
false,
true
)
end, state, dlg, phase, detail)
end
---------------------------------------------------------
-- MODULES
---------------------------------------------------------
local modules = buildModuleList()
local mainModule = findModuleByBase(modules, processBase)
if mainModule == nil then
mainModule = {
name = process,
base = processBase,
size = processSize,
finish = processEnd
}
table.insert(modules, mainModule)
table.sort(modules, function(a,b) return a.base < b.base end)
end
print(string.format('Main module: %s (%x-%x)', mainModule.name, mainModule.base, mainModule.finish))
print(string.format('Modules known: %d', #modules))
---------------------------------------------------------
-- RTTI DISCOVERY SCOPE
---------------------------------------------------------
local function chooseDiscoveryScope()
local form = createForm(false)
form.Caption = 'RTTI discovery'
form.Width = 300
form.Position = poScreenCenter
form.KeyPreview = true
local MARGIN = 10
local GAP = 8
local BUTTON_W = 100
local lbl = createLabel(form)
lbl.Caption = 'Choose RTTI discovery scope'
lbl.Left = MARGIN
lbl.Top = GAP
local bottomPanel = createPanel(form)
bottomPanel.Align = alBottom
bottomPanel.BevelOuter = bvNone
local buttonPanel = createPanel(bottomPanel)
buttonPanel.BevelOuter = bvNone
local btnOK = createButton(buttonPanel)
btnOK.Caption = 'OK'
btnOK.Left = 0
btnOK.Width = BUTTON_W
local btnCancel = createButton(buttonPanel)
btnCancel.Caption = 'Cancel'
btnCancel.Width = BUTTON_W
btnCancel.Left = btnOK.Left + BUTTON_W + MARGIN
buttonPanel.Width = btnCancel.Left + BUTTON_W
buttonPanel.Height = math.max(btnOK.Height, btnCancel.Height)
bottomPanel.Height = buttonPanel.Height + GAP
local function centerButtonPanel()
buttonPanel.Left = math.floor((bottomPanel.Width - buttonPanel.Width) / 2)
buttonPanel.Top = math.floor((bottomPanel.Height - buttonPanel.Height) / 2)
end
bottomPanel.OnResize = centerButtonPanel
local listbox = createListBox(form)
listbox.Left = MARGIN
listbox.Top = lbl.Top + lbl.Height + GAP
listbox.Width = form.ClientWidth - MARGIN * 2
listbox.Anchors = '[akLeft, akTop, akRight]'
listbox.Items.add('Process module only - fast start')
listbox.Items.add('All modules - slower start, broader class list')
listbox.ItemIndex = 0
local picked = nil
local function accept()
if listbox.ItemIndex == 0 then
picked = {
name = "Process only",
startaddr = processBase,
stopaddr = processEnd,
showprogress = false
}
form.ModalResult = mrOK
elseif listbox.ItemIndex == 1 then
picked = {
name = "All modules",
startaddr = 0,
stopaddr = maxaddr,
showprogress = true
}
form.ModalResult = mrOK
end
end
btnOK.OnClick = function()
accept()
end
btnCancel.OnClick = function()
form.ModalResult = mrCancel
end
listbox.OnKeyDown = function(sender, key)
if (key == VK_RETURN or key == VK_SPACE) then
accept()
key = 0
elseif key == VK_ESCAPE then
form.ModalResult = mrCancel
key = 0
end
end
form.OnKeyDown = function(sender, key)
if key == VK_ESCAPE then
form.ModalResult = mrCancel
key = 0
elseif key == VK_RETURN then
accept()
key = 0
end
end
listbox.OnDblClick = function(sender)
accept()
end
form.OnShow = function(sender)
local itemH = listbox.ItemHeight
if itemH == 0 then itemH = btnOK.Height end
listbox.Height = itemH * listbox.Items.Count + 4
form.ClientHeight =
listbox.Top +
listbox.Height +
bottomPanel.Height
centerButtonPanel()
listbox.setFocus()
end
local modalResult = form.showModal()
safeDestroy(form)
if modalResult ~= mrOK then
return nil
end
return picked
end
local discovery = chooseDiscoveryScope()
if discovery == nil then
return
end
print(string.format('RTTI discovery scope: %s', discovery.name))
---------------------------------------------------------
-- NAME LIST
---------------------------------------------------------
local names = nil
local function buildNameListFromHits(hits, dlg)
local namesLocal = {}
local namesSeen = {}
if dlg then
dlg.setStatus('Collecting RTTI classes...', 'Reading names from scan results')
dlg.setProgress(0, #hits, nil)
end
for i=1,#hits do
if (i % 256) == 0 then
if dlg then
dlg.setProgress(i, #hits, nil)
dlg.checkCancelled()
end
pulseUI()
end
local a = hits[i]
local mod = getOrCreateModuleByAddress(modules, a)
if mod ~= nil then
local td = a - tdNameOffset
if not namesSeen[td] then
local nm = readString(a+4)
if nm ~= nil and nm ~= "" then
namesSeen[td] = true
local ne = {}
ne.name = nm
ne.typeDescriptor = td
ne.modulename = mod.name
ne.modulebase = mod.base
ne.moduleend = mod.finish
ne.display = string.format('%s [%s]', ne.name, ne.modulename)
ne.search = (ne.name .. " " .. ne.modulename):lower()
table.insert(namesLocal, ne)
end
end
end
end
table.sort(namesLocal, function(a,b)
local an = a.name:lower()
local bn = b.name:lower()
if an ~= bn then return an < bn end
local am = a.modulename:lower()
local bm = b.modulename:lower()
if am ~= bm then return am < bm end
return a.typeDescriptor < b.typeDescriptor
end)
return namesLocal
end
if discovery.showprogress then
local okRun, result, runErr = runWithProgress('RTTI discovery', function(state, dlg)
local hits = withMemScan(function(s, fl)
return scanStringValue(
s,
fl,
'.?AV',
discovery.startaddr,
discovery.stopaddr,
"*W*X*C",
fsmNotAligned,
'1',
state,
dlg,
'Scanning RTTI strings...',
discovery.name
)
end)
print(string.format("RTTI string hits: %d", #hits))
return buildNameListFromHits(hits, dlg)
end)
if not okRun then
if runErr == CANCELLED then
print("RTTI discovery cancelled by user")
return
end
error(runErr)
end
names = result
else
local hits = withMemScan(function(s, fl)
return scanStringValue(
s,
fl,
'.?AV',
discovery.startaddr,
discovery.stopaddr,
"*W*X*C",
fsmNotAligned,
'1'
)
end)
print(string.format("RTTI string hits: %d", #hits))
names = buildNameListFromHits(hits)
end
print(string.format("RTTI classes collected: %d", #names))
if #names == 0 then
print("No MSVC RTTI classes were found")
return
end
---------------------------------------------------------
-- CUSTOM DIALOG START
---------------------------------------------------------
local function pickClass(entries)
local form = createForm(false)
form.Caption = 'RTTI Classes (' .. #entries .. ' found)'
form.Width = 640
form.Height = 480
form.Position = poScreenCenter
form.KeyPreview = true
form.BorderStyle = bsSizeable
pcall(function() form.WindowState = wsMaximized end)
local MARGIN = 10
local GAP = 8
local BUTTON_W = 100
-- TOP PANEL (Search)
local topPanel = createPanel(form)
topPanel.Align = alTop
topPanel.BevelOuter = bvNone
local lblSearch = createLabel(topPanel)
lblSearch.Caption = 'Search:'
lblSearch.Width = lblSearch.Canvas.getTextWidth(lblSearch.Caption)
lblSearch.Left = MARGIN
lblSearch.Top = GAP + 3
local edtSearch = createEdit(topPanel)