WinAsm Studio, The Assembly IDE - Free Downloads, Source Code
Articles
Programming Quick Start
32-bit Assembler is Easy
Porting Iczelion tutorials
What is FASM
Hard Drive Recovery
Wiring your own LAN
 
Forum
Pages (2) [1] 2   ( Go to first unread post )

How to reverse a string, various methods for reversing strings in Assembly Language.

dqtln
Quote Post


New Member
*

Group: Members
Posts: 4
Member No.: 854
Joined: 13-December 04


Sponsored Links
hi all smile.gif
string db "dqtln123"
how to reverse it : "321nltqd"
thanks
PMEmail Poster
Top
shoorick
Quote Post


Extremely Active Member
******

Group: Admins
Posts: 2314
Member No.: 160
Joined: 22-June 04


at first tell us how we can find end of string:
1. place terminator at the and (zero, or say "$")
2. place string length at the start
3. suppose fixed length of 8 bytes

last case is simpliest:
CODE
mov eax,dword [string]
mov edx,dword [string + 4]
bswap eax
bswap edx
mov dword [string + 4],eax
mov dword [string],edx
PMEmail PosterUsers Website
Top
dqtln
Quote Post


New Member
*

Group: Members
Posts: 4
Member No.: 854
Joined: 13-December 04


string db "12345678"
reverse it : "78563412"
view tack hex dump of victim , kaka
i done ... thanks for reply
PMEmail Poster
Top
guyenWinasm
Quote Post


Active Member
***

Group: Members
Posts: 47
Member No.: 1386
Joined: 22-July 05


QUOTE (shoorick @ Feb 12 2007, 02:31 AM)
at first tell us how we can find end of string:
1. place terminator at the and (zero, or say "$")
2. place string length at the start
3. suppose fixed length of 8 bytes

last case is simpliest:
CODE
mov eax,dword [string]
mov edx,dword [string + 4]
bswap eax
bswap edx
mov dword [string + 4],eax
mov dword [string],edx

bswap doesn't work when lower then .486 specified.

idea is push and reset pointer to beginning of string again pop
CODE

string   db '1234567890'
strlen    dw $-string


IRP StackAction <push, pop>  //repeat first time push second time pop
LOCAL loop1                          // local variable in macro

lea  di, string                           // di=ptr to string
mov cx, strlen                         // cx= string length

loop1:
IFIDNI &StackAction&, <push> //  
mov al, byte ptr ds:[di]            // al= di -th byte
ENDIF

&StackAction& ax                    //replace with macro parameter

IFIDNI &StackAction&, <pop> // if pop
mov byte ptr ds:[di], al             // [di] = char in al
ENDIF

inc di                                      // di= next char
dec cx                                    // go toward 0
or cx, cx                                 // is counter 0?
jnz loop1                                 // if not loop ever

endm

haven't tested. but u got the idea
PMEmail Poster
Top
shoorick
Quote Post


Extremely Active Member
******

Group: Admins
Posts: 2314
Member No.: 160
Joined: 22-June 04


QUOTE (guyenWinasm @ Feb 24 2007, 05:30 AM)
bswap doesn't work when lower then .486 specified.

what cpu required?
CODE
string db "dqtln123"

� �lxi d,string
� �lxi h,7
� �mvi b,4
� �dad d
loop:
� �ldax d
� �mov c,m
� �xchg
� �mov m,c
� �stax d
� �inx h
� �dcx d
� �xchg
� �dec b
� �jnz loop
wink.gif
PMEmail PosterUsers Website
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

Topic Options Pages (2) [1] 2  Reply to this topicStart new topicStart Poll

 

Sponsors
Computer Science

Internet
C/C++
Hardware & PC maintenance

HiEditor

General Discussions
Suggestions/Bug Reports
WinAsm Studio

General Discussions
Suggestions/Bug Reports
WinAsm Studio FAQ
Multilingual User Interface
Add-Ins
Assembly Programming

Main
Newbies
Projects
Custom Controls
Snippets
Announcements & Rules

Announcements

General

Online Degrees - Distance Learning
The Heap
Russian