当前位置:网站首页 > 新媒体 > 正文

exe怎么解压成文件(电脑上强力卸载的软件找回方法)

0 李勇seo 李勇seo 2025-04-25 23:29 3

前有有讲过,如何通过JAVA,将JAR制作成自解压的exe文件。现收到需求:用户下载exe时,自动往exe文件中添加或覆盖某文件。

思路:

JAVA 修改自解压文件内容

1、由于自解压的exe文件由sfx、config.txt、7z压缩文件组成。所以直接用SevenZFile是打不开该文件的。

2、从exe文件中,找到config.txt结尾标识的位置(pos).

3、将exe文件拆会成两具临时文件件:sfx+config.txt文件,z7.7z压缩包文件。

4、调用SevenZFile,添加中覆盖文件组成新的压缩文件newz7.7z压缩包。

5、合并sfx+config.txt文件、newz7.7z压缩包成exe生解压文件。

代码如下:

其中:d:\test\7z自解压.exe 为自解压exe文件。

/**
	 * 查找文件中的config.txt结尾位置
	 * 
	 * @throws IOException
	 */
	@Test
	public void getConfigEndPosTest() throws IOException {
		final File exeFile = new File("d:\test\7z自解压.exe");
		final byte[] configEnd= ";!@InstallEnd@!".getBytes("ISO-8859-1");
		final BufferedInputStream exeBis = new BufferedInputStream(new FileInputStream(exeFile));
		// sfx假定大于124928
		exeBis.skip(124928);
		int b;
		long pos = 124928;
		int macth = 0;
		while ((b = exeBis.read()) != -1) {
			pos++;
			if (configEnd[macth] == b) {
				macth++;
			} else {
				macth = 0;
			}
			if (macth == 15) {
				System.out.print(pos);
				break;
			}
		}
		exeBis.close();
	}

	/**
	 * 自解压文件拆分成: sfx+config, 7z两个临时文件
	 * 
	 * @throws IOException
	 */
	@Test
	public void splitFileTest() throws IOException {
		final File exeFile = new File("d:\test\7z自解压.exe");
		final FileInputStream exeIn = new FileInputStream(exeFile);

		final File sfxFile = new File("d:\test\sfx.tmp");
		sfxFile.createNewFile();
		final FileOutputStream sfxOs = new FileOutputStream(sfxFile);
		// 125070 第一步求得的pos
		byte[] buffer = new byte[125070];
		int length;
		length = exeIn.read(buffer);
		sfxOs.write(buffer, 0, length);
		sfxOs.close();

		final File z7File = new File("d:\test\z7.7z");
		z7File.createNewFile();
		final FileOutputStream z7Os = new FileOutputStream(z7File);
		while ((length = exeIn.read(buffer)) > 0) {
			z7Os.write(buffer, 0, length);
		}
		z7Os.close();
		exeIn.close();
	}

	/**
	 * 添加或覆盖的文件到7z
	 * 
	 * @throws IOException
	 */
	@Test
	public void writeFileTo7z() throws IOException {
		 //略,7z文件处理
	}
	
	/**
	 * sfx+config + 新的7z文件成exe.
	 * @throws IOException
	 */
	@Test
	public void mergeFile() throws IOException {
		//略, 参考前一篇的《JAVA JAR制作可自运行的EXE包》
	}
李勇seo

李勇seo

TA很懒,啥都没写...

本文暂时没有评论,来添加一个吧(●'◡'●)

取消回复欢迎 发表评论:

@百闻站长 本站部分内容转自互联网,若有侵权等问题请及时与本站联系,我们将在第一时间删除处理。 | 粤ICP备2025402138号 | (地图