网页上显示出hex编码
<%@ page import="java.sql.*" %>
<%@ page import="java.io.PrintWriter" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.TimeZone" %>
<html>
<head>
<title>Display File Content</title>
</head>
<body>
<%
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
try {
// 数据库连接信息
String jdbcUrl = "jdbc:mysql://localhost:3306/ceshi?useSSL=false&serverTimezone=" + TimeZone.getDefault().getID();
String user = "root";
String password = "root";
// 加载驱动程序
Class.forName("com.mysql.jdbc.Driver");
// 建立数据库连接
connection = DriverManager.getConnection(jdbcUrl, user, password);
statement = connection.createStatement();
// 查询文件内容
String sql = "SELECT HEX(LOAD_FILE('/home/1.txt')) AS hex_content";
resultSet = statement.executeQuery(sql);
if (resultSet.next()) {
String hexContent = resultSet.getString("hex_content");
// 在网页上显示文件内容
out.println(hexContent);
} else {
out.println("<p>File not found or permission denied.</p>");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
// 关闭数据库连接
try {
if (resultSet != null) resultSet.close();
if (statement != null) statement.close();
if (connection != null) connection.close();
} catch (SQLException e) {
}
}
%>
</body>
</html>
python代码hex转成
import binascii
# 读取hex编码的内容
with open('/home//1.txt', 'r') as file:
hex_content = file.read().strip()
# 将hex转换为bytes
binary_content = binascii.unhexlify(hex_content)
# 将bytes写入jar文件
with open('/home/1.jar', 'wb') as output_file:
output_file.write(binary_content)
print("转换完成,输出文件:/home/output.jar")
mysql连接地址下载
https://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.6/mysql-connector-java-5.1.6.jar
4 条评论
这篇文章不错!
文章的叙述风格独特,用词精准,让人回味无穷。
技术伦理的探讨体现人文科技平衡意识。
跨界融合的尝试为文章注入新鲜活力。