Agent Skills
› aresbit/MateBot
› elf-patcher
elf-patcher
GitHub通过C代码和链接器脚本修改ELF二进制文件,注入补丁到代码洞或指定地址,支持符号定义、段放置及交叉平台生成,适用于逆向工程和二进制插桩。
Trigger Scenarios
需要修改Linux ELF二进制文件
使用C代码替代汇编进行二进制修补
向二进制中注入编译后的C代码
执行二进制插桩任务
Install
npx skills add aresbit/MateBot --skill elf-patcher -g -y
SKILL.md
Frontmatter
{
"name": "elf-patcher",
"description": "Patch ELF binaries using C code and linker script magic. Use when modifying Linux binaries by injecting compiled C code into code caves or specific addresses. Alternative to assembly patching for binary modification, reverse engineering payloads, or binary instrumentation tasks. Supports defining symbols at addresses, placing sections at offsets, and cross-platform patch generation."
}
ELF Patcher with C
Patch ELF binaries using C code and GNU linker features instead of raw assembly.
Quick Start
- Copy templates from
assets/directory - Customize
patch_at,patch_size, and external symbols in linkerscript - Write patch logic in C using
SECTION(".patch.code.*")attribute - Compile:
gcc -c binpatch.c -o binpatch.o -fno-pic -fno-pie -nostdlib - Link:
ld -T binpatch.ld binpatch.o -o patch.bin -nostdlib --oformat binary - Apply:
dd if=patch.bin of=target bs=1 seek=0xADDR conv=notrunc
Core Technique
This method leverages two GNU Linker features:
1. Symbol Definition
Define symbols at specific addresses in linkerscript:
my_puts = 0x42069;
Reference in C:
extern void (*my_puts)(char *);
2. Section Placement
Force sections to specific virtual addresses:
SECTIONS {
. = 0xdeadbeefcafebabe; /* Location counter */
.patch ALIGN(1) : SUBALIGN(1) { /* No alignment */
KEEP(*(.patch))
}
}
C Code Pattern
#define SECTION(x) __attribute__((section(x)))
SECTION(".patch.data.message")
const char msg[] = "Hello from patch!";
SECTION(".patch.code.entry")
void patch_entry() {
puts(msg); /* 'puts' defined in linkerscript */
}
Linker Script Pattern
patch_at = 0x01139; /* Target address */
patch_size = 511; /* Available bytes */
puts = 0x1030; /* PLT entry */
SECTIONS {
. = patch_at;
.patch ALIGN(1) : SUBALIGN(1) {
KEEP(*(.patch.code.*))
KEEP(*(.patch.data.*))
}
ASSERT(SIZEOF(.patch) <= patch_size, "patch too big")
}
Resources
scripts/
apply_patch.py- Python script to apply binary patch to target file
references/
technique.md- Detailed technical documentation and considerations
assets/
binpatch.c- Template for patch C codebinpatch.ld- Template for linker scriptMakefile- Build automation template
Important Considerations
- PIE binaries: Use
-fno-pic -fno-pieflags for non-PIE code - Size limits:
ASSERTin linkerscript validates patch fits - ABI matching: May need assembly stubs for calling conventions
- External symbols: Set to actual PLT/GOT addresses from target binary
Extensions
This technique enables:
- Other languages (Rust, Zig, Nim) for patch generation
- Cross-platform patches (platform-specific only in linker script)
- PE/Mach-O compatibility
- Embedded dynamic symbol resolvers
Read references/technique.md for full technical details.
Version History
- 2328a17 Current 2026-08-20 10:31


