Hello and welcome back.
In the previous lesson I showed you how to use a loader using Python, but that loader could only patch
one array of bytes.
What if you want to have more than one place to patch?
So to solve that, I've written another script called "loader_multiple_patches," which you can download
from the resource section for this lecture.
And this version allows you to do multiple file patches.
Now, assuming that you have three locations that you want to patch,
so the first one is this array of bytes.
So you, as usual, you will put it in this,
assign it to this variable.
And then the bytes that you're going to use to replace will be in the second variable.
And I rename it as "array_to_find_one"
and "data_to_replace_one."
And assume you have a second array of bytes which you'd like to patch.
Then that will be under the second variable "data_to_find_two" and you just paste it here, and the data
to replace it with is called "data_to_replace_two," which you put it here. And assume again that you have
a third array of bytes that you want to patch.
So you put it in a third location here.
Third, you assign it to the third variable here, "data_to_find_three."
And the bytes which you are going to use to replace them will be assigned to this variable "data_to_replace_three."
"data_to_replace_three."
So this, you can create as many as you want.
Here we have 3, 1, 2, 3.
So if you have a fourth one, just create another set, "data_to_replace_four," "data_to_find_four," and "data_to_replace_four."
"data_to_replace_four."
Now the next part is to do the same thing to this code here.
So you duplicate it twice.
So you have three segments here.
The first one you rename the variable to "data_to_find_bytes_one," "data_to_replace_bytes_one."
And here you, you put it as "data_to_find_one," which is coming from here, and "data_to_replace_one," coming
from here.
And then the second batch is "data_to_find_bytes_two,"
"data_to_replace_bytes_two."
And then here, replace it with "data_to_find_two," which is coming from here.
There are two, "data_to_replace_two," which is coming from here.
And finally, the third batch is "data_to_find_bytes_three" and "data_to_replace_bytes_three," and the corresponding
"data_to_find_three" and "data_to_replace_three."
Now if you have four, let's say you have four, "data_to_find_four" and "data_to_replace_four"
here,
also you need to create a fourth, a fourth batch and change the variables accordingly.
Just copy and paste and change accordingly.
So these are the changes you make that you had, that I have made to the original script.
You,
so you can have as many bytes, array of bytes as you like, as many patches as you want.
So if there are three here, there should be three here as well.
Now the next change is over here.
If you scroll down to the bottom,
so you also find that now this part here has been changed.
Originally it was a "patch_memory," which looks like this,
a simple one.
So now I've redone it to become a separate function, "patch_memory."
So "patch_memory" now is here, a new function.
Previously we just have "write_memory" directly here like this.
And I've now, uh, redone the code.
So now you have "patch_memory."
So "patch_memory" is a function which will handle the patching itself,
and you can call it multiple times.
So here I call it three times.
The first one is to pass the first batch of array of bytes and the "data_to_replace_bytes_one."
The second time I call it is "data_to_find_bytes_two," the second array of bytes, and the second set of
hex bytes to replace it with. And the third one is here.
So we call it three times, 1, 2, 3.
This three here is referring to, is referring to this three over here.
First set,
second set,
third set.
So if you have four here, let's say you have, you have four, four array of bytes here, also four.
Then you will call,
you will call this function four times.
The fourth time will be "data_to_find_bytes_four," "data_to_replace_bytes_four."
So you can, you can modify it accordingly.
So this script is a template which you can use to patch more than one array of bytes.
If you have only two, then of course you delete the third batch here and then use only two.
And then, uh, here also we have two.
And then down here also you have only two calls.
So you have unlimited number of calls which you can make using this Python script.
So I hope this makes it more flexible for you guys,
uh, to write Python script that can patch any number of array of bytes that you like.
So that's all for this video.
Thank you for watching.