Global Labes?

Just starting out? Need help? Post your questions and find answers here.
木漏れ日
New User
New User
Posts: 6
Joined: Sun Apr 24, 2016 2:07 pm

Global Labes?

Post by 木漏れ日 »

This is really great: (PB 4.51)

Code: Select all

Procedure toki()
  Code_Start:
  !mov rax,98764
  !mov ecx,eax
  Code_End:
  !testl:
EndProcedure

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; EXAMPLE 1

try.i
!mov rcx,testl;<-------WORKS
!mov [v_try],rcx
Debug try  

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; EXAMPLE 2

  Text$ = "Disassemblierter Code: " + Chr(13)  
  If ExamineAssembly(?Code_Start, ?Code_End);<-------WORKS
    While NextInstruction()
      Text$ + RSet(Hex(InstructionAddress()), SizeOf(Integer)*2, "0")
      Text$ + " " + InstructionString() + Chr(13)
    Wend
  EndIf
  
  MessageRequester("Ergebnis", Text$)
How could i do this in PB 5.4 ?
(Is there a way to get global labels...?)
Last edited by 木漏れ日 on Fri Apr 29, 2016 4:58 pm, edited 1 time in total.
infratec
Always Here
Always Here
Posts: 7604
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Global Labes?

Post by infratec »

Hi,

according to the help:
Lables in procedures are only available inside of the procedure.
You need a trick.
I'll test something...
infratec
Always Here
Always Here
Posts: 7604
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Global Labes?

Post by infratec »

Hi,

the following works, but...
you have to call your procedure before you can disassemble it.

Code: Select all

Global *T1, *T2


Procedure toki()
  Code_Start:
  !mov rax,98764
  !mov ecx,eax
  Code_End:
  !testl:
  
  *T1 = ?Code_Start
  *T2 = ?Code_End
  
  Debug *T1
  Debug *T2
  
EndProcedure

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; EXAMPLE 1

; try.i
; !mov rcx,testl;<-------WORKS
; !mov [v_try],rcx
; Debug try 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; EXAMPLE 2


toki()

Text$ = "Disassemblierter Code: " + #CR$
;If ExamineAssembly(?Code_Start, ?Code_End);<-------WORKS
If ExamineAssembly(*T1, *T2)
  Debug 1
  While NextInstruction()
    Debug 2
    Text$ + RSet(Hex(InstructionAddress()), SizeOf(Integer)*2, "0")
    Text$ + " " + InstructionString() + #CR$
  Wend
EndIf

MessageRequester("Ergebnis", Text$)
Or something like that:

Code: Select all

ExamineAssembly(@toki(), @toki() + 40)
Bernd
DontTalkToMe
Enthusiast
Enthusiast
Posts: 334
Joined: Mon Feb 04, 2013 5:28 pm

Re: Global Labes?

Post by DontTalkToMe »

You could also just use asm labels, at the cost of some little work to implement one or two macros.

Code: Select all



; x86 unicode with ret as a top level variable

; x64, ascii, and ret as a local variable must be implemented if required with some conditional compilation

!extrn _PB_ExamineAssembly2_UNICODE@8

Macro ExamineAssemblyEx(r, s, e)
EnableASM
 lea eax, [e]
 push eax
 lea eax, [s]
 push eax
 call _PB_ExamineAssembly2_UNICODE@8  
 mov r, eax
DisableASM  
EndMacro

; example

Procedure toki()
!toki_start:
  !mov eax, 1
  !mov ecx,eax
!toki_end:  
EndProcedure


Define ret

Text$ = "Disassemblierter Code: " + #CR$

*p = @toki() ; at least reference the proc once

ExamineAssemblyEx (ret, toki_start, toki_end)

If ret 
  While NextInstruction()
    Text$ + RSet(Hex(InstructionAddress()), SizeOf(Integer)*2, "0")
    Text$ + " " + InstructionString() + #CR$
  Wend
EndIf

MessageRequester("Ergebnis", Text$)

木漏れ日
New User
New User
Posts: 6
Joined: Sun Apr 24, 2016 2:07 pm

Re: Global Labes?

Post by 木漏れ日 »

infratec wrote:...

Code: Select all

Global *T1, *T2


Procedure toki()
  Code_Start:
  !mov rax,98764
  !mov ecx,eax
  Code_End:
  !testl:
  
  *T1 = ?Code_Start
  *T2 = ?Code_End
  
  Debug *T1
  Debug *T2
  
EndProcedure

...[/quote]

Thanks for the help :)
ill probably end up using something like this or signatures.
Unless there are better ways :>

[quote="DontTalkToMe"]You could also just use asm labels, at the cost of some little work to implement one or two macros.
...
[/quote]

wont work -> the same problem -> labels are not global!
DontTalkToMe
Enthusiast
Enthusiast
Posts: 334
Joined: Mon Feb 04, 2013 5:28 pm

Re: Global Labes?

Post by DontTalkToMe »

木漏れ日 wrote:
wont work -> the same problem -> labels are not global!
I don't understand: the example above works and asm labels are accessible from everywhere (from asm).

PB labels are also accessible from everywhere (from asm).

Your problem is just you are trying to access PB labels (local to procedures) through PB commands, and obviously you can't do it since they are local.

I actually like the solution above more than the one using the two global vars also because you don't need to execute the procedure to disassemble it, but it's up to you.

Can even be simplified

Code: Select all

Macro GetLabelAddress (r, l)
EnableASM
CompilerIf (#PB_Compiler_Processor = #PB_Processor_x86)
 lea eax, [l]
 mov r, eax
CompilerElse 
 lea rax, [l]
 mov r, rax  
CompilerEndIf
DisableASM 
EndMacro

; example

Procedure toki()
!toki_start:
  !mov eax, 1
  !mov ecx,eax
!toki_end: 
EndProcedure


Define s, e, *p

Text$ = "Disassemblierter Code: " + #CR$

*p = @toki() ; at least reference the proc once

GetLabelAddress (s, toki_start)
GetLabelAddress (e, toki_end)

If ExamineAssembly(s, e)
  While NextInstruction()
    Text$ + RSet(Hex(InstructionAddress()), SizeOf(Integer)*2, "0")
    Text$ + " " + InstructionString() + #CR$
  Wend
EndIf

MessageRequester("Ergebnis", Text$)

木漏れ日
New User
New User
Posts: 6
Joined: Sun Apr 24, 2016 2:07 pm

Re: Global Labes?

Post by 木漏れ日 »

DontTalkToMe wrote: Your problem is just you are trying to access PB labels (local to procedures) through PB commands, and obviously you can't do it since they are local.
I actually like the solution above more than the one using the two global vars also because you don't need to execute the procedure...
thank you :)

but now im a bit confused...

in my sample i tried it without pb commands
(hence my hastly 1st reply - sorry)

with your line

Code: Select all

*p = @toki() 
it works! :oops:

but im not exactly sure why :?:
DontTalkToMe
Enthusiast
Enthusiast
Posts: 334
Joined: Mon Feb 04, 2013 5:28 pm

Re: Global Labes?

Post by DontTalkToMe »

Because you have to execute or at least reference the procedure, else it will be dropped from the generated code.
By getting its address, I reference it and the compiler keep its body, else it's discarded.
木漏れ日
New User
New User
Posts: 6
Joined: Sun Apr 24, 2016 2:07 pm

Re: Global Labes?

Post by 木漏れ日 »

Thank you for your explanation :idea:
Now i understand why it wasnt working before :D
Post Reply