Page 1 of 1
Global Labes?
Posted: Thu Apr 28, 2016 6:21 pm
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...?)
Re: Global Labes?
Posted: Fri Apr 29, 2016 8:37 am
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...
Re: Global Labes?
Posted: Fri Apr 29, 2016 8:45 am
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
Re: Global Labes?
Posted: Fri Apr 29, 2016 11:32 am
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$)
Re: Global Labes?
Posted: Fri Apr 29, 2016 4:56 pm
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!
Re: Global Labes?
Posted: Fri Apr 29, 2016 6:34 pm
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$)
Re: Global Labes?
Posted: Fri Apr 29, 2016 8:20 pm
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
it works!
but im not exactly sure why

Re: Global Labes?
Posted: Fri Apr 29, 2016 9:02 pm
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.
Re: Global Labes?
Posted: Fri Apr 29, 2016 9:26 pm
by 木漏れ日
Thank you for your explanation
Now i understand why it wasnt working before
