flat assembler
Message board for the users of flat assembler.

Index > Main > 32 bit string macro

Author
Thread Post new topic Reply to topic
redsock



Joined: 09 Oct 2009
Posts: 365
Location: Australia
redsock
Hey all, hoping for some assistance with my 32 bit string macro. It works well enough the way I have it, but surely there is a much, much better way to do it that I just haven't been able to work out.

Basically, there are two problems with it: 1) I couldn't figure out a better (or the proper) way to do it without wasting space in my end-resultant binary for my "scratch space" to promote normal strings to 32 bits. 2) I tried several things to get my macro to do comma-delimited lists, such as 'hello world',10,'hello again',10 but finally decided it is better to just ask you guys Smile hopefully y'all can enlighten me, hahah.

Code:
static_string_limit = 256

static_string_space:
        db static_string_limit dup 0

macro cleartext name*,val* {
        local AA,BB,.WTF,CC,DD,I,Si,J
        align 16
        name:
        dq      AA
        .WTF:
        db      val
        BB = ($ - .WTF)
        AA = BB
        if AA > static_string_limit
                display `name # " name is too long (static_string_limit setting)",13,10
                err
        end if
        ; so now, we have declared a straight byte version
        CC = AA shl 2
        ; CC now has how many bytes we really need for it
        DD = CC - BB
        ; so we can declare our extra space here:
        db      DD dup 0
        ; now we need to COPY the BB# of bytes stored at .WTF into the static_string_space (temporarily)
        ; and once it is there, we can them promote it to 32 bits back into the address at WTF
        ; and then clear the bytes we wrote into at static_string_space so they don't get dumped into
        ; our binary
        ; TODO: there has to be a way to do this without using the static_string_space
        I = 0
        repeat BB
                load Si byte from .WTF+I
                store byte Si at static_string_space+I
                I = I + 1
        end repeat
        I = 0
        J = 0
        repeat BB
                load Si byte from static_string_space+I
                store dword Si at .WTF+J
                I = I + 1
                J = J + 4
        end repeat
        I = 0
        J = 0
        repeat BB
                store byte J at static_string_space+I
                I = I + 1
        end repeat
}
    


It places a 64bit length preface before the 32bit promoted string, and all works well, other than the aforementioned issues with it.

cleartext .myvar, 'string'

works a treat... but with the static_string_space in the binary, as well as my inability to work out how to get 'string',10 to work properly, heheh.

Cheers and thanks as always
Post 05 Sep 2014, 03:42
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17717
Location: In your JS exploiting you and your system
revolution
If you work through the string backwards then you won't need to copy the string to a temporary buffer.
Post 05 Sep 2014, 06:16
View user's profile Send private message Visit poster's website Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
redsock
As for your first issue, I totally support the revolution's suggestion.
As for the second one, just put brackets around val* in your macro header. Almost forgot: and put the directive common in front of the local directive.

_________________
Faith is a superposition of knowledge and fallacy
Post 05 Sep 2014, 11:14
View user's profile Send private message Reply with quote
redsock



Joined: 09 Oct 2009
Posts: 365
Location: Australia
redsock
Hah! Sometimes the simplest and most obvious ways to solve problems are the most elusive... haha, thx very kindly to both of you...

Here is the revised macro, much nicer:

Code:
macro cleartext name*, [val*] {
common
        local .DAT,CC,I,Si,J
        align 16
        name:
        dq      CC
        .DAT:
        db      val
        CC = ($ - .DAT)
        ; create filler for the diff
        db ((CC shl 2) - CC) dup 0
        ; next up: walk backward through the string and promote it to 32bits
        I = CC - 1
        J = I shl 2
        repeat CC
                load Si byte from .DAT+I
                store dword Si at .DAT+J
                I = I - 1
                J = J - 4
        end repeat
}
    


Smile Smile
Post 05 Sep 2014, 21:45
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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.