Tools for Windows programming

A Forum for free software.

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: 12 Nov 2016 20:01 
Offline

Joined: 07 Feb 2015 12:53
Posts: 37
Here is a macro to copy strings to the stack :

Code:
StrToStack  This string is passed to the stack

esp points to the address of the string in the stack.

The StrToStack macro splits a string to DWORD values and pushes them to the stack :

Code:
kc
ats
eht
ot d
essa
p si
gni
rts
sihT

push    27491
push    1635021600
push    1701344288
push    1869881444
push    1702064993
push    1881174889
push    543649385
push    1920234272
push    1936287828


A usage example :
Code:
include Test.inc
include StrToStackMacro.inc

; DEBUG_STR_TO_STACK=1

.data

frmt    db 13,10,13,10,'%s',13,10,'%s'
        db 13,10,13,10
        db 'Length of string1 = %d',13,10
        db 'Length of string2 = %d',13,10
        db 0

.data?

str1    dd ?
str2    dd ?
len1    dd ?
len2    dd ?
stack   dd ?

buffer  db 128 dup(?)

.code

start:

    StdOutX     <Macro test>

    StrToStack  This string is passed to the stack

    mov     str1,esp
    mov     stack,stackcount
    mov     len1,stringlen

    mov     str2,\
            @StrToStack(The second long line copied to the stack)
   
    add     stack,stackcount
    mov     len2,stringlen

    invoke  wsprintf,ADDR buffer,\
            ADDR frmt,str1,str2,len1,len2
           
    invoke  StdOut,ADDR buffer

    add     esp,stack

    invoke  ExitProcess,0

END start


stackcount : number of bytes to balance the stack to remove the string
stringlen : the length of the string in the stack


Attachments:
StrToStack.zip [5.94 KiB]
Downloaded 12 times
Top
 Profile  
 
PostPosted: 09 Apr 2017 10:47 
Offline

Joined: 07 Feb 2015 12:53
Posts: 37
Here is the Masm 64 bit version.


Attachments:
StringToStack.zip [7.68 KiB]
Downloaded 6 times
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


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 post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group