
Untitled
By: a guest on
Jun 20th, 2012 | syntax:
None | size: 2.27 KB | hits: 11 | expires: Never
;MASMPlus 代码模板 - 控制台程序
;link: /SUBSYSTEM:CONSOLE /nologo /SECTION:.text,RWE /MERGE:.rdata=.text /MERGE:.data=.text
.686
.model flat, stdcall
option casemap :none
include windows.inc
include kernel32.inc
include masm32.inc
includelib kernel32.lib
includelib masm32.lib
include macro.asm
.data
ddMagicNumbers dd 576,2838748,9760642,13925733,21502882, \
30222582,35811704,41345235,45306303, \
54451205,66477898,75360464,84057730, \
91119754,97171761,99622608,108506849, \
117227799
NNums equ lengthof ddMagicNumbers - 1
ddNNums dd NNums
sCantOpen db "无法打开pack01.pak,请把此程序放到游戏的resource目录里运行!", 13, 10, 0
sCantWrite db "无法以写入方式打开文件!请尝试使用管理员权限运行本程序!", 13, 10, 0
sWriting db "正在写入 "
sSongName db "00.ogg"
sTail db " ...", 13, 10, 0
.data?
pBuf dd ?
hDataFile dd ?
ddJunk dd ?
.CODE
ErrMsg proc pMsg:DWORD
invoke StdOut, pMsg
invoke StdIn, offset ddJunk, 3
invoke ExitProcess, 1
ret
ErrMsg endp
START:
invoke CreateFile, offset CTEXT("pack01.pak"), GENERIC_READ, FILE_SHARE_READ OR FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL
.if eax == -1
invoke ErrMsg, offset sCantOpen
.endif
mov hDataFile, eax
invoke VirtualAlloc,NULL,15*1024*1024,MEM_COMMIT,PAGE_READWRITE
mov pBuf, eax
lea esi, ddMagicNumbers
lodsd
mov ebx, eax ; ebx <- this postition
.while ddNNums
lodsd
mov edi, eax ; edi <- next position
invoke SetFilePointer, hDataFile, ebx, NULL, FILE_BEGIN
mov edx, edi
sub edx, ebx ; <- size
invoke ReadFile,hDataFile, pBuf, edx, offset ddJunk,NULL
mov eax, NNums
sub eax, ddNNums
inc eax
cmp eax, 0ah
jl @F
add eax, 0F6h
@@:
bswap eax
shr eax, 16
add ax, '00'
mov WORD ptr sSongName, ax
mov BYTE ptr sTail, ' '
invoke StdOut, offset sWriting
mov BYTE ptr sTail, 0
invoke CreateFile, offset sSongName, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL
push eax ; pair with CloseHandle
.if eax == -1
invoke ErrMsg, offset sCantWrite
.endif
mov edx, edi
sub edx, ebx ; <- size
invoke WriteFile, eax, pBuf, edx, offset ddJunk, NULL
call CloseHandle
mov ebx, edi ; next one
dec ddNNums
.endw
ret
end START