From d9a14daa00e62de637c063f357c38cd86efd7666 Mon Sep 17 00:00:00 2001 From: johannst Date: Sat, 30 Apr 2022 17:43:08 +0000 Subject: deploy: f33fbacc6aaa54599458ac3eb375708650656010 --- print.html | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 101 insertions(+), 5 deletions(-) (limited to 'print.html') diff --git a/print.html b/print.html index 92023db..f0056f3 100644 --- a/print.html +++ b/print.html @@ -83,7 +83,7 @@ @@ -1747,6 +1747,22 @@ gdb -ex 'target remote localhost:1234'
  > r2 -B <baddr> <exe>         # open <exe> mapped to addr <baddr>
   oob <addr>                    # reopen current file at <baddr>
 
+

Examples

+

Patch file (alter bytes)

+
  > r2 [-w] <file>
+  oo+           # re-open for write if -w was not passed
+  s <addr>      # seek to position
+  wv <data>     # write 4 byte (dword)
+
+

Assemble / Disassmble (rasm2)

+
  rasm2 -L      # list supported archs
+
+  > rasm2 -a x86 'mov eax, 0xdeadbeef'
+  b8efbeadde
+
+  > rasm2 -a x86 -d "b8efbeadde"
+  mov eax, 0xdeadbeef
+

qemu(1)

All the examples & notes use qemu-system-x86_64 but in most cases this can be swapped with the system emulator for other architectures.

@@ -2043,7 +2059,7 @@ package and sort by size.

-s states (UDP) Unbound, Idle -

Examples

+

Examples

File flags

Show open files with file flags for process:

lsof +fg -p <pid>
@@ -2085,7 +2101,7 @@ package and sort by size.

(EXPR) .............. Group exprs
-

Examples

+

Examples

Show all tcp IPv4 sockets connecting to port 443:

ss -4 'dport 443'
 
@@ -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 -

Examples

+

Examples

Trace open(2) & socket(2) syscalls for a running process + child processes:

strace -f -e trace=open,socket -p <pid>
 
@@ -2416,6 +2432,8 @@ LD_PRELOAD=./libmtrace.so <binary>

Target options

# List all target options with their description.
@@ -3147,7 +3165,7 @@ tcp/udp/icmp            Filter for protocol.
 

Use and/or/not and () to build filter expressions.

-

Examples

+

Examples

Capture packets from remote host

# -k: Start capturing immediately.
 ssh <host> tcpdump -i <IF> -w - | sudo wireshark -k -i -
@@ -3157,6 +3175,7 @@ ssh <host> tcpdump -i <IF> -w - | sudo wireshark -k -i -
 
  • x86_64
  • arm64
  • armv7
  • +
  • riscv
  • x86_64

    keywords: x86_64, x86, abi

    @@ -3892,6 +3911,83 @@ required when compiling natively on arm.

  • GNU Assembler
  • GNU Assembler Directives
  • GNU Assembler ARM dependent features
  • + +

    riscv

    +

    keywords: rv32, rv64

    +
      +
    • ISA type: RISC
    • +
    • Endianness: little, big
    • +
    +

    Registers

    +
      +
    • riscv32 => XLEN=32
    • +
    • riscv64 => XLEN=64
    • +
    +

    General purpose registers

    +
    [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
    +
    +

    ASM skeleton

    +

    Small assembler skeleton, ready to use with following properties:

    +
      +
    • use raw Linux syscalls (man 2 syscall for ABI)
    • +
    • no C runtime (crt)
    • +
    • gnu assembler gas
    • +
    +
    // file: greet.S
    +
    +#include <asm/unistd.h>     // syscall NRs
    +
    +    .section .text, "ax", @progbits
    +    .balign 4               // align code on 4byte boundary
    +    .global _start
    +_start:
    +    li a0, 2                // fd
    +    la a1, greeting         // buf
    +    ld a2, (greeting_len)   // &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, "a", @progbits
    +greeting:
    +    .asciz "Hi ASM-World!\n"
    +greeting_len:
    +    .int .-greeting
    +
    +
    +

    man gcc: file.S assembler code that must be preprocessed.

    +
    +

    To cross-compile and run:

    +
    > riscv64-linux-gnu-gcc -o greet greet.S -nostartfiles -nostdlib                \
    +    -Wl,--dynamic-linker=/usr/riscv64-linux-gnu/lib/ld-linux-riscv64-lp64d.so.1 \
    +  && qemu-riscv64 ./greet
    +Hi ASM-World!
    +
    +
    +

    Cross-compiling on Ubuntu 20.04 (x86_64), paths might differ on other +distributions. Explicitly specifying the dynamic linker should not be +required when compiling natively on riscv.

    +

    Select dynamic linker according to abi used during compile & link.

    +
    +

    References

    + -- cgit v1.2.3