flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > Code cannot be generated

Author
Thread Post new topic Reply to topic
CandyMan



Joined: 04 Sep 2009
Posts: 414
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
CandyMan 22 Sep 2021, 14:28
Code:
        use32

macro   jmp target
{
local ..Next,..Prev
virtual at $
..Prev:
        jmp target
..Next:
end virtual
if $>=2
        load W word from (..Prev-2)
        if W and 0xF0 = 70h & W shr 8 = (..Next-..Prev)
          nop
        else
          jmp   target
        end if
else
        jmp     target
end if
}
        jz      @F
        jmp     Jump
@@:
        rb      256
Jump:
        jz      @F
        jmp     Jmp2
@@:
        rb      256
Jmp2:    

_________________
smaller is better
Post 22 Sep 2021, 14:28
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 22 Sep 2021, 14:50
Post 22 Sep 2021, 14:50
View user's profile Send private message Visit poster's website Reply with quote
CandyMan



Joined: 04 Sep 2009
Posts: 414
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
CandyMan 23 Sep 2021, 16:50
I want to replace all jmp instructions that preceded with jcc with nop, but only those that are not jumped to by another jmp instruction. Unfortunately, the macro doesn't work for me. The directive in the macro erroneously displays "000", and at the end of the code correctly displays "110".
Help me.
Code:
        use32

virtual at 0
Jumps::
        rd 1024
end virtual

virtual at 0
Jump2::
        rd 1024
end virtual

virtual at 0
Jump3::
        rb 1024
end virtual

Starts = 0
Start2 = 0

macro   jmp Target
{
local ..Next,..Prev,..Curr,..Found,Sticky
if ~ Target eqtype eax
virtual at $
..Prev:
        jmp Target
..Next:
end virtual
  store dword Target at Jumps:Starts shl 2
  Starts = Starts+1
if $-$$>=2
  store dword ..Prev at Jump2:Start2 shl 3+0
  store dword ..Next at Jump2:Start2 shl 3+4
  Start2 = Start2+1

  load ..Found byte from Jump3:Starts-1
  display ..Found+'0'

        load W word from ..Prev-2
        if W and 0xF0 = 70h & W shr 8 = (..Next-..Prev) & ..Found = 0 | Sticky = 1
                nop
                Sticky = 1
        else
          jmp   Target
                Sticky = 0
        end if
else
        jmp     Target                                                `
                Sticky = 0
end if
end if
}

        inc     eax
        jz      @F      ;\ not possible to modify
Y:      jmp     Jmp3    ;/
@@:
        rdmsr
Jmp3:
        jmp     Y

        jz      @F      ;\ possible to modify
        jmp     Jmp4    ;/
@@:     rdtscp
Jmp4:

  display 13,10
  repeat Starts
    ..Found = 0
    load X dword from Jumps:(%-1) shl 2
    repeat Start2
      load X1 dword from Jump2:(%-1) shl 3+0
      load X2 dword from Jump2:(%-1) shl 3+4
      if X>=X1 & X<=X2
        ..Found = 1
        Break
      end if
    end repeat
    display ..Found+'0'
    store byte ..Found at Jump3:(%-1)
  end repeat    

_________________
smaller is better
Post 23 Sep 2021, 16:50
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.