aboutsummaryrefslogtreecommitdiffhomepage
path: root/print.html
diff options
context:
space:
mode:
authorjohannst <johannst@users.noreply.github.com>2022-04-30 17:43:08 +0000
committerjohannst <johannst@users.noreply.github.com>2022-04-30 17:43:08 +0000
commitd9a14daa00e62de637c063f357c38cd86efd7666 (patch)
treeb4d8182c8eb1c016672ecc1765ded6eea370076e /print.html
parent039b83e9f2854082928ee92dcefe032570e4c14a (diff)
downloadnotes-d9a14daa00e62de637c063f357c38cd86efd7666.tar.gz
notes-d9a14daa00e62de637c063f357c38cd86efd7666.zip
deploy: f33fbacc6aaa54599458ac3eb375708650656010
Diffstat (limited to 'print.html')
-rw-r--r--print.html106
1 files changed, 101 insertions, 5 deletions
diff --git a/print.html b/print.html
index 92023db..f0056f3 100644
--- a/print.html
+++ b/print.html
@@ -83,7 +83,7 @@
<nav id="sidebar" class="sidebar" aria-label="Table of contents">
<div id="sidebar-scrollbox" class="sidebar-scrollbox">
- <ol class="chapter"><li class="expanded affix "><a href="intro.html">Introduction</a></li><li class="expanded "><a href="tools/index.html"><strong aria-hidden="true">1.</strong> Tools</a></li><li><ol class="section"><li class="expanded "><a href="tools/zsh.html"><strong aria-hidden="true">1.1.</strong> zsh</a></li><li class="expanded "><a href="tools/bash.html"><strong aria-hidden="true">1.2.</strong> bash</a></li><li class="expanded "><a href="tools/fish.html"><strong aria-hidden="true">1.3.</strong> fish</a></li><li class="expanded "><a href="tools/tmux.html"><strong aria-hidden="true">1.4.</strong> tmux</a></li><li class="expanded "><a href="tools/git.html"><strong aria-hidden="true">1.5.</strong> git</a></li><li class="expanded "><a href="tools/awk.html"><strong aria-hidden="true">1.6.</strong> awk</a></li><li class="expanded "><a href="tools/emacs.html"><strong aria-hidden="true">1.7.</strong> emacs</a></li><li class="expanded "><a href="tools/gpg.html"><strong aria-hidden="true">1.8.</strong> gpg</a></li><li class="expanded "><a href="tools/gdb.html"><strong aria-hidden="true">1.9.</strong> gdb</a></li><li class="expanded "><a href="tools/gdbserver.html"><strong aria-hidden="true">1.10.</strong> gdbserver</a></li><li class="expanded "><a href="tools/radare2.html"><strong aria-hidden="true">1.11.</strong> radare2</a></li><li class="expanded "><a href="tools/qemu.html"><strong aria-hidden="true">1.12.</strong> qemu</a></li><li class="expanded "><a href="tools/pacman.html"><strong aria-hidden="true">1.13.</strong> pacman</a></li></ol></li><li class="expanded "><a href="monitor/index.html"><strong aria-hidden="true">2.</strong> Resource analysis &amp; monitor</a></li><li><ol class="section"><li class="expanded "><a href="monitor/lsof.html"><strong aria-hidden="true">2.1.</strong> lsof</a></li><li class="expanded "><a href="monitor/ss.html"><strong aria-hidden="true">2.2.</strong> ss</a></li><li class="expanded "><a href="monitor/pidstat.html"><strong aria-hidden="true">2.3.</strong> pidstat</a></li><li class="expanded "><a href="monitor/pgrep.html"><strong aria-hidden="true">2.4.</strong> pgrep</a></li><li class="expanded "><a href="monitor/pmap.html"><strong aria-hidden="true">2.5.</strong> pmap</a></li><li class="expanded "><a href="monitor/pstack.html"><strong aria-hidden="true">2.6.</strong> pstack</a></li></ol></li><li class="expanded "><a href="trace_profile/index.html"><strong aria-hidden="true">3.</strong> Trace and Profile</a></li><li><ol class="section"><li class="expanded "><a href="trace_profile/strace.html"><strong aria-hidden="true">3.1.</strong> strace</a></li><li class="expanded "><a href="trace_profile/ltrace.html"><strong aria-hidden="true">3.2.</strong> ltrace</a></li><li class="expanded "><a href="trace_profile/perf.html"><strong aria-hidden="true">3.3.</strong> perf</a></li><li class="expanded "><a href="trace_profile/oprofile.html"><strong aria-hidden="true">3.4.</strong> OProfile</a></li><li class="expanded "><a href="trace_profile/time.html"><strong aria-hidden="true">3.5.</strong> time</a></li></ol></li><li class="expanded "><a href="binary/index.html"><strong aria-hidden="true">4.</strong> Binary</a></li><li><ol class="section"><li class="expanded "><a href="binary/od.html"><strong aria-hidden="true">4.1.</strong> od</a></li><li class="expanded "><a href="binary/xxd.html"><strong aria-hidden="true">4.2.</strong> xxd</a></li><li class="expanded "><a href="binary/readelf.html"><strong aria-hidden="true">4.3.</strong> readelf</a></li><li class="expanded "><a href="binary/objdump.html"><strong aria-hidden="true">4.4.</strong> objdump</a></li><li class="expanded "><a href="binary/nm.html"><strong aria-hidden="true">4.5.</strong> nm</a></li></ol></li><li class="expanded "><a href="development/index.html"><strong aria-hidden="true">5.</strong> Development</a></li><li><ol class="section"><li class="expanded "><a href="development/c++filt.html"><strong aria-hidden="true">5.1.</strong> c++filt</a></li><li class="expanded "><a href="development/c++.html"><strong aria-hidden="true">5.2.</strong> c++</a></li><li class="expanded "><a href="development/glibc.html"><strong aria-hidden="true">5.3.</strong> glibc</a></li><li class="expanded "><a href="development/gcc.html"><strong aria-hidden="true">5.4.</strong> gcc</a></li><li class="expanded "><a href="development/make.html"><strong aria-hidden="true">5.5.</strong> make</a></li><li class="expanded "><a href="development/ld.so.html"><strong aria-hidden="true">5.6.</strong> ld.so</a></li><li class="expanded "><a href="development/symbolver.html"><strong aria-hidden="true">5.7.</strong> symbol versioning</a></li><li class="expanded "><a href="development/python.html"><strong aria-hidden="true">5.8.</strong> python</a></li></ol></li><li class="expanded "><a href="linux/index.html"><strong aria-hidden="true">6.</strong> Linux</a></li><li><ol class="section"><li class="expanded "><a href="linux/systemd.html"><strong aria-hidden="true">6.1.</strong> systemd</a></li><li class="expanded "><a href="linux/coredump.html"><strong aria-hidden="true">6.2.</strong> coredump</a></li><li class="expanded "><a href="linux/ptrace_scope.html"><strong aria-hidden="true">6.3.</strong> ptrace_scope</a></li></ol></li><li class="expanded "><a href="network/index.html"><strong aria-hidden="true">7.</strong> Network</a></li><li><ol class="section"><li class="expanded "><a href="network/tcpdump.html"><strong aria-hidden="true">7.1.</strong> tcpdump</a></li></ol></li><li class="expanded "><a href="arch/index.html"><strong aria-hidden="true">8.</strong> Arch</a></li><li><ol class="section"><li class="expanded "><a href="arch/x86_64.html"><strong aria-hidden="true">8.1.</strong> x86_64</a></li><li class="expanded "><a href="arch/arm64.html"><strong aria-hidden="true">8.2.</strong> arm64</a></li><li class="expanded "><a href="arch/armv7.html"><strong aria-hidden="true">8.3.</strong> armv7</a></li></ol></li></ol>
+ <ol class="chapter"><li class="expanded affix "><a href="intro.html">Introduction</a></li><li class="expanded "><a href="tools/index.html"><strong aria-hidden="true">1.</strong> Tools</a></li><li><ol class="section"><li class="expanded "><a href="tools/zsh.html"><strong aria-hidden="true">1.1.</strong> zsh</a></li><li class="expanded "><a href="tools/bash.html"><strong aria-hidden="true">1.2.</strong> bash</a></li><li class="expanded "><a href="tools/fish.html"><strong aria-hidden="true">1.3.</strong> fish</a></li><li class="expanded "><a href="tools/tmux.html"><strong aria-hidden="true">1.4.</strong> tmux</a></li><li class="expanded "><a href="tools/git.html"><strong aria-hidden="true">1.5.</strong> git</a></li><li class="expanded "><a href="tools/awk.html"><strong aria-hidden="true">1.6.</strong> awk</a></li><li class="expanded "><a href="tools/emacs.html"><strong aria-hidden="true">1.7.</strong> emacs</a></li><li class="expanded "><a href="tools/gpg.html"><strong aria-hidden="true">1.8.</strong> gpg</a></li><li class="expanded "><a href="tools/gdb.html"><strong aria-hidden="true">1.9.</strong> gdb</a></li><li class="expanded "><a href="tools/gdbserver.html"><strong aria-hidden="true">1.10.</strong> gdbserver</a></li><li class="expanded "><a href="tools/radare2.html"><strong aria-hidden="true">1.11.</strong> radare2</a></li><li class="expanded "><a href="tools/qemu.html"><strong aria-hidden="true">1.12.</strong> qemu</a></li><li class="expanded "><a href="tools/pacman.html"><strong aria-hidden="true">1.13.</strong> pacman</a></li></ol></li><li class="expanded "><a href="monitor/index.html"><strong aria-hidden="true">2.</strong> Resource analysis &amp; monitor</a></li><li><ol class="section"><li class="expanded "><a href="monitor/lsof.html"><strong aria-hidden="true">2.1.</strong> lsof</a></li><li class="expanded "><a href="monitor/ss.html"><strong aria-hidden="true">2.2.</strong> ss</a></li><li class="expanded "><a href="monitor/pidstat.html"><strong aria-hidden="true">2.3.</strong> pidstat</a></li><li class="expanded "><a href="monitor/pgrep.html"><strong aria-hidden="true">2.4.</strong> pgrep</a></li><li class="expanded "><a href="monitor/pmap.html"><strong aria-hidden="true">2.5.</strong> pmap</a></li><li class="expanded "><a href="monitor/pstack.html"><strong aria-hidden="true">2.6.</strong> pstack</a></li></ol></li><li class="expanded "><a href="trace_profile/index.html"><strong aria-hidden="true">3.</strong> Trace and Profile</a></li><li><ol class="section"><li class="expanded "><a href="trace_profile/strace.html"><strong aria-hidden="true">3.1.</strong> strace</a></li><li class="expanded "><a href="trace_profile/ltrace.html"><strong aria-hidden="true">3.2.</strong> ltrace</a></li><li class="expanded "><a href="trace_profile/perf.html"><strong aria-hidden="true">3.3.</strong> perf</a></li><li class="expanded "><a href="trace_profile/oprofile.html"><strong aria-hidden="true">3.4.</strong> OProfile</a></li><li class="expanded "><a href="trace_profile/time.html"><strong aria-hidden="true">3.5.</strong> time</a></li></ol></li><li class="expanded "><a href="binary/index.html"><strong aria-hidden="true">4.</strong> Binary</a></li><li><ol class="section"><li class="expanded "><a href="binary/od.html"><strong aria-hidden="true">4.1.</strong> od</a></li><li class="expanded "><a href="binary/xxd.html"><strong aria-hidden="true">4.2.</strong> xxd</a></li><li class="expanded "><a href="binary/readelf.html"><strong aria-hidden="true">4.3.</strong> readelf</a></li><li class="expanded "><a href="binary/objdump.html"><strong aria-hidden="true">4.4.</strong> objdump</a></li><li class="expanded "><a href="binary/nm.html"><strong aria-hidden="true">4.5.</strong> nm</a></li></ol></li><li class="expanded "><a href="development/index.html"><strong aria-hidden="true">5.</strong> Development</a></li><li><ol class="section"><li class="expanded "><a href="development/c++filt.html"><strong aria-hidden="true">5.1.</strong> c++filt</a></li><li class="expanded "><a href="development/c++.html"><strong aria-hidden="true">5.2.</strong> c++</a></li><li class="expanded "><a href="development/glibc.html"><strong aria-hidden="true">5.3.</strong> glibc</a></li><li class="expanded "><a href="development/gcc.html"><strong aria-hidden="true">5.4.</strong> gcc</a></li><li class="expanded "><a href="development/make.html"><strong aria-hidden="true">5.5.</strong> make</a></li><li class="expanded "><a href="development/ld.so.html"><strong aria-hidden="true">5.6.</strong> ld.so</a></li><li class="expanded "><a href="development/symbolver.html"><strong aria-hidden="true">5.7.</strong> symbol versioning</a></li><li class="expanded "><a href="development/python.html"><strong aria-hidden="true">5.8.</strong> python</a></li></ol></li><li class="expanded "><a href="linux/index.html"><strong aria-hidden="true">6.</strong> Linux</a></li><li><ol class="section"><li class="expanded "><a href="linux/systemd.html"><strong aria-hidden="true">6.1.</strong> systemd</a></li><li class="expanded "><a href="linux/coredump.html"><strong aria-hidden="true">6.2.</strong> coredump</a></li><li class="expanded "><a href="linux/ptrace_scope.html"><strong aria-hidden="true">6.3.</strong> ptrace_scope</a></li></ol></li><li class="expanded "><a href="network/index.html"><strong aria-hidden="true">7.</strong> Network</a></li><li><ol class="section"><li class="expanded "><a href="network/tcpdump.html"><strong aria-hidden="true">7.1.</strong> tcpdump</a></li></ol></li><li class="expanded "><a href="arch/index.html"><strong aria-hidden="true">8.</strong> Arch</a></li><li><ol class="section"><li class="expanded "><a href="arch/x86_64.html"><strong aria-hidden="true">8.1.</strong> x86_64</a></li><li class="expanded "><a href="arch/arm64.html"><strong aria-hidden="true">8.2.</strong> arm64</a></li><li class="expanded "><a href="arch/armv7.html"><strong aria-hidden="true">8.3.</strong> armv7</a></li><li class="expanded "><a href="arch/riscv.html"><strong aria-hidden="true">8.4.</strong> riscv</a></li></ol></li></ol>
</div>
<div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
</nav>
@@ -1747,6 +1747,22 @@ gdb -ex 'target remote localhost:1234'
<pre><code class="language-markdown"> &gt; r2 -B &lt;baddr&gt; &lt;exe&gt; # open &lt;exe&gt; mapped to addr &lt;baddr&gt;
oob &lt;addr&gt; # reopen current file at &lt;baddr&gt;
</code></pre>
+<h1><a class="header" href="#examples-2" id="examples-2">Examples</a></h1>
+<h2><a class="header" href="#patch-file-alter-bytes" id="patch-file-alter-bytes">Patch file (alter bytes)</a></h2>
+<pre><code class="language-markdown"> &gt; r2 [-w] &lt;file&gt;
+ oo+ # re-open for write if -w was not passed
+ s &lt;addr&gt; # seek to position
+ wv &lt;data&gt; # write 4 byte (dword)
+</code></pre>
+<h2><a class="header" href="#assemble--disassmble-rasm2" id="assemble--disassmble-rasm2">Assemble / Disassmble (rasm2)</a></h2>
+<pre><code class="language-markdown"> rasm2 -L # list supported archs
+
+ &gt; rasm2 -a x86 'mov eax, 0xdeadbeef'
+ b8efbeadde
+
+ &gt; rasm2 -a x86 -d &quot;b8efbeadde&quot;
+ mov eax, 0xdeadbeef
+</code></pre>
<h1><a class="header" href="#qemu1" id="qemu1">qemu(1)</a></h1>
<p>All the examples &amp; notes use <code>qemu-system-x86_64</code> but in most cases
this can be swapped with the system emulator for other architectures.</p>
@@ -2043,7 +2059,7 @@ package and sort by size.</p>
-s states (UDP)
Unbound, Idle
</code></pre>
-<h1><a class="header" href="#examples-2" id="examples-2">Examples</a></h1>
+<h1><a class="header" href="#examples-3" id="examples-3">Examples</a></h1>
<h2><a class="header" href="#file-flags" id="file-flags">File flags</a></h2>
<p>Show open files with file flags for process:</p>
<pre><code class="language-markdown">lsof +fg -p &lt;pid&gt;
@@ -2085,7 +2101,7 @@ package and sort by size.</p>
(EXPR) .............. Group exprs
</code></pre>
-<h1><a class="header" href="#examples-3" id="examples-3">Examples</a></h1>
+<h1><a class="header" href="#examples-4" id="examples-4">Examples</a></h1>
<p>Show all tcp IPv4 sockets connecting to port <code>443</code>:</p>
<pre><code class="language-markdown">ss -4 'dport 443'
</code></pre>
@@ -2164,7 +2180,7 @@ major_pagefault: Happens when the page needed is NOT in memory, the kernel
trace=signal ............... trace signal related syscalls
signal ..................... trace signals delivered to the process
</code></pre>
-<h1><a class="header" href="#examples-4" id="examples-4">Examples</a></h1>
+<h1><a class="header" href="#examples-5" id="examples-5">Examples</a></h1>
<p>Trace <code>open(2)</code> &amp; <code>socket(2)</code> syscalls for a running process + child processes:</p>
<pre><code class="language-markdown">strace -f -e trace=open,socket -p &lt;pid&gt;
</code></pre>
@@ -2416,6 +2432,8 @@ LD_PRELOAD=./libmtrace.so &lt;binary&gt;
<ul>
<li><code>-E</code> run only preprocessor</li>
<li><code>-dM</code> list only <code>#define</code> statements</li>
+<li><code>-###</code> dry-run, outputting exact compiler/linker invocations</li>
+<li><code>-print-multi-lib</code> print available multilib configurations</li>
</ul>
<h3><a class="header" href="#target-options" id="target-options">Target options</a></h3>
<pre><code class="language-bash"># List all target options with their description.
@@ -3147,7 +3165,7 @@ tcp/udp/icmp Filter for protocol.
<blockquote>
<p>Use <code>and/or/not</code> and <code>()</code> to build filter expressions.</p>
</blockquote>
-<h1><a class="header" href="#examples-5" id="examples-5">Examples</a></h1>
+<h1><a class="header" href="#examples-6" id="examples-6">Examples</a></h1>
<h2><a class="header" href="#capture-packets-from-remote-host" id="capture-packets-from-remote-host">Capture packets from remote host</a></h2>
<pre><code class="language-makrdown"># -k: Start capturing immediately.
ssh &lt;host&gt; tcpdump -i &lt;IF&gt; -w - | sudo wireshark -k -i -
@@ -3157,6 +3175,7 @@ ssh &lt;host&gt; tcpdump -i &lt;IF&gt; -w - | sudo wireshark -k -i -
<li><a href="arch/./x86_64.html">x86_64</a></li>
<li><a href="arch/./arm64.html">arm64</a></li>
<li><a href="arch/./armv7.html">armv7</a></li>
+<li><a href="arch/./riscv.html">riscv</a></li>
</ul>
<h1><a class="header" href="#x86_64" id="x86_64">x86_64</a></h1>
<p>keywords: x86_64, x86, abi</p>
@@ -3893,6 +3912,83 @@ required when compiling natively on arm.</p>
<li><a href="https://sourceware.org/binutils/docs/as/Pseudo-Ops.html#Pseudo-Ops">GNU Assembler Directives</a></li>
<li><a href="https://sourceware.org/binutils/docs/as/ARM_002dDependent.html">GNU Assembler <code>ARM</code> dependent features</a></li>
</ul>
+<h1><a class="header" href="#riscv" id="riscv">riscv</a></h1>
+<p>keywords: rv32, rv64</p>
+<ul>
+<li>ISA type: <code>RISC</code></li>
+<li>Endianness: <code>little</code>, <code>big</code></li>
+</ul>
+<h2><a class="header" href="#registers-3" id="registers-3">Registers</a></h2>
+<ul>
+<li>riscv32 =&gt; <code>XLEN=32</code></li>
+<li>riscv64 =&gt; <code>XLEN=64</code></li>
+</ul>
+<h3><a class="header" href="#general-purpose-registers-2" id="general-purpose-registers-2">General purpose registers</a></h3>
+<pre><code class="language-markdown">[XLEN-1:0] abi name desc
+---------------------------------------------
+x0 zero zero register
+x1 ra return addr
+x2 sp stack ptr
+x3 gp global ptr
+x4 tp thread ptr
+x5-x7 t0-t2 temp regs
+x8-x9 s0-s1 saved regs
+x10-x17 a0-a7 arg regs
+x18-x27 s2-s11 saved regs
+x28-x31 t3-t6 temp regs
+</code></pre>
+<h2><a class="header" href="#asm-skeleton-3" id="asm-skeleton-3">ASM skeleton</a></h2>
+<p>Small assembler skeleton, ready to use with following properties:</p>
+<ul>
+<li>use raw Linux syscalls (<code>man 2 syscall</code> for ABI)</li>
+<li>no <code>C runtime (crt)</code></li>
+<li>gnu assembler <a href="https://sourceware.org/binutils/docs/as"><code>gas</code></a></li>
+</ul>
+<pre><code class="language-mipsasm">// file: greet.S
+
+#include &lt;asm/unistd.h&gt; // syscall NRs
+
+ .section .text, &quot;ax&quot;, @progbits
+ .balign 4 // align code on 4byte boundary
+ .global _start
+_start:
+ li a0, 2 // fd
+ la a1, greeting // buf
+ ld a2, (greeting_len) // &amp;len
+ li a7, __NR_write // write(2) syscall
+ ecall
+
+ li a0, 42 // exit code
+ li a7, __NR_exit // exit(2) syscall
+ ecall
+
+ .balign 8 // align data on 8byte boundary
+ .section .rodata, &quot;a&quot;, @progbits
+greeting:
+ .asciz &quot;Hi ASM-World!\n&quot;
+greeting_len:
+ .int .-greeting
+</code></pre>
+<blockquote>
+<p>man gcc: <code>file.S</code> assembler code that must be preprocessed.</p>
+</blockquote>
+<p>To cross-compile and run:</p>
+<pre><code class="language-bash">&gt; riscv64-linux-gnu-gcc -o greet greet.S -nostartfiles -nostdlib \
+ -Wl,--dynamic-linker=/usr/riscv64-linux-gnu/lib/ld-linux-riscv64-lp64d.so.1 \
+ &amp;&amp; qemu-riscv64 ./greet
+Hi ASM-World!
+</code></pre>
+<blockquote>
+<p>Cross-compiling on <code>Ubuntu 20.04 (x86_64)</code>, paths might differ on other
+distributions. Explicitly specifying the dynamic linker should not be
+required when compiling natively on riscv.</p>
+<p>Select dynamic linker according to abi used during compile &amp; link.</p>
+</blockquote>
+<h2><a class="header" href="#references-6" id="references-6">References</a></h2>
+<ul>
+<li><a href="https://sourceware.org/binutils/docs/as">GNU Assembler</a></li>
+<li><a href="https://sourceware.org/binutils/docs/as/Pseudo-Ops.html#Pseudo-Ops">GNU Assembler Directives</a></li>
+</ul>
</main>