It is currently Sun Jan 24, 2021 8:21 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Using PureBasic to Put the Hex Into ASM Code
PostPosted: Wed Sep 05, 2012 2:17 am 
Offline
Enthusiast
Enthusiast

Joined: Fri Jul 25, 2003 11:24 pm
Posts: 532
"Put the Hex into ASM Code"? Sounds strange, but let me show you what I mean

Here is the coded section:

Procedure.l tmp()
lablel1:
mov eax, 0xffffffff
label2:
add eax,1
label3:
ProcedureReturn
label4:
EndProcedure

MessageRequester("TRIAL","EAX = "+str$(tmp))

I get the result of 0, which is what I should get. But now I want the hex code involved
I want to use a pointer to label1 and pull up each byte in sequence until I get to label2,
then go from a pointer to label2 and do the same again for each byte until I reach
label3, then again from lable3 until I reach label4.

What I am trying to do is see when and where the prefix 66h comes into play. According
to what I've read, it should not appear. Then I am going to change the instructions to
involve ax instead of eax, When i repeat the scan from label1 to label3, I expect to find
two. I've a reason for wanting to know this for sure, which is why I'm looking for a bit of
help on using label pointers.

_________________
has-been wanna-be (You may not agree with what I say, but it will make you think).


Top
 Profile  
Reply with quote  
 Post subject: Re: Using PureBasic to Put the Hex Into ASM Code
PostPosted: Wed Sep 05, 2012 2:39 am 
Offline
Addict
Addict

Joined: Fri Apr 25, 2003 11:10 pm
Posts: 1232
oldefoxx, have a look at viewtopic.php?f=13&t=51174
fasm dll comes with a demo that instantly assembles snippets of asm source giving you the machine code.


Top
 Profile  
Reply with quote  
 Post subject: Re: Using PureBasic to Put the Hex Into ASM Code
PostPosted: Wed Sep 05, 2012 6:51 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3710
Location: Netherlands
Code:
Procedure.l tmp()
label1:
!mov eax, 0xffffffff
label2:
!add eax,1
label3:
ProcedureReturn
label4:
EndProcedure

s.s = ""
*addr.Ascii = ?label2
While *addr < ?label3
  s + Hex(*addr\a) + " "
  *addr + 1
Wend

MessageRequester("Output" , s)


Top
 Profile  
Reply with quote  
 Post subject: Re: Using PureBasic to Put the Hex Into ASM Code
PostPosted: Thu Sep 06, 2012 1:33 am 
Offline
Enthusiast
Enthusiast

Joined: Fri Jul 25, 2003 11:24 pm
Posts: 532
Very nice. I had a suspicion about how it would be approached, but I was not "enough with the language"
to bring it together. I made a few small changes, to get the flavor I was looking for:

Code:
Procedure.l tmp()
    label1:
    !mov eax, 0xffffffff
    label2:
    !add eax,1
    label3:
    ProcedureReturn
    label4:
    EndProcedure

    s.s = "!mov eax, 0xffffffff ==> "
    *addr.Ascii = ?label1
    While *addr < ?label2
      s + Hex(*addr\a) + " "
      *addr + 1
    Wend
    s+Chr(13)+Chr(10)+"!add eax,1 ==> "
    While *addr< ?label3
      s+Hex(*addr\a)+" "
      *addr+1
    Wend
    s+Chr(13)+Chr(10)+"ProcedureReturn (EAX) = "+Str(tmp)
    MessageRequester("Output" , s)


But to verify that the process is going what is expected of it, I changed the value
being loaded into EAX at the start of the procedure. Now it reads like this:

Code:
    Procedure.l tmp()
    label1:
    !mov eax, 0x12345678
    label2:
    !add eax,1
    label3:
    ProcedureReturn
    label4:
    EndProcedure

    s.s = "!mov eax, 0xffffffff ==> "
    *addr.Ascii = ?label1
    While *addr < ?label2
      s + Hex(*addr\a) + " "
      *addr + 1
    Wend
    s+Chr(13)+Chr(10)+"!add eax,1 ==> "
    While *addr< ?label3
      s+Hex(*addr\a)+" "
      *addr+1
    Wend
    s+Chr(13)+Chr(10)+"ProcedureReturn (EAX) = "+Str(tmp)
    MessageRequester("Output" , s)

No matter what value is assign to EAX at the start, the ProcedureReturn is always
equal to zero (0). Any idea why that is?

_________________
has-been wanna-be (You may not agree with what I say, but it will make you think).


Top
 Profile  
Reply with quote  
 Post subject: Re: Using PureBasic to Put the Hex Into ASM Code
PostPosted: Thu Sep 06, 2012 1:48 am 
Offline
Addict
Addict
User avatar

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 3767
Location: Utah, USA
oldefoxx wrote:
No matter what value is assign to EAX at the start, the ProcedureReturn is always
equal to zero (0). Any idea why that is?

It is because you never execute the procedure to get its return value, you only reference its contents (machine code) with the labels.

You should make this small change:
Code:
;change this
s+Chr(13)+Chr(10)+"ProcedureReturn (EAX) = "+Str(tmp)

;to this
s+Chr(13)+Chr(10)+"ProcedureReturn (EAX) = "+Str(tmp())

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Using PureBasic to Put the Hex Into ASM Code
PostPosted: Thu Sep 06, 2012 2:08 am 
Offline
Enthusiast
Enthusiast

Joined: Fri Jul 25, 2003 11:24 pm
Posts: 532
Then I just learned something. tmp is not tmp(). Interesting. In some other languages,
if there is no parameters involved, the () is not required. An example that many people
might recognize where the () is required is the POS() in some of the early Basics, which
involves the current position on the line (column location). I also learned something
else, which is that while tmp is therefore undefined, it did not signal a compiler error.

_________________
has-been wanna-be (You may not agree with what I say, but it will make you think).


Top
 Profile  
Reply with quote  
 Post subject: Re: Using PureBasic to Put the Hex Into ASM Code
PostPosted: Thu Sep 06, 2012 2:19 am 
Offline
Enthusiast
Enthusiast

Joined: Fri Jul 25, 2003 11:24 pm
Posts: 532
Now this is interesting. I set the code back to 0xffffffff as I had it originally, and changed
Str() in the later part to Hex(), and got back an answere with 16 F's in it. Eight would have
been enough. Sixteen is like a quad, not a long.
Code:
    Procedure.l tmp()
    label1:
    !mov eax, 0xfffffffe
    label2:
    !add eax,1
    label3:
    ProcedureReturn
    label4:
    EndProcedure

    s.s = "!mov eax, 0xffffffff ==> "
    *addr.Ascii = ?label1
    While *addr < ?label2
      s + Hex(*addr\a) + " "
      *addr + 1
    Wend
    s+Chr(13)+Chr(10)+"!add eax,1 ==> "
    While *addr< ?label3
      s+Hex(*addr\a)+" "
      *addr+1
    Wend
    s+Chr(13)+Chr(10)+"ProcedureReturn (EAX) = "+Hex(tmp())
    MessageRequester("Output" , s)

_________________
has-been wanna-be (You may not agree with what I say, but it will make you think).


Top
 Profile  
Reply with quote  
 Post subject: Re: Using PureBasic to Put the Hex Into ASM Code
PostPosted: Thu Sep 06, 2012 6:07 am 
Offline
Addict
Addict
User avatar

Joined: Sat Apr 26, 2003 8:26 am
Posts: 2999
Location: Planet Earth
oldefoxx wrote:
Now this is interesting. I set the code back to 0xffffffff as I had it originally, and changed
Str() in the later part to Hex(), and got back an answere with 16 F's in it. Eight would have
been enough. Sixteen is like a quad, not a long.

Use Hex(tmp(),#PB_Long).

Hex() takes a quad by default, so the .l 0xffffffff (it is -1, because PB uses signed types)
is converted to .q 0xffffffffffffffff (-1 for quads).

RSet is used to fill the string on the left side, so the byte display "1" becomes "01"
and long "FF" becomes "000000FF".

Variables do not need to be defined by default. Use EnableExplicit for enabling it.

Yes, procedures are always used with (), for example the address of the procedure is: @tmp().
Without () it is a simple variable.

Code:
    EnableExplicit
   
    Procedure.l tmp()
        label1:
            !mov eax, 0xfffffffe
        label2:
            !add eax,1
        label3:
            ProcedureReturn
        label4:
    EndProcedure
   
    Procedure.s GetByteCode( *_start.Ascii, *_end.Ascii, _msg.s="" )
        While *_start < *_end
            _msg + " " + RSet( Hex( *_start\a , #PB_Byte ) , 2, "0")
            *_start + 1
        Wend
        ProcedureReturn _msg
    EndProcedure

    Define s.s

    s = GetByteCode(?label1,?label2,"!mov eax, 0xfffffffe ==>")
    s + #CRLF$
    s + GetByteCode(?label2,?label3,"!add eax,1 ==>")
    s + #CRLF$ + "ProcedureReturn (EAX) = " + RSet( Hex(tmp(),#PB_Long) , 8, "0" )
    MessageRequester("Output" , s)


Top
 Profile  
Reply with quote  
 Post subject: Re: Using PureBasic to Put the Hex Into ASM Code
PostPosted: Thu Sep 06, 2012 9:04 am 
Offline
Enthusiast
Enthusiast

Joined: Fri Jul 25, 2003 11:24 pm
Posts: 532
I appreciate your response. Stretches my understanding further. It's real late, and I
think I am done for the night. This has been a good thread to be part of.

_________________
has-been wanna-be (You may not agree with what I say, but it will make you think).


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


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

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye