diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index ad252c1..e2f094d 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -1,7 +1,7 @@ use std::sync::Mutex; use crate::{app_error::AppError, app_state::AppState, pe_parse::pe::ReadOnlyPE}; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use serde_json::{json, Value}; use tauri::{AppHandle, Manager, State}; @@ -209,6 +209,25 @@ pub fn command_write_data( Ok(()) } +#[tauri::command(async)] +pub fn command_write_data_list( + app_state: State<'_, Mutex>, + data_list: Vec, +) -> Result<(), AppError> { + let mut app_state = app_state.lock().unwrap(); + for edit_data in data_list { + app_state.write_data(edit_data.offset, &edit_data.data)?; + } + Ok(()) +} + +#[derive(Serialize, Deserialize)] +pub struct EditData{ + offset: usize, + data: Vec, +} + + // 命令,添加节 #[tauri::command(async)] pub fn command_add_section( diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index d7c89f2..0569147 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -26,6 +26,7 @@ pub fn run() { commands::command_get_pe_data_section_headers, commands::command_get_pe_data_import_directory, commands::command_write_data, + commands::command_write_data_list, commands::command_add_section, commands::command_test, ]) diff --git a/src/components/DosHeader/DosHeader.module.scss b/src/components/DosHeader/DosHeader.module.scss index 54e9c35..aef32e7 100644 --- a/src/components/DosHeader/DosHeader.module.scss +++ b/src/components/DosHeader/DosHeader.module.scss @@ -1,8 +1,9 @@ -.root { - margin: 8px; - margin-top: 0; - height: 100%; - background-color: white; - border-radius: 5px; - padding: 16px; + + +.optionalContent{ + margin-bottom: 12px; + justify-content: end; +} +.optionalItem{ + margin-left: 16px; } \ No newline at end of file diff --git a/src/components/DosHeader/DosHeader.tsx b/src/components/DosHeader/DosHeader.tsx index a1b808f..08fdacd 100644 --- a/src/components/DosHeader/DosHeader.tsx +++ b/src/components/DosHeader/DosHeader.tsx @@ -4,7 +4,166 @@ import NodeTableComponent, { DataType, } from "../NodeTableComponent/NodeTableComponent"; import { invoke } from "@tauri-apps/api/core"; -import { message } from "antd"; +import { Button, Flex, message } from "antd"; +import styles from './DosHeader.module.scss' + + +const dataTemplate: DataTemplateInterface = { + e_magic: { + name: "e_magic", + description: "标识文件的魔数,DOS 可执行文件的值通常为 'MZ'。", + value: 0, + size: 2, + offset: 0, + data_type: "hex", + }, + e_cblp: { + name: "e_cblp", + description: "文件最后一页的字节数,指示文件不完整页的大小。", + value: 0, + size: 2, + offset: 2, + data_type: "hex", + }, + e_cp: { + name: "e_cp", + description: "文件的总页数(每页 512 字节)。", + value: 0, + size: 2, + offset: 4, + data_type: "hex", + }, + e_crlc: { + name: "e_crlc", + description: "重定位表中的条目数。", + value: 0, + size: 2, + offset: 6, + data_type: "hex", + }, + e_cparhdr: { + name: "e_cparhdr", + description: "文件头部的段数,单位为 16 字节段。", + value: 0, + size: 2, + offset: 8, + data_type: "hex", + }, + e_minalloc: { + name: "e_minalloc", + description: "程序需要的最小额外段数。", + value: 0, + size: 2, + offset: 10, + data_type: "hex", + }, + e_maxalloc: { + name: "e_maxalloc", + description: "程序可以分配的最大额外段数。", + value: 0, + size: 2, + offset: 12, + data_type: "hex", + }, + e_ss: { + name: "e_ss", + description: "初始的 SS 寄存器值,段偏移地址。", + value: 0, + size: 2, + offset: 14, + data_type: "hex", + }, + e_sp: { + name: "e_sp", + description: "初始的 SP 寄存器值,栈顶指针。", + value: 0, + size: 2, + offset: 16, + data_type: "hex", + }, + e_csum: { + name: "e_csum", + description: "校验和(一般为 0)。", + value: 0, + size: 2, + offset: 18, + data_type: "hex", + }, + e_ip: { + name: "e_ip", + description: "初始的 IP 寄存器值,代码段的入口偏移地址。", + value: 0, + size: 2, + offset: 20, + data_type: "hex", + }, + e_cs: { + name: "e_cs", + description: "初始的 CS 寄存器值,代码段的段基址。", + value: 0, + size: 2, + offset: 22, + data_type: "hex", + }, + e_lfarlc: { + name: "e_lfarlc", + description: "重定位表的文件偏移。", + value: 0, + size: 2, + offset: 24, + data_type: "hex", + }, + e_ovno: { + name: "e_ovno", + description: "覆盖号(通常为 0)。", + value: 0, + size: 2, + offset: 26, + data_type: "hex", + }, + e_res: { + name: "e_res", + description: "保留字段,通常为 0。", + value: null, + size: 8, + offset: 28, + array_element_size: 2, + data_type: "array", + }, + e_oemid: { + name: "e_oemid", + description: "OEM 标识符。", + value: 0, + size: 2, + offset: 36, + data_type: "hex", + }, + e_oeminfo: { + name: "e_oeminfo", + description: "OEM 信息。", + value: 0, + size: 2, + offset: 38, + data_type: "hex", + }, + e_res2: { + name: "e_res2", + description: "保留字段,通常为 0。", + value: 0, + size: 20, + offset: 40, + data_type: "array", + array_element_size: 2, + }, + e_lfanew: { + name: "e_lfanew", + description: "PE 文件头的偏移地址。", + value: 0, + size: 4, + offset: 60, + data_type: "hex", + }, +}; interface DosHeaderResponseData { base_offset: number; fields: { @@ -50,176 +209,7 @@ const formatEditValue = (item: DataType) => { export default function DosHeader() { const [data, setData] = useState(); - const [messageApi, contextHolder] = message.useMessage(); - const success = () => { - messageApi.open({ - type: "success", - content: "修改成功!", - }); - }; - const error = () => { - messageApi.open({ - type: "error", - content: "修改失败!", - }); - }; - - const dataTemplate: DataTemplateInterface = { - e_magic: { - name: "e_magic", - description: "标识文件的魔数,DOS 可执行文件的值通常为 'MZ'。", - value: 0, - size: 2, - offset: 0, - data_type: "hex", - }, - e_cblp: { - name: "e_cblp", - description: "文件最后一页的字节数,指示文件不完整页的大小。", - value: 0, - size: 2, - offset: 2, - data_type: "hex", - }, - e_cp: { - name: "e_cp", - description: "文件的总页数(每页 512 字节)。", - value: 0, - size: 2, - offset: 4, - data_type: "hex", - }, - e_crlc: { - name: "e_crlc", - description: "重定位表中的条目数。", - value: 0, - size: 2, - offset: 6, - data_type: "hex", - }, - e_cparhdr: { - name: "e_cparhdr", - description: "文件头部的段数,单位为 16 字节段。", - value: 0, - size: 2, - offset: 8, - data_type: "hex", - }, - e_minalloc: { - name: "e_minalloc", - description: "程序需要的最小额外段数。", - value: 0, - size: 2, - offset: 10, - data_type: "hex", - }, - e_maxalloc: { - name: "e_maxalloc", - description: "程序可以分配的最大额外段数。", - value: 0, - size: 2, - offset: 12, - data_type: "hex", - }, - e_ss: { - name: "e_ss", - description: "初始的 SS 寄存器值,段偏移地址。", - value: 0, - size: 2, - offset: 14, - data_type: "hex", - }, - e_sp: { - name: "e_sp", - description: "初始的 SP 寄存器值,栈顶指针。", - value: 0, - size: 2, - offset: 16, - data_type: "hex", - }, - e_csum: { - name: "e_csum", - description: "校验和(一般为 0)。", - value: 0, - size: 2, - offset: 18, - data_type: "hex", - }, - e_ip: { - name: "e_ip", - description: "初始的 IP 寄存器值,代码段的入口偏移地址。", - value: 0, - size: 2, - offset: 20, - data_type: "hex", - }, - e_cs: { - name: "e_cs", - description: "初始的 CS 寄存器值,代码段的段基址。", - value: 0, - size: 2, - offset: 22, - data_type: "hex", - }, - e_lfarlc: { - name: "e_lfarlc", - description: "重定位表的文件偏移。", - value: 0, - size: 2, - offset: 24, - data_type: "hex", - }, - e_ovno: { - name: "e_ovno", - description: "覆盖号(通常为 0)。", - value: 0, - size: 2, - offset: 26, - data_type: "hex", - }, - e_res: { - name: "e_res", - description: "保留字段,通常为 0。", - value: null, - size: 8, - offset: 28, - array_element_size: 2, - data_type: "array", - }, - e_oemid: { - name: "e_oemid", - description: "OEM 标识符。", - value: 0, - size: 2, - offset: 36, - data_type: "hex", - }, - e_oeminfo: { - name: "e_oeminfo", - description: "OEM 信息。", - value: 0, - size: 2, - offset: 38, - data_type: "hex", - }, - e_res2: { - name: "e_res2", - description: "保留字段,通常为 0。", - value: 0, - size: 20, - offset: 40, - data_type: "array", - array_element_size: 2, - }, - e_lfanew: { - name: "e_lfanew", - description: "PE 文件头的偏移地址。", - value: 0, - size: 4, - offset: 60, - data_type: "hex", - }, - }; + const [editValues, setEditValues] = useState([]); const command = "command_get_pe_data_dos_header"; @@ -259,24 +249,34 @@ export default function DosHeader() { }, ]; - const handleSave = (item: DataType) => { + const handleEdit = (item: DataType) => { if (!checkEditValue(item)) { return; } - const bufs = formatEditValue(item); - console.log("bufs", bufs, item); - invoke("command_write_data", { - offset: item.offset, - data: bufs, + const formatEditData: any = {}; + formatEditData.offset = item.offset; + formatEditData.data = formatEditValue(item); + console.log("formatEditData", formatEditData); + const newEditValues = [...editValues, formatEditData]; + setEditValues(newEditValues); + // 需要同步修改data + const newData = { ...data }; + newData.fields[item.name] = item.value; + setData(newData); + } + + + const handleSave = () => { + const command = "command_write_data_list"; + invoke(command, { dataList: editValues }).then((res) => { + message.success("保存成功"); + // 刷新数据 + getData(); + // 清空编辑数据 + setEditValues([]); + }).catch((err) => { + message.error(`保存失败: ${err}`); }) - .then((_res) => { - // 提示 - success(); - getData(); - }) - .catch(() => { - error(); - }); }; const getData = () => { @@ -291,12 +291,25 @@ export default function DosHeader() { return ( <> - {contextHolder} + + + + ); diff --git a/src/components/ImportDirectory/ImportDirectory.tsx b/src/components/ImportDirectory/ImportDirectory.tsx index 37df242..20a0039 100644 --- a/src/components/ImportDirectory/ImportDirectory.tsx +++ b/src/components/ImportDirectory/ImportDirectory.tsx @@ -116,7 +116,6 @@ const ModuleFuntionsComponent: React.FC = ( props ) => { const { functionList } = props; - console.log("functionList", functionList); const columns = [ { title: "序号", @@ -155,7 +154,7 @@ const ModuleFuntionsComponent: React.FC = ( return ( ); diff --git a/src/pages/MainPage.module.scss b/src/pages/MainPage.module.scss index bb9012e..293fd5a 100644 --- a/src/pages/MainPage.module.scss +++ b/src/pages/MainPage.module.scss @@ -26,10 +26,11 @@ .content{ background-color: white; display: flex; - justify-content: center; + justify-content: start; border-radius: 5px; overflow: scroll; padding: 16px; + flex-direction: column; } .mainContent {