mirror of
https://github.com/brain-hackers/lab
synced 2024-12-22 12:10:04 +09:00
Add x1 C example / improve extract.py to extract all sections after .text
This commit is contained in:
parent
beb13f7943
commit
a1ff34dbca
12
x1/Makefile
12
x1/Makefile
@ -1,10 +1,20 @@
|
||||
CROSS_COMPILE:=arm-linux-gnueabihf-
|
||||
AS:=$(CROSS_COMPILE)as
|
||||
CC:=$(CROSS_COMPILE)gcc
|
||||
|
||||
.PHONY:
|
||||
all: return.bin mrc.bin
|
||||
all: return.bin mrc.bin c/main.bin
|
||||
|
||||
.PHONY:
|
||||
clean:
|
||||
@rm -f *.bin */*.bin
|
||||
|
||||
%.bin: %.S
|
||||
@$(AS) $<
|
||||
@./extract.py a.out $@
|
||||
@rm -f a.out
|
||||
|
||||
c/main.bin:
|
||||
@$(CC) -nostdlib -static -fPIC -mcpu=cortex-a7 c/start.S c/main.c
|
||||
@./extract.py a.out $@
|
||||
#@rm -f a.out
|
||||
|
BIN
x1/c/main.bin
Normal file
BIN
x1/c/main.bin
Normal file
Binary file not shown.
14
x1/c/main.c
Normal file
14
x1/c/main.c
Normal file
@ -0,0 +1,14 @@
|
||||
void main() {
|
||||
char *str = "Hello World";
|
||||
int aa = 1234;
|
||||
int i;
|
||||
for (i=0; i<999; i++) {
|
||||
asm volatile(
|
||||
"mrc p15, 0, r10, c1, c0, 0\n"
|
||||
"bic r10, #1\n"
|
||||
"mcr p15, 0, r10, c1, c0, 0\n"
|
||||
: "=r" (aa)
|
||||
);
|
||||
aa += 1;
|
||||
}
|
||||
}
|
7
x1/c/start.S
Normal file
7
x1/c/start.S
Normal file
@ -0,0 +1,7 @@
|
||||
.align 2
|
||||
.global _start
|
||||
|
||||
_start:
|
||||
push {r4, lr}
|
||||
bl main
|
||||
pop {r4, pc}
|
@ -19,9 +19,11 @@ def extract(elf):
|
||||
print('Input ELF has no .text section', file=sys.stderr)
|
||||
|
||||
with open(sys.argv[2], 'wb') as f:
|
||||
f.write(text.data())
|
||||
elf.stream.seek(0)
|
||||
elf.stream.read(text.header.sh_offset)
|
||||
f.write(elf.stream.read())
|
||||
|
||||
print(f'Successfully extracted the .text section to "{sys.argv[2]}"')
|
||||
print(f'Successfully extracted the necessary sections to "{sys.argv[2]}"')
|
||||
|
||||
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user