Save data in executable

后端 未结 7 1231
Happy的楠姐
Happy的楠姐 2021-02-04 13:12

I have a portable executable that saves data to a file in the same folder as the executable. Is there any way that I can save data into the executable itself when I close the ap

相关标签:
7条回答
  • 2021-02-04 14:09

    you can add data to end of executable file :

    var executableName = Process.GetCurrentProcess().MainModule.FileName;
    
        // rename executable file
        var newExecutableName = fullPath.Replace(".exe", "_.exe");
        FileInfo fi = new FileInfo(executableName);
        fi.MoveTo(newExecutableName);
    
        // make copy of executable file to original name
        File.Copy(newExecutableName, executableName);
    
        // write data end of new file
        var bytes = Encoding.ASCII.GetBytes("new data...");
    
        using (FileStream file = File.OpenWrite(executableName))
          {
              file.Seek(0, SeekOrigin.End);
              file.Write(bytes, 0, bytes.Length);
           }
    
        // we can delete old file when exited
    
    0 讨论(0)
提交回复
热议问题