pspdev/sdk "sio" sample from 1.50 kernel to 3.xx k

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

Moderators: cheriff, TyRaNiD

J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

There are threads on the audio codecs. You'd best read them. snprintf is part of newlib. Don't use either of the libc specifiers and it will use newlib automatically.
quadrizo
Posts: 21
Joined: Thu Aug 23, 2007 10:21 pm

Post by quadrizo »

yes i've read them, and thanks to them! i have an atrac player on 1.50 which
works well but i hope to have a compatibility with 3.xx kernel ...

maybe could i have an answer to load a module from flash without linkink issues :
i don't use snprintf direcly : it's a call in the fonction startModukeswithargs
ldqmoon
Posts: 13
Joined: Tue Dec 04, 2007 1:17 am

Post by ldqmoon »

it seems a little late to reply this post :(
but I have met a problem of bright set program of sakya.

with this code

Code: Select all

 pspDebugScreenPrintf("Brightness level %i\n", getBrightness()); 
I always get "Brightness level 0 ", it seems the function getBrightness didn't take effect. I don't know why....

I'm using psp2000 with 3.71m33-4.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

ldqmoon wrote:it seems a little late to reply this post :(
but I have met a problem of bright set program of sakya.

with this code

Code: Select all

 pspDebugScreenPrintf("Brightness level %i\n", getBrightness()); 
I always get "Brightness level 0 ", it seems the function getBrightness didn't take effect. I don't know why....

I'm using psp2000 with 3.71m33-4.
It probably uses a kernel NID that changed for 3.71. To keep working with 3.71, you probably need to find the new NID. The other option is to move on to 3.80+ and rely on the NID resolver.
ldqmoon
Posts: 13
Joined: Tue Dec 04, 2007 1:17 am

Post by ldqmoon »

Hi J.F
thanks for your reply so quick.

you mean I need to find out a NID which can used for 3.71?

For I don't know much about NID, I don't know how to use it. When I got the NID, need i change the .s file which generated by psp-build-exports?
just like the red character in the follow code?

STUB_START "myLib",0x40090000,0x00020005
STUB_FUNC 0x19F94895,getBrightness
STUB_FUNC 0xB6551455,setBrightness
STUB_END




or do something else?
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

No, the sce functions those functions call. For example, in my MediaEngine.prx, I check the fw version and call either sceSysregMeResetEnable or sceSysregMeResetEnable371, where sceSysregMeResetEnable is the "normal" sce function to enable the reset of the ME defined by the SDK. The 371 version I defined myself in a .S file that is included in the prx project and looks like

Code: Select all

	.set noreorder

#include "pspimport.s"

	IMPORT_START   "sceSysreg_driver",0x00040000
	IMPORT_FUNC    "sceSysreg_driver",0xA9997109,sceSysregMeResetEnable371
	IMPORT_FUNC    "sceSysreg_driver",0x76220E94,sceSysregMeResetDisable371
	IMPORT_FUNC    "sceSysreg_driver",0x3199CF1C,sceSysregMeBusClockEnable371
	IMPORT_FUNC    "sceSysreg_driver",0x07881A0B,sceSysregMeBusClockDisable371
Finding the correct 3.71 NID for the sce functions is a big pain, which is one reason why D_A started including the NID resolver in 3.80. With the NID resolver, you just use the 3.52 or earlier NID and it'll convert it to the proper 3.80+ NID.

So if you really WANT it to work for 3.71, be prepared for some tough work (or find someone to do it for you :D ). Otherwise just require folks to use the newer firmware.
ldqmoon
Posts: 13
Joined: Tue Dec 04, 2007 1:17 am

Post by ldqmoon »

It's a bad news for me :(

I found a code for NID finding.

Code: Select all

u32 libsNameToNid(const char *name)
{
    u8 digest[20];
    u32 nid;

    if(sceKernelUtilsSha1Digest((u8 *) name, strlen(name), digest) >= 0)
    {
        nid = digest&#91;0&#93; | &#40;digest&#91;1&#93; << 8&#41; | &#40;digest&#91;2&#93; << 16&#41; | &#40;digest&#91;3&#93; << 24&#41;;
        return nid;
     &#125;

      return 0;
&#125;
I have used it in 3.71 m33 to find out the NID of sceDisplayGetBrightness. call this function like this:
libsNameToNid("sceDisplayGetBrightness");

but no effect too.


Now I think I need to update FW of my psp :(
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

You can't find NIDs that way in 3.71+ as Sony started doing random numbers for the NIDs. You have to disassemble the library, then try to find similar sections of code (the idea being that whatever the function was, it won't have changed much for the newer firmware), then look for the NID referring to that section of code. Like I said, a big pain. There's a few threads here where a couple folks posted some of the 3.71 NIDs. Check if the one(s) you need are there.
AnonyDev
Posts: 1
Joined: Thu Oct 30, 2008 10:49 am

Post by AnonyDev »

Edit: Pirata helped me get it working :)
peb
Posts: 26
Joined: Mon Mar 12, 2007 10:01 pm

Post by peb »

I had tried your driver with 5.xx firmware, but it don't work, it freeze my PSP... What can do that?
Sorry for my English, I'm french.
User avatar
Gaby_64
Posts: 33
Joined: Fri Dec 19, 2008 4:04 am

Post by Gaby_64 »

Before I start trying to make the wlanscan_elf work on 5.00M33-4 on psp slim, has anyone done it yet

EDIT: these is what I got up to now:

makefile

Code: Select all

TARGET = AirCrack-PSP
OBJS =main.o netlib.o aircrack-ptw-lib.o	

#USE_PSPSDK_LIBC = 1

BUILD_PRX = 1

PSP_FW_VERSION = 500

INCDIR =
CFLAGS = -O2 -G0 -Wall

CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

LIBDIR =
LDFLAGS =
LIBS = -lpng -lz -lpspaudio -lpsppower -lpspgum -lpspgu -lpsppower -lpsprtc -lpspwlan -lpspnet -lm

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = AirCrack-PSP
PSP_EBOOT_ICON  = 
#PSP_EBOOT_ICON1 = 
#PSP_EBOOT_PIC1  = 

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak

netlib.c (the prx):

Code: Select all

#include <pspsdk.h>
#include <pspkernel.h>
#include <pspdebug.h>

PSP_MODULE_INFO&#40;"netlib", 0x1006, 1, 1&#41;;
PSP_MAIN_THREAD_ATTR&#40;0&#41;;

int sceNetConfigUpInterface&#40;const char *name&#41;;
int sceNet_lib_7BA3ED91&#40;const char *name, void *type, u32 *size, void *buf, u32 *unk&#41;;
int sceNetConfigDownInterface&#40;const char *name&#41;;

int module_start&#40;SceSize args, void *argp&#41;
&#123;
   return 0;
&#125;

int module_stop&#40;&#41;
&#123;
   return 0;
&#125;

netlib.exp:

Code: Select all

# Define the exports for the prx
PSP_BEGIN_EXPORTS

# These four lines are mandatory &#40;although you can add other functions like module_stop&#41;
# syslib is a psynonym for the single mandatory export.
PSP_EXPORT_START&#40;syslib, 0, 0x8000&#41;
PSP_EXPORT_FUNC_HASH&#40;module_start&#41;
PSP_EXPORT_VAR_HASH&#40;module_info&#41;
PSP_EXPORT_END

# Export our function
PSP_EXPORT_START&#40;netlib, 0, 0x0009&#41;
PSP_EXPORT_FUNC&#40;sceNetConfigUpInterface&#41;
PSP_EXPORT_FUNC&#40;sceNet_lib_7BA3ED91&#41;
PSP_EXPORT_FUNC&#40;sceNetConfigDownInterface&#41;
PSP_EXPORT_END

PSP_END_EXPORTS

makefile

Code: Select all

TARGET = netlib
OBJS = netlib.o

INCDIR =
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

BUILD_PRX = 1
PRX_EXPORTS = netlib.exp

USE_KERNEL_LIBC=1
USE_KERNEL_LIBS=1

LIBDIR =
LDFLAGS = -mno-crt0 -nostartfiles
LIBS = -lpspkernel -lpspdebug  -lpspsdk -lpspdisplay_driver -lpspwlan -lpspnet


PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak
User avatar
Gaby_64
Posts: 33
Joined: Fri Dec 19, 2008 4:04 am

Post by Gaby_64 »

main.c:

Code: Select all

#include <pspdisplay.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspctrl.h>
#include <psppower.h>
#include <pspwlan.h>
#include <pspnet.h>
#include <pspiofilemgr_kernel.h>
#include <pspsdk.h>
#include <pspgu.h>
#include <png.h>
#define printf pspDebugScreenPrintf
#define cls pspDebugScreenClear
SceCtrlData pad;
#include "aircrack.h"

PSP_MODULE_INFO&#40;"AirCrack-PSP", 0, 1, 0&#41;;
PSP_MAIN_THREAD_ATTR&#40;THREAD_ATTR_USER&#41;;
PSP_HEAP_SIZE_MAX&#40;&#41;;

/* Exit callback */
int exit_callback&#40;int arg1, int arg2, void *common&#41;
&#123;
	sceWlanDevDetach&#40;&#41;;
	sceNetTerm&#40;&#41;;
	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;

/* Init the scan */
int sceNetConfigUpInterface&#40;const char *name&#41;;
/* Do the scan */
int sceNet_lib_7BA3ED91&#40;const char *name, void *type, u32 *size, void *buf, u32 *unk&#41;;
/* Terminate the scan */
int sceNetConfigDownInterface&#40;const char *name&#41;;

#define InitScan sceNetConfigUpInterface
#define ScanAPs  sceNet_lib_7BA3ED91
#define TermScan sceNetConfigDownInterface

unsigned char scan_data&#91;0xA80&#93;;
char buffer&#91;55&#93;;

/* Returned data */
struct ScanData
&#123;
	struct ScanHead *pNext; 
	unsigned char bssid&#91;6&#93;; 
	char channel; 
	unsigned char namesize; 
	char name&#91;32&#93;; 
	unsigned int bsstype; 
	unsigned int beaconperiod; 
	unsigned int dtimperiod; 
	unsigned int timestamp; 
	unsigned int localtime; 
	unsigned short atim; 
	unsigned short capabilities; 
	unsigned char  rate&#91;8&#93;; 
	unsigned short rssi; 
	unsigned char  sizepad&#91;6&#93;; 
&#125; __attribute__&#40;&#40;packed&#41;&#41;;

/* Capability flags */
const char *caps&#91;8&#93; = &#123;
	"ESS, ",
	"IBSS, ",
	"CF Pollable, ",
	"CF Pollreq,  ",
	"Privacy &#40;WEP&#41;, ",
	"Short Preamble, ",
	"PBCC, ",
	"Channel Agility, "
&#125;;

/* Print the scan summary data to stdout */
void print_apsum&#40;struct ScanData *pData&#41;
&#123;
	char name&#91;33&#93;;
	strncpy&#40;name, pData->name, 32&#41;;
	name&#91;32&#93; = 0;

	printf&#40;"SSID&#58; %s",name&#41;;
	if &#40;pData->capabilities == 0&#41; &#123;
		printf&#40;"SECURITY&#58; NONE"&#41;;
	&#125; 
	else if &#40;pData->capabilities == 1&#41; &#123;
        printf&#40;"SECURITY&#58; WEP"&#41;;
	&#125;
	else if &#40;pData->capabilities == 2&#41; &#123;
        printf&#40;"SECURITY&#58; WPA1"&#41;;
	&#125;
	else if &#40;pData->capabilities == 3&#41; &#123;
        printf&#40;"SECURITY&#58; WPA2"&#41;;
	&#125;
	printf&#40;"    SIG&#58; %d%%", pData->rssi&#41;;
	printf&#40;"/n"&#41;;
&#125;

struct ScanData *do_scan&#40;int *count&#41;&#123;

	unsigned char type&#91;0x4C&#93;;
	u32 size, unk;
	int i;
	int ret;

	if&#40;&#40;ret = InitScan&#40;"wlan"&#41;&#41; >= 0&#41; &#123;
		memset&#40;type, 0, sizeof&#40;type&#41;&#41;;
		/* Set the channels we want to scan */
		for&#40;i = 1; i < 0xF; i++&#41; &#123;
			type&#91;0x9+i&#93; = i;
		&#125;
		type&#91;0x3C&#93; = 1;
		*&#40;&#40;u32*&#41; &#40;type + 0x44&#41;&#41; = 1;    //6/* Minimum strength */
		*&#40;&#40;u32*&#41; &#40;type + 0x48&#41;&#41; = 100;  /* Maximum strength */
		size = sizeof&#40;scan_data&#41;;
		unk  = 0;
		memset&#40;scan_data, 0, sizeof&#40;scan_data&#41;&#41;;
		ret = ScanAPs&#40;"wlan", type, &size, scan_data, &unk&#41;;
		if&#40;ret < 0&#41; &#123;
			printf&#40;"Error, could not perform scan err = %08X\n", ret&#41;;
		&#125; 
		else &#123;
			*count = size / sizeof&#40;struct ScanData&#41;;
			return &#40;struct ScanData *&#41; scan_data;
		&#125;
	&#125;
	else &#123;
		printf&#40;"Error, cannot initialise scan\n"&#41;;
	&#125;
	TermScan&#40;"wlan"&#41;;
	return NULL;
&#125;


int main&#40;&#41; &#123;
	pspDebugScreenInit&#40;&#41;;
    pspDebugScreenClear&#40;&#41;;
    SetupCallbacks&#40;&#41;;

	SceUID modid = pspSdkLoadStartModule&#40;"netlib.prx", PSP_MEMORY_PARTITION_KERNEL&#41;;
	if &#40;modid < 0&#41;&#123;
		pspDebugScreenPrintf&#40;"Error 0x%08X loading/starting netlib.prx\n", modid&#41;;
        do &#123; sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
		&#125; while &#40;pad.Buttons == 0&#41;;
		sceKernelExitGame&#40;&#41;;
	&#125;

	printf&#40;"AirCrack-PSP by Gaby_64\nTest 0.43\nPress any key to start scanning\n\n"&#41;;
	do &#123; sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
	&#125; while &#40;pad.Buttons == 0&#41;;

	if&#40;pspSdkLoadInetModules&#40;&#41; < 0&#41;
	&#123;
		printf&#40;"Error, could not load inet modules\n"&#41;;
		do &#123; sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
		&#125; while &#40;pad.Buttons == 0&#41;;
		sceKernelExitGame&#40;&#41;;
	&#125;

	int ret, count, x, y, scan;
	struct ScanData *pScan = NULL;
	ret = sceNetInit&#40;0x20000, 0x20, 0x1000, 0x20, 0x1000&#41;;
	if&#40;ret < 0&#41;
	&#123;
		printf&#40;"Error initialising network lib %08X\n", ret&#41;;
		do &#123; sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
		&#125; while &#40;pad.Buttons == 0&#41;;
		sceKernelExitGame&#40;&#41;;
	&#125;
	while&#40;sceWlanGetSwitchState&#40;&#41; == 0&#41; &#123;
		printf&#40;"Please set wlan switch to on\n"&#41;;
		while&#40;sceWlanGetSwitchState&#40;&#41; == 0&#41; &#123;
		&#125;
	&#125;
	ret = -1;
	while&#40;ret < 0&#41;
	&#123;
		ret = sceWlanDevAttach&#40;&#41;;
		if&#40;ret == 0x80410D0E&#41;
		&#123;
			sceKernelDelayThread&#40;1000000&#41;;
		&#125;
		else if&#40;ret < 0&#41;
		&#123;
			printf&#40;"Error attaching to wlan device %08X\n", ret&#41;;
			do &#123; sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
			&#125; while &#40;pad.Buttons == 0&#41;;
			sceKernelExitGame&#40;&#41;;
		&#125;
	&#125;
	while&#40;scan&#41;&#123;
		sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
		pScan = do_scan&#40;&count&#41;;
		for &#40;x=0;x<count;x++&#41; &#123;
			print_apsum&#40;&pScan&#91;x&#93;&#41;;
			y = y + 30; 
		&#125;
		y = 56;
		if&#40;pad.Buttons & PSP_CTRL_CROSS&#41; &#123;
			scan = 0;
		&#125;
	&#125;

	const char Capf&#91;20&#93; = "./ptw.cap";
	FILE *CapFile = fopen&#40;Capf, "rb"&#41;;

	CheckCapFile&#40;CapFile&#41;;
	sceKernelDelayThread&#40;100000&#41;;
	ParsePackets&#40;CapFile&#41;;
	sceKernelDelayThread&#40;100000&#41;;
	RecoverWepKEY&#40;&#41;;

	sceKernelDelayThread&#40;100000&#41;;
	do &#123; sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
	&#125; while &#40;pad.Buttons == 0&#41;;
	
	sceKernelExitGame&#40;&#41;;
	return 0;
&#125;
User avatar
Gaby_64
Posts: 33
Joined: Fri Dec 19, 2008 4:04 am

Post by Gaby_64 »

Can anyone help me for the above.
I still keep getting the library not found error on psp
adrahil
Posts: 274
Joined: Thu Mar 16, 2006 1:55 am

Post by adrahil »

Your main PRX tries to import the exports of netlib, which it itself will load, so it won't even boot. There are a few ways to work around this, search around the forums.



Oh, and by the way, forget it, there is no way to capture raw packets on the PSP :) And even less possibility to inject anything.
User avatar
Gaby_64
Posts: 33
Joined: Fri Dec 19, 2008 4:04 am

Post by Gaby_64 »

I've looked around the forum but didnt find anything, can u tell me what im searching exactly for
User avatar
Gaby_64
Posts: 33
Joined: Fri Dec 19, 2008 4:04 am

Post by Gaby_64 »

Ive manged to make the scanner work
If you want to try it here: http://psp.wijou.com/forum/index.php?showtopic=815

Its part of the aircrack im working on (nothing eccept that scanner in it for now, but it does have a wep crack function but it doesnt work)
Post Reply