我正在尝试在 masm 程序集中制作一个十六进制编辑器。我为十六进制编辑器的编写器部分编写了一些代码,但速度很慢。我尝试了 2 个不同版本的代码。第一个代码循环并检查文本文件(如 A9)中的十六进制字节,然后将字节 A9 写入输出二进制文件。第二个代码做同样的事情,但将字节写入缓冲区,然后将缓冲区写入最后的二进制文件,但由于某种原因,每次将代码写入缓冲区时,它应该写入字节 00 它什么也没写我的二进制文件已从其中删除了所有 00。同样由于某种原因,这两个代码都需要完全相同的时间来编写二进制文件。这是两个代码
数据
local data
LOCAL hFile :DWORD
LOCAL flen :DWORD
LOCAL hMem$ :DWORD
LOCAL hFile2 :DWORD
LOCAL hBuf$ :DWORD
data
Buffer db 80 dup (0)
FileBuffer db 9000 dup (0)
FileBufferBytesWritten db 9000 dup (0)
Done db "Done",0
zerozero db 00h,0
zeroone db 01h,0
zerotwo db 02h,0
zerothree db 03h,0
zerofour db 04h,0
zerofive db 05h,0
zerosix db 06h,0
zeroseven db 07h,0
zeroeight db 08h,0
zeronine db 09h,0
zeroA db 0Ah,0
zeroB db 0Bh,0
zeroC db 0Ch,0
zeroD db 0Dh,0
zeroE db 0Eh,0
zeroF db 0Fh,0
onezero db 10h,0
oneone db 11h,0
onetwo db 12h,0
onethree db 13h,0
onefour db 14h,0
onefive db 15h,0
onesix db 16h,0
oneseven db 17h,0
oneeight db 18h,0
onenine db 19h,0
oneA db 1Ah,0
oneB db 1Bh,0
oneC db 1Ch,0
oneD db 1Dh,0
oneE db 1Eh,0
oneF db 1Fh,0
twozero db 20h,0
twoone db 21h,0
twotwo db 22h,0
twothree db 23h,0
twofour db 24h,0
twofive db 25h,0
twosix db 26h,0
twoseven db 27h,0
twoeight db 28h,0
twonine db 29h,0
twoA db 2Ah,0
twoB db 2Bh,0
twoC db 2Ch,0
twoD db 2Dh,0
twoE db 2Eh,0
twoF db 2Fh,0
threezero db 30h,0
threeone db 31h,0
threetwo db 32h,0
threethree db 33h,0
threefour db 34h,0
threefive db 35h,0
threesix db 36h,0
threeseven db 37h,0
threeeight db 38h,0
threenine db 39h,0
threeA db 3Ah,0
threeB db 3Bh,0
threeC db 3Ch,0
threeD db 3Dh,0
threeE db 3Eh,0
threeF db 3Fh,0
fourzero db 40h,0
fourone db 41h,0
fourtwo db 42h,0
fourthree db 43h,0
fourfour db 44h,0
fourfive db 45h,0
foursix db 46h,0
fourseven db 47h,0
foureight db 48h,0
fournine db 49h,0
fourA db 4Ah,0
fourB db 4Bh,0
fourC db 4Ch,0
fourD db 4Dh,0
fourE db 4Eh,0
fourF db 4Fh,0
fivezero db 50h,0
fiveone db 51h,0
fivetwo db 52h,0
fivethree db 53h,0
fivefour db 54h,0
fivefive db 55h,0
fivesix db 56h,0
fiveseven db 57h,0
fiveeight db 58h,0
fivenine db 59h,0
fiveA db 5Ah,0
fiveB db 5Bh,0
fiveC db 5Ch,0
fiveD db 5Dh,0
fiveE db 5Eh,0
fiveF db 5Fh,0
sixzero db 60h,0
sixone db 61h,0
sixtwo db 62h,0
sixthree db 63h,0
sixfour db 64h,0
sixfive db 65h,0
sixsix db 66h,0
sixseven db 67h,0
sixeight db 68h,0
sixnine db 69h,0
sixA db 6Ah,0
sixB db 6Bh,0
sixC db 6Ch,0
sixD db 6Dh,0
sixE db 6Eh,0
sixF db 6Fh,0
sevenzero db 70h,0
sevenone db 71h,0
seventwo db 72h,0
seventhree db 73h,0
sevenfour db 74h,0
sevenfive db 75h,0
sevensix db 76h,0
sevenseven db 77h,0
seveneight db 78h,0
sevennine db 79h,0
sevenA db 7Ah,0
sevenB db 7Bh,0
sevenC db 7Ch,0
sevenD db 7Dh,0
sevenE db 7Eh,0
sevenF db 7Fh,0
eightzero db 80h,0
eightone db 81h,0
eighttwo db 82h,0
eightthree db 83h,0
eightfour db 84h,0
eightfive db 85h,0
eightsix db 86h,0
eightseven db 87h,0
eighteight db 88h,0
eightnine db 89h,0
eightA db 8Ah,0
eightB db 8Bh,0
eightC db 8Ch,0
eightD db 8Dh,0
eightE db 8Eh,0
eightF db 8Fh,0
ninezero db 90h,0
nineone db 91h,0
ninetwo db 92h,0
ninethree db 93h,0
ninefour db 94h,0
ninefive db 95h,0
ninesix db 96h,0
nineseven db 97h,0
nineeight db 98h,0
ninenine db 99h,0
nineA db 9Ah,0
nineB db 9Bh,0
nineC db 9Ch,0
nineD db 9Dh,0
nineE db 9Eh,0
nineF db 9Fh,0
Azero db 0A0h,0
Aone db 0A1h,0
Atwo db 0A2h,0
Athree db 0A3h,0
Afour db 0A4h,0
Afive db 0A5h,0
Asix db 0A6h,0
Aseven db 0A7h,0
Aeight db 0A8h,0
Anine db 0A9h,0
AA db 0AAh,0
AB db 0ABh,0
AC db 0ACh,0
AD db 0ADh,0
AE db 0AEh,0
AF db 0AFh,0
Bzero db 0B0h,0
Bone db 0B1h,0
Btwo db 0B2h,0
Bthree db 0B3h,0
Bfour db 0B4h,0
Bfive db 0B5h,0
Bsix db 0B6h,0
Bseven db 0B7h,0
Beight db 0B8h,0
Bnine db 0B9h,0
BA db 0BAh,0
BB db 0BBh,0
BC db 0BCh,0
BD db 0BDh,0
BE db 0BEh,0
BF db 0BFh,0
Czero db 0C0h,0
Cone db 0C1h,0
Ctwo db 0C2h,0
Cthree db 0C3h,0
Cfour db 0C4h,0
Cfive db 0C5h,0
Csix db 0C6h,0
Cseven db 0C7h,0
Ceight db 0C8h,0
Cnine db 0C9h,0
CA db 0CAh,0
CB db 0CBh,0
CC db 0CCh,0
CD db 0CDh,0
CE db 0CEh,0
CF db 0CFh,0
Dzero db 0D0h,0
Deeone db 0D1h,0
Dtwo db 0D2h,0
Dthree db 0D3h,0
Dfour db 0D4h,0
Dfive db 0D5h,0
Dsix db 0D6h,0
Dseven db 0D7h,0
Deight db 0D8h,0
Dnine db 0D9h,0
DA db 0DAh,0
DeeB db 0DBh,0
DC db 0DCh,0
DeeD db 0DDh,0
DE db 0DEh,0
DeeF db 0DFh,0
Ezero db 0E0h,0
Eone db 0E1h,0
Etwo db 0E2h,0
Ethree db 0E3h,0
Efour db 0E4h,0
Efive db 0E5h,0
Esix db 0E6h,0
Eseven db 0E7h,0
Eeight db 0E8h,0
Enine db 0E9h,0
EA db 0EAh,0
EB db 0EBh,0
EC db 0ECh,0
ED db 0EDh,0
EE db 0EEh,0
EF db 0EFh,0
Fzero db 0F0h,0
Fone db 0F1h,0
Ftwo db 0F2h,0
Fthree db 0F3h,0
Ffour db 0F4h,0
Ffive db 0F5h,0
Fsix db 0F6h,0
Fseven db 0F7h,0
Feight db 0F8h,0
Fnine db 0F9h,0
FA db 0FAh,0
FB db 0FBh,0
FC db 0FCh,0
FD db 0FDh,0
FE db 0FFh,0
FF db 0FFh,0
.data ?
Bytes dd ?
BytesWritten dd ?
第一个代码
writehexadecimal macro bytetext,byte
mov eax, cmp$(ADDR Buffer,bytetext)
.if eax == 0
invoke WriteFile,hFile2,addr byte,1,addr BytesWritten,NULL
.endif
EndM
invoke CreateFile, addr FilePathformatted, GENERIC_READ, 0, 0,OPEN_EXISTING, 0, 0
mov hFile, eax
invoke GetFileSize,hFile,NULL
mov edi,eax
invoke CreateFile,addr FilePath2,GENERIC_WRITE,FILE_SHARE_WRITE,
NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL
mov hFile2, eax
xor esi,esi
writebinary:
invoke ReadFile, hFile, ADDR Buffer,2, addr BytesWritten, 0
writehexadecimal "00",zerozero
writehexadecimal "01",zeroone
writehexadecimal "02",zerotwo
writehexadecimal "03",zerothree
writehexadecimal "04",zerofour
writehexadecimal "05",zerofive
writehexadecimal "06",zerosix
writehexadecimal "07",zeroseven
writehexadecimal "08",zeroeight
writehexadecimal "09",zeronine
writehexadecimal "0A",zeroA
writehexadecimal "0B",zeroB
writehexadecimal "0C",zeroC
writehexadecimal "0D",zeroD
writehexadecimal "0E",zeroE
writehexadecimal "0F",zeroF
writehexadecimal "10",onezero
writehexadecimal "11",oneone
writehexadecimal "12",onetwo
writehexadecimal "13",onethree
writehexadecimal "14",onefour
writehexadecimal "15",onefive
writehexadecimal "16",onesix
writehexadecimal "17",oneseven
writehexadecimal "18",oneeight
writehexadecimal "19",onenine
writehexadecimal "1A",oneA
writehexadecimal "1B",oneB
writehexadecimal "1C",oneC
writehexadecimal "1D",oneD
writehexadecimal "1E",oneE
writehexadecimal "1F",oneF
writehexadecimal "20",twozero
writehexadecimal "21",twoone
writehexadecimal "22",twotwo
writehexadecimal "23",twothree
writehexadecimal "24",twofour
writehexadecimal "25",twofive
writehexadecimal "26",twosix
writehexadecimal "27",twoseven
writehexadecimal "28",twoeight
writehexadecimal "29",twonine
writehexadecimal "2A",twoA
writehexadecimal "2B",twoB
writehexadecimal "2C",twoC
writehexadecimal "2D",twoD
writehexadecimal "2E",twoE
writehexadecimal "2F",twoF
writehexadecimal "30",threezero
writehexadecimal "31",threeone
writehexadecimal "32",threetwo
writehexadecimal "33",threethree
writehexadecimal "34",threefour
writehexadecimal "35",threefive
writehexadecimal "36",threesix
writehexadecimal "37",threeseven
writehexadecimal "38",threeeight
writehexadecimal "39",threenine
writehexadecimal "3A",threeA
writehexadecimal "3B",threeB
writehexadecimal "3C",threeC
writehexadecimal "3D",threeD
writehexadecimal "3E",threeE
writehexadecimal "3F",threeF
writehexadecimal "40",fourzero
writehexadecimal "41",fourone
writehexadecimal "42",fourtwo
writehexadecimal "43",fourthree
writehexadecimal "44",fourfour
writehexadecimal "45",fourfive
writehexadecimal "46",foursix
writehexadecimal "47",fourseven
writehexadecimal "48",foureight
writehexadecimal "49",fournine
writehexadecimal "4A",fourA
writehexadecimal "4B",fourB
writehexadecimal "4C",fourC
writehexadecimal "4D",fourD
writehexadecimal "4E",fourE
writehexadecimal "4F",fourF
writehexadecimal "50",fivezero
writehexadecimal "51",fiveone
writehexadecimal "52",fivetwo
writehexadecimal "53",fivethree
writehexadecimal "54",fivefour
writehexadecimal "55",fivefive
writehexadecimal "56",fivesix
writehexadecimal "57",fiveseven
writehexadecimal "58",fiveeight
writehexadecimal "59",fivenine
writehexadecimal "5A",fiveA
writehexadecimal "5B",fiveB
writehexadecimal "5C",fiveC
writehexadecimal "5D",fiveD
writehexadecimal "5E",fiveE
writehexadecimal "5F",fiveF
writehexadecimal "60",sixzero
writehexadecimal "61",sixone
writehexadecimal "62",sixtwo
writehexadecimal "63",sixthree
writehexadecimal "64",sixfour
writehexadecimal "65",sixfive
writehexadecimal "66",sixsix
writehexadecimal "67",sixseven
writehexadecimal "68",sixeight
writehexadecimal "69",sixnine
writehexadecimal "6A",sixA
writehexadecimal "6B",sixB
writehexadecimal "6C",sixC
writehexadecimal "6D",sixD
writehexadecimal "6E",sixE
writehexadecimal "6F",sixF
writehexadecimal "70",sevenzero
writehexadecimal "71",sevenone
writehexadecimal "72",seventwo
writehexadecimal "73",seventhree
writehexadecimal "74",sevenfour
writehexadecimal "75",sevenfive
writehexadecimal "76",sevensix
writehexadecimal "77",sevenseven
writehexadecimal "78",seveneight
writehexadecimal "79",sevennine
writehexadecimal "7A",sevenA
writehexadecimal "7B",sevenB
writehexadecimal "7C",sevenC
writehexadecimal "7D",sevenD
writehexadecimal "7E",sevenE
writehexadecimal "7F",sevenF
writehexadecimal "80",eightzero
writehexadecimal "81",eightone
writehexadecimal "82",eighttwo
writehexadecimal "83",eightthree
writehexadecimal "84",eightfour
writehexadecimal "85",eightfive
writehexadecimal "86",eightsix
writehexadecimal "87",eightseven
writehexadecimal "88",eighteight
writehexadecimal "89",eightnine
writehexadecimal "8A",eightA
writehexadecimal "8B",eightB
writehexadecimal "8C",eightC
writehexadecimal "8D",eightD
writehexadecimal "8E",eightE
writehexadecimal "8F",eightF
writehexadecimal "90",ninezero
writehexadecimal "91",nineone
writehexadecimal "92",ninetwo
writehexadecimal "93",ninethree
writehexadecimal "94",ninefour
writehexadecimal "95",ninefive
writehexadecimal "96",ninesix
writehexadecimal "97",nineseven
writehexadecimal "98",nineeight
writehexadecimal "99",ninenine
writehexadecimal "9A",nineA
writehexadecimal "9B",nineB
writehexadecimal "9C",nineC
writehexadecimal "9D",nineD
writehexadecimal "9E",nineE
writehexadecimal "9F",nineF
writehexadecimal "A0",Azero
writehexadecimal "A1",Aone
writehexadecimal "A2",Atwo
writehexadecimal "A3",Athree
writehexadecimal "A4",Afour
writehexadecimal "A5",Afive
writehexadecimal "A6",Asix
writehexadecimal "A7",Aseven
writehexadecimal "A8",Aeight
writehexadecimal "A9",Anine
writehexadecimal "AA",AA
writehexadecimal "AB",AB
writehexadecimal "AC",AC
writehexadecimal "AD",AD
writehexadecimal "AE",AE
writehexadecimal "AF",AF
writehexadecimal "B0",Bzero
writehexadecimal "B1",Bone
writehexadecimal "B2",Btwo
writehexadecimal "B3",Bthree
writehexadecimal "B4",Bfour
writehexadecimal "B5",Bfive
writehexadecimal "B6",Bsix
writehexadecimal "B7",Bseven
writehexadecimal "B8",Beight
writehexadecimal "B9",Bnine
writehexadecimal "BA",BA
writehexadecimal "BB",BB
writehexadecimal "BC",BC
writehexadecimal "BD",BD
writehexadecimal "BE",BE
writehexadecimal "BF",BF
writehexadecimal "C0",Czero
writehexadecimal "C1",Cone
writehexadecimal "C2",Ctwo
writehexadecimal "C3",Cthree
writehexadecimal "C4",Cfour
writehexadecimal "C5",Cfive
writehexadecimal "C6",Csix
writehexadecimal "C7",Cseven
writehexadecimal "C8",Ceight
writehexadecimal "C9",Cnine
writehexadecimal "CA",CA
writehexadecimal "CB",CB
writehexadecimal "CC",CC
writehexadecimal "CD",CD
writehexadecimal "CE",CE
writehexadecimal "CF",CF
writehexadecimal "D0",Dzero
writehexadecimal "D1",Done
writehexadecimal "D2",Dtwo
writehexadecimal "D3",Dthree
writehexadecimal "D4",Dfour
writehexadecimal "D5",Dfive
writehexadecimal "D6",Dsix
writehexadecimal "D7",Dseven
writehexadecimal "D8",Deight
writehexadecimal "D9",Dnine
writehexadecimal "DA",DA
writehexadecimal "DB",DeeB
writehexadecimal "DC",DC
writehexadecimal "DD",DeeD
writehexadecimal "DE",DE
writehexadecimal "DF",DeeF
writehexadecimal "E0",Ezero
writehexadecimal "E1",Eone
writehexadecimal "E2",Etwo
writehexadecimal "E3",Ethree
writehexadecimal "E4",Efour
writehexadecimal "E5",Efive
writehexadecimal "E6",Esix
writehexadecimal "E7",Eseven
writehexadecimal "E8",Eeight
writehexadecimal "E9",Enine
writehexadecimal "EA",EA
writehexadecimal "EB",EB
writehexadecimal "EC",EC
writehexadecimal "ED",ED
writehexadecimal "EE",EE
writehexadecimal "EF",EF
writehexadecimal "F0",Fzero
writehexadecimal "F1",Fone
writehexadecimal "F2",Ftwo
writehexadecimal "F3",Fthree
writehexadecimal "F4",Ffour
writehexadecimal "F5",Ffive
writehexadecimal "F6",Fsix
writehexadecimal "F7",Fseven
writehexadecimal "F8",Feight
writehexadecimal "F9",Fnine
writehexadecimal "FA",FA
writehexadecimal "FB",FB
writehexadecimal "FC",FC
writehexadecimal "FD",FD
writehexadecimal "FE",FE
writehexadecimal "FF",FF
sub edi,2
.if edi == 0
invoke CloseHandle,hFile
invoke CloseHandle,hFile2
invoke MessageBox, NULL, addr Done, offset BoxCaption, NULL
ret
.endif
jmp writebinary
第二个代码
writehexadecimal macro bytetext,byte
mov eax, cmp$(ADDR Buffer,bytetext)
.if eax == 0
invoke lstrcat,addr FileBuffer,addr byte
inc esi
.endif
EndM
invoke CreateFile, addr FilePathformatted, GENERIC_READ, 0, 0,OPEN_EXISTING, 0, 0
mov hFile, eax
invoke GetFileSize,hFile,NULL
mov edi,eax
invoke CreateFile,addr FilePath2,GENERIC_WRITE,FILE_SHARE_WRITE, NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL
mov hFile2, eax
xor esi,esi
writebinary:
invoke ReadFile, hFile, ADDR Buffer,2, addr BytesWritten, 0
与第一个代码相同的十六进制列表。堆栈溢出说我达到了字符限制,所以我不需要再次编写该列表
sub edi,2
.if esi == 9000
invoke WriteFile,hFile2,addr FileBuffer,sizeof FileBuffer,addr BytesWritten,NULL
.endif
.if edi == 0
invoke WriteFile,hFile2,addr FileBuffer,esi,addr FileBufferBytesWritten,NULL
invoke CloseHandle,hFile
invoke CloseHandle,hFile2
invoke MessageBox, NULL, addr Done, offset BoxCaption, NULL
ret
.endif
jmp writebinary
所以我的问题是任何人都可以帮助我使这个代码更快,所以它是一种即时而不是花费 5 分钟来编写一个 1mb 大小的二进制文件。
谢谢你