Page 1 of 1

OK I give up! (nice easy one for a guru)

Posted: Fri Jan 06, 2012 12:05 pm
by PeterBotes
I have been trying to sort this all morning and getting totally head screwed!

All I want to do is get some bytes from memory, actually from an address of a procedure

Code: Select all

Procedure Test()
    EnableASM
    MOV EAX,1
    ADD EAX,2
    DisableASM
EndProcedure


  OpenConsole()
  Address.l = @Test()
  PrintN(Hex(PeekA(Address.l)))
  JustWait$ = Input()
  CloseConsole()

I want this to return B8, start of the Mov EAX,1 code, I have tried everything (well obviously not EVERYTHING lol) I think my head is now just screwed and I cannot see the wood for the trees, PLEASE HELP.

Thanks

P

Re: OK I give up! (nice easy one for a guru)

Posted: Fri Jan 06, 2012 12:24 pm
by marc_256
Hi,

For what i think is,
PrintN(Hex(PeekA(Address.l)))
You need a full address Integer 32 bits or 64 bits not Ascii is only one byte.

Code: Select all

PrintN(Hex(PeekI(Address.l)))
Also Adress.i is better for use with 32/64 bit systems


EDIT: SORRY WRONG ANSWER :oops:
Not tested !!

Marc

Re: OK I give up! (nice easy one for a guru)

Posted: Fri Jan 06, 2012 12:28 pm
by Pupil
PB adds a stub at the beginning of the procedure that handles register preservation etc. Your code is located after all this. There's an option in the compiler that outputs the generated ASM for you to modify and optionally reassemble (you should check out this option to see what's being added at the start of every procedure).
The code below should give the output that you were expecting:

Code: Select all

Procedure Test()
    EnableASM
label1:
    MOV EAX,1
    ADD EAX,2
    DisableASM
EndProcedure


  OpenConsole()
  Address.l = ?label1
  PrintN(Hex(PeekA(Address.l)))
  JustWait$ = Input()
  CloseConsole()

Re: OK I give up! (nice easy one for a guru)

Posted: Fri Jan 06, 2012 12:29 pm
by Danilo
PeterBotes wrote:All I want to do is get some bytes from memory, actually from an address of a procedure
[...]
I want this to return B8, start of the Mov EAX,1 code, I have tried everything (well obviously not EVERYTHING lol) I think my head is now just screwed and I cannot see the wood for the trees, PLEASE HELP.
There is some hidden Code for procedure startup/init, so your code is not directly @Test().

Code: Select all

Procedure Test()
  EnableASM
    Test_Code:
        MOV EAX,1
        ADD EAX,2
  DisableASM
EndProcedure


OpenConsole()
  Address.i = ?Test_Code
  PrintN(Hex(PeekA(Address)))
  JustWait$ = Input()
CloseConsole()
Too late. :)

Anyway, better use Integer .i or *pointers for addresses.

Re: OK I give up! (nice easy one for a guru)

Posted: Fri Jan 06, 2012 2:13 pm
by PeterBotes
I did try most of the suggestion so far before posting hence me going a little mad! non seem to work so far.

Code: Select all


Procedure Test()
  EnableASM
  Code:
    MOV EAX,1
    ADD EAX,2
  DisableASM
EndProcedure
  
  OpenConsole()


  Address.i = ?Code
  For i=0 To 100
    PrintN(Hex(PeekA(Address.i+i)))
    Debug Hex(PeekA(Address.i+i))
  Next
  
  Name$ = Input()
  CloseConsole()

Results from first few bytes of output

68
0
0
0
0
E8

Should be

B8
01
00
00
00
83

I Also tried "Address.i = @Code" without luck, also looked how to produce a .asm file and could not find that option!

To try to make sence of it all I have dumped a larger section of bytes and I can see each instruction but they are surrounded by extra code!

Output from dumping more bytes ?Code label

68,6,0,0,0,E8,70,FE,FF,FF,B8,1,0,0,0,68,7,0,0,0,E8,61,FE,FF,FF,83,C0,2,68,9,0,0,0,E8,54,FE,FF,FF,31,C0,52,50,E8,45,33,0,0,58,5A,C3

Which is this

Code: Select all

68 06000000   PUSH 6
E8 70FEFFFF   CALL prog1.004010E1
B8 01000000   MOV EAX,1  <<<<<<<<<<<<<<<<<<<<<<<
68 07000000   PUSH 7
E8 61FEFFFF   CALL prog1.004010E1
83C0 02       ADD EAX,2    <<<<<<<<<<<<<<<<<<<<<<<
68 09000000   PUSH 9
E8 54FEFFFF   CALL prog1.004010E1
31C0          XOR EAX,EAX
52            PUSH EDX
50            PUSH EAX
E8 45330000   CALL prog1.004045DB
58            POP EAX
5A            POP EDX
C3            RETN
What is PB doing :?

Thanks

Re: OK I give up! (nice easy one for a guru)

Posted: Fri Jan 06, 2012 2:26 pm
by Danilo
PeterBotes wrote:What is PB doing :?
PB inserts code for debug checks, for example updating line numbers
for debugging. Turn off debugger with DisableDebugger or use direct-ASM
with '!' in front of ASM code.

Code: Select all

Procedure Test()
  DisableDebugger
  EnableASM
  Code:
    MOV EAX,1
    ADD EAX,2
  CodeEnd:
  DisableASM
  EnableDebugger
EndProcedure
  
  OpenConsole()


  For i=?Code To ?CodeEnd-1
    PrintN(Hex(PeekA(i)))
    Debug Hex(PeekA(i))
  Next
  
  Name$ = Input()
  CloseConsole()
Or

Code: Select all

Procedure Test()
  Code:
    !MOV EAX,1
    !ADD EAX,2
  CodeEnd:
EndProcedure
  
  OpenConsole()


  For i=?Code To ?CodeEnd-1
    PrintN(Hex(PeekA(i)))
    Debug Hex(PeekA(i))
  Next
  
  Name$ = Input()
  CloseConsole()

Re: OK I give up! (nice easy one for a guru)

Posted: Fri Jan 06, 2012 4:22 pm
by PeterBotes
Doh, I told you a guru would spot it lol

thanks everyone