Replace IncludeBinary

Share your advanced PureBasic knowledge/code with the community.
User avatar
oryaaaaa
Addict
Addict
Posts: 825
Joined: Mon Jan 12, 2004 11:40 pm
Location: Okazaki, JAPAN

Replace IncludeBinary

Post by oryaaaaa »

Code updated For 5.20+

You are use this code for each PC including different license information etc.

IncludeSource::"easyshut.exe"

Code: Select all

Country.s="@@@@@@@@@"
MessageRequester("TEST", Country+"'s prices are high. ", #MB_OK)
MainSource::

Code: Select all

    ; ##################  Referred code #####################
    ; PureBasic :: View topic - Search for strings in a binary file
    ; http://www.purebasic.fr/english/viewtopic.php?t=18675
    ; Author MrMat

    DataSection
    ClientFile:
     IncludeBinary "easyshut.exe"
    ClientFileEnd:
    EndDataSection

    Procedure ReplaceIncludeBinary(*binaryfile,binarysize, String1.s, String2.s)
      stringsize=Len(String1)
      *finalpos= *binaryfile + binarysize - stringsize
      *searchpos = *binaryfile
      While *binaryfile <= *finalpos
        pos=0
        While pos < stringsize And PeekB(*searchpos + pos) = PeekB(@String1 + pos)
          pos +1
        Wend
        If pos = stringsize
          result =1
          Break
        EndIf
        *searchpos + 1
      Wend
      If result = 1 And Len(String2) <= stringsize
        PokeS(*searchpos, String2)
        ProcedureReturn #True
      EndIf
      ProcedureReturn #False
    EndProcedure

    If ReplaceIncludeBinary(?ClientFile, ?ClientFileEnd-?ClientFile, "@@@@@@@@", "JAPAN"+Chr(0))
      CreateFile(1, "easyshut2.exe")
      WriteData(1, ?ClientFile, ?ClientFileEnd-?ClientFile)
      CloseFile(1) 
      MessageRequester("Result", "Create Binary", #MB_OK)
    EndIf

    End