2026年11月17日 星期二

WinDbg 使用筆記

Install

Install WinDbg

Install by winget

winget install Microsoft.WinDbg

Update by winget

winget upgrade Microsoft.WinDbg

Command-Line Options

windbg-command-line-options

-srcpath <SourcePath>

指定 source路徑。


-y <SymbolPath>

指定 symbol search path,多個路徑使用分號(;)隔開。如果路徑有空白字元,使用引號(")包住路徑。


-z <DumpFile>

指定 dump file


Meta-Commands

meta-commands

.lines

Toggle Source Line Support

Enable source line support

.line -e

Disable source line support

.line -d

.reload

Reload Module

強制 debugger立即載入 symbols

.reload /f

.srcpath

Set Source Path

.srcpath <SourcePath>

.sympath

Set Symbol Path

.sympath <SymbolPath>

Commands


lm

List Loaded Modules

lm

ln

List Nearest Symbols

ln <Address>

lsa

List Source Lines

lsa <Address>

u

Unassemble

顯示 Address上的指令

u <Address>

顯示 Address及其後的5個指令

u <Address> L5

uf

Unassemble Function

uf <Address>

MSVC Tools

環境設定

command-prompt-powershell

使用MSVC Tools之前,要先調用環境設定的腳本

Cmd

"%ProgramFiles%\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat"

PowerShell

& 'C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\Launch-VsDevShell.ps1'

dumpbin

dumpbin reference

用來查看object、exe及DLL檔的工具。dumpbin只有/HEADERS功能可以使用在/GL編譯出來的檔案上。

/headers

顯示檔案跟其中 section的 header

dumpbin /headers <file_path>

editbin

editbin reference

用來修改object、exe及DLL檔的工具。editbin不能使用在/GL編譯出來的檔案上。

/rebase

更改檔案的base address

editbin /rebase:base=<addr> <file_path>

2026年9月19日 星期六

PnPUtil

官方網址:
https://learn.microsoft.com/zh-tw/windows-hardware/drivers/devtest/pnputil

PnPUtil是 Windows下用於管理驅動及設備的命令列工具

/enum-devices

列舉系統中 class name為 USB的裝置

pnputil /enum-device /class "USB"

2026年7月14日 星期二

nmap 使用筆記

https://nmap.org/

公司實驗室的機器 IP有時候飄來飄去,這時候就可以靠 nmap來找到需要的機器。


掃描指定機器的常用埠

nmap 192.168.1.10
Starting Nmap 7.95 ( https://nmap.org ) at 2026-07-14 17:52 CST Nmap scan report for renegade-ThinkPad-L13 (192.168.1.10) Host is up (0.000069s latency). Not shown: 998 closed tcp ports (conn-refused) PORT STATE SERVICE 22/tcp open ssh 3389/tcp open ms-wbt-server Nmap done: 1 IP address (1 host up) scanned in 0.04 seconds


掃描子網路 (192.168.1.0 to 192.168.1.255)

nmap 192.168.1.0/24


掃描指定的埠

nmap -p 22 192.168.1.10
Starting Nmap 7.95 ( https://nmap.org ) at 2026-07-14 17:53 CST Nmap scan report for renegade-ThinkPad-L13 (192.168.1.10) Host is up (0.000052s latency). PORT STATE SERVICE 22/tcp open ssh Nmap done: 1 IP address (1 host up) scanned in 0.03 seconds


偵測每個埠上運行的服務

nmap -sV 192.168.1.10
Nmap scan report for renegade-ThinkPad-L13 (192.168.1.10) Host is up (0.000069s latency). Not shown: 998 closed tcp ports (conn-refused) PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 10.0p2 Ubuntu 5ubuntu5.4 (Ubuntu Linux; protocol 2.0) 3389/tcp open ms-wbt-server Microsoft Terminal Service Service Info: OSs: Linux, Windows; CPE: cpe:/o:linux:linux_kernel, cpe:/o:microsoft:windows Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 11.24 seconds


掃描子網路下所有 port 22的狀態為 open的機器

nmap -p 22 -T4 --open -oG - 192.168.1.10
# Nmap 7.95 scan initiated Tue Jul 14 18:16:59 2026 as: nmap -p 22 -T4 -oG - 192.168.1.0/24 Host: 172.31.97.112 (renegade-ThinkPad-L13) Status: Up Host: 172.31.97.112 (renegade-ThinkPad-L13) Ports: 22/open/tcp//ssh/// # Nmap done at Tue Jul 14 18:16:59 2026 -- 1 IP address (1 host up) scanned in 0.03 seconds
  • -T4 加速掃描速度
  • --open 只列出狀態為 open的 port
  • --oG - 輸出grepable的格式到console

2026年7月13日 星期一

Coreutils for Windows

官方網址:
https://learn.microsoft.com/en-us/windows/core-utils/overview
https://github.com/microsoft/coreutils

Coreutils可以在原生Windows上跑 UNIX風格命令列工具,由 Microsoft自己維護。

安裝:

winget install Microsoft.Coreutils

能用的命令可以參考:
https://learn.microsoft.com/en-us/windows/core-utils/commands

2026年3月9日 星期一

[Linux] Linux common utility

記錄一些常用的 Linux指令或工具


echo

將字串或變數輸出到終端機的指令

echo "Hello World!"

輸出字串

echo $HOME

輸出變數


cat

concatenate,主要功能為將檔案內容輸出到終端機或另一個檔案

cat command options
-n, --number輸出行數。


cat a.txt

輸出 a.txt的檔案內容


cat a.txt b.txt

將 a.txt和 b.txt的檔案內容串接輸出到終端機


cat a.txt b.txt > ab.txt

將 a.txt和 b.txt的檔案內容串接寫到新檔案 ab.txt中


cat b.txt >> a.txt

將 b.txt的檔案內容串接寫到 a.txt後


pwd

print working directory,輸出當前終端機的目錄

pwd


ls

list,用來輸出目錄的內容或資訊

ls command options
-lLong format。顯示詳細資訊。
-aAll file。顯示隱藏檔案。
-hHuman-readable。將檔案容量大小顯示為人類可讀格式。
-tSort by time。以修改時間來將檔案排序,由新到舊。
-RRecursive。列出所有包含子目錄中的檔案。


ls -l
-rw-rw-r-- 1 goyour123 goyour123 182 Feb 28 00:08 a.txt
  • -rw-rw-r-- 檔案類型與權限,一共有10個字元。
    • 第一個字元代表檔案類型
      • [-] 檔案
      • [d] 目錄
      • [l] 連結檔(symbolic link)
      • [b] 塊設備(block device)
      • [c] 字符設備(charater device)
    • 剩下九個字元以三個為一組,分別代表檔案擁有者(Owner)、群組(Group)及其他使用者(Others)的權限
      • [r] 代表可讀(read)
      • [w] 代表可寫(write)
      • [x] 代表可執行(execute)
  • 1 代表檔案的硬連結(hard link)數量
  • goyour123 檔案的擁有者
  • goyour123 檔案的群組
  • 182 檔案的容量大小(bytes)
  • Feb 28 00:08 檔案最近修改日期
  • a.txt 檔案名稱

cd

change directory,切換目錄

cd
cd ~

切換到家目錄


cd /

切換到根目錄


cd ..

切換到上一層目錄


cd -

切換到上一次所在的目錄


cd /path/to/dir

使用絕對路徑切換目錄


cd dir

切換到當前目錄下的子目錄



mkdir

make directory,建立目錄

mkdir dir

在當前目錄下建立目錄


mkdir -p /path/to/dir

建立多個層級的目錄


mkdir -m 777 dir

建立目錄並設定權限


mkdir dir1 dir2 dir3

建立多個目錄



mv

move,用來重新命名或移動檔案和目錄

mv command options
-iinteractive。檔案覆蓋前跳出提示。
-fforce。強制覆蓋已存在的檔案。
-nno-clobber。不覆蓋已存在的檔案。
-uupdate。當來源檔案較新或是目的檔案不存在才移動。
-vverbose。顯示命令執行詳細過程。


mv a.txt /path/to/dir
mv a.txt b.txt c.txt /path/to/dir

移動檔案


mv a.txt b.txt

重新命名檔案



cp

copy,複製檔案和目錄

cp command options
-rrecursive。遞迴地複製檔案,用來複製目錄。
-iinteractive。檔案覆蓋前跳出提示。
-ppreserve。保留檔案的權限及時間戳。
-uupdate。當來源檔案較新或是目的檔案不存在才複製。
-apreserve all。遞迴地複製檔案,並且保留檔案權限及時間戳。
-vverbose。顯示命令執行詳細過程。


cp a.txt b.txt

複製檔案


cp a.txt /path/to/dir

複製檔案到目錄



man

manual,用來查看命令、系統呼叫、函式庫或設定檔的使用方法。

man 操作方法
/搜尋關鍵字
q離開


man ls

查詢 ls的使用方法



rm

remove,用來刪除檔案或目錄。

cp command options
-fforce。強制刪除。
-rrecursive。遞迴地刪除目錄及其中的檔案。
-iinteractive。刪除檔案前跳出提示。
-vverbose。顯示命令執行詳細過程。


rm a.txt

刪除檔案


rm -rf /path/to/dir

強制刪除目錄及其中檔案



touch

用來建立空檔案或是更新檔案的時間戳。


touch a.txt
touch a.txt b.txt c.txt

建立空檔案,如果檔案存在則更新時間戳為現在。


touch -t 202604201000 a.txt

指定更新時間,格式為 [[CC]YY]MMDDhhmm[.ss]。


touch -r reference.txt target.txt

參考其他檔案的時間來更新。


touch -a a.txt

只更新 atime(access time)。


touch -m a.txt

只更新 mtime(modify time)。



chmod

change mode。用來變更檔案或目錄的存取權限。

  • 使用者分類
    • u (user/owner)
    • g (group)
    • o (others)
    • a (all)
  • 權限分類
    • r, 4 (read)
    • w, 2 (write)
    • x, 1 (execute)

chmod 777 a.txt

給予所有人讀寫及執行權限。


chmod 755 a.txt

給予檔案擁有者所有權限,其他人讀取及執行權限。


chmod 644 a.txt

給予檔案擁有者讀寫權限,其他人只有讀取權限。


chmod +x a.txt

給予所有人執行權限。


chmod u+x a.txt

給予擁有者寫入權限。


chmod g-x,o-w a.txt

取消群組及其他人的寫入權限。


chmod a=r a.txt

所有人設定為只能讀取權限。


tar

tape archive。打包及檔案壓縮工具。

tar command options
-f指定要處理的檔名
-v列出每一步處理涉及的檔案資訊
-x解開 tar檔案
-z呼叫 gzip壓縮或解壓縮檔案。
-c建立壓縮檔案。


tar -xvf a.tar

解開tar檔案


tar -zxvf b.tar.gz

解開tar.gz檔案


tee

將標準輸入同時導向檔案及標準輸出。


ls -l | tee ls.txt

輸出ls -l的結果並將結果寫入到 ls.txt的檔案中


2025年11月7日 星期五

lf - terminal file manager 使用筆記

官方網址:
https://github.com/gokcehan/lf

lf 命令


最重要的命令
q離開 lf

移動
j or [↓]檔案列表中往下移動
k or [↑]檔案列表中往上移動
[Ctrl] + d檔案列表中往下移動半頁
[Ctrl] + u檔案列表中往上移動半頁
[Ctrl] + b or [PgDn]檔案列表中往下移動一頁
[Ctrl] + f or [PgUp]檔案列表中往上移動一頁
h or [←]移動到上一層目錄
l or [→]移動到下一層目錄,或者開啟檔案
gg or [Home]移動到最上面的檔案
G or [End]移動到最下面的檔案

檔案操作
gg or [Home]移動到最上面的檔案
G or [End]移動到最下面的檔案
[Space]選取目前的檔案
v取消選取目前的檔案
u取消所有選取的檔案
y複製目前或者選取的檔案
d剪下目前或者選取的檔案
p貼上複製或剪下的檔案到當前的目錄
c取消貼上複製或剪下的檔案

命令列
:輸入預設或自定義的命令
$在 shell下執行命令
%在 shell下執行命令,並將ui pipe到input,output pipe到ui
!在 shell下執行命令,並等待按鍵輸入
&在背景執行命令

搜尋
/搜尋符合pattern的輸入
?反向搜尋符合pattern的輸入
n下一個符合pattern的結果
N上一個符合pattern的結果

設定
z更改某些選項的設定
s更改 sortby及 info的設定

開啟
e開啟檔案編輯器
i開啟 pager
w開啟 shell


lf 設定檔

Linux

  ~/.config/lf/lfrc

Windows

  C:\Users\%username%\AppData\Roaming\lf\lfrc


環境變數

可以透過修改環境變數來更改 lf的預設指令

環境變數
OPENERWindows: start
Linux: xdg-open
EDITORWindows: notepad
Linux: vi
PAGERWindows: more
Linux: less
SHELLWindows: cmd
Linux: sh

參考連結:
https://github.com/gokcehan/lf/wiki/Tutorial

2024年10月28日 星期一

rappel - Assembly REPL

官方網址:
https://github.com/yrp604/rappel

rappel提供了一個 assembly的交互式介面環境,可以在執行完指令後馬上看到暫存器狀態的變化,用來嘗試一些指令非常好用。

編譯完後可從./bin/rappel執行,Ctrl + d 退出程序:

./bin/rappel
rax=0000000000000000 rbx=0000000000000000 rcx=0000000000000000
rdx=0000000000000000 rsi=0000000000000000 rdi=0000000000000000
rip=0000000000400001 rsp=00007ffd6bf14b30 rbp=0000000000000000
 r8=0000000000000000  r9=0000000000000000 r10=0000000000000000
r11=0000000000000000 r12=0000000000000000 r13=0000000000000000
r14=0000000000000000 r15=0000000000000000
[cf=0, zf=0, of=0, sf=0, pf=0, af=0, df=0]
cs=0033  ss=002b  ds=0000  es=0000  fs=0000  gs=0000            efl=00000202

mov rax, 0x10
rax=0000000000000010 rbx=0000000000000000 rcx=0000000000000000
rdx=0000000000000000 rsi=0000000000000000 rdi=0000000000000000
rip=0000000000400006 rsp=00007ffd6bf14b30 rbp=0000000000000000
 r8=0000000000000000  r9=0000000000000000 r10=0000000000000000
r11=0000000000000000 r12=0000000000000000 r13=0000000000000000
r14=0000000000000000 r15=0000000000000000
[cf=0, zf=0, of=0, sf=0, pf=0, af=0, df=0]
cs=0033  ss=002b  ds=0000  es=0000  fs=0000  gs=0000            efl=00000202

2024年10月11日 星期五

[Linux] GDB 使用筆記


.gdbinit

可以透過將 .gdbinit檔案放到 home目錄下對 GDB做初始化設定。


  set disassemble-next-line on


GDB 指令

設置斷點

(gdb) b
(gdb) break [function name]

執行程式

(gdb) r
(gdb) run [args]

離開 gdb

(gdb) q
(gdb) quit

顯示下一個所要執行的組合語言指令

(gdb) set disassemble-next-line on

確認當前 set disassemble-next-line的設定狀態

(gdb) show disassemble-next-line

顯示暫存器的值

(gdb) i r
(gdb) info registers
(gdb) info registers [registers]

將 rax暫存器的值設為 0x1234

(gdb) set $rax = 0x1234

印出 0x402000地址的值

(gdb) p/x *(0x402000)

2024年9月24日 星期二

[Linux] grep 命令使用筆記

grep是 Linux下用來在檔案中尋找文字的工具。

語法


grep [options] [pattern] [files]

常用 Option


grep command options
Matching Control
-e PATTERNS指定搜尋的 pattern,可以宣告多次。
-i, --ignore-case忽略大小寫。
-v, --invert-match印出不符合的結果。
-wwhole word only。
General Output Control
-c, --count只印出符合結果的行數。
-l只印出符合結果的檔案名稱。
-o只印出符合的部分。
Output Line Prefix Control
-h, --no-filename只顯示符合的結果,不顯示檔案名稱。
-n, --line-number在符合的結果前面加上行號。
Context Line Control
-A NUM印出符合的結果後面 NUM行。
-B NUM印出符合的結果前面 NUM行。
-C NUM印出符合的結果前面及後面 NUM行。
File and Directory Selection
-r, --recursive尋找指定目錄下所有檔案的符合結果。

使用方法


grep "abcd" file.txt
grep -e "abcd" file.txt

在 file.txt中尋找有 abcd字串的行。


grep -e "abcd" -e "efgh" file.txt

在 file.txt中尋找有 abcd字串及有 efgh的行。


grep -e "abcd" -e "efgh" file.txt file2.txt

在 file.txt和 file2.txt中尋找有 abcd字串及有 efgh的行。


grep -r "abcd" .

在當前目錄下的所有檔案中尋找有 abcd字串的行。


grep -r -l "abcd" .

只列出當前目錄下的所有檔案中有 abcd字串的檔案名稱。