Get Current Application Name [Inline ASM]

Share your advanced PureBasic knowledge/code with the community.
Mr52
User
User
Posts: 12
Joined: Tue Jun 21, 2011 3:59 pm

Get Current Application Name [Inline ASM]

Post by Mr52 »

;Thanks to mjrod5 for Fasm Example
;Mr52
Procedure GetSelfName()
!MOV eax, [fs:0x30]
!MOV eax, [eax+0x0C]
!MOV eax, [eax+0x14]
!MOV ecx, [eax+0x24] ;Length
!MOV eax, [eax+0x28] ;Buffer(Unicode btw)
ProcedureReturn
EndProcedure

It returns the Application Name like in VB App.Exename :)

it doesnt return the Path
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Get Current Application Name [Inline ASM]

Post by ts-soft »

thx,
easier to use:

Code: Select all

Procedure _GetSelfName()
  !MOV eax, [fs:0x30]
  !MOV eax, [eax+0x0C]
  !MOV eax, [eax+0x14]
  !MOV ecx, [eax+0x24] ;Length
  !MOV eax, [eax+0x28] ;Buffer(Unicode btw)
  ProcedureReturn
EndProcedure

Procedure.s GetSelfName()
  ProcedureReturn PeekS(_GetSelfName(), -1, #PB_Unicode)
EndProcedure

Debug GetSelfName()
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Mr52
User
User
Posts: 12
Joined: Tue Jun 21, 2011 3:59 pm

Re: Get Current Application Name [Inline ASM]

Post by Mr52 »

whats the difference between mine and urs ?
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Get Current Application Name [Inline ASM]

Post by ts-soft »

It returns the string in the right format and not only a pointer to a unicode buffer :wink:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Get Current Application Name [Inline ASM]

Post by luis »

Am I missing something ?

Code: Select all

Debug GetFilePart(ProgramFilename())
We can do natively already.

But thanx for the asm example anyway :)
"Have you tried turning it off and on again ?"
Nituvious
Addict
Addict
Posts: 1029
Joined: Sat Jul 11, 2009 4:57 am
Location: United States

Re: Get Current Application Name [Inline ASM]

Post by Nituvious »

That's very cool. Thanks for sharing, love to see ASM code to learn from!
▓▓▓▓▓▒▒▒▒▒░░░░░
Mr52
User
User
Posts: 12
Joined: Tue Jun 21, 2011 3:59 pm

Re: Get Current Application Name [Inline ASM]

Post by Mr52 »

oh @ts-soft thanks got it :P
User avatar
ar-s
Enthusiast
Enthusiast
Posts: 344
Joined: Sat Oct 06, 2007 11:20 pm
Location: France

Re: Get Current Application Name [Inline ASM]

Post by ar-s »

Interesting code thanks.

The native PB command is still faster for me.
Is that a normal thing ?

Code: Select all

	Procedure _GetSelfName() 
    !MOV eax, [fs:0x30] 
    !MOV eax, [eax+0x0C] 
    !MOV eax, [eax+0x14] 
    !MOV ecx, [eax+0x24] ;Length 
    !MOV eax, [eax+0x28] ;Buffer(Unicode btw) 
    ProcedureReturn 
  EndProcedure 
  
  
  t=ElapsedMilliseconds()
  mot$=""
  For i = 1 To 10000
    mot$+PeekS(_GetSelfName(), -1, #PB_Unicode)
  Next i
  
  temps = ElapsedMilliseconds()-t
  MessageRequester("t","ASM : "+Str(temps))
    
  
  
  t=ElapsedMilliseconds()
  mot$=""
  For i = 1 To 10000
    mot$+GetFilePart(ProgramFilename())
  Next i
  
  temps = ElapsedMilliseconds()-t
  MessageRequester("t","PB : "+Str(temps))
~Ar-S~
My Image Hoster for PB users
My webSite (french) with PB apps : LDVMULTIMEDIA
PB - 3.x / 5.7x / 6 - W11 x64 - Ryzen 7 3700x / #Rpi4

Code: Select all

r3p347 : 7ry : un71l d0n3 = 1
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Get Current Application Name [Inline ASM]

Post by luis »

@ar-s

With your code you are timing the string concatenation routines of PB, not the execution time of the two functions :D

When you do benchmarks, you must pay attention to any possible overhead you are introducing with your test code.
In your case it's all overhead. Change the mot$+ with mot$= to confirm that.

Anyway, how many times do you have to ask for that kind of info in your program ? Probably one.

So one millisecond or 100 milliseconds I would say it's not much important.
"Have you tried turning it off and on again ?"
User avatar
em_uk
Enthusiast
Enthusiast
Posts: 366
Joined: Sun Aug 08, 2010 3:32 pm
Location: Manchester UK

Re: Get Current Application Name [Inline ASM]

Post by em_uk »

Code: Select all

Procedure _GetSelfName()
  !MOV eax, [fs:0x30]
  !MOV eax, [eax+0x0C]
  !MOV eax, [eax+0x14]
  !MOV ecx, [eax+0x24] ;Length
  !MOV eax, [eax+0x28] ;Buffer(Unicode btw)
  ProcedureReturn
EndProcedure


t=ElapsedMilliseconds()
mot$=""
For i = 1 To 10000
  mot$=PeekS(_GetSelfName(), -1, #PB_Unicode)
Next i

Debug mot$

temps = ElapsedMilliseconds()-t
MessageRequester("t","ASM : "+Str(temps))



t=ElapsedMilliseconds()
mot$=""
For i = 1 To 10000
  mot$=GetFilePart(ProgramFilename())
Next i

Debug mot$

temps = ElapsedMilliseconds()-t
MessageRequester("t","PB : "+Str(temps))
Completes instantly on my machine. Both results 0.
----

R Tape loading error, 0:1
Post Reply