MCPcopy
hub / github.com/Gallopsled/pwntools / attach

Function attach

pwnlib/windbg.py:142–239  ·  view source on GitHub ↗

attach(target, windbgscript=None, windbg_args=[]) -> int Attach to a running process with WinDbg. Arguments: target(int, str, process): Process to attach to. windbgscript(str, list): WinDbg script to run after attaching. windbg_args(list): Additional argument

(target, windbgscript=None, windbg_args=[])

Source from the content-addressed store, hash-verified

140
141@LocalContext
142def attach(target, windbgscript=None, windbg_args=[]):
143 """attach(target, windbgscript=None, windbg_args=[]) -> int
144
145 Attach to a running process with WinDbg.
146
147 Arguments:
148 target(int, str, process): Process to attach to.
149 windbgscript(str, list): WinDbg script to run after attaching.
150 windbg_args(list): Additional arguments to pass to WinDbg.
151
152 Returns:
153 int: PID of the WinDbg process.
154
155 Notes:
156
157 The ``target`` argument is very robust, and can be any of the following:
158
159 :obj:`int`
160 PID of a process
161 :obj:`str`
162 Process name. The youngest process is selected.
163 :class:`.process`
164 Process to connect to
165
166 Examples:
167
168 Attach to a process by PID
169
170 >>> pid = windbg.attach(1234) # doctest: +SKIP
171
172 Attach to the youngest process by name
173
174 >>> pid = windbg.attach('cmd.exe') # doctest: +SKIP
175
176 Attach a debugger to a :class:`.process` tube and automate interaction
177
178 >>> io = process('cmd') # doctest: +SKIP
179 >>> pid = windbg.attach(io, windbgscript='''
180 ... bp kernelbase!WriteFile
181 ... g
182 ... ''') # doctest: +SKIP
183 """
184 if context.noptrace:
185 log.warn_once("Skipping debug attach since context.noptrace==True")
186 return
187
188 # let's see if we can find a pid to attach to
189 pid = None
190 if isinstance(target, six.integer_types):
191 # target is a pid, easy peasy
192 pid = target
193 elif isinstance(target, str):
194 # pidof picks the youngest process
195 pids = list(proc.pidof(target))
196 if not pids:
197 log.error('No such process: %s', target)
198 pid = pids[0]
199 log.info('Attaching to youngest process "%s" (PID = %d)' %

Callers 1

debugFunction · 0.70

Calls 5

warn_onceMethod · 0.80
errorMethod · 0.80
infoMethod · 0.80
registerMethod · 0.80
binaryFunction · 0.70

Tested by

no test coverage detected