Skip to content

Commit 38075b5

Browse files
committed
updated some comments in the patch code
1 parent 37a11fb commit 38075b5

File tree

8 files changed

+38
-18
lines changed

8 files changed

+38
-18
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
BUILD_DIR = './build'
22
INTERP_PATH = $(PWD)/build/shiva
33
PATCH_PATH = "modules/aarch64_patches"
4-
GCC_OPTS= -fPIC -ggdb -c
4+
GCC_OPTS= -fPIC -ggdb -c -DDEBUG
55
OBJ_LIST=shiva.o shiva_util.o shiva_signal.o shiva_ulexec.o shiva_auxv.o \
66
shiva_module.o shiva_trace.o shiva_trace_thread.o shiva_error.o shiva_maps.o shiva_analyze.o \
77
shiva_callsite.o shiva_target.o shiva_xref.o shiva_transform.o shiva_so.o shiva_post_linker.o

modules/aarch64_patches/dataonly_interposing/test_data.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ int foo(void)
1111

1212
int bar(void)
1313
{
14+
static int data_var2 = 10;
1415
printf("I am a function that won't be patched\n");
1516
printf("I'm accessing data_var and its value is %#x\n", data_var);
1617
return 0;
0 Bytes
Binary file not shown.

modules/aarch64_patches/fsplice/example2/fsplice_patch.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,20 @@
22
#include <stdio.h>
33
#include "shiva_module.h"
44

5+
/*
6+
* Splice C code into function foo()
7+
* At Offset 0x72c - 0x73c
8+
*/
59

610
SHIVA_T_SPLICE_FUNCTION(foo, 0x72c, 0x73c)
711
{
8-
/*
9-
* Attach x0 (arg1) to a use-able variable. (Which
10-
* will live in the .bss).
11-
*/
12-
SHIVA_T_PAIR_X0(str);
12+
SHIVA_T_PAIR_X0(str); // register char *str asm("x0");
1313
if (str != NULL) {
14-
fprintf(stdout, "(fprintf version): Printing arg: %s\n", str);
14+
fprintf(stdout, "Printing str: %s\n", str);
1515
}
16-
bar();
1716
}
1817

19-
int bar(void)
20-
{
21-
printf("I am the new bar\n");
22-
}
18+
19+
20+
21+
-304 Bytes
Binary file not shown.

modules/aarch64_patches/fsplice/example6/fsplice_host.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/*
2+
* The original program that we want to patch
3+
*/
4+
15
#include <stdio.h>
26

37
const char *banner = "ElfMaster";
@@ -8,7 +12,7 @@ int foo(int num, char *str)
812
if (num == 7)
913
goto done;
1014
strcpy(global_buf, banner);
11-
printf("Printing str: %s\n", str); // <- replace with patch
15+
printf("Printing str: %s\n", str); // <- splice code in here
1216
done:
1317
return 0;
1418
}

modules/aarch64_patches/fsplice/example6/fsplice_patch.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,36 @@
1+
/*
2+
* Patch code.
3+
* Patch 1. Create a new .data variable, data_val
4+
* Patch 2. Splice code into function foo() (Very intensive operation)
5+
* Patch 3. Rewrite function bar() via symbol interposition
6+
*/
7+
18
#include <stdint.h>
29
#include <stdio.h>
310
#include "shiva_module.h"
411

5-
int data_val = 7;
6-
extern char global_buf[255];
12+
int data_val = 7; // adds in a new .data global variable
13+
extern char global_buf[255]; // links to external global_buf[] variable
714

15+
/*
16+
* The SHIVA_T_SPLICE_FUNCTION will splice it's body of C code
17+
* into the function foo() at address 0x818. It won't fit between
18+
* 0x818 and 0x828 so it extends the size of the function.
19+
*/
820
SHIVA_T_SPLICE_FUNCTION(foo, 0x818, 0x828)
921
{
10-
SHIVA_T_PAIR_BP_16(str);
22+
SHIVA_T_PAIR_BP_16(str); //equiv to char *str = [bp, #16]
1123
if (str != NULL) {
1224
fprintf(stdout, "Printing str: %s\n", str);
1325
}
1426
fprintf(stdout, "global_buf: %s\n", global_buf);
1527
bar();
1628
}
1729

30+
/*
31+
* Completely re-writes the function bar() so that it
32+
* prints data_val + 1
33+
*/
1834
int bar(void)
1935
{
2036
data_val = data_val + 1;

modules/aarch64_patches/rodata_interposing/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
INTERP_PATH="/lib/shiva"
22
SHIVA-LD_PATH="../../../tools/shiva-ld/shiva-ld"
3-
all:
3+
patch:
44
# Build the module ro_patch.c with a large code model
55
gcc -mcmodel=large -fno-pic -I ../ -fno-stack-protector -c ro_patch.c
6-
6+
prog:
77
# Build the program we are patching
88
gcc -O0 test_rodata.c -o test_rodata
99

0 commit comments

Comments
 (0)