-
Notifications
You must be signed in to change notification settings - Fork 71
/
dmp.ahk
345 lines (304 loc) · 9.98 KB
/
dmp.ahk
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
; http://the-automator.com/download/dmp.ahk
; dmp Version 1.25
; By ObiWanKenobi
; Visit guresicpark.de for dmp updates
; May 8, 2015
;~ http://guresicpark.de/autohotkey/dmp
dmp(pVar*) {
static _iCallCount := 0
; set x as basic variable name
aVarnames := ["x"]
; now search variable name
sLines := _dmpListLines()
aLines := StrSplit(sLines, "`n", "`r")
iLinesLength := aLines.Length()
for deltaLines, LinesItem in aLines
{
sCurrentLine := aLines[(aLines.Length()+1)-deltaLines]
if RegExMatch(sCurrentLine, "i)dmp\s*\(.*\)", match)
{
RegExMatch(sCurrentLine, "^(\d+)\:", match)
iLineNumber := match1 + 0
aVarnames := _dmpGetVarnames(sCurrentLine)
break
}
}
; start dump
_iCallCount++
for deltaVar, VarItem in pVar
{
global gliRowCount := 0
global glsRet=
_dmp(VarItem, aVarnames[deltaVar])
glsRet := LTrim(glsRet, "`r`n")
glsRet := StrReplace(glsRet, "%", "``%")
if (sDmpOutput!="")
sDmpOutput .= "`r`n`r`n`r`n`r`n"
sDmpOutput .= ">>>>> " . aVarnames[deltaVar]
sDmpOutput .= "`r`n`r`n"
sDmpOutput .= glsRet
sDmpOutput .= "`r`n`r`n"
if (gliRowCount > 1)
sDmpOutput .= gliRowCount . " elements for " . aVarnames[deltaVar] . " "
sDmpOutput .= "<<<<<"
}
pidCurrent := DllCall("GetCurrentProcessId")
sScriptPopup =
(ltrim join`r`n
#NoEnv
sDmpOutput=
`(join``r``n
%sDmpOutput%
`)
OnMessage(0x0111, "On_EN_SETFOCUS")
OnMessage(0x100, "OnKeyDown")
Gui +AlwaysOnTop +ToolWindow +Resize +MinSize400x300
Gui, Add, Edit, +Readonly w780 h570 vedit, `% sDmpOutput
Gui, Add, Button, xm w100 y+10 gButtonContinue vButtonContinue, Continue
Gui, Add, Button, xp+120 yp+0 w100 gButtonReload vButtonReload, Reload script
Gui, Add, Button, xp+120 yp+0 w100 gButtonKill vButtonKill, Kill script
gosub Guisize
Gui, Show, Center w800 h600, call #%_iCallCount% in line %iLineNumber% - dmp 1.25
Return
Guisize:
glsEditWidth := "w" . A_GuiWidth - 20
glsEditHeight := "h" . A_GuiHeight - 50
GuiControl, Move, edit, `% glsEditWidth . " " . glsEditHeight
GuiControl, Move, ButtonContinue, `% "y" . (A_GuiHeight - 30)
GuiControl, Move, ButtonReload, `% "y" . (A_GuiHeight - 30)
GuiControl, Move, ButtonKill, `% "y" . (A_GuiHeight - 30)
return
ButtonReload:
process, close, `% %pidCurrent%
Sleep, 120
Run, %A_ScriptFullPath%
ExitApp
return
ButtonKill:
process, close, `% %pidCurrent%
GUIEscape:
GuiClose:
ButtonContinue:
ExitApp
On_EN_SETFOCUS(wParam, lParam) {
Static EM_SETSEL := 0x00B1
Static EN_SETFOCUS := 0x0100
Critical
If ((wParam >> 16) = EN_SETFOCUS) {
DllCall("User32.dll\HideCaret", "Ptr", lParam)
PostMessage, `%EM_SETSEL`%, -1, 0, , ahk_id `%lParam`%
}
}
OnKeyDown(wParam)
{
if (wParam = 13)
ExitApp
}
)
pidScriptPopup := _dmpDynaRun(sScriptPopup)
Process, WaitClose, %pidScriptPopup%
}
_dmp(pVar, _psPrefix, _piLevel:=0) {
global gliRowCount
global glsRet
if (IsObject(pVar))
{
if (_dmpArrayEmpty(pVar))
{
gliRowCount++
glsRet .= "`r`n" . _psPrefix . " := []"
}
else
{
for deltaVar, VarItem in pVar
{
_dmp(VarItem, _psPrefix . "[" . _dmpGetQuotes(deltaVar) . "]", _piLevel + 1)
}
}
}
else
{
gliRowCount++
glsRet .= "`r`n" . _psPrefix . " := " . _dmpGetQuotes(pVar)
}
}
_dmpArrayEmpty(paArray) {
for deltaArray, ArrayItem in paArray
return false
return true
}
_dmpGetQuotes(pVar) {
sRet=
if !IsObject(pVar)
{
if (ObjGetCapacity([pVar], 1) != "")
{
if (RegExMatch(pVar, "^\d+\.\d+$"))
sRet := pVar
else
{
if (StrSplit(pVar, "`n", "`r").Length() > 1)
sRet := "`n"
sRet .= """" . pVar . """"
}
}
else
{
if !pVar
sRet := "0"
else
sRet := pVar
}
}
return sRet
}
_dmpRecursiveBracketNeutralizer(ByRef psText, paBracket, piStartLevel:=0, piStartPos:=1, _piLevel:=0) {
iPos := piStartPos
while (iPos <= StrLen(psText))
{
if (SubStr(psText, iPos, StrLen(paBracket[1]))==paBracket[1])
{
iPos := _dmpRecursiveBracketNeutralizer(psText, paBracket, piStartLevel, iPos+1, _piLevel+1)
}
else if (SubStr(psText, iPos, StrLen(paBracket[2]))==paBracket[2])
{
if (piStartLevel<_piLevel)
{
; do replacement
iDiff:=iPos+StrLen(paBracket[2])-piStartPos
sReplacement=
loop, % (iDiff+1)
sReplacement .= "*"
psText:=_dmpReplaceSE(psText, piStartPos-1, (iPos-1)+StrLen(paBracket[2]), sReplacement)
; calculate difference between old found string and replacement for iPos reset
iPos+=(StrLen(sReplacement)-iDiff)
}
return iPos++
}
else
iPos++
}
}
; *** string functions
_dmpStringSplitPositions(psText, psNeedle, piStartPos:=1) {
aRet := []
if (psText != "")
{
iStartPos := piStartPos
while (iPos := InStr(psText, psNeedle, false, iStartPos))
{
aEl := []
aEl["iStartPos"] := iStartPos
aEl["iEndPos"] := iPos-1
aRet.Push(aEl)
iStartPos := iPos + StrLen(psNeedle)
}
aEl := []
aEl["iStartPos"] := iStartPos
aEl["iEndPos"] := StrLen(psText)
aRet.Push(aEl)
}
return aRet
}
_dmpReplaceSE(psText, piPosStart, piPosEnd:="", psReplacement:="") {
if (psText!="")
{
piPosEnd := piPosEnd != "" ? piPosEnd : StrLen(psText)
sBefore := SubStr(psText, 1, piPosStart-1)
sAfter := SubStr(psText, piPosEnd+1, StrLen(psText))
return sBefore . psReplacement . sAfter
}
else
{
return psReplacement
}
}
_dmpExtractSE(psText, piPosStart, piPosEnd:="") {
if (psText != "")
{
piPosEnd := piPosEnd != "" ? piPosEnd : StrLen(psText)
return SubStr(psText, piPosStart, piPosEnd-(piPosStart-1))
}
}
_dmpGetVarContent(psText) {
sRet=
if RegExMatch(psText, "i)dmp\s*\((.*)\)", match)
{
sRet := match1
}
return sRet
}
_dmpGetVarnames(psText) {
aRet := []
if (psText!="")
{
sTextSaved := psText
_dmpRecursiveBracketNeutralizer(psText, ["{", "}"])
_dmpRecursiveBracketNeutralizer(psText, ["[", "]"])
_dmpRecursiveBracketNeutralizer(psText, ["(", ")"], 1)
sVarContent := _dmpGetVarContent(psText)
aVarContentPositions := _dmpStringSplitPositions(sVarContent, ",")
sVarContentSaved := _dmpGetVarContent(sTextSaved)
for deltaVarContentPositions, VarContentPositionsItem in aVarContentPositions
{
sFound := _dmpExtractSE(sVarContentSaved, VarContentPositionsItem["iStartPos"], VarContentPositionsItem["iEndPos"])
sFound=%sFound%
aRet.Push(sFound)
}
}
return aRet
}
; *** external functions
_dmpDynaRun(s, pn:="", pr:=""){ ; s=Script,pn=PipeName,n:=,pr=Parameters,p1+p2=hPipes,P=PID
static AhkPath:="""" A_AhkPath """" (A_IsCompiled||(A_IsDll&&DllCall(A_AhkPath "\ahkgetvar","Str","A_IsCompiled"))?" /E":"") " """
if (-1=p1 := DllCall("CreateNamedPipe","str",pf:="\\.\pipe\" (pn!=""?pn:"AHK" A_TickCount),"uint",2,"uint",0,"uint",255,"uint",0,"uint",0,"Ptr",0,"Ptr",0))
|| (-1=p2 := DllCall("CreateNamedPipe","str",pf,"uint",2,"uint",0,"uint",255,"uint",0,"uint",0,"Ptr",0,"Ptr",0))
Return 0
; allow compiled executable to execute dynamic scripts. Requires AHK_H
Run, % AhkPath pf """ " pr,,UseErrorLevel HIDE, P
If ErrorLevel
return 0,DllCall("CloseHandle","Ptr",p1),DllCall("CloseHandle","Ptr",p2)
DllCall("ConnectNamedPipe","Ptr",p1,"Ptr",0),DllCall("CloseHandle","Ptr",p1),DllCall("ConnectNamedPipe","Ptr",p2,"Ptr",0)
if !DllCall("WriteFile","Ptr",p2,"Wstr",s:=(A_IsUnicode?chr(0xfeff):"") s,"UInt",StrLen(s)*(A_IsUnicode ? 2 : 1)+(A_IsUnicode?4:6),"uint*",0,"Ptr",0)
P:=0
DllCall("CloseHandle","Ptr",p2)
Return P
}
_dmpListLines() {
static hwndEdit, pSFW, pSW, bkpSFW, bkpSW
ListLines Off
if !hwndEdit
{
; Retrieve the handle of our main window's Edit control:
dhw := A_DetectHiddenWindows
DetectHiddenWindows, On
Process, Exist
ControlGet, hwndEdit, Hwnd,, Edit1, ahk_class AutoHotkey ahk_pid %ErrorLevel%
DetectHiddenWindows, %dhw%
astr := A_IsUnicode ? "astr" : "str"
hmod := DllCall("GetModuleHandle", "str", "user32.dll")
; Get addresses of these two functions:
pSFW := DllCall("GetProcAddress", "uint", hmod, astr, "SetForegroundWindow")
pSW := DllCall("GetProcAddress", "uint", hmod, astr, "ShowWindow")
; Make them writable:
DllCall("VirtualProtect", "uint", pSFW, "uint", 8, "uint", 0x40, "uint*", 0)
DllCall("VirtualProtect", "uint", pSW, "uint", 8, "uint", 0x40, "uint*", 0)
; Save initial values of the first 8 bytes:
bkpSFW := NumGet(pSFW+0, 0, "int64")
bkpSW := NumGet(pSW+0, 0, "int64")
}
; Overwrite SetForegroundWindow() and ShowWindow() temporarily:
NumPut(0x0004C200000001B8, pSFW+0, 0, "int64") ; return TRUE
NumPut(0x0008C200000001B8, pSW+0, 0, "int64") ; return TRUE
; Dump ListLines into hidden AutoHotkey main window:
ListLines
; Restore SetForegroundWindow() and ShowWindow():
NumPut(bkpSFW, pSFW+0, 0, "int64")
NumPut(bkpSW, pSW+0, 0, "int64")
; Retrieve ListLines text and strip out some unnecessary stuff:
ControlGetText, ListLinesText,, ahk_id %hwndEdit%
RegExMatch(ListLinesText, ".*`r`n`r`n\K[\s\S]*(?=`r`n`r`n.*$)", ListLinesText)
StringReplace, ListLinesText, ListLinesText, `r`n, `n, All
ListLines On
return ListLinesText ; This line appears in ListLines if we're called more than once.
}