How to get own filename of running program?

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

How to get own filename of running program?

Post by Torch »

How do I get the filename of my current running program.

Suppose my module is flash0:/vsh/modules/torch.prx, then from inside torch.prx how can I detect its filename. Suppose I rename it to something.prx, it should be able to find its filename as something.prx.
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

Best you can do is assume it was passed to the process in its arguments, so with classic main functions it will be argv[0] or with the PSP native entry point it will be the first string on argp.
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

Actually I've made a replacment vshmain.prx which asks for a password with a pretty GUI, and then launches vshmain_real.prx.
I'm proud to say that I'm sure its the best password protection thingie available at present. I'll release it in 10 mins after i complete the readme.

I also wanted to protect recovery, so i recompiled it to launch recovery_real.prx instead.

I want to avoid compiling it twice and editing the path each time. So I though if I could just have a single file that i'll copy to both vshmain.prx and recovery.prx, and it'll autodetect its own name and will launch vshmain_real.prx or recovery_real.prx correspondingly.
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

Yah well the first argument should be the path to the currently running file, so just look at that.
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

TyRaNiD wrote:Yah well the first argument should be the path to the currently running file, so just look at that.
Thats the problem, it isnt. On coldboot the vshmain.prx gets 0 parameters.
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

With 0 parameters I don't know whether its recovery, or vshmain.
All future calls to vshmain have like 256-1024 character big parameters.

I'm forwarding all parameters to the real vshmain.prx so that the xmb error messages and stuff are shown.
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

Oh well you are stuffed then :P
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

Isn't there some convoluted way?
Like getting the moduleid or something of the current app, then searching through the list of loaded modules? The list of loaded modules contains the filesnames doesnt it? Or are those just the names defined by module_info?
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

I don't think the module list contains filenames, I could be wrong though, it has been a while. The PSP doesn't need them so it doesn't save them at all.

Does the recovery prx get started with a path? If so could you not just use the logic that if you have a path it is recovery else it is vshmain?
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

TyRaNiD wrote:I don't think the module list contains filenames, I could be wrong though, it has been a while. The PSP doesn't need them so it doesn't save them at all.

Does the recovery prx get started with a path? If so could you not just use the logic that if you have a path it is recovery else it is vshmain?
Silly me. I completely forgot to check if recovery was started with any parameters... Will check and see.
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

Post Reply