├── .gitignore ├── CMakeLists.txt ├── README.md ├── libdebugnet ├── CMakeLists.txt ├── Makefile ├── include │ └── debugnet.h └── source │ └── debugnet.c └── sample ├── CMakeLists.txt ├── Makefile └── main.c /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.elf 3 | *.velf 4 | *.o 5 | *.a 6 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | if(NOT DEFINED CMAKE_TOOLCHAIN_FILE) 4 | if(DEFINED ENV{VITASDK}) 5 | set(CMAKE_TOOLCHAIN_FILE "$ENV{VITASDK}/share/vita.toolchain.cmake" CACHE PATH "toolchain file") 6 | else() 7 | message(FATAL_ERROR "Please define VITASDK to point to your SDK path!") 8 | endif() 9 | endif() 10 | 11 | project(debugnet) 12 | add_subdirectory(libdebugnet) 13 | add_subdirectory(sample) 14 | 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | DEBUGNET FOR VITA 2 | ================= 3 | 4 | What does this do? 5 | =================== 6 | 7 | debugnet is a vita small library to debug your homebrew code over udp. It is the same method that i use to debug PlayStation 3 code, so i can use the same host tools for PlayStation Vita and PlayStation 3 to do it. 8 | 9 | How do I use it? 10 | ================== 11 | 12 | 1) Compile and install library and include file 13 | 14 | 15 | ``` 16 | cd libdebugnet 17 | make 18 | make install 19 | ``` 20 | 21 | or 22 | 23 | ``` 24 | mkdir build 25 | cd build 26 | cmake .. 27 | make 28 | make install 29 | ``` 30 | 31 | 2) Compile sample 32 | 33 | 34 | ``` 35 | cd sample 36 | edit main.c and change your server ip and port to listen udp messages from PlayStation Vita 37 | make 38 | ``` 39 | 40 | 3) Open a terminal and execute (change port if you don't use 18194). It can be in osx, linux or if you have socat like tool on windows 41 | 42 | ``` 43 | socat udp-recv:18194 stdout 44 | ``` 45 | 46 | 4) Install debugnetsample.vpk in your vita an run it 47 | 48 | You will see in socat terminal window output from your PlayStation Vita: 49 | 50 | ``` 51 | debugnet initialized 52 | Copyright (C) 2010,2015 Antonio Jose Ramos Marquez aka bigboss @psxdev 53 | This Program is subject to the terms of the Mozilla Public 54 | License, v. 2.0. If a copy of the MPL was not distributed with this 55 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 56 | ready to have a lot of fun... 57 | [VITA][DEBUG]: Test debug level 1 58 | [VITA][ERROR]: Test error level 1 59 | [VITA][INFO]: Test info level 1 60 | ``` 61 | 62 | 5) ready to have a lot of fun :P and switch done to henkaku and vitasdk 63 | 64 | 65 | Change log 66 | =========================== 67 | - 24/03/2017 Cmake added by devnoname120 68 | - 04/09/2016 Update to support henkaku and last vitasdk 69 | - 21/01/2016 Update to support last vitasdk 70 | 71 | 72 | Credits 73 | =========================== 74 | 75 | Special thanks goes to: 76 | 77 | - team molecule for bring henkaku to make life easier for homebrew developer 78 | - All people who collaborated in #PSP2SDK: @173210, @xerpi(i stole you network initialization code :P from FTPVita), @frangar , @frtomtomdu80, @hykemthedemon , @SMOKE587, @Josh_Axey ... 79 | - All ps3dev and ps2dev old comrades 80 | - xyzz for help with vita toolchain 81 | 82 | -------------------------------------------------------------------------------- /libdebugnet/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | if(NOT DEFINED CMAKE_TOOLCHAIN_FILE) 4 | if(DEFINED ENV{VITASDK}) 5 | set(CMAKE_TOOLCHAIN_FILE "$ENV{VITASDK}/share/vita.toolchain.cmake" CACHE PATH "toolchain file") 6 | else() 7 | message(FATAL_ERROR "Please define VITASDK to point to your SDK path!") 8 | endif() 9 | endif() 10 | 11 | project(debugnet) 12 | include("${VITASDK}/share/vita.cmake" REQUIRED) 13 | 14 | set(SRC_FILES 15 | source/debugnet.c) 16 | set(INC_FILES 17 | include) 18 | 19 | set(CFLAGS -Wl,-q -Wall -O3) 20 | 21 | add_library(${PROJECT_NAME} STATIC ${SRC_FILES}) 22 | target_include_directories(${PROJECT_NAME} PRIVATE ${INC_FILES}) 23 | target_compile_options(${PROJECT_NAME} PRIVATE ${CFLAGS}) 24 | 25 | install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) 26 | install(FILES include/debugnet.h DESTINATION include) 27 | 28 | -------------------------------------------------------------------------------- /libdebugnet/Makefile: -------------------------------------------------------------------------------- 1 | TARGET_LIB = libdebugnet.a 2 | OBJS = source/debugnet.o 3 | INCLUDES = include 4 | PREFIX = arm-vita-eabi 5 | CC = $(PREFIX)-gcc 6 | AR = $(PREFIX)-ar 7 | CFLAGS = -Wl,-q -Wall -O3 -I$(INCLUDES) 8 | ASFLAGS = $(CFLAGS) 9 | 10 | all: $(TARGET_LIB) 11 | 12 | 13 | $(TARGET_LIB): $(OBJS) 14 | $(AR) -rc $@ $^ 15 | 16 | clean: 17 | @rm -rf $(TARGET_LIB) $(OBJS) 18 | 19 | install: $(TARGET_LIB) 20 | @cp $(TARGET_LIB) $(VITASDK)/arm-vita-eabi/lib 21 | @cp include/debugnet.h $(VITASDK)/arm-vita-eabi/include 22 | @echo "Installed!" 23 | -------------------------------------------------------------------------------- /libdebugnet/include/debugnet.h: -------------------------------------------------------------------------------- 1 | /* 2 | * debugnet library for PSP2 3 | * Copyright (C) 2010,2015 Antonio Jose Ramos Marquez (aka bigboss) @psxdev on twitter 4 | * Repository https://github.com/psxdev/debugnet 5 | */ 6 | #ifndef _DEBUGNET_H_ 7 | #define _DEBUGNET_H_ 8 | 9 | #define NET_INIT_SIZE 1*1024*1024 10 | 11 | #define NONE 0 12 | #define INFO 1 13 | #define ERROR 2 14 | #define DEBUG 3 15 | 16 | typedef struct debugNetConfiguration 17 | { 18 | int debugnet_initialized; 19 | int SocketFD; 20 | int logLevel; 21 | 22 | } debugNetConfiguration; 23 | 24 | #ifdef __cplusplus 25 | extern "C" 26 | { 27 | #endif 28 | 29 | 30 | int debugNetInit(const char *serverIp, int port, int level); 31 | int debugNetInitWithConf(debugNetConfiguration *conf); 32 | debugNetConfiguration *debugNetGetConf(); 33 | int debugNetSetConf(debugNetConfiguration *conf); 34 | void debugNetFinish(); 35 | void debugNetUDPSend(const char *text); 36 | void debugNetUDPPrintf(const char *format, ...); 37 | void debugNetPrintf(int level, const char* format, ...); 38 | void debugNetSetLogLevel(int level); 39 | int debugNetCreateConf(); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | #endif 45 | -------------------------------------------------------------------------------- /libdebugnet/source/debugnet.c: -------------------------------------------------------------------------------- 1 | /* 2 | * debugnet library for PSP2 3 | * Copyright (C) 2010,2015 Antonio Jose Ramos Marquez (aka bigboss) @psxdev on twitter 4 | * Repository https://github.com/psxdev/debugnet 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include "debugnet.h" 17 | 18 | int debugnet_external_conf=0; 19 | debugNetConfiguration *dconfig=NULL; 20 | static void *net_memory = NULL; 21 | static SceNetInAddr vita_addr; 22 | struct SceNetSockaddrIn stSockAddr; 23 | 24 | 25 | /** 26 | * UDP printf for debugnet library, 27 | * use debugNetPrintf() instead unless necessary 28 | * 29 | * @par Example: 30 | * @code 31 | * debugNetUDPPrintf("This is a %s test\n", "real"); 32 | * @endcode 33 | */ 34 | void debugNetUDPPrintf(const char* fmt, ...) 35 | { 36 | char buffer[0x800]; 37 | va_list arg; 38 | va_start(arg, fmt); 39 | sceClibVsnprintf(buffer, sizeof(buffer), fmt, arg); 40 | va_end(arg); 41 | 42 | debugNetUDPSend(buffer); 43 | } 44 | 45 | /** 46 | * UDP Raw text send for debugnet library, 47 | * use debugNetPrintf() instead unless necessary 48 | * 49 | * @par Example: 50 | * @code 51 | * debugNetUDPSend("This is a test\n"); 52 | * @endcode 53 | * 54 | * @param text - NULL-terminated buffer containing the raw text to send 55 | */ 56 | void debugNetUDPSend(const char *text) 57 | { 58 | sceNetSend(dconfig->SocketFD, text, strlen(text), 0); 59 | } 60 | 61 | /** 62 | * Log Level printf for debugnet library 63 | * 64 | * @par Example: 65 | * @code 66 | * debugNetPrintf(INFO,"This is a %s test\n", "real"); 67 | * @endcode 68 | * 69 | * @param level - NONE,INFO,ERROR or DEBUG 70 | */ 71 | void debugNetPrintf(int level, const char* format, ...) 72 | { 73 | char msgbuf[0x800]; 74 | va_list args; 75 | 76 | if (level>dconfig->logLevel) 77 | return; 78 | 79 | va_start(args, format); 80 | 81 | sceClibVsnprintf(msgbuf,2048, format, args); 82 | msgbuf[2047] = 0; 83 | va_end(args); 84 | if(level>dconfig->logLevel) 85 | { 86 | level=NONE; 87 | } 88 | switch(level) 89 | { 90 | case INFO: 91 | debugNetUDPPrintf("[VITA][INFO]: %s",msgbuf); 92 | break; 93 | case ERROR: 94 | debugNetUDPPrintf("[VITA][ERROR]: %s",msgbuf); 95 | break; 96 | case DEBUG: 97 | debugNetUDPPrintf("[VITA][DEBUG]: %s",msgbuf); 98 | break; 99 | case NONE: 100 | break; 101 | default: 102 | debugNetUDPPrintf("%s",msgbuf); 103 | 104 | } 105 | } 106 | /** 107 | * Set log level for debugnet library 108 | * 109 | * @par Example: 110 | * @code 111 | * debugNetSetLogLevel(DEBUG); 112 | * @endcode 113 | * @param level - DEBUG,ERROR,INFO or NONE 114 | */ 115 | void debugNetSetLogLevel(int level) 116 | { 117 | if(dconfig) 118 | { 119 | dconfig->logLevel=level; 120 | } 121 | } 122 | /** 123 | * Init debugnet library 124 | * 125 | * @par Example: 126 | * @code 127 | * #define LOGLEVEL 3 128 | * int ret; 129 | * ret = debugNetInit("172.26.0.2", 18194, DEBUG); 130 | * @endcode 131 | * 132 | * @param serverIP - your pc/mac server ip 133 | * @param port - udp port server 134 | * @param level - DEBUG,ERROR,INFO or NONE 135 | */ 136 | int debugNetInit(const char *serverIp, int port, int level) 137 | { 138 | int ret=0; 139 | SceNetInitParam initparam; 140 | SceNetCtlInfo info; 141 | 142 | if(debugNetCreateConf()) 143 | { 144 | return dconfig->debugnet_initialized; 145 | } 146 | 147 | debugNetSetLogLevel(level); 148 | 149 | 150 | if (sceSysmoduleIsLoaded(SCE_SYSMODULE_NET) != SCE_SYSMODULE_LOADED) 151 | ret=sceSysmoduleLoadModule(SCE_SYSMODULE_NET); 152 | 153 | if (ret >=0) { 154 | 155 | 156 | /*net initialazation code from xerpi at https://github.com/xerpi/FTPVita/blob/master/ftp.c*/ 157 | /* Init Net */ 158 | if (sceNetShowNetstat() == SCE_NET_ERROR_ENOTINIT) { 159 | net_memory = malloc(NET_INIT_SIZE); 160 | 161 | initparam.memory = net_memory; 162 | initparam.size = NET_INIT_SIZE; 163 | initparam.flags = 0; 164 | 165 | ret = sceNetInit(&initparam); 166 | //printf("sceNetInit(): 0x%08X\n", ret); 167 | } else { 168 | //printf("Net is already initialized.\n"); 169 | } 170 | 171 | /* Init NetCtl */ 172 | ret = sceNetCtlInit(); 173 | //printf("sceNetCtlInit(): 0x%08X\n", ret); 174 | 175 | 176 | /* Get IP address */ 177 | ret = sceNetCtlInetGetInfo(SCE_NETCTL_INFO_GET_IP_ADDRESS, &info); 178 | //printf("sceNetCtlInetGetInfo(): 0x%08X\n", ret); 179 | 180 | 181 | /* Save the IP of PSVita to a global variable */ 182 | sceNetInetPton(SCE_NET_AF_INET, info.ip_address, &vita_addr); 183 | 184 | /* Create datagram udp socket*/ 185 | dconfig->SocketFD = sceNetSocket("debugnet_socket", 186 | SCE_NET_AF_INET , SCE_NET_SOCK_DGRAM, SCE_NET_IPPROTO_UDP); 187 | 188 | memset(&stSockAddr, 0, sizeof stSockAddr); 189 | 190 | 191 | /*Populate SceNetSockaddrIn structure values*/ 192 | stSockAddr.sin_family = SCE_NET_AF_INET; 193 | stSockAddr.sin_port = sceNetHtons(port); 194 | sceNetInetPton(SCE_NET_AF_INET, serverIp, &stSockAddr.sin_addr); 195 | 196 | /*Connect socket to server*/ 197 | sceNetConnect(dconfig->SocketFD, (struct SceNetSockaddr *)&stSockAddr, sizeof stSockAddr); 198 | 199 | /*Show log on pc/mac side*/ 200 | debugNetUDPPrintf("debugnet initialized\n"); 201 | debugNetUDPPrintf("Copyright (C) 2010,2015 Antonio Jose Ramos Marquez aka bigboss @psxdev\n"); 202 | debugNetUDPPrintf("This Program is subject to the terms of the Mozilla Public\n" 203 | "License, v. 2.0. If a copy of the MPL was not distributed with this\n" 204 | "file, You can obtain one at http://mozilla.org/MPL/2.0/.\n"); 205 | debugNetUDPPrintf("ready to have a lot of fun...\n"); 206 | 207 | /*library debugnet initialized*/ 208 | dconfig->debugnet_initialized = 1; 209 | } 210 | 211 | return dconfig->debugnet_initialized; 212 | } 213 | 214 | debugNetConfiguration *debugNetGetConf() 215 | { 216 | if(dconfig) 217 | { 218 | return dconfig; 219 | } 220 | 221 | return NULL; 222 | } 223 | int debugNetSetConf(debugNetConfiguration *conf) 224 | { 225 | if(conf) 226 | { 227 | dconfig=conf; 228 | debugnet_external_conf=1; 229 | return dconfig->debugnet_initialized; 230 | } 231 | 232 | return 0; 233 | } 234 | int debugNetInitWithConf(debugNetConfiguration *conf) 235 | { 236 | int ret; 237 | ret=debugNetSetConf(conf); 238 | if(ret) 239 | { 240 | debugNetPrintf(INFO,"debugnet already initialized using configuration from psp2link\n"); 241 | debugNetPrintf(INFO,"debugnet_initialized=%d SocketFD=%d logLevel=%d\n",dconfig->debugnet_initialized,dconfig->SocketFD,dconfig->logLevel); 242 | debugNetPrintf(INFO,"ready to have a lot of fun...\n"); 243 | return dconfig->debugnet_initialized; 244 | } 245 | else 246 | { 247 | return 0; 248 | } 249 | 250 | } 251 | int debugNetCreateConf() 252 | { 253 | if(!dconfig) 254 | { 255 | dconfig=malloc(sizeof(debugNetConfiguration)); 256 | dconfig->debugnet_initialized=0; 257 | dconfig->SocketFD = -1; 258 | dconfig->logLevel=INFO; 259 | return 0; 260 | } 261 | 262 | if(dconfig->debugnet_initialized) 263 | { 264 | return 1; 265 | } 266 | return 0; 267 | } 268 | 269 | 270 | /** 271 | * Finish debugnet library 272 | * 273 | * @par Example: 274 | * @code 275 | * debugNetFinish(); 276 | * @endcode 277 | */ 278 | void debugNetFinish() 279 | { 280 | 281 | if(!debugnet_external_conf) 282 | { 283 | if (dconfig->debugnet_initialized) { 284 | dconfig->debugnet_initialized = 0; 285 | dconfig->SocketFD=-1; 286 | 287 | //sceNetCtlTerm(); 288 | 289 | //sceNetTerm(); 290 | 291 | //sceSysmoduleUnloadModule(SCE_SYSMODULE_NET); 292 | 293 | if (net_memory) { 294 | free(net_memory); 295 | net_memory = NULL; 296 | } 297 | } 298 | } 299 | 300 | } 301 | -------------------------------------------------------------------------------- /sample/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | if(NOT DEFINED CMAKE_TOOLCHAIN_FILE) 4 | if(DEFINED ENV{VITASDK}) 5 | set(CMAKE_TOOLCHAIN_FILE "$ENV{VITASDK}/share/vita.toolchain.cmake" CACHE PATH "toolchain file") 6 | else() 7 | message(FATAL_ERROR "Please define VITASDK to point to your SDK path!") 8 | endif() 9 | endif() 10 | 11 | project(debugnetsample) 12 | include("${VITASDK}/share/vita.cmake" REQUIRED) 13 | 14 | set(VITA_TITLEID "BIGB00001") 15 | 16 | set(CFLAGS "-Wl,-q -Wall -O3") 17 | 18 | add_executable(${PROJECT_NAME}.elf main.c) 19 | target_compile_options(${PROJECT_NAME}.elf PRIVATE ${CFLAGS}) 20 | 21 | target_link_libraries(${PROJECT_NAME}.elf 22 | c 23 | debugnet 24 | SceNetCtl_stub 25 | SceNet_stub 26 | SceSysmodule_stub 27 | ) 28 | 29 | vita_create_self(${PROJECT_NAME}.self ${PROJECT_NAME}.elf) 30 | vita_create_vpk(${PROJECT_NAME}.vpk ${VITA_TITLEID} ${PROJECT_NAME}.self 31 | NAME ${PROJECT_NAME} 32 | ) 33 | -------------------------------------------------------------------------------- /sample/Makefile: -------------------------------------------------------------------------------- 1 | TITLE_ID = BIGB00001 2 | TARGET = debugnetsample 3 | OBJS = main.o 4 | 5 | LIBS = -lc -lSceKernel_stub -ldebugnet -lSceNetCtl_stub -lSceNet_stub -lSceSysmodule_stub 6 | 7 | 8 | PREFIX = arm-vita-eabi 9 | CC = $(PREFIX)-gcc 10 | CFLAGS = -Wl,-q -Wall -O3 11 | ASFLAGS = $(CFLAGS) 12 | 13 | all: $(TARGET).vpk 14 | 15 | %.vpk: eboot.bin 16 | vita-mksfoex -s TITLE_ID=$(TITLE_ID) "$(TARGET)" param.sfo 17 | vita-pack-vpk -s param.sfo -b eboot.bin $@ 18 | 19 | eboot.bin: $(TARGET).velf 20 | vita-make-fself $< $@ 21 | 22 | %.velf: %.elf 23 | vita-elf-create $< $@ 24 | 25 | $(TARGET).elf: $(OBJS) 26 | $(CC) $(CFLAGS) $^ $(LIBS) -o $@ 27 | 28 | clean: 29 | @rm -rf $(TARGET).vpk $(TARGET).velf $(TARGET).elf $(OBJS) \ 30 | eboot.bin param.sfo 31 | 32 | vpksend: $(TARGET).vpk 33 | curl -T $(TARGET).vpk ftp://$(PSVITAIP):1337/ux0:/ 34 | @echo "Sent." 35 | 36 | send: eboot.bin 37 | curl -T eboot.bin ftp://$(PSVITAIP):1337/ux0:/app/$(TITLE_ID)/ 38 | @echo "Sent." 39 | -------------------------------------------------------------------------------- /sample/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * debugnet library sample for PSP2 3 | * Copyright (C) 2010,2015 Antonio Jose Ramos Marquez (aka bigboss) @psxdev on twitter 4 | * Repository https://github.com/psxdev/debugnet 5 | */ 6 | #include 7 | #include 8 | 9 | 10 | 11 | #define ip_server "192.168.1.3" 12 | #define port_server 18194 13 | int main() 14 | { 15 | int ret; 16 | ret=debugNetInit(ip_server,port_server,DEBUG); 17 | debugNetPrintf(DEBUG,"Test debug level %d\n",ret); 18 | debugNetPrintf(ERROR,"Test error level %d\n",ret); 19 | debugNetPrintf(INFO,"Test info level %d\n",ret); 20 | debugNetFinish(); 21 | sceKernelExitProcess(0); 22 | return 0; 23 | } --------------------------------------------------------------------------------