flat assembler
Message board for the users of flat assembler.

Index > Windows > how this would work?

Author
Thread Post new topic Reply to topic
MisterQ



Joined: 19 Sep 2009
Posts: 1
MisterQ 29 Nov 2009, 02:18
Very Happy Hello, in C++:
Code:
      #include<STDIO.h>
  void main (void){
    int a;
      printf ("Programa víctima de una inyección.By MisterM\n");
     printf ("El objetivo es conseguir que muestre'1'\n");
    getchar ();

     _asm{
                lea edx,a
                   mov eax,0
                   mov [edx],eax
                       }
              printf("%d\n",a);
                getchar();
          }
                  

....in Delphi:
Code:
                 program victima;
           {$APPTYPE CONSOLE}
          var
          i: integer;
   begin

        WriteLn ('******************************************') ;
        WriteLn ('Programa victima de una inyeccion by Miguel');
        WriteLn ('El objetivo es conseguir que muestre 1');
        WriteLn ('--------------------------------------');
        ReadLn;
     asm
          push edx
           lea edx,i
            mov eax,0
           mov [edx],eax
          pop edx
     end;
        WriteLn (i);
      ReadLn;
   end.
                


How do get the same in Fasm?
Code:
          
  format PE console
   entry start
 
    include 'win32a.inc'
 
;======================================
section '.data' data readable writeable
;======================================
 
  hello_msg db 'Programa victima de una inyeccion',13,10
            db 'El objetivo es conseguir que muestre 1',13 ,10
            db ' ',13,10

            a  dd ?


;=======================================
section '.code' code readable executable
;=======================================
 
  start:
        ccall   [printf],hello_msg
        ccall   [getchar]


        lea edx,[a]
        mov eax,0
        mov [edx],eax


      ;HERE is the problem...?


        ccall   [printf],a
        ccall   [getchar]

        stdcall [ExitProcess],0
 
;====================================
section '.idata' import data readable
;====================================
 
  library kernel,'kernel32.dll',\
          msvcrt,'msvcrt.dll'
 
  import kernel,\
          ExitProcess, 'ExitProcess'
  import msvcrt,\
          printf,'printf',\
          getchar,'_fgetchar'
                    

Thanks... [/code]

_________________
Hello Here I am again
Post 29 Nov 2009, 02:18
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 29 Nov 2009, 02:45
Before anything, fix your string, you have to end it with a NULL and remove the CR characters because them are redundant with the C API, using LF is enough:
Code:
  hello_msg db 'Programa victima de una inyeccion',10,\
             'El objetivo es conseguir que muestre 1',10,\
             ' ',10,\
             0 ; End of NULL terminated string      


Now the problem just seems to be that you forgot to pass a format string to the second printf and that you were passing a pointer to a rather than its content:
Code:
cinvoke printf, fmt, [a]
cinvoke getchar
invoke ExitProcess, 0

fmt db '%d', 10, 0    


BTW, if the program objective really is to show 1 then replace "mov eax, 0" with "mov eax, 1" or even just "mov [a], 1" and discard all the other instructions.
Post 29 Nov 2009, 02:45
View user's profile Send private message Reply with quote
asmMe



Joined: 14 Jun 2011
Posts: 18
asmMe 18 Jul 2011, 16:06
Loco, off topic but...

Quote:

Before anything, fix your string, you have to end it with a NULL and remove the CR characters because them are redundant with the C API, using LF is enough:


Is the CR placed by C automatically or is it just not used?
My reason for asking..
Try opening a '*.txt' file that has LFs but no corresponding CR in Notepad.exe. It doesn't recognize LFs as a newline without the CR
Post 18 Jul 2011, 16:06
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 18 Jul 2011, 17:04
Code:
format PE console 4.0

include 'win32a.inc'

entry start

section '.code' readable executable
fmt db 10, 0
start:
        cinvoke printf, fmt
        invoke ExitProcess,0

section '.idata' data import readable writeable
library kernel32,'kernel32.dll',msvcrt,'msvcrt.dll'
import kernel32,ExitProcess,'ExitProcess'
import msvcrt,printf,'printf'    
If you set a breakpoint at WriteConsoleA you'll see the following buffer:
Code:
CPU Dump
Address   Hex dump                                         ASCII
0007FAF8  0D 0A                                            ..    
And the "Count" parameter is equal to two. If you set fmt to "13, 10, 0" then buffer is:
Code:
CPU Dump
Address   Hex dump                                         ASCII
0007FAF8  0D 0D 0A                                         ...    
And the "Count" parameter is equal to three.

Haven't checked what happens with fprintf, could you contribute that test?Very Happy
Post 18 Jul 2011, 17:04
View user's profile Send private message Reply with quote
asmMe



Joined: 14 Jun 2011
Posts: 18
asmMe 18 Jul 2011, 21:09
Thanks for the clarification Loco.
I don't use any of the cinvoke functions, I have similar ones written from years ago that I still use.
Post 18 Jul 2011, 21:09
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.