CARRIE 发表于 2014-8-7 09:09:53

Delphi自定义获取网卡MAC地址过程

//获取网卡MAC地址===============================================================
procedure CvtInt;
asm
      OR      CL,CL
      JNZ   @CvtLoop
@C1:    OR      EAX,EAX
      JNS   @C2
      NEG   EAX
      CALL    @C2
      MOV   AL,'-'
      INC   ECX
      DEC   ESI
      MOV   ,AL
      RET
@C2:    MOV   ECX,10

@CvtLoop:
      PUSH    EDX
      PUSH    ESI
@D1:    XOR   EDX,EDX
      DIV   ECX
      DEC   ESI
      ADD   DL,'0'
      CMP   DL,'0'+10
      JB      @D2
      ADD   DL,('A'-'0')-10
@D2:    MOV   ,DL
      OR      EAX,EAX
      JNE   @D1
      POP   ECX
      POP   EDX
      SUB   ECX,ESI
      SUB   EDX,ECX
      JBE   @D5
      ADD   ECX,EDX
      MOV   AL,'0'
      SUB   ESI,EDX
      JMP   @z
@zloop: MOV   ,AL
@z:   DEC   EDX
      JNZ   @zloop
      MOV   ,AL
@D5:
end;

function IntToHex(Value: Integer; Digits: Integer): string;
asm
      CMP   EDX, 32      // Digits < buffer length?
      JBE   @A1
      XOR   EDX, EDX
@A1:    PUSH    ESI
      MOV   ESI, ESP
      SUB   ESP, 32
      PUSH    ECX            // result ptr
      MOV   ECX, 16      // base 16   EDX = Digits = field width
      CALL    CvtInt
      MOV   EDX, ESI
      POP   EAX            // result ptr
      CALL    System.@LStrFromPCharLen
      ADD   ESP, 32
      POP   ESI
end;

function MacAddress: string; //获取MAC信息
var      
Lib: Cardinal;
Func: function(GUID: PGUID): Longint; stdcall;      
GUID1, GUID2: TGUID;      
begin
Result :='';      
Lib := LoadLibrary('rpcrt4.dll');
if Lib <> 0 then      
begin
    @Func := GetProcAddress(Lib, 'UuidCreateSequential');
    if Assigned(Func) then
    begin      
      if (Func(@GUID1) = 0) and      
      (Func(@GUID2) = 0) and      
      (GUID1.D4 = GUID2.D4) and      
      (GUID1.D4 = GUID2.D4) and      
      (GUID1.D4 = GUID2.D4) and      
      (GUID1.D4 = GUID2.D4) and      
      (GUID1.D4 = GUID2.D4) and      
      (GUID1.D4 = GUID2.D4) then      
      begin      
      Result :=      
         IntToHex(GUID1.D4, 2) + '-' +
         IntToHex(GUID1.D4, 2) + '-' +
         IntToHex(GUID1.D4, 2) + '-' +      
         IntToHex(GUID1.D4, 2) + '-' +      
         IntToHex(GUID1.D4, 2) + '-' +
         IntToHex(GUID1.D4, 2);      
      end;      
    end;      
    FreeLibrary(Lib);      
end;      
end;
页: [1]
查看完整版本: Delphi自定义获取网卡MAC地址过程