Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Trucos (https://www.clubdelphi.com/foros/forumdisplay.php?f=52)
-   -   mxProtector x32 y x64 (https://www.clubdelphi.com/foros/showthread.php?t=96730)

cloayza 05-06-2024 18:07:00

mxProtector x32 y x64
 
Estimados colegas

Yo utilizo el componente mxProtector en algunas aplicaciones para realizar el control de registro de seriales, etc...

El problema al que me vi enfrentado era que al intentar compilar algunas de estas aplicaciones en x64, este componente no lo permitia ya que tenia una restricción que esta en el archivo MAX.INC.

Código Delphi [-]
{$IFNDEF WIN32}
  Sorry, only 32bit versions of Delphi/C++ Builder are supported by this component!
{$ENDIF}

Nota: Luego de realizar las modificaciones esta línea hay que comentarla...

La razón de esto son las funciones en Asembler que forman parte del componente:
  • IsCPUIDAvailable
  • GetCPUID
  • GetCPUVendor

Y como dicen la necesidad tiene cara de hereje, me di a la labor de buscar opciones para estas funciones y afortunadamente encontre soluciones.

Ahora puedo compilar este componente en aplicaciones x32 y x64 y mis aplicaciones siguen operando como si nada hubiera pasado.

Les comparto el código que utilice para superar este pequeño problema, no si antes indicar las fuentes de donde obtuve las soluciones, que son:

David Heffernan
https://stackoverflow.com/questions/...-code-to-amd64

JBontes
https://github.com/JBontes/FastCode/...tcodeCPUID.pas

Aquí va los segmentos de códigos que hay que tocar en archivo mxProtector.Pas:
Código Delphi [-]
....

/ *************************************************************************************
// ** IsCPUIDAvailable, 10/12/01 2:04:15 PM
// *************************************************************************************

Const
     ID_BIT = $200000;

Type
     TCPUID = Array[ 1..4 ] Of Longint;
     TVendor = Array[ 0..11 ] Of Ansichar;

{Function IsCPUIDAvailable: Boolean; Register;
Asm
  PUSHFD
  POP     EAX
  MOV     EDX,EAX
  XOR     EAX,ID_BIT
  PUSH    EAX
  POPFD
  PUSHFD
  POP     EAX
  XOR     EAX,EDX
  JZ      @exit
  MOV     AL,True
@exit:
End;}

//Nueva código que sustituye IsCPUIDAvailable
Function IsCPUIDAvailable: Boolean; Register;
Asm
{$IF Defined(CPUX86)}
  PUSHFD
  POP     EAX
  MOV     EDX,EAX
  XOR     EAX,ID_BIT
  PUSH    EAX
  POPFD
  PUSHFD
  POP     EAX
  XOR     EAX,EDX
  JZ      @exit
  MOV     AL,True
@exit:
{$ELSE}
  MOV     EAX, True      {x64 always has CPUID}
{$ENDIF}
End;

// *************************************************************************************
// ** GetCPUID, 10/12/01 2:04:09 PM
// *************************************************************************************

{Function GetCPUID: TCPUID; Assembler; Register;
Asm
  PUSH    EBX
  PUSH    EDI
  MOV     EDI,EAX
  MOV     EAX,1
  DW      $A20F
  STOSD
  MOV     EAX,EBX
  STOSD
  MOV     EAX,ECX
  STOSD
  MOV     EAX,EDX
  STOSD
  POP     EDI
  POP     EBX
End;}

{
Autor : David Heffernan
Url   :https://stackoverflow.com/questions/...-code-to-amd64
}
function GetCPUID: TCPUID; Assembler; Register;
asm
{$IF Defined(CPUX86)}
  push  ebx
  push  edi
  mov   edi, eax
  mov   eax, 1
  xor   ecx,ecx
  cpuid
  mov   [edi+$0], eax
  mov   [edi+$4], ebx
  mov   [edi+$8], ecx
  mov   [edi+$c], edx
  pop   edi
  pop   ebx
{$ELSEIF Defined(CPUX64)}
  mov   r8, rbx
  mov   r9, rcx
  mov   eax, 1
  cpuid
  mov   [r9+$0], eax
  mov   [r9+$4], ebx
  mov   [r9+$8], ecx
  mov   [r9+$c], edx
  mov   rbx, r8
{$IFEND}
end;

// *************************************************************************************
// ** GetCPUVendor, 10/12/01 2:04:06 PM
// *************************************************************************************

{Function GetCPUVendor: TVendor; Assembler; Register;
Asm
  PUSH    EBX
  PUSH    EDI
  MOV     EDI,EAX
  MOV     EAX,0
  DW      $A20F
  MOV     EAX,EBX
  XCHG    EBX,ECX
  MOV    ECX,4
@1:
  STOSB
  SHR     EAX,8
  LOOP    @1
  MOV     EAX,EDX
  MOV    ECX,4
@2:
  STOSB
  SHR     EAX,8
  LOOP    @2
  MOV     EAX,EBX
  MOV    ECX,4
@3:
  STOSB
  SHR     EAX,8
  LOOP    @3
  POP     EDI
  POP     EBX
End;}

{
Autor: JBontes
Url  : https://github.com/JBontes/FastCode/...tcodeCPUID.pas
}
function GetCPUVendor:TVendor; Assembler; Register;
type
  TRegisters = record
      EAX,
      EBX,
      ECX,
      EDX: Cardinal;
  end;

var
  Registers: TRegisters;

  procedure GetCPUID_Internal({Param: Cardinal; }var Registers: TRegisters);
  {https://github.com/JBontes/FastCode/blob/master/FastcodeCPUID.pas}
  asm
  {$ifdef cpux86}
    PUSH    EBX                         {save affected registers}
    PUSH    EDI
    MOV     EDI, Registers
    XOR     EBX, EBX                    {clear EBX register}
    XOR     ECX, ECX                    {clear ECX register}
    XOR     EDX, EDX                    {clear EDX register}
    DB $0F, $A2                         {CPUID opcode}
    MOV     TRegisters(EDI).&EAX, EAX   {save EAX register}
    MOV     TRegisters(EDI).&EBX, EBX   {save EBX register}
    MOV     TRegisters(EDI).&ECX, ECX   {save ECX register}
    MOV     TRegisters(EDI).&EDX, EDX   {save EDX register}
    POP     EDI                         {restore registers}
    POP     EBX
  {$else X64}
    PUSH    RBX
    PUSH    RDI
    MOV     RDI, Registers
    MOV     EAX, ECX
    XOR     EBX, EBX
    XOR     ECX, ECX
    XOR     EDX, EDX
    CPUID
    MOV     TRegisters(RDI).&EAX, EAX
    MOV     TRegisters(RDI).&EBX, EBX
    MOV     TRegisters(RDI).&ECX, ECX
    MOV     TRegisters(RDI).&EDX, EDX
    POP     RDI
    POP     RBX
  {$endif}
  end;

begin
  GetCPUID_Internal({0,} Registers);

  {get vendor string}
  Move(Registers.EBX, Result[0], 4);
  Move(Registers.EDX, Result[4], 4);
  Move(Registers.ECX, Result[8], 4);
end;

// *************************************************************************************
// ** TmxProtector.InternalGetHardwareID, 10/12/01 2:04:03 PM
// *************************************************************************************

Function TmxProtector.InternalGetHardwareID: String;
...

Espero les sirva...Saludos cordiales

Casimiro Notevi 05-06-2024 19:06:07

^\||/^\||/^\||/

dec 06-06-2024 07:53:28

Hola a todos,

¡Gracias por compartirlo con todos nosotros, cloayza!

Neftali [Germán.Estévez] 06-06-2024 08:48:12

Gracias...
^\||/^\||/^\||/

Neeruu 29-04-2025 22:54:34

Hola cloayza, muchas gracias...

Podrias compartir todos los componentes mxprotector? ( pido que los comparta porque entiendo que son de libre distribucion), si estoy equivocado, perdon. Avisen y borro el post.)

Gracias.

Neftali [Germán.Estévez] 30-04-2025 08:35:04

Creo recordar que estaban en el FTP del club.
https://terawiki.clubdelphi.com/Delp...xComponents__/


La franja horaria es GMT +2. Ahora son las 17:29:07.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi