[fpc-pascal] fpc-2.1.4.x86_64-win64.exe: default switch generates intel asm, ironic ? Can free pascal reverse engineer executables and dll's ?
Skybuck Flying
skybuck2000 at hotmail.com
Thu Jul 26 12:02:41 CEST 2007
Hello,
I like free pascal compiler to generate an assembler listing of
HelloWorld.pas and fortunately it can do that which is really cool !
I simply type:
ppcrossx64 HelloWorld.pas -default
It then generates a HelloWorld.S file:
Here is a snipper from it ;)
<Begin of Snippet>
; Begin asmlist al_procedures
_TEXT SEGMENT
ALIGN 16
PUBLIC PASCALMAIN
PASCALMAIN:
PUBLIC main
main:
push rbp
mov rbp,rsp
sub rsp,96
mov qword ptr [rbp-8],rbx
call FPC_INITIALIZEUNITS
call fpc_get_output
mov rbx,rax
mov al,1
mov r9,24
mov r8,offset _$HELLOWORLD$_Ld1
mov rdx,rbx
mov ecx,0
mov byte ptr [rsp+32],al
call fpc_write_text_pchar_as_array
call FPC_IOCHECK
mov rcx,rbx
call fpc_writeln_end
call FPC_IOCHECK
mov eax,10
mov qword ptr [U_P$HELLOWORLD_TEST],eax
call fpc_get_output
mov rbx,rax
mov al,1
mov r9,5
mov r8,offset _$HELLOWORLD$_Ld2
mov rdx,rbx
mov ecx,0
mov byte ptr [rsp+32],al
call fpc_write_text_pchar_as_array
call FPC_IOCHECK
mov r8,qword ptr [U_P$HELLOWORLD_TEST]
mov rdx,rbx
mov ecx,0
call fpc_write_text_sint
call FPC_IOCHECK
mov rcx,rbx
call fpc_writeln_end
call FPC_IOCHECK
mov eax,100
mov qword ptr [U_P$HELLOWORLD_TEST],eax
call fpc_get_output
mov rbx,rax
mov al,1
mov r9,5
mov r8,offset _$HELLOWORLD$_Ld2
mov rdx,rbx
mov ecx,0
mov byte ptr [rsp+32],al
call fpc_write_text_pchar_as_array
call FPC_IOCHECK
mov r8,qword ptr [U_P$HELLOWORLD_TEST]
mov rdx,rbx
mov ecx,0
call fpc_write_text_sint
call FPC_IOCHECK
mov rcx,rbx
call fpc_writeln_end
call FPC_IOCHECK
mov rax,-1
mov qword ptr [U_P$HELLOWORLD_TEST],rax
call fpc_get_output
mov rbx,rax
mov al,1
mov r9,5
mov r8,offset _$HELLOWORLD$_Ld2
mov rdx,rbx
mov ecx,0
mov byte ptr [rsp+32],al
call fpc_write_text_pchar_as_array
call FPC_IOCHECK
mov r8,qword ptr [U_P$HELLOWORLD_TEST]
mov rdx,rbx
mov ecx,0
call fpc_write_text_sint
call FPC_IOCHECK
mov rcx,rbx
call fpc_writeln_end
call FPC_IOCHECK
mov dword ptr [U_P$HELLOWORLD_TEST],-1
mov dword ptr [U_P$HELLOWORLD_TEST+4],2147483647
call fpc_get_output
mov rbx,rax
mov al,1
mov r9,5
mov r8,offset _$HELLOWORLD$_Ld2
mov rdx,rbx
mov ecx,0
mov byte ptr [rsp+32],al
call fpc_write_text_pchar_as_array
call FPC_IOCHECK
mov r8,qword ptr [U_P$HELLOWORLD_TEST]
mov rdx,rbx
mov ecx,0
call fpc_write_text_sint
call FPC_IOCHECK
mov rcx,rbx
call fpc_writeln_end
call FPC_IOCHECK
call fpc_get_input
mov rbx,rax
mov rcx,rbx
call fpc_readln_end
call FPC_IOCHECK
call FPC_DO_EXIT
mov rbx,qword ptr [rbp-8]
leave
ret
; End asmlist al_procedures
; Begin asmlist al_globals
<End of Snippet>
Pretty cool.
Kinda ironic how it can generate it, but not interpret it ? ;)
For me it doesn't matter that much, I would like to give AT&T asm a try...
though it might not be smart because Visual Studio 2005, Intel, probably AMD
too, and Delphi 2007 all use intel syntax.
So for future compatibility using AT&T asm syntax might not be too smart.
But maybe I will like AT&T syntax... I never liked intel syntax that much...
kinda stupid and crazy but ok ;) :)
I wonder what free pascal can do more ?
Can it reverse engineer executables and dll's and produce asm listings ?
Bye,
Skybuck.
----- Original Message -----
From: "Jonas Maebe" <jonas.maebe at elis.ugent.be>
To: "FPC-Pascal users discussions" <fpc-pascal at lists.freepascal.org>
Sent: Thursday, July 26, 2007 10:51 AM
Subject: Re: [fpc-pascal] fpc-2.1.4.x86_64-win64.exe: -Mdelphi not working ?
>
> On 26 Jul 2007, at 10:44, Skybuck Flying wrote:
>
>> I just reinstalled fpc-2.1.4.x86_64-win64.exe:
>>
>> And this time I used the -Mdelphi compiler switch but it still gives
>> problems:
>>
>> Y:\Free Pascal\Tests\Hello World>ppcrossx64 HelloWorld.pas -Mdelphi
>> HelloWorld.pas(9,10) Error: Unknown identifier "EAX"
>> HelloWorld.pas(9,12) Error: Unknown identifier "ECX"
>> HelloWorld.pas(9,12) Error: Asm: [mov ???,???] invalid combination of
>> opcode and
>> operands
>> HelloWorld.pas(16,4) Fatal: There were 3 errors compiling module,
>> stopping
>> Fatal: Compilation aborted
>
> I guess the Intel assembler syntax is simply not supported for x86-64.
> You will have to use AT&T syntax instead. Here are some google links to
> tutorials and overview documents:
> http://www.google.com/search?rls=en&q=at%26t+assembler+syntax
>
>
> Jonas
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
More information about the fpc-pascal
mailing list