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

Just starting out? Need help? Post your questions and find answers here.
PeterBotes
User
User
Posts: 63
Joined: Tue Nov 15, 2011 2:12 pm

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

Post 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
marc_256
Addict
Addict
Posts: 835
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

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

Post 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
Last edited by marc_256 on Fri Jan 06, 2012 12:32 pm, edited 2 times in total.
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

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

Post 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()
Last edited by Pupil on Fri Jan 06, 2012 4:03 pm, edited 2 times in total.
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

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

Post 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.
PeterBotes
User
User
Posts: 63
Joined: Tue Nov 15, 2011 2:12 pm

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

Post 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
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

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

Post 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()
PeterBotes
User
User
Posts: 63
Joined: Tue Nov 15, 2011 2:12 pm

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

Post by PeterBotes »

Doh, I told you a guru would spot it lol

thanks everyone
Post Reply