Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 841b734

Browse files
committed
doc: updated doc
1 parent 2c10cdb commit 841b734

File tree

10 files changed

+76
-23
lines changed

10 files changed

+76
-23
lines changed

docs/0.5.0/_modules/libdebug/data/memory_view.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,8 @@ <h1>Source code for libdebug.data.memory_view</h1><div class="highlight"><pre>
557557
<span class="sd"> key (int | slice | str | tuple): The key to write to memory.</span>
558558
<span class="sd"> value (bytes): The value to write.</span>
559559
<span class="sd"> &quot;&quot;&quot;</span>
560+
<span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="nb">bytes</span><span class="p">):</span>
561+
<span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s2">&quot;Invalid type for the value to write to memory. Expected bytes.&quot;</span><span class="p">)</span>
560562
<span class="bp">self</span><span class="o">.</span><span class="n">_manage_memory_write_type</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
561563

562564
<span class="k">def</span> <span class="nf">_manage_memory_read_type</span><span class="p">(</span><span class="bp">self</span><span class="p">:</span> <span class="n">MemoryView</span><span class="p">,</span> <span class="n">key</span><span class="p">:</span> <span class="nb">int</span> <span class="o">|</span> <span class="nb">slice</span> <span class="o">|</span> <span class="nb">str</span> <span class="o">|</span> <span class="nb">tuple</span><span class="p">,</span> <span class="n">file</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">&quot;hybrid&quot;</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">bytes</span><span class="p">:</span>

docs/0.5.0/_modules/libdebug/debugger/internal_debugger.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1515,7 +1515,7 @@ <h1>Source code for libdebug.debugger.internal_debugger</h1><div class="highligh
15151515
<span class="c1"># If the address was not found and the backing file is not &quot;absolute&quot;,</span>
15161516
<span class="c1"># we have to assume it is in the main map</span>
15171517
<span class="n">backing_file</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_process_full_path</span><span class="p">()</span>
1518-
<span class="n">liblog</span><span class="o">.</span><span class="n">debugger</span><span class="p">(</span>
1518+
<span class="n">liblog</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span>
15191519
<span class="sa">f</span><span class="s2">&quot;No backing file specified and no corresponding absolute address found for </span><span class="si">{</span><span class="nb">hex</span><span class="p">(</span><span class="n">address</span><span class="p">)</span><span class="si">}</span><span class="s2">. Assuming </span><span class="si">{</span><span class="n">backing_file</span><span class="si">}</span><span class="s2">.&quot;</span><span class="p">,</span>
15201520
<span class="p">)</span>
15211521
<span class="k">elif</span> <span class="p">(</span>

docs/0.5.0/_sources/basic_features.rst.txt

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ You can force the addressing mode by using the following syntax:
148148
d.memory[0x1000, 0x10, "absolute"]
149149
d.memory[0x1000, 0x10, "hybrid"]
150150
151-
If you specify a full or a substring of a file name, libdebug will search for the memory map of the file and use the base address of the file as the base address for the relative addressing. If the file is not found or multiple matches are found, an exeption is raised.
151+
If you specify a full or a substring of a file name, libdebug will search for the memory map of the file and use the base address of the file as the base address for the relative addressing. If the file is not found or multiple matches are found, an exception is raised.
152152

153153
.. code-block:: python
154154
d.memory[0x1000, 0x10, "file_name"]
@@ -245,7 +245,7 @@ An alternative to running the program from the beginning and to resume libdebug
245245
d.attach(pid)
246246
247247
Graceful Termination
248-
====================================
248+
====================
249249

250250
If you want to kill the process being debugged, you can use the `kill()` method. When repeatedly running new instances of debugged program, remember to call the `kill()` command on old instances to avoid large memory usage. The syntax is as follows:
251251

@@ -259,7 +259,34 @@ When you are done with the debugger object, you can terminate the background thr
259259
260260
d.terminate()
261261
262+
263+
Post Mortem Analysis
264+
====================
265+
You can check at every moment if the whole process (or a specific thread) is dead by using the `dead` property. The syntax is as follows:
266+
267+
.. code-block:: python
268+
269+
if not d.dead:
270+
print("The process is not dead")
271+
else:
272+
print("The process is dead")
273+
274+
Moreover, after the process has died, you can check the exit code and the exit signal by using the `exit_code` and `exit_signal` properties, respectively. The syntax is as follows:
275+
276+
.. code-block:: python
277+
278+
if d.dead:
279+
print(f"The process exited with code {d.exit_code}")
280+
281+
.. code-block:: python
282+
283+
if d.dead:
284+
print(f"The process exited with signal {d.exit_signal}")
285+
286+
You can also access registers after the process has died. This is useful for *post-mortem* analysis.
287+
288+
262289
Supported Architectures
263-
====================================
290+
=======================
264291

265292
libdebug currently only supports Linux under the x86_64 (AMD64) architecture. Support for other architectures is planned for future releases. Stay tuned.

docs/0.5.0/_sources/catch_signals.rst.txt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
Signals
22
=======
33

4-
libdebug supports catching of signals. You can, in fact, execute a callback or pause the script when a specific signal directed at the debugged process is intercepted by the tracer. \
4+
libdebug supports catching of signals. You can, in fact, execute a callback or pause the script when a specific signal directed at the debugged process is intercepted by the tracer.
5+
56
The following is the signature of the callback function:
67

78
.. code-block:: python
89
910
def callback(d: ThreadContext, catcher: SignalCatcher) -> None:
1011
11-
along with the thread where the signal was intercepted from, the callback is also passed the `SignalCatcher` object. \
12+
along with the thread where the signal was intercepted from, the callback is also passed the `SignalCatcher` object.
1213

1314
When registering a signal catcher, you can either specify the signal number or the conventional signal name (e.g. 'SIGINT').
1415

@@ -52,17 +53,17 @@ As with breakpoints and syscall handlers, you can access the `hit_count` propert
5253
5354
Note: You cannot catch **SIGSTOP**, **SIGTRAP**, and **SIGKILL**.
5455

55-
These signals are internally used by the ptrace and the debugger, or are enforced by the kernel to be passed directly to the child process without the possibility of being caught.
56+
These signals are internally used by ptrace and the debugger, or are enforced by the kernel to be passed directly to the child process without the possibility of being caught.
5657

5758
Just like with syscalls, there can be at most one user-defined catcher for each signal.
5859

5960
If a new catcher is defined for a signal that is already catched or hijacked, the new catcher will replace the old one, and a warning is printed.
6061

6162
Signal Filtering
6263
----------------
63-
Instead of setting a catcher on signals, you could want to filter which signals are not to be forwarded to the debugged process during execution.
64+
Instead of setting a catcher on signals, you might want to filter which signals are not to be forwarded to the debugged process during execution.
6465

65-
By default, all signals not related to the libdebug's internals are forwarded. For example, SIGSTOP is never passed to the process.
66+
By default, all signals not related to libdebug internals are forwarded. For example, SIGSTOP is never passed to the process.
6667

6768
.. code-block:: python
6869
@@ -94,7 +95,7 @@ When registering a signal hijack, you can either specify the signal number or th
9495
9596
Note: Just like with catchers, you cannot hijack **SIGSTOP**, **SIGTRAP**, and **SIGKILL**.
9697

97-
These signals are internally used by the ptrace and the debugger, or are enforced by the kernel to be passed directly to the child process without the possibility of being caught.
98+
These signals are internally used by ptrace and the debugger, or are enforced by the kernel to be passed directly to the child process without the possibility of being caught.
9899

99100
Hijacking Loop Detection
100101
^^^^^^^^^^^^^^^^^^^^^^^^
@@ -108,7 +109,7 @@ For example, the following code raises a `RuntimeError`:
108109
catcher2 = d.hijack_signal("SIGINT", "SIGPIPE")
109110
110111
Recursion
111-
^^^^^^^^^^^^^^
112+
^^^^^^^^^
112113
Mixing signal catching and hijacking can become messy. Because of this, libdebug provides users with the choice of whether to execute the catcher for a signal that was triggered *by* a hijack.
113114

114115
This behavior is enabled by the parameter `recursive`, available when instantiating a hijack or a catcher. By default, the parameter is set to False.

docs/0.5.0/_sources/handle_syscalls.rst.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ In the case of *handling*, the user can provide a callback function that will be
88
In the case of *hijacking*, the user can modify the syscall that was supposed to be executed, either by changing its parameters or replacing it with another syscall.
99

1010
Handlers
11-
-------
11+
--------
1212
When handling a syscall, the user can provide up to two callback functions that will be called whenever the handled syscall is executed. One that is called before executing the syscall (`on_enter`), the other is called after executing the syscall (`on_exit`).
1313

1414
Please note that it is not necessary to specify both `on_enter` and `on_exit` callbacks. It is sufficient to specify only one of them. The callback function must have the following signature:
@@ -106,7 +106,7 @@ For example, the following code raises a `RuntimeError`:
106106
107107
108108
Recursion
109-
^^^^^^^^^^^^^^
109+
^^^^^^^^^
110110
Mixing syscall handling and hijacking can become messy. Because of this, libdebug provides users with the choice of whether to execute the handler for a syscall that was triggered *by* a hijack.
111111

112112
This behavior is enabled by the parameter `recursive`, available when instantiating a hijack or a handler. By default, the parameter is set to False.

docs/0.5.0/_sources/index.rst.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Installing libdebug once you have dependencies is as simple as running the follo
5757
5858
python3 -m pip install libdebug
5959
60-
This will install the stable build of the library. If you don't mind a few hicups, you can install the latest dev build from the Github repository:
60+
This will install the stable build of the library. If you don't mind a few hiccups, you can install the latest dev build from the Github repository:
6161

6262
.. code-block:: bash
6363

docs/0.5.0/basic_features.html

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ <h2>Absolute and Relative Addressing<a class="headerlink" href="#absolute-and-re
529529
<p>When accessing memory, you can use both absolute and relative addressing. Absolute addressing is the most common way to access memory, where you provide the exact address you want to access. Relative addressing is a more advanced way to access memory, where you provide an address relative to a base address.
530530
By default, the memory access in libdebug is done using an hybrid addressing mode. This means that libdebug will try to resolve the address as an absolute address first. If the address is not found, libdebug will try to resolve the address as a relative address, using as base the one of the binary. In this case, a warning will be printed.
531531
You can force the addressing mode by using the following syntax:</p>
532-
<p>If you specify a full or a substring of a file name, libdebug will search for the memory map of the file and use the base address of the file as the base address for the relative addressing. If the file is not found or multiple matches are found, an exeption is raised.</p>
532+
<p>If you specify a full or a substring of a file name, libdebug will search for the memory map of the file and use the base address of the file as the base address for the relative addressing. If the file is not found or multiple matches are found, an exception is raised.</p>
533533
<p>You can also use the wildcard string “binary” to use the base address of the binary as the base address for the relative addressing. The same behavior is applied if you pass a string corresponding to the binary name.</p>
534534
</section>
535535
</section>
@@ -609,6 +609,26 @@ <h1>Graceful Termination<a class="headerlink" href="#graceful-termination" title
609609
</pre></div>
610610
</div>
611611
</section>
612+
<section id="post-mortem-analysis">
613+
<h1>Post Mortem Analysis<a class="headerlink" href="#post-mortem-analysis" title="Link to this heading">#</a></h1>
614+
<p>You can check at every moment if the whole process (or a specific thread) is dead by using the <cite>dead</cite> property. The syntax is as follows:</p>
615+
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="ow">not</span> <span class="n">d</span><span class="o">.</span><span class="n">dead</span><span class="p">:</span>
616+
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;The process is not dead&quot;</span><span class="p">)</span>
617+
<span class="k">else</span><span class="p">:</span>
618+
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;The process is dead&quot;</span><span class="p">)</span>
619+
</pre></div>
620+
</div>
621+
<p>Moreover, after the process has died, you can check the exit code and the exit signal by using the <cite>exit_code</cite> and <cite>exit_signal</cite> properties, respectively. The syntax is as follows:</p>
622+
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="n">d</span><span class="o">.</span><span class="n">dead</span><span class="p">:</span>
623+
<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;The process exited with code </span><span class="si">{</span><span class="n">d</span><span class="o">.</span><span class="n">exit_code</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
624+
</pre></div>
625+
</div>
626+
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="n">d</span><span class="o">.</span><span class="n">dead</span><span class="p">:</span>
627+
<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;The process exited with signal </span><span class="si">{</span><span class="n">d</span><span class="o">.</span><span class="n">exit_signal</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
628+
</pre></div>
629+
</div>
630+
<p>You can also access registers after the process has died. This is useful for <em>post-mortem</em> analysis.</p>
631+
</section>
612632
<section id="supported-architectures">
613633
<h1>Supported Architectures<a class="headerlink" href="#supported-architectures" title="Link to this heading">#</a></h1>
614634
<p>libdebug currently only supports Linux under the x86_64 (AMD64) architecture. Support for other architectures is planned for future releases. Stay tuned.</p>
@@ -684,6 +704,7 @@ <h1>Supported Architectures<a class="headerlink" href="#supported-architectures"
684704
</li>
685705
<li class="toc-h1 nav-item toc-entry"><a class="reference internal nav-link" href="#detach-and-gdb-migration">Detach and GDB Migration</a></li>
686706
<li class="toc-h1 nav-item toc-entry"><a class="reference internal nav-link" href="#graceful-termination">Graceful Termination</a></li>
707+
<li class="toc-h1 nav-item toc-entry"><a class="reference internal nav-link" href="#post-mortem-analysis">Post Mortem Analysis</a></li>
687708
<li class="toc-h1 nav-item toc-entry"><a class="reference internal nav-link" href="#supported-architectures">Supported Architectures</a></li>
688709
</ul>
689710

0 commit comments

Comments
 (0)