WEBVTT

1
00:00.620 --> 00:02.420
Hello and welcome back.

2
00:02.450 --> 00:11.780
In the previous lesson I showed you how to use a loader using Python, but that loader could only patch

3
00:11.780 --> 00:14.240
one array of bytes.

4
00:14.840 --> 00:18.230
What if you want to have more than one place to patch?

5
00:18.860 --> 00:24.860
So to solve that, I've written another script called "loader_multiple_patches," which you can download

6
00:24.860 --> 00:27.440
from the resource section for this lecture.

7
00:27.680 --> 00:34.280
And this version allows you to do multiple file patches.

8
00:34.520 --> 00:38.540
Now, assuming that you have three locations that you want to patch,

9
00:38.660 --> 00:41.360
so the first one is this array of bytes.

10
00:42.290 --> 00:46.760
So you, as usual, you will put it in this,

11
00:47.360 --> 00:49.010
assign it to this variable.

12
00:49.310 --> 00:55.160
And then the bytes that you're going to use to replace will be in the second variable.

13
00:55.190 --> 00:57.920
And I rename it as "array_to_find_one"

14
00:57.920 --> 00:59.780
and "data_to_replace_one."

15
01:00.830 --> 01:04.460
And assume you have a second array of bytes which you'd like to patch.

16
01:04.490 --> 01:10.780
Then that will be under the second variable "data_to_find_two" and you just paste it here, and the data

17
01:10.780 --> 01:17.530
to replace it with is called "data_to_replace_two," which you put it here. And assume again that you have

18
01:17.530 --> 01:19.690
a third array of bytes that you want to patch.

19
01:19.690 --> 01:22.540
So you put it in a third location here.

20
01:22.570 --> 01:27.820
Third, you assign it to the third variable here, "data_to_find_three."

21
01:28.150 --> 01:35.740
And the bytes which you are going to use to replace them will be assigned to this variable "data_to_replace_three."

22
01:35.740 --> 01:36.910
"data_to_replace_three."

23
01:37.420 --> 01:40.540
So this, you can create as many as you want.

24
01:40.570 --> 01:42.580
Here we have 3, 1, 2, 3.

25
01:42.580 --> 01:48.850
So if you have a fourth one, just create another set, "data_to_replace_four," "data_to_find_four," and "data_to_replace_four."

26
01:48.850 --> 01:49.750
"data_to_replace_four."

27
01:51.130 --> 01:56.560
Now the next part is to do the same thing to this code here.

28
01:56.710 --> 01:59.230
So you duplicate it twice.

29
01:59.230 --> 02:01.330
So you have three segments here.

30
02:01.570 --> 02:08.140
The first one you rename the variable to "data_to_find_bytes_one," "data_to_replace_bytes_one."

31
02:08.140 --> 02:16.080
And here you, you put it as "data_to_find_one," which is coming from here, and "data_to_replace_one," coming

32
02:16.080 --> 02:16.890
from here.

33
02:17.610 --> 02:23.460
And then the second batch is "data_to_find_bytes_two,"

34
02:23.490 --> 02:25.050
"data_to_replace_bytes_two."

35
02:25.080 --> 02:29.490
And then here, replace it with "data_to_find_two," which is coming from here.

36
02:29.520 --> 02:33.480
There are two, "data_to_replace_two," which is coming from here.

37
02:33.630 --> 02:39.870
And finally, the third batch is "data_to_find_bytes_three" and "data_to_replace_bytes_three," and the corresponding

38
02:39.870 --> 02:42.120
"data_to_find_three" and "data_to_replace_three."

39
02:42.150 --> 02:47.700
Now if you have four, let's say you have four, "data_to_find_four" and "data_to_replace_four"

40
02:47.730 --> 02:48.270
here,

41
02:48.270 --> 02:53.070
also you need to create a fourth, a fourth batch and change the variables accordingly.

42
02:53.070 --> 02:55.350
Just copy and paste and change accordingly.

43
02:55.620 --> 03:00.450
So these are the changes you make that you had, that I have made to the original script.

44
03:00.780 --> 03:01.350
You,

45
03:01.350 --> 03:06.900
so you can have as many bytes, array of bytes as you like, as many patches as you want.

46
03:06.900 --> 03:09.720
So if there are three here, there should be three here as well.

47
03:10.080 --> 03:12.240
Now the next change is over here.

48
03:12.270 --> 03:14.070
If you scroll down to the bottom,

49
03:15.360 --> 03:18.480
so you also find that now this part here has been changed.

50
03:18.510 --> 03:23.030
Originally it was a "patch_memory," which looks like this,

51
03:23.990 --> 03:25.220
a simple one.

52
03:27.590 --> 03:34.430
So now I've redone it to become a separate function, "patch_memory."

53
03:34.550 --> 03:38.150
So "patch_memory" now is here, a new function.

54
03:38.630 --> 03:42.650
Previously we just have "write_memory" directly here like this.

55
03:43.520 --> 03:47.570
And I've now, uh, redone the code.

56
03:50.360 --> 03:52.490
So now you have "patch_memory."

57
03:53.450 --> 03:58.700
So "patch_memory" is a function which will handle the patching itself,

58
03:58.700 --> 04:00.740
and you can call it multiple times.

59
04:00.770 --> 04:02.540
So here I call it three times.

60
04:02.540 --> 04:09.110
The first one is to pass the first batch of array of bytes and the "data_to_replace_bytes_one."

61
04:09.680 --> 04:17.060
The second time I call it is "data_to_find_bytes_two," the second array of bytes, and the second set of

62
04:17.240 --> 04:21.170
hex bytes to replace it with. And the third one is here.

63
04:21.200 --> 04:24.770
So we call it three times, 1, 2, 3.

64
04:24.800 --> 04:30.890
This three here is referring to, is referring to this three over here.

65
04:31.640 --> 04:32.240
First set,

66
04:32.270 --> 04:32.900
second set,

67
04:32.930 --> 04:33.560
third set.

68
04:33.590 --> 04:39.830
So if you have four here, let's say you have, you have four, four array of bytes here, also four.

69
04:39.860 --> 04:41.690
Then you will call,

70
04:42.020 --> 04:44.390
you will call this function four times.

71
04:44.630 --> 04:49.370
The fourth time will be "data_to_find_bytes_four," "data_to_replace_bytes_four."

72
04:49.370 --> 04:51.980
So you can, you can modify it accordingly.

73
04:51.980 --> 04:58.370
So this script is a template which you can use to patch more than one array of bytes.

74
04:58.580 --> 05:04.130
If you have only two, then of course you delete the third batch here and then use only two.

75
05:04.160 --> 05:07.280
And then, uh, here also we have two.

76
05:07.310 --> 05:10.580
And then down here also you have only two calls.

77
05:10.580 --> 05:15.800
So you have unlimited number of calls which you can make using this Python script.

78
05:15.800 --> 05:19.280
So I hope this makes it more flexible for you guys,

79
05:19.640 --> 05:25.160
uh, to write Python script that can patch any number of array of bytes that you like.

80
05:25.160 --> 05:26.960
So that's all for this video.

81
05:26.960 --> 05:28.340
Thank you for watching.