Skip to content

Instantly share code, notes, and snippets.

@SnowOnion
Last active March 15, 2025 09:39
Show Gist options
  • Save SnowOnion/beea5b22289035961e6ea8b38084ea52 to your computer and use it in GitHub Desktop.
Save SnowOnion/beea5b22289035961e6ea8b38084ea52 to your computer and use it in GitHub Desktop.
Replace strings in executable files

1. Source & Build

hello.c

#include<stdio.h>
int main(){
  printf("helloWorld!\n");
  return 0;
}
# Mac with M3 (Apple Silicon)
clang hello.c -o hello-clang-mac-arm.out

# Mac with Intel Chip
clang hello.c -o hello-clang-mac-x86.out

2. Execute & Replace & Execute

Mac, ARM, 等长替换

现象:killed

➜  Downloads ./hello-clang-mac-arm.out
helloWorld!
➜  Downloads strings ./hello-clang-mac-arm.out
helloWorld!
➜  Downloads emacs hello-clang-mac-arm.out
➜  Downloads strings ./hello-clang-mac-arm.out
helloWoXXX!
➜  Downloads ./hello-clang-mac-arm.out
[1]    32025 killed     ./hello-clang-mac-arm.out

用 lldb:正常(?)执行!

➜  Downloads lldb ./hello-clang-mac-arm.out
(lldb) target create "./hello-clang-mac-arm.out"
Current executable set to '/Users/sonion/Downloads/hello-clang-mac-arm.out' (arm64).
(lldb) r
Process 32437 launched: '/Users/sonion/Downloads/hello-clang-mac-arm.out' (arm64)
helloWoXXX!
Process 32437 exited with status = 0 (0x00000000)
(lldb) r
Process 32460 launched: '/Users/sonion/Downloads/hello-clang-mac-arm.out' (arm64)
helloWoXXX!
Process 32460 exited with status = 0 (0x00000000)
(lldb) ^D

Mac, ARM, 增加长度

现象:killed

➜  Downloads emacs hello-clang-mac-arm.out
➜  Downloads strings ./hello-clang-mac-arm.out
helloWoXXXXXX
➜  Downloads ./hello-clang-mac-arm.out
[1]    32150 killed     ./hello-clang-mac-arm.out

用 lldb:error: process exited with status -1 (no such process.)

➜  Downloads lldb ./hello-clang-mac-arm.out
(lldb) target create "./hello-clang-mac-arm.out"
Current executable set to '/Users/sonion/Downloads/hello-clang-mac-arm.out' (arm64).
(lldb) r
error: process exited with status -1 (no such process.)
(lldb) r
error: process exited with status -1 (no such process.)
(lldb) ^D
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment