├── .clang-format ├── .gitignore ├── README.md ├── install.sh └── libPS4 ├── Makefile ├── crt0.s ├── include ├── barrier.h ├── base64.h ├── camera.h ├── cfg.h ├── debug.h ├── dump.h ├── elf.h ├── elf64.h ├── elf_common.h ├── eventflag.h ├── file.h ├── fw_defines.h ├── graphics.h ├── jit.h ├── kernel.h ├── libc.h ├── memory.h ├── module.h ├── mutex.h ├── network.h ├── pad.h ├── payload_utils.h ├── pfs.h ├── pkg.h ├── proc.h ├── ps4.h ├── pthread.h ├── registry.h ├── semaphore.h ├── strings.h ├── syscall.h ├── sysutil.h ├── types.h ├── unknown.h └── usb.h ├── linker.x └── source ├── barrier.c ├── base64.c ├── camera.c ├── cfg.c ├── debug.c ├── dump.c ├── eventflag.c ├── file.c ├── jit.c ├── kernel.c ├── libc.c ├── memory.c ├── module.c ├── network.c ├── pad.c ├── payload_utils.c ├── pfs.c ├── pkg.c ├── proc.c ├── pthread.c ├── registry.c ├── semaphore.c ├── strings.c ├── syscall.s ├── sysutil.c ├── unknown.c └── usb.c /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | # BasedOnStyle: LLVM 4 | AccessModifierOffset: -2 5 | AlignAfterOpenBracket: Align 6 | AlignConsecutiveAssignments: false 7 | AlignConsecutiveDeclarations: false 8 | AlignEscapedNewlines: Right 9 | AlignOperands: true 10 | AlignTrailingComments: true 11 | AllowAllParametersOfDeclarationOnNextLine: true 12 | AllowShortBlocksOnASingleLine: false 13 | AllowShortCaseLabelsOnASingleLine: false 14 | AllowShortFunctionsOnASingleLine: All 15 | AllowShortIfStatementsOnASingleLine: false 16 | AllowShortLoopsOnASingleLine: false 17 | AlwaysBreakAfterDefinitionReturnType: None 18 | AlwaysBreakAfterReturnType: None 19 | AlwaysBreakBeforeMultilineStrings: false 20 | AlwaysBreakTemplateDeclarations: false 21 | BinPackArguments: true 22 | BinPackParameters: true 23 | BraceWrapping: 24 | AfterClass: false 25 | AfterControlStatement: false 26 | AfterEnum: false 27 | AfterFunction: false 28 | AfterNamespace: false 29 | AfterObjCDeclaration: false 30 | AfterStruct: false 31 | AfterUnion: false 32 | AfterExternBlock: false 33 | BeforeCatch: false 34 | BeforeElse: false 35 | IndentBraces: false 36 | SplitEmptyFunction: true 37 | SplitEmptyRecord: true 38 | SplitEmptyNamespace: true 39 | BreakBeforeBinaryOperators: None 40 | BreakBeforeBraces: Attach 41 | BreakBeforeInheritanceComma: false 42 | BreakBeforeTernaryOperators: true 43 | BreakConstructorInitializersBeforeComma: false 44 | BreakConstructorInitializers: BeforeColon 45 | BreakAfterJavaFieldAnnotations: false 46 | BreakStringLiterals: true 47 | ColumnLimit: 0 48 | CommentPragmas: '^ IWYU pragma:' 49 | CompactNamespaces: false 50 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 51 | ConstructorInitializerIndentWidth: 4 52 | ContinuationIndentWidth: 4 53 | Cpp11BracedListStyle: true 54 | DerivePointerAlignment: false 55 | DisableFormat: false 56 | ExperimentalAutoDetectBinPacking: false 57 | FixNamespaceComments: true 58 | ForEachMacros: 59 | - foreach 60 | - Q_FOREACH 61 | - BOOST_FOREACH 62 | IncludeBlocks: Preserve 63 | IncludeCategories: 64 | - Regex: '^"(llvm|llvm-c|clang|clang-c)/' 65 | Priority: 2 66 | - Regex: '^(<|"(gtest|gmock|isl|json)/)' 67 | Priority: 3 68 | - Regex: '.*' 69 | Priority: 1 70 | IncludeIsMainRegex: '(Test)?$' 71 | IndentCaseLabels: false 72 | IndentPPDirectives: None 73 | IndentWidth: 2 74 | IndentWrappedFunctionNames: false 75 | JavaScriptQuotes: Leave 76 | JavaScriptWrapImports: true 77 | KeepEmptyLinesAtTheStartOfBlocks: true 78 | MacroBlockBegin: '' 79 | MacroBlockEnd: '' 80 | MaxEmptyLinesToKeep: 1 81 | NamespaceIndentation: None 82 | ObjCBlockIndentWidth: 2 83 | ObjCSpaceAfterProperty: false 84 | ObjCSpaceBeforeProtocolList: true 85 | PenaltyBreakAssignment: 2 86 | PenaltyBreakBeforeFirstCallParameter: 19 87 | PenaltyBreakComment: 300 88 | PenaltyBreakFirstLessLess: 120 89 | PenaltyBreakString: 1000 90 | PenaltyExcessCharacter: 1000000 91 | PenaltyReturnTypeOnItsOwnLine: 60 92 | PointerAlignment: Right 93 | RawStringFormats: 94 | - Delimiter: pb 95 | Language: TextProto 96 | BasedOnStyle: google 97 | ReflowComments: true 98 | SortIncludes: true 99 | SortUsingDeclarations: true 100 | SpaceAfterCStyleCast: false 101 | SpaceAfterTemplateKeyword: true 102 | SpaceBeforeAssignmentOperators: true 103 | SpaceBeforeParens: ControlStatements 104 | SpaceInEmptyParentheses: false 105 | SpacesBeforeTrailingComments: 1 106 | SpacesInAngles: false 107 | SpacesInContainerLiterals: true 108 | SpacesInCStyleCastParentheses: false 109 | SpacesInParentheses: false 110 | SpacesInSquareBrackets: false 111 | Standard: Cpp11 112 | TabWidth: 2 113 | UseTab: Never 114 | ... 115 | 116 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | libPS4/build 2 | libPS4/libPS4.a 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | PS4 Payload SDK 2 | ================= 3 | An open source SDK for writing payloads for the PlayStation 4 4 | 5 | ## Chain of Development 6 | [CTurt](https://github.com/CTurt/PS4-SDK) > [IDC](https://github.com/idc/ps4-payload-sdk) > [xvortex](https://github.com/xvortex/ps4-payload-sdk) > [stooged](https://github.com/stooged/ps4-payload-sdk) > [Scene-Collective](https://github.com/Scene-Collective/ps4-payload-sdk) 7 | 8 | ## Why? 9 | Built with existing payload in mind and to be used in the autobuild system. Hopefully this is just a stop-gap until a full featured Mira release. 10 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Install prerequisites if root 4 | if [ "$EUID" -ne 0 ]; then 5 | echo "Not root, skipping update and install" 6 | exit 7 | else 8 | apt-get update 9 | apt-get -y install binutils gcc make 10 | fi 11 | 12 | # Delete directory if it exists and make empty directory 13 | if [ "$PWD" != "/opt/ps4sdk" ]; then 14 | rm -rf /opt/ps4sdk || true 15 | mkdir -p /opt/ps4sdk 16 | fi 17 | 18 | # Build SDK 19 | cd libPS4 || (echo "Unable to enter subdirectory" && exit) 20 | make 21 | cd .. 22 | 23 | # Copy compiled SDK 24 | if [ "$PWD" != "/opt/ps4sdk" ]; then 25 | cp -r libPS4 /opt/ps4sdk 26 | cp install.sh /opt/ps4sdk/update.sh 27 | fi 28 | 29 | # Clear path from .bashrc if it's there 30 | sed -i "s/^\s*export PS4SDK=.*//gm" /etc/profile 31 | 32 | # Add to paths 33 | echo "export PS4SDK=/opt/ps4sdk" | tee -a /etc/profile 34 | export PS4SDK=/opt/ps4sdk 35 | -------------------------------------------------------------------------------- /libPS4/Makefile: -------------------------------------------------------------------------------- 1 | CC := gcc 2 | AR := ar 3 | ODIR := build 4 | SDIR := source 5 | IDIR := include 6 | CFLAGS := -I$(IDIR) -Os -std=c11 -ffunction-sections -fdata-sections -fno-builtin -nostartfiles -nostdlib -Wall -Wextra -masm=intel -march=btver2 -mtune=btver2 -m64 -mabi=sysv -mcmodel=small -fpie -fPIC 7 | CFILES := $(wildcard $(SDIR)/*.c) 8 | SFILES := $(wildcard $(SDIR)/*.s) 9 | OBJS := $(patsubst $(SDIR)/%.c, build/%.o, $(CFILES)) $(patsubst $(SDIR)/%.s, build/%.o, $(SFILES)) 10 | 11 | TARGET = libPS4.a 12 | 13 | $(TARGET): $(ODIR) $(OBJS) 14 | $(AR) rcs $@ $(OBJS) 15 | 16 | $(ODIR)/%.o: $(SDIR)/%.c 17 | $(CC) -c -o $@ $< $(CFLAGS) 18 | 19 | $(ODIR)/%.o: $(SDIR)/%.s 20 | $(CC) -c -o $@ $< $(CFLAGS) 21 | 22 | $(ODIR): 23 | @mkdir $@ 24 | 25 | .PHONY: clean 26 | 27 | clean: 28 | rm -rf $(TARGET) $(ODIR) 29 | -------------------------------------------------------------------------------- /libPS4/crt0.s: -------------------------------------------------------------------------------- 1 | .intel_syntax noprefix 2 | .text 3 | 4 | .global _start 5 | _start: 6 | jmp _main 7 | -------------------------------------------------------------------------------- /libPS4/include/barrier.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef BARRIER_H 4 | #define BARRIER_H 5 | 6 | #include "types.h" 7 | 8 | int mutexInit(const char *name, unsigned int attributes); 9 | int mutexDestroy(int mutex); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /libPS4/include/base64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Base64 encoding/decoding (RFC1341) 3 | * Copyright (c) 2005, Jouni Malinen 4 | * 5 | * This software may be distributed under the terms of the BSD license. 6 | * See README for more details. 7 | */ 8 | 9 | #pragma once 10 | 11 | #ifndef BASE64_H 12 | #define BASE64_H 13 | 14 | #include "types.h" 15 | 16 | unsigned char *base64_encode(const unsigned char *src, size_t len, size_t *out_len); 17 | unsigned char *base64_decode(const unsigned char *src, size_t len, size_t *out_len); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /libPS4/include/camera.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef CAMERA_H 4 | #define CAMERA_H 5 | 6 | #include "types.h" 7 | 8 | //from libSceCamera.sprx firmware 1.76. Other can change 9 | typedef struct SceCameraStartParameter { 10 | uint32_t size; //0x0 <- set to 0x18 before call 24 bytes it is a check hardcoded in libSceCamera.sprx 11 | uint32_t unknown1; //0x4 12 | uint32_t unknown2; //0x8 13 | void *unknown3; //0xc 14 | } SceCameraStartParameter; 15 | 16 | typedef struct SceCameraFrameData { 17 | uint32_t size; //0x0 <- set to size< 0xb1+0x158=0x209 (521) it is a check hardcoded in libSceCamera.sprx.I suppose size 520 it's the worst case to pass the check 18 | uint32_t unknown1; //0x4 19 | uint32_t unknown2[32]; //0x8 20 | void *pleft[4]; //0x88 video frame pointers for left camera 4 resolution modes 21 | void *pright[4]; //0xa8 video frame pointers for right camera 4 resolution modes 22 | uint32_t sizeleft[4]; //0xc8 video frame size for left camera 4 resolution modes 23 | uint32_t sizeright[4]; //0xd8 video frame size for right camera 4 resolution modes 24 | uint32_t statusleft; //0xe8 25 | uint32_t statusright; //0xec 26 | uint32_t unknown3[70]; //0xf0 27 | } SceCameraFrameData; 28 | 29 | typedef struct SceCameraDeviceInfo { 30 | uint32_t size; //0x0 <- set to 0x10 before call 24 bytes it is a check hardcoded in libSceCamera.sprx 31 | uint32_t revision; //0x4 <- check set to 0x1 before call 32 | uint32_t unknown1; //0x8 33 | uint32_t unknown2; //0xc 34 | } SceCameraDeviceInfo; 35 | 36 | typedef struct SceCameraConfig { 37 | uint32_t size; //0x0 <- set to 0x68 it is a check hardcoded in libSceCamera.sprx 38 | uint32_t unknown[100]; //0x4 39 | } SceCameraConfig; 40 | 41 | extern int (*sceCameraOpen)(int userid, int type, int index, void *); 42 | extern int (*sceCameraClose)(int handle); 43 | extern int (*sceCameraIsAttached)(int index); 44 | extern int (*sceCameraGetFrameData)(int handle, SceCameraFrameData *frame); 45 | extern int (*sceCameraStart)(int handle, SceCameraStartParameter *param); 46 | extern int (*sceCameraStop)(int handle); 47 | extern int (*sceCameraGetDeviceInfo)(int handle, SceCameraDeviceInfo *info); 48 | extern int (*sceCameraGetDeviceConfig)(int handle, SceCameraConfig *config); 49 | extern int (*sceCameraGetConfig)(int handle, SceCameraConfig *config); 50 | extern int (*sceCameraSetConfig)(int handle, SceCameraConfig *config); 51 | 52 | void initCamera(void); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /libPS4/include/cfg.h: -------------------------------------------------------------------------------- 1 | /* inih -- simple .ini/.cfg file parser 2 | 3 | inih is released under the New BSD license (see LICENSE.txt). Go to the project 4 | home page for more info: 5 | 6 | https://github.com/benhoyt/inih 7 | 8 | */ 9 | 10 | #pragma once 11 | 12 | #ifndef CFG_H 13 | #define CFG_H 14 | 15 | #include "libc.h" 16 | #include "types.h" 17 | 18 | /* Nonzero if cfg_handler callback should accept lineno parameter. */ 19 | #ifndef CFG_HANDLER_LINENO 20 | #define CFG_HANDLER_LINENO 0 21 | #endif 22 | 23 | /* Typedef for prototype of handler function. */ 24 | #if CFG_HANDLER_LINENO 25 | typedef int (*cfg_handler)(void *user, const char *name, const char *value, int lineno); 26 | #else 27 | typedef int (*cfg_handler)(void *user, const char *name, const char *value); 28 | #endif 29 | 30 | /* Typedef for prototype of fgets-style reader function. */ 31 | typedef char *(*cfg_reader)(char *str, int num, void *stream); 32 | 33 | /* Parse given CONF-style file. May have name=value pairs 34 | (whitespace stripped), and comments starting with ';' (semicolon). 35 | 36 | For each name=value pair parsed, call handler function with given user 37 | pointer and value (data only valid for duration 38 | of handler call). Handler should return nonzero on success, zero on error. 39 | 40 | Returns 0 on success, line number of first error on parse error (doesn't 41 | stop on first error), -1 on file open error, or -2 on memory allocation 42 | error (only when CFG_USE_STACK is zero). 43 | */ 44 | int cfg_parse(const char *filename, cfg_handler handler, void *user); 45 | 46 | /* Same as cfg_parse(), but takes a FILE* instead of filename. This doesn't 47 | close the file when it's finished -- the caller must do that. */ 48 | int cfg_parse_file(FILE *file, cfg_handler handler, void *user); 49 | 50 | /* Same as cfg_parse(), but takes an cfg_reader function pointer instead of 51 | filename. Used for implementing custom or string-based I/O (see also 52 | cfg_parse_string). */ 53 | int cfg_parse_stream(cfg_reader reader, void *stream, cfg_handler handler, void *user); 54 | 55 | /* Same as cfg_parse(), but takes a zero-terminated string with the CONF data 56 | instead of a file. Useful for parsing CONF data from a network socket or 57 | already in memory. */ 58 | int cfg_parse_string(const char *string, cfg_handler handler, void *user); 59 | 60 | /* Nonzero to allow multi-line value parsing, in the style of Python's 61 | configparser. If allowed, cfg_parse() will call the handler with the same 62 | name for each subsequent line parsed. */ 63 | #ifndef CFG_ALLOW_MULTILINE 64 | #define CFG_ALLOW_MULTILINE 0 65 | #endif 66 | 67 | /* Nonzero to allow a UTF-8 BOM sequence (0xEF 0xBB 0xBF) at the start of 68 | the file. See http://code.google.com/p/inih/issues/detail?id=21 */ 69 | #ifndef CFG_ALLOW_BOM 70 | #define CFG_ALLOW_BOM 0 71 | #endif 72 | 73 | /* Nonzero to allow inline comments (with valid inline comment characters 74 | specified by CFG_INLINE_COMMENT_PREFIXES). Set to 0 to turn off and match 75 | Python 3.2+ configparser behaviour. */ 76 | #ifndef CFG_ALLOW_INLINE_COMMENTS 77 | #define CFG_ALLOW_INLINE_COMMENTS 1 78 | #endif 79 | #ifndef CFG_INLINE_COMMENT_PREFIXES 80 | #define CFG_INLINE_COMMENT_PREFIXES ";" 81 | #endif 82 | 83 | /* Nonzero to use stack for line buffer, zero to use heap (malloc/free). */ 84 | #ifndef CFG_USE_STACK 85 | #define CFG_USE_STACK 1 86 | #endif 87 | 88 | /* Maximum line length for any line in CONF file (stack or heap). Note that 89 | this must be 3 more than the longest line (due to '\r', '\n', and '\0'). */ 90 | #ifndef CFG_MAX_LINE 91 | #define CFG_MAX_LINE 200 92 | #endif 93 | 94 | /* Nonzero to allow heap line buffer to grow via realloc(), zero for a 95 | fixed-size buffer of CFG_MAX_LINE bytes. Only applies if CFG_USE_STACK is 96 | zero. */ 97 | #ifndef CFG_ALLOW_REALLOC 98 | #define CFG_ALLOW_REALLOC 0 99 | #endif 100 | 101 | /* Initial size in bytes for heap line buffer. Only applies if CFG_USE_STACK 102 | is zero. */ 103 | #ifndef CFG_INITIAL_ALLOC 104 | #define CFG_INITIAL_ALLOC 200 105 | #endif 106 | 107 | /* Stop parsing on first error (default is to keep parsing). */ 108 | #ifndef CFG_STOP_ON_FIRST_ERROR 109 | #define CFG_STOP_ON_FIRST_ERROR 0 110 | #endif 111 | 112 | #endif /* __CFG_H__ */ 113 | -------------------------------------------------------------------------------- /libPS4/include/debug.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef DEBUG_H 4 | #define DEBUG_H 5 | 6 | #include "libc.h" 7 | #include "network.h" 8 | #include "syscall.h" 9 | #include "types.h" 10 | 11 | extern int DEBUG_SOCK; 12 | 13 | #define printf_debug(...) \ 14 | do { \ 15 | char debug_message[512] = {0}; \ 16 | int size = snprintf_s(debug_message, sizeof(debug_message), ##__VA_ARGS__); \ 17 | syscall(601, 7, debug_message, 0); \ 18 | if (DEBUG_SOCK >= 0) { \ 19 | SckSend(DEBUG_SOCK, debug_message, size); \ 20 | } \ 21 | } while (0); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /libPS4/include/dump.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef DUMP_H 4 | #define DUMP_H 5 | 6 | #include "types.h" 7 | 8 | typedef struct { 9 | int index; 10 | uint64_t fileoff; 11 | size_t bufsz; 12 | size_t filesz; 13 | int enc; 14 | } SegmentBufInfo; 15 | 16 | int is_self(const char *fn); 17 | void decrypt_and_dump_self(char *selfFile, char *saveFile); 18 | void decrypt_dir(char *sourcedir, char *destdir); 19 | int wait_for_app(char *title_id); 20 | int wait_for_bdcopy(char *title_id); 21 | int wait_for_usb(char *usb_name, char *usb_path); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /libPS4/include/elf.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef ELF_H 4 | #define ELF_H 5 | 6 | #include "types.h" 7 | 8 | #include "elf64.h" 9 | #include "elf_common.h" 10 | 11 | // Swapped 12 | #define SELF_MAGIC 0x1D3D154F 13 | #define ELF_MAGIC 0x464C457F 14 | 15 | typedef struct { 16 | uint32_t props; 17 | uint32_t reserved; 18 | uint64_t offset; 19 | uint64_t file_size; 20 | uint64_t memory_size; 21 | } SelfEntry; 22 | 23 | // SELF Header from: https://www.psdevwiki.com/ps4/SELF_File_Format#SELF_Header_Structure 24 | typedef struct { 25 | uint32_t magic; /* File magic. */ 26 | 27 | // uint32_t unknown; /* Always 00 01 01 12. */ 28 | uint8_t version; 29 | uint8_t mode; 30 | uint8_t endian; 31 | uint8_t attr; 32 | 33 | unsigned char content_type; /* 1 on Self, 4 on PUP Entry. */ 34 | unsigned char program_type; /* 0x0 PUP, 0x8 NPDRM Application, 0x9 PLUGIN, 0xC Kernel, 0xE Security Module, 0xF Secure Kernel */ 35 | uint16_t padding; /* Padding. */ 36 | uint16_t header_size; /* Header size. */ 37 | uint16_t signature_size; /* Metadata size? */ 38 | uint64_t self_size; /* Size of SELF. */ 39 | uint16_t num_of_segments; /* Number of Segments, 1 Kernel, 2 SL and Modules, 4 Kernel ELFs, 6 .selfs, 2 .sdll, 6 .sprx, 6 ShellCore, 6 eboot.bin, 2 sexe. */ 40 | uint16_t flags; /* Always 0x22. */ 41 | uint32_t reserved; /* Reserved. */ 42 | } SelfHeader; 43 | 44 | // SCE Header from: https://www.psdevwiki.com/ps4/SELF_File_Format#SCE_Special 45 | typedef struct { 46 | uint64_t program_authority_id; 47 | uint64_t program_type; 48 | uint64_t app_version; 49 | uint64_t fw_version; 50 | unsigned char digest[0x20]; 51 | } SceHeader; 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /libPS4/include/elf64.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1996-1998 John D. Polstra. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 | * SUCH DAMAGE. 25 | * 26 | * $FreeBSD: release/9.0.0/sys/sys/elf64.h 186667 2009-01-01 02:08:56Z obrien $ 27 | */ 28 | 29 | #pragma once 30 | 31 | #ifndef ELF64_H 32 | #define ELF64_H 33 | 34 | #include "types.h" 35 | 36 | #include "elf_common.h" 37 | 38 | /* 39 | * ELF definitions common to all 64-bit architectures. 40 | */ 41 | 42 | typedef uint64_t Elf64_Addr; 43 | typedef uint16_t Elf64_Half; 44 | typedef uint64_t Elf64_Off; 45 | typedef int32_t Elf64_Sword; 46 | typedef int64_t Elf64_Sxword; 47 | typedef uint32_t Elf64_Word; 48 | typedef uint64_t Elf64_Lword; 49 | typedef uint64_t Elf64_Xword; 50 | 51 | /* 52 | * Types of dynamic symbol hash table bucket and chain elements. 53 | * 54 | * This is inconsistent among 64 bit architectures, so a machine dependent 55 | * typedef is required. 56 | */ 57 | 58 | typedef Elf64_Word Elf64_Hashelt; 59 | 60 | /* Non-standard class-dependent datatype used for abstraction. */ 61 | typedef Elf64_Xword Elf64_Size; 62 | typedef Elf64_Sxword Elf64_Ssize; 63 | 64 | /* 65 | * ELF header. 66 | */ 67 | 68 | typedef struct { 69 | unsigned char e_ident[EI_NIDENT]; /* File identification. */ 70 | Elf64_Half e_type; /* File type. */ 71 | Elf64_Half e_machine; /* Machine architecture. */ 72 | Elf64_Word e_version; /* ELF format version. */ 73 | Elf64_Addr e_entry; /* Entry point. */ 74 | Elf64_Off e_phoff; /* Program header file offset. */ 75 | Elf64_Off e_shoff; /* Section header file offset. */ 76 | Elf64_Word e_flags; /* Architecture-specific flags. */ 77 | Elf64_Half e_ehsize; /* Size of ELF header in bytes. */ 78 | Elf64_Half e_phentsize; /* Size of program header entry. */ 79 | Elf64_Half e_phnum; /* Number of program header entries. */ 80 | Elf64_Half e_shentsize; /* Size of section header entry. */ 81 | Elf64_Half e_shnum; /* Number of section header entries. */ 82 | Elf64_Half e_shstrndx; /* Section name strings section. */ 83 | } Elf64_Ehdr; 84 | 85 | /* 86 | * Section header. 87 | */ 88 | 89 | typedef struct { 90 | Elf64_Word sh_name; /* Section name (index into the 91 | section header string table). */ 92 | Elf64_Word sh_type; /* Section type. */ 93 | Elf64_Xword sh_flags; /* Section flags. */ 94 | Elf64_Addr sh_addr; /* Address in memory image. */ 95 | Elf64_Off sh_offset; /* Offset in file. */ 96 | Elf64_Xword sh_size; /* Size in bytes. */ 97 | Elf64_Word sh_link; /* Index of a related section. */ 98 | Elf64_Word sh_info; /* Depends on section type. */ 99 | Elf64_Xword sh_addralign; /* Alignment in bytes. */ 100 | Elf64_Xword sh_entsize; /* Size of each entry in section. */ 101 | } Elf64_Shdr; 102 | 103 | /* 104 | * Program header. 105 | */ 106 | 107 | typedef struct { 108 | Elf64_Word p_type; /* Entry type. */ 109 | Elf64_Word p_flags; /* Access permission flags. */ 110 | Elf64_Off p_offset; /* File offset of contents. */ 111 | Elf64_Addr p_vaddr; /* Virtual address in memory image. */ 112 | Elf64_Addr p_paddr; /* Physical address (not used). */ 113 | Elf64_Xword p_filesz; /* Size of contents in file. */ 114 | Elf64_Xword p_memsz; /* Size of contents in memory. */ 115 | Elf64_Xword p_align; /* Alignment in memory and file. */ 116 | } Elf64_Phdr; 117 | 118 | /* 119 | * Dynamic structure. The ".dynamic" section contains an array of them. 120 | */ 121 | 122 | typedef struct { 123 | Elf64_Sxword d_tag; /* Entry type. */ 124 | union { 125 | Elf64_Xword d_val; /* Integer value. */ 126 | Elf64_Addr d_ptr; /* Address value. */ 127 | } d_un; 128 | } Elf64_Dyn; 129 | 130 | /* 131 | * Relocation entries. 132 | */ 133 | 134 | /* Relocations that don't need an addend field. */ 135 | typedef struct { 136 | Elf64_Addr r_offset; /* Location to be relocated. */ 137 | Elf64_Xword r_info; /* Relocation type and symbol index. */ 138 | } Elf64_Rel; 139 | 140 | /* Relocations that need an addend field. */ 141 | typedef struct { 142 | Elf64_Addr r_offset; /* Location to be relocated. */ 143 | Elf64_Xword r_info; /* Relocation type and symbol index. */ 144 | Elf64_Sxword r_addend; /* Addend. */ 145 | } Elf64_Rela; 146 | 147 | /* Macros for accessing the fields of r_info. */ 148 | #define ELF64_R_SYM(info) ((info) >> 32) 149 | #define ELF64_R_TYPE(info) ((info)&0xffffffffL) 150 | 151 | /* Macro for constructing r_info from field values. */ 152 | #define ELF64_R_INFO(sym, type) (((sym) << 32) + ((type)&0xffffffffL)) 153 | 154 | #define ELF64_R_TYPE_DATA(info) (((Elf64_Xword)(info) << 32) >> 40) 155 | #define ELF64_R_TYPE_ID(info) (((Elf64_Xword)(info) << 56) >> 56) 156 | #define ELF64_R_TYPE_INFO(data, type) \ 157 | (((Elf64_Xword)(data) << 8) + (Elf64_Xword)(type)) 158 | 159 | /* 160 | * Note entry header 161 | */ 162 | typedef Elf_Note Elf64_Nhdr; 163 | 164 | /* 165 | * Move entry 166 | */ 167 | typedef struct { 168 | Elf64_Lword m_value; /* symbol value */ 169 | Elf64_Xword m_info; /* size + index */ 170 | Elf64_Xword m_poffset; /* symbol offset */ 171 | Elf64_Half m_repeat; /* repeat count */ 172 | Elf64_Half m_stride; /* stride info */ 173 | } Elf64_Move; 174 | 175 | #define ELF64_M_SYM(info) ((info) >> 8) 176 | #define ELF64_M_SIZE(info) ((unsigned char)(info)) 177 | #define ELF64_M_INFO(sym, size) (((sym) << 8) + (unsigned char)(size)) 178 | 179 | /* 180 | * Hardware/Software capabilities entry 181 | */ 182 | typedef struct { 183 | Elf64_Xword c_tag; /* how to interpret value */ 184 | union { 185 | Elf64_Xword c_val; 186 | Elf64_Addr c_ptr; 187 | } c_un; 188 | } Elf64_Cap; 189 | 190 | /* 191 | * Symbol table entries. 192 | */ 193 | 194 | typedef struct { 195 | Elf64_Word st_name; /* String table index of name. */ 196 | unsigned char st_info; /* Type and binding information. */ 197 | unsigned char st_other; /* Reserved (not used). */ 198 | Elf64_Half st_shndx; /* Section index of symbol. */ 199 | Elf64_Addr st_value; /* Symbol value. */ 200 | Elf64_Xword st_size; /* Size of associated object. */ 201 | } Elf64_Sym; 202 | 203 | /* Macros for accessing the fields of st_info. */ 204 | #define ELF64_ST_BIND(info) ((info) >> 4) 205 | #define ELF64_ST_TYPE(info) ((info)&0xf) 206 | 207 | /* Macro for constructing st_info from field values. */ 208 | #define ELF64_ST_INFO(bind, type) (((bind) << 4) + ((type)&0xf)) 209 | 210 | /* Macro for accessing the fields of st_other. */ 211 | #define ELF64_ST_VISIBILITY(oth) ((oth)&0x3) 212 | 213 | /* Structures used by Sun & GNU-style symbol versioning. */ 214 | typedef struct { 215 | Elf64_Half vd_version; 216 | Elf64_Half vd_flags; 217 | Elf64_Half vd_ndx; 218 | Elf64_Half vd_cnt; 219 | Elf64_Word vd_hash; 220 | Elf64_Word vd_aux; 221 | Elf64_Word vd_next; 222 | } Elf64_Verdef; 223 | 224 | typedef struct { 225 | Elf64_Word vda_name; 226 | Elf64_Word vda_next; 227 | } Elf64_Verdaux; 228 | 229 | typedef struct { 230 | Elf64_Half vn_version; 231 | Elf64_Half vn_cnt; 232 | Elf64_Word vn_file; 233 | Elf64_Word vn_aux; 234 | Elf64_Word vn_next; 235 | } Elf64_Verneed; 236 | 237 | typedef struct { 238 | Elf64_Word vna_hash; 239 | Elf64_Half vna_flags; 240 | Elf64_Half vna_other; 241 | Elf64_Word vna_name; 242 | Elf64_Word vna_next; 243 | } Elf64_Vernaux; 244 | 245 | typedef Elf64_Half Elf64_Versym; 246 | 247 | typedef struct { 248 | Elf64_Half si_boundto; /* direct bindings - symbol bound to */ 249 | Elf64_Half si_flags; /* per symbol flags */ 250 | } Elf64_Syminfo; 251 | 252 | #endif 253 | -------------------------------------------------------------------------------- /libPS4/include/elf_common.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2000, 2001, 2008, 2011, David E. O'Brien 3 | * Copyright (c) 1998 John D. Polstra. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 | * SUCH DAMAGE. 26 | * 27 | * $FreeBSD: release/9.0.0/sys/sys/elf_common.h 221569 2011-05-07 01:05:31Z obrien $ 28 | */ 29 | 30 | #pragma once 31 | 32 | #ifndef ELF_COMMON_H 33 | #define ELF_COMMON_H 34 | 35 | #include "types.h" 36 | 37 | /* 38 | * ELF definitions that are independent of architecture or word size. 39 | */ 40 | 41 | /* 42 | * Note header. The ".note" section contains an array of notes. Each 43 | * begins with this header, aligned to a word boundary. Immediately 44 | * following the note header is n_namesz bytes of name, padded to the 45 | * next word boundary. Then comes n_descsz bytes of descriptor, again 46 | * padded to a word boundary. The values of n_namesz and n_descsz do 47 | * not include the padding. 48 | */ 49 | 50 | typedef struct { 51 | uint32_t n_namesz; /* Length of name. */ 52 | uint32_t n_descsz; /* Length of descriptor. */ 53 | uint32_t n_type; /* Type of this note. */ 54 | } Elf_Note; 55 | 56 | /* 57 | * The header for GNU-style hash sections. 58 | */ 59 | 60 | typedef struct { 61 | uint32_t gh_nbuckets; /* Number of hash buckets. */ 62 | uint32_t gh_symndx; /* First visible symbol in .dynsym. */ 63 | uint32_t gh_maskwords; /* #maskwords used in bloom filter. */ 64 | uint32_t gh_shift2; /* Bloom filter shift count. */ 65 | } Elf_GNU_Hash_Header; 66 | 67 | /* Indexes into the e_ident array. Keep synced with 68 | http://www.sco.com/developers/gabi/latest/ch4.eheader.html */ 69 | #define EI_MAG0 0 /* Magic number, byte 0. */ 70 | #define EI_MAG1 1 /* Magic number, byte 1. */ 71 | #define EI_MAG2 2 /* Magic number, byte 2. */ 72 | #define EI_MAG3 3 /* Magic number, byte 3. */ 73 | #define EI_CLASS 4 /* Class of machine. */ 74 | #define EI_DATA 5 /* Data format. */ 75 | #define EI_VERSION 6 /* ELF format version. */ 76 | #define EI_OSABI 7 /* Operating system / ABI identification */ 77 | #define EI_ABIVERSION 8 /* ABI version */ 78 | #define OLD_EI_BRAND 8 /* Start of architecture identification. */ 79 | #define EI_PAD 9 /* Start of padding (per SVR4 ABI). */ 80 | #define EI_NIDENT 16 /* Size of e_ident array. */ 81 | 82 | /* Values for the magic number bytes. */ 83 | #define ELFMAG0 0x7f 84 | #define ELFMAG1 'E' 85 | #define ELFMAG2 'L' 86 | #define ELFMAG3 'F' 87 | #define ELFMAG "\177ELF" /* magic string */ 88 | #define SELFMAG 4 /* magic string size */ 89 | 90 | /* Values for e_ident[EI_VERSION] and e_version. */ 91 | #define EV_NONE 0 92 | #define EV_CURRENT 1 93 | 94 | /* Values for e_ident[EI_CLASS]. */ 95 | #define ELFCLASSNONE 0 /* Unknown class. */ 96 | #define ELFCLASS32 1 /* 32-bit architecture. */ 97 | #define ELFCLASS64 2 /* 64-bit architecture. */ 98 | 99 | /* Values for e_ident[EI_DATA]. */ 100 | #define ELFDATANONE 0 /* Unknown data format. */ 101 | #define ELFDATA2LSB 1 /* 2's complement little-endian. */ 102 | #define ELFDATA2MSB 2 /* 2's complement big-endian. */ 103 | 104 | /* Values for e_ident[EI_OSABI]. */ 105 | #define ELFOSABI_NONE 0 /* UNIX System V ABI */ 106 | #define ELFOSABI_HPUX 1 /* HP-UX operating system */ 107 | #define ELFOSABI_NETBSD 2 /* NetBSD */ 108 | #define ELFOSABI_LINUX 3 /* GNU/Linux */ 109 | #define ELFOSABI_HURD 4 /* GNU/Hurd */ 110 | #define ELFOSABI_86OPEN 5 /* 86Open common IA32 ABI */ 111 | #define ELFOSABI_SOLARIS 6 /* Solaris */ 112 | #define ELFOSABI_AIX 7 /* AIX */ 113 | #define ELFOSABI_IRIX 8 /* IRIX */ 114 | #define ELFOSABI_FREEBSD 9 /* FreeBSD */ 115 | #define ELFOSABI_TRU64 10 /* TRU64 UNIX */ 116 | #define ELFOSABI_MODESTO 11 /* Novell Modesto */ 117 | #define ELFOSABI_OPENBSD 12 /* OpenBSD */ 118 | #define ELFOSABI_OPENVMS 13 /* Open VMS */ 119 | #define ELFOSABI_NSK 14 /* HP Non-Stop Kernel */ 120 | #define ELFOSABI_AROS 15 /* Amiga Research OS */ 121 | #define ELFOSABI_ARM 97 /* ARM */ 122 | #define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */ 123 | 124 | #define ELFOSABI_SYSV ELFOSABI_NONE /* symbol used in old spec */ 125 | #define ELFOSABI_MONTEREY ELFOSABI_AIX /* Monterey */ 126 | 127 | /* e_ident */ 128 | #define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \ 129 | (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \ 130 | (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \ 131 | (ehdr).e_ident[EI_MAG3] == ELFMAG3) 132 | 133 | /* Values for e_type. */ 134 | #define ET_NONE 0 /* Unknown type. */ 135 | #define ET_REL 1 /* Relocatable. */ 136 | #define ET_EXEC 2 /* Executable. */ 137 | #define ET_DYN 3 /* Shared object. */ 138 | #define ET_CORE 4 /* Core file. */ 139 | #define ET_LOOS 0xfe00 /* First operating system specific. */ 140 | #define ET_HIOS 0xfeff /* Last operating system-specific. */ 141 | #define ET_LOPROC 0xff00 /* First processor-specific. */ 142 | #define ET_HIPROC 0xffff /* Last processor-specific. */ 143 | 144 | /* Values for e_machine. */ 145 | #define EM_NONE 0 /* Unknown machine. */ 146 | #define EM_M32 1 /* AT&T WE32100. */ 147 | #define EM_SPARC 2 /* Sun SPARC. */ 148 | #define EM_386 3 /* Intel i386. */ 149 | #define EM_68K 4 /* Motorola 68000. */ 150 | #define EM_88K 5 /* Motorola 88000. */ 151 | #define EM_860 7 /* Intel i860. */ 152 | #define EM_MIPS 8 /* MIPS R3000 Big-Endian only. */ 153 | #define EM_S370 9 /* IBM System/370. */ 154 | #define EM_MIPS_RS3_LE 10 /* MIPS R3000 Little-Endian. */ 155 | #define EM_PARISC 15 /* HP PA-RISC. */ 156 | #define EM_VPP500 17 /* Fujitsu VPP500. */ 157 | #define EM_SPARC32PLUS 18 /* SPARC v8plus. */ 158 | #define EM_960 19 /* Intel 80960. */ 159 | #define EM_PPC 20 /* PowerPC 32-bit. */ 160 | #define EM_PPC64 21 /* PowerPC 64-bit. */ 161 | #define EM_S390 22 /* IBM System/390. */ 162 | #define EM_V800 36 /* NEC V800. */ 163 | #define EM_FR20 37 /* Fujitsu FR20. */ 164 | #define EM_RH32 38 /* TRW RH-32. */ 165 | #define EM_RCE 39 /* Motorola RCE. */ 166 | #define EM_ARM 40 /* ARM. */ 167 | #define EM_SH 42 /* Hitachi SH. */ 168 | #define EM_SPARCV9 43 /* SPARC v9 64-bit. */ 169 | #define EM_TRICORE 44 /* Siemens TriCore embedded processor. */ 170 | #define EM_ARC 45 /* Argonaut RISC Core. */ 171 | #define EM_H8_300 46 /* Hitachi H8/300. */ 172 | #define EM_H8_300H 47 /* Hitachi H8/300H. */ 173 | #define EM_H8S 48 /* Hitachi H8S. */ 174 | #define EM_H8_500 49 /* Hitachi H8/500. */ 175 | #define EM_IA_64 50 /* Intel IA-64 Processor. */ 176 | #define EM_MIPS_X 51 /* Stanford MIPS-X. */ 177 | #define EM_COLDFIRE 52 /* Motorola ColdFire. */ 178 | #define EM_68HC12 53 /* Motorola M68HC12. */ 179 | #define EM_MMA 54 /* Fujitsu MMA. */ 180 | #define EM_PCP 55 /* Siemens PCP. */ 181 | #define EM_NCPU 56 /* Sony nCPU. */ 182 | #define EM_NDR1 57 /* Denso NDR1 microprocessor. */ 183 | #define EM_STARCORE 58 /* Motorola Star*Core processor. */ 184 | #define EM_ME16 59 /* Toyota ME16 processor. */ 185 | #define EM_ST100 60 /* STMicroelectronics ST100 processor. */ 186 | #define EM_TINYJ 61 /* Advanced Logic Corp. TinyJ processor. */ 187 | #define EM_X86_64 62 /* Advanced Micro Devices x86-64 */ 188 | #define EM_AMD64 EM_X86_64 /* Advanced Micro Devices x86-64 (compat) */ 189 | #define EM_PDSP 63 /* Sony DSP Processor. */ 190 | #define EM_FX66 66 /* Siemens FX66 microcontroller. */ 191 | #define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 \ 192 | microcontroller. */ 193 | #define EM_ST7 68 /* STmicroelectronics ST7 8-bit \ 194 | microcontroller. */ 195 | #define EM_68HC16 69 /* Motorola MC68HC16 microcontroller. */ 196 | #define EM_68HC11 70 /* Motorola MC68HC11 microcontroller. */ 197 | #define EM_68HC08 71 /* Motorola MC68HC08 microcontroller. */ 198 | #define EM_68HC05 72 /* Motorola MC68HC05 microcontroller. */ 199 | #define EM_SVX 73 /* Silicon Graphics SVx. */ 200 | #define EM_ST19 74 /* STMicroelectronics ST19 8-bit mc. */ 201 | #define EM_VAX 75 /* Digital VAX. */ 202 | #define EM_CRIS 76 /* Axis Communications 32-bit embedded \ 203 | processor. */ 204 | #define EM_JAVELIN 77 /* Infineon Technologies 32-bit embedded \ 205 | processor. */ 206 | #define EM_FIREPATH 78 /* Element 14 64-bit DSP Processor. */ 207 | #define EM_ZSP 79 /* LSI Logic 16-bit DSP Processor. */ 208 | #define EM_MMIX 80 /* Donald Knuth's educational 64-bit proc. */ 209 | #define EM_HUANY 81 /* Harvard University machine-independent \ 210 | object files. */ 211 | #define EM_PRISM 82 /* SiTera Prism. */ 212 | #define EM_AVR 83 /* Atmel AVR 8-bit microcontroller. */ 213 | #define EM_FR30 84 /* Fujitsu FR30. */ 214 | #define EM_D10V 85 /* Mitsubishi D10V. */ 215 | #define EM_D30V 86 /* Mitsubishi D30V. */ 216 | #define EM_V850 87 /* NEC v850. */ 217 | #define EM_M32R 88 /* Mitsubishi M32R. */ 218 | #define EM_MN10300 89 /* Matsushita MN10300. */ 219 | #define EM_MN10200 90 /* Matsushita MN10200. */ 220 | #define EM_PJ 91 /* picoJava. */ 221 | #define EM_OPENRISC 92 /* OpenRISC 32-bit embedded processor. */ 222 | #define EM_ARC_A5 93 /* ARC Cores Tangent-A5. */ 223 | #define EM_XTENSA 94 /* Tensilica Xtensa Architecture. */ 224 | #define EM_VIDEOCORE 95 /* Alphamosaic VideoCore processor. */ 225 | #define EM_TMM_GPP 96 /* Thompson Multimedia General Purpose \ 226 | Processor. */ 227 | #define EM_NS32K 97 /* National Semiconductor 32000 series. */ 228 | #define EM_TPC 98 /* Tenor Network TPC processor. */ 229 | #define EM_SNP1K 99 /* Trebia SNP 1000 processor. */ 230 | #define EM_ST200 100 /* STMicroelectronics ST200 microcontroller. */ 231 | #define EM_IP2K 101 /* Ubicom IP2xxx microcontroller family. */ 232 | #define EM_MAX 102 /* MAX Processor. */ 233 | #define EM_CR 103 /* National Semiconductor CompactRISC \ 234 | microprocessor. */ 235 | #define EM_F2MC16 104 /* Fujitsu F2MC16. */ 236 | #define EM_MSP430 105 /* Texas Instruments embedded microcontroller \ 237 | msp430. */ 238 | #define EM_BLACKFIN 106 /* Analog Devices Blackfin (DSP) processor. */ 239 | #define EM_SE_C33 107 /* S1C33 Family of Seiko Epson processors. */ 240 | #define EM_SEP 108 /* Sharp embedded microprocessor. */ 241 | #define EM_ARCA 109 /* Arca RISC Microprocessor. */ 242 | #define EM_UNICORE 110 /* Microprocessor series from PKU-Unity Ltd. \ 243 | and MPRC of Peking University */ 244 | 245 | /* Non-standard or deprecated. */ 246 | #define EM_486 6 /* Intel i486. */ 247 | #define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */ 248 | #define EM_ALPHA_STD 41 /* Digital Alpha (standard value). */ 249 | #define EM_ALPHA 0x9026 /* Alpha (written in the absence of an ABI) */ 250 | 251 | /* Special section indexes. */ 252 | #define SHN_UNDEF 0 /* Undefined, missing, irrelevant. */ 253 | #define SHN_LORESERVE 0xff00 /* First of reserved range. */ 254 | #define SHN_LOPROC 0xff00 /* First processor-specific. */ 255 | #define SHN_HIPROC 0xff1f /* Last processor-specific. */ 256 | #define SHN_LOOS 0xff20 /* First operating system-specific. */ 257 | #define SHN_HIOS 0xff3f /* Last operating system-specific. */ 258 | #define SHN_ABS 0xfff1 /* Absolute values. */ 259 | #define SHN_COMMON 0xfff2 /* Common data. */ 260 | #define SHN_XINDEX 0xffff /* Escape -- index stored elsewhere. */ 261 | #define SHN_HIRESERVE 0xffff /* Last of reserved range. */ 262 | 263 | /* sh_type */ 264 | #define SHT_NULL 0 /* inactive */ 265 | #define SHT_PROGBITS 1 /* program defined information */ 266 | #define SHT_SYMTAB 2 /* symbol table section */ 267 | #define SHT_STRTAB 3 /* string table section */ 268 | #define SHT_RELA 4 /* relocation section with addends */ 269 | #define SHT_HASH 5 /* symbol hash table section */ 270 | #define SHT_DYNAMIC 6 /* dynamic section */ 271 | #define SHT_NOTE 7 /* note section */ 272 | #define SHT_NOBITS 8 /* no space section */ 273 | #define SHT_REL 9 /* relocation section - no addends */ 274 | #define SHT_SHLIB 10 /* reserved - purpose unknown */ 275 | #define SHT_DYNSYM 11 /* dynamic symbol table section */ 276 | #define SHT_INIT_ARRAY 14 /* Initialization function pointers. */ 277 | #define SHT_FINI_ARRAY 15 /* Termination function pointers. */ 278 | #define SHT_PREINIT_ARRAY 16 /* Pre-initialization function ptrs. */ 279 | #define SHT_GROUP 17 /* Section group. */ 280 | #define SHT_SYMTAB_SHNDX 18 /* Section indexes (see SHN_XINDEX). */ 281 | #define SHT_LOOS 0x60000000 /* First of OS specific semantics */ 282 | #define SHT_LOSUNW 0x6ffffff4 283 | #define SHT_SUNW_dof 0x6ffffff4 284 | #define SHT_SUNW_cap 0x6ffffff5 285 | #define SHT_SUNW_SIGNATURE 0x6ffffff6 286 | #define SHT_GNU_HASH 0x6ffffff6 287 | #define SHT_SUNW_ANNOTATE 0x6ffffff7 288 | #define SHT_SUNW_DEBUGSTR 0x6ffffff8 289 | #define SHT_SUNW_DEBUG 0x6ffffff9 290 | #define SHT_SUNW_move 0x6ffffffa 291 | #define SHT_SUNW_COMDAT 0x6ffffffb 292 | #define SHT_SUNW_syminfo 0x6ffffffc 293 | #define SHT_SUNW_verdef 0x6ffffffd 294 | #define SHT_GNU_verdef 0x6ffffffd /* Symbol versions provided */ 295 | #define SHT_SUNW_verneed 0x6ffffffe 296 | #define SHT_GNU_verneed 0x6ffffffe /* Symbol versions required */ 297 | #define SHT_SUNW_versym 0x6fffffff 298 | #define SHT_GNU_versym 0x6fffffff /* Symbol version table */ 299 | #define SHT_HISUNW 0x6fffffff 300 | #define SHT_HIOS 0x6fffffff /* Last of OS specific semantics */ 301 | #define SHT_LOPROC 0x70000000 /* reserved range for processor */ 302 | #define SHT_AMD64_UNWIND 0x70000001 /* unwind information */ 303 | #define SHT_MIPS_DWARF 0x7000001e /* MIPS gcc uses MIPS_DWARF */ 304 | #define SHT_HIPROC 0x7fffffff /* specific section header types */ 305 | #define SHT_LOUSER 0x80000000 /* reserved range for application */ 306 | #define SHT_HIUSER 0xffffffff /* specific indexes */ 307 | 308 | /* Flags for sh_flags. */ 309 | #define SHF_WRITE 0x1 /* Section contains writable data. */ 310 | #define SHF_ALLOC 0x2 /* Section occupies memory. */ 311 | #define SHF_EXECINSTR 0x4 /* Section contains instructions. */ 312 | #define SHF_MERGE 0x10 /* Section may be merged. */ 313 | #define SHF_STRINGS 0x20 /* Section contains strings. */ 314 | #define SHF_INFO_LINK 0x40 /* sh_info holds section index. */ 315 | #define SHF_LINK_ORDER 0x80 /* Special ordering requirements. */ 316 | #define SHF_OS_NONCONFORMING 0x100 /* OS-specific processing required. */ 317 | #define SHF_GROUP 0x200 /* Member of section group. */ 318 | #define SHF_TLS 0x400 /* Section contains TLS data. */ 319 | #define SHF_MASKOS 0x0ff00000 /* OS-specific semantics. */ 320 | #define SHF_MASKPROC 0xf0000000 /* Processor-specific semantics. */ 321 | 322 | /* Values for p_type. */ 323 | #define PT_NULL 0 /* Unused entry. */ 324 | #define PT_LOAD 1 /* Loadable segment. */ 325 | #define PT_DYNAMIC 2 /* Dynamic linking information segment. */ 326 | #define PT_INTERP 3 /* Pathname of interpreter. */ 327 | #define PT_NOTE 4 /* Auxiliary information. */ 328 | #define PT_SHLIB 5 /* Reserved (not used). */ 329 | #define PT_PHDR 6 /* Location of program header itself. */ 330 | #define PT_TLS 7 /* Thread local storage segment */ 331 | #define PT_LOOS 0x60000000 /* First OS-specific. */ 332 | #define PT_SUNW_UNWIND 0x6464e550 /* amd64 UNWIND program header */ 333 | #define PT_GNU_EH_FRAME 0x6474e550 334 | #define PT_GNU_STACK 0x6474e551 335 | #define PT_LOSUNW 0x6ffffffa 336 | #define PT_SUNWBSS 0x6ffffffa /* Sun Specific segment */ 337 | #define PT_SUNWSTACK 0x6ffffffb /* describes the stack segment */ 338 | #define PT_SUNWDTRACE 0x6ffffffc /* private */ 339 | #define PT_SUNWCAP 0x6ffffffd /* hard/soft capabilities segment */ 340 | #define PT_HISUNW 0x6fffffff 341 | #define PT_HIOS 0x6fffffff /* Last OS-specific. */ 342 | #define PT_LOPROC 0x70000000 /* First processor-specific type. */ 343 | #define PT_HIPROC 0x7fffffff /* Last processor-specific type. */ 344 | 345 | /* Values for p_flags. */ 346 | #define PF_X 0x1 /* Executable. */ 347 | #define PF_W 0x2 /* Writable. */ 348 | #define PF_R 0x4 /* Readable. */ 349 | #define PF_MASKOS 0x0ff00000 /* Operating system-specific. */ 350 | #define PF_MASKPROC 0xf0000000 /* Processor-specific. */ 351 | 352 | /* Extended program header index. */ 353 | #define PN_XNUM 0xffff 354 | 355 | /* Values for d_tag. */ 356 | #define DT_NULL 0 /* Terminating entry. */ 357 | #define DT_NEEDED 1 /* String table offset of a needed shared \ 358 | library. */ 359 | #define DT_PLTRELSZ 2 /* Total size in bytes of PLT relocations. */ 360 | #define DT_PLTGOT 3 /* Processor-dependent address. */ 361 | #define DT_HASH 4 /* Address of symbol hash table. */ 362 | #define DT_STRTAB 5 /* Address of string table. */ 363 | #define DT_SYMTAB 6 /* Address of symbol table. */ 364 | #define DT_RELA 7 /* Address of ElfNN_Rela relocations. */ 365 | #define DT_RELASZ 8 /* Total size of ElfNN_Rela relocations. */ 366 | #define DT_RELAENT 9 /* Size of each ElfNN_Rela relocation entry. */ 367 | #define DT_STRSZ 10 /* Size of string table. */ 368 | #define DT_SYMENT 11 /* Size of each symbol table entry. */ 369 | #define DT_INIT 12 /* Address of initialization function. */ 370 | #define DT_FINI 13 /* Address of finalization function. */ 371 | #define DT_SONAME 14 /* String table offset of shared object \ 372 | name. */ 373 | #define DT_RPATH 15 /* String table offset of library path. [sup] */ 374 | #define DT_SYMBOLIC 16 /* Indicates "symbolic" linking. [sup] */ 375 | #define DT_REL 17 /* Address of ElfNN_Rel relocations. */ 376 | #define DT_RELSZ 18 /* Total size of ElfNN_Rel relocations. */ 377 | #define DT_RELENT 19 /* Size of each ElfNN_Rel relocation. */ 378 | #define DT_PLTREL 20 /* Type of relocation used for PLT. */ 379 | #define DT_DEBUG 21 /* Reserved (not used). */ 380 | #define DT_TEXTREL 22 /* Indicates there may be relocations in \ 381 | non-writable segments. [sup] */ 382 | #define DT_JMPREL 23 /* Address of PLT relocations. */ 383 | #define DT_BIND_NOW 24 /* [sup] */ 384 | #define DT_INIT_ARRAY 25 /* Address of the array of pointers to \ 385 | initialization functions */ 386 | #define DT_FINI_ARRAY 26 /* Address of the array of pointers to \ 387 | termination functions */ 388 | #define DT_INIT_ARRAYSZ 27 /* Size in bytes of the array of \ 389 | initialization functions. */ 390 | #define DT_FINI_ARRAYSZ 28 /* Size in bytes of the array of \ 391 | terminationfunctions. */ 392 | #define DT_RUNPATH 29 /* String table offset of a null-terminated \ 393 | library search path string. */ 394 | #define DT_FLAGS 30 /* Object specific flag values. */ 395 | #define DT_ENCODING 32 /* Values greater than or equal to DT_ENCODING \ 396 | and less than DT_LOOS follow the rules for \ 397 | the interpretation of the d_un union \ 398 | as follows: even == 'd_ptr', odd == 'd_val' \ 399 | or none */ 400 | #define DT_PREINIT_ARRAY 32 /* Address of the array of pointers to \ 401 | pre-initialization functions. */ 402 | #define DT_PREINIT_ARRAYSZ 33 /* Size in bytes of the array of \ 403 | pre-initialization functions. */ 404 | #define DT_MAXPOSTAGS 34 /* number of positive tags */ 405 | #define DT_LOOS 0x6000000d /* First OS-specific */ 406 | #define DT_SUNW_AUXILIARY 0x6000000d /* symbol auxiliary name */ 407 | #define DT_SUNW_RTLDINF 0x6000000e /* ld.so.1 info (private) */ 408 | #define DT_SUNW_FILTER 0x6000000f /* symbol filter name */ 409 | #define DT_SUNW_CAP 0x60000010 /* hardware/software */ 410 | #define DT_HIOS 0x6ffff000 /* Last OS-specific */ 411 | 412 | /* 413 | * DT_* entries which fall between DT_VALRNGHI & DT_VALRNGLO use the 414 | * Dyn.d_un.d_val field of the Elf*_Dyn structure. 415 | */ 416 | #define DT_VALRNGLO 0x6ffffd00 417 | #define DT_CHECKSUM 0x6ffffdf8 /* elf checksum */ 418 | #define DT_PLTPADSZ 0x6ffffdf9 /* pltpadding size */ 419 | #define DT_MOVEENT 0x6ffffdfa /* move table entry size */ 420 | #define DT_MOVESZ 0x6ffffdfb /* move table size */ 421 | #define DT_FEATURE_1 0x6ffffdfc /* feature holder */ 422 | #define DT_POSFLAG_1 0x6ffffdfd /* flags for DT_* entries, effecting */ 423 | /* the following DT_* entry. */ 424 | /* See DF_P1_* definitions */ 425 | #define DT_SYMINSZ 0x6ffffdfe /* syminfo table size (in bytes) */ 426 | #define DT_SYMINENT 0x6ffffdff /* syminfo entry size (in bytes) */ 427 | #define DT_VALRNGHI 0x6ffffdff 428 | 429 | /* 430 | * DT_* entries which fall between DT_ADDRRNGHI & DT_ADDRRNGLO use the 431 | * Dyn.d_un.d_ptr field of the Elf*_Dyn structure. 432 | * 433 | * If any adjustment is made to the ELF object after it has been 434 | * built, these entries will need to be adjusted. 435 | */ 436 | #define DT_ADDRRNGLO 0x6ffffe00 437 | #define DT_GNU_HASH 0x6ffffef5 /* GNU-style hash table */ 438 | #define DT_CONFIG 0x6ffffefa /* configuration information */ 439 | #define DT_DEPAUDIT 0x6ffffefb /* dependency auditing */ 440 | #define DT_AUDIT 0x6ffffefc /* object auditing */ 441 | #define DT_PLTPAD 0x6ffffefd /* pltpadding (sparcv9) */ 442 | #define DT_MOVETAB 0x6ffffefe /* move table */ 443 | #define DT_SYMINFO 0x6ffffeff /* syminfo table */ 444 | #define DT_ADDRRNGHI 0x6ffffeff 445 | 446 | #define DT_VERSYM 0x6ffffff0 /* Address of versym section. */ 447 | #define DT_RELACOUNT 0x6ffffff9 /* number of RELATIVE relocations */ 448 | #define DT_RELCOUNT 0x6ffffffa /* number of RELATIVE relocations */ 449 | #define DT_FLAGS_1 0x6ffffffb /* state flags - see DF_1_* defs */ 450 | #define DT_VERDEF 0x6ffffffc /* Address of verdef section. */ 451 | #define DT_VERDEFNUM 0x6ffffffd /* Number of elems in verdef section */ 452 | #define DT_VERNEED 0x6ffffffe /* Address of verneed section. */ 453 | #define DT_VERNEEDNUM 0x6fffffff /* Number of elems in verneed section */ 454 | 455 | #define DT_LOPROC 0x70000000 /* First processor-specific type. */ 456 | #define DT_DEPRECATED_SPARC_REGISTER 0x7000001 457 | #define DT_AUXILIARY 0x7ffffffd /* shared library auxiliary name */ 458 | #define DT_USED 0x7ffffffe /* ignored - same as needed */ 459 | #define DT_FILTER 0x7fffffff /* shared library filter name */ 460 | #define DT_HIPROC 0x7fffffff /* Last processor-specific type. */ 461 | 462 | /* Values for DT_FLAGS */ 463 | #define DF_ORIGIN 0x0001 /* Indicates that the object being loaded may \ 464 | make reference to the $ORIGIN substitution \ 465 | string */ 466 | #define DF_SYMBOLIC 0x0002 /* Indicates "symbolic" linking. */ 467 | #define DF_TEXTREL 0x0004 /* Indicates there may be relocations in \ 468 | non-writable segments. */ 469 | #define DF_BIND_NOW 0x0008 /* Indicates that the dynamic linker should \ 470 | process all relocations for the object \ 471 | containing this entry before transferring \ 472 | control to the program. */ 473 | #define DF_STATIC_TLS 0x0010 /* Indicates that the shared object or \ 474 | executable contains code using a static \ 475 | thread-local storage scheme. */ 476 | 477 | /* Values for DT_FLAGS_1 */ 478 | #define DF_1_BIND_NOW 0x00000001 /* Same as DF_BIND_NOW */ 479 | #define DF_1_GLOBAL 0x00000002 /* Set the RTLD_GLOBAL for object */ 480 | #define DF_1_NODELETE 0x00000008 /* Set the RTLD_NODELETE for object */ 481 | #define DF_1_LOADFLTR 0x00000010 /* Immediate loading of filtees */ 482 | #define DF_1_NOOPEN 0x00000040 /* Do not allow loading on dlopen() */ 483 | #define DF_1_ORIGIN 0x00000080 /* Process $ORIGIN */ 484 | 485 | /* Values for n_type. Used in core files. */ 486 | #define NT_PRSTATUS 1 /* Process status. */ 487 | #define NT_FPREGSET 2 /* Floating point registers. */ 488 | #define NT_PRPSINFO 3 /* Process state info. */ 489 | #define NT_THRMISC 7 /* Thread miscellaneous info. */ 490 | 491 | /* Symbol Binding - ELFNN_ST_BIND - st_info */ 492 | #define STB_LOCAL 0 /* Local symbol */ 493 | #define STB_GLOBAL 1 /* Global symbol */ 494 | #define STB_WEAK 2 /* like global - lower precedence */ 495 | #define STB_LOOS 10 /* Reserved range for operating system */ 496 | #define STB_HIOS 12 /* specific semantics. */ 497 | #define STB_LOPROC 13 /* reserved range for processor */ 498 | #define STB_HIPROC 15 /* specific semantics. */ 499 | 500 | /* Symbol type - ELFNN_ST_TYPE - st_info */ 501 | #define STT_NOTYPE 0 /* Unspecified type. */ 502 | #define STT_OBJECT 1 /* Data object. */ 503 | #define STT_FUNC 2 /* Function. */ 504 | #define STT_SECTION 3 /* Section. */ 505 | #define STT_FILE 4 /* Source file. */ 506 | #define STT_COMMON 5 /* Uninitialized common block. */ 507 | #define STT_TLS 6 /* TLS object. */ 508 | #define STT_NUM 7 509 | #define STT_LOOS 10 /* Reserved range for operating system */ 510 | #define STT_HIOS 12 /* specific semantics. */ 511 | #define STT_LOPROC 13 /* reserved range for processor */ 512 | #define STT_HIPROC 15 /* specific semantics. */ 513 | 514 | /* Symbol visibility - ELFNN_ST_VISIBILITY - st_other */ 515 | #define STV_DEFAULT 0x0 /* Default visibility (see binding). */ 516 | #define STV_INTERNAL 0x1 /* Special meaning in relocatable objects. */ 517 | #define STV_HIDDEN 0x2 /* Not visible. */ 518 | #define STV_PROTECTED 0x3 /* Visible but not preemptible. */ 519 | #define STV_EXPORTED 0x4 520 | #define STV_SINGLETON 0x5 521 | #define STV_ELIMINATE 0x6 522 | 523 | /* Special symbol table indexes. */ 524 | #define STN_UNDEF 0 /* Undefined symbol index. */ 525 | 526 | /* Symbol versioning flags. */ 527 | #define VER_DEF_CURRENT 1 528 | #define VER_DEF_IDX(x) VER_NDX(x) 529 | 530 | #define VER_FLG_BASE 0x01 531 | #define VER_FLG_WEAK 0x02 532 | 533 | #define VER_NEED_CURRENT 1 534 | #define VER_NEED_WEAK (1u << 15) 535 | #define VER_NEED_HIDDEN VER_NDX_HIDDEN 536 | #define VER_NEED_IDX(x) VER_NDX(x) 537 | 538 | #define VER_NDX_LOCAL 0 539 | #define VER_NDX_GLOBAL 1 540 | #define VER_NDX_GIVEN 2 541 | 542 | #define VER_NDX_HIDDEN (1u << 15) 543 | #define VER_NDX(x) ((x) & ~(1u << 15)) 544 | 545 | #define CA_SUNW_NULL 0 546 | #define CA_SUNW_HW_1 1 /* first hardware capabilities entry */ 547 | #define CA_SUNW_SF_1 2 /* first software capabilities entry */ 548 | 549 | /* 550 | * Syminfo flag values 551 | */ 552 | #define SYMINFO_FLG_DIRECT 0x0001 /* symbol ref has direct association */ 553 | /* to object containing defn. */ 554 | #define SYMINFO_FLG_PASSTHRU 0x0002 /* ignored - see SYMINFO_FLG_FILTER */ 555 | #define SYMINFO_FLG_COPY 0x0004 /* symbol is a copy-reloc */ 556 | #define SYMINFO_FLG_LAZYLOAD 0x0008 /* object containing defn should be */ 557 | /* lazily-loaded */ 558 | #define SYMINFO_FLG_DIRECTBIND 0x0010 /* ref should be bound directly to */ 559 | /* object containing defn. */ 560 | #define SYMINFO_FLG_NOEXTDIRECT 0x0020 /* don't let an external reference */ 561 | /* directly bind to this symbol */ 562 | #define SYMINFO_FLG_FILTER 0x0002 /* symbol ref is associated to a */ 563 | #define SYMINFO_FLG_AUXILIARY 0x0040 /* standard or auxiliary filter */ 564 | 565 | /* 566 | * Syminfo.si_boundto values. 567 | */ 568 | #define SYMINFO_BT_SELF 0xffff /* symbol bound to self */ 569 | #define SYMINFO_BT_PARENT 0xfffe /* symbol bound to parent */ 570 | #define SYMINFO_BT_NONE 0xfffd /* no special symbol binding */ 571 | #define SYMINFO_BT_EXTERN 0xfffc /* symbol defined as external */ 572 | #define SYMINFO_BT_LOWRESERVE 0xff00 /* beginning of reserved entries */ 573 | 574 | /* 575 | * Syminfo version values. 576 | */ 577 | #define SYMINFO_NONE 0 /* Syminfo version */ 578 | #define SYMINFO_CURRENT 1 579 | #define SYMINFO_NUM 2 580 | 581 | /* 582 | * Relocation types. 583 | * 584 | * All machine architectures are defined here to allow tools on one to 585 | * handle others. 586 | */ 587 | 588 | #define R_386_NONE 0 /* No relocation. */ 589 | #define R_386_32 1 /* Add symbol value. */ 590 | #define R_386_PC32 2 /* Add PC-relative symbol value. */ 591 | #define R_386_GOT32 3 /* Add PC-relative GOT offset. */ 592 | #define R_386_PLT32 4 /* Add PC-relative PLT offset. */ 593 | #define R_386_COPY 5 /* Copy data from shared object. */ 594 | #define R_386_GLOB_DAT 6 /* Set GOT entry to data address. */ 595 | #define R_386_JMP_SLOT 7 /* Set GOT entry to code address. */ 596 | #define R_386_RELATIVE 8 /* Add load address of shared object. */ 597 | #define R_386_GOTOFF 9 /* Add GOT-relative symbol address. */ 598 | #define R_386_GOTPC 10 /* Add PC-relative GOT table address. */ 599 | #define R_386_TLS_TPOFF 14 /* Negative offset in static TLS block */ 600 | #define R_386_TLS_IE 15 /* Absolute address of GOT for -ve static TLS */ 601 | #define R_386_TLS_GOTIE 16 /* GOT entry for negative static TLS block */ 602 | #define R_386_TLS_LE 17 /* Negative offset relative to static TLS */ 603 | #define R_386_TLS_GD 18 /* 32 bit offset to GOT (index,off) pair */ 604 | #define R_386_TLS_LDM 19 /* 32 bit offset to GOT (index,zero) pair */ 605 | #define R_386_TLS_GD_32 24 /* 32 bit offset to GOT (index,off) pair */ 606 | #define R_386_TLS_GD_PUSH 25 /* pushl instruction for Sun ABI GD sequence */ 607 | #define R_386_TLS_GD_CALL 26 /* call instruction for Sun ABI GD sequence */ 608 | #define R_386_TLS_GD_POP 27 /* popl instruction for Sun ABI GD sequence */ 609 | #define R_386_TLS_LDM_32 28 /* 32 bit offset to GOT (index,zero) pair */ 610 | #define R_386_TLS_LDM_PUSH 29 /* pushl instruction for Sun ABI LD sequence */ 611 | #define R_386_TLS_LDM_CALL 30 /* call instruction for Sun ABI LD sequence */ 612 | #define R_386_TLS_LDM_POP 31 /* popl instruction for Sun ABI LD sequence */ 613 | #define R_386_TLS_LDO_32 32 /* 32 bit offset from start of TLS block */ 614 | #define R_386_TLS_IE_32 33 /* 32 bit offset to GOT static TLS offset entry */ 615 | #define R_386_TLS_LE_32 34 /* 32 bit offset within static TLS block */ 616 | #define R_386_TLS_DTPMOD32 35 /* GOT entry containing TLS index */ 617 | #define R_386_TLS_DTPOFF32 36 /* GOT entry containing TLS offset */ 618 | #define R_386_TLS_TPOFF32 37 /* GOT entry of -ve static TLS offset */ 619 | 620 | #define R_ARM_NONE 0 /* No relocation. */ 621 | #define R_ARM_PC24 1 622 | #define R_ARM_ABS32 2 623 | #define R_ARM_REL32 3 624 | #define R_ARM_PC13 4 625 | #define R_ARM_ABS16 5 626 | #define R_ARM_ABS12 6 627 | #define R_ARM_THM_ABS5 7 628 | #define R_ARM_ABS8 8 629 | #define R_ARM_SBREL32 9 630 | #define R_ARM_THM_PC22 10 631 | #define R_ARM_THM_PC8 11 632 | #define R_ARM_AMP_VCALL9 12 633 | #define R_ARM_SWI24 13 634 | #define R_ARM_THM_SWI8 14 635 | #define R_ARM_XPC25 15 636 | #define R_ARM_THM_XPC22 16 637 | #define R_ARM_COPY 20 /* Copy data from shared object. */ 638 | #define R_ARM_GLOB_DAT 21 /* Set GOT entry to data address. */ 639 | #define R_ARM_JUMP_SLOT 22 /* Set GOT entry to code address. */ 640 | #define R_ARM_RELATIVE 23 /* Add load address of shared object. */ 641 | #define R_ARM_GOTOFF 24 /* Add GOT-relative symbol address. */ 642 | #define R_ARM_GOTPC 25 /* Add PC-relative GOT table address. */ 643 | #define R_ARM_GOT32 26 /* Add PC-relative GOT offset. */ 644 | #define R_ARM_PLT32 27 /* Add PC-relative PLT offset. */ 645 | #define R_ARM_GNU_VTENTRY 100 646 | #define R_ARM_GNU_VTINHERIT 101 647 | #define R_ARM_RSBREL32 250 648 | #define R_ARM_THM_RPC22 251 649 | #define R_ARM_RREL32 252 650 | #define R_ARM_RABS32 253 651 | #define R_ARM_RPC24 254 652 | #define R_ARM_RBASE 255 653 | 654 | /* Name Value Field Calculation */ 655 | #define R_IA_64_NONE 0 /* None */ 656 | #define R_IA_64_IMM14 0x21 /* immediate14 S + A */ 657 | #define R_IA_64_IMM22 0x22 /* immediate22 S + A */ 658 | #define R_IA_64_IMM64 0x23 /* immediate64 S + A */ 659 | #define R_IA_64_DIR32MSB 0x24 /* word32 MSB S + A */ 660 | #define R_IA_64_DIR32LSB 0x25 /* word32 LSB S + A */ 661 | #define R_IA_64_DIR64MSB 0x26 /* word64 MSB S + A */ 662 | #define R_IA_64_DIR64LSB 0x27 /* word64 LSB S + A */ 663 | #define R_IA_64_GPREL22 0x2a /* immediate22 @gprel(S + A) */ 664 | #define R_IA_64_GPREL64I 0x2b /* immediate64 @gprel(S + A) */ 665 | #define R_IA_64_GPREL32MSB 0x2c /* word32 MSB @gprel(S + A) */ 666 | #define R_IA_64_GPREL32LSB 0x2d /* word32 LSB @gprel(S + A) */ 667 | #define R_IA_64_GPREL64MSB 0x2e /* word64 MSB @gprel(S + A) */ 668 | #define R_IA_64_GPREL64LSB 0x2f /* word64 LSB @gprel(S + A) */ 669 | #define R_IA_64_LTOFF22 0x32 /* immediate22 @ltoff(S + A) */ 670 | #define R_IA_64_LTOFF64I 0x33 /* immediate64 @ltoff(S + A) */ 671 | #define R_IA_64_PLTOFF22 0x3a /* immediate22 @pltoff(S + A) */ 672 | #define R_IA_64_PLTOFF64I 0x3b /* immediate64 @pltoff(S + A) */ 673 | #define R_IA_64_PLTOFF64MSB 0x3e /* word64 MSB @pltoff(S + A) */ 674 | #define R_IA_64_PLTOFF64LSB 0x3f /* word64 LSB @pltoff(S + A) */ 675 | #define R_IA_64_FPTR64I 0x43 /* immediate64 @fptr(S + A) */ 676 | #define R_IA_64_FPTR32MSB 0x44 /* word32 MSB @fptr(S + A) */ 677 | #define R_IA_64_FPTR32LSB 0x45 /* word32 LSB @fptr(S + A) */ 678 | #define R_IA_64_FPTR64MSB 0x46 /* word64 MSB @fptr(S + A) */ 679 | #define R_IA_64_FPTR64LSB 0x47 /* word64 LSB @fptr(S + A) */ 680 | #define R_IA_64_PCREL60B 0x48 /* immediate60 form1 S + A - P */ 681 | #define R_IA_64_PCREL21B 0x49 /* immediate21 form1 S + A - P */ 682 | #define R_IA_64_PCREL21M 0x4a /* immediate21 form2 S + A - P */ 683 | #define R_IA_64_PCREL21F 0x4b /* immediate21 form3 S + A - P */ 684 | #define R_IA_64_PCREL32MSB 0x4c /* word32 MSB S + A - P */ 685 | #define R_IA_64_PCREL32LSB 0x4d /* word32 LSB S + A - P */ 686 | #define R_IA_64_PCREL64MSB 0x4e /* word64 MSB S + A - P */ 687 | #define R_IA_64_PCREL64LSB 0x4f /* word64 LSB S + A - P */ 688 | #define R_IA_64_LTOFF_FPTR22 0x52 /* immediate22 @ltoff(@fptr(S + A)) */ 689 | #define R_IA_64_LTOFF_FPTR64I 0x53 /* immediate64 @ltoff(@fptr(S + A)) */ 690 | #define R_IA_64_LTOFF_FPTR32MSB 0x54 /* word32 MSB @ltoff(@fptr(S + A)) */ 691 | #define R_IA_64_LTOFF_FPTR32LSB 0x55 /* word32 LSB @ltoff(@fptr(S + A)) */ 692 | #define R_IA_64_LTOFF_FPTR64MSB 0x56 /* word64 MSB @ltoff(@fptr(S + A)) */ 693 | #define R_IA_64_LTOFF_FPTR64LSB 0x57 /* word64 LSB @ltoff(@fptr(S + A)) */ 694 | #define R_IA_64_SEGREL32MSB 0x5c /* word32 MSB @segrel(S + A) */ 695 | #define R_IA_64_SEGREL32LSB 0x5d /* word32 LSB @segrel(S + A) */ 696 | #define R_IA_64_SEGREL64MSB 0x5e /* word64 MSB @segrel(S + A) */ 697 | #define R_IA_64_SEGREL64LSB 0x5f /* word64 LSB @segrel(S + A) */ 698 | #define R_IA_64_SECREL32MSB 0x64 /* word32 MSB @secrel(S + A) */ 699 | #define R_IA_64_SECREL32LSB 0x65 /* word32 LSB @secrel(S + A) */ 700 | #define R_IA_64_SECREL64MSB 0x66 /* word64 MSB @secrel(S + A) */ 701 | #define R_IA_64_SECREL64LSB 0x67 /* word64 LSB @secrel(S + A) */ 702 | #define R_IA_64_REL32MSB 0x6c /* word32 MSB BD + A */ 703 | #define R_IA_64_REL32LSB 0x6d /* word32 LSB BD + A */ 704 | #define R_IA_64_REL64MSB 0x6e /* word64 MSB BD + A */ 705 | #define R_IA_64_REL64LSB 0x6f /* word64 LSB BD + A */ 706 | #define R_IA_64_LTV32MSB 0x74 /* word32 MSB S + A */ 707 | #define R_IA_64_LTV32LSB 0x75 /* word32 LSB S + A */ 708 | #define R_IA_64_LTV64MSB 0x76 /* word64 MSB S + A */ 709 | #define R_IA_64_LTV64LSB 0x77 /* word64 LSB S + A */ 710 | #define R_IA_64_PCREL21BI 0x79 /* immediate21 form1 S + A - P */ 711 | #define R_IA_64_PCREL22 0x7a /* immediate22 S + A - P */ 712 | #define R_IA_64_PCREL64I 0x7b /* immediate64 S + A - P */ 713 | #define R_IA_64_IPLTMSB 0x80 /* function descriptor MSB special */ 714 | #define R_IA_64_IPLTLSB 0x81 /* function descriptor LSB speciaal */ 715 | #define R_IA_64_SUB 0x85 /* immediate64 A - S */ 716 | #define R_IA_64_LTOFF22X 0x86 /* immediate22 special */ 717 | #define R_IA_64_LDXMOV 0x87 /* immediate22 special */ 718 | #define R_IA_64_TPREL14 0x91 /* imm14 @tprel(S + A) */ 719 | #define R_IA_64_TPREL22 0x92 /* imm22 @tprel(S + A) */ 720 | #define R_IA_64_TPREL64I 0x93 /* imm64 @tprel(S + A) */ 721 | #define R_IA_64_TPREL64MSB 0x96 /* word64 MSB @tprel(S + A) */ 722 | #define R_IA_64_TPREL64LSB 0x97 /* word64 LSB @tprel(S + A) */ 723 | #define R_IA_64_LTOFF_TPREL22 0x9a /* imm22 @ltoff(@tprel(S+A)) */ 724 | #define R_IA_64_DTPMOD64MSB 0xa6 /* word64 MSB @dtpmod(S + A) */ 725 | #define R_IA_64_DTPMOD64LSB 0xa7 /* word64 LSB @dtpmod(S + A) */ 726 | #define R_IA_64_LTOFF_DTPMOD22 0xaa /* imm22 @ltoff(@dtpmod(S+A)) */ 727 | #define R_IA_64_DTPREL14 0xb1 /* imm14 @dtprel(S + A) */ 728 | #define R_IA_64_DTPREL22 0xb2 /* imm22 @dtprel(S + A) */ 729 | #define R_IA_64_DTPREL64I 0xb3 /* imm64 @dtprel(S + A) */ 730 | #define R_IA_64_DTPREL32MSB 0xb4 /* word32 MSB @dtprel(S + A) */ 731 | #define R_IA_64_DTPREL32LSB 0xb5 /* word32 LSB @dtprel(S + A) */ 732 | #define R_IA_64_DTPREL64MSB 0xb6 /* word64 MSB @dtprel(S + A) */ 733 | #define R_IA_64_DTPREL64LSB 0xb7 /* word64 LSB @dtprel(S + A) */ 734 | #define R_IA_64_LTOFF_DTPREL22 0xba /* imm22 @ltoff(@dtprel(S+A)) */ 735 | 736 | #define R_MIPS_NONE 0 /* No reloc */ 737 | #define R_MIPS_16 1 /* Direct 16 bit */ 738 | #define R_MIPS_32 2 /* Direct 32 bit */ 739 | #define R_MIPS_REL32 3 /* PC relative 32 bit */ 740 | #define R_MIPS_26 4 /* Direct 26 bit shifted */ 741 | #define R_MIPS_HI16 5 /* High 16 bit */ 742 | #define R_MIPS_LO16 6 /* Low 16 bit */ 743 | #define R_MIPS_GPREL16 7 /* GP relative 16 bit */ 744 | #define R_MIPS_LITERAL 8 /* 16 bit literal entry */ 745 | #define R_MIPS_GOT16 9 /* 16 bit GOT entry */ 746 | #define R_MIPS_PC16 10 /* PC relative 16 bit */ 747 | #define R_MIPS_CALL16 11 /* 16 bit GOT entry for function */ 748 | #define R_MIPS_GPREL32 12 /* GP relative 32 bit */ 749 | #define R_MIPS_GOTHI16 21 /* GOT HI 16 bit */ 750 | #define R_MIPS_GOTLO16 22 /* GOT LO 16 bit */ 751 | #define R_MIPS_CALLHI16 30 /* upper 16 bit GOT entry for function */ 752 | #define R_MIPS_CALLLO16 31 /* lower 16 bit GOT entry for function */ 753 | 754 | #define R_PPC_NONE 0 /* No relocation. */ 755 | #define R_PPC_ADDR32 1 756 | #define R_PPC_ADDR24 2 757 | #define R_PPC_ADDR16 3 758 | #define R_PPC_ADDR16_LO 4 759 | #define R_PPC_ADDR16_HI 5 760 | #define R_PPC_ADDR16_HA 6 761 | #define R_PPC_ADDR14 7 762 | #define R_PPC_ADDR14_BRTAKEN 8 763 | #define R_PPC_ADDR14_BRNTAKEN 9 764 | #define R_PPC_REL24 10 765 | #define R_PPC_REL14 11 766 | #define R_PPC_REL14_BRTAKEN 12 767 | #define R_PPC_REL14_BRNTAKEN 13 768 | #define R_PPC_GOT16 14 769 | #define R_PPC_GOT16_LO 15 770 | #define R_PPC_GOT16_HI 16 771 | #define R_PPC_GOT16_HA 17 772 | #define R_PPC_PLTREL24 18 773 | #define R_PPC_COPY 19 774 | #define R_PPC_GLOB_DAT 20 775 | #define R_PPC_JMP_SLOT 21 776 | #define R_PPC_RELATIVE 22 777 | #define R_PPC_LOCAL24PC 23 778 | #define R_PPC_UADDR32 24 779 | #define R_PPC_UADDR16 25 780 | #define R_PPC_REL32 26 781 | #define R_PPC_PLT32 27 782 | #define R_PPC_PLTREL32 28 783 | #define R_PPC_PLT16_LO 29 784 | #define R_PPC_PLT16_HI 30 785 | #define R_PPC_PLT16_HA 31 786 | #define R_PPC_SDAREL16 32 787 | #define R_PPC_SECTOFF 33 788 | #define R_PPC_SECTOFF_LO 34 789 | #define R_PPC_SECTOFF_HI 35 790 | #define R_PPC_SECTOFF_HA 36 791 | 792 | /* 793 | * 64-bit relocations 794 | */ 795 | #define R_PPC64_ADDR64 38 796 | #define R_PPC64_ADDR16_HIGHER 39 797 | #define R_PPC64_ADDR16_HIGHERA 40 798 | #define R_PPC64_ADDR16_HIGHEST 41 799 | #define R_PPC64_ADDR16_HIGHESTA 42 800 | #define R_PPC64_UADDR64 43 801 | #define R_PPC64_REL64 44 802 | #define R_PPC64_PLT64 45 803 | #define R_PPC64_PLTREL64 46 804 | #define R_PPC64_TOC16 47 805 | #define R_PPC64_TOC16_LO 48 806 | #define R_PPC64_TOC16_HI 49 807 | #define R_PPC64_TOC16_HA 50 808 | #define R_PPC64_TOC 51 809 | #define R_PPC64_DTPMOD64 68 810 | #define R_PPC64_TPREL64 73 811 | #define R_PPC64_DTPREL64 78 812 | 813 | /* 814 | * TLS relocations 815 | */ 816 | #define R_PPC_TLS 67 817 | #define R_PPC_DTPMOD32 68 818 | #define R_PPC_TPREL16 69 819 | #define R_PPC_TPREL16_LO 70 820 | #define R_PPC_TPREL16_HI 71 821 | #define R_PPC_TPREL16_HA 72 822 | #define R_PPC_TPREL32 73 823 | #define R_PPC_DTPREL16 74 824 | #define R_PPC_DTPREL16_LO 75 825 | #define R_PPC_DTPREL16_HI 76 826 | #define R_PPC_DTPREL16_HA 77 827 | #define R_PPC_DTPREL32 78 828 | #define R_PPC_GOT_TLSGD16 79 829 | #define R_PPC_GOT_TLSGD16_LO 80 830 | #define R_PPC_GOT_TLSGD16_HI 81 831 | #define R_PPC_GOT_TLSGD16_HA 82 832 | #define R_PPC_GOT_TLSLD16 83 833 | #define R_PPC_GOT_TLSLD16_LO 84 834 | #define R_PPC_GOT_TLSLD16_HI 85 835 | #define R_PPC_GOT_TLSLD16_HA 86 836 | #define R_PPC_GOT_TPREL16 87 837 | #define R_PPC_GOT_TPREL16_LO 88 838 | #define R_PPC_GOT_TPREL16_HI 89 839 | #define R_PPC_GOT_TPREL16_HA 90 840 | 841 | /* 842 | * The remaining relocs are from the Embedded ELF ABI, and are not in the 843 | * SVR4 ELF ABI. 844 | */ 845 | 846 | #define R_PPC_EMB_NADDR32 101 847 | #define R_PPC_EMB_NADDR16 102 848 | #define R_PPC_EMB_NADDR16_LO 103 849 | #define R_PPC_EMB_NADDR16_HI 104 850 | #define R_PPC_EMB_NADDR16_HA 105 851 | #define R_PPC_EMB_SDAI16 106 852 | #define R_PPC_EMB_SDA2I16 107 853 | #define R_PPC_EMB_SDA2REL 108 854 | #define R_PPC_EMB_SDA21 109 855 | #define R_PPC_EMB_MRKREF 110 856 | #define R_PPC_EMB_RELSEC16 111 857 | #define R_PPC_EMB_RELST_LO 112 858 | #define R_PPC_EMB_RELST_HI 113 859 | #define R_PPC_EMB_RELST_HA 114 860 | #define R_PPC_EMB_BIT_FLD 115 861 | #define R_PPC_EMB_RELSDA 116 862 | 863 | #define R_SPARC_NONE 0 864 | #define R_SPARC_8 1 865 | #define R_SPARC_16 2 866 | #define R_SPARC_32 3 867 | #define R_SPARC_DISP8 4 868 | #define R_SPARC_DISP16 5 869 | #define R_SPARC_DISP32 6 870 | #define R_SPARC_WDISP30 7 871 | #define R_SPARC_WDISP22 8 872 | #define R_SPARC_HI22 9 873 | #define R_SPARC_22 10 874 | #define R_SPARC_13 11 875 | #define R_SPARC_LO10 12 876 | #define R_SPARC_GOT10 13 877 | #define R_SPARC_GOT13 14 878 | #define R_SPARC_GOT22 15 879 | #define R_SPARC_PC10 16 880 | #define R_SPARC_PC22 17 881 | #define R_SPARC_WPLT30 18 882 | #define R_SPARC_COPY 19 883 | #define R_SPARC_GLOB_DAT 20 884 | #define R_SPARC_JMP_SLOT 21 885 | #define R_SPARC_RELATIVE 22 886 | #define R_SPARC_UA32 23 887 | #define R_SPARC_PLT32 24 888 | #define R_SPARC_HIPLT22 25 889 | #define R_SPARC_LOPLT10 26 890 | #define R_SPARC_PCPLT32 27 891 | #define R_SPARC_PCPLT22 28 892 | #define R_SPARC_PCPLT10 29 893 | #define R_SPARC_10 30 894 | #define R_SPARC_11 31 895 | #define R_SPARC_64 32 896 | #define R_SPARC_OLO10 33 897 | #define R_SPARC_HH22 34 898 | #define R_SPARC_HM10 35 899 | #define R_SPARC_LM22 36 900 | #define R_SPARC_PC_HH22 37 901 | #define R_SPARC_PC_HM10 38 902 | #define R_SPARC_PC_LM22 39 903 | #define R_SPARC_WDISP16 40 904 | #define R_SPARC_WDISP19 41 905 | #define R_SPARC_GLOB_JMP 42 906 | #define R_SPARC_7 43 907 | #define R_SPARC_5 44 908 | #define R_SPARC_6 45 909 | #define R_SPARC_DISP64 46 910 | #define R_SPARC_PLT64 47 911 | #define R_SPARC_HIX22 48 912 | #define R_SPARC_LOX10 49 913 | #define R_SPARC_H44 50 914 | #define R_SPARC_M44 51 915 | #define R_SPARC_L44 52 916 | #define R_SPARC_REGISTER 53 917 | #define R_SPARC_UA64 54 918 | #define R_SPARC_UA16 55 919 | #define R_SPARC_TLS_GD_HI22 56 920 | #define R_SPARC_TLS_GD_LO10 57 921 | #define R_SPARC_TLS_GD_ADD 58 922 | #define R_SPARC_TLS_GD_CALL 59 923 | #define R_SPARC_TLS_LDM_HI22 60 924 | #define R_SPARC_TLS_LDM_LO10 61 925 | #define R_SPARC_TLS_LDM_ADD 62 926 | #define R_SPARC_TLS_LDM_CALL 63 927 | #define R_SPARC_TLS_LDO_HIX22 64 928 | #define R_SPARC_TLS_LDO_LOX10 65 929 | #define R_SPARC_TLS_LDO_ADD 66 930 | #define R_SPARC_TLS_IE_HI22 67 931 | #define R_SPARC_TLS_IE_LO10 68 932 | #define R_SPARC_TLS_IE_LD 69 933 | #define R_SPARC_TLS_IE_LDX 70 934 | #define R_SPARC_TLS_IE_ADD 71 935 | #define R_SPARC_TLS_LE_HIX22 72 936 | #define R_SPARC_TLS_LE_LOX10 73 937 | #define R_SPARC_TLS_DTPMOD32 74 938 | #define R_SPARC_TLS_DTPMOD64 75 939 | #define R_SPARC_TLS_DTPOFF32 76 940 | #define R_SPARC_TLS_DTPOFF64 77 941 | #define R_SPARC_TLS_TPOFF32 78 942 | #define R_SPARC_TLS_TPOFF64 79 943 | 944 | #define R_X86_64_NONE 0 /* No relocation. */ 945 | #define R_X86_64_64 1 /* Add 64 bit symbol value. */ 946 | #define R_X86_64_PC32 2 /* PC-relative 32 bit signed sym value. */ 947 | #define R_X86_64_GOT32 3 /* PC-relative 32 bit GOT offset. */ 948 | #define R_X86_64_PLT32 4 /* PC-relative 32 bit PLT offset. */ 949 | #define R_X86_64_COPY 5 /* Copy data from shared object. */ 950 | #define R_X86_64_GLOB_DAT 6 /* Set GOT entry to data address. */ 951 | #define R_X86_64_JMP_SLOT 7 /* Set GOT entry to code address. */ 952 | #define R_X86_64_RELATIVE 8 /* Add load address of shared object. */ 953 | #define R_X86_64_GOTPCREL 9 /* Add 32 bit signed pcrel offset to GOT. */ 954 | #define R_X86_64_32 10 /* Add 32 bit zero extended symbol value */ 955 | #define R_X86_64_32S 11 /* Add 32 bit sign extended symbol value */ 956 | #define R_X86_64_16 12 /* Add 16 bit zero extended symbol value */ 957 | #define R_X86_64_PC16 13 /* Add 16 bit signed extended pc relative symbol value */ 958 | #define R_X86_64_8 14 /* Add 8 bit zero extended symbol value */ 959 | #define R_X86_64_PC8 15 /* Add 8 bit signed extended pc relative symbol value */ 960 | #define R_X86_64_DTPMOD64 16 /* ID of module containing symbol */ 961 | #define R_X86_64_DTPOFF64 17 /* Offset in TLS block */ 962 | #define R_X86_64_TPOFF64 18 /* Offset in static TLS block */ 963 | #define R_X86_64_TLSGD 19 /* PC relative offset to GD GOT entry */ 964 | #define R_X86_64_TLSLD 20 /* PC relative offset to LD GOT entry */ 965 | #define R_X86_64_DTPOFF32 21 /* Offset in TLS block */ 966 | #define R_X86_64_GOTTPOFF 22 /* PC relative offset to IE GOT entry */ 967 | #define R_X86_64_TPOFF32 23 /* Offset in static TLS block */ 968 | 969 | #endif /* !_SYS_ELF_COMMON_H_ */ 970 | -------------------------------------------------------------------------------- /libPS4/include/eventflag.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef EVENTFLAG_H 4 | #define EVENTFLAG_H 5 | 6 | #include "types.h" 7 | 8 | int createEventFlag(const char *name); 9 | int destroyEventFlag(int eventFlag); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /libPS4/include/file.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef FILE_H 4 | #define FILE_H 5 | 6 | #include "types.h" 7 | 8 | #define O_RDONLY 0x0000 9 | #define O_WRONLY 0x0001 10 | #define O_RDWR 0x0002 11 | #define O_ACCMODE 0x0003 12 | 13 | #define O_NONBLOCK 0x0004 /* no delay */ 14 | #define O_APPEND 0x0008 /* set append mode */ 15 | #define O_CREAT 0x0200 /* create if nonexistent */ 16 | #define O_TRUNC 0x0400 /* truncate to zero length */ 17 | #define O_EXCL 0x0800 /* error if already exists */ 18 | 19 | #define S_ISDIR(m) (((m)&0170000) == 0040000) 20 | #define S_ISCHR(m) (((m)&0170000) == 0020000) 21 | #define S_ISBLK(m) (((m)&0170000) == 0060000) 22 | #define S_ISREG(m) (((m)&0170000) == 0100000) 23 | #define S_ISFIFO(m) (((m)&0170000) == 0010000) 24 | #define S_ISLNK(m) (((m)&0170000) == 0120000) 25 | #define S_ISSOCK(m) (((m)&0170000) == 0140000) 26 | #define S_ISWHT(m) (((m)&0170000) == 0160000) 27 | 28 | #define PATH_MAX 255 29 | 30 | #define MNT_UPDATE 0x0000000000010000ULL /* not real mount, just update */ 31 | 32 | struct stat { 33 | dev_t st_dev; /* inode's device */ 34 | ino_t st_ino; /* inode's number */ 35 | mode_t st_mode; /* inode protection mode */ 36 | nlink_t st_nlink; /* number of hard links */ 37 | uid_t st_uid; /* user ID of the file's owner */ 38 | gid_t st_gid; /* group ID of the file's group */ 39 | dev_t st_rdev; /* device type */ 40 | struct timespec st_atim; /* time of last access */ 41 | struct timespec st_mtim; /* time of last data modification */ 42 | struct timespec st_ctim; /* time of last file status change */ 43 | off_t st_size; /* file size, in bytes */ 44 | blkcnt_t st_blocks; /* blocks allocated for file */ 45 | blksize_t st_blksize; /* optimal blocksize for I/O */ 46 | fflags_t st_flags; /* user defined flags for file */ 47 | uint32_t st_gen; /* file generation number */ 48 | int32_t st_lspare; 49 | struct timespec st_birthtim; /* time of file creation */ 50 | unsigned int : (8 / 2) * (16 - (int)sizeof(struct timespec)); 51 | unsigned int : (8 / 2) * (16 - (int)sizeof(struct timespec)); 52 | }; 53 | 54 | struct dirent { 55 | uint32_t d_fileno; 56 | uint16_t d_reclen; 57 | uint8_t d_type; 58 | uint8_t d_namlen; 59 | char d_name[255 + 1]; 60 | }; 61 | 62 | struct iovec { 63 | void *iov_base; 64 | size_t iov_len; 65 | }; 66 | 67 | ssize_t read(int fd, void *buf, size_t nbyte); 68 | ssize_t write(int fd, const void *buf, size_t count); 69 | int open(const char *path, int flags, int mode); 70 | int close(int fd); 71 | int link(const char *path, const char *link); 72 | int unlink(const char *pathname); 73 | int readlink(const char *path, char *buf, int bufsiz); 74 | int symlink(const char *path, const char *link); 75 | int mount(const char *type, const char *dir, int flags, void *data); 76 | int nmount(struct iovec *iov, uint32_t niov, int flags); 77 | int unmount(const char *dir, int flags); 78 | int fchown(int fd, int uid, int gid); 79 | int fchmod(int fd, int mode); 80 | int rename(const char *oldpath, const char *newpath); 81 | int mkdir(const char *pathname, mode_t mode); 82 | int rmdir(const char *path); 83 | int stat(const char *path, struct stat *sb); 84 | int fstat(int fd, struct stat *sb); 85 | int fstatat(int fd, const char *path, struct stat *buf, int flag); 86 | int lstat(const char *path, struct stat *buf); 87 | int getdents(int fd, char *buf, int count); 88 | off_t lseek(int fildes, off_t offset, int whence); 89 | int getSandboxDirectory(char *destination, int *length); 90 | int file_exists(char *fname); 91 | int dir_exists(char *dname); 92 | int symlink_exists(const char *fname); 93 | void touch_file(char *destfile); 94 | void copy_file(char *sourcefile, char *destfile); 95 | void copy_dir(char *sourcedir, char *destdir); 96 | int file_compare(char *fname1, char *fname2); 97 | int rmtree(const char *path); 98 | int fgetc_pointer(int fp); 99 | int mount_large_fs(const char *device, const char *mountpoint, const char *fstype, const char *mode, unsigned int flags); 100 | void create_iovec(struct iovec **iov, int *iovlen, const char *name, const void *val, size_t len); 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /libPS4/include/graphics.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef GRAPHICS_H 4 | #define GRAPHICS_H 5 | 6 | #define RGB(r, g, b) ((r) | ((g) << 8) | ((b) << 16) | (0xff << 24)) 7 | 8 | #define RED 0xff0000ff 9 | #define GREEN 0xff00ff00 10 | #define BLUE 0xffff0000 11 | 12 | #define WHITE 0xffffffff 13 | #define BLACK 0xff000000 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /libPS4/include/jit.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef JIT_H 4 | #define JIT_H 5 | 6 | #include "types.h" 7 | 8 | extern int (*sceKernelJitCreateSharedMemory)(int flags, size_t size, int protection, int *destinationHandle); 9 | extern int (*sceKernelJitCreateAliasOfSharedMemory)(int handle, int protection, int *destinationHandle); 10 | extern int (*sceKernelJitMapSharedMemory)(int handle, int protection, void **destination); 11 | 12 | void initJIT(void); 13 | 14 | void allocateJIT(size_t size, void **executableAddress, void **writableAddress); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /libPS4/include/kernel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef KERNEL_H 4 | #define KERNEL_H 5 | 6 | #include "types.h" 7 | 8 | typedef struct { 9 | uint64_t unk1; 10 | char version_string[0x1C]; 11 | uint32_t version; 12 | } SceFwInfo; 13 | 14 | typedef struct { 15 | int type; //0x00 16 | int req_id; //0x04 17 | int priority; //0x08 18 | int msg_id; //0x0C 19 | int target_id; //0x10 20 | int user_id; //0x14 21 | int unk1; //0x18 22 | int unk2; //0x1C 23 | int app_id; //0x20 24 | int error_num; //0x24 25 | int unk3; //0x28 26 | char use_icon_image_uri; //0x2C 27 | char message[1024]; //0x2D 28 | char uri[1024]; //0x42D 29 | char unkstr[1024]; //0x82D 30 | } SceNotificationRequest; //Size = 0xC30 31 | 32 | typedef struct timeval SceKernelTimeval; 33 | typedef uint64_t SceKernelEqueue; 34 | 35 | extern int libKernelHandle; 36 | 37 | extern int **__stack_chk_guard; 38 | extern void (*__stack_chk_fail)(void); 39 | extern int *(*__error)(); 40 | #define errno (*__error()) 41 | 42 | extern int (*sceKernelError)(int); 43 | 44 | extern int (*sceKernelLoadStartModule)(const char *name, size_t argc, const void *argv, unsigned int flags, int, int); 45 | 46 | extern int (*sceKernelAllocateDirectMemory)(off_t searchStart, off_t searchEnd, size_t length, size_t alignment, int type, off_t *physicalAddressDestination); 47 | extern int (*sceKernelMapDirectMemory)(void **addr, size_t length, int protection, int flags, off_t start, size_t alignment); 48 | extern size_t (*sceKernelGetDirectMemorySize)(); 49 | 50 | extern int (*sceKernelStat)(const char *path, void *buf); 51 | extern int (*sceKernelOpen)(const char *path, int flags, int mode); 52 | extern int (*sceKernelRead)(int fd, void *buf, size_t nbyte); 53 | extern int (*sceKernelLseek)(int fd, off_t offset, int whence); 54 | extern int (*sceKernelClose)(int fd); 55 | 56 | extern unsigned int (*sceKernelSleep)(unsigned int seconds); 57 | extern int (*sceKernelUsleep)(unsigned int microseconds); 58 | extern int (*usleep)(unsigned int microseconds); 59 | extern int (*sceKernelGettimeofday)(SceKernelTimeval *tp); 60 | extern uint64_t (*sceKernelGetProcessTime)(void); 61 | extern int (*sceKernelGetCurrentCpu)(void); 62 | 63 | extern int (*sysctl)(int *name, unsigned int namelen, char *oldval, size_t *oldlen, char *newval, size_t newlen); 64 | extern int (*sysctlbyname)(char *name, char *oldval, size_t *oldlen, char *newval, size_t newlen); 65 | extern int (*sysarch)(int type, void *arg); 66 | extern int (*execve)(char *path, char *argv[], char *envp[]); 67 | int ioctl(int fd, unsigned long com, void *data); 68 | 69 | extern void *(*pthread_self)(); 70 | extern int (*pthread_setaffinity_np)(void *one, long unsigned int two, void *three); 71 | 72 | extern int (*sceKernelCreateEqueue)(SceKernelEqueue *eq, const char *name); 73 | extern int (*sceKernelDeleteEqueue)(SceKernelEqueue eq); 74 | extern int (*sceKernelAddUserEvent)(SceKernelEqueue eq, int id); 75 | extern int (*sceKernelAddReadEvent)(SceKernelEqueue eq, int fd, size_t size, void *udata); 76 | 77 | extern int (*getuid)(); 78 | extern int (*getgid)(); 79 | extern int (*getpid)(); 80 | 81 | extern int (*setuid)(int uid); 82 | extern int (*setgid)(int gid); 83 | extern int (*setreuid)(int ruid, int euid); 84 | extern int (*setregid)(int rgid, int egid); 85 | 86 | extern int (*sceKernelSendNotificationRequest)(int device, SceNotificationRequest *req, size_t size, int blocking); 87 | extern const char *(*sceKernelGetFsSandboxRandomWord)(); 88 | extern int (*sceKernelGetSystemSwVersion)(SceFwInfo *fw_info); 89 | 90 | extern uint32_t (*sceKernelGetCpuTemperature)(uint32_t *); 91 | 92 | extern uint32_t (*sceKernelGetIdPs)(void *); 93 | extern uint32_t (*sceKernelGetOpenPsId)(void *); 94 | extern uint32_t (*sceKernelGetOpenPsIdForSystem)(void *); 95 | 96 | int kill(int pid, int signum); 97 | 98 | void initKernel(void); 99 | 100 | int kexec(void *func, void *user_arg); 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /libPS4/include/libc.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef LIBC_H 4 | #define LIBC_H 5 | 6 | #include "types.h" 7 | 8 | typedef struct DIR DIR; 9 | typedef int FILE; 10 | 11 | #define SEEK_SET 0 12 | #define SEEK_CUR 1 13 | #define SEEK_END 2 14 | 15 | extern void *(*malloc)(size_t size); 16 | extern void (*free)(void *ptr); 17 | extern void *(*calloc)(size_t num, size_t size); 18 | extern void *(*realloc)(void *ptr, size_t size); 19 | extern void *(*memalign)(size_t boundary, size_t size); 20 | extern void *(*memset)(void *destination, int value, size_t num); 21 | extern void *(*memcpy)(void *destination, const void *source, size_t num); 22 | extern int (*memcmp)(const void *s1, const void *s2, size_t n); 23 | extern void *(*memmove)(void *dst, const void *src, size_t len); 24 | extern errno_t (*memmove_s)(void *dest, rsize_t destsz, const void *src, rsize_t count); 25 | extern char *(*strcpy)(char *destination, const char *source); 26 | extern char *(*strncpy)(char *destination, const char *source, size_t num); 27 | extern errno_t *(*strncpy_s)(char *restrict dest, rsize_t destsz, const char *restrict src, rsize_t count); 28 | extern char *(*strcat)(char *dest, const char *src); 29 | extern char *(*strncat)(char *dest, const char *src, size_t n); 30 | extern size_t (*strlen)(const char *s); 31 | extern int (*strcmp)(const char *s1, const char *s2); 32 | extern int (*strncmp)(const char *s1, const char *s2, size_t n); 33 | extern int (*sprintf)(char *str, const char *format, ...); 34 | extern int (*snprintf)(char *str, size_t size, const char *format, ...); 35 | extern int (*snprintf_s)(char *restrict buffer, rsize_t bufsz, const char *restrict format, ...); 36 | extern int (*sscanf)(const char *str, const char *format, ...); 37 | extern int (*strtol)(const char* s1, char** s2, int base); 38 | extern char *(*strtok)(char *str, const char *delimiters); 39 | extern char *(*strchr)(const char *s, int c); 40 | extern char *(*strrchr)(const char *s, int c); 41 | extern char *(*strstr)(char *str1, char *str2); 42 | extern char *(*strdup)(const char *s); 43 | extern char *(*strtok)(char *str, const char *sep); 44 | extern char *(*index)(const char *s, int c); 45 | extern char *(*rindex)(const char *s, int c); 46 | extern char *(*rindex)(const char *s, int c); 47 | extern int (*isdigit)(int c); 48 | extern int (*atoi)(const char *s); 49 | extern double (*atof)(const char *s); 50 | extern size_t (*strlcpy)(char *dst, const char *src, size_t size); 51 | extern char *(*strerror)(int errnum); 52 | extern void *(*_Getpctype)(); 53 | extern unsigned long (*_Stoul)(const char *, char **, int); 54 | extern void (*bcopy)(const void *s1, void *s2, size_t n); 55 | extern double (*ceil)(double x); 56 | 57 | extern void (*srand)(unsigned int seed); 58 | extern int (*rand)(void); 59 | 60 | extern char *(*asctime)(const struct tm *tm); 61 | extern char *(*asctime_r)(const struct tm *tm, char *buf); 62 | extern char *(*ctime)(const time_t *timep); 63 | extern char *(*ctime_r)(const time_t *timep, char *buf); 64 | extern time_t (*time)(time_t *tloc); 65 | extern struct tm *(*gmtime)(const time_t *timep); 66 | extern struct tm *(*gmtime_s)(const time_t *timep, struct tm *result); 67 | extern struct tm *(*localtime)(const time_t *timep); 68 | extern struct tm *(*localtime_r)(const time_t *timep, struct tm *result); 69 | extern time_t (*mktime)(struct tm *tm); 70 | 71 | extern DIR *(*opendir)(const char *filename); 72 | extern struct dirent *(*readdir)(DIR *dirp); 73 | extern int (*readdir_r)(DIR *dirp, struct dirent *entry, struct dirent **result); 74 | extern long (*telldir)(const DIR *dirp); 75 | extern void (*seekdir)(DIR *dirp, long loc); 76 | extern void (*rewinddir)(DIR *dirp); 77 | extern int (*closedir)(DIR *dirp); 78 | extern int (*dirfd)(DIR *dirp); 79 | extern char *(*getprogname)(); 80 | 81 | extern FILE *(*fopen)(const char *filename, const char *mode); 82 | extern size_t (*fread)(void *ptr, size_t size, size_t count, FILE *stream); 83 | extern size_t (*fwrite)(const void *ptr, size_t size, size_t count, FILE *stream); 84 | extern int (*fseek)(FILE *stream, long int offset, int origin); 85 | extern long int (*ftell)(FILE *stream); 86 | extern int (*fclose)(FILE *stream); 87 | extern int (*fprintf)(FILE *stream, const char *format, ...); 88 | 89 | int memset_s(void *s, rsize_t smax, int c, rsize_t n); 90 | 91 | void initLibc(void); 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /libPS4/include/memory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef MEMORY_H 4 | #define MEMORY_H 5 | 6 | #include "types.h" 7 | 8 | #define PAGE_SIZE (16 * 1024) 9 | 10 | #define PROT_CPU_READ 1 11 | #define PROT_CPU_WRITE 2 12 | #define PROT_CPU_EXEC 4 13 | #define PROT_GPU_EXEC 8 14 | #define PROT_GPU_READ 16 15 | #define PROT_GPU_WRITE 32 16 | 17 | #define PROT_NONE 0 18 | #define PROT_READ PROT_CPU_READ 19 | #define PROT_WRITE PROT_CPU_WRITE 20 | #define PROT_EXEC PROT_CPU_EXEC 21 | 22 | #define MAP_SHARED 1 23 | #define MAP_PRIVATE 2 24 | #define MAP_TYPE 0xf 25 | #define MAP_FIXED 0x10 26 | #define MAP_ANONYMOUS 0x1000 27 | #define MAP_32BIT 0x80000 28 | 29 | #define MAP_FAILED (void *)-1 30 | 31 | #define MS_SYNC 0x0000 32 | #define MS_ASYNC 0x0001 33 | #define MS_INVALIDATE 0x0002 34 | 35 | struct memoryRegionInfo { 36 | void *base; // 0x0 37 | void *end; // 0x8 38 | unsigned int flags; // 0x16 39 | }; 40 | 41 | struct otherMemoryRegionInfo { 42 | void *base; // 0x0 43 | void *end; // 0x8 44 | char unknown[0xa]; // 0x16 45 | char name[32]; // 0x20 46 | }; 47 | 48 | void *mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset); 49 | int munmap(void *addr, size_t len); 50 | int mprotect(void *addr, size_t len, int prot); 51 | int msync(void *addr, size_t len, int flags); 52 | int mlock(void *addr, size_t len); 53 | int munlock(void *addr, size_t len); 54 | 55 | int getMemoryInfo(void *address, struct memoryRegionInfo *destination); 56 | int getOtherMemoryInfo(void *address, int nextMatchIfUnmapped, struct otherMemoryRegionInfo *destination); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /libPS4/include/module.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef MODULE_H 4 | #define MODULE_H 5 | 6 | #include "types.h" 7 | 8 | #define RESOLVE(module, name) getFunctionAddressByName(module, #name, &name) 9 | 10 | struct moduleInfo { 11 | size_t size; // 0x0 12 | char name[32]; // 0x8 13 | char padding1[0xe0]; // 0x28 14 | void *codeBase; // 0x108 15 | unsigned int codeSize; // 0x110 16 | void *dataBase; // 0x118 17 | unsigned int dataSize; // 0x120 18 | char padding2[0x3c]; // 0x124 19 | }; 20 | 21 | extern int (*sceSysmoduleLoadModule)(int id); 22 | 23 | int getFunctionAddressByName(int loadedModuleID, char *name, void *destination); 24 | int getLoadedModules(int *destination, int max, int *count); 25 | int getModuleInfo(int loadedModuleID, struct moduleInfo *destination); 26 | int loadModule(const char *name, int *idDestination); 27 | int unloadModule(int id); 28 | 29 | void initModule(void); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /libPS4/include/mutex.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef MUTEX_H 4 | #define MUTEX_H 5 | 6 | #include "types.h" 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /libPS4/include/network.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef NETWORK_H 4 | #define NETWORK_H 5 | 6 | #include "types.h" 7 | 8 | #define IP(a, b, c, d) (((a) << 0) + ((b) << 8) + ((c) << 16) + ((d) << 24)) 9 | #define htons(a) __builtin_bswap16(a) 10 | 11 | #define AF_INET 0x0002 12 | 13 | #define IN_ADDR_ANY 0 14 | 15 | #define SOCK_STREAM 1 16 | #define SOCK_DGRAM 2 17 | 18 | #define SOL_SOCKET 0xffff 19 | #define SO_NBIO 0x1200 20 | 21 | #define MSG_DONTWAIT 0x80 22 | #define MSG_WAITALL 0x40 23 | 24 | #define IPPROTO_TCP 6 25 | #define TCP_NODELAY 1 26 | 27 | enum { 28 | SCE_NET_IPPROTO_IP = 0, 29 | SCE_NET_IPPROTO_ICMP = 1, 30 | SCE_NET_IPPROTO_IGMP = 2, 31 | SCE_NET_IPPROTO_TCP = 6, 32 | SCE_NET_IPPROTO_UDP = 17, 33 | SCE_NET_SOL_SOCKET = 0xffff 34 | }; 35 | 36 | enum { 37 | SCE_NET_SO_REUSEADDR = 0x00000004, 38 | }; 39 | 40 | enum { 41 | SCE_NET_ERROR_EINTR = 0x80410104, 42 | }; 43 | 44 | enum { 45 | SCE_NET_SOCKET_ABORT_FLAG_RCV_PRESERVATION = 0x00000001, 46 | SCE_NET_SOCKET_ABORT_FLAG_SND_PRESERVATION = 0x00000002 47 | }; 48 | 49 | struct in_addr { 50 | unsigned int s_addr; 51 | }; 52 | 53 | struct sockaddr_in { 54 | unsigned char sin_len; 55 | unsigned char sin_family; 56 | unsigned short sin_port; 57 | struct in_addr sin_addr; 58 | unsigned short sin_vport; 59 | char sin_zero[6]; 60 | }; 61 | 62 | struct sockaddr { 63 | unsigned char sin_len; 64 | unsigned char sa_family; 65 | char sa_data[14]; 66 | }; 67 | 68 | typedef unsigned int socklen_t; 69 | 70 | /* info code */ 71 | #define SCE_NET_CTL_INFO_DEVICE 1 72 | #define SCE_NET_CTL_INFO_ETHER_ADDR 2 73 | #define SCE_NET_CTL_INFO_MTU 3 74 | #define SCE_NET_CTL_INFO_LINK 4 75 | #define SCE_NET_CTL_INFO_BSSID 5 76 | #define SCE_NET_CTL_INFO_SSID 6 77 | #define SCE_NET_CTL_INFO_WIFI_SECURITY 7 78 | #define SCE_NET_CTL_INFO_RSSI_DBM 8 79 | #define SCE_NET_CTL_INFO_RSSI_PERCENTAGE 9 80 | #define SCE_NET_CTL_INFO_CHANNEL 10 81 | #define SCE_NET_CTL_INFO_IP_CONFIG 11 82 | #define SCE_NET_CTL_INFO_DHCP_HOSTNAME 12 83 | #define SCE_NET_CTL_INFO_PPPOE_AUTH_NAME 13 84 | #define SCE_NET_CTL_INFO_IP_ADDRESS 14 85 | #define SCE_NET_CTL_INFO_NETMASK 15 86 | #define SCE_NET_CTL_INFO_DEFAULT_ROUTE 16 87 | #define SCE_NET_CTL_INFO_PRIMARY_DNS 17 88 | #define SCE_NET_CTL_INFO_SECONDARY_DNS 18 89 | #define SCE_NET_CTL_INFO_HTTP_PROXY_CONFIG 19 90 | #define SCE_NET_CTL_INFO_HTTP_PROXY_SERVER 20 91 | #define SCE_NET_CTL_INFO_HTTP_PROXY_PORT 21 92 | #define SCE_NET_CTL_INFO_RESERVED1 22 93 | #define SCE_NET_CTL_INFO_RESERVED2 23 94 | 95 | #define SCE_NET_ETHER_ADDR_LEN 6 96 | 97 | typedef struct SceNetEtherAddr { 98 | uint8_t data[SCE_NET_ETHER_ADDR_LEN]; 99 | } SceNetEtherAddr; 100 | 101 | #define SCE_NET_CTL_SSID_LEN (32 + 1) 102 | #define SCE_NET_CTL_HOSTNAME_LEN (255 + 1) 103 | #define SCE_NET_CTL_AUTH_NAME_LEN (127 + 1) 104 | #define SCE_NET_CTL_IPV4_ADDR_STR_LEN (16) 105 | 106 | typedef union SceNetCtlInfo { 107 | uint32_t device; 108 | SceNetEtherAddr ether_addr; 109 | uint32_t mtu; 110 | uint32_t link; 111 | SceNetEtherAddr bssid; 112 | char ssid[SCE_NET_CTL_SSID_LEN]; 113 | uint32_t wifi_security; 114 | uint8_t rssi_dbm; 115 | uint8_t rssi_percentage; 116 | uint8_t channel; 117 | uint32_t ip_config; 118 | char dhcp_hostname[SCE_NET_CTL_HOSTNAME_LEN]; 119 | char pppoe_auth_name[SCE_NET_CTL_AUTH_NAME_LEN]; 120 | char ip_address[SCE_NET_CTL_IPV4_ADDR_STR_LEN]; 121 | char netmask[SCE_NET_CTL_IPV4_ADDR_STR_LEN]; 122 | char default_route[SCE_NET_CTL_IPV4_ADDR_STR_LEN]; 123 | char primary_dns[SCE_NET_CTL_IPV4_ADDR_STR_LEN]; 124 | char secondary_dns[SCE_NET_CTL_IPV4_ADDR_STR_LEN]; 125 | uint32_t http_proxy_config; 126 | char http_proxy_server[SCE_NET_CTL_HOSTNAME_LEN]; 127 | uint16_t http_proxy_port; 128 | } SceNetCtlInfo; 129 | 130 | extern int *(*sceNetErrnoLoc)(void); 131 | #define sce_net_errno (*sceNetErrnoLoc()) 132 | 133 | extern int (*sceNetSocket)(const char *, int, int, int); 134 | extern int (*sceNetSocketClose)(int); 135 | extern int (*sceNetConnect)(int, struct sockaddr *, int); 136 | extern int (*sceNetSend)(int, const void *, size_t, int); 137 | extern int (*sceNetBind)(int, struct sockaddr *, int); 138 | extern int (*sceNetListen)(int, int); 139 | extern int (*sceNetAccept)(int, struct sockaddr *, unsigned int *); 140 | extern int (*sceNetRecv)(int, void *, size_t, int); 141 | extern int (*sceNetSocketAbort)(int, int); 142 | 143 | extern int (*sceNetGetsockname)(int, struct sockaddr *, unsigned int *); 144 | extern int (*sceNetGetsockopt)(int s, int level, int optname, void *restrict optval, socklen_t *restrict optlen); 145 | extern int (*sceNetSetsockopt)(int s, int level, int optname, const void *optval, socklen_t optlen); 146 | 147 | extern char (*sceNetInetNtop)(int af, const void *src, char *dst, int size); 148 | extern int (*sceNetInetPton)(int af, const char *src, void *dst); 149 | 150 | extern uint64_t (*sceNetHtonll)(uint64_t host64); 151 | extern uint32_t (*sceNetHtonl)(uint32_t host32); 152 | extern uint16_t (*sceNetHtons)(uint16_t host16); 153 | extern uint64_t (*sceNetNtohll)(uint64_t net64); 154 | extern uint32_t (*sceNetNtohl)(uint32_t net32); 155 | extern uint16_t (*sceNetNtohs)(uint16_t net16); 156 | 157 | extern int (*sceNetCtlInit)(void); 158 | extern void (*sceNetCtlTerm)(void); 159 | extern int (*sceNetCtlGetInfo)(int code, SceNetCtlInfo *info); 160 | 161 | void initNetwork(void); 162 | int SckConnect(char *hostIP, int hostPort); 163 | void SckClose(int socket); 164 | void SckSend(int socket, char *sdata, int length); 165 | char *SckRecv(int socket); 166 | void SckRecvf(int socket, char *destfile); 167 | 168 | #endif 169 | -------------------------------------------------------------------------------- /libPS4/include/pad.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef PAD_H 4 | #define PAD_H 5 | 6 | #include "types.h" 7 | 8 | extern int (*scePadInit)(void); 9 | extern int (*scePadOpen)(int userID, int, int, void *); 10 | extern int (*scePadClose)(int handle); 11 | extern int (*scePadRead)(int handle, void *data, int count); 12 | extern int (*scePadReadState)(int handle, void *data); 13 | 14 | void initPad(void); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /libPS4/include/payload_utils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef PAYLOAD_UTILS_H 4 | #define PAYLOAD_UTILS_H 5 | 6 | #include "types.h" 7 | 8 | struct auditinfo_addr { 9 | char useless[184]; 10 | }; 11 | 12 | struct ucred { 13 | uint32_t useless1; 14 | uint32_t cr_uid; 15 | uint32_t cr_ruid; 16 | uint32_t useless2; 17 | uint32_t useless3; 18 | uint32_t cr_rgid; 19 | uint32_t useless4; 20 | void *useless5; 21 | void *useless6; 22 | void *cr_prison; 23 | void *useless7; 24 | uint32_t useless8; 25 | void *useless9[2]; 26 | void *useless10; 27 | struct auditinfo_addr useless11; 28 | uint32_t *cr_groups; 29 | uint32_t useless12; 30 | }; 31 | 32 | struct filedesc { 33 | void *useless1[3]; 34 | void *fd_rdir; 35 | void *fd_jdir; 36 | }; 37 | 38 | struct proc { 39 | char useless[64]; 40 | struct ucred *p_ucred; 41 | struct filedesc *p_fd; 42 | }; 43 | 44 | struct thread { 45 | void *useless; 46 | struct proc *td_proc; 47 | }; 48 | 49 | struct kpayload_kbase_info { 50 | uint16_t fw_version; 51 | uint64_t uaddr; 52 | }; 53 | 54 | struct kpayload_kbase_args { 55 | void *syscall_handler; 56 | struct kpayload_kbase_info *kpayload_kbase_info; 57 | }; 58 | 59 | struct kpayload_dump_info { 60 | uint16_t fw_version; 61 | uint64_t kaddr; 62 | uint64_t uaddr; 63 | size_t size; 64 | }; 65 | 66 | struct kpayload_dump_args { 67 | void *syscall_handler; 68 | struct kpayload_dump_info *kpayload_dump_info; 69 | }; 70 | 71 | struct kpayload_firmware_info { 72 | uint16_t fw_version; 73 | }; 74 | 75 | struct kpayload_firmware_args { 76 | void *syscall_handler; 77 | struct kpayload_firmware_info *kpayload_firmware_info; 78 | }; 79 | 80 | struct kpayload_kclock_info { 81 | uint16_t fw_version; 82 | uint64_t set_time; 83 | }; 84 | 85 | struct kpayload_kclock_args { 86 | void *syscall_handler; 87 | struct kpayload_kclock_info *kpayload_kclock_info; 88 | }; 89 | 90 | struct kpayload_target_id_info { 91 | uint16_t fw_version; 92 | uint8_t spoof; 93 | }; 94 | 95 | struct kpayload_target_id_args { 96 | void *syscall_handler; 97 | struct kpayload_target_id_info *kpayload_target_id_info; 98 | }; 99 | 100 | #define X86_CR0_WP (1 << 16) 101 | 102 | static inline __attribute__((always_inline)) uint64_t __readmsr(unsigned long __register) { 103 | unsigned long __edx; 104 | unsigned long __eax; 105 | __asm__("rdmsr" 106 | : "=d"(__edx), "=a"(__eax) 107 | : "c"(__register)); 108 | return (((uint64_t)__edx) << 32) | (uint64_t)__eax; 109 | } 110 | 111 | static inline __attribute__((always_inline)) uint64_t readCr0(void) { 112 | uint64_t cr0; 113 | __asm__ volatile("movq %0, %%cr0" 114 | : "=r"(cr0) 115 | : 116 | : "memory"); 117 | return cr0; 118 | } 119 | 120 | static inline __attribute__((always_inline)) void writeCr0(uint64_t cr0) { 121 | __asm__ volatile("movq %%cr0, %0" 122 | : 123 | : "r"(cr0) 124 | : "memory"); 125 | } 126 | 127 | #define copyout_macro(x) \ 128 | kernel_base = &((uint8_t *)__readmsr(0xC0000082))[-K##x##_XFAST_SYSCALL]; \ 129 | copyout = (void *)(kernel_base + K##x##_COPYOUT); 130 | 131 | #define jailbreak_macro(x) \ 132 | kernel_base = &((uint8_t *)__readmsr(0xC0000082))[-K##x##_XFAST_SYSCALL]; \ 133 | kernel_ptr = (uint8_t *)kernel_base; \ 134 | prison0 = (void **)&kernel_ptr[K##x##_PRISON_0]; \ 135 | rootvnode = (void **)&kernel_ptr[K##x##_ROOTVNODE]; 136 | 137 | #define mmap_macro(x) \ 138 | kernel_base = &((uint8_t *)__readmsr(0xC0000082))[-K##x##_XFAST_SYSCALL]; \ 139 | kernel_ptr = (uint8_t *)kernel_base; \ 140 | mmap_patch_1 = &kernel_ptr[K##x##_MMAP_SELF_1]; \ 141 | mmap_patch_2 = &kernel_ptr[K##x##_MMAP_SELF_2]; \ 142 | mmap_patch_3 = &kernel_ptr[K##x##_MMAP_SELF_3]; 143 | 144 | #define aslr_macro(x) \ 145 | kernel_base = &((uint8_t *)__readmsr(0xC0000082))[-K##x##_XFAST_SYSCALL]; \ 146 | kernel_ptr = (uint8_t *)kernel_base; \ 147 | aslr_patch = &kernel_ptr[K##x##_DISABLE_ASLR]; 148 | 149 | #define kclock_macro(x) \ 150 | kernel_base = &((uint8_t *)__readmsr(0xC0000082))[-K##x##_XFAST_SYSCALL]; \ 151 | if (atoi(#x) > 407) { \ 152 | sceSblSrtcClearTimeDifference = (void *)(kernel_base + K##x##_CLEAR_TIME_DIFFERENCE); \ 153 | sceSblSrtcClearTimeDifference(15); \ 154 | } \ 155 | sceSblSrtcSetTime = (void *)(kernel_base + K##x##_SET_TIME); 156 | 157 | #define enable_browser_macro(x) \ 158 | kernel_base = &((uint8_t *)__readmsr(0xC0000082))[-K##x##_XFAST_SYSCALL]; \ 159 | sceRegMgrSetInt = (void *)(kernel_base + K##x##_REG_MGR_SET_INT); 160 | 161 | #define tid_macro(x) \ 162 | kernel_base = &((uint8_t *)__readmsr(0xC0000082))[-K##x##_XFAST_SYSCALL]; \ 163 | kernel_ptr = (uint8_t *)kernel_base; \ 164 | tid_patch = &kernel_ptr[K##x##_TARGET_ID]; 165 | 166 | #define icc_nvs_write_macro(x) \ 167 | kernel_base = &((uint8_t *)__readmsr(0xC0000082))[-K##x##_XFAST_SYSCALL]; \ 168 | icc_nvs_write = (void *)(kernel_base + K##x##_ICC_NVS_WRITE); 169 | 170 | #define npdrm_macro(x) \ 171 | kernel_base = &((uint8_t *)__readmsr(0xC0000082))[-K##x##_XFAST_SYSCALL]; \ 172 | kernel_ptr = (uint8_t *)kernel_base; \ 173 | npdrm_open = &kernel_ptr[K##x##_NPDRM_OPEN]; \ 174 | npdrm_close = &kernel_ptr[K##x##_NPDRM_CLOSE]; \ 175 | npdrm_ioctl = &kernel_ptr[K##x##_NPDRM_IOCTL]; 176 | 177 | #define caseentry(id, macro) \ 178 | case id: \ 179 | macro(id); \ 180 | break; 181 | 182 | #define build_kpayload(id, macro) \ 183 | switch (id) { \ 184 | caseentry(350, macro); \ 185 | caseentry(355, macro); \ 186 | caseentry(370, macro); \ 187 | caseentry(400, macro); \ 188 | caseentry(401, macro); \ 189 | caseentry(405, macro); \ 190 | caseentry(406, macro); \ 191 | caseentry(407, macro); \ 192 | caseentry(450, macro); \ 193 | caseentry(455, macro); \ 194 | caseentry(470, macro); \ 195 | caseentry(471, macro); \ 196 | caseentry(472, macro); \ 197 | caseentry(473, macro); \ 198 | caseentry(474, macro); \ 199 | caseentry(500, macro); \ 200 | caseentry(501, macro); \ 201 | caseentry(503, macro); \ 202 | caseentry(505, macro); \ 203 | caseentry(507, macro); \ 204 | caseentry(550, macro); \ 205 | caseentry(553, macro); \ 206 | caseentry(555, macro); \ 207 | caseentry(556, macro); \ 208 | caseentry(600, macro); \ 209 | caseentry(602, macro); \ 210 | caseentry(620, macro); \ 211 | caseentry(650, macro); \ 212 | caseentry(651, macro); \ 213 | caseentry(670, macro); \ 214 | caseentry(671, macro); \ 215 | caseentry(672, macro); \ 216 | caseentry(700, macro); \ 217 | caseentry(701, macro); \ 218 | caseentry(702, macro); \ 219 | caseentry(750, macro); \ 220 | caseentry(751, macro); \ 221 | caseentry(755, macro); \ 222 | caseentry(800, macro); \ 223 | caseentry(801, macro); \ 224 | caseentry(803, macro); \ 225 | caseentry(850, macro); \ 226 | caseentry(852, macro); \ 227 | caseentry(900, macro); \ 228 | caseentry(903, macro); \ 229 | caseentry(904, macro); \ 230 | caseentry(950, macro); \ 231 | caseentry(951, macro); \ 232 | caseentry(960, macro); \ 233 | caseentry(1000, macro); \ 234 | caseentry(1001, macro); \ 235 | caseentry(1050, macro); \ 236 | caseentry(1070, macro); \ 237 | caseentry(1071, macro); \ 238 | caseentry(1100, macro); \ 239 | caseentry(1102, macro); \ 240 | caseentry(1150, macro); \ 241 | caseentry(1152, macro); \ 242 | caseentry(1200, macro); \ 243 | caseentry(1202, macro); \ 244 | caseentry(1250, macro); \ 245 | default: \ 246 | printf_debug("Unsupported firmware"); \ 247 | return -1; \ 248 | } 249 | 250 | int is_fw_spoofed(); 251 | int is_jailbroken(); 252 | 253 | uint16_t get_firmware(); 254 | int get_firmware_string(char *fw_string); 255 | 256 | uint64_t get_kernel_base(); 257 | int get_memory_dump(uint64_t kaddr, uint64_t *dump, size_t size); 258 | int jailbreak(); 259 | int mmap_patch(); 260 | int disable_aslr(); 261 | int kernel_clock(uint64_t value); 262 | int enable_browser(); 263 | int spoof_target_id(uint8_t id); 264 | int enable_perm_uart(); 265 | int exit_idu(); 266 | int npdrm_patch(); 267 | 268 | #endif 269 | -------------------------------------------------------------------------------- /libPS4/include/pfs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef PFS_H 4 | #define PFS_H 5 | 6 | #include "types.h" 7 | 8 | struct pfs_header_t { 9 | uint64_t version; 10 | uint64_t magic; 11 | uint32_t id[2]; 12 | char fmode; 13 | char clean; 14 | char ronly; 15 | char rsv; 16 | uint16_t mode; 17 | uint16_t unk1; 18 | uint32_t blocksz; 19 | uint32_t nbackup; 20 | uint64_t nblock; 21 | uint64_t ndinode; 22 | uint64_t ndblock; 23 | uint64_t ndinodeblock; 24 | uint64_t superroot_ino; 25 | } __attribute__((packed)); 26 | 27 | struct di_d32 { 28 | uint16_t mode; 29 | uint16_t nlink; 30 | uint32_t flags; 31 | uint64_t size; 32 | uint64_t size_compressed; 33 | uint64_t unix_time[4]; 34 | uint32_t time_nsec[4]; 35 | uint32_t uid; 36 | uint32_t gid; 37 | uint64_t spare[2]; 38 | uint32_t blocks; 39 | uint32_t db[12]; 40 | uint32_t ib[5]; 41 | } __attribute__((packed)); 42 | 43 | struct dirent_t { 44 | uint32_t ino; 45 | uint32_t type; 46 | uint32_t namelen; 47 | uint32_t entsize; 48 | //char name[namelen+1]; 49 | } __attribute__((packed)); 50 | 51 | int unpfs(char *pfsfn, char *tidpath); 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /libPS4/include/pkg.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef PKG_H 4 | #define PKG_H 5 | 6 | #include "types.h" 7 | 8 | #define PS4_PKG_MAGIC 0x544E437F // .CNT 9 | 10 | enum PS4_PKG_ENTRY_TYPES { 11 | PS4_PKG_ENTRY_TYPE_DIGEST_TABLE = 0x0001, 12 | PS4_PKG_ENTRY_TYPE_0x800 = 0x0010, 13 | PS4_PKG_ENTRY_TYPE_0x200 = 0x0020, 14 | PS4_PKG_ENTRY_TYPE_0x180 = 0x0080, 15 | PS4_PKG_ENTRY_TYPE_META_TABLE = 0x0100, 16 | PS4_PKG_ENTRY_TYPE_NAME_TABLE = 0x0200, 17 | PS4_PKG_ENTRY_TYPE_LICENSE = 0x0400, 18 | PS4_PKG_ENTRY_TYPE_FILE1 = 0x1000, 19 | PS4_PKG_ENTRY_TYPE_FILE2 = 0x1200 20 | }; 21 | 22 | // CNT/PKG structures. 23 | struct cnt_pkg_main_header { 24 | uint32_t magic; 25 | uint32_t type; 26 | uint32_t unk_0x08; 27 | uint32_t unk_0x0C; 28 | uint16_t unk1_entries_num; 29 | uint16_t table_entries_num; 30 | uint16_t system_entries_num; 31 | uint16_t unk2_entries_num; 32 | uint32_t file_table_offset; 33 | uint32_t main_entries_data_size; 34 | uint32_t unk_0x20; 35 | uint32_t body_offset; 36 | uint32_t unk_0x28; 37 | uint32_t body_size; 38 | uint8_t unk_0x30[0x10]; 39 | uint8_t content_id[0x30]; 40 | uint32_t unk_0x70; 41 | uint32_t unk_0x74; 42 | uint32_t unk_0x78; 43 | uint32_t unk_0x7C; 44 | uint32_t date; 45 | uint32_t time; 46 | uint32_t unk_0x88; 47 | uint32_t unk_0x8C; 48 | uint8_t unk_0x90[0x70]; 49 | uint8_t main_entries1_digest[0x20]; 50 | uint8_t main_entries2_digest[0x20]; 51 | uint8_t digest_table_digest[0x20]; 52 | uint8_t body_digest[0x20]; 53 | } __attribute__((packed)); 54 | 55 | struct cnt_pkg_content_header { 56 | uint32_t unk_0x400; 57 | uint32_t unk_0x404; 58 | uint32_t unk_0x408; 59 | uint32_t unk_0x40C; 60 | uint32_t unk_0x410; 61 | uint32_t content_offset; 62 | uint32_t unk_0x418; 63 | uint32_t content_size; 64 | uint32_t unk_0x420; 65 | uint32_t unk_0x424; 66 | uint32_t unk_0x428; 67 | uint32_t unk_0x42C; 68 | uint32_t unk_0x430; 69 | uint32_t unk_0x434; 70 | uint32_t unk_0x438; 71 | uint32_t unk_0x43C; 72 | uint8_t content_digest[0x20]; 73 | uint8_t content_one_block_digest[0x20]; 74 | } __attribute__((packed)); 75 | 76 | struct cnt_pkg_table_entry { 77 | uint32_t type; 78 | uint32_t unk1; 79 | uint32_t flags1; 80 | uint32_t flags2; 81 | uint32_t offset; 82 | uint32_t size; 83 | uint32_t unk2; 84 | uint32_t unk3; 85 | } __attribute__((packed)); 86 | 87 | // Internal structure. 88 | struct file_entry { 89 | int offset; 90 | int size; 91 | char *name; 92 | }; 93 | 94 | int isfpkg(char *pkgfn); 95 | int unpkg(char *pkgfn, char *tidpath); 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /libPS4/include/proc.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef PROC_H 4 | #define PROC_H 5 | 6 | #include "types.h" 7 | 8 | #define CTL_KERN 1 9 | #define KERN_PROC 14 10 | #define KERN_PROC_ALL 0 /* everything */ 11 | #define KERN_PROC_PID 1 /* by process id */ 12 | #define KERN_PROC_PGRP 2 /* by process group id */ 13 | #define KERN_PROC_SESSION 3 /* by session of pid */ 14 | #define KERN_PROC_TTY 4 /* by controlling tty */ 15 | #define KERN_PROC_UID 5 /* by effective uid */ 16 | #define KERN_PROC_RUID 6 /* by real uid */ 17 | 18 | #define PT_TRACE_ME 0 /* child declares it's being traced */ 19 | #define PT_READ_I 1 /* read word in child's I space */ 20 | #define PT_READ_D 2 /* read word in child's D space */ 21 | /* was PT_READ_U 3 * read word in child's user structure */ 22 | #define PT_WRITE_I 4 /* write word in child's I space */ 23 | #define PT_WRITE_D 5 /* write word in child's D space */ 24 | /* was PT_WRITE_U 6 * write word in child's user structure */ 25 | #define PT_CONTINUE 7 /* continue the child */ 26 | #define PT_KILL 8 /* kill the child process */ 27 | #define PT_STEP 9 /* single step the child */ 28 | #define PT_ATTACH 10 /* trace some running process */ 29 | #define PT_DETACH 11 /* stop tracing a process */ 30 | #define PT_IO 12 /* do I/O to/from stopped process. */ 31 | #define PT_LWPINFO 13 /* Info about the LWP that stopped. */ 32 | #define PT_GETNUMLWPS 14 /* get total number of threads */ 33 | #define PT_GETLWPLIST 15 /* get thread list */ 34 | #define PT_CLEARSTEP 16 /* turn off single step */ 35 | #define PT_SETSTEP 17 /* turn on single step */ 36 | #define PT_SUSPEND 18 /* suspend a thread */ 37 | #define PT_RESUME 19 /* resume a thread */ 38 | #define PT_TO_SCE 20 39 | #define PT_TO_SCX 21 40 | #define PT_SYSCALL 22 41 | #define PT_FOLLOW_FORK 23 42 | #define PT_GETREGS 33 /* get general-purpose registers */ 43 | #define PT_SETREGS 34 /* set general-purpose registers */ 44 | #define PT_GETFPREGS 35 /* get floating-point registers */ 45 | #define PT_SETFPREGS 36 /* set floating-point registers */ 46 | #define PT_GETDBREGS 37 /* get debugging registers */ 47 | #define PT_SETDBREGS 38 /* set debugging registers */ 48 | #define PT_VM_TIMESTAMP 40 /* Get VM version (timestamp) */ 49 | #define PT_VM_ENTRY 41 /* Get VM map (entry) */ 50 | 51 | #define PIOD_READ_D 1 /* Read from D space */ 52 | #define PIOD_WRITE_D 2 /* Write to D space */ 53 | #define PIOD_READ_I 3 /* Read from I space */ 54 | #define PIOD_WRITE_I 4 /* Write to I space */ 55 | 56 | #define SIGQUIT 3 /*quit program*/ 57 | #define SIGKILL 9 /*kill program*/ 58 | #define SIGTERM 15 /*software termination signal*/ 59 | 60 | struct kinfo_proc { 61 | int structSize; 62 | int layout; 63 | void *args; 64 | void *paddr; 65 | void *addr; 66 | void *tracep; 67 | void *textvp; 68 | void *fd; 69 | void *vmspace; 70 | void *wchan; 71 | int pid; 72 | char useless[0x173]; 73 | char name[]; 74 | }; 75 | 76 | struct ptrace_io_desc { 77 | int piod_op; /* I/O operation */ 78 | void *piod_offs; /* child offset */ 79 | void *piod_addr; /* parent offset */ 80 | size_t piod_len; /* request length */ 81 | }; 82 | 83 | int findProcess(char *procName); 84 | 85 | void procAttach(int pid); 86 | void procDetach(int pid); 87 | void procReadBytes(int pid, void *offset, void *buffer, size_t len); 88 | void procWriteBytes(int pid, void *offset, void *buffer, size_t len); 89 | void closeProcess(char *procname); 90 | void killProcess(char *procname); 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /libPS4/include/ps4.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef PS4_H 4 | #define PS4_H 5 | 6 | #include "barrier.h" 7 | #include "base64.h" 8 | #include "camera.h" 9 | #include "cfg.h" 10 | #include "debug.h" 11 | #include "dump.h" 12 | #include "elf.h" 13 | #include "eventflag.h" 14 | #include "file.h" 15 | #include "fw_defines.h" 16 | #include "graphics.h" 17 | #include "jit.h" 18 | #include "kernel.h" 19 | #include "libc.h" 20 | #include "memory.h" 21 | #include "module.h" 22 | #include "mutex.h" 23 | #include "network.h" 24 | #include "pad.h" 25 | #include "payload_utils.h" 26 | #include "pfs.h" 27 | #include "pkg.h" 28 | #include "proc.h" 29 | #include "pthread.h" 30 | #include "registry.h" 31 | #include "semaphore.h" 32 | #include "strings.h" 33 | #include "syscall.h" 34 | #include "sysutil.h" 35 | #include "types.h" 36 | #include "unknown.h" 37 | #include "usb.h" 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /libPS4/include/pthread.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef PTHREAD_H 4 | #define PTHREAD_H 5 | 6 | #include "types.h" 7 | 8 | typedef void *ScePthread; 9 | typedef void *ScePthreadAttr; 10 | 11 | typedef void *ScePthreadMutex; 12 | typedef void *ScePthreadMutexattr; 13 | 14 | typedef void *ScePthreadBarrier; 15 | typedef void *ScePthreadBarrierattr; 16 | 17 | extern int (*scePthreadCreate)(ScePthread *thread, const ScePthreadAttr *attr, void *(*entry)(void *), void *arg, const char *name); 18 | extern void (*scePthreadExit)(void *value); 19 | extern int (*scePthreadDetach)(ScePthread thread); 20 | extern int (*scePthreadJoin)(ScePthread thread, void **value_ptr); 21 | extern void (*scePthreadYield)(void); 22 | extern ScePthread (*scePthreadSelf)(void); 23 | extern int (*scePthreadCancel)(ScePthread thread); 24 | 25 | extern int (*scePthreadMutexInit)(ScePthreadMutex *mutex, const ScePthreadMutexattr *attr, const char *name); 26 | extern int (*scePthreadMutexDestroy)(ScePthreadMutex *mutex); 27 | extern int (*scePthreadMutexLock)(ScePthreadMutex *mutex); 28 | extern int (*scePthreadMutexTrylock)(ScePthreadMutex *mutex); 29 | extern int (*scePthreadMutexTimedlock)(ScePthreadMutex *mutex, SceKernelUseconds usec); 30 | extern int (*scePthreadMutexUnlock)(ScePthreadMutex *mutex); 31 | 32 | extern int (*scePthreadBarrierInit)(ScePthreadBarrier *barrier, const ScePthreadBarrierattr *attr, unsigned int count); 33 | extern int (*scePthreadBarrierWait)(ScePthreadBarrier *barrier); 34 | 35 | void initPthread(void); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /libPS4/include/registry.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef REGISTRY_H 4 | #define REGISTRY_H 5 | 6 | #include "types.h" 7 | 8 | int registryCommand(int command); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /libPS4/include/semaphore.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef SEMAPHORE_H 4 | #define SEMAPHORE_H 5 | 6 | #include "types.h" 7 | 8 | int createSemaphore(const char *name, int attributes, int startingCount, int maxCount); 9 | int removeSemaphore(int semaphore); 10 | int openSemaphore(const char *name, int oflag, int mode, unsigned int value); 11 | int closeSemaphore(int semaphore); 12 | int waitSemaphore(int semaphore, int requiredCount, int *microsecondTimeout); 13 | int pollSemaphore(int semaphore, int requiredCount); 14 | int signalSemaphore(int semaphore, int count); 15 | int cancelSemaphore(int semaphore, int count, int *threadsReleased); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /libPS4/include/strings.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef STRINGS_H 4 | #define STRINGS_H 5 | 6 | #include "types.h" 7 | 8 | char *replace_str(char *str, char *orig, char *rep); 9 | int split_string(char *str, char c, char ***arr); 10 | char *read_string(int f); 11 | int substring(char *haystack, char *needle); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /libPS4/include/syscall.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef SYSCALL_H 4 | #define SYSCALL_H 5 | 6 | #include "types.h" 7 | 8 | #define SYSCALL(name, number) \ 9 | __asm__(".intel_syntax noprefix"); \ 10 | __asm__(".globl " #name ""); \ 11 | __asm__("" #name ":"); \ 12 | __asm__("movq rax, " #number ""); \ 13 | __asm__("jmp syscall_macro"); 14 | 15 | unsigned long syscall(unsigned long n, ...); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /libPS4/include/sysutil.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef SYSUTIL_H 4 | #define SYSUTIL_H 5 | 6 | #include "debug.h" 7 | #include "kernel.h" 8 | #include "libc.h" 9 | #include "network.h" 10 | #include "types.h" 11 | 12 | #define SCE_USER_SERVICE_MAX_LOGIN_USERS 4 13 | #define SCE_USER_SERVICE_MAX_USER_NAME_LENGTH 16 14 | 15 | extern int (*sceSysUtilSendSystemNotificationWithText)(int messageType, char *message); 16 | 17 | typedef struct SceUserServiceLoginUserIdList { 18 | int32_t userId[SCE_USER_SERVICE_MAX_LOGIN_USERS]; 19 | } SceUserServiceLoginUserIdList; 20 | 21 | void initSysUtil(void); 22 | void openBrowser(char *uri); 23 | int getUserIDList(SceUserServiceLoginUserIdList *userIdList); 24 | int32_t getUserID(); 25 | char *getUserName(int32_t userId); 26 | int32_t getInitialUser(); 27 | void reboot(); 28 | void shutdown(); 29 | 30 | // HUGE shoutout to OSM-Made for removing the need to use the football/soccer icon in the notifications 31 | // https://github.com/OSM-Made/PS4-Notify 32 | #define printf_notification(...) \ 33 | do { \ 34 | SceNotificationRequest noti_buffer; \ 35 | char icon_uri[38] = "cxml://psnotification/tex_icon_system"; \ 36 | noti_buffer.type = 0; \ 37 | noti_buffer.unk3 = 0; \ 38 | noti_buffer.use_icon_image_uri = 1; \ 39 | noti_buffer.target_id = -1; \ 40 | snprintf_s(noti_buffer.uri, sizeof(noti_buffer.uri), icon_uri); \ 41 | snprintf_s(noti_buffer.message, sizeof(noti_buffer.message), ##__VA_ARGS__); \ 42 | printf_debug("[NOTIFICATION]: %s\n", noti_buffer.message); \ 43 | sceKernelSendNotificationRequest(0, (SceNotificationRequest *)¬i_buffer, sizeof(noti_buffer), 0); \ 44 | } while (0) 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /libPS4/include/types.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef TYPES_H 4 | #define TYPES_H 5 | 6 | #include 7 | 8 | #ifndef UNUSED 9 | #define UNUSED(x) (void)(x) 10 | #endif 11 | 12 | //#define offsetof(a, b) ((size_t)(((void *)&((a *)NULL)->b) - NULL)) 13 | 14 | #ifndef NULL 15 | #define NULL 0 16 | #endif 17 | 18 | #define BIT(n) (1 << (n)) 19 | 20 | typedef int errno_t; 21 | typedef int errno; 22 | 23 | typedef int bool; 24 | 25 | typedef uint64_t size_t; 26 | typedef uint64_t rsize_t; 27 | typedef int64_t ssize_t; 28 | typedef uint16_t wchar_t; 29 | 30 | typedef uint8_t uint8; 31 | typedef uint16_t uint16; 32 | typedef uint32_t uint32; 33 | typedef uint64_t uint64; 34 | 35 | typedef int8_t int8; 36 | typedef int16_t int16; 37 | typedef int32_t int32; 38 | typedef int64_t int64; 39 | 40 | typedef float float32; 41 | typedef double float64; 42 | 43 | typedef volatile uint8_t vuint8; 44 | typedef volatile uint16_t vuint16; 45 | typedef volatile uint32_t vuint32; 46 | typedef volatile uint64_t vuint64; 47 | 48 | typedef volatile int8_t vint8; 49 | typedef volatile int16_t vint16; 50 | typedef volatile int32_t vint32; 51 | typedef volatile int64_t vint64; 52 | 53 | typedef volatile float32 vfloat32; 54 | typedef volatile float64 vfloat64; 55 | 56 | typedef uint8_t byte; 57 | 58 | typedef uint8_t u8; 59 | typedef uint16_t u16; 60 | typedef uint32_t u32; 61 | typedef uint64_t u64; 62 | 63 | typedef int8_t s8; 64 | typedef int16_t s16; 65 | typedef int32_t s32; 66 | typedef int64_t s64; 67 | 68 | typedef volatile u8 vu8; 69 | typedef volatile u16 vu16; 70 | typedef volatile u32 vu32; 71 | typedef volatile u64 vu64; 72 | 73 | typedef volatile s8 vs8; 74 | typedef volatile s16 vs16; 75 | typedef volatile s32 vs32; 76 | typedef volatile s64 vs64; 77 | 78 | //typedef int ptrdiff_t; 79 | //typedef unsigned int *uintptr_t; 80 | //typedef int *intptr_t; 81 | 82 | /* POSIX types */ 83 | typedef uint32_t blksize_t; 84 | typedef int64_t blkcnt_t; 85 | typedef uint32_t dev_t; 86 | typedef uint32_t fflags_t; 87 | typedef uint32_t gid_t; 88 | typedef uint32_t ino_t; 89 | typedef uint16_t mode_t; 90 | typedef uint16_t nlink_t; 91 | typedef int64_t off_t; 92 | typedef uint32_t uid_t; 93 | typedef int64_t time_t; 94 | typedef long suseconds_t; 95 | 96 | #define RSIZE_MAX (SIZE_MAX >> 1) 97 | 98 | struct timespec { 99 | time_t tv_sec; 100 | long tv_nsec; 101 | }; 102 | 103 | struct timeval { 104 | time_t tv_sec; 105 | suseconds_t tv_usec; 106 | }; 107 | 108 | struct tm { 109 | int tm_sec; 110 | int tm_min; 111 | int tm_hour; 112 | int tm_mday; 113 | int tm_mon; 114 | int tm_year; 115 | int tm_wday; 116 | int tm_yday; 117 | int tm_isdst; 118 | }; 119 | 120 | /* SCE types */ 121 | typedef unsigned int SceKernelUseconds; 122 | 123 | #endif 124 | -------------------------------------------------------------------------------- /libPS4/include/unknown.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef UNKNOWN_H 4 | #define UNKNOWN_H 5 | 6 | #include "types.h" 7 | 8 | int unknownResourceCreate(const char *name); 9 | int unknownResourceDestroy(int unknownResource); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /libPS4/include/usb.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef USB_H 4 | #define USB_H 5 | 6 | #include "types.h" 7 | 8 | /* Grabbed from libusb (www.libusb.org) */ 9 | 10 | enum libusb_class_code { 11 | LIBUSB_CLASS_PER_INTERFACE = 0, 12 | LIBUSB_CLASS_AUDIO = 1, 13 | LIBUSB_CLASS_COMM = 2, 14 | LIBUSB_CLASS_HID = 3, 15 | LIBUSB_CLASS_PHYSICAL = 5, 16 | LIBUSB_CLASS_PRINTER = 7, 17 | LIBUSB_CLASS_PTP = 6, 18 | LIBUSB_CLASS_IMAGE = 6, 19 | LIBUSB_CLASS_MASS_STORAGE = 8, 20 | LIBUSB_CLASS_HUB = 9, 21 | LIBUSB_CLASS_DATA = 10, 22 | LIBUSB_CLASS_SMART_CARD = 0x0b, 23 | LIBUSB_CLASS_CONTENT_SECURITY = 0x0d, 24 | LIBUSB_CLASS_VIDEO = 0x0e, 25 | LIBUSB_CLASS_PERSONAL_HEALTHCARE = 0x0f, 26 | LIBUSB_CLASS_DIAGNOSTIC_DEVICE = 0xdc, 27 | LIBUSB_CLASS_WIRELESS = 0xe0, 28 | LIBUSB_CLASS_APPLICATION = 0xfe, 29 | LIBUSB_CLASS_VENDOR_SPEC = 0xff 30 | }; 31 | 32 | enum libusb_descriptor_type { 33 | LIBUSB_DT_DEVICE = 0x01, 34 | LIBUSB_DT_CONFIG = 0x02, 35 | LIBUSB_DT_STRING = 0x03, 36 | LIBUSB_DT_INTERFACE = 0x04, 37 | LIBUSB_DT_ENDPOINT = 0x05, 38 | LIBUSB_DT_BOS = 0x0f, 39 | LIBUSB_DT_DEVICE_CAPABILITY = 0x10, 40 | LIBUSB_DT_HID = 0x21, 41 | LIBUSB_DT_REPORT = 0x22, 42 | LIBUSB_DT_PHYSICAL = 0x23, 43 | LIBUSB_DT_HUB = 0x29, 44 | LIBUSB_DT_SUPERSPEED_HUB = 0x2a, 45 | LIBUSB_DT_SS_ENDPOINT_COMPANION = 0x30 46 | }; 47 | 48 | #define LIBUSB_ENDPOINT_ADDRESS_MASK 0x0f 49 | #define LIBUSB_ENDPOINT_DIR_MASK 0x80 50 | 51 | enum libusb_endpoint_direction { 52 | LIBUSB_ENDPOINT_IN = 0x80, 53 | LIBUSB_ENDPOINT_OUT = 0x00 54 | }; 55 | 56 | #define LIBUSB_TRANSFER_TYPE_MASK 0x03 57 | 58 | enum libusb_transfer_type { 59 | LIBUSB_TRANSFER_TYPE_CONTROL = 0, 60 | LIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1, 61 | LIBUSB_TRANSFER_TYPE_BULK = 2, 62 | LIBUSB_TRANSFER_TYPE_INTERRUPT = 3, 63 | LIBUSB_TRANSFER_TYPE_BULK_STREAM = 4, 64 | }; 65 | 66 | enum libusb_standard_request { 67 | LIBUSB_REQUEST_GET_STATUS = 0x00, 68 | LIBUSB_REQUEST_CLEAR_FEATURE = 0x01, 69 | LIBUSB_REQUEST_SET_FEATURE = 0x03, 70 | LIBUSB_REQUEST_SET_ADDRESS = 0x05, 71 | LIBUSB_REQUEST_GET_DESCRIPTOR = 0x06, 72 | LIBUSB_REQUEST_SET_DESCRIPTOR = 0x07, 73 | LIBUSB_REQUEST_GET_CONFIGURATION = 0x08, 74 | LIBUSB_REQUEST_SET_CONFIGURATION = 0x09, 75 | LIBUSB_REQUEST_GET_INTERFACE = 0x0A, 76 | LIBUSB_REQUEST_SET_INTERFACE = 0x0B, 77 | LIBUSB_REQUEST_SYNCH_FRAME = 0x0C, 78 | LIBUSB_REQUEST_SET_SEL = 0x30, 79 | LIBUSB_SET_ISOCH_DELAY = 0x31, 80 | }; 81 | 82 | enum libusb_request_type { 83 | LIBUSB_REQUEST_TYPE_STANDARD = (0x00 << 5), 84 | LIBUSB_REQUEST_TYPE_CLASS = (0x01 << 5), 85 | LIBUSB_REQUEST_TYPE_VENDOR = (0x02 << 5), 86 | LIBUSB_REQUEST_TYPE_RESERVED = (0x03 << 5) 87 | }; 88 | 89 | enum libusb_request_recipient { 90 | LIBUSB_RECIPIENT_DEVICE = 0x00, 91 | LIBUSB_RECIPIENT_INTERFACE = 0x01, 92 | LIBUSB_RECIPIENT_ENDPOINT = 0x02, 93 | LIBUSB_RECIPIENT_OTHER = 0x03, 94 | }; 95 | 96 | enum libusb_error { 97 | LIBUSB_SUCCESS = 0, 98 | LIBUSB_ERROR_IO = -1, 99 | LIBUSB_ERROR_INVALID_PARAM = -2, 100 | LIBUSB_ERROR_ACCESS = -3, 101 | LIBUSB_ERROR_NO_DEVICE = -4, 102 | LIBUSB_ERROR_NOT_FOUND = -5, 103 | LIBUSB_ERROR_BUSY = -6, 104 | LIBUSB_ERROR_TIMEOUT = -7, 105 | LIBUSB_ERROR_OVERFLOW = -8, 106 | LIBUSB_ERROR_PIPE = -9, 107 | LIBUSB_ERROR_INTERRUPTED = -10, 108 | LIBUSB_ERROR_NO_MEM = -11, 109 | LIBUSB_ERROR_NOT_SUPPORTED = -12, 110 | LIBUSB_ERROR_OTHER = -99, 111 | }; 112 | 113 | #define LIBUSB_ERROR_COUNT 14 114 | 115 | typedef struct libusb_device_descriptor { 116 | uint8_t bLength; 117 | uint8_t bDescriptorType; 118 | uint16_t bcdUSB; 119 | uint8_t bDeviceClass; 120 | uint8_t bDeviceSubClass; 121 | uint8_t bDeviceProtocol; 122 | uint8_t bMaxPacketSize0; 123 | uint16_t idVendor; 124 | uint16_t idProduct; 125 | uint16_t bcdDevice; 126 | uint8_t iManufacturer; 127 | uint8_t iProduct; 128 | uint8_t iSerialNumber; 129 | uint8_t bNumConfigurations; 130 | } libusb_device_descriptor; 131 | 132 | struct libusb_endpoint_descriptor { 133 | uint8_t bLength; 134 | uint8_t bDescriptorType; 135 | uint8_t bEndpointAddress; 136 | uint8_t bmAttributes; 137 | uint16_t wMaxPacketSize; 138 | uint8_t bInterval; 139 | uint8_t bRefresh; 140 | uint8_t bSynchAddress; 141 | const unsigned char *extra; 142 | int extra_length; 143 | }; 144 | 145 | struct libusb_interface_descriptor { 146 | uint8_t bLength; 147 | uint8_t bDescriptorType; 148 | uint8_t bInterfaceNumber; 149 | uint8_t bAlternateSetting; 150 | uint8_t bNumEndpoints; 151 | uint8_t bInterfaceClass; 152 | uint8_t bInterfaceSubClass; 153 | uint8_t bInterfaceProtocol; 154 | uint8_t iInterface; 155 | const struct libusb_endpoint_descriptor *endpoint; 156 | const unsigned char *extra; 157 | int extra_length; 158 | }; 159 | 160 | struct libusb_interface { 161 | const struct libusb_interface_descriptor *altsetting; 162 | int num_altsetting; 163 | }; 164 | 165 | struct libusb_config_descriptor { 166 | uint8_t bLength; 167 | uint8_t bDescriptorType; 168 | uint16_t wTotalLength; 169 | uint8_t bNumInterfaces; 170 | uint8_t bConfigurationValue; 171 | uint8_t iConfiguration; 172 | uint8_t bmAttributes; 173 | uint8_t MaxPower; 174 | const struct libusb_interface *interface; 175 | const unsigned char *extra; 176 | int extra_length; 177 | }; 178 | 179 | typedef struct libusb_device libusb_device; 180 | typedef struct libusb_device_handle libusb_device_handle; 181 | 182 | extern int (*sceUsbdInit)(void); 183 | extern void (*sceUsbdExit)(void); 184 | 185 | extern ssize_t (*sceUsbdGetDeviceList)(libusb_device ***list); 186 | extern void (*sceUsbdFreeDeviceList)(libusb_device **list, int unrefDevices); 187 | 188 | extern int (*sceUsbdGetDeviceDescriptor)(libusb_device *device, libusb_device_descriptor *desc); 189 | 190 | extern int (*sceUsbdOpen)(libusb_device *dev, libusb_device_handle **devh); 191 | extern libusb_device_handle *(*sceUsbdOpenDeviceWithVidPid)(unsigned short vendorId, unsigned short productId); 192 | extern void (*sceUsbdClose)(libusb_device_handle *devh); 193 | 194 | extern int (*sceUsbdSetInterfaceAltSetting)(libusb_device_handle *dev, int interface_number, int alternate_setting); 195 | extern int (*sceUsbdClearHalt)(libusb_device_handle *devh, unsigned char endpoint); 196 | extern int (*sceUsbdResetDevice)(libusb_device_handle *devh); 197 | extern int (*sceUsbdCheckConnected)(libusb_device_handle *devh); 198 | 199 | extern int (*sceUsbdControlTransfer)(libusb_device_handle *devh, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, unsigned char *data, uint16_t wLength, unsigned int timeout); 200 | extern int (*sceUsbdBulkTransfer)(struct libusb_device_handle *devh, unsigned char endpoint, unsigned char *data, int length, int *transferred, unsigned int timeout); 201 | extern int (*sceUsbdInterruptTransfer)(struct libusb_device_handle *devh, unsigned char endpoint, unsigned char *data, int length, int *transferred, unsigned int timeout); 202 | 203 | extern int (*sceUsbdGetActiveConfigDescriptor)(libusb_device *dev, struct libusb_config_descriptor **config); 204 | extern int (*sceUsbdGetConfigDescriptor)(libusb_device *dev, uint8_t config_index, struct libusb_config_descriptor **config); 205 | extern int (*sceUsbdGetConfigDescriptorByValue)(libusb_device *dev, uint8_t bConfigurationValue, struct libusb_config_descriptor **config); 206 | extern void (*sceUsbdFreeConfigDescriptor)(struct libusb_config_descriptor *config); 207 | 208 | void initUsb(void); 209 | 210 | #endif 211 | -------------------------------------------------------------------------------- /libPS4/linker.x: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64") 2 | OUTPUT_ARCH(i386:x86-64) 3 | 4 | ENTRY(_start) 5 | 6 | PHDRS 7 | { 8 | code_seg PT_LOAD; 9 | rdata_seg PT_LOAD; 10 | data_seg PT_LOAD; 11 | bss_seg PT_LOAD; 12 | } 13 | 14 | SECTIONS 15 | { 16 | .text : { 17 | *(.text.start) 18 | *(.text*) 19 | } : code_seg 20 | .rodata : { 21 | *(.rodata) 22 | *(.rodata*) 23 | } : rdata_seg 24 | .data : { *(.data) } : data_seg 25 | .bss : { *(.bss) } : bss_seg 26 | /DISCARD/ : { 27 | *(.comment) 28 | *(.note.GNU-stack) 29 | *(.eh_frame) 30 | *(.interp) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /libPS4/source/barrier.c: -------------------------------------------------------------------------------- 1 | #include "syscall.h" 2 | 3 | #include "barrier.h" 4 | 5 | SYSCALL(barrierInit, 557); 6 | SYSCALL(barrierDestroy, 558); 7 | -------------------------------------------------------------------------------- /libPS4/source/base64.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Base64 encoding/decoding (RFC1341) 3 | * Copyright (c) 2005-2011, Jouni Malinen 4 | * 5 | * This software may be distributed under the terms of the BSD license. 6 | * See README for more details. 7 | */ 8 | 9 | #include "libc.h" 10 | 11 | #include "base64.h" 12 | 13 | static const unsigned char base64_table[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 14 | 15 | /** 16 | * base64_encode - Base64 encode 17 | * @src: Data to be encoded 18 | * @len: Length of the data to be encoded 19 | * @out_len: Pointer to output length variable, or %NULL if not used 20 | * Returns: Allocated buffer of out_len bytes of encoded data, 21 | * or %NULL on failure 22 | * 23 | * Caller is responsible for freeing the returned buffer. Returned buffer is 24 | * nul terminated to make it easier to use as a C string. The nul terminator is 25 | * not included in out_len. 26 | */ 27 | unsigned char *base64_encode(const unsigned char *src, size_t len, size_t *out_len) { 28 | unsigned char *out, *pos; 29 | const unsigned char *end, *in; 30 | size_t olen; 31 | int line_len; 32 | 33 | olen = len * 4 / 3 + 4; /* 3-byte blocks to 4-byte */ 34 | olen += olen / 72; /* line feeds */ 35 | olen++; /* nul termination */ 36 | if (olen < len) { 37 | return NULL; /* integer overflow */ 38 | } 39 | out = malloc(olen); 40 | if (out == NULL) { 41 | return NULL; 42 | } 43 | 44 | end = src + len; 45 | in = src; 46 | pos = out; 47 | line_len = 0; 48 | while (end - in >= 3) { 49 | *pos++ = base64_table[in[0] >> 2]; 50 | *pos++ = base64_table[((in[0] & 0x03) << 4) | (in[1] >> 4)]; 51 | *pos++ = base64_table[((in[1] & 0x0f) << 2) | (in[2] >> 6)]; 52 | *pos++ = base64_table[in[2] & 0x3f]; 53 | in += 3; 54 | line_len += 4; 55 | if (line_len >= 72) { 56 | *pos++ = '\n'; 57 | line_len = 0; 58 | } 59 | } 60 | 61 | if (end - in) { 62 | *pos++ = base64_table[in[0] >> 2]; 63 | if (end - in == 1) { 64 | *pos++ = base64_table[(in[0] & 0x03) << 4]; 65 | *pos++ = '='; 66 | } else { 67 | *pos++ = base64_table[((in[0] & 0x03) << 4) | (in[1] >> 4)]; 68 | *pos++ = base64_table[(in[1] & 0x0f) << 2]; 69 | } 70 | *pos++ = '='; 71 | line_len += 4; 72 | } 73 | 74 | if (line_len) { 75 | *pos++ = '\n'; 76 | } 77 | 78 | *pos = '\0'; 79 | if (out_len) { 80 | *out_len = pos - out; 81 | } 82 | return out; 83 | } 84 | 85 | /** 86 | * base64_decode - Base64 decode 87 | * @src: Data to be decoded 88 | * @len: Length of the data to be decoded 89 | * @out_len: Pointer to output length variable 90 | * Returns: Allocated buffer of out_len bytes of decoded data, 91 | * or %NULL on failure 92 | * 93 | * Caller is responsible for freeing the returned buffer. 94 | */ 95 | unsigned char *base64_decode(const unsigned char *src, size_t len, size_t *out_len) { 96 | unsigned char dtable[256], *out, *pos, block[4]; 97 | size_t i, count, olen; 98 | int pad = 0; 99 | 100 | memset(dtable, 0x80, 256); 101 | for (i = 0; i < sizeof(base64_table) - 1; i++) { 102 | dtable[base64_table[i]] = (unsigned char)i; 103 | } 104 | dtable['='] = 0; 105 | 106 | count = 0; 107 | for (i = 0; i < len; i++) { 108 | if (dtable[src[i]] != 0x80) { 109 | count++; 110 | } 111 | } 112 | 113 | if (count == 0 || count % 4) { 114 | return NULL; 115 | } 116 | 117 | olen = count / 4 * 3; 118 | pos = out = malloc(olen); 119 | if (out == NULL) { 120 | return NULL; 121 | } 122 | 123 | count = 0; 124 | for (i = 0; i < len; i++) { 125 | unsigned char tmp = dtable[src[i]]; 126 | if (tmp == 0x80) { 127 | continue; 128 | } 129 | 130 | if (src[i] == '=') { 131 | pad++; 132 | } 133 | block[count] = tmp; 134 | count++; 135 | if (count == 4) { 136 | *pos++ = (block[0] << 2) | (block[1] >> 4); 137 | *pos++ = (block[1] << 4) | (block[2] >> 2); 138 | *pos++ = (block[2] << 6) | block[3]; 139 | count = 0; 140 | if (pad) { 141 | if (pad == 1) { 142 | pos--; 143 | } else if (pad == 2) { 144 | pos -= 2; 145 | } else { 146 | /* Invalid padding */ 147 | free(out); 148 | return NULL; 149 | } 150 | break; 151 | } 152 | } 153 | } 154 | 155 | *out_len = pos - out; 156 | return out; 157 | } 158 | -------------------------------------------------------------------------------- /libPS4/source/camera.c: -------------------------------------------------------------------------------- 1 | #include "kernel.h" 2 | #include "module.h" 3 | 4 | #include "camera.h" 5 | 6 | int libCamera; 7 | 8 | int (*sceCameraOpen)(int userid, int type, int index, void *); 9 | int (*sceCameraClose)(int handle); 10 | int (*sceCameraIsAttached)(int index); 11 | int (*sceCameraGetFrameData)(int handle, SceCameraFrameData *frame); 12 | int (*sceCameraStart)(int handle, SceCameraStartParameter *param); 13 | int (*sceCameraStop)(int handle); 14 | int (*sceCameraGetDeviceInfo)(int handle, SceCameraDeviceInfo *info); 15 | int (*sceCameraGetDeviceConfig)(int handle, SceCameraConfig *config); 16 | int (*sceCameraGetConfig)(int handle, SceCameraConfig *config); 17 | int (*sceCameraSetConfig)(int handle, SceCameraConfig *config); 18 | 19 | void initCamera(void) { 20 | if (libCamera) { 21 | return; 22 | } 23 | 24 | libCamera = sceKernelLoadStartModule("libSceCamera.sprx", 0, 0, 0, NULL, NULL); 25 | 26 | RESOLVE(libCamera, sceCameraOpen); 27 | RESOLVE(libCamera, sceCameraClose); 28 | RESOLVE(libCamera, sceCameraIsAttached); 29 | RESOLVE(libCamera, sceCameraGetFrameData); 30 | RESOLVE(libCamera, sceCameraStart); 31 | RESOLVE(libCamera, sceCameraStop); 32 | RESOLVE(libCamera, sceCameraGetDeviceInfo); 33 | RESOLVE(libCamera, sceCameraGetDeviceConfig); 34 | RESOLVE(libCamera, sceCameraGetConfig); 35 | RESOLVE(libCamera, sceCameraSetConfig); 36 | } 37 | -------------------------------------------------------------------------------- /libPS4/source/cfg.c: -------------------------------------------------------------------------------- 1 | /* inih -- simple .ini/.cfg file parser 2 | 3 | inih is released under the New BSD license (see LICENSE.txt). Go to the project 4 | home page for more info: 5 | 6 | https://github.com/benhoyt/inih 7 | 8 | */ 9 | 10 | #include "libc.h" 11 | 12 | #include "cfg.h" 13 | 14 | #define MAX_NAME 50 15 | #define EOF '\00' 16 | 17 | static inline int fgetc_file(FILE *fp) { 18 | char c; 19 | if (fread(&c, 1, 1, fp) == 0) { 20 | return (EOF); 21 | } 22 | return (c); 23 | } 24 | 25 | static char *fgets(char *dst, int max, FILE *fp) { 26 | int c = EOF; 27 | char *p; 28 | 29 | /* get max bytes or upto a newline */ 30 | for (p = dst, max--; max > 0; max--) { 31 | if ((c = fgetc_file(fp)) == EOF) { 32 | break; 33 | } 34 | *p++ = c; 35 | if (c == '\n') { 36 | break; 37 | } 38 | } 39 | *p = 0; 40 | if (p == dst || c == EOF) { 41 | return NULL; 42 | } 43 | return (p); 44 | } 45 | 46 | bool isspace(int c) { 47 | return c == ' ' || c == '\t'; 48 | } 49 | 50 | /* Used by cfg_parse_string() to keep track of string parsing state. */ 51 | typedef struct { 52 | const char *ptr; 53 | size_t num_left; 54 | } cfg_parse_string_ctx; 55 | 56 | /* Strip whitespace chars off end of given string, in place. Return s. */ 57 | static char *rstrip(char *s) { 58 | char *p = s + strlen(s); 59 | while (p > s && isspace((unsigned char)(*--p))) { 60 | *p = '\0'; 61 | } 62 | return s; 63 | } 64 | 65 | /* Return pointer to first non-whitespace char in given string. */ 66 | static char *lskip(const char *s) { 67 | while (*s && isspace((unsigned char)(*s))) { 68 | s++; 69 | } 70 | return (char *)s; 71 | } 72 | 73 | /* Return pointer to first char (of chars) or inline comment in given string, 74 | or pointer to null at end of string if neither found. Inline comment must 75 | be prefixed by a whitespace character to register as a comment. */ 76 | static char *find_chars_or_comment(const char *s, const char *chars) { 77 | #if CFG_ALLOW_INLINE_COMMENTS 78 | int was_space = 0; 79 | while (*s && (!chars || !strchr(chars, *s)) && !(was_space && strchr(CFG_INLINE_COMMENT_PREFIXES, *s))) { 80 | was_space = isspace((unsigned char)(*s)); 81 | s++; 82 | } 83 | #else 84 | while (*s && (!chars || !strchr(chars, *s))) { 85 | s++; 86 | } 87 | #endif 88 | return (char *)s; 89 | } 90 | 91 | /* Version of strncpy that ensures dest (size bytes) is null-terminated. */ 92 | static char *strncpy0(char *dest, const char *src, size_t size) { 93 | strncpy(dest, src, size); 94 | dest[size - 1] = '\0'; 95 | return dest; 96 | } 97 | 98 | /* See documentation in header file. */ 99 | int cfg_parse_stream(cfg_reader reader, void *stream, cfg_handler handler, void *user) { 100 | /* Uses a fair bit of stack (use heap instead if you need to) */ 101 | #if CFG_USE_STACK 102 | char line[CFG_MAX_LINE]; 103 | int max_line = CFG_MAX_LINE; 104 | #else 105 | char *line; 106 | int max_line = CFG_INITIAL_ALLOC; 107 | #endif 108 | #if CFG_ALLOW_REALLOC 109 | char *new_line; 110 | int offset; 111 | #endif 112 | char prev_name[MAX_NAME] = ""; 113 | 114 | char *start; 115 | char *end; 116 | char *name; 117 | char *value; 118 | int lineno = 0; 119 | int error = 0; 120 | 121 | #if !CFG_USE_STACK 122 | line = (char *)malloc(CFG_INITIAL_ALLOC); 123 | if (!line) { 124 | return -2; 125 | } 126 | #endif 127 | 128 | #if CFG_HANDLER_LINENO 129 | #define HANDLER(u, n, v) handler(u, n, v, lineno) 130 | #else 131 | #define HANDLER(u, n, v) handler(u, n, v) 132 | #endif 133 | 134 | /* Scan through stream line by line */ 135 | while (reader(line, max_line, stream) != NULL) { 136 | #if CFG_ALLOW_REALLOC 137 | offset = strlen(line); 138 | while (offset == max_line - 1 && line[offset - 1] != '\n') { 139 | max_line *= 2; 140 | if (max_line > CFG_MAX_LINE) { 141 | max_line = CFG_MAX_LINE; 142 | } 143 | new_line = realloc(line, max_line); 144 | if (!new_line) { 145 | free(line); 146 | return -2; 147 | } 148 | line = new_line; 149 | if (reader(line + offset, max_line - offset, stream) == NULL) { 150 | break; 151 | } 152 | if (max_line >= CFG_MAX_LINE) { 153 | break; 154 | } 155 | offset += strlen(line + offset); 156 | } 157 | #endif 158 | 159 | lineno++; 160 | 161 | start = line; 162 | #if CFG_ALLOW_BOM 163 | if (lineno == 1 && (unsigned char)start[0] == 0xEF && (unsigned char)start[1] == 0xBB && (unsigned char)start[2] == 0xBF) { 164 | start += 3; 165 | } 166 | #endif 167 | start = lskip(rstrip(start)); 168 | 169 | if (*start == ';' || *start == '#') { 170 | /* Per Python configparser, allow both ; and # comments at the 171 | start of a line */ 172 | } 173 | #if CFG_ALLOW_MULTILINE 174 | else if (*prev_name && *start && start > line) { 175 | /* Non-blank line with leading whitespace, treat as continuation 176 | of previous name's value (as per Python configparser). */ 177 | if (!HANDLER(user, prev_name, start) && !error) 178 | error = lineno; 179 | } 180 | #endif 181 | else if (*start) { 182 | /* Not a comment, must be a name[=:]value pair */ 183 | end = find_chars_or_comment(start, "=:"); 184 | if (*end == '=' || *end == ':') { 185 | *end = '\0'; 186 | name = rstrip(start); 187 | value = end + 1; 188 | #if CFG_ALLOW_INLINE_COMMENTS 189 | end = find_chars_or_comment(value, NULL); 190 | if (*end) { 191 | *end = '\0'; 192 | } 193 | #endif 194 | value = lskip(value); 195 | rstrip(value); 196 | 197 | /* Valid name[=:]value pair found, call handler */ 198 | strncpy0(prev_name, name, sizeof(prev_name)); 199 | if (!HANDLER(user, name, value) && !error) { 200 | error = lineno; 201 | } 202 | } else if (!error) { 203 | /* No '=' or ':' found on name[=:]value line */ 204 | error = lineno; 205 | } 206 | } 207 | 208 | #if CFG_STOP_ON_FIRST_ERROR 209 | if (error) { 210 | break; 211 | } 212 | #endif 213 | } 214 | 215 | #if !CFG_USE_STACK 216 | free(line); 217 | #endif 218 | 219 | return error; 220 | } 221 | 222 | /* See documentation in header file. */ 223 | int cfg_parse_file(FILE *file, cfg_handler handler, void *user) { 224 | return cfg_parse_stream((cfg_reader)fgets, file, handler, user); 225 | } 226 | 227 | /* See documentation in header file. */ 228 | int cfg_parse(const char *filename, cfg_handler handler, void *user) { 229 | FILE *file; 230 | int error; 231 | 232 | file = fopen(filename, "r"); 233 | if (!file) { 234 | return -1; 235 | } 236 | error = cfg_parse_file(file, handler, user); 237 | fclose(file); 238 | return error; 239 | } 240 | 241 | /* An cfg_reader function to read the next line from a string buffer. This 242 | is the fgets() equivalent used by cfg_parse_string(). */ 243 | static char *cfg_reader_string(char *str, int num, void *stream) { 244 | cfg_parse_string_ctx *ctx = (cfg_parse_string_ctx *)stream; 245 | const char *ctx_ptr = ctx->ptr; 246 | size_t ctx_num_left = ctx->num_left; 247 | char *strp = str; 248 | char c; 249 | 250 | if (ctx_num_left == 0 || num < 2) { 251 | return NULL; 252 | } 253 | 254 | while (num > 1 && ctx_num_left != 0) { 255 | c = *ctx_ptr++; 256 | ctx_num_left--; 257 | *strp++ = c; 258 | if (c == '\n') { 259 | break; 260 | } 261 | num--; 262 | } 263 | 264 | *strp = '\0'; 265 | ctx->ptr = ctx_ptr; 266 | ctx->num_left = ctx_num_left; 267 | return str; 268 | } 269 | 270 | /* See documentation in header file. */ 271 | int cfg_parse_string(const char *string, cfg_handler handler, void *user) { 272 | cfg_parse_string_ctx ctx; 273 | 274 | ctx.ptr = string; 275 | ctx.num_left = strlen(string); 276 | return cfg_parse_stream((cfg_reader)cfg_reader_string, &ctx, handler, user); 277 | } 278 | -------------------------------------------------------------------------------- /libPS4/source/debug.c: -------------------------------------------------------------------------------- 1 | #include "debug.h" 2 | 3 | int DEBUG_SOCK = -1; 4 | -------------------------------------------------------------------------------- /libPS4/source/dump.c: -------------------------------------------------------------------------------- 1 | #include "elf.h" 2 | #include "file.h" 3 | #include "kernel.h" 4 | #include "libc.h" 5 | #include "memory.h" 6 | 7 | #include "dump.h" 8 | 9 | int is_self(const char *fn) { 10 | struct stat st; 11 | int res = 0; 12 | int fd = open(fn, O_RDONLY, 0); 13 | if (fd != -1) { 14 | stat(fn, &st); 15 | void *addr = mmap(0, 0x4000, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); 16 | if (addr != MAP_FAILED) { 17 | if (st.st_size >= 4) { 18 | uint32_t selfMagic = *(uint32_t *)((uint8_t *)addr + 0x00); 19 | if (selfMagic == SELF_MAGIC) { 20 | uint16_t snum = *(uint16_t *)((uint8_t *)addr + 0x18); 21 | if (st.st_size >= (0x20 + snum * 0x20 + 4)) { 22 | uint32_t elfMagic = *(uint32_t *)((uint8_t *)addr + 0x20 + snum * 0x20); 23 | if (elfMagic == ELF_MAGIC) { 24 | res = 1; 25 | } 26 | } 27 | } 28 | } 29 | munmap(addr, 0x4000); 30 | } 31 | close(fd); 32 | } 33 | return res; 34 | } 35 | 36 | #define DECRYPT_SIZE 0x100000 37 | 38 | bool read_decrypt_segment(int fd, uint64_t index, uint64_t offset, size_t size, uint8_t *out) { 39 | uint8_t *outPtr = out; 40 | uint64_t outSize = size; 41 | uint64_t realOffset = (index << 32) | offset; 42 | while (outSize > 0) { 43 | size_t bytes = (outSize > DECRYPT_SIZE) ? DECRYPT_SIZE : outSize; 44 | uint8_t *addr = (uint8_t *)mmap(0, bytes, PROT_READ, MAP_PRIVATE | 0x80000, fd, realOffset); 45 | if (addr == MAP_FAILED) { 46 | return 0; 47 | } 48 | memcpy(outPtr, addr, bytes); 49 | munmap(addr, bytes); 50 | outPtr += bytes; 51 | outSize -= bytes; 52 | realOffset += bytes; 53 | } 54 | return 1; 55 | } 56 | 57 | int is_segment_in_other_segment(Elf64_Phdr *phdr, int index, Elf64_Phdr *phdrs, int num) { 58 | for (int i = 0; i < num; i += 1) { 59 | Elf64_Phdr *p = &phdrs[i]; 60 | if (i != index) { 61 | if (p->p_filesz > 0) { 62 | if ((phdr->p_offset >= p->p_offset) && ((phdr->p_offset + phdr->p_filesz) <= (p->p_offset + p->p_filesz))) { 63 | return 1; 64 | } 65 | } 66 | } 67 | } 68 | return 0; 69 | } 70 | 71 | SegmentBufInfo *parse_phdr(Elf64_Phdr *phdrs, int num, int *segBufNum) { 72 | SegmentBufInfo *infos = (SegmentBufInfo *)malloc(sizeof(SegmentBufInfo) * num); 73 | if (infos == NULL) { 74 | return NULL; // Is this what should be returned when unable to allocate `infos`? 75 | } 76 | int segindex = 0; 77 | for (int i = 0; i < num; i += 1) { 78 | Elf64_Phdr *phdr = &phdrs[i]; 79 | if (phdr->p_filesz > 0) { 80 | if ((!is_segment_in_other_segment(phdr, i, phdrs, num)) || (phdr->p_type == 0x6fffff01)) { 81 | SegmentBufInfo *info = &infos[segindex]; 82 | segindex += 1; 83 | info->index = i; 84 | info->bufsz = (phdr->p_filesz + (phdr->p_align - 1)) & (~(phdr->p_align - 1)); 85 | info->filesz = phdr->p_filesz; 86 | info->fileoff = phdr->p_offset; 87 | info->enc = (phdr->p_type != 0x6fffff01) ? 1 : 0; 88 | } 89 | } 90 | } 91 | *segBufNum = segindex; 92 | return infos; 93 | } 94 | 95 | void do_dump(char *saveFile, int fd, SegmentBufInfo *segBufs, int segBufNum, Elf64_Ehdr *ehdr) { 96 | int sf = open(saveFile, O_WRONLY | O_CREAT | O_TRUNC, 0777); 97 | if (sf != -1) { 98 | size_t elfsz = 0x40 + ehdr->e_phnum * sizeof(Elf64_Phdr); 99 | write(sf, ehdr, elfsz); 100 | for (int i = 0; i < segBufNum; i += 1) { 101 | uint8_t *buf = (uint8_t *)malloc(segBufs[i].bufsz); 102 | if (buf != NULL) { 103 | memset(buf, 0, segBufs[i].bufsz); 104 | if (segBufs[i].enc) { 105 | if (read_decrypt_segment(fd, segBufs[i].index, 0, segBufs[i].filesz, buf)) { 106 | lseek(sf, segBufs[i].fileoff, SEEK_SET); 107 | write(sf, buf, segBufs[i].bufsz); 108 | } 109 | } else { 110 | lseek(fd, -segBufs[i].filesz, SEEK_END); 111 | read(fd, buf, segBufs[i].filesz); 112 | lseek(sf, segBufs[i].fileoff, SEEK_SET); 113 | write(sf, buf, segBufs[i].filesz); 114 | } 115 | free(buf); 116 | } 117 | } 118 | close(sf); 119 | } 120 | } 121 | 122 | void decrypt_and_dump_self(char *selfFile, char *saveFile) { 123 | int fd = open(selfFile, O_RDONLY, 0); 124 | if (fd != -1) { 125 | void *addr = mmap(0, 0x4000, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); 126 | if (addr != MAP_FAILED) { 127 | uint16_t snum = *(uint16_t *)((uint8_t *)addr + 0x18); 128 | Elf64_Ehdr *ehdr = (Elf64_Ehdr *)((uint8_t *)addr + 0x20 + snum * 0x20); 129 | ehdr->e_shoff = ehdr->e_shentsize = ehdr->e_shnum = ehdr->e_shstrndx = 0; 130 | Elf64_Phdr *phdrs = (Elf64_Phdr *)((uint8_t *)ehdr + 0x40); 131 | int segBufNum = 0; 132 | SegmentBufInfo *segBufs = parse_phdr(phdrs, ehdr->e_phnum, &segBufNum); 133 | do_dump(saveFile, fd, segBufs, segBufNum, ehdr); 134 | free(segBufs); 135 | munmap(addr, 0x4000); 136 | } 137 | close(fd); 138 | } 139 | } 140 | 141 | void decrypt_dir(char *sourcedir, char *destdir) { 142 | DIR *dir; 143 | struct dirent *dp; 144 | struct stat info; 145 | char src_path[1024], dst_path[1024]; 146 | 147 | dir = opendir(sourcedir); 148 | if (!dir) { 149 | return; 150 | } 151 | 152 | mkdir(destdir, 0777); 153 | 154 | while ((dp = readdir(dir)) != NULL) { 155 | if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) { 156 | // Do Nothing 157 | } else { 158 | sprintf(src_path, "%s/%s", sourcedir, dp->d_name); 159 | sprintf(dst_path, "%s/%s", destdir, dp->d_name); 160 | if (!stat(src_path, &info)) { 161 | if (S_ISDIR(info.st_mode)) { 162 | decrypt_dir(src_path, dst_path); 163 | } else if (S_ISREG(info.st_mode)) { 164 | if (is_self(src_path)) { 165 | decrypt_and_dump_self(src_path, dst_path); 166 | } 167 | } 168 | } 169 | } 170 | } 171 | closedir(dir); 172 | } 173 | 174 | int wait_for_app(char *title_id) { 175 | int res = 0; 176 | 177 | DIR *dir; 178 | struct dirent *dp; 179 | 180 | dir = opendir("/mnt/sandbox/pfsmnt"); 181 | if (!dir) { 182 | return 0; 183 | } 184 | 185 | while ((dp = readdir(dir)) != NULL) { 186 | if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..") || !strncmp(dp->d_name, "AZIF00003", 9)) { 187 | // Do Nothing 188 | } else { 189 | if (strstr(dp->d_name, "-app0") != NULL) { 190 | sscanf(dp->d_name, "%[^-]", title_id); 191 | res = 1; 192 | break; 193 | } 194 | } 195 | } 196 | closedir(dir); 197 | 198 | return res; 199 | } 200 | 201 | int wait_for_bdcopy(char *title_id) { 202 | char path[256]; 203 | char *buf; 204 | size_t filelen, progress; 205 | 206 | sprintf(path, "/system_data/playgo/%s/bdcopy.pbm", title_id); 207 | FILE *pbm = fopen(path, "rb"); 208 | if (!pbm) { // This is what triggers a "dump" when a game is deleted while the dumper is already running 209 | return 100; // Returning 100 will stop the wait_for_bdcopy loop 210 | } 211 | 212 | fseek(pbm, 0, SEEK_END); 213 | filelen = ftell(pbm); 214 | fseek(pbm, 0, SEEK_SET); 215 | 216 | buf = malloc(filelen); 217 | if (buf == NULL) { 218 | fclose(pbm); 219 | return 0; // Return 0 on when unable to allocate buffer, should this be 100? It will trigger the same issue above 220 | } 221 | 222 | fread(buf, sizeof(char), filelen, pbm); 223 | fclose(pbm); 224 | 225 | progress = 0; 226 | for (size_t i = 0x100; i < filelen; i++) { 227 | if (buf[i]) { 228 | progress++; 229 | } 230 | } 231 | 232 | free(buf); 233 | 234 | return (progress * 100 / (filelen - 0x100)); 235 | } 236 | 237 | int wait_for_usb(char *usb_name, char *usb_path) { 238 | int row = 0; 239 | char probefile[19]; 240 | int fd = -1; 241 | 242 | while (fd == -1) { 243 | sceKernelUsleep(100 * 1000); 244 | 245 | if (row >= 80) { // 10 attempts at each USB #, reaching 8 resets to 0 246 | row = 0; 247 | } else { 248 | row += 1; 249 | } 250 | 251 | snprintf_s(probefile, sizeof(probefile), "/mnt/usb%i/.probe", row / 10); 252 | fd = open(probefile, O_WRONLY | O_CREAT | O_TRUNC, 0777); 253 | } 254 | close(fd); 255 | unlink(probefile); 256 | sprintf(usb_name, "USB%i", row / 10); 257 | sprintf(usb_path, "/mnt/usb%i", row / 10); 258 | 259 | return 1; 260 | } 261 | -------------------------------------------------------------------------------- /libPS4/source/eventflag.c: -------------------------------------------------------------------------------- 1 | #include "syscall.h" 2 | 3 | #include "eventflag.h" 4 | 5 | SYSCALL(createEventFlag, 538); 6 | SYSCALL(destroyEventFlag, 539); 7 | -------------------------------------------------------------------------------- /libPS4/source/file.c: -------------------------------------------------------------------------------- 1 | #include "libc.h" 2 | #include "syscall.h" 3 | 4 | #include "file.h" 5 | 6 | SYSCALL(read, 3); 7 | SYSCALL(write, 4); 8 | SYSCALL(open, 5); 9 | SYSCALL(close, 6); 10 | SYSCALL(unlink, 10); 11 | SYSCALL(link, 9); 12 | SYSCALL(readlink, 58); 13 | SYSCALL(symlink, 57); 14 | SYSCALL(mount, 21); 15 | SYSCALL(nmount, 378); 16 | SYSCALL(unmount, 22); 17 | SYSCALL(fchown, 123); 18 | SYSCALL(fchmod, 124); 19 | SYSCALL(rename, 128); 20 | SYSCALL(mkdir, 136); 21 | SYSCALL(rmdir, 137); 22 | SYSCALL(stat, 188); 23 | SYSCALL(fstat, 189); 24 | SYSCALL(lstat, 190); 25 | SYSCALL(getdents, 272); 26 | SYSCALL(lseek, 478); 27 | SYSCALL(fstatat, 493); 28 | 29 | int getSandboxDirectory(char *destination, int *length) { 30 | return syscall(602, 0, destination, length); 31 | } 32 | 33 | int file_exists(char *fname) { 34 | int file = open(fname, O_RDONLY, 0); 35 | if (file != -1) { 36 | close(file); 37 | return 1; 38 | } 39 | return 0; 40 | } 41 | 42 | int dir_exists(char *dname) { 43 | DIR *dir = opendir(dname); 44 | if (dir) { 45 | closedir(dir); 46 | return 1; 47 | } 48 | return 0; 49 | } 50 | 51 | int symlink_exists(const char *fname) { 52 | struct stat statbuf; 53 | if (lstat(fname, &statbuf) < 0) { 54 | return -1; 55 | } 56 | if (S_ISLNK(statbuf.st_mode) == 1) { 57 | return 1; 58 | } else { 59 | return 0; 60 | } 61 | } 62 | 63 | void touch_file(char *destfile) { 64 | int fd = open(destfile, O_WRONLY | O_CREAT | O_TRUNC, 0777); 65 | if (fd != -1) { 66 | close(fd); 67 | } 68 | } 69 | 70 | void copy_file(char *sourcefile, char *destfile) { 71 | int src = open(sourcefile, O_RDONLY, 0); 72 | if (src != -1) { 73 | int out = open(destfile, O_WRONLY | O_CREAT | O_TRUNC, 0777); 74 | if (out != -1) { 75 | char *buffer = malloc(4194304); 76 | if (buffer != NULL) { 77 | size_t bytes; 78 | while ((bytes = read(src, buffer, 4194304)) > 0) { 79 | write(out, buffer, bytes); 80 | } 81 | free(buffer); 82 | } 83 | close(out); 84 | } 85 | close(src); 86 | } 87 | } 88 | 89 | void copy_dir(char *sourcedir, char *destdir) { 90 | DIR *dir = opendir(sourcedir); 91 | struct dirent *dp; 92 | struct stat info; 93 | char src_path[1024]; 94 | char dst_path[1024]; 95 | 96 | if (!dir) { 97 | return; 98 | } 99 | mkdir(destdir, 0777); 100 | while ((dp = readdir(dir)) != NULL) { 101 | if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) { 102 | continue; 103 | } else { 104 | sprintf(src_path, "%s/%s", sourcedir, dp->d_name); 105 | sprintf(dst_path, "%s/%s", destdir, dp->d_name); 106 | 107 | if (!stat(src_path, &info)) { 108 | if (S_ISDIR(info.st_mode)) { 109 | copy_dir(src_path, dst_path); 110 | } else if (S_ISREG(info.st_mode)) { 111 | copy_file(src_path, dst_path); 112 | } 113 | } 114 | } 115 | } 116 | closedir(dir); 117 | } 118 | 119 | int file_compare(char *fname1, char *fname2) { 120 | int res = 0; 121 | int file1 = open(fname1, O_RDONLY, 0); 122 | int file2 = open(fname2, O_RDONLY, 0); 123 | char *buffer1 = malloc(65536); 124 | char *buffer2 = malloc(65536); 125 | 126 | if (file1 && file2 && buffer1 != NULL && buffer2 != NULL) { 127 | lseek(file1, 0, SEEK_END); 128 | lseek(file2, 0, SEEK_END); 129 | long size1 = lseek(file1, 0, SEEK_CUR); 130 | long size2 = lseek(file2, 0, SEEK_CUR); 131 | lseek(file1, 0L, SEEK_SET); 132 | lseek(file2, 0L, SEEK_SET); 133 | if (size1 == size2) { 134 | int lastBytes = 100; 135 | if (size1 < lastBytes) { 136 | lastBytes = size1; 137 | } 138 | lseek(file1, -lastBytes, SEEK_END); 139 | lseek(file2, -lastBytes, SEEK_END); 140 | int bytesRead1 = read(file1, buffer1, sizeof(char)); 141 | int bytesRead2 = read(file2, buffer2, sizeof(char)); 142 | if (bytesRead1 > 0 && bytesRead1 == bytesRead2) { 143 | res = 1; 144 | for (int i = 0; i < bytesRead1; i++) { 145 | if (buffer1[i] != buffer2[i]) { 146 | res = 0; 147 | break; 148 | } 149 | } 150 | } 151 | } 152 | } 153 | 154 | free(buffer1); 155 | free(buffer2); 156 | close(file1); 157 | close(file2); 158 | return res; 159 | } 160 | 161 | int rmtree(const char *path) { 162 | DIR *d = opendir(path); 163 | int r = -1; 164 | 165 | if (d) { 166 | struct dirent *p; 167 | 168 | r = 0; 169 | while (!r && (p = readdir(d))) { 170 | int r2 = -1; 171 | char *buf; 172 | size_t len; 173 | 174 | if (!strcmp(p->d_name, ".") || !strcmp(p->d_name, "..")) { 175 | continue; 176 | } 177 | 178 | len = strlen(path) + strlen(p->d_name) + 2; 179 | buf = malloc(len); 180 | 181 | if (buf) { 182 | struct stat statbuf; 183 | 184 | snprintf(buf, len, "%s/%s", path, p->d_name); 185 | if (!stat(buf, &statbuf)) { 186 | if (S_ISDIR(statbuf.st_mode)) { 187 | r2 = rmtree(buf); 188 | } else { 189 | r2 = unlink(buf); 190 | } 191 | } 192 | free(buf); 193 | } 194 | r = r2; 195 | } 196 | closedir(d); 197 | } 198 | 199 | if (!r) { 200 | r = rmdir(path); 201 | } 202 | 203 | return r; 204 | } 205 | 206 | int fgetc_pointer(int fp) { 207 | char c; 208 | if (read(fp, &c, 1) == 0) { 209 | return (-1); 210 | } 211 | return (c); 212 | } 213 | 214 | void build_iovec(struct iovec **iov, int *iovlen, const char *name, const void *val, size_t len) { 215 | int i; 216 | if (*iovlen < 0) { 217 | return; 218 | } 219 | i = *iovlen; 220 | *iov = realloc(*iov, sizeof **iov * (i + 2)); 221 | if (*iov == NULL) { 222 | *iovlen = -1; 223 | return; 224 | } 225 | (*iov)[i].iov_base = strdup(name); 226 | (*iov)[i].iov_len = strlen(name) + 1; 227 | ++i; 228 | (*iov)[i].iov_base = (void *)val; 229 | if (len == (size_t)-1) { 230 | if (val != NULL) { 231 | len = strlen(val) + 1; 232 | } else { 233 | len = 0; 234 | } 235 | } 236 | (*iov)[i].iov_len = (int)len; 237 | *iovlen = ++i; 238 | } 239 | 240 | int mount_large_fs(const char *device, const char *mountpoint, const char *fstype, const char *mode, unsigned int flags) { 241 | struct iovec *iov = NULL; 242 | int iovlen = 0; 243 | build_iovec(&iov, &iovlen, "fstype", fstype, -1); 244 | build_iovec(&iov, &iovlen, "fspath", mountpoint, -1); 245 | build_iovec(&iov, &iovlen, "from", device, -1); 246 | build_iovec(&iov, &iovlen, "large", "yes", -1); 247 | build_iovec(&iov, &iovlen, "timezone", "static", -1); 248 | build_iovec(&iov, &iovlen, "async", "", -1); 249 | build_iovec(&iov, &iovlen, "ignoreacl", "", -1); 250 | if (mode) { 251 | build_iovec(&iov, &iovlen, "dirmask", mode, -1); 252 | build_iovec(&iov, &iovlen, "mask", mode, -1); 253 | } 254 | return nmount(iov, iovlen, flags); 255 | } 256 | -------------------------------------------------------------------------------- /libPS4/source/jit.c: -------------------------------------------------------------------------------- 1 | #include "kernel.h" 2 | #include "memory.h" 3 | #include "module.h" 4 | 5 | #include "jit.h" 6 | 7 | int libJIT; 8 | 9 | int (*sceKernelJitCreateSharedMemory)(int flags, size_t size, int protection, int *destinationHandle); 10 | int (*sceKernelJitCreateAliasOfSharedMemory)(int handle, int protection, int *destinationHandle); 11 | int (*sceKernelJitMapSharedMemory)(int handle, int protection, void **destination); 12 | 13 | void initJIT(void) { 14 | if (libJIT) { 15 | return; 16 | } 17 | 18 | RESOLVE(libKernelHandle, sceKernelJitCreateSharedMemory); 19 | RESOLVE(libKernelHandle, sceKernelJitCreateAliasOfSharedMemory); 20 | RESOLVE(libKernelHandle, sceKernelJitMapSharedMemory); 21 | 22 | libJIT = 1; 23 | } 24 | 25 | void allocateJIT(size_t size, void **executableAddress, void **writableAddress) { 26 | int executableHandle; 27 | int writableHandle; 28 | 29 | sceKernelJitCreateSharedMemory(0, size, PROT_CPU_READ | PROT_CPU_WRITE | PROT_CPU_EXEC, &executableHandle); 30 | sceKernelJitCreateAliasOfSharedMemory(executableHandle, PROT_CPU_READ | PROT_CPU_WRITE, &writableHandle); 31 | 32 | *executableAddress = mmap(NULL, size, PROT_CPU_READ | PROT_CPU_EXEC, MAP_SHARED, executableHandle, 0); 33 | 34 | //sceKernelJitMapSharedMemory(writableHandle, PROT_CPU_READ | PROT_CPU_WRITE, writableAddress); 35 | *writableAddress = mmap(NULL, size, PROT_CPU_READ | PROT_CPU_WRITE, MAP_PRIVATE | MAP_TYPE, writableHandle, 0); 36 | } 37 | -------------------------------------------------------------------------------- /libPS4/source/kernel.c: -------------------------------------------------------------------------------- 1 | #include "module.h" 2 | #include "syscall.h" 3 | 4 | #include "kernel.h" 5 | 6 | int libKernelHandle; 7 | 8 | int **__stack_chk_guard; 9 | void (*__stack_chk_fail)(void); 10 | int *(*__error)(); 11 | 12 | int (*sceKernelError)(int); 13 | 14 | int (*sceKernelLoadStartModule)(const char *name, size_t argc, const void *argv, unsigned int flags, int, int); 15 | 16 | int (*sceKernelAllocateDirectMemory)(off_t searchStart, off_t searchEnd, size_t length, size_t alignment, int type, off_t *physicalAddressDestination); 17 | int (*sceKernelMapDirectMemory)(void **addr, size_t length, int protection, int flags, off_t start, size_t alignment); 18 | size_t (*sceKernelGetDirectMemorySize)(); 19 | 20 | int (*sceKernelStat)(const char *path, void *buf); 21 | int (*sceKernelOpen)(const char *path, int flags, int mode); 22 | int (*sceKernelRead)(int fd, void *buf, size_t nbyte); 23 | int (*sceKernelLseek)(int fd, off_t offset, int whence); 24 | int (*sceKernelClose)(int fd); 25 | 26 | unsigned int (*sceKernelSleep)(unsigned int seconds); 27 | int (*sceKernelUsleep)(unsigned int microseconds); 28 | int (*usleep)(unsigned int microseconds); 29 | int (*sceKernelGettimeofday)(SceKernelTimeval *tp); 30 | uint64_t (*sceKernelGetProcessTime)(void); 31 | int (*sceKernelGetCurrentCpu)(void); 32 | 33 | int (*sysctl)(int *name, unsigned int namelen, char *oldval, size_t *oldlen, char *newval, size_t newlen); 34 | int (*sysctlbyname)(char *name, char *oldval, size_t *oldlen, char *newval, size_t newlen); 35 | int (*sysarch)(int type, void *arg); 36 | int (*execve)(char *path, char *argv[], char *envp[]); 37 | 38 | void *(*pthread_self)(); 39 | int (*pthread_setaffinity_np)(void *one, long unsigned int two, void *three); 40 | 41 | int (*sceKernelCreateEqueue)(SceKernelEqueue *eq, const char *name); 42 | int (*sceKernelDeleteEqueue)(SceKernelEqueue eq); 43 | int (*sceKernelAddUserEvent)(SceKernelEqueue eq, int id); 44 | int (*sceKernelAddReadEvent)(SceKernelEqueue eq, int fd, size_t size, void *udata); 45 | 46 | int (*getuid)(); 47 | int (*getgid)(); 48 | int (*getpid)(); 49 | 50 | int (*setuid)(int uid); 51 | int (*setgid)(int gid); 52 | int (*setreuid)(int ruid, int euid); 53 | int (*setregid)(int rgid, int egid); 54 | 55 | int (*sceKernelSendNotificationRequest)(int device, SceNotificationRequest *req, size_t size, int blocking); 56 | const char *(*sceKernelGetFsSandboxRandomWord)(); 57 | int (*sceKernelGetSystemSwVersion)(SceFwInfo *fw_info); 58 | 59 | uint32_t (*sceKernelGetCpuTemperature)(uint32_t *); 60 | 61 | uint32_t (*sceKernelGetIdPs)(void *); 62 | uint32_t (*sceKernelGetOpenPsId)(void *); 63 | uint32_t (*sceKernelGetOpenPsIdForSystem)(void *); 64 | 65 | SYSCALL(kill, 37); 66 | SYSCALL(ioctl, 54); 67 | 68 | SYSCALL(kexec, 11); 69 | 70 | void initKernel(void) { 71 | if (libKernelHandle) { 72 | return; 73 | } 74 | 75 | __error = NULL; 76 | 77 | if (loadModule("libkernel.sprx", &libKernelHandle)) { 78 | if (loadModule("libkernel_web.sprx", &libKernelHandle)) { 79 | loadModule("libkernel_sys.sprx", &libKernelHandle); 80 | } 81 | } 82 | 83 | RESOLVE(libKernelHandle, __stack_chk_guard); 84 | RESOLVE(libKernelHandle, __stack_chk_fail); 85 | RESOLVE(libKernelHandle, __error); 86 | 87 | RESOLVE(libKernelHandle, sceKernelError); 88 | 89 | RESOLVE(libKernelHandle, sceKernelLoadStartModule); 90 | 91 | RESOLVE(libKernelHandle, sceKernelAllocateDirectMemory); 92 | RESOLVE(libKernelHandle, sceKernelMapDirectMemory); 93 | RESOLVE(libKernelHandle, sceKernelGetDirectMemorySize); 94 | 95 | RESOLVE(libKernelHandle, sceKernelStat); 96 | RESOLVE(libKernelHandle, sceKernelOpen); 97 | RESOLVE(libKernelHandle, sceKernelRead); 98 | RESOLVE(libKernelHandle, sceKernelLseek); 99 | RESOLVE(libKernelHandle, sceKernelClose); 100 | 101 | RESOLVE(libKernelHandle, sceKernelSleep); 102 | RESOLVE(libKernelHandle, sceKernelUsleep); 103 | RESOLVE(libKernelHandle, usleep); 104 | RESOLVE(libKernelHandle, sceKernelGettimeofday); 105 | RESOLVE(libKernelHandle, sceKernelGetProcessTime); 106 | RESOLVE(libKernelHandle, sceKernelGetCurrentCpu); 107 | 108 | RESOLVE(libKernelHandle, sysctl); 109 | RESOLVE(libKernelHandle, sysctlbyname); 110 | RESOLVE(libKernelHandle, sysarch); 111 | RESOLVE(libKernelHandle, execve); 112 | 113 | RESOLVE(libKernelHandle, pthread_self); 114 | RESOLVE(libKernelHandle, pthread_setaffinity_np); 115 | 116 | RESOLVE(libKernelHandle, sceKernelCreateEqueue); 117 | RESOLVE(libKernelHandle, sceKernelDeleteEqueue); 118 | RESOLVE(libKernelHandle, sceKernelAddUserEvent); 119 | RESOLVE(libKernelHandle, sceKernelAddReadEvent); 120 | 121 | RESOLVE(libKernelHandle, getuid); 122 | RESOLVE(libKernelHandle, getgid); 123 | RESOLVE(libKernelHandle, getpid); 124 | 125 | RESOLVE(libKernelHandle, setuid); 126 | RESOLVE(libKernelHandle, setgid); 127 | RESOLVE(libKernelHandle, setreuid); 128 | RESOLVE(libKernelHandle, setregid); 129 | 130 | RESOLVE(libKernelHandle, sceKernelSendNotificationRequest); 131 | RESOLVE(libKernelHandle, sceKernelGetFsSandboxRandomWord); 132 | RESOLVE(libKernelHandle, sceKernelGetSystemSwVersion); 133 | 134 | RESOLVE(libKernelHandle, sceKernelGetCpuTemperature); 135 | 136 | RESOLVE(libKernelHandle, sceKernelGetIdPs); 137 | RESOLVE(libKernelHandle, sceKernelGetOpenPsId); 138 | RESOLVE(libKernelHandle, sceKernelGetOpenPsIdForSystem); 139 | } 140 | -------------------------------------------------------------------------------- /libPS4/source/libc.c: -------------------------------------------------------------------------------- 1 | #include "file.h" 2 | #include "kernel.h" 3 | #include "module.h" 4 | 5 | #include "libc.h" 6 | 7 | int libc; 8 | 9 | void *(*malloc)(size_t size); 10 | void (*free)(void *ptr); 11 | void *(*calloc)(size_t num, size_t size); 12 | void *(*realloc)(void *ptr, size_t size); 13 | void *(*memalign)(size_t boundary, size_t size); 14 | void *(*memset)(void *destination, int value, size_t num); 15 | void *(*memcpy)(void *destination, const void *source, size_t num); 16 | int (*memcmp)(const void *s1, const void *s2, size_t n); 17 | void *(*memmove)(void *dst, const void *src, size_t len); 18 | errno_t (*memmove_s)(void *dest, rsize_t destsz, const void *src, rsize_t count); 19 | char *(*strcpy)(char *destination, const char *source); 20 | char *(*strncpy)(char *destination, const char *source, size_t num); 21 | errno_t *(*strncpy_s)(char *restrict dest, rsize_t destsz, const char *restrict src, rsize_t count); 22 | char *(*strcat)(char *dest, const char *src); 23 | char *(*strncat)(char *dest, const char *src, size_t n); 24 | size_t (*strlen)(const char *s); 25 | int (*strcmp)(const char *s1, const char *s2); 26 | int (*strncmp)(const char *s1, const char *s2, size_t n); 27 | int (*sprintf)(char *str, const char *format, ...); 28 | int (*snprintf)(char *str, size_t size, const char *format, ...); 29 | int (*snprintf_s)(char *restrict buffer, rsize_t bufsz, const char *restrict format, ...); 30 | int (*sscanf)(const char *str, const char *format, ...); 31 | int (*strtol)(const char* s1, char** s2, int base); 32 | char *(*strtok)(char *str, const char *delimiters); 33 | char *(*strchr)(const char *s, int c); 34 | char *(*strrchr)(const char *s, int c); 35 | char *(*strstr)(char *str1, char *str2); 36 | char *(*strdup)(const char *s); 37 | char *(*strtok)(char *str, const char *sep); 38 | char *(*index)(const char *s, int c); 39 | char *(*rindex)(const char *s, int c); 40 | int (*isdigit)(int c); 41 | int (*atoi)(const char *s); 42 | double (*atof)(const char *s); 43 | size_t (*strlcpy)(char *dst, const char *src, size_t size); 44 | char *(*strerror)(int errnum); 45 | void *(*_Getpctype)(); 46 | unsigned long (*_Stoul)(const char *, char **, int); 47 | void (*bcopy)(const void *s1, void *s2, size_t n); 48 | double (*ceil)(double x); 49 | 50 | void (*srand)(unsigned int seed); 51 | int (*rand)(void); 52 | 53 | char *(*asctime)(const struct tm *tm); 54 | char *(*asctime_r)(const struct tm *tm, char *buf); 55 | char *(*ctime)(const time_t *timep); 56 | char *(*ctime_r)(const time_t *timep, char *buf); 57 | time_t (*time)(time_t *tloc); 58 | struct tm *(*gmtime)(const time_t *timep); 59 | struct tm *(*gmtime_s)(const time_t *timep, struct tm *result); 60 | struct tm *(*localtime)(const time_t *timep); 61 | struct tm *(*localtime_r)(const time_t *timep, struct tm *result); 62 | time_t (*mktime)(struct tm *tm); 63 | 64 | DIR *(*opendir)(const char *filename); 65 | struct dirent *(*readdir)(DIR *dirp); 66 | int (*readdir_r)(DIR *dirp, struct dirent *entry, struct dirent **result); 67 | long (*telldir)(const DIR *dirp); 68 | void (*seekdir)(DIR *dirp, long loc); 69 | void (*rewinddir)(DIR *dirp); 70 | int (*closedir)(DIR *dirp); 71 | int (*dirfd)(DIR *dirp); 72 | char *(*getprogname)(); 73 | 74 | FILE *(*fopen)(const char *filename, const char *mode); 75 | size_t (*fread)(void *ptr, size_t size, size_t count, FILE *stream); 76 | size_t (*fwrite)(const void *ptr, size_t size, size_t count, FILE *stream); 77 | int (*fseek)(FILE *stream, long int offset, int origin); 78 | long int (*ftell)(FILE *stream); 79 | int (*fclose)(FILE *stream); 80 | int (*fprintf)(FILE *stream, const char *format, ...); 81 | 82 | int memset_s(void *s, rsize_t smax, int c, rsize_t n) { 83 | bool violation = (s == NULL) || (smax > RSIZE_MAX) || (n > RSIZE_MAX) || (n > smax); 84 | if (violation) { 85 | if ((s != NULL) && !(smax > RSIZE_MAX)) { 86 | for (rsize_t i = 0; i < smax; ++i) { 87 | ((volatile unsigned char *)s)[i] = c; 88 | } 89 | } 90 | return 1; 91 | } else { 92 | for (rsize_t i = 0; i < n; ++i) { 93 | ((volatile unsigned char *)s)[i] = c; 94 | } 95 | return 0; 96 | } 97 | } 98 | 99 | void initLibc(void) { 100 | if (libc) { 101 | return; 102 | } 103 | 104 | libc = sceKernelLoadStartModule("libSceLibcInternal.sprx", 0, 0, 0, NULL, NULL); 105 | 106 | RESOLVE(libc, malloc); 107 | RESOLVE(libc, free); 108 | RESOLVE(libc, calloc); 109 | RESOLVE(libc, realloc); 110 | RESOLVE(libc, memalign); 111 | RESOLVE(libc, memset); 112 | RESOLVE(libc, memcpy); 113 | RESOLVE(libc, memcmp); 114 | RESOLVE(libc, memmove); 115 | RESOLVE(libc, memmove_s); 116 | RESOLVE(libc, strcpy); 117 | RESOLVE(libc, strncpy); 118 | RESOLVE(libc, strncpy_s); 119 | RESOLVE(libc, strcat); 120 | RESOLVE(libc, strncat); 121 | RESOLVE(libc, strlen); 122 | RESOLVE(libc, strcmp); 123 | RESOLVE(libc, strncmp); 124 | RESOLVE(libc, sprintf); 125 | RESOLVE(libc, snprintf); 126 | RESOLVE(libc, snprintf_s); 127 | RESOLVE(libc, sscanf); 128 | RESOLVE(libc, strtol); 129 | RESOLVE(libc, strtok); 130 | RESOLVE(libc, strchr); 131 | RESOLVE(libc, strrchr); 132 | RESOLVE(libc, strstr); 133 | RESOLVE(libc, strdup); 134 | RESOLVE(libc, strtok); 135 | RESOLVE(libc, index); 136 | RESOLVE(libc, rindex); 137 | RESOLVE(libc, isdigit); 138 | RESOLVE(libc, atoi); 139 | RESOLVE(libc, atof); 140 | RESOLVE(libc, strlcpy); 141 | RESOLVE(libc, strerror); 142 | RESOLVE(libc, _Getpctype); 143 | RESOLVE(libc, _Stoul); 144 | RESOLVE(libc, bcopy); 145 | RESOLVE(libc, ceil); 146 | 147 | RESOLVE(libc, srand); 148 | RESOLVE(libc, rand); 149 | 150 | RESOLVE(libc, asctime); 151 | RESOLVE(libc, asctime_r); 152 | RESOLVE(libc, ctime); 153 | RESOLVE(libc, ctime_r); 154 | RESOLVE(libc, time); 155 | RESOLVE(libc, gmtime); 156 | RESOLVE(libc, gmtime_s); 157 | RESOLVE(libc, localtime); 158 | RESOLVE(libc, localtime_r); 159 | RESOLVE(libc, mktime); 160 | 161 | RESOLVE(libc, opendir); 162 | RESOLVE(libc, readdir); 163 | RESOLVE(libc, readdir_r); 164 | RESOLVE(libc, telldir); 165 | RESOLVE(libc, seekdir); 166 | RESOLVE(libc, rewinddir); 167 | RESOLVE(libc, closedir); 168 | RESOLVE(libc, dirfd); 169 | 170 | RESOLVE(libc, getprogname); 171 | 172 | RESOLVE(libc, fopen); 173 | RESOLVE(libc, fread); 174 | RESOLVE(libc, fwrite); 175 | RESOLVE(libc, fseek); 176 | RESOLVE(libc, ftell); 177 | RESOLVE(libc, fclose); 178 | RESOLVE(libc, fprintf); 179 | } 180 | -------------------------------------------------------------------------------- /libPS4/source/memory.c: -------------------------------------------------------------------------------- 1 | #include "syscall.h" 2 | 3 | #include "memory.h" 4 | 5 | SYSCALL(mmap, 477); 6 | SYSCALL(munmap, 73); 7 | SYSCALL(mprotect, 74); 8 | SYSCALL(msync, 65); 9 | SYSCALL(mlock, 203); 10 | SYSCALL(munlock, 204); 11 | 12 | SYSCALL(getMemoryInfo, 547); 13 | SYSCALL(getOtherMemoryInfo, 572); 14 | -------------------------------------------------------------------------------- /libPS4/source/module.c: -------------------------------------------------------------------------------- 1 | #include "kernel.h" 2 | #include "syscall.h" 3 | 4 | #include "module.h" 5 | 6 | int libModule; 7 | 8 | int (*sceSysmoduleLoadModule)(int id); 9 | 10 | SYSCALL(getFunctionAddressByName, 591); 11 | SYSCALL(getLoadedModules, 592); 12 | 13 | int getModuleInfo(int loadedModuleID, struct moduleInfo *destination) { 14 | destination->size = sizeof(*destination); 15 | return syscall(593, loadedModuleID, destination); 16 | } 17 | 18 | int loadModule(const char *name, int *idDestination) { 19 | return syscall(594, name, 0, idDestination, 0); 20 | } 21 | 22 | int unloadModule(int id) { 23 | return syscall(595, id, 0, 0); 24 | } 25 | 26 | void initModule(void) { 27 | if (libModule) { 28 | return; 29 | } 30 | 31 | libModule = sceKernelLoadStartModule("libSceSysmodule.sprx", 0, 0, 0, NULL, NULL); 32 | 33 | // Just use sceKernelLoadStartModule instead 34 | RESOLVE(libModule, sceSysmoduleLoadModule); 35 | } 36 | -------------------------------------------------------------------------------- /libPS4/source/network.c: -------------------------------------------------------------------------------- 1 | #include "file.h" 2 | #include "kernel.h" 3 | #include "libc.h" 4 | #include "module.h" 5 | 6 | #include "network.h" 7 | 8 | int libNet; 9 | int libNetCtl; 10 | 11 | int *(*sceNetErrnoLoc)(void); 12 | 13 | int (*sceNetSocket)(const char *, int, int, int); 14 | int (*sceNetSocketClose)(int); 15 | int (*sceNetConnect)(int, struct sockaddr *, int); 16 | int (*sceNetSend)(int, const void *, size_t, int); 17 | int (*sceNetBind)(int, struct sockaddr *, int); 18 | int (*sceNetListen)(int, int); 19 | int (*sceNetAccept)(int, struct sockaddr *, unsigned int *); 20 | int (*sceNetRecv)(int, void *, size_t, int); 21 | int (*sceNetSocketAbort)(int, int); 22 | 23 | int (*sceNetGetsockname)(int, struct sockaddr *, unsigned int *); 24 | int (*sceNetGetsockopt)(int s, int level, int optname, void *restrict optval, socklen_t *restrict optlen); 25 | int (*sceNetSetsockopt)(int s, int level, int optname, const void *optval, socklen_t optlen); 26 | 27 | char (*sceNetInetNtop)(int af, const void *src, char *dst, int size); 28 | int (*sceNetInetPton)(int af, const char *src, void *dst); 29 | 30 | uint64_t (*sceNetHtonll)(uint64_t host64); 31 | uint32_t (*sceNetHtonl)(uint32_t host32); 32 | uint16_t (*sceNetHtons)(uint16_t host16); 33 | uint64_t (*sceNetNtohll)(uint64_t net64); 34 | uint32_t (*sceNetNtohl)(uint32_t net32); 35 | uint16_t (*sceNetNtohs)(uint16_t net16); 36 | 37 | int (*sceNetCtlInit)(void); 38 | void (*sceNetCtlTerm)(void); 39 | int (*sceNetCtlGetInfo)(int code, SceNetCtlInfo *info); 40 | 41 | void initNetwork(void) { 42 | if (!libNet) { 43 | libNet = sceKernelLoadStartModule("libSceNet.sprx", 0, 0, 0, NULL, NULL); 44 | 45 | RESOLVE(libNet, sceNetErrnoLoc); 46 | 47 | RESOLVE(libNet, sceNetSocket); 48 | RESOLVE(libNet, sceNetSocketClose); 49 | RESOLVE(libNet, sceNetConnect); 50 | RESOLVE(libNet, sceNetSend); 51 | RESOLVE(libNet, sceNetBind); 52 | RESOLVE(libNet, sceNetListen); 53 | RESOLVE(libNet, sceNetAccept); 54 | RESOLVE(libNet, sceNetRecv); 55 | RESOLVE(libNet, sceNetSocketAbort); 56 | 57 | RESOLVE(libNet, sceNetGetsockname); 58 | RESOLVE(libNet, sceNetGetsockopt); 59 | RESOLVE(libNet, sceNetSetsockopt); 60 | 61 | RESOLVE(libNet, sceNetInetNtop); 62 | RESOLVE(libNet, sceNetInetPton); 63 | 64 | RESOLVE(libNet, sceNetHtonll); 65 | RESOLVE(libNet, sceNetHtonl); 66 | RESOLVE(libNet, sceNetHtons); 67 | RESOLVE(libNet, sceNetNtohll); 68 | RESOLVE(libNet, sceNetNtohl); 69 | RESOLVE(libNet, sceNetNtohs); 70 | } 71 | 72 | if (!libNetCtl) { 73 | libNetCtl = sceKernelLoadStartModule("libSceNetCtl.sprx", 0, 0, 0, NULL, NULL); 74 | 75 | RESOLVE(libNetCtl, sceNetCtlInit); 76 | RESOLVE(libNetCtl, sceNetCtlTerm); 77 | RESOLVE(libNetCtl, sceNetCtlGetInfo); 78 | } 79 | } 80 | 81 | int SckConnect(char *hostIP, int hostPort) { 82 | struct in_addr ip_addr; 83 | sceNetInetPton(AF_INET, hostIP, &ip_addr); 84 | struct sockaddr_in sk; 85 | sk.sin_len = sizeof(sk); 86 | sk.sin_family = AF_INET; 87 | sk.sin_addr = ip_addr; 88 | sk.sin_port = sceNetHtons(hostPort); 89 | memset(sk.sin_zero, 0, sizeof(sk.sin_zero)); 90 | char socketName[] = "psocket"; 91 | int sck = sceNetSocket(socketName, AF_INET, SOCK_STREAM, 0); 92 | sceNetConnect(sck, (struct sockaddr *)&sk, sizeof(sk)); 93 | return sck; 94 | } 95 | 96 | void SckClose(int socket) { 97 | sceNetSocketClose(socket); 98 | } 99 | 100 | void SckSend(int socket, char *sdata, int length) { 101 | sceNetSend(socket, sdata, length, 0); 102 | } 103 | 104 | char *SckRecv(int socket) { 105 | char rbuf[4096], *retval = malloc(sizeof(char) * 1); 106 | int plen, length = 0, i; 107 | while ((plen = sceNetRecv(socket, rbuf, sizeof(rbuf), 0)) > 0) { 108 | void *tmp = (char *)realloc(retval, sizeof(char) * (length + plen) + 1); 109 | if (tmp == NULL) { 110 | free(retval); 111 | return NULL; 112 | } else { 113 | retval = tmp; 114 | } 115 | for (i = 0; i < plen; i++) { 116 | retval[length] = rbuf[i]; 117 | length++; 118 | } 119 | memset(rbuf, 0, sizeof rbuf); 120 | } 121 | return retval; 122 | } 123 | 124 | void SckRecvf(int socket, char *destfile) { 125 | char rbuf[4096]; 126 | int plen, fid = open(destfile, O_WRONLY | O_CREAT | O_TRUNC, 0777); 127 | while ((plen = sceNetRecv(socket, rbuf, sizeof(rbuf), 0)) > 0) { 128 | write(fid, rbuf, plen); 129 | memset(rbuf, 0, sizeof rbuf); 130 | } 131 | close(fid); 132 | } 133 | -------------------------------------------------------------------------------- /libPS4/source/pad.c: -------------------------------------------------------------------------------- 1 | #include "kernel.h" 2 | #include "module.h" 3 | 4 | #include "pad.h" 5 | 6 | int libPad; 7 | 8 | int (*scePadInit)(void); 9 | int (*scePadOpen)(int userID, int, int, void *); 10 | int (*scePadClose)(int handle); 11 | int (*scePadRead)(int handle, void *data, int count); 12 | int (*scePadReadState)(int handle, void *data); 13 | 14 | void initPad(void) { 15 | if (libPad) { 16 | return; 17 | } 18 | 19 | libPad = sceKernelLoadStartModule("libScePad.sprx", 0, 0, 0, NULL, NULL); 20 | 21 | RESOLVE(libPad, scePadInit); 22 | RESOLVE(libPad, scePadOpen); 23 | RESOLVE(libPad, scePadClose); 24 | RESOLVE(libPad, scePadRead); 25 | RESOLVE(libPad, scePadReadState); 26 | 27 | scePadInit(); 28 | } 29 | -------------------------------------------------------------------------------- /libPS4/source/payload_utils.c: -------------------------------------------------------------------------------- 1 | #include "debug.h" 2 | #include "elf.h" 3 | #include "file.h" 4 | #include "fw_defines.h" 5 | #include "kernel.h" 6 | #include "libc.h" 7 | #include "memory.h" 8 | 9 | #include "payload_utils.h" 10 | 11 | uint16_t g_firmware; 12 | 13 | int is_fw_spoofed() { 14 | SceFwInfo ssv_fw; 15 | char ssv_fw_trimmed[5]; 16 | uint16_t ssv_fw_final; 17 | 18 | uint16_t libc_fw = get_firmware(); 19 | sceKernelGetSystemSwVersion(&ssv_fw); 20 | 21 | char temp[0x1C]; 22 | snprintf(temp, 0x1C, "%s", ssv_fw.version_string); 23 | 24 | char *first = strtok(temp, "."); 25 | char *second = strtok(NULL, "."); 26 | 27 | sprintf(ssv_fw_trimmed, "%s%c%c", first, second[0], second[1]); 28 | 29 | ssv_fw_final = atoi(ssv_fw_trimmed); 30 | 31 | if (ssv_fw_final != libc_fw) { 32 | return 1; 33 | } 34 | 35 | return 0; 36 | } 37 | 38 | int is_jailbroken() { 39 | int fd = open("/user/.jailbreak", O_WRONLY, 0777); 40 | if (fd >= 0) { 41 | close(fd); 42 | unlink("/user/.jailbreak"); 43 | return 1; 44 | } else { 45 | return 0; 46 | } 47 | } 48 | 49 | int kpayload_kbase(struct thread *td, struct kpayload_kbase_args *args) { 50 | UNUSED(td); 51 | void *kernel_base; 52 | 53 | int (*copyout)(const void *kaddr, void *uaddr, size_t len); 54 | 55 | uint16_t fw_version = args->kpayload_kbase_info->fw_version; 56 | 57 | // NOTE: This is a C preprocessor macro 58 | build_kpayload(fw_version, copyout_macro); 59 | 60 | uint64_t uaddr = args->kpayload_kbase_info->uaddr; 61 | copyout(&kernel_base, (uint64_t *)uaddr, 8); 62 | 63 | return 0; 64 | } 65 | 66 | int kpayload_dump(struct thread *td, struct kpayload_dump_args *args) { 67 | UNUSED(td); 68 | void *kernel_base; 69 | 70 | int (*copyout)(const void *kaddr, void *uaddr, size_t len); 71 | 72 | uint16_t fw_version = args->kpayload_dump_info->fw_version; 73 | 74 | // NOTE: This is a C preprocessor macro 75 | build_kpayload(fw_version, copyout_macro); 76 | 77 | uint64_t kaddr = args->kpayload_dump_info->kaddr; 78 | uint64_t uaddr = args->kpayload_dump_info->uaddr; 79 | size_t size = args->kpayload_dump_info->size; 80 | 81 | int ret = copyout((uint64_t *)kaddr, (uint64_t *)uaddr, size); 82 | 83 | if (ret == -1) { 84 | memset((uint64_t *)uaddr, 0, size); 85 | } 86 | 87 | return ret; 88 | } 89 | 90 | int kpayload_jailbreak(struct thread *td, struct kpayload_firmware_args *args) { 91 | struct filedesc *fd; 92 | struct ucred *cred; 93 | fd = td->td_proc->p_fd; 94 | cred = td->td_proc->p_ucred; 95 | 96 | void *kernel_base; 97 | uint8_t *kernel_ptr; 98 | void **prison0; 99 | void **rootvnode; 100 | 101 | uint16_t fw_version = args->kpayload_firmware_info->fw_version; 102 | 103 | // NOTE: This is a C preprocessor macro 104 | build_kpayload(fw_version, jailbreak_macro); 105 | 106 | cred->cr_uid = 0; 107 | cred->cr_ruid = 0; 108 | cred->cr_rgid = 0; 109 | cred->cr_groups[0] = 0; 110 | 111 | cred->cr_prison = *prison0; 112 | fd->fd_rdir = fd->fd_jdir = *rootvnode; 113 | 114 | void *td_ucred = *(void **)(((char *)td) + 304); 115 | 116 | uint64_t *sonyCred = (uint64_t *)(((char *)td_ucred) + 96); 117 | *sonyCred = 0xffffffffffffffff; 118 | 119 | uint64_t *sceProcessAuthorityId = (uint64_t *)(((char *)td_ucred) + 88); 120 | *sceProcessAuthorityId = 0x3801000000000013; 121 | 122 | uint64_t *sceProcCap = (uint64_t *)(((char *)td_ucred) + 104); 123 | *sceProcCap = 0xffffffffffffffff; 124 | 125 | return 0; 126 | } 127 | 128 | int kpayload_mmap(struct thread *td, struct kpayload_firmware_args *args) { 129 | UNUSED(td); 130 | void *kernel_base; 131 | uint8_t *kernel_ptr; 132 | 133 | uint8_t *kmem; 134 | uint8_t *mmap_patch_1; 135 | uint8_t *mmap_patch_2; 136 | uint8_t *mmap_patch_3; 137 | 138 | uint16_t fw_version = args->kpayload_firmware_info->fw_version; 139 | 140 | // NOTE: This is a C preprocessor macro 141 | build_kpayload(fw_version, mmap_macro); 142 | 143 | uint64_t cr0 = readCr0(); 144 | writeCr0(cr0 & ~X86_CR0_WP); 145 | 146 | kmem = (uint8_t *)mmap_patch_1; 147 | kmem[0] = 0xB8; 148 | kmem[1] = 0x01; 149 | kmem[2] = 0x00; 150 | kmem[3] = 0x00; 151 | kmem[4] = 0x00; 152 | kmem[5] = 0xC3; 153 | 154 | kmem = (uint8_t *)mmap_patch_2; 155 | kmem[0] = 0xB8; 156 | kmem[1] = 0x01; 157 | kmem[2] = 0x00; 158 | kmem[3] = 0x00; 159 | kmem[4] = 0x00; 160 | kmem[5] = 0xC3; 161 | 162 | kmem = (uint8_t *)mmap_patch_3; 163 | kmem[0] = 0x31; 164 | kmem[1] = 0xC0; 165 | kmem[2] = 0xEB; 166 | kmem[3] = 0x01; 167 | 168 | writeCr0(cr0); 169 | 170 | return 0; 171 | } 172 | 173 | int kpayload_aslr(struct thread *td, struct kpayload_firmware_args *args) { 174 | UNUSED(td); 175 | void *kernel_base; 176 | uint8_t *kernel_ptr; 177 | 178 | uint8_t *kmem; 179 | uint8_t *aslr_patch; 180 | 181 | uint16_t fw_version = args->kpayload_firmware_info->fw_version; 182 | 183 | // NOTE: This is a C preprocessor macro 184 | build_kpayload(fw_version, aslr_macro); 185 | 186 | uint64_t cr0 = readCr0(); 187 | writeCr0(cr0 & ~X86_CR0_WP); 188 | 189 | // This may change depending on new firmware's function structure 190 | kmem = (uint8_t *)aslr_patch; 191 | kmem[0] = 0xEB; 192 | if (fw_version < 600 || fw_version > 755) { 193 | // 3.50-5.56 and 8.00-12.50 194 | kmem[1] = 0x00; 195 | } 196 | 197 | writeCr0(cr0); 198 | 199 | return 0; 200 | } 201 | 202 | int kpayload_kernel_clock(struct thread *td, struct kpayload_kclock_args *args) { 203 | UNUSED(td); 204 | void *kernel_base; 205 | 206 | void (*sceSblSrtcSetTime)(uint64_t tm); 207 | void (*sceSblSrtcClearTimeDifference)(uint64_t value); 208 | 209 | uint16_t fw_version = args->kpayload_kclock_info->fw_version; 210 | 211 | // NOTE: This is a C preprocessor macro 212 | build_kpayload(fw_version, kclock_macro); 213 | 214 | uint64_t set_time = args->kpayload_kclock_info->set_time; 215 | 216 | sceSblSrtcSetTime(set_time); 217 | 218 | return 0; 219 | } 220 | 221 | int kpayload_enable_browser(struct thread *td, struct kpayload_firmware_args *args) { 222 | UNUSED(td); 223 | void *kernel_base; 224 | 225 | uint64_t (*sceRegMgrSetInt)(uint32_t regId, int value); 226 | 227 | uint16_t fw_version = args->kpayload_firmware_info->fw_version; 228 | 229 | // NOTE: This is a C preprocessor macro 230 | build_kpayload(fw_version, enable_browser_macro); 231 | 232 | sceRegMgrSetInt(0x3C040000, 0); 233 | 234 | return 0; 235 | } 236 | 237 | int kpayload_target_id(struct thread *td, struct kpayload_target_id_args *args) { 238 | UNUSED(td); 239 | void *kernel_base; 240 | uint8_t *kernel_ptr; 241 | 242 | uint8_t *kmem; 243 | uint8_t *tid_patch; 244 | 245 | uint16_t fw_version = args->kpayload_target_id_info->fw_version; 246 | uint8_t spoof = args->kpayload_target_id_info->spoof; 247 | 248 | // NOTE: This is a C preprocessor macro 249 | build_kpayload(fw_version, tid_macro); 250 | 251 | uint64_t cr0 = readCr0(); 252 | writeCr0(cr0 & ~X86_CR0_WP); 253 | 254 | kmem = (uint8_t *)tid_patch; 255 | kmem[0] = spoof; 256 | 257 | writeCr0(cr0); 258 | 259 | return 0; 260 | } 261 | 262 | int kpayload_perm_uart(struct thread *td, struct kpayload_firmware_args *args) { 263 | UNUSED(td); 264 | void *kernel_base; 265 | 266 | uint64_t (*icc_nvs_write)(uint32_t block, uint32_t offset, uint32_t size, void *value); 267 | 268 | uint16_t fw_version = args->kpayload_firmware_info->fw_version; 269 | 270 | // NOTE: This is a C preprocessor macro 271 | build_kpayload(fw_version, icc_nvs_write_macro); 272 | 273 | char uart = 1; 274 | icc_nvs_write(4, 0x31F, 1, &uart); 275 | 276 | return 0; 277 | } 278 | 279 | int kpayload_exit_idu(struct thread *td, struct kpayload_firmware_args *args) { 280 | UNUSED(td); 281 | void *kernel_base; 282 | 283 | uint64_t (*icc_nvs_write)(uint32_t block, uint32_t offset, uint32_t size, void *value); 284 | 285 | uint16_t fw_version = args->kpayload_firmware_info->fw_version; 286 | 287 | // NOTE: This is a C preprocessor macro 288 | build_kpayload(fw_version, icc_nvs_write_macro); 289 | 290 | char flag = 0; 291 | icc_nvs_write(4, 0x1600, 1, &flag); 292 | 293 | return 0; 294 | } 295 | 296 | int kpayload_npdrm_patch(struct thread *td, struct kpayload_firmware_args *args) { 297 | UNUSED(td); 298 | void *kernel_base; 299 | uint8_t *kernel_ptr; 300 | 301 | uint8_t *kmem; 302 | uint8_t *npdrm_close; 303 | uint8_t *npdrm_open; 304 | uint8_t *npdrm_ioctl; 305 | 306 | uint16_t fw_version = args->kpayload_firmware_info->fw_version; 307 | 308 | // NOTE: This is a C preprocessor macro 309 | build_kpayload(fw_version, npdrm_macro); 310 | 311 | uint64_t cr0 = readCr0(); 312 | writeCr0(cr0 & ~X86_CR0_WP); 313 | 314 | kmem = (uint8_t *)npdrm_open; 315 | kmem[0] = 0x31; 316 | kmem[1] = 0xC0; 317 | kmem[2] = 0xC3; 318 | 319 | kmem = (uint8_t *)npdrm_close; 320 | kmem[0] = 0x31; 321 | kmem[1] = 0xC0; 322 | kmem[2] = 0xC3; 323 | 324 | // This may change depending on new firmware's function structure 325 | kmem = (uint8_t *)npdrm_ioctl; 326 | kmem[0] = 0xEB; 327 | if (fw_version < 500) { 328 | // 3.50-4.74 329 | kmem[1] = 0x04; 330 | } else { 331 | // 5.00-12.50 332 | kmem[1] = 0x00; 333 | } 334 | 335 | writeCr0(cr0); 336 | 337 | return 0; 338 | } 339 | 340 | uint16_t get_firmware() { 341 | // Return early if this has already been run 342 | if (g_firmware) { 343 | return g_firmware; 344 | } 345 | 346 | char sandbox_path[33]; // `/XXXXXXXXXX/common/lib/libc.sprx` [Char count of 32 + nullterm] 347 | snprintf_s(sandbox_path, sizeof(sandbox_path), "/%s/common/lib/libc.sprx", sceKernelGetFsSandboxRandomWord()); 348 | int fd = open(sandbox_path, O_RDONLY, 0); 349 | if (fd < 0) { 350 | // Assume it's currently jailbroken 351 | fd = open("/system/common/lib/libc.sprx", O_RDONLY, 0); 352 | if (fd < 0) { 353 | // It's really broken 354 | return -1; 355 | } 356 | } 357 | 358 | // Read SELF header from file 359 | lseek(fd, 0, SEEK_SET); 360 | SelfHeader self_header; 361 | if (read(fd, &self_header, sizeof(self_header)) != sizeof(self_header)) { 362 | return -1; 363 | } 364 | 365 | // Calculate ELF header offset from the number of SELF segments 366 | uint64_t elf_header_offset = sizeof(self_header) + self_header.num_of_segments * sizeof(SelfEntry); 367 | 368 | // Read ELF header from file 369 | lseek(fd, elf_header_offset, SEEK_SET); 370 | Elf64_Ehdr elf_header; 371 | if (read(fd, &elf_header, sizeof(elf_header)) != sizeof(elf_header)) { 372 | return -1; 373 | } 374 | 375 | // Calculate SCE header offset from number of ELF entries 376 | uint64_t sce_header_offset = elf_header_offset + elf_header.e_ehsize + elf_header.e_phnum * elf_header.e_phentsize; 377 | 378 | // Align 379 | while (sce_header_offset % 0x10 != 0) { 380 | sce_header_offset++; 381 | } 382 | 383 | // Read SCE header 384 | lseek(fd, sce_header_offset, SEEK_SET); 385 | SceHeader sce_header; 386 | if (read(fd, &sce_header, sizeof(sce_header)) != sizeof(sce_header)) { 387 | return -1; 388 | } 389 | 390 | close(fd); 391 | 392 | // Format and return 393 | char string_fw[5] = {0}; // "0000\0" 394 | snprintf_s(string_fw, sizeof(string_fw), "%02lx%02lx", (sce_header.fw_version >> (5 * 8)) & 0xFF, (sce_header.fw_version >> (4 * 8)) & 0xFF); 395 | 396 | uint16_t ret = atoi(string_fw); // Numerical representation of the firmware version. ex: 505 for 5.05, 702 for 7.02, etc 397 | 398 | g_firmware = ret; 399 | return ret; 400 | } 401 | 402 | int get_firmware_string(char *fw_string) { 403 | uint16_t fw_version = get_firmware(); 404 | 405 | sprintf(fw_string, "%i", fw_version); 406 | 407 | if (fw_version < 10) { 408 | sprintf(fw_string, "0.0%c", fw_string[0]); 409 | } else if (fw_version < 100) { 410 | sprintf(fw_string, "0.%c%c", fw_string[0], fw_string[1]); 411 | } else if (fw_version < 1000) { 412 | sprintf(fw_string, "%c.%c%c", fw_string[0], fw_string[1], fw_string[2]); 413 | } else if (fw_version < 10000) { 414 | sprintf(fw_string, "%c%c.%c%c", fw_string[0], fw_string[1], fw_string[2], fw_string[3]); 415 | } else { 416 | return -1; 417 | } 418 | 419 | return 0; 420 | } 421 | 422 | uint64_t get_kernel_base() { 423 | uint64_t kernel_base; 424 | uint64_t *kernel_base_ptr = mmap(NULL, 8, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); // Allocate a buffer in userland 425 | struct kpayload_kbase_info kpayload_kbase_info; 426 | kpayload_kbase_info.fw_version = get_firmware(); 427 | kpayload_kbase_info.uaddr = (uint64_t)kernel_base_ptr; 428 | if (kexec(&kpayload_kbase, &kpayload_kbase_info) < 0) { 429 | kernel_base = -1; 430 | } else { 431 | memcpy(&kernel_base, kernel_base_ptr, 8); 432 | } 433 | munmap(kernel_base_ptr, 8); 434 | return kernel_base; 435 | } 436 | 437 | int get_memory_dump(uint64_t kaddr, uint64_t *uaddr, size_t size) { 438 | struct kpayload_dump_info kpayload_dump_info; 439 | kpayload_dump_info.fw_version = get_firmware(); 440 | kpayload_dump_info.kaddr = kaddr; 441 | kpayload_dump_info.uaddr = (uint64_t)uaddr; 442 | kpayload_dump_info.size = size; 443 | return kexec(&kpayload_dump, &kpayload_dump_info); 444 | } 445 | 446 | int jailbreak() { 447 | if (is_jailbroken()) { 448 | return 0; 449 | } 450 | struct kpayload_firmware_info kpayload_firmware_info; 451 | kpayload_firmware_info.fw_version = get_firmware(); 452 | return kexec(&kpayload_jailbreak, &kpayload_firmware_info); 453 | } 454 | 455 | int mmap_patch() { 456 | struct kpayload_firmware_info kpayload_firmware_info; 457 | kpayload_firmware_info.fw_version = get_firmware(); 458 | return kexec(&kpayload_mmap, &kpayload_firmware_info); 459 | } 460 | 461 | int disable_aslr() { 462 | struct kpayload_firmware_info kpayload_firmware_info; 463 | kpayload_firmware_info.fw_version = get_firmware(); 464 | return kexec(&kpayload_aslr, &kpayload_firmware_info); 465 | } 466 | 467 | int kernel_clock(uint64_t set_time) { 468 | struct kpayload_kclock_info kpayload_kclock_info; 469 | kpayload_kclock_info.fw_version = get_firmware(); 470 | kpayload_kclock_info.set_time = set_time; 471 | return kexec(&kpayload_kernel_clock, &kpayload_kclock_info); 472 | } 473 | 474 | int enable_browser() { 475 | struct kpayload_firmware_info kpayload_firmware_info; 476 | kpayload_firmware_info.fw_version = get_firmware(); 477 | return kexec(&kpayload_enable_browser, &kpayload_firmware_info); 478 | } 479 | 480 | int spoof_target_id(uint8_t id) { 481 | struct kpayload_target_id_info kpayload_target_id_info; 482 | kpayload_target_id_info.fw_version = get_firmware(); 483 | kpayload_target_id_info.spoof = id; 484 | return kexec(&kpayload_target_id, &kpayload_target_id_info); 485 | } 486 | 487 | int enable_perm_uart() { 488 | struct kpayload_firmware_info kpayload_firmware_info; 489 | kpayload_firmware_info.fw_version = get_firmware(); 490 | return kexec(&kpayload_perm_uart, &kpayload_firmware_info); 491 | } 492 | 493 | int exit_idu() { 494 | struct kpayload_firmware_info kpayload_firmware_info; 495 | kpayload_firmware_info.fw_version = get_firmware(); 496 | return kexec(&kpayload_exit_idu, &kpayload_firmware_info); 497 | } 498 | 499 | int npdrm_patch() { 500 | struct kpayload_firmware_info kpayload_firmware_info; 501 | kpayload_firmware_info.fw_version = get_firmware(); 502 | return kexec(&kpayload_npdrm_patch, &kpayload_firmware_info); 503 | } 504 | -------------------------------------------------------------------------------- /libPS4/source/pfs.c: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2013 Hykem 2 | // Licensed under the terms of the GNU GPL, version 2 3 | // http://www.gnu.org/licenses/gpl-2.0.txt 4 | 5 | #include "file.h" 6 | #include "libc.h" 7 | 8 | #include "pfs.h" 9 | 10 | int pfs; 11 | size_t pfs_size, pfs_copied; 12 | struct pfs_header_t *header; 13 | struct di_d32 *inodes; 14 | 15 | #define BUFFER_SIZE 0x100000 16 | 17 | char *copy_buffer; 18 | 19 | void memcpy_to_file(const char *fname, uint64_t ptr, uint64_t size) { 20 | int fd = open(fname, O_WRONLY | O_CREAT | O_TRUNC, 0777); 21 | if (fd != -1) { 22 | size_t ix = 0; 23 | while (size > 0) { 24 | size_t bytes = (size > BUFFER_SIZE) ? BUFFER_SIZE : size; 25 | lseek(pfs, ptr + ix * BUFFER_SIZE, SEEK_SET); 26 | read(pfs, copy_buffer, bytes); 27 | write(fd, copy_buffer, bytes); 28 | size -= bytes; 29 | ix++; 30 | pfs_copied += bytes; 31 | if (pfs_copied > pfs_size) { 32 | pfs_copied = pfs_size; 33 | } 34 | } 35 | close(fd); 36 | } 37 | } 38 | 39 | static void parse_directory(int ino, int lev, char *parent_name, bool dry_run) { 40 | for (uint32_t z = 0; z < inodes[ino].blocks; z++) { 41 | uint32_t db = inodes[ino].db[0] + z; 42 | uint64_t pos = (uint64_t)header->blocksz * db; 43 | uint64_t size = inodes[ino].size; 44 | uint64_t top = pos + size; 45 | 46 | while (pos < top) { 47 | struct dirent_t *ent = malloc(sizeof(struct dirent_t)); 48 | if (ent == NULL) { 49 | return; 50 | } 51 | 52 | lseek(pfs, pos, SEEK_SET); 53 | read(pfs, ent, sizeof(struct dirent_t)); 54 | 55 | if (ent->type == 0) { 56 | free(ent); 57 | break; 58 | } 59 | 60 | char *name = malloc(ent->namelen + 1); 61 | if (name == NULL) { 62 | free(ent); 63 | return; 64 | } 65 | memset(name, 0, ent->namelen + 1); 66 | if (lev > 0) { 67 | lseek(pfs, pos + sizeof(struct dirent_t), SEEK_SET); 68 | read(pfs, name, ent->namelen); 69 | } 70 | 71 | char *fname; 72 | if (parent_name != NULL) { 73 | fname = malloc(strlen(parent_name) + ent->namelen + 2); 74 | if (fname == NULL) { 75 | free(ent); 76 | free(name); 77 | return; 78 | } 79 | sprintf(fname, "%s/%s", parent_name, name); 80 | } else { 81 | fname = malloc(ent->namelen + 2); 82 | if (fname == NULL) { 83 | free(ent); 84 | free(name); 85 | return; 86 | } 87 | sprintf(fname, "%s", name); 88 | } 89 | 90 | if ((ent->type == 2) && (lev > 0)) { 91 | if (dry_run) { 92 | pfs_size += inodes[ent->ino].size; 93 | } else { 94 | memcpy_to_file(fname, (uint64_t)header->blocksz * inodes[ent->ino].db[0], inodes[ent->ino].size); 95 | } 96 | } else if (ent->type == 3) { 97 | mkdir(fname, 0777); 98 | parse_directory(ent->ino, lev + 1, fname, dry_run); 99 | } 100 | 101 | pos += ent->entsize; 102 | 103 | free(ent); 104 | free(name); 105 | free(fname); 106 | } 107 | } 108 | } 109 | 110 | int unpfs(char *pfsfn, char *tidpath) { 111 | if (tidpath == NULL) { 112 | return -1; 113 | } 114 | 115 | copy_buffer = malloc(BUFFER_SIZE); 116 | if (copy_buffer == NULL) { 117 | return -1; 118 | } 119 | 120 | mkdir(tidpath, 0777); 121 | 122 | pfs = open(pfsfn, O_RDONLY, 0); 123 | if (pfs < 0) { 124 | free(copy_buffer); 125 | return -1; 126 | } 127 | 128 | header = malloc(sizeof(struct pfs_header_t)); 129 | if (header == NULL) { 130 | free(copy_buffer); 131 | close(pfs); 132 | return -1; 133 | } 134 | lseek(pfs, 0, SEEK_SET); 135 | read(pfs, header, sizeof(struct pfs_header_t)); 136 | 137 | inodes = malloc(sizeof(struct di_d32) * header->ndinode); 138 | if (inodes == NULL) { 139 | free(copy_buffer); 140 | close(pfs); 141 | free(header); 142 | return -1; 143 | } 144 | 145 | uint32_t ix = 0; 146 | 147 | for (uint32_t i = 0; i < header->ndinodeblock; i++) { 148 | for (uint32_t j = 0; (j < (header->blocksz / sizeof(struct di_d32))) && (ix < header->ndinode); j++) { 149 | lseek(pfs, (uint64_t)header->blocksz * (i + 1) + sizeof(struct di_d32) * j, SEEK_SET); 150 | read(pfs, &inodes[ix], sizeof(struct di_d32)); 151 | ix++; 152 | } 153 | } 154 | 155 | pfs_size = 0; 156 | pfs_copied = 0; 157 | 158 | parse_directory(header->superroot_ino, 0, tidpath, 1); 159 | parse_directory(header->superroot_ino, 0, tidpath, 0); 160 | 161 | free(copy_buffer); 162 | free(header); 163 | close(pfs); 164 | free(inodes); 165 | 166 | return 0; 167 | } 168 | -------------------------------------------------------------------------------- /libPS4/source/pkg.c: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2013 Hykem 2 | // Licensed under the terms of the GNU GPL, version 2 3 | // http://www.gnu.org/licenses/gpl-2.0.txt 4 | 5 | #include "file.h" 6 | #include "libc.h" 7 | #include "strings.h" 8 | 9 | #include "pkg.h" 10 | 11 | #define EOF '\00' 12 | 13 | // Helper functions. 14 | static inline uint16_t bswap_16(uint16_t val) { 15 | return ((val & (uint16_t)0x00ffU) << 8) | ((val & (uint16_t)0xff00U) >> 8); 16 | } 17 | 18 | static inline uint32_t bswap_32(uint32_t val) { 19 | return ((val & (uint32_t)0x000000ffUL) << 24) | ((val & (uint32_t)0x0000ff00UL) << 8) | ((val & (uint32_t)0x00ff0000UL) >> 8) | ((val & (uint32_t)0xff000000UL) >> 24); 20 | } 21 | 22 | int isfpkg(char *pkgfn) { 23 | int result = 0; 24 | FILE *in = NULL; 25 | struct cnt_pkg_main_header m_header; 26 | struct cnt_pkg_content_header c_header; 27 | memset_s(&m_header, sizeof(struct cnt_pkg_main_header), 0, sizeof(struct cnt_pkg_main_header)); 28 | memset_s(&c_header, sizeof(struct cnt_pkg_main_header), 0, sizeof(struct cnt_pkg_content_header)); 29 | 30 | if ((in = fopen(pkgfn, "rb")) == NULL) { 31 | result = 1; 32 | } else { 33 | char buffer[5]; 34 | fseek(in, 1, SEEK_SET); 35 | fread(buffer, 1, 4, in); 36 | if (strcmp(buffer, "CNT@") == 0) { 37 | result = 0; 38 | } else { 39 | fseek(in, 0, SEEK_SET); 40 | fread(&m_header, 1, 0x180, in); 41 | 42 | if (m_header.magic != PS4_PKG_MAGIC) { 43 | result = 2; 44 | } else if (bswap_32(m_header.type) != 1) { 45 | result = 3; 46 | } 47 | } 48 | } 49 | 50 | fclose(in); 51 | return result; 52 | } 53 | 54 | static void _mkdir(const char *dir) { 55 | char tmp[256]; 56 | char *p = NULL; 57 | 58 | snprintf(tmp, sizeof(tmp), "%s", dir); 59 | for (p = tmp + 1; *p; p++) { 60 | if (*p == '/') { 61 | *p = 0; 62 | mkdir(tmp, 0777); 63 | *p = '/'; 64 | } 65 | } 66 | } 67 | 68 | static char *get_entry_name_by_type(uint32_t type) { 69 | char *entry_name = malloc(32); 70 | 71 | if ((type >= 0x1201) && (type <= 0x121F)) { 72 | sprintf(entry_name, "icon0_%02u.png", type - 0x1201); 73 | } else if ((type >= 0x1241) && (type <= 0x125F)) { 74 | sprintf(entry_name, "pic1_%02u.png", type - 0x1241); 75 | } else if ((type >= 0x1261) && (type <= 0x127F)) { 76 | sprintf(entry_name, "changeinfo/changeinfo_%02u.xml", type - 0x1261); 77 | } else if ((type >= 0x1281) && (type <= 0x129F)) { 78 | sprintf(entry_name, "icon0_%02u.dds", type - 0x1281); 79 | } else if ((type >= 0x12C1) && (type <= 0x12DF)) { 80 | sprintf(entry_name, "pic1_%02u.dds", type - 0x12C1); 81 | } else if ((type >= 0x1400) && (type <= 0x147F)) { 82 | sprintf(entry_name, "trophy/trophy%02u.trp", type - 0x1400); 83 | } else if ((type >= 0x1600) && (type <= 0x1609)) { 84 | sprintf(entry_name, "keymap_rp/%03u.png", type - 0x15FF); 85 | } else if ((type >= 0x1610) && (type <= 0x16F5)) { 86 | sprintf(entry_name, "keymap_rp/%02u/%03u.png", (type - 0x1610) / 10, (((type - 0x160F) % 10) ? (type - 0x160F) % 10 : 10)); 87 | } else { 88 | free(entry_name); 89 | entry_name = NULL; 90 | switch (type) { 91 | case 0x0400: 92 | entry_name = "license.dat"; 93 | break; 94 | case 0x0401: 95 | entry_name = "license.info"; 96 | break; 97 | case 0x0402: 98 | entry_name = "nptitle.dat"; 99 | break; 100 | case 0x0403: 101 | entry_name = "npbind.dat"; 102 | break; 103 | case 0x0404: 104 | entry_name = "selfinfo.dat"; 105 | break; 106 | case 0x0406: 107 | entry_name = "imageinfo.dat"; 108 | break; 109 | case 0x0407: 110 | entry_name = "target-deltainfo.dat"; 111 | break; 112 | case 0x0408: 113 | entry_name = "origin-deltainfo.dat"; 114 | break; 115 | case 0x0409: 116 | entry_name = "psreserved.dat"; 117 | break; 118 | case 0x1000: 119 | entry_name = "param.sfo"; 120 | break; 121 | case 0x1001: 122 | entry_name = "playgo-chunk.dat"; 123 | break; 124 | case 0x1002: 125 | entry_name = "playgo-chunk.sha"; 126 | break; 127 | case 0x1003: 128 | entry_name = "playgo-manifest.xml"; 129 | break; 130 | case 0x1004: 131 | entry_name = "pronunciation.xml"; 132 | break; 133 | case 0x1005: 134 | entry_name = "pronunciation.sig"; 135 | break; 136 | case 0x1006: 137 | entry_name = "pic1.png"; 138 | break; 139 | case 0x1007: 140 | entry_name = "pubtoolinfo.dat"; 141 | break; 142 | case 0x1008: 143 | entry_name = "app/playgo-chunk.dat"; 144 | break; 145 | case 0x1009: 146 | entry_name = "app/playgo-chunk.sha"; 147 | break; 148 | case 0x100A: 149 | entry_name = "app/playgo-manifest.xml"; 150 | break; 151 | case 0x100B: 152 | entry_name = "shareparam.json"; 153 | break; 154 | case 0x100C: 155 | entry_name = "shareoverlayimage.png"; 156 | break; 157 | case 0x100D: 158 | entry_name = "save_data.png"; 159 | break; 160 | case 0x100E: 161 | entry_name = "shareprivacyguardimage.png"; 162 | break; 163 | case 0x1200: 164 | entry_name = "icon0.png"; 165 | break; 166 | case 0x1220: 167 | entry_name = "pic0.png"; 168 | break; 169 | case 0x1240: 170 | entry_name = "snd0.at9"; 171 | break; 172 | case 0x1260: 173 | entry_name = "changeinfo/changeinfo.xml"; 174 | break; 175 | case 0x1280: 176 | entry_name = "icon0.dds"; 177 | break; 178 | case 0x12A0: 179 | entry_name = "pic0.dds"; 180 | break; 181 | case 0x12C0: 182 | entry_name = "pic1.dds"; 183 | break; 184 | } 185 | } 186 | 187 | return entry_name; 188 | } 189 | 190 | int unpkg(char *pkgfn, char *tidpath) { 191 | struct cnt_pkg_main_header m_header; 192 | struct cnt_pkg_content_header c_header; 193 | memset(&m_header, 0, sizeof(struct cnt_pkg_main_header)); 194 | memset(&c_header, 0, sizeof(struct cnt_pkg_content_header)); 195 | 196 | int fdin = open(pkgfn, O_RDONLY, 0); 197 | if (fdin == -1) { 198 | return 1; 199 | } 200 | 201 | // Read in the main CNT header (size seems to be 0x180 with 4 hashes included). 202 | lseek(fdin, 0, SEEK_SET); 203 | read(fdin, &m_header, 0x180); 204 | 205 | if (m_header.magic != PS4_PKG_MAGIC) { 206 | return 2; 207 | } 208 | 209 | // Seek to offset 0x400 and read content associated header (size seems to be 0x80 with 2 hashes included). 210 | lseek(fdin, 0x400, SEEK_SET); 211 | read(fdin, &c_header, 0x80); 212 | 213 | // Locate the entry table and list each type of section inside the PKG/CNT file. 214 | lseek(fdin, bswap_32(m_header.file_table_offset), SEEK_SET); 215 | 216 | struct cnt_pkg_table_entry *entries = malloc(sizeof(struct cnt_pkg_table_entry) * bswap_16(m_header.table_entries_num)); 217 | if (entries == NULL) { 218 | close(fdin); 219 | return 3; 220 | } 221 | memset(entries, 0, sizeof(struct cnt_pkg_table_entry) * bswap_16(m_header.table_entries_num)); 222 | int i; 223 | for (i = 0; i < bswap_16(m_header.table_entries_num); i++) { 224 | read(fdin, &entries[i], 0x20); 225 | } 226 | 227 | // Vars for file name listing. 228 | struct file_entry *entry_files = malloc(sizeof(struct file_entry) * bswap_16(m_header.table_entries_num)); 229 | if (entry_files == NULL) { 230 | close(fdin); 231 | free(entries); 232 | return 4; 233 | } 234 | memset(entry_files, 0, sizeof(struct file_entry) * bswap_16(m_header.table_entries_num)); 235 | char *file_name_list[256]; 236 | int file_name_index = 0; 237 | int file_count = 0; 238 | 239 | // Search through the data entries and locate the name table entry. 240 | // This section should keep relevant strings for internal files inside the PKG/CNT file. 241 | for (i = 0; i < bswap_16(m_header.table_entries_num); i++) { 242 | if (bswap_32(entries[i].type) == PS4_PKG_ENTRY_TYPE_NAME_TABLE) { 243 | lseek(fdin, bswap_32(entries[i].offset) + 1, SEEK_SET); 244 | while ((file_name_list[file_name_index] = read_string(fdin))[0] != '\0') { 245 | file_name_index++; 246 | } 247 | } 248 | } 249 | 250 | // Search through the data entries and locate file entries. 251 | // These entries need to be mapped with the names collected from the name table. 252 | for (i = 0; i < bswap_16(m_header.table_entries_num); i++) { 253 | // Use a predefined list for most file names. 254 | entry_files[i].name = get_entry_name_by_type(bswap_32(entries[i].type)); 255 | entry_files[i].offset = bswap_32(entries[i].offset); 256 | entry_files[i].size = bswap_32(entries[i].size); 257 | 258 | if (((bswap_32(entries[i].type) & PS4_PKG_ENTRY_TYPE_FILE1) == PS4_PKG_ENTRY_TYPE_FILE1) || (((bswap_32(entries[i].type) & PS4_PKG_ENTRY_TYPE_FILE2) == PS4_PKG_ENTRY_TYPE_FILE2))) { 259 | // If a file was found and it's name is not on the predefined list, try to map it with 260 | // a name from the name table. 261 | if (entry_files[i].name == NULL) { 262 | entry_files[i].name = file_name_list[file_count]; 263 | } 264 | if (entry_files[i].name != NULL) { 265 | file_count++; 266 | } 267 | } 268 | } 269 | 270 | // Set up the output directory for file writing. 271 | char dest_path[256]; 272 | char title_id[256]; 273 | 274 | memset(title_id, 0, 256); 275 | memcpy(title_id, tidpath, 255); 276 | mkdir(title_id, 0777); 277 | 278 | // Search through the entries for mapped file data and output it. 279 | for (i = 0; i < bswap_16(m_header.table_entries_num); i++) { 280 | // Var for file writing. 281 | unsigned char *entry_file_data = (unsigned char *)realloc(NULL, entry_files[i].size); 282 | 283 | lseek(fdin, entry_files[i].offset, SEEK_SET); 284 | read(fdin, entry_file_data, entry_files[i].size); 285 | 286 | if (entry_files[i].name == NULL) 287 | continue; 288 | 289 | sprintf(dest_path, "%s/sce_sys/%s", title_id, entry_files[i].name); 290 | 291 | _mkdir(dest_path); 292 | 293 | int fdout = open(dest_path, O_WRONLY | O_CREAT | O_TRUNC, 0777); 294 | if (fdout != -1) { 295 | write(fdout, entry_file_data, entry_files[i].size); 296 | close(fdout); 297 | } else { 298 | close(fdin); 299 | free(entries); 300 | free(entry_files); 301 | return 5; 302 | } 303 | } 304 | 305 | // Clean up. 306 | close(fdin); 307 | 308 | free(entries); 309 | free(entry_files); 310 | 311 | return 0; 312 | } 313 | -------------------------------------------------------------------------------- /libPS4/source/proc.c: -------------------------------------------------------------------------------- 1 | #include "kernel.h" 2 | #include "libc.h" 3 | #include "syscall.h" 4 | 5 | #include "proc.h" 6 | 7 | int findProcess(char *procName) { 8 | int procPID = 0; 9 | while (!procPID) { 10 | int mib[3]; 11 | size_t len; 12 | mib[0] = CTL_KERN; 13 | mib[1] = KERN_PROC; 14 | mib[2] = KERN_PROC_ALL; 15 | 16 | if (sysctl(mib, 3, NULL, &len, NULL, 0) != -1) { 17 | if (len > 0) { 18 | void *dump = malloc(len); 19 | if (dump == NULL) { 20 | return -1; 21 | } 22 | if (sysctl(mib, 3, dump, &len, NULL, 0) != -1) { 23 | int structSize = *(int *)dump; 24 | for (size_t i = 0; i < (len / structSize); i++) { 25 | struct kinfo_proc *procInfo = (struct kinfo_proc *)(dump + (i * structSize)); 26 | if (!strcmp(procInfo->name, procName)) { 27 | procPID = procInfo->pid; 28 | break; 29 | } 30 | } 31 | } 32 | free(dump); 33 | } 34 | } 35 | 36 | sceKernelSleep(1); 37 | } 38 | return procPID; 39 | } 40 | 41 | void closeProcess(char *procname) { 42 | int pid = findProcess(procname); 43 | syscall(37, pid, SIGTERM); 44 | } 45 | 46 | void killProcess(char *procname) { 47 | int pid = findProcess(procname); 48 | syscall(37, pid, SIGKILL); 49 | } 50 | 51 | int ptrace(int req, int pid, void *addr, int data); 52 | SYSCALL(ptrace, 26); 53 | 54 | void PTRACE(int req, int pid, void *addr, int data) { 55 | while (ptrace(req, pid, addr, data)) { 56 | ; 57 | } 58 | } 59 | 60 | void procAttach(int pid) { 61 | PTRACE(PT_ATTACH, pid, NULL, NULL); 62 | } 63 | 64 | void procDetach(int pid) { 65 | PTRACE(PT_DETACH, pid, NULL, NULL); 66 | } 67 | 68 | void procReadBytes(int pid, void *offset, void *buffer, size_t len) { 69 | struct ptrace_io_desc pt_desc; 70 | pt_desc.piod_op = PIOD_READ_D; 71 | pt_desc.piod_addr = buffer; 72 | pt_desc.piod_offs = offset; 73 | pt_desc.piod_len = len; 74 | PTRACE(PT_IO, pid, &pt_desc, NULL); 75 | } 76 | 77 | void procWriteBytes(int pid, void *offset, void *buffer, size_t len) { 78 | struct ptrace_io_desc pt_desc; 79 | pt_desc.piod_op = PIOD_WRITE_D; 80 | pt_desc.piod_addr = buffer; 81 | pt_desc.piod_offs = offset; 82 | pt_desc.piod_len = len; 83 | PTRACE(PT_IO, pid, &pt_desc, NULL); 84 | } 85 | -------------------------------------------------------------------------------- /libPS4/source/pthread.c: -------------------------------------------------------------------------------- 1 | #include "kernel.h" 2 | #include "module.h" 3 | 4 | #include "pthread.h" 5 | 6 | int libPthread; 7 | 8 | int (*scePthreadCreate)(ScePthread *thread, const ScePthreadAttr *attr, void *(*entry)(void *), void *arg, const char *name); 9 | void (*scePthreadExit)(void *value); 10 | int (*scePthreadDetach)(ScePthread thread); 11 | int (*scePthreadJoin)(ScePthread thread, void **value_ptr); 12 | void (*scePthreadYield)(void); 13 | ScePthread (*scePthreadSelf)(void); 14 | int (*scePthreadCancel)(ScePthread thread); 15 | 16 | int (*scePthreadMutexInit)(ScePthreadMutex *mutex, const ScePthreadMutexattr *attr, const char *name); 17 | int (*scePthreadMutexDestroy)(ScePthreadMutex *mutex); 18 | int (*scePthreadMutexLock)(ScePthreadMutex *mutex); 19 | int (*scePthreadMutexTrylock)(ScePthreadMutex *mutex); 20 | int (*scePthreadMutexTimedlock)(ScePthreadMutex *mutex, SceKernelUseconds usec); 21 | int (*scePthreadMutexUnlock)(ScePthreadMutex *mutex); 22 | 23 | int (*scePthreadBarrierInit)(ScePthreadBarrier *barrier, const ScePthreadBarrierattr *attr, unsigned int count); 24 | int (*scePthreadBarrierWait)(ScePthreadBarrier *barrier); 25 | 26 | void initPthread(void) { 27 | if (libPthread) { 28 | return; 29 | } 30 | 31 | RESOLVE(libKernelHandle, scePthreadCreate); 32 | RESOLVE(libKernelHandle, scePthreadExit); 33 | RESOLVE(libKernelHandle, scePthreadDetach); 34 | RESOLVE(libKernelHandle, scePthreadJoin); 35 | RESOLVE(libKernelHandle, scePthreadYield); 36 | RESOLVE(libKernelHandle, scePthreadSelf); 37 | RESOLVE(libKernelHandle, scePthreadCancel); 38 | 39 | RESOLVE(libKernelHandle, scePthreadMutexInit); 40 | RESOLVE(libKernelHandle, scePthreadMutexDestroy); 41 | RESOLVE(libKernelHandle, scePthreadMutexLock); 42 | RESOLVE(libKernelHandle, scePthreadMutexTrylock); 43 | RESOLVE(libKernelHandle, scePthreadMutexTimedlock); 44 | RESOLVE(libKernelHandle, scePthreadMutexUnlock); 45 | 46 | RESOLVE(libKernelHandle, scePthreadBarrierInit); 47 | RESOLVE(libKernelHandle, scePthreadBarrierWait); 48 | 49 | libPthread = 1; 50 | } 51 | -------------------------------------------------------------------------------- /libPS4/source/registry.c: -------------------------------------------------------------------------------- 1 | #include "syscall.h" 2 | 3 | #include "registry.h" 4 | 5 | SYSCALL(registryCommand, 532); 6 | -------------------------------------------------------------------------------- /libPS4/source/semaphore.c: -------------------------------------------------------------------------------- 1 | #include "syscall.h" 2 | 3 | #include "semaphore.h" 4 | 5 | int createSemaphore(const char *name, int attributes, int startingCount, int maxCount) { 6 | return syscall(549, name, attributes, startingCount, maxCount, 0); 7 | } 8 | 9 | SYSCALL(removeSemaphore, 550); 10 | SYSCALL(openSemaphore, 551); 11 | SYSCALL(closeSemaphore, 552); 12 | SYSCALL(waitSemaphore, 553); 13 | SYSCALL(pollSemaphore, 554); 14 | SYSCALL(signalSemaphore, 555); 15 | SYSCALL(cancelSemaphore, 556); 16 | -------------------------------------------------------------------------------- /libPS4/source/strings.c: -------------------------------------------------------------------------------- 1 | #include "file.h" 2 | #include "libc.h" 3 | 4 | #include "strings.h" 5 | 6 | char *replace_str(char *str, char *orig, char *rep) { 7 | char *ret; 8 | int i, count = 0; 9 | size_t newlen = strlen(rep); 10 | size_t oldlen = strlen(orig); 11 | for (i = 0; str[i] != '\0'; i++) { 12 | if (strstr(&str[i], orig) == &str[i]) { 13 | count++; 14 | i += oldlen - 1; 15 | } 16 | } 17 | ret = malloc(i + count * (newlen - oldlen)); 18 | if (ret == NULL) { 19 | return str; 20 | } 21 | i = 0; 22 | while (*str) { 23 | if (strstr(str, orig) == str) { 24 | strcpy(&ret[i], rep); 25 | i += newlen; 26 | str += oldlen; 27 | } else { 28 | ret[i++] = *str++; 29 | } 30 | } 31 | ret[i] = '\0'; 32 | return ret; 33 | } 34 | 35 | int split_string(char *str, char c, char ***arr) { 36 | int count = 1; 37 | int token_len = 1; 38 | int i = 0; 39 | char *p; 40 | char *t; 41 | p = str; 42 | while (*p != '\0') { 43 | if (*p == c) { 44 | count++; 45 | } 46 | p++; 47 | } 48 | *arr = (char **)malloc(sizeof(char *) * count); 49 | if (*arr == NULL) { 50 | return 0; 51 | } 52 | p = str; 53 | while (*p != '\0') { 54 | if (*p == c) { 55 | (*arr)[i] = (char *)malloc(sizeof(char) * token_len); 56 | if ((*arr)[i] == NULL) { 57 | return 0; 58 | } 59 | token_len = 0; 60 | i++; 61 | } 62 | p++; 63 | token_len++; 64 | } 65 | (*arr)[i] = (char *)malloc(sizeof(char) * token_len); 66 | if ((*arr)[i] == NULL) { 67 | return 0; 68 | } 69 | i = 0; 70 | p = str; 71 | t = ((*arr)[i]); 72 | while (*p != '\0') { 73 | if (*p != c && *p != '\0') { 74 | *t = *p; 75 | t++; 76 | } else { 77 | *t = '\0'; 78 | i++; 79 | t = ((*arr)[i]); 80 | } 81 | p++; 82 | } 83 | return count; 84 | } 85 | 86 | char *read_string(int f) { 87 | char *string = malloc(sizeof(char) * 65536); 88 | int c; 89 | int length = 0; 90 | if (!string) { 91 | return string; 92 | } 93 | while ((c = fgetc_pointer(f)) != -1) { 94 | string[length++] = c; 95 | } 96 | string[length++] = '\0'; 97 | 98 | return realloc(string, sizeof(char) * length); 99 | } 100 | 101 | int substring(char *haystack, char *needle) { 102 | if (strlen(haystack) >= strlen(needle)) { 103 | for (int i = strlen(haystack) - strlen(needle); i >= 0; i--) { 104 | int found = 1; 105 | for (size_t d = 0; d < strlen(needle); d++) { 106 | if (haystack[i + d] != needle[d]) { 107 | found = 0; 108 | break; 109 | } 110 | } 111 | if (found == 1) { 112 | return i; 113 | } 114 | } 115 | } 116 | return -1; 117 | } 118 | -------------------------------------------------------------------------------- /libPS4/source/syscall.s: -------------------------------------------------------------------------------- 1 | .intel_syntax noprefix 2 | 3 | .extern __error 4 | 5 | .text 6 | 7 | .globl syscall 8 | syscall: 9 | xor rax, rax 10 | 11 | .globl syscall_macro 12 | syscall_macro: 13 | mov r10, rcx 14 | syscall 15 | jb _error 16 | ret 17 | 18 | _error: 19 | cmp qword ptr __error[rip], 0 20 | jz _end 21 | push rax 22 | call __error[rip] 23 | pop rcx 24 | mov [rax], ecx 25 | movq rax, -1 26 | movq rdx, -1 27 | 28 | _end: 29 | ret 30 | -------------------------------------------------------------------------------- /libPS4/source/sysutil.c: -------------------------------------------------------------------------------- 1 | #include "kernel.h" 2 | #include "libc.h" 3 | #include "module.h" 4 | #include "syscall.h" 5 | 6 | #include "sysutil.h" 7 | 8 | int sysUtilHandle; 9 | int libSceSystemService; 10 | int libSceUserService; 11 | 12 | int (*sceSysUtilSendSystemNotificationWithText)(int messageType, char *message); 13 | int (*sceSystemServiceLaunchWebBrowser)(const char *uri, void *); 14 | int (*sceUserServiceInitialize)(void *); 15 | int (*sceUserServiceGetLoginUserIdList)(SceUserServiceLoginUserIdList *); 16 | int (*sceUserServiceGetUserName)(int32_t userId, char *userName, const size_t size); 17 | int (*sceUserServiceGetInitialUser)(int32_t *); 18 | int (*sceUserServiceTerminate)(); 19 | int (*sceKernelReboot)(); 20 | 21 | void initSysUtil(void) { 22 | if (!sysUtilHandle) { 23 | sysUtilHandle = sceKernelLoadStartModule("/system/common/lib/libSceSysUtil.sprx", 0, 0, 0, NULL, NULL); 24 | 25 | RESOLVE(sysUtilHandle, sceSysUtilSendSystemNotificationWithText); 26 | } 27 | 28 | if (!libSceSystemService) { 29 | libSceSystemService = sceKernelLoadStartModule("/system/common/lib/libSceSystemService.sprx", 0, 0, 0, NULL, NULL); 30 | 31 | RESOLVE(libSceSystemService, sceSystemServiceLaunchWebBrowser); 32 | } 33 | } 34 | 35 | void initUserService(void) { 36 | if (libSceUserService) { 37 | return; 38 | } 39 | 40 | libSceUserService = sceKernelLoadStartModule("/system/common/lib/libSceUserService.sprx", 0, 0, 0, NULL, NULL); 41 | 42 | RESOLVE(libSceUserService, sceUserServiceInitialize); 43 | RESOLVE(libSceUserService, sceUserServiceGetInitialUser); 44 | RESOLVE(libSceUserService, sceUserServiceGetLoginUserIdList); 45 | RESOLVE(libSceUserService, sceUserServiceGetUserName); 46 | RESOLVE(libSceUserService, sceUserServiceTerminate); 47 | } 48 | 49 | void openBrowser(char *uri) { 50 | sceSystemServiceLaunchWebBrowser(uri, NULL); 51 | } 52 | 53 | int getUserIDList(SceUserServiceLoginUserIdList *userIdList) { 54 | initUserService(); 55 | if (sceUserServiceInitialize(NULL) == 0) { 56 | if (sceUserServiceGetLoginUserIdList(userIdList) == 0) { 57 | sceUserServiceTerminate(); 58 | return 0; 59 | } 60 | } 61 | return -1; 62 | } 63 | 64 | int32_t getUserID() { 65 | SceUserServiceLoginUserIdList userIdList; 66 | getUserIDList(&userIdList); 67 | for (int i = 0; i < 1; i++) { 68 | if (userIdList.userId[i] != -1) { 69 | return userIdList.userId[i]; 70 | } 71 | } 72 | return -1; 73 | } 74 | 75 | char *getUserName(int32_t userId) { 76 | char *retval = malloc(SCE_USER_SERVICE_MAX_USER_NAME_LENGTH + 1); 77 | if (retval == NULL) { 78 | return NULL; 79 | } 80 | initUserService(); 81 | if (sceUserServiceInitialize(NULL) == 0) { 82 | char username[SCE_USER_SERVICE_MAX_USER_NAME_LENGTH + 1]; 83 | if (sceUserServiceGetUserName(userId, username, sizeof(username)) == 0) { 84 | strcpy(retval, username); 85 | sceUserServiceTerminate(); 86 | return retval; 87 | } 88 | } 89 | free(retval); 90 | return NULL; 91 | } 92 | 93 | int32_t getInitialUser() { 94 | int32_t userId; 95 | initUserService(); 96 | if (sceUserServiceInitialize(NULL) == 0) { 97 | if (sceUserServiceGetInitialUser(&userId) == 0) { 98 | sceUserServiceTerminate(); 99 | return userId; 100 | } 101 | } 102 | return -1; 103 | } 104 | 105 | void shutdown() { 106 | int evf = syscall(540, "SceSysCoreReboot"); 107 | syscall(546, evf, 0x4000, 0); 108 | syscall(541, evf); 109 | syscall(37, 1, 30); 110 | } 111 | 112 | void reboot() { 113 | int libkernel = sceKernelLoadStartModule("/system/common/lib/libkernel.sprx", 0, 0, 0, NULL, NULL); 114 | RESOLVE(libkernel, sceKernelReboot); 115 | sceKernelReboot(); 116 | } 117 | -------------------------------------------------------------------------------- /libPS4/source/unknown.c: -------------------------------------------------------------------------------- 1 | #include "syscall.h" 2 | 3 | #include "unknown.h" 4 | 5 | SYSCALL(unknownResourceCreate, 574); 6 | SYSCALL(unknownResourceDestroy, 575); 7 | -------------------------------------------------------------------------------- /libPS4/source/usb.c: -------------------------------------------------------------------------------- 1 | #include "kernel.h" 2 | #include "module.h" 3 | 4 | #include "usb.h" 5 | 6 | int libUsb; 7 | 8 | int (*sceUsbdInit)(void); 9 | void (*sceUsbdExit)(void); 10 | 11 | ssize_t (*sceUsbdGetDeviceList)(libusb_device ***list); 12 | void (*sceUsbdFreeDeviceList)(libusb_device **list, int unrefDevices); 13 | 14 | int (*sceUsbdGetDeviceDescriptor)(libusb_device *device, libusb_device_descriptor *desc); 15 | 16 | int (*sceUsbdOpen)(libusb_device *dev, libusb_device_handle **devh); 17 | libusb_device_handle *(*sceUsbdOpenDeviceWithVidPid)(unsigned short vendorId, unsigned short productId); 18 | void (*sceUsbdClose)(libusb_device_handle *devh); 19 | 20 | int (*sceUsbdSetInterfaceAltSetting)(libusb_device_handle *dev, int interface_number, int alternate_setting); 21 | int (*sceUsbdClearHalt)(libusb_device_handle *devh, unsigned char endpoint); 22 | int (*sceUsbdResetDevice)(libusb_device_handle *devh); 23 | int (*sceUsbdCheckConnected)(libusb_device_handle *devh); 24 | 25 | int (*sceUsbdControlTransfer)(libusb_device_handle *devh, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, unsigned char *data, uint16_t wLength, unsigned int timeout); 26 | int (*sceUsbdBulkTransfer)(struct libusb_device_handle *devh, unsigned char endpoint, unsigned char *data, int length, int *transferred, unsigned int timeout); 27 | int (*sceUsbdInterruptTransfer)(struct libusb_device_handle *devh, unsigned char endpoint, unsigned char *data, int length, int *transferred, unsigned int timeout); 28 | 29 | int (*sceUsbdGetActiveConfigDescriptor)(libusb_device *dev, struct libusb_config_descriptor **config); 30 | int (*sceUsbdGetConfigDescriptor)(libusb_device *dev, uint8_t config_index, struct libusb_config_descriptor **config); 31 | int (*sceUsbdGetConfigDescriptorByValue)(libusb_device *dev, uint8_t bConfigurationValue, struct libusb_config_descriptor **config); 32 | void (*sceUsbdFreeConfigDescriptor)(struct libusb_config_descriptor *config); 33 | 34 | void initUsb(void) { 35 | if (libUsb) { 36 | return; 37 | } 38 | 39 | libUsb = sceKernelLoadStartModule("libSceUsbd.sprx", 0, 0, 0, NULL, NULL); 40 | 41 | RESOLVE(libUsb, sceUsbdInit); 42 | RESOLVE(libUsb, sceUsbdExit); 43 | 44 | RESOLVE(libUsb, sceUsbdGetDeviceList); 45 | RESOLVE(libUsb, sceUsbdFreeDeviceList); 46 | 47 | RESOLVE(libUsb, sceUsbdGetDeviceDescriptor); 48 | 49 | RESOLVE(libUsb, sceUsbdOpen); 50 | RESOLVE(libUsb, sceUsbdOpenDeviceWithVidPid); 51 | RESOLVE(libUsb, sceUsbdClose); 52 | 53 | RESOLVE(libUsb, sceUsbdSetInterfaceAltSetting); 54 | RESOLVE(libUsb, sceUsbdClearHalt); 55 | RESOLVE(libUsb, sceUsbdResetDevice); 56 | RESOLVE(libUsb, sceUsbdCheckConnected); 57 | 58 | RESOLVE(libUsb, sceUsbdControlTransfer); 59 | RESOLVE(libUsb, sceUsbdBulkTransfer); 60 | RESOLVE(libUsb, sceUsbdInterruptTransfer); 61 | 62 | RESOLVE(libUsb, sceUsbdGetActiveConfigDescriptor); 63 | RESOLVE(libUsb, sceUsbdGetConfigDescriptor); 64 | RESOLVE(libUsb, sceUsbdGetConfigDescriptorByValue); 65 | RESOLVE(libUsb, sceUsbdFreeConfigDescriptor); 66 | } 67 | --------------------------------------------------------------------------------