C# Binary Search + Replace
How can i search for a specified byte array and replace everything from the beginning to this byte array (included)
Basically i have my pattern to find
byte find = { 0x00, 0x48, 0x00 };
and
byte ddsHeaderDXT1 = { 0x44, 0x44, 0x53, 0x20, 0x7C, 0x00, 0x00, 0x00, 0x07, 0x10, 0x08, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4E, 0x56, 0x54, 0x54, 0x06, 0x00, 0x02, 0x00, 0x20, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x44, 0x58, 0x54, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10 };
the thing i wanna do is to search for my find
array, once it's found, select all bytes from the beginning of the file to this find
array included, and replace all this with my ddsHeaderDXT1
array.
The file can be pretty big but the pattern is always at the beginning (less than 500 first bytes), not always at the same offset and can be found only once.
I have already tried rene's code here but it doesn't do anything.
Also i get my file from OpenFileDialog and read its bytes
byte src = File.ReadAllBytes(ofdFilePath);
c# search replace byte
add a comment |
How can i search for a specified byte array and replace everything from the beginning to this byte array (included)
Basically i have my pattern to find
byte find = { 0x00, 0x48, 0x00 };
and
byte ddsHeaderDXT1 = { 0x44, 0x44, 0x53, 0x20, 0x7C, 0x00, 0x00, 0x00, 0x07, 0x10, 0x08, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4E, 0x56, 0x54, 0x54, 0x06, 0x00, 0x02, 0x00, 0x20, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x44, 0x58, 0x54, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10 };
the thing i wanna do is to search for my find
array, once it's found, select all bytes from the beginning of the file to this find
array included, and replace all this with my ddsHeaderDXT1
array.
The file can be pretty big but the pattern is always at the beginning (less than 500 first bytes), not always at the same offset and can be found only once.
I have already tried rene's code here but it doesn't do anything.
Also i get my file from OpenFileDialog and read its bytes
byte src = File.ReadAllBytes(ofdFilePath);
c# search replace byte
"I have already tried rene's code here but it doesn't do anything". I doubt it does not do anything. What have you tried exactly, and how did that not work precisely as you expected?
– elgonzo
Nov 18 '18 at 19:32
If you want to replace everything from the beginning andddsHeaderDXT1
is shorter than the position found, what do you expect to happen?
– Olivier Jacot-Descombes
Nov 18 '18 at 19:38
@elgonzo i have triedReplaceBytes(src, find, ddsHeaderDXT1);
and it just didn't change my file but there was no error, maybe i did something wrong. @OlivierJacot-Descombes then i just wanna insert and increase the file size ¯_(ツ)_/¯
– Asval
Nov 18 '18 at 20:06
What I mean is,ddsHeaderDXT1
has a length of 110. If you find the pattern at position 400, you can fill the bytes at indexes 0 .. 109 with it. With what are you going to fill the bytes 110 .. 399?
– Olivier Jacot-Descombes
Nov 18 '18 at 20:10
@OlivierJacot-Descombes then i just wanna delete the rest
– Asval
Nov 18 '18 at 20:11
add a comment |
How can i search for a specified byte array and replace everything from the beginning to this byte array (included)
Basically i have my pattern to find
byte find = { 0x00, 0x48, 0x00 };
and
byte ddsHeaderDXT1 = { 0x44, 0x44, 0x53, 0x20, 0x7C, 0x00, 0x00, 0x00, 0x07, 0x10, 0x08, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4E, 0x56, 0x54, 0x54, 0x06, 0x00, 0x02, 0x00, 0x20, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x44, 0x58, 0x54, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10 };
the thing i wanna do is to search for my find
array, once it's found, select all bytes from the beginning of the file to this find
array included, and replace all this with my ddsHeaderDXT1
array.
The file can be pretty big but the pattern is always at the beginning (less than 500 first bytes), not always at the same offset and can be found only once.
I have already tried rene's code here but it doesn't do anything.
Also i get my file from OpenFileDialog and read its bytes
byte src = File.ReadAllBytes(ofdFilePath);
c# search replace byte
How can i search for a specified byte array and replace everything from the beginning to this byte array (included)
Basically i have my pattern to find
byte find = { 0x00, 0x48, 0x00 };
and
byte ddsHeaderDXT1 = { 0x44, 0x44, 0x53, 0x20, 0x7C, 0x00, 0x00, 0x00, 0x07, 0x10, 0x08, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4E, 0x56, 0x54, 0x54, 0x06, 0x00, 0x02, 0x00, 0x20, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x44, 0x58, 0x54, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10 };
the thing i wanna do is to search for my find
array, once it's found, select all bytes from the beginning of the file to this find
array included, and replace all this with my ddsHeaderDXT1
array.
The file can be pretty big but the pattern is always at the beginning (less than 500 first bytes), not always at the same offset and can be found only once.
I have already tried rene's code here but it doesn't do anything.
Also i get my file from OpenFileDialog and read its bytes
byte src = File.ReadAllBytes(ofdFilePath);
c# search replace byte
c# search replace byte
asked Nov 18 '18 at 19:20
AsvalAsval
31
31
"I have already tried rene's code here but it doesn't do anything". I doubt it does not do anything. What have you tried exactly, and how did that not work precisely as you expected?
– elgonzo
Nov 18 '18 at 19:32
If you want to replace everything from the beginning andddsHeaderDXT1
is shorter than the position found, what do you expect to happen?
– Olivier Jacot-Descombes
Nov 18 '18 at 19:38
@elgonzo i have triedReplaceBytes(src, find, ddsHeaderDXT1);
and it just didn't change my file but there was no error, maybe i did something wrong. @OlivierJacot-Descombes then i just wanna insert and increase the file size ¯_(ツ)_/¯
– Asval
Nov 18 '18 at 20:06
What I mean is,ddsHeaderDXT1
has a length of 110. If you find the pattern at position 400, you can fill the bytes at indexes 0 .. 109 with it. With what are you going to fill the bytes 110 .. 399?
– Olivier Jacot-Descombes
Nov 18 '18 at 20:10
@OlivierJacot-Descombes then i just wanna delete the rest
– Asval
Nov 18 '18 at 20:11
add a comment |
"I have already tried rene's code here but it doesn't do anything". I doubt it does not do anything. What have you tried exactly, and how did that not work precisely as you expected?
– elgonzo
Nov 18 '18 at 19:32
If you want to replace everything from the beginning andddsHeaderDXT1
is shorter than the position found, what do you expect to happen?
– Olivier Jacot-Descombes
Nov 18 '18 at 19:38
@elgonzo i have triedReplaceBytes(src, find, ddsHeaderDXT1);
and it just didn't change my file but there was no error, maybe i did something wrong. @OlivierJacot-Descombes then i just wanna insert and increase the file size ¯_(ツ)_/¯
– Asval
Nov 18 '18 at 20:06
What I mean is,ddsHeaderDXT1
has a length of 110. If you find the pattern at position 400, you can fill the bytes at indexes 0 .. 109 with it. With what are you going to fill the bytes 110 .. 399?
– Olivier Jacot-Descombes
Nov 18 '18 at 20:10
@OlivierJacot-Descombes then i just wanna delete the rest
– Asval
Nov 18 '18 at 20:11
"I have already tried rene's code here but it doesn't do anything". I doubt it does not do anything. What have you tried exactly, and how did that not work precisely as you expected?
– elgonzo
Nov 18 '18 at 19:32
"I have already tried rene's code here but it doesn't do anything". I doubt it does not do anything. What have you tried exactly, and how did that not work precisely as you expected?
– elgonzo
Nov 18 '18 at 19:32
If you want to replace everything from the beginning and
ddsHeaderDXT1
is shorter than the position found, what do you expect to happen?– Olivier Jacot-Descombes
Nov 18 '18 at 19:38
If you want to replace everything from the beginning and
ddsHeaderDXT1
is shorter than the position found, what do you expect to happen?– Olivier Jacot-Descombes
Nov 18 '18 at 19:38
@elgonzo i have tried
ReplaceBytes(src, find, ddsHeaderDXT1);
and it just didn't change my file but there was no error, maybe i did something wrong. @OlivierJacot-Descombes then i just wanna insert and increase the file size ¯_(ツ)_/¯– Asval
Nov 18 '18 at 20:06
@elgonzo i have tried
ReplaceBytes(src, find, ddsHeaderDXT1);
and it just didn't change my file but there was no error, maybe i did something wrong. @OlivierJacot-Descombes then i just wanna insert and increase the file size ¯_(ツ)_/¯– Asval
Nov 18 '18 at 20:06
What I mean is,
ddsHeaderDXT1
has a length of 110. If you find the pattern at position 400, you can fill the bytes at indexes 0 .. 109 with it. With what are you going to fill the bytes 110 .. 399?– Olivier Jacot-Descombes
Nov 18 '18 at 20:10
What I mean is,
ddsHeaderDXT1
has a length of 110. If you find the pattern at position 400, you can fill the bytes at indexes 0 .. 109 with it. With what are you going to fill the bytes 110 .. 399?– Olivier Jacot-Descombes
Nov 18 '18 at 20:10
@OlivierJacot-Descombes then i just wanna delete the rest
– Asval
Nov 18 '18 at 20:11
@OlivierJacot-Descombes then i just wanna delete the rest
– Asval
Nov 18 '18 at 20:11
add a comment |
1 Answer
1
active
oldest
votes
The following should do the trick:
public static bool TryFindAndReplace<T>(
T source,
T pattern,
T replacement,
out T newArray)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
if (pattern == null)
throw new ArgumentNullException(nameof(pattern));
if (replacement == null)
throw new ArgumentNullException(nameof(replacement));
newArray = null;
if (pattern.Length > source.Length)
return false;
for (var start = 0;
start < source.Length - pattern.Length + 1;
start += 1)
{
var segment = new ArraySegment<T>(source, start, pattern.Length);
if (Enumerable.SequenceEqual(segment, pattern))
{
newArray = replacement.Concat(source.Skip(start + pattern.Length))
.ToArray();
return true;
}
}
return false;
}
Simple to read and therefore simple to understand. Its not the fastest solution by any means, but things need to be as fast as you need them to be, not faster.
If you need a more performant implementation, you can optimize from here.
thanks for the answer, i'm still kinda new to c#, what does <T> means and how can i use this?
– Asval
Nov 18 '18 at 20:17
@Asval it’s generics. It enables you to being able to use this method with any type, not just bytes. Think ofT
as “insert type here”
– InBetween
Nov 18 '18 at 21:41
oh alright i got it, it's smart :) thanks btw your code works like a charm :D
– Asval
Nov 18 '18 at 22:25
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53364589%2fc-sharp-binary-search-replace%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The following should do the trick:
public static bool TryFindAndReplace<T>(
T source,
T pattern,
T replacement,
out T newArray)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
if (pattern == null)
throw new ArgumentNullException(nameof(pattern));
if (replacement == null)
throw new ArgumentNullException(nameof(replacement));
newArray = null;
if (pattern.Length > source.Length)
return false;
for (var start = 0;
start < source.Length - pattern.Length + 1;
start += 1)
{
var segment = new ArraySegment<T>(source, start, pattern.Length);
if (Enumerable.SequenceEqual(segment, pattern))
{
newArray = replacement.Concat(source.Skip(start + pattern.Length))
.ToArray();
return true;
}
}
return false;
}
Simple to read and therefore simple to understand. Its not the fastest solution by any means, but things need to be as fast as you need them to be, not faster.
If you need a more performant implementation, you can optimize from here.
thanks for the answer, i'm still kinda new to c#, what does <T> means and how can i use this?
– Asval
Nov 18 '18 at 20:17
@Asval it’s generics. It enables you to being able to use this method with any type, not just bytes. Think ofT
as “insert type here”
– InBetween
Nov 18 '18 at 21:41
oh alright i got it, it's smart :) thanks btw your code works like a charm :D
– Asval
Nov 18 '18 at 22:25
add a comment |
The following should do the trick:
public static bool TryFindAndReplace<T>(
T source,
T pattern,
T replacement,
out T newArray)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
if (pattern == null)
throw new ArgumentNullException(nameof(pattern));
if (replacement == null)
throw new ArgumentNullException(nameof(replacement));
newArray = null;
if (pattern.Length > source.Length)
return false;
for (var start = 0;
start < source.Length - pattern.Length + 1;
start += 1)
{
var segment = new ArraySegment<T>(source, start, pattern.Length);
if (Enumerable.SequenceEqual(segment, pattern))
{
newArray = replacement.Concat(source.Skip(start + pattern.Length))
.ToArray();
return true;
}
}
return false;
}
Simple to read and therefore simple to understand. Its not the fastest solution by any means, but things need to be as fast as you need them to be, not faster.
If you need a more performant implementation, you can optimize from here.
thanks for the answer, i'm still kinda new to c#, what does <T> means and how can i use this?
– Asval
Nov 18 '18 at 20:17
@Asval it’s generics. It enables you to being able to use this method with any type, not just bytes. Think ofT
as “insert type here”
– InBetween
Nov 18 '18 at 21:41
oh alright i got it, it's smart :) thanks btw your code works like a charm :D
– Asval
Nov 18 '18 at 22:25
add a comment |
The following should do the trick:
public static bool TryFindAndReplace<T>(
T source,
T pattern,
T replacement,
out T newArray)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
if (pattern == null)
throw new ArgumentNullException(nameof(pattern));
if (replacement == null)
throw new ArgumentNullException(nameof(replacement));
newArray = null;
if (pattern.Length > source.Length)
return false;
for (var start = 0;
start < source.Length - pattern.Length + 1;
start += 1)
{
var segment = new ArraySegment<T>(source, start, pattern.Length);
if (Enumerable.SequenceEqual(segment, pattern))
{
newArray = replacement.Concat(source.Skip(start + pattern.Length))
.ToArray();
return true;
}
}
return false;
}
Simple to read and therefore simple to understand. Its not the fastest solution by any means, but things need to be as fast as you need them to be, not faster.
If you need a more performant implementation, you can optimize from here.
The following should do the trick:
public static bool TryFindAndReplace<T>(
T source,
T pattern,
T replacement,
out T newArray)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
if (pattern == null)
throw new ArgumentNullException(nameof(pattern));
if (replacement == null)
throw new ArgumentNullException(nameof(replacement));
newArray = null;
if (pattern.Length > source.Length)
return false;
for (var start = 0;
start < source.Length - pattern.Length + 1;
start += 1)
{
var segment = new ArraySegment<T>(source, start, pattern.Length);
if (Enumerable.SequenceEqual(segment, pattern))
{
newArray = replacement.Concat(source.Skip(start + pattern.Length))
.ToArray();
return true;
}
}
return false;
}
Simple to read and therefore simple to understand. Its not the fastest solution by any means, but things need to be as fast as you need them to be, not faster.
If you need a more performant implementation, you can optimize from here.
edited Nov 18 '18 at 20:00
answered Nov 18 '18 at 19:46
InBetweenInBetween
25.3k34068
25.3k34068
thanks for the answer, i'm still kinda new to c#, what does <T> means and how can i use this?
– Asval
Nov 18 '18 at 20:17
@Asval it’s generics. It enables you to being able to use this method with any type, not just bytes. Think ofT
as “insert type here”
– InBetween
Nov 18 '18 at 21:41
oh alright i got it, it's smart :) thanks btw your code works like a charm :D
– Asval
Nov 18 '18 at 22:25
add a comment |
thanks for the answer, i'm still kinda new to c#, what does <T> means and how can i use this?
– Asval
Nov 18 '18 at 20:17
@Asval it’s generics. It enables you to being able to use this method with any type, not just bytes. Think ofT
as “insert type here”
– InBetween
Nov 18 '18 at 21:41
oh alright i got it, it's smart :) thanks btw your code works like a charm :D
– Asval
Nov 18 '18 at 22:25
thanks for the answer, i'm still kinda new to c#, what does <T> means and how can i use this?
– Asval
Nov 18 '18 at 20:17
thanks for the answer, i'm still kinda new to c#, what does <T> means and how can i use this?
– Asval
Nov 18 '18 at 20:17
@Asval it’s generics. It enables you to being able to use this method with any type, not just bytes. Think of
T
as “insert type here”– InBetween
Nov 18 '18 at 21:41
@Asval it’s generics. It enables you to being able to use this method with any type, not just bytes. Think of
T
as “insert type here”– InBetween
Nov 18 '18 at 21:41
oh alright i got it, it's smart :) thanks btw your code works like a charm :D
– Asval
Nov 18 '18 at 22:25
oh alright i got it, it's smart :) thanks btw your code works like a charm :D
– Asval
Nov 18 '18 at 22:25
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53364589%2fc-sharp-binary-search-replace%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
"I have already tried rene's code here but it doesn't do anything". I doubt it does not do anything. What have you tried exactly, and how did that not work precisely as you expected?
– elgonzo
Nov 18 '18 at 19:32
If you want to replace everything from the beginning and
ddsHeaderDXT1
is shorter than the position found, what do you expect to happen?– Olivier Jacot-Descombes
Nov 18 '18 at 19:38
@elgonzo i have tried
ReplaceBytes(src, find, ddsHeaderDXT1);
and it just didn't change my file but there was no error, maybe i did something wrong. @OlivierJacot-Descombes then i just wanna insert and increase the file size ¯_(ツ)_/¯– Asval
Nov 18 '18 at 20:06
What I mean is,
ddsHeaderDXT1
has a length of 110. If you find the pattern at position 400, you can fill the bytes at indexes 0 .. 109 with it. With what are you going to fill the bytes 110 .. 399?– Olivier Jacot-Descombes
Nov 18 '18 at 20:10
@OlivierJacot-Descombes then i just wanna delete the rest
– Asval
Nov 18 '18 at 20:11