Einzelnen Beitrag anzeigen

CCRDude

Registriert seit: 9. Jun 2011
675 Beiträge
 
FreePascal / Lazarus
 
#5

AW: Zydis - X86/X86-64 Disassembler Library

  Alt 9. Apr 2018, 13:22
Wollte mich ja schon viel früher rückmelden, klappt aber leider erst jetzt

Offensichtliche Änderungen für FreePascal sind marginal.

Statisches Linken klappt in FPC nicht, da es Eigenheiten der Obj-Dateien nicht unterstützt.

Ich musste die Array-Größe der Konstante X86DATA festlegen, da kann FPC scheinbar keine konstanten dynamischen Arrays.

FreePascal ist mit Namespaces noch nicht so weit, daher IFDEFs für System.SysUtils.

Für Unterschiede in Methoden-Deklarationen in implementation und interface muss in den Delphi-Kompatibilitätsmodus geschaltet werden.

Mit 64 bit kompiliert klappt SimpleDemo so super.

In 32 bit haut mir aktuell leider ein "File not open" als Fehler raus (in Formatter.FormatInstruction). ZydisFormatterFormatInstructionEx liefert ZYDIS_STATUS_INVALID_PARAMETER.

Hier mein diff:

Delphi-Quellcode:
 Examples/SimpleDemo.dpr | 8 ++++----
 Zydis/Zydis.Decoder.pas | 7 ++++++-
 Zydis/Zydis.Exception.pas | 3 ++-
 Zydis/Zydis.Formatter.pas | 11 ++++++++---
 Zydis/Zydis.pas | 5 +++++
 5 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/Examples/SimpleDemo.dpr b/Examples/SimpleDemo.dpr
index c2b81fe..4917731 100644
--- a/Examples/SimpleDemo.dpr
+++ b/Examples/SimpleDemo.dpr
@@ -31,7 +31,7 @@ program SimpleDemo;
 {$R *.res}
 
 uses
- System.SysUtils,
+ {$IFDEF FPC} SysUtils, {$ELSE FPC} System.SysUtils, {$ENDIF FPC}
   Zydis in '../Zydis/Zydis.pas',
   Zydis.Exception in '../Zydis/Zydis.Exception.pas',
   Zydis.Decoder in '../Zydis/Zydis.Decoder.pas',
@@ -42,9 +42,9 @@ uses
 {* ============================================================================================== *}
 
 const
- X86DATA: array of Byte = [$51, $8D, $45, $FF, $50, $FF, $75, $0C, $FF, $75,
- $08, $FF, $15, $A0, $A5, $48, $76, $85, $C0, $0F,
- $88, $FC, $DA, $02, $00];
+ X86DATA: array[0..24] of Byte = ($51, $8D, $45, $FF, $50, $FF, $75, $0C, $FF, $75,
+ $08, $FF, $15, $A0, $A5, $48, $76, $85, $C0, $0F,
+ $88, $FC, $DA, $02, $00);
 
 var
   Formatter: Zydis.Formatter.TZydisFormatter;
diff --git a/Zydis/Zydis.Decoder.pas b/Zydis/Zydis.Decoder.pas
index 1ec0d80..ed06371 100644
--- a/Zydis/Zydis.Decoder.pas
+++ b/Zydis/Zydis.Decoder.pas
@@ -28,8 +28,13 @@ unit Zydis.Decoder;
 
 interface
 
+{$IFDEF FPC}
+{$MODE Delphi}
+{$ENDIF FPC}
+
 uses
- System.SysUtils, Zydis, Zydis.Exception;
+ {$IFDEF FPC} SysUtils, {$ELSE FPC} System.SysUtils, {$ENDIF FPC}
+ Zydis, Zydis.Exception;
 
 type
   TZydisDecoder = class sealed(TObject)
diff --git a/Zydis/Zydis.Exception.pas b/Zydis/Zydis.Exception.pas
index b23bc90..e5c45ca 100644
--- a/Zydis/Zydis.Exception.pas
+++ b/Zydis/Zydis.Exception.pas
@@ -29,7 +29,8 @@ unit Zydis.Exception;
 interface
 
 uses
- System.SysUtils, Zydis;
+ {$IFDEF FPC} SysUtils, {$ELSE FPC} System.SysUtils, {$ENDIF FPC}
+ Zydis;
 
 type
   TZydisException = class(Exception)
diff --git a/Zydis/Zydis.Formatter.pas b/Zydis/Zydis.Formatter.pas
index 1922910..3e5d61c 100644
--- a/Zydis/Zydis.Formatter.pas
+++ b/Zydis/Zydis.Formatter.pas
@@ -28,8 +28,13 @@ unit Zydis.Formatter;
 
 interface
 
+{$IFDEF FPC}
+{$MODE Delphi}
+{$ENDIF FPC}
+
 uses
- System.SysUtils, Zydis, Zydis.Exception;
+ {$IFDEF FPC} SysUtils, {$ELSE FPC} System.SysUtils, {$ENDIF FPC}
+ Zydis, Zydis.Exception;
 
 type
   TZydisFormatter = class(TObject)
@@ -383,7 +388,7 @@ begin
     Data := @Buffer[0];
   end;
   if (not ZydisSuccess(Status)) then TZydisException.RaiseException(Status);
- Result := String(PAnsiChar(Data));
+ Result := String(AnsiString(PAnsiChar(Data)));
 end;
 
 function TZydisFormatter.FormatOperand(const Instruction: TZydisDecodedInstruction;
@@ -410,7 +415,7 @@ begin
     Data := @Buffer[0];
   end;
   if (not ZydisSuccess(Status)) then TZydisException.RaiseException(Status);
- Result := String(PAnsiChar(Data));
+ Result := String(AnsiString(PAnsiChar(Data)));
 end;
 
 class function TZydisFormatter.InternalFormatInstruction(const Formatter: Zydis.TZydisFormatter;
diff --git a/Zydis/Zydis.pas b/Zydis/Zydis.pas
index 41695f7..6c839de 100644
--- a/Zydis/Zydis.pas
+++ b/Zydis/Zydis.pas
@@ -30,6 +30,11 @@ interface
 
 {$DEFINE ZYDIS_DYNAMIC_LINK}
 
+{$IFDEF FPC}
+{$DEFINE ZYDIS_DYNAMIC_LINK}
+{$MODE Delphi}
+{$ENDIF FPC}
+
 {* ============================================================================================== *}
 {* Constants                                                                                      *}
 {* ============================================================================================== *}
  Mit Zitat antworten Zitat