1 つの実行可能ファイルをもう 1 つの実行可能ファイルの末尾に追加し、一時フォルダーに展開するコードを記述できます。
以前に同様のことを行ったことがありますが、構成ファイルといくつかのビットマップを Windows の EXE に追加しました。私が行った方法は、最初にEXEの最後に自分のものを追加し、その後、2番目のexeのオフセットになるデータのファイルオフセットを含む小さな構造体を書くことでした。
アプリを実行するときは、ファイルの末尾から構造体のサイズを引いたところまでシークし、ファイル オフセットを抽出して 2 番目の exe を一時フォルダーにコピーしてから起動します。
OK、リクエストに応じてもう少し詳しく説明します。これは、結合された EXE を作成するための擬似コードです。これは、メインの EXE をコンパイルした後に実行する小さなユーティリティです。
Open destination file
Open main exe as a binary file
Copy main exe to destination file
offset = size of main exe
Open 2nd exe as a binary file
Copy 2nd exe to the output file
Write the offset to the output file
では、抽出手順です。これは、メインの EXE に入ります。
Find the location of our own EXE file (GetModuleFileName() under Windows)
Open the file in binary mode
Seek to the end minus sizeof(offset) (typically 4 bytes)
Read the offset value
Seek to the offset position
Open a temporary file in binary mode
Read bytes from the main EXE and write to the temporary file
Launch the temporary file