Как в golang изменить строку в уже скомпилированном exe файле? Действия будут происходить на стороне клиента, программа будет уже установлена и работать, необходимо изменить определённую строку в этой программе.
Вот код на purebasic, как реализовать тоже самое на golang и желательно без winApi.
Procedure.s MainPart(Text.s)
;Simple text-Box
OpenWindow(0,0,0,240,160,"Notes",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
;CreateGadgetList(WindowID(0))
StringGadget(0,5,5,230,150,Text,#ES_MULTILINE|#WS_VSCROLL|#WS_HSCROLL|#ES_AUTOHSCROLL|#ES_AUTOVSCROLL)
Repeat:Until WaitWindowEvent() = #PB_Event_CloseWindow;EventCloseWindow
ProcedureReturn GetGadgetText(0)
EndProcedure
;Get program and temp-folder name
program.s= Space(1000):GetModuleFileName_(0,program,1000)
temp.s= Space(1000):GetTempPath_(1000,temp)
;Construct Clone-Name
clone.s= temp+"_"+GetFilePart(program)
;Check mode by parameter
mode.s=ProgramParameter()
If mode="clone" ;I am the clone
;Check if another instance is running (cause makes no sense here)
Mutex=CreateMutex_(0,1,"Mischas Notes")
Error=GetLastError_()
If Mutex<>0 And Error=0
program=ProgramParameter()
Size=FileSize(program)
ReadFile(0,program)
FileSeek(0,Size-12)
If ReadLong(0) = 1234321 ;this is a sign for us that there are resources inside
Size=ReadLong(0)
resourcesize=ReadLong(0)
FileSeek(0,Size)
*res=AllocateMemory(resourcesize)
ReadData(0,*res,resourcesize)
resource.s=PeekS(*res)
EndIf
FileSeek(0,0)
*header=AllocateMemory(Size)
ReadData(0,*header,Size) ;Put the small main-program in the pocket (alternate do this in the end)
CloseFile(0)
newtext.s=MainPart(resource) ;The main-program
If newtext <> resource ;Ok, now we construct new program with new resources
resourcesize=Len(newtext) + 1
*res=AllocateMemory(resourcesize)
PokeS(*res,newtext)
SetFileAttributes_(program,#FILE_ATTRIBUTE_NORMAL) ;maybe its write-protected
CreateFile(1,program)
WriteData(1,*header,Size) ;program-part
WriteData(1,*res,resourcesize) ;resource-part
WriteLong(1,1234321) ;Our sign
WriteLong(1,Size) ;Adress of resources
WriteLong(1,resourcesize) ;Size of resources
CloseFile(1)
EndIf
RunProgram(program,"killclone","",0)
EndIf
CloseHandle_(Mutex)
ElseIf mode="killclone" ;Delete clone of program
Sleep_(500)
DeleteFile(clone)
Else ;normal mode
;Create and start clone
If FileSize(clone) = -1
CopyFile(program,clone)
EndIf
RunProgram(clone,"clone "+Chr(34)+program+Chr(34),"",0)
EndIf
End
https://dropmefiles.com/kUUVj - скомпилированный вариант.