因此,我有两个文件,一个是字节文件,一个是asm文件。 asm文件的文本具有多个部分,例如.data,.rdata,.text等。我正在尝试创建一个代码,该代码可以根据asm文件中的位置从字节部分删除十六进制。基本上,这两个文件是相同的,只是asm文件具有指令,而bytes文件则包含asm的十六进制。例如,我要删除字节文件中的所有.text十六进制,方法是在asm中查找.text的第一个实例,然后检入字节文件并删除这些行。
clc;clear all;close all;
% read the entire asm file into one string
C1=fileread('kD8OJCT6bsvcBU9IVaeA.asm');
% find the location in asm file string that start with '.rdata'
temp1=strfind(C1,'.idata');
ii=1;
jj=1;
while ii<=length(temp1)
% read the wholeset of numbers after '.rdata:'
temp2=C1(temp1(ii)+7:temp1(ii)+13);
% there are some '.rdata:' that are not at the beginning of the rows
% and they start with 'off'. So, we discard them
if temp2(1)~='o'
num{jj}=temp2; % the cell array containing all the numbers after '.rdata:'
jj=jj+1;
end
ii=ii+1;
end
% read the entire bytes file into one string
C2=fileread('kD8OJCT6bsvcBU9IVaeA.bytes');
C3=C2; % the string that will be modified and written as the new bytes file
% find the location in bytes file string that start with number sets in the
% num cell array
ii=1;
jj=1;
while ii<=length(num)
temp3=strfind(C2,num{ii});
if ~isempty(temp3)
temp4(jj)=temp3; % temp 4 contains the beginning address of the lines containing the number sets
jj=jj+1;
end
ii=ii+1;
end
temp4=unique(temp4);
% deleting the lines in the .bytes file (each line contains 56 characters
for ii=1:length(temp4)
C3(temp4(ii):temp4(ii)+56)=[];
end
% write the modified data to the bytes file
fileID = fopen('file3.bytes','w');
fwrite(fileID,C3);
fclose(fileID);