原文:https://www.pediy.com/kssd/pediy10/97107.html
Struct A { Int charme; }*a; Struct B { A c; }*b
int _ClientLogin( LPVOID _lpStruct) { TranSocket *stSock; ... int k = stSock->dwIndex; //相当于取stSock.dwIndex 赋值给k ... return (0); }
.386 .model flat,stdcall option casemap:none include windows.inc include kernel32.inc include user32.inc includelib user32.lib includelib kernel32.lib aa struct charme dd ? aa ends bb struct charme1 dd ? cc aa <> bb ends .data? p2 bb <> ;;;;;;;注意 p1 aa <> ;;;;;;;;注意 szEAX db 8 dup('0'),0 strr1 dd ? .data strr db "charme",0 .code ExchangCode proc w32BitCode:DWORD,lpCode:DWORD push ebx push ecx push esi mov esi,lpCode mov eax,w32BitCode mov ecx,8 @@nextchar: push ecx rol eax,4 mov ebx,eax and ebx,0000000Fh cmp bl,09 jle @@char0_9 add bl,07h @@char0_9: add bl,30h mov BYTE PTR [esi],bl inc esi pop ecx loop @@nextchar pop esi pop ecx pop ebx ret ExchangCode endp main proc mov p1.charme,20h mov ebx, p2.cc.charme push offset szEAX push ebx call ExchangCode push 40h push offset strr push offset szEAX push 0 call MessageBox ;push 03e8h ;call Sleep push 0 call ExitProcess main endp end main
.386 .model flat,stdcall option casemap:none include D:\MASMPlus\Include\windows.inc include D:\MASMPlus\Include\kernel32.inc include D:\MASMPlus\Include\user32.inc includelib D:\MASMPlus\Lib\kernel32.lib includelib D:\MASMPlus\Lib\user32.lib X struct a dd 10h b db 10 dup(?) X ends Y struct cc dd ? d dd ? e db ? Y ends M struct p X <> q Y <> M ends .data stMy M <> szEAX db 8 dup('0'),0 szTitle db "charme",0 .code ExchangCode proc w32BitCode:DWORD,lpCode:DWORD push ebx push ecx push esi mov esi,lpCode mov eax,w32BitCode mov ecx,8 @@nextchar: push ecx rol eax,4 mov ebx,eax and ebx,0000000Fh cmp bl,09 jle @@char0_9 add bl,07h @@char0_9: add bl,30h mov BYTE PTR [esi],bl inc esi pop ecx loop @@nextchar pop esi pop ecx pop ebx ret ExchangCode endp start: ;;正确做法一 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;lea ebx, stMy ;;指向M结构的一个指针 ;mov eax,(M ptr [ebx]).p.a;;必须加上M ptr因为C里面我们也看到了,实际上这个指向M结构的指针已idngyao确定是某个结构的,,因为你lea ebx, stMy只是初始化了一个指针,并没有给你要初始化的结构分配空间 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;正确在做法二 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;mov ebx,sizeof M ;;mov eax,stMy[ebx].p.a ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;正确做法三 lea esi,stMy.p mov ebx,(X ptr [esi]).a push offset szEAX push ebx call ExchangCode push 40h push offset szTitle push offset szEAX push 0 call MessageBox ret end start
AA struct Ch1 dd ? Ch2 dd ? AA ends .data Align word aa AA 3 dup(<0,0>) .code Start: Mov edi,0 Mov ecx,3 Mov eax,1 Loopp: Mov (AA ptr aa[edi]).ch1,eax Mov (AA ptr aa[edi]).ch2,eax Add edi,TYPE AA ;;或者是SIZEOF AA,这里获得的大小就是结构数组里单个数组的大小 Inc eax Loop loopp Push 0 Call ExitProcess End start
lea ebx, stMy mov eax, [ebx].p.a