invoke VirtualAlloc,0h,400h,MEM_COMMIT,PAGE_READWRITE
.if eax!=0h
push eax
mov edx,eax
....
....
assume edi:ptr NTRESOURCE
lea ecx,[edx].lpRemoteName - [ERROR!!!]
...
...
assume edx:nothing
assume - [error]!
Код:
Пример этот видел в KmdTut, а у меня не работает, хотя пишу почти тоже самое!
Из KmdTut:
Код:
assume esi:ptr FILE_DIRECTORY_INFORMATION
...
...
lea eax, [esi].FileName
...
assume esi:nothing
...
...
lea eax, [esi].FileName
...
assume esi:nothing
Всё тоже самое, но не работает!!!
Почему???
Код:
assume edx:ptr NTRESOURCE
lea ecx,[edx].lpRemoteName - [ERROR!!!]
...
...
assume edx:nothing
lea ecx,[edx].lpRemoteName - [ERROR!!!]
...
...
assume edx:nothing
С Assembler'ом надо внимательнее просто быть...
Написал assume edi, а использую edx!
Код:
.386
.model flat, stdcall
option casemap :none
include E:\masm32\include\windows.inc
include E:\masm32\include\kernel32.inc
include E:\masm32\include\user32.inc
include E:\masm32\include\advapi32.inc
include E:\masm32\include\mpr.inc
includelib E:\masm32\lib\kernel32.lib
includelib E:\masm32\lib\user32.lib
includelib E:\masm32\lib\advapi32.lib
includelib E:\masm32\lib\mpr.lib
;include def32.inc
include E:\masm32\macros\Strings.mac
NTRESOURCE struc
dwScope dd ?
dwType dd ?
dwDisplayType dd ?
dwUsage dd ?
lpLocalName dd ?
lpRemoteName dd ?
lpComment dd ?
lpProvider dd ?
NTRESOURCE ends
.const
greet_message db 'My program',0h
error1_message db 'Could not get current user name',0h
error2_message db 'Could not enumerate',0h
good_exit_msg db 'Normal termination',0h
.data
user_name db 'List of connected resources for user '
user_buff db 64 dup (?)
user_buff_l dd $-user_buff
enum_buf_l dd 1056
enum_entries dd 1
enum_buf_len dd 800h
.data?
enum_buf NTRESOURCE <?,?,?,?,?,?,?,?>
dd 256 dup (?)
message_l dd ?
enum_handle dd ?
bytes dd ?
alloc_adr dd ?
.code
_start:
;invoke MessageBox,0h,offset greet_message,offset greet_message,MB_OK
invoke WNetGetUser,0h, offset user_buff, offset user_buff_l
cmp eax,NO_ERROR
jne error_exit1
invoke MessageBox,0h,offset user_name,offset user_name,MB_OK
invoke VirtualAlloc,0h,800h,MEM_COMMIT,PAGE_READWRITE
.if eax!=0h
push eax
mov dword ptr alloc_adr,eax
invoke MessageBox,0h,$CTA0("Memory Allocating success"),$CTA0("Success"),MB_OK
xor eax,eax
call netenum
pop eax
invoke VirtualFree,eax,800h,MEM_DECOMMIT
.if eax!=0
invoke MessageBox,0h,$CTA0("Memory DeAllocating success"),$CTA0("Success"),MB_OK
.else
invoke MessageBox,0h,$CTA0("Memmory DeAllocating Error"),$CTA0("Error"),MB_OK
.endif
.else
invoke MessageBox,0h,$CTA0("Memmory Allocating Error"),$CTA0("Error"),MB_OK
.endif
exit_program:
invoke MessageBox,0h,offset good_exit_msg,offset good_exit_msg,MB_OK
err_exit_program:
invoke ExitProcess,0h
error_exit1:
invoke MessageBox,0h,offset error1_message,offset error1_message,MB_OK
jmp short err_exit_program
netenum proc
invoke WNetOpenEnum,RESOURCE_GLOBALNET,RESOURCETYPE_ANY,0h,eax,offset enum_handle
cmp eax,NO_ERROR
jne error_exit2
enumeration_loop:
;invoke WNetEnumResource,dword ptr enum_handle,offset enum_entries,offset enum_buf,offset enum_buf_l
invoke WNetEnumResource,dword ptr enum_handle,offset enum_entries,dword ptr alloc_adr,offset enum_buf_len
comment @
;Для отладки!
push eax
push edx
push ebx
push ecx
mov eax,dword ptr enum_handle
mov edx,offset enum_entries
mov ebx,dword ptr alloc_adr
mov ecx,offset enum_buf_len
invoke WNetEnumResource,dword ptr enum_handle,offset enum_entries,dword ptr alloc_adr,offset enum_buf_len
pop ecx
pop ebx
pop edx
pop eax
@
cmp eax,ERROR_NO_MORE_ITEMS
je end_enumeration
cmp eax,NO_ERROR
jne error_exit2
;invoke MessageBox,0h,dword ptr enum_buf.lpLocalName,dword ptr enum_buf.lpLocalName,MB_OK
;invoke MessageBox,0h,dword ptr enum_buf.lpRemoteName,dword ptr enum_buf.lpRemoteName,MB_OK
mov edx,dword ptr alloc_adr
assume edx:ptr NTRESOURCE
invoke MessageBox,0h,[edx].lpRemoteName,$CTA0("Success"),MB_OK
assume edx:nothing
comment @
push eax
push edx
invoke CreateFile,$CTA0("3.txt"),GENERIC_READ or GENERIC_WRITE,0h,0h,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0h
push eax
invoke WriteFile,eax,edx,800h,offset bytes,0h
pop eax
invoke CloseHandle,eax
pop edx
pop eax
@
comment @
push dword ptr enum_handle
mov eax,dword ptr enum_buf
call netenum
pop dword ptr enum_handle
@
;invoke VirtualAlloc,0h,400h,MEM_COMMIT,PAGE_EXECUTE_READWRITE
;Надо, наверное, выделять память и туда всё писать... и вызываться рекурсивно потом...
push dword ptr enum_handle
push dword ptr enum_entries
push dword ptr alloc_adr
push dword ptr enum_buf_len
mov ecx,dword ptr alloc_adr
push ecx
invoke VirtualAlloc,0h,800h,MEM_COMMIT,PAGE_READWRITE
pop ecx
.if eax!=0h
push eax
mov dword ptr alloc_adr,eax
push ecx
invoke MessageBox,0h,$CTA0("Memory Allocating success"),$CTA0("Success in Recursion Function"),MB_OK
pop ecx
;xor eax,eax
assume ecx:ptr NTRESOURCE
lea eax,[ecx].dwScope
assume ecx:nothing
push 0
pop dword ptr enum_handle
call netenum
pop eax
invoke VirtualFree,eax,800h,MEM_DECOMMIT
.if eax!=0
invoke MessageBox,0h,$CTA0("Memory DeAllocating success"),$CTA0("Success in Recursion Function"),MB_OK
.else
invoke MessageBox,0h,$CTA0("Memmory DeAllocating Error"),$CTA0("Error in Recursion Function"),MB_OK
.endif
.else
invoke MessageBox,0h,$CTA0("Memmory Allocating Error"),$CTA0("Error in Recursion Function"),MB_OK
.endif
pop dword ptr enum_buf_len
pop dword ptr alloc_adr
pop dword ptr enum_entries
pop dword ptr enum_handle
jmp enumeration_loop
end_enumeration:
comment @
invoke CreateFile,$CTA0("3.txt"),GENERIC_READ or GENERIC_WRITE,0h,0h,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0h
push eax
invoke WriteFile,eax,offset enum_buf,1056,offset bytes,0h
pop eax
invoke CloseHandle,eax
@
invoke WNetCloseEnum,dword ptr enum_handle
ret
error_exit2:
invoke MessageBox,0h,offset error2_message,offset error2_message,MB_OK
;jmp short err_exit_program
ret
netenum endp
end _start
.model flat, stdcall
option casemap :none
include E:\masm32\include\windows.inc
include E:\masm32\include\kernel32.inc
include E:\masm32\include\user32.inc
include E:\masm32\include\advapi32.inc
include E:\masm32\include\mpr.inc
includelib E:\masm32\lib\kernel32.lib
includelib E:\masm32\lib\user32.lib
includelib E:\masm32\lib\advapi32.lib
includelib E:\masm32\lib\mpr.lib
;include def32.inc
include E:\masm32\macros\Strings.mac
NTRESOURCE struc
dwScope dd ?
dwType dd ?
dwDisplayType dd ?
dwUsage dd ?
lpLocalName dd ?
lpRemoteName dd ?
lpComment dd ?
lpProvider dd ?
NTRESOURCE ends
.const
greet_message db 'My program',0h
error1_message db 'Could not get current user name',0h
error2_message db 'Could not enumerate',0h
good_exit_msg db 'Normal termination',0h
.data
user_name db 'List of connected resources for user '
user_buff db 64 dup (?)
user_buff_l dd $-user_buff
enum_buf_l dd 1056
enum_entries dd 1
enum_buf_len dd 800h
.data?
enum_buf NTRESOURCE <?,?,?,?,?,?,?,?>
dd 256 dup (?)
message_l dd ?
enum_handle dd ?
bytes dd ?
alloc_adr dd ?
.code
_start:
;invoke MessageBox,0h,offset greet_message,offset greet_message,MB_OK
invoke WNetGetUser,0h, offset user_buff, offset user_buff_l
cmp eax,NO_ERROR
jne error_exit1
invoke MessageBox,0h,offset user_name,offset user_name,MB_OK
invoke VirtualAlloc,0h,800h,MEM_COMMIT,PAGE_READWRITE
.if eax!=0h
push eax
mov dword ptr alloc_adr,eax
invoke MessageBox,0h,$CTA0("Memory Allocating success"),$CTA0("Success"),MB_OK
xor eax,eax
call netenum
pop eax
invoke VirtualFree,eax,800h,MEM_DECOMMIT
.if eax!=0
invoke MessageBox,0h,$CTA0("Memory DeAllocating success"),$CTA0("Success"),MB_OK
.else
invoke MessageBox,0h,$CTA0("Memmory DeAllocating Error"),$CTA0("Error"),MB_OK
.endif
.else
invoke MessageBox,0h,$CTA0("Memmory Allocating Error"),$CTA0("Error"),MB_OK
.endif
exit_program:
invoke MessageBox,0h,offset good_exit_msg,offset good_exit_msg,MB_OK
err_exit_program:
invoke ExitProcess,0h
error_exit1:
invoke MessageBox,0h,offset error1_message,offset error1_message,MB_OK
jmp short err_exit_program
netenum proc
invoke WNetOpenEnum,RESOURCE_GLOBALNET,RESOURCETYPE_ANY,0h,eax,offset enum_handle
cmp eax,NO_ERROR
jne error_exit2
enumeration_loop:
;invoke WNetEnumResource,dword ptr enum_handle,offset enum_entries,offset enum_buf,offset enum_buf_l
invoke WNetEnumResource,dword ptr enum_handle,offset enum_entries,dword ptr alloc_adr,offset enum_buf_len
comment @
;Для отладки!
push eax
push edx
push ebx
push ecx
mov eax,dword ptr enum_handle
mov edx,offset enum_entries
mov ebx,dword ptr alloc_adr
mov ecx,offset enum_buf_len
invoke WNetEnumResource,dword ptr enum_handle,offset enum_entries,dword ptr alloc_adr,offset enum_buf_len
pop ecx
pop ebx
pop edx
pop eax
@
cmp eax,ERROR_NO_MORE_ITEMS
je end_enumeration
cmp eax,NO_ERROR
jne error_exit2
;invoke MessageBox,0h,dword ptr enum_buf.lpLocalName,dword ptr enum_buf.lpLocalName,MB_OK
;invoke MessageBox,0h,dword ptr enum_buf.lpRemoteName,dword ptr enum_buf.lpRemoteName,MB_OK
mov edx,dword ptr alloc_adr
assume edx:ptr NTRESOURCE
invoke MessageBox,0h,[edx].lpRemoteName,$CTA0("Success"),MB_OK
assume edx:nothing
comment @
push eax
push edx
invoke CreateFile,$CTA0("3.txt"),GENERIC_READ or GENERIC_WRITE,0h,0h,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0h
push eax
invoke WriteFile,eax,edx,800h,offset bytes,0h
pop eax
invoke CloseHandle,eax
pop edx
pop eax
@
comment @
push dword ptr enum_handle
mov eax,dword ptr enum_buf
call netenum
pop dword ptr enum_handle
@
;invoke VirtualAlloc,0h,400h,MEM_COMMIT,PAGE_EXECUTE_READWRITE
;Надо, наверное, выделять память и туда всё писать... и вызываться рекурсивно потом...
push dword ptr enum_handle
push dword ptr enum_entries
push dword ptr alloc_adr
push dword ptr enum_buf_len
mov ecx,dword ptr alloc_adr
push ecx
invoke VirtualAlloc,0h,800h,MEM_COMMIT,PAGE_READWRITE
pop ecx
.if eax!=0h
push eax
mov dword ptr alloc_adr,eax
push ecx
invoke MessageBox,0h,$CTA0("Memory Allocating success"),$CTA0("Success in Recursion Function"),MB_OK
pop ecx
;xor eax,eax
assume ecx:ptr NTRESOURCE
lea eax,[ecx].dwScope
assume ecx:nothing
push 0
pop dword ptr enum_handle
call netenum
pop eax
invoke VirtualFree,eax,800h,MEM_DECOMMIT
.if eax!=0
invoke MessageBox,0h,$CTA0("Memory DeAllocating success"),$CTA0("Success in Recursion Function"),MB_OK
.else
invoke MessageBox,0h,$CTA0("Memmory DeAllocating Error"),$CTA0("Error in Recursion Function"),MB_OK
.endif
.else
invoke MessageBox,0h,$CTA0("Memmory Allocating Error"),$CTA0("Error in Recursion Function"),MB_OK
.endif
pop dword ptr enum_buf_len
pop dword ptr alloc_adr
pop dword ptr enum_entries
pop dword ptr enum_handle
jmp enumeration_loop
end_enumeration:
comment @
invoke CreateFile,$CTA0("3.txt"),GENERIC_READ or GENERIC_WRITE,0h,0h,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0h
push eax
invoke WriteFile,eax,offset enum_buf,1056,offset bytes,0h
pop eax
invoke CloseHandle,eax
@
invoke WNetCloseEnum,dword ptr enum_handle
ret
error_exit2:
invoke MessageBox,0h,offset error2_message,offset error2_message,MB_OK
;jmp short err_exit_program
ret
netenum endp
end _start
На C++ и Delphi всё просто - берёшь массив структур NTRESOURCE и всё!
А тут что-то dup(...) не работает!
Пришлось VirtualAlloc везде пихать...
Не знаю правильно это или не очень, но у меня работает!