For example, functionality like this would be ideal:
Code: Select all
result.i = HexReplaceInFile("test.exe", "F606017415538D", "8026007415538D")
Code: Select all
result.i = HexReplaceInFile("test.exe", "F606017415538D", "8026007415538D")
Code: Select all
length = 32 ; or whatever it is
*searchdata = AllocateMemory(length)
*replacedata = AllocateMemory(length)
*testdata = AllocateMemory(length)
;///////////////////////////////////////////////////////////
; Here place your search and replace data in the mem blocks
;///////////////////////////////////////////////////////////
If OpenFile(0, "myfile.bin")
readpos = 0
thiseof = Lof(0) - length
While (Not Eof(0)) And readpos <= thiseof
FileSeek(0, readpos)
ReadData(0, *testdata, length)
If CompareMemory(*testdata, *searchdata, length)
WriteData(readpos, *replacedata, length)
EndIf
readpos + 1
Wend
CloseFile(0)
EndIf
LOL, okay okay... I'll play with it. Point taken. Thanks again.netmaestro wrote:Note that I fixed a typo which would cause it to fail. Afaik an actual example would look like this one here:
http://www.purebasic.fr/english/viewtop ... 76&start=3
Code: Select all
*searchdata = "hello"
*replacedata = "there"
wallgod wrote:
I don't know how to place data into memory blocks.
returns the error "trying to write a string into a numerical variable"Code: Select all
*searchdata = "hello" *replacedata = "there"
Sigh... the embarrassment of being a n00b.
Code: Select all
*searchdata = @"hello"
*replacedata = @"there"
Ahhh... merci! What does that @ actually mean?rsts wrote:wallgod wrote:
I don't know how to place data into memory blocks.
returns the error "trying to write a string into a numerical variable"Code: Select all
*searchdata = "hello" *replacedata = "there"
Sigh... the embarrassment of being a n00b.cheersCode: Select all
*searchdata = @"hello" *replacedata = @"there"
Oh okay, so if i set *searchdata = @"hello", it jumps to the first position in the memory block containing that string?rsts wrote:When you set *searchdata = "hello" you're attempting to set the string "hello" as a memory address, thus the error.
setting *searchdata = @"hello" sets the memorypointer *searchdata to the location in memory of the string "hello" or @(the memory location of)"hello"
cheers
Code: Select all
Procedure.s AsciiToHex(binData$)
tdata$ = Space(Len(binData$)*2)
BinToHex(@binData$,Len(binData$),@tdata$,#False)
ProcedureReturn tdata$
EndProcedure
Procedure.s HexToAscii(hexdata$)
hdata$ = Space(Len(hexdata$))
HexToBin(@hexdata$,Len(hexdata$),@hdata$)
ProcedureReturn hdata$
EndProcedure
length = 7 ; or whatever it is
*searchdata = AllocateMemory(length)
*replacedata = AllocateMemory(length)
*testdata = AllocateMemory(length)
;///////////////////////////////////////////////////////////
*searchdata = @HexToAscii("F606017415538D")
*replacedata = @HexToAscii("8026007415538D")
MessageRequester("","get here?",#MB_OK)
;///////////////////////////////////////////////////////////
If OpenFile(0, "test.dll")
readpos = 0
thiseof = Lof(0) - length
While (Not Eof(0)) And readpos <= thiseof
FileSeek(0, readpos)
ReadData(0, *testdata, length)
If CompareMemory(*testdata, *searchdata, length)
WriteData(readpos, *replacedata, length)
EndIf
readpos + 1
Wend
CloseFile(0)
EndIf
Code: Select all
ToFind$ = "F606017415538D"
ToReplace$ = "8026007415538D"
length = Len(ToFind$)/2
*searchdata = AllocateMemory(length)
*replacedata = AllocateMemory(length)
*testdata = AllocateMemory(length)
;///////////////////////////////////////////////////////////
; Here place your search and replace data in the mem blocks
For k=0 To length-1
PokeB(*searchdata+k ,Val("$"+PeekS(@ToFind$+(k*2) ,2)))
PokeB(*replacedata+k,Val("$"+PeekS(@ToReplace$+(k*2),2)))
Next
;///////////////////////////////////////////////////////////
If OpenFile(0, "myfile.bin")
readpos = 0
thiseof = Lof(0) - length
While (Not Eof(0)) And readpos <= thiseof
FileSeek(0, readpos)
ReadData(0, *testdata, length)
If CompareMemory(*testdata, *searchdata, length)
WriteData(0, *replacedata, length)
EndIf
readpos + 1
Wend
CloseFile(0)
EndIf