Author Topic: [asm] A program to copy a string onto another string  (Read 2441 times)

0 Members and 1 Guest are viewing this topic.

Offline parad0x

  • VIP
  • Royal Highness
  • *
  • Posts: 638
  • Cookies: 118
    • View Profile
[asm] A program to copy a string onto another string
« on: April 27, 2013, 08:47:23 am »
Here is what I wrote, Its for linux systems


Code: (Asm) [Select]

#A simple asm program for that copies a string onto another.


.data
    EvilZone:
      .asciz "I love EvilZone.org!\n"


   Before_Copying:
       .asciz "Before copying: "


   After_Copying:
      .asciz "After Copying: "


   New_Line:
      .asciz "\n"
.bss


   .lcomm copied_string, 21


.text


.globl _start


_start:


  #Function to print copied_string and EvilZone on the Screen   
   
   movl $4, %eax
   movl $1, %ebx
   movl $Before_Copying, %ecx
   movl $16, %edx
   int  $0x80


   movl $4, %eax
   movl $1, %ebx
   movl $copied_string, %ecx
   movl $21, %edx
   int  $0x80


   movl $4, %eax
   movl $1, %ebx
   movl $New_Line, %ecx
   movl $21, %edx
   int  $0x80


#Function to copy string EvilZone to copied_string
 
   movl $EvilZone, %esi      #Copy the address of string EvilZone into register esi
   movl $copied_string, %edi   #Copy the address of copy_string into register edi
   movl $21, %ecx         #Copy the length of string EvilZone into register ecx for using REP
   cld
   rep movsb
   std




   movl $4, %eax
   movl $1, %ebx
   movl $After_Copying, %ecx
   movl $15, %edx
   int  $0x80


   movl $4, %eax
   movl $1, %ebx
   movl $EvilZone, %ecx
   movl $21, %edx
   int  $0x80 


  #Function to exit the program


   movl $1, %eax
   movl $0, %ebx
   int $0x80   


Output:


Code: [Select]
root@bt:~# /root/Desktop/asm/CopyString
Before copying:
After Copying: I love EvilZone.org!
root@bt:~#


Feel free to criticise the code.
I will work upon if you think the code is not upto the mark.
« Last Edit: April 27, 2013, 08:48:49 am by parad0x »

Offline Stackprotector

  • Administrator
  • Titan
  • *
  • Posts: 2515
  • Cookies: 205
    • View Profile
Re: [asm] A program to copy a string onto another string
« Reply #1 on: April 28, 2013, 02:06:56 pm »
A good way is to null escape your string and check if you hit the null byte instead of taking the strlen in the process. And of course, then you would need to do some dynamic memory magic or take a maximum strlen in mind.
~Factionwars