CFR-Windows环境CFR工具的下载和使用

CFR-Windows环境CFR工具的下载和使用

一、下载命令

curl -L -o cfr-0.152.jar "https://www.benf.org/other/cfr/cfr-0.152.jar"

或者

通过网盘分享的文件:cfr-0.152.jar
链接: https://pan.baidu.com/s/1LrDSXBUiuROvbnzeMpTrqg?pwd=sky1 提取码: sky1

二、使用CFR命令反编译.class文件

java -jar /path/to/cfr.jar /path/to/YourClass.class

三、编译后的.java文件 中文字符都为unicode编码,将以下脚本放入到项目更目录文件夹下,并执行以下命令

python unicode_converter.py

root_dir替换成实际项目地址

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import re
import codecs

def unicode_to_chinese(text):
	"""将Unicode转义序列转换为中文字符"""
	def replace_unicode(match):
		unicode_str = match.group(0)
		try:
			# 提取Unicode码点
			code_point = unicode_str.replace('\\u', '')
			# 转换为字符
			char = chr(int(code_point, 16))
			return char
		except:
			return unicode_str

	# 匹配\uXXXX格式的Unicode转义序列
	pattern = r'\\u[0-9a-fA-F]{4}'
	return re.sub(pattern, replace_unicode, text)

def process_java_file(file_path):
	"""处理单个Java文件"""
	try:
		with open(file_path, 'r', encoding='utf-8') as f:
			content = f.read()

		# 转换Unicode转义序列
		new_content = unicode_to_chinese(content)

		# 如果内容有变化,写回文件
		if new_content != content:
			with open(file_path, 'w', encoding='utf-8') as f:
				f.write(new_content)
			print(f"已处理: {file_path}")
			return True
	except Exception as e:
		print(f"处理文件时出错 {file_path}: {e}")

	return False

def main():
	# 项目根目录
	root_dir = "C:/xxx/src"
	processed_count = 0

	# 遍历所有Java文件
	for root, dirs, files in os.walk(root_dir):
		for file in files:
			if file.endswith('.java'):
				file_path = os.path.join(root, file)
				if process_java_file(file_path):
					processed_count += 1

	print(f"处理完成,共转换了 {processed_count} 个文件")

if __name__ == "__main__":
	main()
posted @ 2025-08-27 15:46  skystrivegao  阅读(146)  评论(0)    收藏  举报