mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-25 19:21:35 +01:00
port runtc
This commit is contained in:
36
README.adoc
36
README.adoc
@@ -1462,7 +1462,7 @@ so it is close to the failing `0xbf0000cc`.
|
||||
`readelf`:
|
||||
|
||||
....
|
||||
./runtc readelf -s "$(./getvar build_dir)/kernel_module-1.0/hello.ko"
|
||||
./runtc readelf -- -s "$(./getvar build_dir)/kernel_module-1.0/hello.ko"
|
||||
....
|
||||
|
||||
does not give any interesting hits at `cc`, no symbol was placed that far.
|
||||
@@ -1535,7 +1535,7 @@ The base address shows on terminal:
|
||||
Now let's find the offset of `myinit`:
|
||||
|
||||
....
|
||||
./runtc readelf \
|
||||
./runtc readelf -- \
|
||||
-s "$(./getvar build_dir)/kernel_module-1.0/fops.ko" | \
|
||||
grep myinit
|
||||
....
|
||||
@@ -1856,7 +1856,7 @@ Cannot access memory at address 0x10604
|
||||
We have also double checked the address with:
|
||||
|
||||
....
|
||||
./runtc -a arm readelf \
|
||||
./runtc -a arm readelf -- \
|
||||
-s "$(./getvar -a arm build_dir)/kernel_module-1.0/fops.ko" | \
|
||||
grep main
|
||||
....
|
||||
@@ -2457,7 +2457,7 @@ TODO Can you run arm executables in the aarch64 guest? https://stackoverflow.com
|
||||
I've tried:
|
||||
|
||||
....
|
||||
./runtc -a aarch64 gcc|cg -static ~/test/hello_world.c -o data/9p/a.out
|
||||
./runtc -a aarch64 gcc -- -static ~/test/hello_world.c -o data/9p/a.out
|
||||
./run -a A -F '/mnt/9p/a.out'
|
||||
....
|
||||
|
||||
@@ -3325,7 +3325,7 @@ vermagic: 4.17.0 SMP mod_unload modversions
|
||||
Module information is stored in a special `.modinfo` section of the ELF file:
|
||||
|
||||
....
|
||||
./runtc readelf -SW "$(./getvar target_dir)/module_info.ko"
|
||||
./runtc readelf -- -SW "$(./getvar target_dir)/module_info.ko"
|
||||
....
|
||||
|
||||
contains:
|
||||
@@ -3337,7 +3337,7 @@ contains:
|
||||
and:
|
||||
|
||||
....
|
||||
./runtc readelf -x .modinfo "$(./getvar build_dir)/module_info.ko"
|
||||
./runtc readelf -- -x .modinfo "$(./getvar build_dir)/module_info.ko"
|
||||
....
|
||||
|
||||
gives:
|
||||
@@ -3554,7 +3554,7 @@ as explained at: https://stackoverflow.com/questions/8545931/using-gdb-to-conver
|
||||
The exact same thing can be done post mortem with:
|
||||
|
||||
....
|
||||
./runtc gdb \
|
||||
./runtc gdb -- \
|
||||
-batch \
|
||||
-ex 'info line *(myinit+0x1d)' \
|
||||
"$(./getvar build_dir)/kernel_module-1.0/panic.ko" \
|
||||
@@ -4884,7 +4884,7 @@ Meaning of the flags:
|
||||
* `vaddr`: first virtual address of a page the belongs to the process. Notably:
|
||||
+
|
||||
....
|
||||
./runtc readelf -l "$(./getvar build_dir)/kernel_module-1.0/user/virt_to_phys_test.out"
|
||||
./runtc readelf -- -l "$(./getvar build_dir)/kernel_module-1.0/user/virt_to_phys_test.out"
|
||||
....
|
||||
+
|
||||
contains:
|
||||
@@ -5256,7 +5256,7 @@ Notes:
|
||||
It can be found from:
|
||||
+
|
||||
....
|
||||
./runtc readelf -e "$(./getvar vmlinux)" | grep Entry
|
||||
./runtc readelf -- -e "$(./getvar vmlinux)" | grep Entry
|
||||
....
|
||||
+
|
||||
TODO confirm further. If I try to break there with:
|
||||
@@ -6747,7 +6747,7 @@ The reason this is cool, is that `ls` is not statically compiled, but since we h
|
||||
In other words, much cooler than:
|
||||
|
||||
....
|
||||
./runtc -a arm gcc -static ./kernel_module/user/hello.c
|
||||
./runtc -a arm gcc -- -static ./kernel_module/user/hello.c
|
||||
qemu-arm a.out
|
||||
....
|
||||
|
||||
@@ -6798,9 +6798,9 @@ First we try some `-static` sanity checks.
|
||||
Works and prints `hello`:
|
||||
|
||||
....
|
||||
./runtc -a x86_64 gcc -static -o x86_64.out ./kernel_module/user/hello.c
|
||||
./runtc -a arm gcc -static -o arm.out ./kernel_module/user/hello.c
|
||||
./runtc -a aarch64 gcc -static -o aarch64.out ./kernel_module/user/hello.c
|
||||
./runtc -a x86_64 gcc -- -static -o x86_64.out ./kernel_module/user/hello.c
|
||||
./runtc -a arm gcc -- -static -o arm.out ./kernel_module/user/hello.c
|
||||
./runtc -a aarch64 gcc -- -static -o aarch64.out ./kernel_module/user/hello.c
|
||||
"$(./getvar -a x86_64 -g exec)" ./gem5/gem5/configs/example/se.py -c ./x86_64.out
|
||||
"$(./getvar -a arm -g exec)" ./gem5/gem5/configs/example/se.py -c ./arm.out
|
||||
"$(./getvar -a aarch64 -g exec)" ./gem5/gem5/configs/example/se.py -c ./aarch64.out
|
||||
@@ -9556,16 +9556,6 @@ Otherwise, it becomes very difficult to keep everything working across path refa
|
||||
|`-q` |QEMU |
|
||||
|===
|
||||
|
||||
==== runtc
|
||||
|
||||
The link:runtc[] helper script runs a Tool Chain executable built by Buildroot.
|
||||
|
||||
For example, to run `readelf -h` for the `arm` architecture, use:
|
||||
|
||||
....
|
||||
./runtc -a arm readelf -h
|
||||
....
|
||||
|
||||
=== CONTRIBUTING
|
||||
|
||||
==== Testing
|
||||
|
||||
56
runtc
56
runtc
@@ -1,19 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
|
||||
while getopts "h${common_getopts_flags}" OPT; do
|
||||
case "$OPT" in
|
||||
h)
|
||||
echo "https://github.com/cirosantilli/linux-kernel-module-cheat#runtc" 2>&1
|
||||
exit
|
||||
;;
|
||||
?)
|
||||
common_getopts_case "$OPT"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
shift "$(($OPTIND - 1))"
|
||||
tool="$1"
|
||||
shift
|
||||
common_setup
|
||||
"${common_buildroot_out_dir}/host/bin/"*-buildroot-*"${tool}" "$@"
|
||||
exit "$?"
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import glob
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
import common
|
||||
|
||||
parser = common.get_argparse(argparse_args={
|
||||
'description':'''Run a Buildroot ToolChain tool like readelf or objdump.
|
||||
|
||||
For example, to run `readelf -h` for the `arm` architecture, use:
|
||||
|
||||
....
|
||||
./%(prog)s -a arm readelf -- -h
|
||||
....
|
||||
|
||||
Get the list of available tools with:
|
||||
|
||||
....
|
||||
ls "$(./getvar -a arm host_bin_dir)"
|
||||
....
|
||||
'''
|
||||
})
|
||||
parser.add_argument('tool', help='Which tool to run.')
|
||||
parser.add_argument(
|
||||
'extra_args',
|
||||
default=[],
|
||||
help='Extra arguments for the tool.',
|
||||
metavar='extra-args',
|
||||
nargs='*'
|
||||
)
|
||||
args = common.setup(parser)
|
||||
paths = glob.glob(os.path.join(common.host_bin_dir, '*-buildroot-*-{}'.format(args.tool)))
|
||||
assert len(paths) == 1
|
||||
sys.exit(subprocess.Popen(paths + args.extra_args).wait())
|
||||
|
||||
Reference in New Issue
Block a user