Wrighting to flash0 | Source

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

Moderators: cheriff, TyRaNiD

Locked
pyrosama
Posts: 66
Joined: Fri May 13, 2005 1:08 pm

Wrighting to flash0 | Source

Post by pyrosama »

This is the source to a tool I put together to with the help of many others to replace files in the firmware.

So let's see an updated version of PSPersonalize....

Code: Select all

/* This is the source to a simple flash tool based on CleanSweep's alpha code by Dot_blank, Yoshi's bricker, and alot of help from ph0rkeh.
Good work guys and thanks for all the help! - Shout out to all my m8's at irc.toc2rta.com #pspchat who have helped me with my random projects. */

//
// Bricker Sample.
//


/*Standard headers*/
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/unistd.h>

/*PSPSDK headers*/
#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspiofilemgr.h>

#include <psptypes.h>
#include <pspumd.h>

/*
================================================================================
standard psp stuff
================================================================================
*/

PSP_MODULE_INFO&#40;"CleanSweep", 0x1000, 1, 1&#41;;   // 0x1000 = Kernel MODE
PSP_MAIN_THREAD_ATTR&#40;0&#41;; // 0 for kernel mode too

#define printf  pspDebugScreenPrintf

/* Define buffer size */
#define BUFSIZE      65536
char   buf&#91;BUFSIZE&#93;; 
/* Exit callback */
int exit_callback&#40;int arg1, int arg2, void *common&#41;
&#123;
	sceKernelExitGame&#40;&#41;;

	return 0;
&#125;

/* Callback thread */
int CallbackThread&#40;SceSize args, void *argp&#41;
&#123;
	int cbid;

	cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, NULL&#41;;
	sceKernelRegisterExitCallback&#40;cbid&#41;;

	sceKernelSleepThreadCB&#40;&#41;;

	return 0;
&#125;

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks&#40;void&#41;
&#123;
	int thid = 0;

	thid = sceKernelCreateThread&#40;"update_thread", CallbackThread, 0x11, 0xFA0, 0, 0&#41;;
	if&#40;thid >= 0&#41;
	&#123;
		sceKernelStartThread&#40;thid, 0, 0&#41;;
	&#125;

	return thid;
&#125;

/* Define a write buffer */
char write_buffer&#91;128*1024&#93;;



/* This code is taken from Yoshi's bricker.*/

void CopyExecute&#40;const char* zFileSrc , const char* zFileDest&#41; &#123;
   int fd1,fd2,len;
             
       //Read   
       fd1 = sceIoOpen&#40;zFileSrc, PSP_O_RDONLY, 0&#41;;
       //Write
       fd2 = sceIoOpen&#40;zFileDest,PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777&#41;; 
       
       if&#40;fd1 < 0&#41;
       &#123;
         printf&#40;"Error Message if the file is not there. \n"&#41;;
       &#125;else&#123;
                 
     while&#40;1&#41; &#123;
      len = sceIoRead&#40;fd1, buf, BUFSIZE&#41;;
      if &#40;len == 0&#41; break;
      sceIoWrite&#40;fd2,buf,len&#41;;
   &#125;
&#125;
   sceIoClose&#40;fd1&#41;;
   sceIoClose&#40;fd2&#41;;
&#125;

/* Menu */

void show_menu&#40;void&#41;
&#123;
	//basic description stuff
	printf&#40;"This is a line that will be printed on the screen when the application is launched. \n"&#41;;
	
	//inputs for user
	printf&#40;"Press Circle to replace system_plugin_bg.rco.\n"&#41;;
	
&#125;

/* main routine */
int main&#40;void&#41;
&#123;
	//assign buttons
	SceCtrlData pad;

  //basic psp startup stuff
	pspDebugScreenSetBackColor&#40;0xFFFFFFFF&#41;;
	pspDebugScreenSetTextColor&#40;0&#41;;
	pspDebugScreenInit&#40;&#41;;
	SetupCallbacks&#40;&#41;;
	sceCtrlSetSamplingCycle&#40;0&#41;;
	sceCtrlSetSamplingMode&#40;1&#41;;
/* This displays the main menu for the application */
	show_menu&#40;&#41;;

/* Assign the flash device. */
sceIoUnassign&#40;"flash0&#58;"&#41;;
sceIoAssign&#40;"flash0&#58;", "lflash0&#58;0,0", "flashfat0&#58;", 0, NULL, 0&#41;; 
/* Main Loop */
	for&#40;;;&#41;
	&#123;
		/* Watch for Circle being pressed */
		sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
		if&#40;pad.Buttons & PSP_CTRL_CIRCLE&#41;
		&#123;
		/* This is the line that deals the final blow. Be carefull I bricked my PSP with this bad boy. */
		CopyExecute&#40;"ms0&#58;/system_pluging_bg.rco","flash0&#58;/vsh/resource/system_plugin_bg.rco"&#41;; 
		/* Clear the screen after flashing is done. */
		pspDebugScreenClear&#40;&#41;;
		/* This prints a message after flashing is complete */
			printf&#40;"Congratz you have just bricked your PSP.\n"&#41;;
		&#125;


		sceDisplayWaitVblankStart&#40;&#41;;
	&#125;
	
	//lets go back to psp menu
	sceKernelExitGame&#40;&#41;;
  //just for good luck &#58;&#41;
	return 0;
&#125;
Thanks,
PyroSama aka Canti
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

If you are writing/stealing code like this, then you definitely should not be messing with your firmware.
Brunni
Posts: 186
Joined: Sat Oct 08, 2005 10:27 pm

Post by Brunni »

I am not sure I understood correctly, but it seems there are some people here who really want to kill homebrew psp development.
Sorry for my bad english
Image Oldschool library for PSP - PC version released
pyrosama
Posts: 66
Joined: Fri May 13, 2005 1:08 pm

Post by pyrosama »

I just wanted to make available a working sample. Yoshi's code doesnt compile, dot's didnt work, and with those two and some help from others we made a working sample people can use...


And this isnt here to "kill homebrew psp development" it's to help it. Granted some people may attempt some not so great applications that cause damage but it's still a tool that should be made available. If a person is stupid enough to use it then they deserve a brick as I did.


Thanks,
PyroSama
User avatar
groepaz
Posts: 305
Joined: Thu Sep 01, 2005 7:44 am
Contact:

Post by groepaz »

mmmh where did you get the source to yoshis bricker from?
pyrosama
Posts: 66
Joined: Fri May 13, 2005 1:08 pm

Post by pyrosama »

These forums.
User avatar
groepaz
Posts: 305
Joined: Thu Sep 01, 2005 7:44 am
Contact:

Post by groepaz »

??? care to give a link?
placasoft
Posts: 53
Joined: Mon Mar 28, 2005 10:53 am

Post by placasoft »

Next time use search function ;)
http://forums.ps2dev.org/viewtopic.php? ... ight=flash

EDIT :
Ok guys, the above code is veeerrrry dangerous! Because if a file does not exist, he just copy a file with 0 byte ... so here is a code with check function ;)

Code: Select all

/*Standard headers*/
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/unistd.h>

/*PSPSDK headers*/
#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspiofilemgr.h>

#include <psptypes.h>
#include <pspumd.h>

/*
================================================================================
standard psp stuff
================================================================================
*/

PSP_MODULE_INFO&#40;"CleanSweep", 0x1000, 1, 1&#41;;   // 0x1000 = Kernel MODE
PSP_MAIN_THREAD_ATTR&#40;0&#41;; // 0 for kernel mode too

#define printf  pspDebugScreenPrintf

int exist = 0;

/* Define buffer size */
#define BUFSIZE      65536
char   buf&#91;BUFSIZE&#93;;
/* Exit callback */
int exit_callback&#40;int arg1, int arg2, void *common&#41;
&#123;
   sceKernelExitGame&#40;&#41;;

   return 0;
&#125;

/* Callback thread */
int CallbackThread&#40;SceSize args, void *argp&#41;
&#123;
   int cbid;

   cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, NULL&#41;;
   sceKernelRegisterExitCallback&#40;cbid&#41;;

   sceKernelSleepThreadCB&#40;&#41;;

   return 0;
&#125;

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks&#40;void&#41;
&#123;
   int thid = 0;

   thid = sceKernelCreateThread&#40;"update_thread", CallbackThread, 0x11, 0xFA0, 0, 0&#41;;
   if&#40;thid >= 0&#41;
   &#123;
      sceKernelStartThread&#40;thid, 0, 0&#41;;
   &#125;

   return thid;
&#125;

/* Define a write buffer */
char write_buffer&#91;128*1024&#93;;


// Checkfunction, too look if a file exist!


void check&#40;const char* zFile&#41; 
&#123;
   int fd3;
       fd3 = sceIoOpen&#40;zFile, PSP_O_RDONLY, 0&#41;;
       if&#40;fd3 < 0&#41;
       	&#123;
				exist = 0;
				&#125;else&#123;
				exist = 1;
				&#125;
  sceIoClose&#40;fd3&#41;;
&#125;


/* This code is taken from Yoshi's bricker + Placa check code ;&#41;*/

void CopyExecute&#40;const char* zFileSrc , const char* zFileDest&#41; &#123;
   check&#40;zFileSrc&#41;;
   if &#40;exist == 1&#41;&#123;
   int fd1,fd2,len;
             
       //Read   
       fd1 = sceIoOpen&#40;zFileSrc, PSP_O_RDONLY, 0&#41;;
       //Write
       fd2 = sceIoOpen&#40;zFileDest,PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777&#41;;
       
       if&#40;fd1 < 0&#41;
       &#123;
         printf&#40;"Error Message if the file is not there. \n"&#41;;
       &#125;else&#123;
                 
     while&#40;1&#41; &#123;
      len = sceIoRead&#40;fd1, buf, BUFSIZE&#41;;
      if &#40;len == 0&#41; break;
      sceIoWrite&#40;fd2,buf,len&#41;;
   &#125;
&#125;
   sceIoClose&#40;fd1&#41;;
   sceIoClose&#40;fd2&#41;;
  &#125;else&#123;
  printf&#40;"%s does not exist\n", zFileSrc&#41;;
	&#125;
&#125;

/* Menu */

void show_menu&#40;void&#41;
&#123;
   //basic description stuff
   printf&#40;"This is a line that will be printed on the screen when the application is launched. \n"&#41;;
   
   //inputs for user
   printf&#40;"Press Circle to replace system_plugin_bg.rco.\n"&#41;;
   
&#125;

/* main routine */
int main&#40;void&#41;
&#123;
   //assign buttons
   SceCtrlData pad;

  //basic psp startup stuff
   pspDebugScreenSetBackColor&#40;0xFFFFFFFF&#41;;
   pspDebugScreenSetTextColor&#40;0&#41;;
   pspDebugScreenInit&#40;&#41;;
   SetupCallbacks&#40;&#41;;
   sceCtrlSetSamplingCycle&#40;0&#41;;
   sceCtrlSetSamplingMode&#40;1&#41;;
/* This displays the main menu for the application */
   show_menu&#40;&#41;;

/* Assign the flash device. */
sceIoUnassign&#40;"flash0&#58;"&#41;;
sceIoAssign&#40;"flash0&#58;", "lflash0&#58;0,0", "flashfat0&#58;", 0, NULL, 0&#41;;
/* Main Loop */
   for&#40;;;&#41;
   &#123;
      /* Watch for Circle being pressed */
      sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
      if&#40;pad.Buttons & PSP_CTRL_CIRCLE&#41;
      &#123;
      /* This is the line that deals the final blow. Be carefull I bricked my PSP with this bad boy. */
      CopyExecute&#40;"ms0&#58;/system_pluging_bg.rco","flash0&#58;/vsh/resource/system_plugin_bg.rco"&#41;;
      /* Clear the screen after flashing is done. */
      pspDebugScreenClear&#40;&#41;;
      /* This prints a message after flashing is complete */
         printf&#40;"Congratz you have just bricked your PSP.\n"&#41;;
      &#125;


      sceDisplayWaitVblankStart&#40;&#41;;
   &#125;
   
   //lets go back to psp menu
   sceKernelExitGame&#40;&#41;;
  //just for good luck &#58;&#41;
   return 0;
&#125; 
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

i HIGHLY do not recommend
anyone to attempt any of these
sample code snippets...they are
guaranteed psp brick ...if that is what
you want then have a blast ;)

but dont start crying if not and
dont say you havent been warned
10011011 00101010 11010111 10001001 10111010
Art
Posts: 642
Joined: Wed Nov 09, 2005 8:01 am

Post by Art »

There is an error in both samples:
CopyExecute("ms0:/system_pluging_bg.rco","flash0:/vsh/resource/system_plugin_bg.rco");

"system_pluging.rco"?
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

well you really shouldnt follow these verbatim
the correct path is indeed flash0:/vsh/resource/system_plugin_bg.rco
but you shouldnt have to mess with that file
in fact DO NOT mess around with that file
its basically useless and only affects the wavy lines
in xmb menu of psp
10011011 00101010 11010111 10001001 10111010
Art
Posts: 642
Joined: Wed Nov 09, 2005 8:01 am

Post by Art »

I was pointing out the spelling of 'plugin', not the file path.
The error would result in a definite brick with the first example without checking because the file spelled 'pluging'would not be found.

That whole first example should be edited out of this forum, it is a VIRUS.

I am messing with other flash0 files using similar example code.
I know the risks, have bricked two PSPs.
User avatar
groepaz
Posts: 305
Joined: Thu Sep 01, 2005 7:44 am
Contact:

Post by groepaz »

a virus??? LOL
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

it is not a virus ...no such things exist for a psp
and dont let anyone tell you otherwise

what you see above is highly incorrect code in C
shoot its not even code at all :P...its like when kids
have paint ...they have blue and red and yellow
and then they just mix around with their hands ..making a mess
and yes that typo would result in a brick ...which
is why mostly anyone will tell you to not look at
this thread any longer ;)
10011011 00101010 11010111 10001001 10111010
Art
Posts: 642
Joined: Wed Nov 09, 2005 8:01 am

Post by Art »

Ok, I guess you got me.
There's no way for any PSP program to perpetuate itself.

Do you have an example of a text (debug or graphics) menu that
you'd share with a C beginner? or a link to find one that can easily be
seperated from the rest of it's program?
Cheers, Art.
Art
Posts: 642
Joined: Wed Nov 09, 2005 8:01 am

Post by Art »

I read correctly if the third poster said that the second poster wants to kill homebrew development.

There is some homebrew that has been shoved to my attention that uses
the first example, and one of them is a real screamer.

It seems this piece of work does find a way to perpetuate itself :p
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

you are the one who perpetuated it :P
this thread should not have been revived
frankly it should be locked already as
theres no more knowledge to gain from just
talking ...flash access is very common thing
these days now
10011011 00101010 11010111 10001001 10111010
Locked