flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Search for string, instructions, etc

Author
Thread Post new topic Reply to topic
score_under



Joined: 27 Aug 2009
Posts: 27
score_under
Is it possible to search (i.e. using "repeat") for a byte, string, or set of instructions?

I tried something similar to this:
Code:
repeat $-$$
  load a byte from $$+%-1
  load b byte from $$+%
  if a eq 'H' & b eq 'i'
    loc equ $$+%-1
  end if
end repeat    

But it didn't work.

Is there any faster way then "load [x] byte from [y]" for strings, too?
Post 19 Jan 2010, 19:18
View user's profile Send private message Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
use
Code:
loc = $$+%-1    
'equ' is for preprocessor, and is a stage BEFORE the assembly stage. macro, match, rept, irp, irps and such are preprocessor directives.

The best way to understand this is that the preprocessor deals with symbolic, or "text" constants... and the assembly stage (i.e the '=') deals with NUMERIC constants (numbers).

and 'repeat' is assembly stage, so you have to use '='


also there is a faster way, if you load a 'word' instead of 'byte' (i.e 2 bytes), but for arbitrary strings it's gonna be pretty slow if you make it work for ANY string.

Here's one way to do it for any string (using a macro) that returns the string position into 'StringPos' assembly-time variable:

Code:
macro GetStringPos [String]
{
 common
  local s, p, n, a, b
  virtual at 0
    db String
    s = $                       ; gets the length of the string into 's'
  end virtual

  p = $$
  n = 1
  while $-p >= s & n=1
    n = 0
    repeat s
      load a byte from p+%-1
      virtual at p
        db String
        load b byte from p+%-1
      end virtual
      if a <> b
        if % > 1
          p = p-1
        end if
        p = p+%
        n = 1
        break
      end if
    end repeat
  end while
  if n = 0
    StringPos = p
  else
    err 'String was not found'
  end if
}

db '1234Som__SomeString_test'

GetStringPos 'Some'
db StringPos    
then look at the output and see the last byte, it should be 0x09 (the string's offset)

_________________
Previously known as The_Grey_Beast
Post 19 Jan 2010, 19:59
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
score_under wrote:

Code:
repeat $-$$
...
  load b byte from $$+%    
That will also fail. The last byte is beyond the end of the buffer will will cause an error. You need this:
Code:
repeat $-$$-1
...
  load b byte from $$+%    
Post 20 Jan 2010, 02:12
View user's profile Send private message Visit poster's website 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.

Powered by rwasa.