├── libpsutil ├── cryptography │ ├── md5.hpp │ ├── rc4.hpp │ ├── md5.cpp │ ├── tiger.hpp │ ├── sha.hpp │ ├── sha.cpp │ ├── rc4.cpp │ └── tiger.cpp ├── network │ ├── httpclient.hpp │ ├── socket.hpp │ ├── httpclient.cpp │ └── socket.cpp ├── system │ ├── syscalls.hpp │ ├── imports.cpp │ ├── imports.hpp │ ├── filesystem.hpp │ ├── syscalls.cpp │ ├── memory.hpp │ ├── memory.cpp │ └── filesystem.cpp ├── string.hpp ├── symbol.hpp ├── symbol.cpp ├── string.cpp ├── math.hpp ├── libpsutil.vcxproj.filters ├── libpsutil.vcxproj └── math.cpp ├── examples ├── http.md ├── symbol.md ├── filesystem.md ├── detour.md ├── cryptography.md └── socket.md ├── libpsutil.sln ├── README.md ├── .gitattributes └── .gitignore /libpsutil/cryptography/md5.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace libpsutil 4 | { 5 | namespace cryptography 6 | { 7 | void md5(void* data, size_t length, unsigned char* digest); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /libpsutil/cryptography/rc4.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace libpsutil 4 | { 5 | namespace cryptography 6 | { 7 | int rc4(char* key, char* plaintext, unsigned char* ciphertext); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /libpsutil/network/httpclient.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace libpsutil 5 | { 6 | namespace network 7 | { 8 | std::string http_get(const std::string& url, std::string query, uint16_t port = 80); 9 | } 10 | } -------------------------------------------------------------------------------- /examples/http.md: -------------------------------------------------------------------------------- 1 | #HTTP Requests 2 | Currently, the only http requests that are supported are GET requests and HTTPS is __NOT__ supported 3 | 4 | ``` 5 | void get() 6 | { 7 | std::string data = libpsutil::network::http_get("http://google.com", "", 80); 8 | } 9 | -------------------------------------------------------------------------------- /libpsutil/system/syscalls.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace libpsutil 6 | { 7 | uint32_t read_process_memory(uint64_t address, void* data, size_t size); 8 | uint32_t write_process_memory(uint64_t address, void* data, size_t size); 9 | void sleep(uint64_t milliseconds); 10 | } -------------------------------------------------------------------------------- /libpsutil/cryptography/md5.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "cryptography/md5.hpp" 4 | 5 | namespace libpsutil 6 | { 7 | namespace cryptography 8 | { 9 | void md5(void* data, size_t length, unsigned char* out) 10 | { 11 | cellMd5Digest(data, length, out); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /libpsutil/cryptography/tiger.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace libpsutil 4 | { 5 | namespace cryptography 6 | { 7 | void tiger64(char* str, size_t length, uint64_t* res); 8 | void tiger128(char* str, size_t length, uint64_t res[2]); 9 | void tiger192(char* str, size_t length, uint64_t res[3]); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /libpsutil/cryptography/sha.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace libpsutil 4 | { 5 | namespace cryptography 6 | { 7 | void sha1(void* data, size_t length, unsigned char* out); 8 | void sha256(void* data, size_t length, unsigned char* out); 9 | void sha512(void* data, size_t length, unsigned char* out); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /examples/symbol.md: -------------------------------------------------------------------------------- 1 | # Symbols 2 | Symbols can be used for an easy way of defining game functions/variables at an address. The TOC is resolved automatically, so only the actual address needs to be specified 3 | 4 | ``` 5 | libpsutil::symbol Function{ 0x12345678 }; 6 | void call() 7 | { 8 | Function(0); 9 | } 10 | ``` 11 | -------------------------------------------------------------------------------- /libpsutil/system/imports.cpp: -------------------------------------------------------------------------------- 1 | #include "system/imports.hpp" 2 | 3 | void* operator new(size_t size) { return _sys_malloc(size); } 4 | void* operator new[](size_t size) { return _sys_malloc(size); } 5 | void* operator new(unsigned int size, unsigned int) { return _sys_malloc(size); } 6 | void operator delete(void* ptr) { _sys_free(ptr); } 7 | void operator delete[](void* ptr) { _sys_free(ptr); } -------------------------------------------------------------------------------- /examples/filesystem.md: -------------------------------------------------------------------------------- 1 | #Filesystem 2 | 3 | ### Writing to a file 4 | ``` 5 | void init() 6 | { 7 | std::string data = "write me to a file!"; 8 | libpsutil::filesystem::write_file("/dev_hdd0/tmp/filename.txt", data.data(), data.length()); 9 | } 10 | ``` 11 | 12 | ### Reading from a file 13 | ``` 14 | void init() 15 | { 16 | char data[100]; 17 | libpsutil::filesystem::read_file("/dev_hdd0/tmp/filename.txt", data, 100); 18 | } 19 | ``` 20 | -------------------------------------------------------------------------------- /libpsutil/system/imports.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | extern "C" 7 | { 8 | int _sys_printf(const char* format, ...); 9 | int _sys_sprintf(char* s, const char* format, ...); 10 | int _sys_vsprintf(char* s, const char* format, va_list arg); 11 | 12 | void* _sys_malloc(size_t n); 13 | void _sys_free(void* ptr); 14 | } 15 | 16 | #define printf _sys_printf 17 | #define sprintf _sys_sprintf 18 | #define vsprintf _sys_vsprintf -------------------------------------------------------------------------------- /libpsutil/string.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #ifdef vector 4 | #undef vector 5 | #endif 6 | #include 7 | 8 | namespace libpsutil 9 | { 10 | namespace string 11 | { 12 | const char* va(const char* fmt, ...); 13 | 14 | std::string to_lower(const std::string& text); 15 | std::string to_upper(const std::string& text); 16 | bool begins_with(const std::string& text, const std::string& search); 17 | bool ends_with(const std::string& text, const std::string& search); 18 | std::vector split(const std::string& text, char delimiter); 19 | }; 20 | } -------------------------------------------------------------------------------- /examples/detour.md: -------------------------------------------------------------------------------- 1 | # Detouring 2 | 3 | ``` 4 | libpsutil::memory::detour* function_detour_t; 5 | void function_detour(int param1, int param2) 6 | { 7 | function_detour_t->invoke(param1, param2); 8 | } 9 | 10 | void init() 11 | { 12 | function_detour_t = new libpsutil::memory::detour(0x00000000, function_detour); 13 | } 14 | ``` 15 | 16 | #### HEN Warning 17 | In order to use HEN you MUST call `libpsutil::memory::detour::force_stub_address(0x0)`. The address to pass to this function needs to be EMPTY, EXECUTABLE memory. This can be found by looking at the program segmentation of the game you are modding 18 | -------------------------------------------------------------------------------- /libpsutil/cryptography/sha.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "cryptography/sha.hpp" 6 | 7 | namespace libpsutil 8 | { 9 | namespace cryptography 10 | { 11 | void sha1(void* data, size_t length, unsigned char* out) 12 | { 13 | cellSha1Digest(data, length, out); 14 | } 15 | 16 | void sha256(void* data, size_t length, unsigned char* out) 17 | { 18 | cellSha256Digest(data, length, out); 19 | } 20 | 21 | void sha512(void* data, size_t length, unsigned char* out) 22 | { 23 | cellSha512Digest(data, length, out); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /libpsutil/symbol.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "system/memory.hpp" 3 | 4 | namespace libpsutil 5 | { 6 | namespace symbol_helper 7 | { 8 | void* get_symbol(unsigned int address, unsigned int toc); 9 | } 10 | 11 | template class symbol 12 | { 13 | public: 14 | operator T* () 15 | { 16 | T* type = *reinterpret_cast(this->mp_object_); 17 | return (decltype(type))symbol_helper::get_symbol(this->mp_object_, toc); 18 | } 19 | 20 | T* get() 21 | { 22 | return this->mp_object_; 23 | } 24 | 25 | int mp_object_; 26 | int toc; 27 | }; 28 | } -------------------------------------------------------------------------------- /examples/cryptography.md: -------------------------------------------------------------------------------- 1 | # Cryptography 2 | RC4 3 | ``` 4 | void encrypt_text(char* text, char* key, char* output) 5 | { 6 | libpsutil::encryption::rc4(key, text, (unsigned char*)output); 7 | } 8 | ``` 9 | 10 | SHA1,SHA256,SHA512 11 | ``` 12 | void hash_text(char* text) 13 | { 14 | char output1[CELL_SHA1_DIGEST_SIZE] = { 0 }; 15 | libpsutil::encryption::sha1(text, strlen(text) + 1, output1); 16 | 17 | char output256[CELL_SHA256_DIGEST_SIZE] = { 0 }; 18 | libpsutil::encryption::sha256(text, strlen(text) + 1, output256); 19 | 20 | char output512[CELL_SHA512_DIGEST_SIZE] = { 0 }; 21 | libpsutil::encryption::sha512(text, strlen(text) + 1, output512); 22 | } 23 | ``` 24 | 25 | MD5 26 | ``` 27 | void hash_text(char* text) 28 | { 29 | char output[CELL_MD5_DIGEST_SIZE] = { 0 }; 30 | libpsutil::encryption::md5(text, strlen(text) + 1, output); 31 | } 32 | ``` 33 | -------------------------------------------------------------------------------- /libpsutil/system/filesystem.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #undef vector 5 | #include 6 | 7 | namespace libpsutil 8 | { 9 | namespace filesystem 10 | { 11 | bool read_file(const std::string& file_name, void* data, size_t size); 12 | std::string read_file(const std::string& file_name); 13 | bool write_file(const std::string& file_name, void* data, size_t size); 14 | bool write_file(const std::string& file_name, const std::string& data); 15 | int64_t get_file_size(const std::string& file_name); 16 | 17 | bool directory_exists(const std::string& directory_name); 18 | bool file_exists(const std::string& file_name); 19 | 20 | void create_directory(const std::string& directory_name); 21 | std::vector list_files(const std::string& directory_name, bool recursive = false); 22 | } 23 | } -------------------------------------------------------------------------------- /libpsutil/symbol.cpp: -------------------------------------------------------------------------------- 1 | #include "symbol.hpp" 2 | 3 | namespace libpsutil 4 | { 5 | namespace symbol_helper 6 | { 7 | struct opd_s 8 | { 9 | unsigned int address; 10 | unsigned int toc; 11 | }; 12 | 13 | std::vector symbol_table; 14 | void* get_symbol(unsigned int address, unsigned int toc) 15 | { 16 | for (auto i = 0; i < symbol_table.size(); i++) 17 | { 18 | opd_s* opd = &symbol_table[i]; 19 | if (opd->address == address) 20 | return opd; 21 | } 22 | 23 | symbol_table.push_back(opd_s()); 24 | opd_s* opd = &symbol_table[symbol_table.size() - 1]; 25 | opd->address = address; 26 | opd->toc = toc != 0 ? toc : memory::get_game_toc(); 27 | 28 | return opd; 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /libpsutil/network/socket.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | #define INVALID_SOCKET -1 7 | #define SOCKET_TIME_OUT 7000 8 | #define min(a,b) (((a) < (b)) ? (a) : (b)) 9 | 10 | namespace libpsutil 11 | { 12 | namespace network 13 | { 14 | enum socket_type 15 | { 16 | SOCKET_TYPE_TCP, 17 | SOCKET_TYPE_UDP 18 | }; 19 | 20 | class socket 21 | { 22 | private: 23 | int socket_; 24 | bool connected_; 25 | uint32_t ip_; 26 | uint16_t port_; 27 | socket_type type_; 28 | sockaddr_in server_addr; 29 | 30 | public: 31 | socket(const std::string& ip, uint16_t port, socket_type type = SOCKET_TYPE_TCP); 32 | socket(uint32_t ip, uint16_t port, socket_type type = SOCKET_TYPE_TCP); 33 | 34 | void close(); 35 | bool connect(); 36 | bool receive(void* data, size_t length); 37 | bool send(const void* data, size_t length); 38 | }; 39 | } 40 | } -------------------------------------------------------------------------------- /libpsutil.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31129.286 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libpsutil", "libpsutil\libpsutil.vcxproj", "{2347B788-0A76-49C8-88BC-5D1A9D88B4A8}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Release|PS3 = Release|PS3 11 | EndGlobalSection 12 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 13 | {2347B788-0A76-49C8-88BC-5D1A9D88B4A8}.Release|PS3.ActiveCfg = Release|PS3 14 | {2347B788-0A76-49C8-88BC-5D1A9D88B4A8}.Release|PS3.Build.0 = Release|PS3 15 | EndGlobalSection 16 | GlobalSection(SolutionProperties) = preSolution 17 | HideSolutionNode = FALSE 18 | EndGlobalSection 19 | GlobalSection(ExtensibilityGlobals) = postSolution 20 | SolutionGuid = {5CB06588-1D07-4B59-9DF6-E741578706A4} 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /examples/socket.md: -------------------------------------------------------------------------------- 1 | # Sockets 2 | 3 | ### TCP Socket 4 | ``` 5 | void tcp_example() 6 | { 7 | libpsutil::network::socket* net = new libpsutil::network::socket("1.2.3.4", 1234); 8 | if(net->connect()) 9 | { 10 | std::string send_data = "111111111111111111"; 11 | net->send(send_data.data(), send_data.length(); 12 | 13 | char recv_data[100]; 14 | net->receive(recv_data, 100); 15 | } 16 | 17 | net->close(); 18 | delete net; 19 | } 20 | ``` 21 | 22 | ### UDP Socket 23 | ``` 24 | void udp_example() 25 | { 26 | libpsutil::network::socket* net = new libpsutil::network::socket("1.2.3.4", 1234, libpsutil::network::socket_type::SOCKET_TYPE_UDP); 27 | if(net->connect()) 28 | { 29 | std::string send_data = "111111111111111111"; 30 | net->send(send_data.data(), send_data.length(); 31 | 32 | char recv_data[100]; 33 | net->receive(recv_data, 100); 34 | } 35 | 36 | net->close(); 37 | delete net; 38 | } 39 | ``` 40 | -------------------------------------------------------------------------------- /libpsutil/network/httpclient.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "network/httpclient.hpp" 3 | #include "network/socket.hpp" 4 | #include "system/imports.hpp" 5 | 6 | namespace libpsutil 7 | { 8 | namespace network 9 | { 10 | std::string http_get(const std::string& url, std::string query, uint16_t port) 11 | { 12 | auto* host = gethostbyname(url.data()); 13 | auto ip = *((uint32_t*)host->h_addr); 14 | 15 | size_t pos = 0; 16 | std::string space = " "; 17 | while ((pos = query.find(space, pos)) != std::string::npos) 18 | query.replace(pos, space.length(), "%20"); 19 | 20 | char response[1024] = { 0 }; 21 | char request[1024] = { 0 }; 22 | sprintf(request, "GET %s HTTP/1.1\nHost: %s\r\n\r\n", query.data(), url.data()); 23 | 24 | socket* http = new socket(ip, port); 25 | auto success = http->connect(); 26 | if (success) 27 | { 28 | success = http->send(request, strlen(request) + 1); 29 | if (success) 30 | { 31 | success = http->receive(response, 1024); 32 | } 33 | } 34 | 35 | http->close(); 36 | delete http; 37 | 38 | return success ? response : ""; 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /libpsutil/cryptography/rc4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "cryptography/rc4.hpp" 3 | 4 | // https://gist.github.com/rverton/a44fc8ca67ab9ec32089 5 | 6 | namespace libpsutil 7 | { 8 | namespace cryptography 9 | { 10 | namespace 11 | { 12 | #define N 256 13 | 14 | void swap(unsigned char* a, unsigned char* b) 15 | { 16 | int tmp = *a; 17 | *a = *b; 18 | *b = tmp; 19 | } 20 | 21 | int KSA(char* key, unsigned char* S) 22 | { 23 | int len = strlen(key); 24 | int j = 0; 25 | 26 | for (int i = 0; i < N; i++) 27 | S[i] = i; 28 | 29 | for (int i = 0; i < N; i++) 30 | { 31 | j = (j + S[i] + key[i % len]) % N; 32 | 33 | swap(&S[i], &S[j]); 34 | } 35 | 36 | return 0; 37 | } 38 | 39 | int PRGA(unsigned char* S, char* plaintext, unsigned char* ciphertext) 40 | { 41 | 42 | int i = 0; 43 | int j = 0; 44 | 45 | for (size_t n = 0, len = strlen(plaintext); n < len; n++) 46 | { 47 | i = (i + 1) % N; 48 | j = (j + S[i]) % N; 49 | 50 | swap(&S[i], &S[j]); 51 | int rnd = S[(S[i] + S[j]) % N]; 52 | 53 | ciphertext[n] = rnd ^ plaintext[n]; 54 | } 55 | 56 | return 0; 57 | } 58 | } 59 | 60 | int rc4(char* key, char* plaintext, unsigned char* ciphertext) 61 | { 62 | unsigned char S[N]; 63 | KSA(key, S); 64 | 65 | PRGA(S, plaintext, ciphertext); 66 | 67 | return 0; 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /libpsutil/string.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "string.hpp" 3 | #include "system/imports.hpp" 4 | 5 | namespace libpsutil 6 | { 7 | namespace string 8 | { 9 | char va_buffer[0x1000]; 10 | const char* va(const char* fmt, ...) 11 | { 12 | memset(va_buffer, 0, 0x1000); 13 | 14 | va_list ap; 15 | va_start(ap, fmt); 16 | vsprintf(va_buffer, fmt, ap); 17 | va_end(ap); 18 | 19 | return va_buffer; 20 | } 21 | 22 | std::string to_lower(const std::string& text) 23 | { 24 | auto output = text; 25 | 26 | std::transform(output.begin(), output.end(), output.begin(), [](const char input) 27 | { 28 | return static_cast(std::tolower(input)); 29 | }); 30 | 31 | return output; 32 | } 33 | 34 | std::string to_upper(const std::string& text) 35 | { 36 | auto output = text; 37 | 38 | std::transform(output.begin(), output.end(), output.begin(), [](const char input) 39 | { 40 | return static_cast(std::toupper(input)); 41 | }); 42 | 43 | return output; 44 | } 45 | 46 | bool begins_with(const std::string& text, const std::string& search) 47 | { 48 | return (text.size() >= search.size() && text.substr(0, search.size()) == search); 49 | } 50 | 51 | bool ends_with(const std::string& text, const std::string& search) 52 | { 53 | return (text.size() >= search.size() && text.substr(text.size() - search.size(), search.size()) == search); 54 | } 55 | 56 | std::vector split(const std::string& text, char delimiter) 57 | { 58 | std::vector out; 59 | std::string::size_type prev_pos = 0, pos = 0; 60 | 61 | while ((pos = text.find(delimiter, pos)) != std::string::npos) 62 | { 63 | std::string substring(text.substr(prev_pos, pos - prev_pos)); 64 | 65 | out.push_back(substring); 66 | 67 | prev_pos = ++pos; 68 | } 69 | 70 | out.push_back(text.substr(prev_pos, pos - prev_pos)); 71 | return out; 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /libpsutil/system/syscalls.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "system/syscalls.hpp" 5 | 6 | namespace libpsutil 7 | { 8 | bool use_hen_syscalls = false; 9 | 10 | uint32_t sys_hen_read_process_memory(uint64_t address, void* data, size_t size) 11 | { 12 | system_call_6(8, 0x7777, 0x31, (uint64_t)sys_process_getpid(), address, (uint64_t)data, size); 13 | return_to_user_prog(uint32_t); 14 | } 15 | 16 | uint32_t sys_hen_write_process_memory(uint64_t address, void* data, size_t size) 17 | { 18 | system_call_6(8, 0x7777, 0x32, (uint64_t)sys_process_getpid(), address, (uint64_t)data, size); 19 | return_to_user_prog(uint32_t); 20 | } 21 | 22 | uint32_t sys_dbg_read_process_memory(uint64_t address, void* data, size_t size) 23 | { 24 | system_call_4(904, (uint64_t)sys_process_getpid(), address, size, (uint64_t)data); 25 | return_to_user_prog(uint32_t); 26 | } 27 | 28 | uint32_t sys_dbg_write_process_memory(uint64_t address, void* data, size_t size) 29 | { 30 | system_call_4(905, (uint64_t)sys_process_getpid(), address, size, (uint64_t)data); 31 | return_to_user_prog(uint32_t); 32 | } 33 | 34 | uint32_t read_process_memory(uint64_t address, void* data, size_t size) 35 | { 36 | if (!use_hen_syscalls) 37 | { 38 | uint32_t read = sys_dbg_read_process_memory(address, data, size); 39 | if (read == SUCCEEDED) 40 | { 41 | return read; 42 | } 43 | } 44 | 45 | use_hen_syscalls = true; 46 | return sys_hen_read_process_memory(address, data, size); 47 | } 48 | 49 | uint32_t write_process_memory(uint64_t address, void* data, size_t size) 50 | { 51 | if (!use_hen_syscalls) 52 | { 53 | uint32_t write = sys_dbg_write_process_memory(address, data, size); 54 | if (write == SUCCEEDED) 55 | { 56 | return write; 57 | } 58 | } 59 | 60 | use_hen_syscalls = true; 61 | return sys_hen_write_process_memory(address, data, size); 62 | } 63 | 64 | void sleep(uint64_t milliseconds) 65 | { 66 | system_call_1(SYS_TIMER_USLEEP, milliseconds * 1000); 67 | } 68 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # libpsutil 2 | #### A single-header PS3 sprx static library for useful additions to the SDK 3 | 4 | ## Prerequisites 5 | - Visual Studio 2013+ 6 | - Sony PS3 4.75+ SDK w/ Visual Studio Integration 7 | 8 | ## Installation 9 | 1. Download the latest release from [Releases](https://github.com/skiff/libpsutil/releases) 10 | 2. Navigate to your SDK installation folder (default: `C:\usr\local\cell\target\ppu`) 11 | 3. Drop the *include* and *lib* folders in and overwrite any existing files 12 | 4. Add `#include ` into your project 13 | 5. Add `libpsutil.a` to your project "Additional Dependencies" 14 | 15 | ![Dependencies](https://i.imgur.com/uLZnsNe.png) 16 | 17 | 6. Make sure your c++ language version is set to C++11 18 | 19 | ## Features 20 | - **Fixed std::string** 21 | - **Fixed std::vector** 22 | - **Added std::initializer_list** 23 | - System printf, sprintf and vsprintf imports 24 | - Read/Write Memory (Includes HEN support!) 25 | - String manipulation (to lower, to upper, split, etc) 26 | - RC4 encryption 27 | - Filesystem API 28 | - Detour/Hooking API (Includes HEN support!) 29 | - TCP/UDP sockets 30 | - HTTP Get requests 31 | - Math library (vec2, vec3, vec4) 32 | 33 | ## Cryptography 34 | In order to use the cryptography namespace, you will need to add additional dependencies for the appropriate functions 35 | - Add `$(SCE_PS3_ROOT)\target\ppu\lib\hash\libsha1.a` for `libpsutil::cryptography::sha1` 36 | - Add `$(SCE_PS3_ROOT)\target\ppu\lib\hash\libsha256.a` for `libpsutil::cryptography::sha256` 37 | - Add `$(SCE_PS3_ROOT)\target\ppu\lib\hash\libsha512.a` for `libpsutil::cryptography::sha512` 38 | - Add `$(SCE_PS3_ROOT)\target\ppu\lib\hash\libmd5.a` for `libpsutil::cryptography::md5` 39 | 40 | ## Dynamic SPRX Loading 41 | If you use my [PS3 Toolbox](https://github.com/skiff/PS3-Toolbox) to load your SPRX without an EBOOT, you will need to grab an update version of this tool. The original release uses the game's header to execute code, but that header is now needed to read the game TOC so adjustments were made to the tool. 42 | 43 | ## HEN Detours 44 | While this library DOES support HEN for detouring, there is an extra function inside the detour class you MUST call to use detours 45 | 46 | `libpsutil::memory::detour::force_stub_address(uint32_t address)` 47 | 48 | This function needs to be given *empty, EXECUTABLE* memory that already exists in the game. Almost all games have one segment that matches this description and it can be found by looking at the program segmentation in IDA 49 | -------------------------------------------------------------------------------- /libpsutil/system/memory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #ifdef vector 4 | #undef vector 5 | #endif 6 | #include 7 | 8 | namespace libpsutil 9 | { 10 | namespace memory 11 | { 12 | bool get(uint32_t address, void* data, size_t length); 13 | bool get(uint32_t address, std::vector& bytes, size_t length); 14 | bool set(uint32_t address, void* data, size_t length); 15 | 16 | bool nop(uint32_t address); 17 | bool blr(uint32_t address); 18 | 19 | void jump(uint32_t address, uint32_t destination, bool linked = false); 20 | void jump_safe(uint32_t address, uint32_t destination, bool linked = false); 21 | 22 | uint32_t get_game_toc(); 23 | 24 | template T get(uint32_t address) 25 | { 26 | T data; 27 | get(address, &data, sizeof(T)); 28 | return data; 29 | } 30 | 31 | template std::vector get(uint32_t address, size_t length) 32 | { 33 | std::vector data; 34 | data.resize(length * sizeof(T)); 35 | get(address, &data[0], length * sizeof(T)); 36 | return data; 37 | } 38 | 39 | template bool set(uint32_t address, T data) 40 | { 41 | return set(address, &data, sizeof(T)); 42 | } 43 | 44 | template bool set(uint32_t address, std::initializer_list list) 45 | { 46 | return set(address, reinterpret_cast(list.data()), list.size() * sizeof(T)); 47 | } 48 | 49 | template T byte_swap(T u) 50 | { 51 | union 52 | { 53 | T u; 54 | unsigned char u8[sizeof(T)]; 55 | } source, dest; 56 | 57 | source.u = u; 58 | 59 | for (size_t k = 0; k < sizeof(T); k++) 60 | dest.u8[k] = source.u8[sizeof(T) - k - 1]; 61 | 62 | return dest.u; 63 | } 64 | 65 | class detour 66 | { 67 | private: 68 | static uint8_t hook_stub_section[0x10000] __attribute__((section(".text"))); 69 | static uint32_t hook_count; 70 | static uint32_t force_stub_addr; 71 | 72 | uint32_t* address; 73 | uint32_t stub_opd[2]; 74 | uint32_t original_instructions[4]; 75 | 76 | uint32_t allocate_stub(); 77 | uint32_t resolve_branch(uint32_t instruction, uint32_t branch_address); 78 | void setup_detour(uint32_t address, void* destination, uint32_t toc_override); 79 | 80 | public: 81 | template detour(uint32_t address, T(*destination), uint32_t toc_override = 0) 82 | { 83 | this->setup_detour(address, reinterpret_cast(destination), toc_override); 84 | } 85 | 86 | ~detour(); 87 | 88 | static void force_stub_address(uint32_t address); 89 | 90 | template T invoke(params... parameters) 91 | { 92 | T(*original)(params...) = (T(*)(params...))this->stub_opd; 93 | return original(parameters...); 94 | } 95 | }; 96 | } 97 | } -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /libpsutil/math.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace libpsutil 5 | { 6 | namespace math 7 | { 8 | int atoi(char* str); 9 | float atof(char* str); 10 | 11 | void srand(uint32_t seed); 12 | uint32_t rand(); 13 | 14 | class vec2_t 15 | { 16 | public: 17 | float x, y; 18 | 19 | vec2_t(); 20 | vec2_t(float x, float y); 21 | vec2_t(float vec[2]); 22 | 23 | vec2_t operator+(const vec2_t vec); 24 | vec2_t operator+(const float* vec); 25 | vec2_t operator-(const vec2_t vec); 26 | vec2_t operator-(const float* vec); 27 | vec2_t operator-() const; 28 | vec2_t operator*(const vec2_t vec); 29 | vec2_t operator*(const float scalar); 30 | 31 | void operator-=(const vec2_t vec); 32 | void operator+=(const vec2_t vec); 33 | void operator*=(const vec2_t vec); 34 | void operator*=(const float scalar); 35 | 36 | bool operator==(const vec2_t vec); 37 | bool operator==(const float value); 38 | bool operator!=(const vec2_t vec); 39 | bool operator!=(const float value); 40 | 41 | operator float* (); 42 | }; 43 | 44 | class vec3_t 45 | { 46 | public: 47 | float x, y, z; 48 | 49 | vec3_t(); 50 | vec3_t(float x, float y, float z); 51 | vec3_t(float vec[3]); 52 | 53 | vec3_t operator+(const vec3_t vec); 54 | vec3_t operator+(const float* vec); 55 | vec3_t operator-(const vec3_t vec); 56 | vec3_t operator-(const float* vec); 57 | vec3_t operator-() const; 58 | vec3_t operator*(const vec3_t vec); 59 | vec3_t operator*(const float scalar); 60 | 61 | void operator-=(const vec3_t vec); 62 | void operator+=(const vec3_t vec); 63 | void operator*=(const vec3_t vec); 64 | void operator*=(const float scalar); 65 | 66 | bool operator==(const vec3_t vec); 67 | bool operator==(const float value); 68 | bool operator!=(const vec3_t vec); 69 | bool operator!=(const float value); 70 | 71 | operator float* (); 72 | 73 | vec3_t forward(float x = 1.0f); 74 | vec3_t normalize(); 75 | float distance(vec3_t vec); 76 | float length(); 77 | void vectors(vec3_t* forward, vec3_t* right, vec3_t* up); 78 | }; 79 | 80 | class vec4_t 81 | { 82 | public: 83 | float x, y, z, w; 84 | 85 | vec4_t(); 86 | vec4_t(float x, float y, float z, float w); 87 | vec4_t(float vec[4]); 88 | 89 | vec4_t operator+(const vec4_t vec); 90 | vec4_t operator+(const float* vec); 91 | vec4_t operator-(const vec4_t vec); 92 | vec4_t operator-(const float* vec); 93 | vec4_t operator-() const; 94 | vec4_t operator*(const vec4_t vec); 95 | vec4_t operator*(const float scalar); 96 | 97 | void operator-=(const vec4_t vec); 98 | void operator+=(const vec4_t vec); 99 | void operator*=(const vec4_t vec); 100 | void operator*=(const float scalar); 101 | 102 | bool operator==(const vec4_t vec); 103 | bool operator==(const float value); 104 | bool operator!=(const vec4_t vec); 105 | bool operator!=(const float value); 106 | 107 | operator float* (); 108 | }; 109 | } 110 | } -------------------------------------------------------------------------------- /libpsutil/libpsutil.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {c845ce83-4880-4f5b-bece-9d9d0e552231} 6 | 7 | 8 | {7848b185-91af-4000-a8f5-fb6d2cb778d5} 9 | 10 | 11 | {68623689-2193-4415-9f84-11b6ab374658} 12 | 13 | 14 | 15 | 16 | 17 | system 18 | 19 | 20 | system 21 | 22 | 23 | system 24 | 25 | 26 | network 27 | 28 | 29 | cryptography 30 | 31 | 32 | system 33 | 34 | 35 | network 36 | 37 | 38 | 39 | 40 | cryptography 41 | 42 | 43 | cryptography 44 | 45 | 46 | cryptography 47 | 48 | 49 | 50 | 51 | 52 | 53 | system 54 | 55 | 56 | system 57 | 58 | 59 | system 60 | 61 | 62 | network 63 | 64 | 65 | cryptography 66 | 67 | 68 | system 69 | 70 | 71 | network 72 | 73 | 74 | 75 | cryptography 76 | 77 | 78 | cryptography 79 | 80 | 81 | cryptography 82 | 83 | 84 | -------------------------------------------------------------------------------- /libpsutil/system/memory.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "system/memory.hpp" 4 | #include "system/syscalls.hpp" 5 | #include "system/imports.hpp" 6 | 7 | namespace libpsutil 8 | { 9 | namespace memory 10 | { 11 | uint8_t detour::hook_stub_section[0x10000] __attribute__((section(".text"))); 12 | uint32_t detour::hook_count = 0; 13 | uint32_t detour::force_stub_addr = 0; 14 | 15 | bool get(uint32_t address, void* data, size_t length) 16 | { 17 | return read_process_memory(address, data, length) == SUCCEEDED; 18 | } 19 | 20 | bool get(uint32_t address, std::vector& bytes, size_t length) 21 | { 22 | bytes.resize(length); 23 | uint8_t* buffer = &bytes[0]; 24 | return read_process_memory(address, buffer, length) == SUCCEEDED; 25 | } 26 | 27 | bool set(uint32_t address, void* data, size_t length) 28 | { 29 | return write_process_memory(address, data, length) == SUCCEEDED; 30 | } 31 | 32 | bool nop(uint32_t address) 33 | { 34 | return memory::set(address, 0x60000000); 35 | } 36 | 37 | bool blr(uint32_t address) 38 | { 39 | return memory::set(address, 0x4E800020); 40 | } 41 | 42 | void jump(uint32_t address, uint32_t destination, bool linked) 43 | { 44 | uint32_t instructions[4] = { 0 }; 45 | 46 | instructions[0] = 0x3C000000 + ((destination >> 16) & 0xFFFF); 47 | instructions[1] = 0x60000000 + (destination & 0xFFFF); 48 | instructions[2] = 0x7C0903A6; 49 | instructions[3] = 0x4E800420 + (linked ? 1 : 0); 50 | 51 | memory::set(address, instructions, sizeof(uint32_t) * 4); 52 | } 53 | 54 | void jump_safe(uint32_t address, uint32_t destination, bool linked) 55 | { 56 | uint32_t instructions[8] = { 0 }; 57 | 58 | instructions[0] = 0xF821FFF9; 59 | instructions[1] = 0xF8010000; 60 | instructions[2] = 0x3C000000 + ((destination >> 16) & 0xFFFF); 61 | instructions[3] = 0x60000000 + (destination & 0xFFFF); 62 | instructions[4] = 0x7C0903A6; 63 | instructions[5] = 0xE8010000; 64 | instructions[6] = 0x38210008; 65 | instructions[7] = 0x4E800420 + (linked ? 1 : 0); 66 | 67 | memory::set(address, instructions, sizeof(uint32_t) * 8); 68 | } 69 | 70 | uint32_t get_game_toc() 71 | { 72 | uint32_t* entry_point = *reinterpret_cast(0x1001C); //ElfHeader->e_entry 73 | return entry_point[1]; 74 | } 75 | 76 | uint32_t detour::allocate_stub() 77 | { 78 | uint8_t* stub_section = this->hook_stub_section; 79 | if (detour::force_stub_addr != 0) 80 | { 81 | stub_section = reinterpret_cast(detour::force_stub_addr); 82 | } 83 | 84 | auto stub_address = reinterpret_cast(&stub_section[this->hook_count * 0xA0]); 85 | this->hook_count++; 86 | 87 | return stub_address; 88 | } 89 | 90 | uint32_t detour::resolve_branch(uint32_t instruction, uint32_t branch_address) 91 | { 92 | uint32_t offset = instruction & 0x3FFFFFC; 93 | 94 | if (offset & (1 << 25)) 95 | offset |= 0xFC000000; 96 | 97 | return branch_address + offset; 98 | } 99 | 100 | void detour::force_stub_address(uint32_t address) 101 | { 102 | detour::force_stub_addr = address; 103 | } 104 | 105 | void detour::setup_detour(uint32_t address, void *destination, uint32_t toc_override) 106 | { 107 | if (address == NULL) { return; } 108 | 109 | memcpy(this->original_instructions, reinterpret_cast(address), 0x10); 110 | 111 | this->address = reinterpret_cast(address); 112 | auto* stub_address = reinterpret_cast(this->allocate_stub()); 113 | 114 | uint32_t instruction_count = 0; 115 | for (int i = 0; i < 4; i++) 116 | { 117 | auto current_address = reinterpret_cast(&stub_address[instruction_count]); 118 | if ((this->address[i] & 0xF8000000) == 0x48000000) 119 | { 120 | memory::jump_safe(current_address, this->resolve_branch(this->address[i], (int)&this->address[i]), true); 121 | instruction_count += 8; 122 | } 123 | else 124 | { 125 | memory::set(current_address, &this->address[i], 4); 126 | instruction_count++; 127 | } 128 | } 129 | 130 | memory::jump_safe(reinterpret_cast(&stub_address[instruction_count]), address + 0x10, false); 131 | memory::jump(address, *reinterpret_cast(destination), false); 132 | 133 | this->stub_opd[0] = reinterpret_cast(stub_address); 134 | this->stub_opd[1] = toc_override != 0 ? toc_override : memory::get_game_toc(); 135 | } 136 | 137 | detour::~detour() 138 | { 139 | memory::set(reinterpret_cast(this->address), this->original_instructions, 0x10); 140 | } 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /libpsutil/libpsutil.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Release 6 | PS3 7 | 8 | 9 | 10 | $(VCTargetsPath12) 11 | {2347B788-0A76-49C8-88BC-5D1A9D88B4A8} 12 | 13 | 14 | 15 | StaticLibrary 16 | SNC 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | NDEBUG;%(PreprocessorDefinitions); 41 | Level2 42 | NotUsing 43 | Cpp11 44 | 45 | 46 | 47 | 48 | 49 | 50 | copy /y "$(TargetPath)" "$(SCE_PS3_ROOT)/target/ppu/lib/" 51 | 52 | 53 | Copy Lib to SCE Lib Directory 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /libpsutil/network/socket.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "network/socket.hpp" 5 | #include "system/imports.hpp" 6 | 7 | namespace libpsutil 8 | { 9 | namespace network 10 | { 11 | namespace 12 | { 13 | time_t get_tick_count() 14 | { 15 | time_t tv; 16 | time(&tv); 17 | return tv; 18 | } 19 | } 20 | 21 | socket::socket(const std::string& ip, uint16_t port, socket_type type) 22 | { 23 | this->ip_ = inet_addr(ip.data()); 24 | this->port_ = port; 25 | this->type_ = type; 26 | this->connected_ = false; 27 | this->socket_ = INVALID_SOCKET; 28 | 29 | memset(&this->server_addr, 0, sizeof(sockaddr_in)); 30 | } 31 | 32 | socket::socket(uint32_t ip, uint16_t port, socket_type type) 33 | { 34 | this->ip_ = ip; 35 | this->port_ = port; 36 | this->type_ = type; 37 | this->connected_ = false; 38 | this->socket_ = INVALID_SOCKET; 39 | 40 | memset(&this->server_addr, 0, sizeof(sockaddr_in)); 41 | } 42 | 43 | void socket::close() 44 | { 45 | if (this->connected_) 46 | { 47 | shutdown(this->socket_, 2); 48 | socketclose(this->socket_); 49 | } 50 | 51 | this->connected_ = false; 52 | this->socket_ = INVALID_SOCKET; 53 | } 54 | 55 | bool socket::connect() 56 | { 57 | if (this->socket_ == INVALID_SOCKET) 58 | { 59 | this->server_addr.sin_family = AF_INET; 60 | this->server_addr.sin_port = htons(this->port_); 61 | this->server_addr.sin_addr.s_addr = this->ip_; 62 | 63 | if (this->type_ == socket_type::SOCKET_TYPE_TCP) 64 | { 65 | auto sockfd = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 66 | if (sockfd < 0) 67 | { 68 | printf("[Socket]: Failed to create TCP socket\n"); 69 | return false; 70 | } 71 | 72 | if (::connect(sockfd, (sockaddr*)&this->server_addr, sizeof(this->server_addr)) < 0) 73 | { 74 | printf("[Socket]: Failed to connect to %08X:%i\n", this->ip_, this->port_); 75 | return false; 76 | } 77 | 78 | this->socket_ = sockfd; 79 | this->connected_ = true; 80 | return true; 81 | } 82 | 83 | auto sockfd = ::socket(AF_INET, SOCK_DGRAM, 0); 84 | if (sockfd < 0) 85 | { 86 | printf("[Socket]: Failed to create UDP socket\n"); 87 | return false; 88 | } 89 | 90 | this->socket_ = sockfd; 91 | this->connected_ = true; 92 | return true; 93 | } 94 | 95 | return true; 96 | } 97 | 98 | bool socket::receive(void* data, size_t length) 99 | { 100 | if (!this->connected_ || this->socket_ == INVALID_SOCKET) 101 | { 102 | printf("[Socket]: You must be connected before receiving data\n"); 103 | return false; 104 | } 105 | 106 | char* current_position = (char*)data; 107 | time_t start_time = get_tick_count(); 108 | size_t data_remaining = length; 109 | int recv_length = 0; 110 | 111 | while (data_remaining > 0) 112 | { 113 | if ((get_tick_count() - start_time) > SOCKET_TIME_OUT) 114 | { 115 | printf("[Socket]: Receive timedout\n"); 116 | return false; 117 | } 118 | 119 | int chunk = min(2048, data_remaining); 120 | if (this->type_ == socket_type::SOCKET_TYPE_TCP) 121 | { 122 | recv_length = ::recv(this->socket_, current_position, chunk, 0); 123 | } 124 | else 125 | { 126 | socklen_t recvlen; 127 | recv_length = ::recvfrom(this->socket_, current_position, chunk, 0, (sockaddr*)&this->server_addr, &recvlen); 128 | } 129 | 130 | if (recv_length < 0) 131 | { 132 | printf("[Socket]: Receive failed\n"); 133 | return false; 134 | } 135 | else if (recv_length < chunk) 136 | { 137 | return true; 138 | } 139 | 140 | data_remaining -= recv_length; 141 | current_position += recv_length; 142 | } 143 | 144 | return true; 145 | } 146 | 147 | bool socket::send(const void* data, size_t length) 148 | { 149 | if (!this->connected_ || this->socket_ == INVALID_SOCKET) 150 | { 151 | printf("[Socket]: You must be connected before sending data\n"); 152 | return false; 153 | } 154 | 155 | char* current_position = (char*)data; 156 | time_t start_time = get_tick_count(); 157 | size_t data_remaining = length; 158 | int send_length = 0; 159 | 160 | while (data_remaining > 0) 161 | { 162 | if ((get_tick_count() - start_time) > SOCKET_TIME_OUT) 163 | { 164 | printf("[Socket]: Send timedout\n"); 165 | return false; 166 | } 167 | 168 | int chunk = min(2048, data_remaining); 169 | if (this->type_ == socket_type::SOCKET_TYPE_TCP) 170 | { 171 | send_length = ::send(this->socket_, current_position, chunk, 0); 172 | } 173 | else 174 | { 175 | send_length = ::sendto(this->socket_, current_position, chunk, 0, (sockaddr*)&this->server_addr, sizeof(this->server_addr)); 176 | } 177 | 178 | if (send_length < 0) 179 | { 180 | printf("[Socket]: Send failed\n"); 181 | return false; 182 | } 183 | else if (send_length < chunk) 184 | { 185 | return true; 186 | } 187 | 188 | data_remaining -= send_length; 189 | current_position += send_length; 190 | } 191 | 192 | return true; 193 | } 194 | } 195 | } -------------------------------------------------------------------------------- /libpsutil/system/filesystem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "system/filesystem.hpp" 4 | #include "string.hpp" 5 | 6 | namespace libpsutil 7 | { 8 | namespace filesystem 9 | { 10 | bool read_file(const std::string& file_name, void* data, size_t size) 11 | { 12 | int fd = 0; 13 | uint64_t pos = 0; 14 | uint64_t nread = 0; 15 | 16 | if (cellFsOpen(file_name.data(), 0, &fd, NULL, 0) == CELL_FS_SUCCEEDED) 17 | { 18 | cellFsLseek(fd, 0, CELL_FS_SEEK_SET, &pos); 19 | cellFsRead(fd, data, size, &nread); 20 | cellFsClose(fd); 21 | 22 | return true; 23 | } 24 | 25 | return false; 26 | } 27 | 28 | std::string read_file(const std::string& file_name) 29 | { 30 | auto size = get_file_size(file_name); 31 | if (size != -1) 32 | { 33 | auto* data = new char[size + 1]; 34 | read_file(file_name, data, size); 35 | 36 | std::string output; 37 | output.resize(size + 1); 38 | memcpy(const_cast(output.data()), data, static_cast(size)); 39 | return output; 40 | } 41 | 42 | return {}; 43 | } 44 | 45 | bool write_file(const std::string& file_name, const void* data, size_t size) 46 | { 47 | int fd = 0; 48 | uint64_t pos = 0, nwrite = 0; 49 | 50 | if (cellFsOpen(file_name.data(), CELL_FS_O_WRONLY | CELL_FS_O_CREAT | CELL_FS_O_TRUNC, &fd, NULL, 0) == CELL_FS_SUCCEEDED) 51 | { 52 | cellFsLseek(fd, 0, CELL_FS_SEEK_SET, &pos); 53 | cellFsWrite(fd, data, size, &nwrite); 54 | cellFsClose(fd); 55 | 56 | return true; 57 | } 58 | 59 | return false; 60 | } 61 | 62 | bool write_file(const std::string& file_name, const std::string& data) 63 | { 64 | return write_file(file_name, data.data(), data.length()); 65 | } 66 | 67 | int64_t get_file_size(const std::string& file_name) 68 | { 69 | struct CellFsStat s; 70 | 71 | if (cellFsStat(file_name.data(), &s) == CELL_FS_SUCCEEDED) 72 | { 73 | return static_cast(s.st_size); 74 | } 75 | 76 | return -1; 77 | } 78 | 79 | bool directory_exists(const std::string& directory_name) 80 | { 81 | struct CellFsStat s; 82 | 83 | if (cellFsStat(directory_name.data(), &s) == CELL_FS_SUCCEEDED) 84 | { 85 | return ((s.st_mode & CELL_FS_S_IFDIR) != 0); 86 | } 87 | 88 | return false; 89 | } 90 | 91 | bool file_exists(const std::string& file_name) 92 | { 93 | struct CellFsStat s; 94 | 95 | if (cellFsStat(file_name.data(), &s) == CELL_FS_SUCCEEDED) 96 | { 97 | return ((s.st_mode & CELL_FS_S_IFREG) != 0); 98 | } 99 | 100 | return false; 101 | } 102 | 103 | void create_directory(const std::string& directory_name) 104 | { 105 | if (!directory_exists(directory_name.data())) 106 | { 107 | cellFsMkdir(directory_name.data(), 0777); 108 | } 109 | } 110 | 111 | std::vector list_files(const std::string& directory_name, bool recursive) 112 | { 113 | std::vector files; 114 | 115 | std::string directory_name_ = directory_name; 116 | if (!libpsutil::string::ends_with(directory_name, "/")) 117 | { 118 | directory_name_.append("/"); 119 | } 120 | 121 | int fd; 122 | if (cellFsOpendir(directory_name_.data(), &fd) != CELL_FS_OK) { return files; } 123 | 124 | uint64_t nread; 125 | CellFsDirent dent; 126 | 127 | while (cellFsReaddir(fd, &dent, &nread) == CELL_FS_OK) 128 | { 129 | if (nread == 0) { break; } 130 | 131 | if (dent.d_name[0] != '.') 132 | { 133 | struct CellFsStat st; 134 | auto file = directory_name_ + dent.d_name; 135 | 136 | if (cellFsStat(file.data(), &st) == CELL_FS_SUCCEEDED) 137 | { 138 | if ((st.st_mode & CELL_FS_S_IFDIR) != 0) 139 | { 140 | if (recursive) 141 | { 142 | auto sub_directory = list_files(file, recursive); 143 | for (auto& sub_file : sub_directory) 144 | { 145 | files.push_back(sub_file); 146 | } 147 | } 148 | } 149 | else 150 | { 151 | files.push_back(file); 152 | } 153 | } 154 | } 155 | } 156 | 157 | cellFsClosedir(fd); 158 | 159 | return files; 160 | } 161 | } 162 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/PS3_Debug/** 2 | **/PS3_Release/** 3 | 4 | ## Ignore Visual Studio temporary files, build results, and 5 | ## files generated by popular Visual Studio add-ons. 6 | ## 7 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 8 | 9 | # User-specific files 10 | *.rsuser 11 | *.suo 12 | *.user 13 | *.userosscache 14 | *.sln.docstates 15 | 16 | # User-specific files (MonoDevelop/Xamarin Studio) 17 | *.userprefs 18 | 19 | # Mono auto generated files 20 | mono_crash.* 21 | 22 | # Build results 23 | [Dd]ebug/ 24 | [Dd]ebugPublic/ 25 | [Rr]elease/ 26 | [Rr]eleases/ 27 | x64/ 28 | x86/ 29 | [Ww][Ii][Nn]32/ 30 | [Aa][Rr][Mm]/ 31 | [Aa][Rr][Mm]64/ 32 | bld/ 33 | [Bb]in/ 34 | [Oo]bj/ 35 | [Oo]ut/ 36 | [Ll]og/ 37 | [Ll]ogs/ 38 | 39 | # Visual Studio 2015/2017 cache/options directory 40 | .vs/ 41 | # Uncomment if you have tasks that create the project's static files in wwwroot 42 | #wwwroot/ 43 | 44 | # Visual Studio 2017 auto generated files 45 | Generated\ Files/ 46 | 47 | # MSTest test Results 48 | [Tt]est[Rr]esult*/ 49 | [Bb]uild[Ll]og.* 50 | 51 | # NUnit 52 | *.VisualState.xml 53 | TestResult.xml 54 | nunit-*.xml 55 | 56 | # Build Results of an ATL Project 57 | [Dd]ebugPS/ 58 | [Rr]eleasePS/ 59 | dlldata.c 60 | 61 | # Benchmark Results 62 | BenchmarkDotNet.Artifacts/ 63 | 64 | # .NET Core 65 | project.lock.json 66 | project.fragment.lock.json 67 | artifacts/ 68 | 69 | # ASP.NET Scaffolding 70 | ScaffoldingReadMe.txt 71 | 72 | # StyleCop 73 | StyleCopReport.xml 74 | 75 | # Files built by Visual Studio 76 | *_i.c 77 | *_p.c 78 | *_h.h 79 | *.ilk 80 | *.meta 81 | *.obj 82 | *.iobj 83 | *.pch 84 | *.pdb 85 | *.ipdb 86 | *.pgc 87 | *.pgd 88 | *.rsp 89 | *.sbr 90 | *.tlb 91 | *.tli 92 | *.tlh 93 | *.tmp 94 | *.tmp_proj 95 | *_wpftmp.csproj 96 | *.log 97 | *.vspscc 98 | *.vssscc 99 | .builds 100 | *.pidb 101 | *.svclog 102 | *.scc 103 | 104 | # Chutzpah Test files 105 | _Chutzpah* 106 | 107 | # Visual C++ cache files 108 | ipch/ 109 | *.aps 110 | *.ncb 111 | *.opendb 112 | *.opensdf 113 | *.sdf 114 | *.cachefile 115 | *.VC.db 116 | *.VC.VC.opendb 117 | 118 | # Visual Studio profiler 119 | *.psess 120 | *.vsp 121 | *.vspx 122 | *.sap 123 | 124 | # Visual Studio Trace Files 125 | *.e2e 126 | 127 | # TFS 2012 Local Workspace 128 | $tf/ 129 | 130 | # Guidance Automation Toolkit 131 | *.gpState 132 | 133 | # ReSharper is a .NET coding add-in 134 | _ReSharper*/ 135 | *.[Rr]e[Ss]harper 136 | *.DotSettings.user 137 | 138 | # TeamCity is a build add-in 139 | _TeamCity* 140 | 141 | # DotCover is a Code Coverage Tool 142 | *.dotCover 143 | 144 | # AxoCover is a Code Coverage Tool 145 | .axoCover/* 146 | !.axoCover/settings.json 147 | 148 | # Coverlet is a free, cross platform Code Coverage Tool 149 | coverage*.json 150 | coverage*.xml 151 | coverage*.info 152 | 153 | # Visual Studio code coverage results 154 | *.coverage 155 | *.coveragexml 156 | 157 | # NCrunch 158 | _NCrunch_* 159 | .*crunch*.local.xml 160 | nCrunchTemp_* 161 | 162 | # MightyMoose 163 | *.mm.* 164 | AutoTest.Net/ 165 | 166 | # Web workbench (sass) 167 | .sass-cache/ 168 | 169 | # Installshield output folder 170 | [Ee]xpress/ 171 | 172 | # DocProject is a documentation generator add-in 173 | DocProject/buildhelp/ 174 | DocProject/Help/*.HxT 175 | DocProject/Help/*.HxC 176 | DocProject/Help/*.hhc 177 | DocProject/Help/*.hhk 178 | DocProject/Help/*.hhp 179 | DocProject/Help/Html2 180 | DocProject/Help/html 181 | 182 | # Click-Once directory 183 | publish/ 184 | 185 | # Publish Web Output 186 | *.[Pp]ublish.xml 187 | *.azurePubxml 188 | # Note: Comment the next line if you want to checkin your web deploy settings, 189 | # but database connection strings (with potential passwords) will be unencrypted 190 | *.pubxml 191 | *.publishproj 192 | 193 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 194 | # checkin your Azure Web App publish settings, but sensitive information contained 195 | # in these scripts will be unencrypted 196 | PublishScripts/ 197 | 198 | # NuGet Packages 199 | *.nupkg 200 | # NuGet Symbol Packages 201 | *.snupkg 202 | # The packages folder can be ignored because of Package Restore 203 | **/[Pp]ackages/* 204 | # except build/, which is used as an MSBuild target. 205 | !**/[Pp]ackages/build/ 206 | # Uncomment if necessary however generally it will be regenerated when needed 207 | #!**/[Pp]ackages/repositories.config 208 | # NuGet v3's project.json files produces more ignorable files 209 | *.nuget.props 210 | *.nuget.targets 211 | 212 | # Microsoft Azure Build Output 213 | csx/ 214 | *.build.csdef 215 | 216 | # Microsoft Azure Emulator 217 | ecf/ 218 | rcf/ 219 | 220 | # Windows Store app package directories and files 221 | AppPackages/ 222 | BundleArtifacts/ 223 | Package.StoreAssociation.xml 224 | _pkginfo.txt 225 | *.appx 226 | *.appxbundle 227 | *.appxupload 228 | 229 | # Visual Studio cache files 230 | # files ending in .cache can be ignored 231 | *.[Cc]ache 232 | # but keep track of directories ending in .cache 233 | !?*.[Cc]ache/ 234 | 235 | # Others 236 | ClientBin/ 237 | ~$* 238 | *~ 239 | *.dbmdl 240 | *.dbproj.schemaview 241 | *.jfm 242 | *.pfx 243 | *.publishsettings 244 | orleans.codegen.cs 245 | 246 | # Including strong name files can present a security risk 247 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 248 | #*.snk 249 | 250 | # Since there are multiple workflows, uncomment next line to ignore bower_components 251 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 252 | #bower_components/ 253 | 254 | # RIA/Silverlight projects 255 | Generated_Code/ 256 | 257 | # Backup & report files from converting an old project file 258 | # to a newer Visual Studio version. Backup files are not needed, 259 | # because we have git ;-) 260 | _UpgradeReport_Files/ 261 | Backup*/ 262 | UpgradeLog*.XML 263 | UpgradeLog*.htm 264 | ServiceFabricBackup/ 265 | *.rptproj.bak 266 | 267 | # SQL Server files 268 | *.mdf 269 | *.ldf 270 | *.ndf 271 | 272 | # Business Intelligence projects 273 | *.rdl.data 274 | *.bim.layout 275 | *.bim_*.settings 276 | *.rptproj.rsuser 277 | *- [Bb]ackup.rdl 278 | *- [Bb]ackup ([0-9]).rdl 279 | *- [Bb]ackup ([0-9][0-9]).rdl 280 | 281 | # Microsoft Fakes 282 | FakesAssemblies/ 283 | 284 | # GhostDoc plugin setting file 285 | *.GhostDoc.xml 286 | 287 | # Node.js Tools for Visual Studio 288 | .ntvs_analysis.dat 289 | node_modules/ 290 | 291 | # Visual Studio 6 build log 292 | *.plg 293 | 294 | # Visual Studio 6 workspace options file 295 | *.opt 296 | 297 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 298 | *.vbw 299 | 300 | # Visual Studio LightSwitch build output 301 | **/*.HTMLClient/GeneratedArtifacts 302 | **/*.DesktopClient/GeneratedArtifacts 303 | **/*.DesktopClient/ModelManifest.xml 304 | **/*.Server/GeneratedArtifacts 305 | **/*.Server/ModelManifest.xml 306 | _Pvt_Extensions 307 | 308 | # Paket dependency manager 309 | .paket/paket.exe 310 | paket-files/ 311 | 312 | # FAKE - F# Make 313 | .fake/ 314 | 315 | # CodeRush personal settings 316 | .cr/personal 317 | 318 | # Python Tools for Visual Studio (PTVS) 319 | __pycache__/ 320 | *.pyc 321 | 322 | # Cake - Uncomment if you are using it 323 | # tools/** 324 | # !tools/packages.config 325 | 326 | # Tabs Studio 327 | *.tss 328 | 329 | # Telerik's JustMock configuration file 330 | *.jmconfig 331 | 332 | # BizTalk build output 333 | *.btp.cs 334 | *.btm.cs 335 | *.odx.cs 336 | *.xsd.cs 337 | 338 | # OpenCover UI analysis results 339 | OpenCover/ 340 | 341 | # Azure Stream Analytics local run output 342 | ASALocalRun/ 343 | 344 | # MSBuild Binary and Structured Log 345 | *.binlog 346 | 347 | # NVidia Nsight GPU debugger configuration file 348 | *.nvuser 349 | 350 | # MFractors (Xamarin productivity tool) working folder 351 | .mfractor/ 352 | 353 | # Local History for Visual Studio 354 | .localhistory/ 355 | 356 | # BeatPulse healthcheck temp database 357 | healthchecksdb 358 | 359 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 360 | MigrationBackup/ 361 | 362 | # Ionide (cross platform F# VS Code tools) working folder 363 | .ionide/ 364 | 365 | # Fody - auto-generated XML schema 366 | FodyWeavers.xsd -------------------------------------------------------------------------------- /libpsutil/math.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "math.hpp" 3 | 4 | namespace libpsutil 5 | { 6 | namespace math 7 | { 8 | namespace 9 | { 10 | uint32_t rand_next = 1; 11 | uint32_t rand_r(uint32_t* ctx) 12 | { 13 | return ((*ctx = *ctx * 0x41C64E6D + 0x3039) % ((uint32_t)0x7FFFFFFF + 1)); 14 | } 15 | } 16 | 17 | int atoi(char* str) 18 | { 19 | int32_t res = 0; 20 | for (auto i = 0; str[i] != '\0'; ++i) 21 | { 22 | res = res * 10 + str[i] - '0'; 23 | } 24 | 25 | return res; 26 | } 27 | 28 | float atof(char* str) 29 | { 30 | float rez = 0, fact = 1; 31 | if (*str == '-') 32 | { 33 | str++; 34 | fact = -1; 35 | } 36 | 37 | for (int32_t point_seen = 0; *str; str++) 38 | { 39 | if (*str == '.') 40 | { 41 | point_seen = 1; 42 | continue; 43 | } 44 | 45 | int32_t d = *str - '0'; 46 | if (d >= 0 && d <= 9) 47 | { 48 | if (point_seen) fact /= 10.0f; 49 | rez = rez * 10.0f + (float)d; 50 | } 51 | } 52 | 53 | return rez * fact; 54 | } 55 | 56 | void srand(uint32_t seed) 57 | { 58 | rand_next = seed; 59 | } 60 | 61 | uint32_t rand() 62 | { 63 | return rand_r(&rand_next); 64 | } 65 | 66 | vec2_t::vec2_t() 67 | { 68 | this->x = this->y = 0; 69 | } 70 | 71 | vec2_t::vec2_t(float x, float y) 72 | { 73 | this->x = x; 74 | this->y = y; 75 | } 76 | 77 | vec2_t::vec2_t(float vec[2]) 78 | { 79 | if (vec != 0) 80 | { 81 | this->x = vec[0]; 82 | this->y = vec[1]; 83 | } 84 | else 85 | { 86 | this->x = this->y = 0; 87 | } 88 | } 89 | 90 | vec2_t vec2_t::operator+(const vec2_t vec) 91 | { 92 | return vec2_t(this->x + vec.x, this->y + vec.y); 93 | } 94 | 95 | vec2_t vec2_t::operator+(const float* vec) 96 | { 97 | return vec2_t(this->x + vec[0], this->y + vec[1]); 98 | } 99 | 100 | vec2_t vec2_t::operator-(const vec2_t vec) 101 | { 102 | return vec2_t(this->x - vec.x, this->y - vec.y); 103 | } 104 | 105 | vec2_t vec2_t::operator-(const float* vec) 106 | { 107 | return vec2_t(this->x - vec[0], this->y - vec[1]); 108 | } 109 | 110 | vec2_t vec2_t::operator-() const 111 | { 112 | return vec2_t(-x, -y); 113 | } 114 | 115 | vec2_t vec2_t::operator*(const vec2_t vec) 116 | { 117 | return vec2_t(this->x * vec.x, this->y * vec.y); 118 | } 119 | 120 | vec2_t vec2_t::operator*(const float scalar) 121 | { 122 | return vec2_t(this->x * scalar, this->y * scalar); 123 | } 124 | 125 | void vec2_t::operator-=(const vec2_t vec) 126 | { 127 | this->x -= vec.x; 128 | this->y -= vec.y; 129 | } 130 | 131 | void vec2_t::operator+=(const vec2_t vec) 132 | { 133 | this->x += vec.x; 134 | this->y += vec.y; 135 | } 136 | 137 | void vec2_t::operator*=(const vec2_t vec) 138 | { 139 | this->x *= vec.x; 140 | this->y *= vec.y; 141 | } 142 | 143 | void vec2_t::operator*=(const float scalar) 144 | { 145 | this->x *= scalar; 146 | this->y *= scalar; 147 | } 148 | 149 | bool vec2_t::operator==(const vec2_t vec) 150 | { 151 | return (this->x == vec.x && this->y == vec.y); 152 | } 153 | 154 | bool vec2_t::operator==(const float value) 155 | { 156 | return (this->x == value && this->y == value); 157 | } 158 | 159 | bool vec2_t::operator!=(const vec2_t vec) 160 | { 161 | return !operator==(vec); 162 | } 163 | 164 | bool vec2_t::operator!=(const float value) 165 | { 166 | return !operator==(value); 167 | } 168 | 169 | vec2_t::operator float* () 170 | { 171 | return (float*)&this[0]; 172 | } 173 | 174 | vec3_t::vec3_t() 175 | { 176 | this->x = this->y = 0; 177 | } 178 | 179 | vec3_t::vec3_t(float x, float y, float z) 180 | { 181 | this->x = x; 182 | this->y = y; 183 | this->z = z; 184 | } 185 | 186 | vec3_t::vec3_t(float vec[3]) 187 | { 188 | if (vec != 0) 189 | { 190 | this->x = vec[0]; 191 | this->y = vec[1]; 192 | this->z = vec[2]; 193 | } 194 | else 195 | { 196 | this->x = this->y = this->z = 0; 197 | } 198 | } 199 | 200 | vec3_t vec3_t::operator+(const vec3_t vec) 201 | { 202 | return vec3_t(this->x + vec.x, this->y + vec.y, this->z + vec.z); 203 | } 204 | 205 | vec3_t vec3_t::operator+(const float* vec) 206 | { 207 | return vec3_t(this->x + vec[0], this->y + vec[1], this->z + vec[2]); 208 | } 209 | 210 | vec3_t vec3_t::operator-(const vec3_t vec) 211 | { 212 | return vec3_t(this->x - vec.x, this->y - vec.y, this->z - vec.z); 213 | } 214 | 215 | vec3_t vec3_t::operator-(const float* vec) 216 | { 217 | return vec3_t(this->x - vec[0], this->y - vec[1], this->z - vec[2]); 218 | } 219 | 220 | vec3_t vec3_t::operator-() const 221 | { 222 | return vec3_t(-x, -y, -z); 223 | } 224 | 225 | vec3_t vec3_t::operator*(const vec3_t vec) 226 | { 227 | return vec3_t(this->x * vec.x, this->y * vec.y, this->z * vec.z); 228 | } 229 | 230 | vec3_t vec3_t::operator*(const float scalar) 231 | { 232 | return vec3_t(this->x * scalar, this->y * scalar, this->z * scalar); 233 | } 234 | 235 | void vec3_t::operator-=(const vec3_t vec) 236 | { 237 | this->x -= vec.x; 238 | this->y -= vec.y; 239 | this->z -= vec.z; 240 | } 241 | 242 | void vec3_t::operator+=(const vec3_t vec) 243 | { 244 | this->x += vec.x; 245 | this->y += vec.y; 246 | this->z += vec.z; 247 | } 248 | 249 | void vec3_t::operator*=(const vec3_t vec) 250 | { 251 | this->x *= vec.x; 252 | this->y *= vec.y; 253 | this->z *= vec.z; 254 | } 255 | 256 | void vec3_t::operator*=(const float scalar) 257 | { 258 | this->x *= scalar; 259 | this->y *= scalar; 260 | this->z *= scalar; 261 | } 262 | 263 | bool vec3_t::operator==(const vec3_t vec) 264 | { 265 | return (this->x == vec.x && this->y == vec.y && this->z == vec.z); 266 | } 267 | 268 | bool vec3_t::operator==(const float value) 269 | { 270 | return (this->x == value && this->y == value && this->z == value); 271 | } 272 | 273 | bool vec3_t::operator!=(const vec3_t vec) 274 | { 275 | return !operator==(vec); 276 | } 277 | 278 | bool vec3_t::operator!=(const float value) 279 | { 280 | return !operator==(value); 281 | } 282 | 283 | vec3_t::operator float* () 284 | { 285 | return (float*)&this[0]; 286 | } 287 | 288 | vec3_t vec3_t::forward(float x) 289 | { 290 | float div = M_PI / 180.0f; 291 | 292 | float angle = this->y * div; 293 | float sy = sinf(angle); 294 | float cy = cosf(angle); 295 | 296 | angle = this->x * div; 297 | float sp = sinf(angle); 298 | float cp = cosf(angle); 299 | 300 | return vec3_t(cp * cy * x, cp * sy * x, -sp * x); 301 | } 302 | 303 | vec3_t vec3_t::normalize() 304 | { 305 | vec3_t newvec; 306 | newvec.x = this->x / length(); 307 | newvec.y = this->y / length(); 308 | newvec.z = this->z / length(); 309 | return newvec; 310 | } 311 | 312 | float vec3_t::distance(vec3_t vec) 313 | { 314 | float _x = this->x - vec.x; 315 | float _y = this->y - vec.y; 316 | float _z = this->z - vec.z; 317 | return f_sqrtf((_x * _x) + (_y * _y) + (_z * _z)); 318 | } 319 | 320 | float vec3_t::length() 321 | { 322 | return (float)f_sqrtf(x * x + y * y + z * z); 323 | } 324 | 325 | void vec3_t::vectors(vec3_t* forward, vec3_t* right, vec3_t* up) 326 | { 327 | float angle; 328 | float sr, sp, sy, cr, cp, cy; 329 | 330 | angle = this->y * (M_PI * 2.0f / 360.0f); 331 | sy = sinf(angle); 332 | cy = cosf(angle); 333 | 334 | angle = this->x * (M_PI * 2.0f / 360.0f); 335 | sp = sinf(angle); 336 | cp = cosf(angle); 337 | 338 | angle = this->z * (M_PI * 2.0f / 360.0f); 339 | sr = sinf(angle); 340 | cr = cosf(angle); 341 | 342 | if (forward) 343 | { 344 | forward->x = cp * cy; 345 | forward->y = cp * sy; 346 | forward->z = -sp; 347 | } 348 | if (right) 349 | { 350 | right->x = (-1 * sr * sp * cy + -1 * cr * -sy); 351 | right->y = (-1 * sr * sp * sy + -1 * cr * cy); 352 | right->z = -1 * sr * cp; 353 | } 354 | if (up) 355 | { 356 | up->x = (cr * sp * cy + -sr * -sy); 357 | up->y = (cr * sp * sy + -sr * cy); 358 | up->z = cr * cp; 359 | } 360 | } 361 | 362 | vec4_t::vec4_t() 363 | { 364 | this->x = this->y = 0; 365 | } 366 | 367 | vec4_t::vec4_t(float x, float y, float z, float w) 368 | { 369 | this->x = x; 370 | this->y = y; 371 | this->z = z; 372 | this->w = w; 373 | } 374 | 375 | vec4_t::vec4_t(float vec[4]) 376 | { 377 | if (vec != 0) 378 | { 379 | this->x = vec[0]; 380 | this->y = vec[1]; 381 | this->z = vec[2]; 382 | this->w = vec[3]; 383 | } 384 | else 385 | { 386 | this->x = this->y = this->z = this->w = 0; 387 | } 388 | } 389 | 390 | vec4_t vec4_t::operator+(const vec4_t vec) 391 | { 392 | return vec4_t(this->x + vec.x, this->y + vec.y, this->z + vec.z, this->w + vec.w); 393 | } 394 | 395 | vec4_t vec4_t::operator+(const float* vec) 396 | { 397 | return vec4_t(this->x + vec[0], this->y + vec[1], this->z + vec[2], this->w + vec[3]); 398 | } 399 | 400 | vec4_t vec4_t::operator-(const vec4_t vec) 401 | { 402 | return vec4_t(this->x - vec.x, this->y - vec.y, this->z - vec.z, this->w - vec.w); 403 | } 404 | 405 | vec4_t vec4_t::operator-(const float* vec) 406 | { 407 | return vec4_t(this->x - vec[0], this->y - vec[1], this->z - vec[2], this->w - vec[3]); 408 | } 409 | 410 | vec4_t vec4_t::operator-() const 411 | { 412 | return vec4_t(-x, -y, -z, -w); 413 | } 414 | 415 | vec4_t vec4_t::operator*(const vec4_t vec) 416 | { 417 | return vec4_t(this->x * vec.x, this->y * vec.y, this->z * vec.z, this->w * vec.w); 418 | } 419 | 420 | vec4_t vec4_t::operator*(const float scalar) 421 | { 422 | return vec4_t(this->x * scalar, this->y * scalar, this->z * scalar, this->w * scalar); 423 | } 424 | 425 | void vec4_t::operator-=(const vec4_t vec) 426 | { 427 | this->x -= vec.x; 428 | this->y -= vec.y; 429 | this->z -= vec.z; 430 | this->w -= vec.w; 431 | } 432 | 433 | void vec4_t::operator+=(const vec4_t vec) 434 | { 435 | this->x += vec.x; 436 | this->y += vec.y; 437 | this->z += vec.z; 438 | this->w += vec.w; 439 | } 440 | 441 | void vec4_t::operator*=(const vec4_t vec) 442 | { 443 | this->x *= vec.x; 444 | this->y *= vec.y; 445 | this->z *= vec.z; 446 | this->w *= vec.w; 447 | } 448 | 449 | void vec4_t::operator*=(const float scalar) 450 | { 451 | this->x *= scalar; 452 | this->y *= scalar; 453 | this->z *= scalar; 454 | this->w *= scalar; 455 | } 456 | 457 | bool vec4_t::operator==(const vec4_t vec) 458 | { 459 | return (this->x == vec.x && this->y == vec.y && this->z == vec.z && this->w == vec.w); 460 | } 461 | 462 | bool vec4_t::operator==(const float value) 463 | { 464 | return (this->x == value && this->y == value && this->z == value && this->w == value); 465 | } 466 | 467 | bool vec4_t::operator!=(const vec4_t vec) 468 | { 469 | return !operator==(vec); 470 | } 471 | 472 | bool vec4_t::operator!=(const float value) 473 | { 474 | return !operator==(value); 475 | } 476 | 477 | vec4_t::operator float* () 478 | { 479 | return (float*)&this[0]; 480 | } 481 | } 482 | } -------------------------------------------------------------------------------- /libpsutil/cryptography/tiger.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "cryptography/tiger.hpp" 3 | 4 | typedef unsigned long long int word64; 5 | typedef unsigned long word32; 6 | typedef unsigned char byte; 7 | 8 | /* Big endian: */ 9 | #if !(defined(__alpha)||defined(__i386__)||defined(__vax__)) 10 | #define BIG_ENDIAN 11 | #endif 12 | 13 | /* The following macro denotes that an optimization */ 14 | /* for Alpha is required. It is used only for */ 15 | /* optimization of time. Otherwise it does nothing. */ 16 | #ifdef __alpha 17 | #define OPTIMIZE_FOR_ALPHA 18 | #endif 19 | 20 | /* NOTE that this code is NOT FULLY OPTIMIZED for any */ 21 | /* machine. Assembly code might be much faster on some */ 22 | /* machines, especially if the code is compiled with */ 23 | /* gcc. */ 24 | 25 | /* The number of passes of the hash function. */ 26 | /* Three passes are recommended. */ 27 | /* Use four passes when you need extra security. */ 28 | /* Must be at least three. */ 29 | #define PASSES 3 30 | 31 | //extern word64 table[4*256]; 32 | /* sboxes.c: Tiger S boxes */ 33 | //typedef unsigned long long int word64; 34 | word64 table[4 * 256] = { 35 | 0x02AAB17CF7E90C5ELL /* 0 */, 0xAC424B03E243A8ECLL /* 1 */, 36 | 0x72CD5BE30DD5FCD3LL /* 2 */, 0x6D019B93F6F97F3ALL /* 3 */, 37 | 0xCD9978FFD21F9193LL /* 4 */, 0x7573A1C9708029E2LL /* 5 */, 38 | 0xB164326B922A83C3LL /* 6 */, 0x46883EEE04915870LL /* 7 */, 39 | 0xEAACE3057103ECE6LL /* 8 */, 0xC54169B808A3535CLL /* 9 */, 40 | 0x4CE754918DDEC47CLL /* 10 */, 0x0AA2F4DFDC0DF40CLL /* 11 */, 41 | 0x10B76F18A74DBEFALL /* 12 */, 0xC6CCB6235AD1AB6ALL /* 13 */, 42 | 0x13726121572FE2FFLL /* 14 */, 0x1A488C6F199D921ELL /* 15 */, 43 | 0x4BC9F9F4DA0007CALL /* 16 */, 0x26F5E6F6E85241C7LL /* 17 */, 44 | 0x859079DBEA5947B6LL /* 18 */, 0x4F1885C5C99E8C92LL /* 19 */, 45 | 0xD78E761EA96F864BLL /* 20 */, 0x8E36428C52B5C17DLL /* 21 */, 46 | 0x69CF6827373063C1LL /* 22 */, 0xB607C93D9BB4C56ELL /* 23 */, 47 | 0x7D820E760E76B5EALL /* 24 */, 0x645C9CC6F07FDC42LL /* 25 */, 48 | 0xBF38A078243342E0LL /* 26 */, 0x5F6B343C9D2E7D04LL /* 27 */, 49 | 0xF2C28AEB600B0EC6LL /* 28 */, 0x6C0ED85F7254BCACLL /* 29 */, 50 | 0x71592281A4DB4FE5LL /* 30 */, 0x1967FA69CE0FED9FLL /* 31 */, 51 | 0xFD5293F8B96545DBLL /* 32 */, 0xC879E9D7F2A7600BLL /* 33 */, 52 | 0x860248920193194ELL /* 34 */, 0xA4F9533B2D9CC0B3LL /* 35 */, 53 | 0x9053836C15957613LL /* 36 */, 0xDB6DCF8AFC357BF1LL /* 37 */, 54 | 0x18BEEA7A7A370F57LL /* 38 */, 0x037117CA50B99066LL /* 39 */, 55 | 0x6AB30A9774424A35LL /* 40 */, 0xF4E92F02E325249BLL /* 41 */, 56 | 0x7739DB07061CCAE1LL /* 42 */, 0xD8F3B49CECA42A05LL /* 43 */, 57 | 0xBD56BE3F51382F73LL /* 44 */, 0x45FAED5843B0BB28LL /* 45 */, 58 | 0x1C813D5C11BF1F83LL /* 46 */, 0x8AF0E4B6D75FA169LL /* 47 */, 59 | 0x33EE18A487AD9999LL /* 48 */, 0x3C26E8EAB1C94410LL /* 49 */, 60 | 0xB510102BC0A822F9LL /* 50 */, 0x141EEF310CE6123BLL /* 51 */, 61 | 0xFC65B90059DDB154LL /* 52 */, 0xE0158640C5E0E607LL /* 53 */, 62 | 0x884E079826C3A3CFLL /* 54 */, 0x930D0D9523C535FDLL /* 55 */, 63 | 0x35638D754E9A2B00LL /* 56 */, 0x4085FCCF40469DD5LL /* 57 */, 64 | 0xC4B17AD28BE23A4CLL /* 58 */, 0xCAB2F0FC6A3E6A2ELL /* 59 */, 65 | 0x2860971A6B943FCDLL /* 60 */, 0x3DDE6EE212E30446LL /* 61 */, 66 | 0x6222F32AE01765AELL /* 62 */, 0x5D550BB5478308FELL /* 63 */, 67 | 0xA9EFA98DA0EDA22ALL /* 64 */, 0xC351A71686C40DA7LL /* 65 */, 68 | 0x1105586D9C867C84LL /* 66 */, 0xDCFFEE85FDA22853LL /* 67 */, 69 | 0xCCFBD0262C5EEF76LL /* 68 */, 0xBAF294CB8990D201LL /* 69 */, 70 | 0xE69464F52AFAD975LL /* 70 */, 0x94B013AFDF133E14LL /* 71 */, 71 | 0x06A7D1A32823C958LL /* 72 */, 0x6F95FE5130F61119LL /* 73 */, 72 | 0xD92AB34E462C06C0LL /* 74 */, 0xED7BDE33887C71D2LL /* 75 */, 73 | 0x79746D6E6518393ELL /* 76 */, 0x5BA419385D713329LL /* 77 */, 74 | 0x7C1BA6B948A97564LL /* 78 */, 0x31987C197BFDAC67LL /* 79 */, 75 | 0xDE6C23C44B053D02LL /* 80 */, 0x581C49FED002D64DLL /* 81 */, 76 | 0xDD474D6338261571LL /* 82 */, 0xAA4546C3E473D062LL /* 83 */, 77 | 0x928FCE349455F860LL /* 84 */, 0x48161BBACAAB94D9LL /* 85 */, 78 | 0x63912430770E6F68LL /* 86 */, 0x6EC8A5E602C6641CLL /* 87 */, 79 | 0x87282515337DDD2BLL /* 88 */, 0x2CDA6B42034B701BLL /* 89 */, 80 | 0xB03D37C181CB096DLL /* 90 */, 0xE108438266C71C6FLL /* 91 */, 81 | 0x2B3180C7EB51B255LL /* 92 */, 0xDF92B82F96C08BBCLL /* 93 */, 82 | 0x5C68C8C0A632F3BALL /* 94 */, 0x5504CC861C3D0556LL /* 95 */, 83 | 0xABBFA4E55FB26B8FLL /* 96 */, 0x41848B0AB3BACEB4LL /* 97 */, 84 | 0xB334A273AA445D32LL /* 98 */, 0xBCA696F0A85AD881LL /* 99 */, 85 | 0x24F6EC65B528D56CLL /* 100 */, 0x0CE1512E90F4524ALL /* 101 */, 86 | 0x4E9DD79D5506D35ALL /* 102 */, 0x258905FAC6CE9779LL /* 103 */, 87 | 0x2019295B3E109B33LL /* 104 */, 0xF8A9478B73A054CCLL /* 105 */, 88 | 0x2924F2F934417EB0LL /* 106 */, 0x3993357D536D1BC4LL /* 107 */, 89 | 0x38A81AC21DB6FF8BLL /* 108 */, 0x47C4FBF17D6016BFLL /* 109 */, 90 | 0x1E0FAADD7667E3F5LL /* 110 */, 0x7ABCFF62938BEB96LL /* 111 */, 91 | 0xA78DAD948FC179C9LL /* 112 */, 0x8F1F98B72911E50DLL /* 113 */, 92 | 0x61E48EAE27121A91LL /* 114 */, 0x4D62F7AD31859808LL /* 115 */, 93 | 0xECEBA345EF5CEAEBLL /* 116 */, 0xF5CEB25EBC9684CELL /* 117 */, 94 | 0xF633E20CB7F76221LL /* 118 */, 0xA32CDF06AB8293E4LL /* 119 */, 95 | 0x985A202CA5EE2CA4LL /* 120 */, 0xCF0B8447CC8A8FB1LL /* 121 */, 96 | 0x9F765244979859A3LL /* 122 */, 0xA8D516B1A1240017LL /* 123 */, 97 | 0x0BD7BA3EBB5DC726LL /* 124 */, 0xE54BCA55B86ADB39LL /* 125 */, 98 | 0x1D7A3AFD6C478063LL /* 126 */, 0x519EC608E7669EDDLL /* 127 */, 99 | 0x0E5715A2D149AA23LL /* 128 */, 0x177D4571848FF194LL /* 129 */, 100 | 0xEEB55F3241014C22LL /* 130 */, 0x0F5E5CA13A6E2EC2LL /* 131 */, 101 | 0x8029927B75F5C361LL /* 132 */, 0xAD139FABC3D6E436LL /* 133 */, 102 | 0x0D5DF1A94CCF402FLL /* 134 */, 0x3E8BD948BEA5DFC8LL /* 135 */, 103 | 0xA5A0D357BD3FF77ELL /* 136 */, 0xA2D12E251F74F645LL /* 137 */, 104 | 0x66FD9E525E81A082LL /* 138 */, 0x2E0C90CE7F687A49LL /* 139 */, 105 | 0xC2E8BCBEBA973BC5LL /* 140 */, 0x000001BCE509745FLL /* 141 */, 106 | 0x423777BBE6DAB3D6LL /* 142 */, 0xD1661C7EAEF06EB5LL /* 143 */, 107 | 0xA1781F354DAACFD8LL /* 144 */, 0x2D11284A2B16AFFCLL /* 145 */, 108 | 0xF1FC4F67FA891D1FLL /* 146 */, 0x73ECC25DCB920ADALL /* 147 */, 109 | 0xAE610C22C2A12651LL /* 148 */, 0x96E0A810D356B78ALL /* 149 */, 110 | 0x5A9A381F2FE7870FLL /* 150 */, 0xD5AD62EDE94E5530LL /* 151 */, 111 | 0xD225E5E8368D1427LL /* 152 */, 0x65977B70C7AF4631LL /* 153 */, 112 | 0x99F889B2DE39D74FLL /* 154 */, 0x233F30BF54E1D143LL /* 155 */, 113 | 0x9A9675D3D9A63C97LL /* 156 */, 0x5470554FF334F9A8LL /* 157 */, 114 | 0x166ACB744A4F5688LL /* 158 */, 0x70C74CAAB2E4AEADLL /* 159 */, 115 | 0xF0D091646F294D12LL /* 160 */, 0x57B82A89684031D1LL /* 161 */, 116 | 0xEFD95A5A61BE0B6BLL /* 162 */, 0x2FBD12E969F2F29ALL /* 163 */, 117 | 0x9BD37013FEFF9FE8LL /* 164 */, 0x3F9B0404D6085A06LL /* 165 */, 118 | 0x4940C1F3166CFE15LL /* 166 */, 0x09542C4DCDF3DEFBLL /* 167 */, 119 | 0xB4C5218385CD5CE3LL /* 168 */, 0xC935B7DC4462A641LL /* 169 */, 120 | 0x3417F8A68ED3B63FLL /* 170 */, 0xB80959295B215B40LL /* 171 */, 121 | 0xF99CDAEF3B8C8572LL /* 172 */, 0x018C0614F8FCB95DLL /* 173 */, 122 | 0x1B14ACCD1A3ACDF3LL /* 174 */, 0x84D471F200BB732DLL /* 175 */, 123 | 0xC1A3110E95E8DA16LL /* 176 */, 0x430A7220BF1A82B8LL /* 177 */, 124 | 0xB77E090D39DF210ELL /* 178 */, 0x5EF4BD9F3CD05E9DLL /* 179 */, 125 | 0x9D4FF6DA7E57A444LL /* 180 */, 0xDA1D60E183D4A5F8LL /* 181 */, 126 | 0xB287C38417998E47LL /* 182 */, 0xFE3EDC121BB31886LL /* 183 */, 127 | 0xC7FE3CCC980CCBEFLL /* 184 */, 0xE46FB590189BFD03LL /* 185 */, 128 | 0x3732FD469A4C57DCLL /* 186 */, 0x7EF700A07CF1AD65LL /* 187 */, 129 | 0x59C64468A31D8859LL /* 188 */, 0x762FB0B4D45B61F6LL /* 189 */, 130 | 0x155BAED099047718LL /* 190 */, 0x68755E4C3D50BAA6LL /* 191 */, 131 | 0xE9214E7F22D8B4DFLL /* 192 */, 0x2ADDBF532EAC95F4LL /* 193 */, 132 | 0x32AE3909B4BD0109LL /* 194 */, 0x834DF537B08E3450LL /* 195 */, 133 | 0xFA209DA84220728DLL /* 196 */, 0x9E691D9B9EFE23F7LL /* 197 */, 134 | 0x0446D288C4AE8D7FLL /* 198 */, 0x7B4CC524E169785BLL /* 199 */, 135 | 0x21D87F0135CA1385LL /* 200 */, 0xCEBB400F137B8AA5LL /* 201 */, 136 | 0x272E2B66580796BELL /* 202 */, 0x3612264125C2B0DELL /* 203 */, 137 | 0x057702BDAD1EFBB2LL /* 204 */, 0xD4BABB8EACF84BE9LL /* 205 */, 138 | 0x91583139641BC67BLL /* 206 */, 0x8BDC2DE08036E024LL /* 207 */, 139 | 0x603C8156F49F68EDLL /* 208 */, 0xF7D236F7DBEF5111LL /* 209 */, 140 | 0x9727C4598AD21E80LL /* 210 */, 0xA08A0896670A5FD7LL /* 211 */, 141 | 0xCB4A8F4309EBA9CBLL /* 212 */, 0x81AF564B0F7036A1LL /* 213 */, 142 | 0xC0B99AA778199ABDLL /* 214 */, 0x959F1EC83FC8E952LL /* 215 */, 143 | 0x8C505077794A81B9LL /* 216 */, 0x3ACAAF8F056338F0LL /* 217 */, 144 | 0x07B43F50627A6778LL /* 218 */, 0x4A44AB49F5ECCC77LL /* 219 */, 145 | 0x3BC3D6E4B679EE98LL /* 220 */, 0x9CC0D4D1CF14108CLL /* 221 */, 146 | 0x4406C00B206BC8A0LL /* 222 */, 0x82A18854C8D72D89LL /* 223 */, 147 | 0x67E366B35C3C432CLL /* 224 */, 0xB923DD61102B37F2LL /* 225 */, 148 | 0x56AB2779D884271DLL /* 226 */, 0xBE83E1B0FF1525AFLL /* 227 */, 149 | 0xFB7C65D4217E49A9LL /* 228 */, 0x6BDBE0E76D48E7D4LL /* 229 */, 150 | 0x08DF828745D9179ELL /* 230 */, 0x22EA6A9ADD53BD34LL /* 231 */, 151 | 0xE36E141C5622200ALL /* 232 */, 0x7F805D1B8CB750EELL /* 233 */, 152 | 0xAFE5C7A59F58E837LL /* 234 */, 0xE27F996A4FB1C23CLL /* 235 */, 153 | 0xD3867DFB0775F0D0LL /* 236 */, 0xD0E673DE6E88891ALL /* 237 */, 154 | 0x123AEB9EAFB86C25LL /* 238 */, 0x30F1D5D5C145B895LL /* 239 */, 155 | 0xBB434A2DEE7269E7LL /* 240 */, 0x78CB67ECF931FA38LL /* 241 */, 156 | 0xF33B0372323BBF9CLL /* 242 */, 0x52D66336FB279C74LL /* 243 */, 157 | 0x505F33AC0AFB4EAALL /* 244 */, 0xE8A5CD99A2CCE187LL /* 245 */, 158 | 0x534974801E2D30BBLL /* 246 */, 0x8D2D5711D5876D90LL /* 247 */, 159 | 0x1F1A412891BC038ELL /* 248 */, 0xD6E2E71D82E56648LL /* 249 */, 160 | 0x74036C3A497732B7LL /* 250 */, 0x89B67ED96361F5ABLL /* 251 */, 161 | 0xFFED95D8F1EA02A2LL /* 252 */, 0xE72B3BD61464D43DLL /* 253 */, 162 | 0xA6300F170BDC4820LL /* 254 */, 0xEBC18760ED78A77ALL /* 255 */, 163 | 0xE6A6BE5A05A12138LL /* 256 */, 0xB5A122A5B4F87C98LL /* 257 */, 164 | 0x563C6089140B6990LL /* 258 */, 0x4C46CB2E391F5DD5LL /* 259 */, 165 | 0xD932ADDBC9B79434LL /* 260 */, 0x08EA70E42015AFF5LL /* 261 */, 166 | 0xD765A6673E478CF1LL /* 262 */, 0xC4FB757EAB278D99LL /* 263 */, 167 | 0xDF11C6862D6E0692LL /* 264 */, 0xDDEB84F10D7F3B16LL /* 265 */, 168 | 0x6F2EF604A665EA04LL /* 266 */, 0x4A8E0F0FF0E0DFB3LL /* 267 */, 169 | 0xA5EDEEF83DBCBA51LL /* 268 */, 0xFC4F0A2A0EA4371ELL /* 269 */, 170 | 0xE83E1DA85CB38429LL /* 270 */, 0xDC8FF882BA1B1CE2LL /* 271 */, 171 | 0xCD45505E8353E80DLL /* 272 */, 0x18D19A00D4DB0717LL /* 273 */, 172 | 0x34A0CFEDA5F38101LL /* 274 */, 0x0BE77E518887CAF2LL /* 275 */, 173 | 0x1E341438B3C45136LL /* 276 */, 0xE05797F49089CCF9LL /* 277 */, 174 | 0xFFD23F9DF2591D14LL /* 278 */, 0x543DDA228595C5CDLL /* 279 */, 175 | 0x661F81FD99052A33LL /* 280 */, 0x8736E641DB0F7B76LL /* 281 */, 176 | 0x15227725418E5307LL /* 282 */, 0xE25F7F46162EB2FALL /* 283 */, 177 | 0x48A8B2126C13D9FELL /* 284 */, 0xAFDC541792E76EEALL /* 285 */, 178 | 0x03D912BFC6D1898FLL /* 286 */, 0x31B1AAFA1B83F51BLL /* 287 */, 179 | 0xF1AC2796E42AB7D9LL /* 288 */, 0x40A3A7D7FCD2EBACLL /* 289 */, 180 | 0x1056136D0AFBBCC5LL /* 290 */, 0x7889E1DD9A6D0C85LL /* 291 */, 181 | 0xD33525782A7974AALL /* 292 */, 0xA7E25D09078AC09BLL /* 293 */, 182 | 0xBD4138B3EAC6EDD0LL /* 294 */, 0x920ABFBE71EB9E70LL /* 295 */, 183 | 0xA2A5D0F54FC2625CLL /* 296 */, 0xC054E36B0B1290A3LL /* 297 */, 184 | 0xF6DD59FF62FE932BLL /* 298 */, 0x3537354511A8AC7DLL /* 299 */, 185 | 0xCA845E9172FADCD4LL /* 300 */, 0x84F82B60329D20DCLL /* 301 */, 186 | 0x79C62CE1CD672F18LL /* 302 */, 0x8B09A2ADD124642CLL /* 303 */, 187 | 0xD0C1E96A19D9E726LL /* 304 */, 0x5A786A9B4BA9500CLL /* 305 */, 188 | 0x0E020336634C43F3LL /* 306 */, 0xC17B474AEB66D822LL /* 307 */, 189 | 0x6A731AE3EC9BAAC2LL /* 308 */, 0x8226667AE0840258LL /* 309 */, 190 | 0x67D4567691CAECA5LL /* 310 */, 0x1D94155C4875ADB5LL /* 311 */, 191 | 0x6D00FD985B813FDFLL /* 312 */, 0x51286EFCB774CD06LL /* 313 */, 192 | 0x5E8834471FA744AFLL /* 314 */, 0xF72CA0AEE761AE2ELL /* 315 */, 193 | 0xBE40E4CDAEE8E09ALL /* 316 */, 0xE9970BBB5118F665LL /* 317 */, 194 | 0x726E4BEB33DF1964LL /* 318 */, 0x703B000729199762LL /* 319 */, 195 | 0x4631D816F5EF30A7LL /* 320 */, 0xB880B5B51504A6BELL /* 321 */, 196 | 0x641793C37ED84B6CLL /* 322 */, 0x7B21ED77F6E97D96LL /* 323 */, 197 | 0x776306312EF96B73LL /* 324 */, 0xAE528948E86FF3F4LL /* 325 */, 198 | 0x53DBD7F286A3F8F8LL /* 326 */, 0x16CADCE74CFC1063LL /* 327 */, 199 | 0x005C19BDFA52C6DDLL /* 328 */, 0x68868F5D64D46AD3LL /* 329 */, 200 | 0x3A9D512CCF1E186ALL /* 330 */, 0x367E62C2385660AELL /* 331 */, 201 | 0xE359E7EA77DCB1D7LL /* 332 */, 0x526C0773749ABE6ELL /* 333 */, 202 | 0x735AE5F9D09F734BLL /* 334 */, 0x493FC7CC8A558BA8LL /* 335 */, 203 | 0xB0B9C1533041AB45LL /* 336 */, 0x321958BA470A59BDLL /* 337 */, 204 | 0x852DB00B5F46C393LL /* 338 */, 0x91209B2BD336B0E5LL /* 339 */, 205 | 0x6E604F7D659EF19FLL /* 340 */, 0xB99A8AE2782CCB24LL /* 341 */, 206 | 0xCCF52AB6C814C4C7LL /* 342 */, 0x4727D9AFBE11727BLL /* 343 */, 207 | 0x7E950D0C0121B34DLL /* 344 */, 0x756F435670AD471FLL /* 345 */, 208 | 0xF5ADD442615A6849LL /* 346 */, 0x4E87E09980B9957ALL /* 347 */, 209 | 0x2ACFA1DF50AEE355LL /* 348 */, 0xD898263AFD2FD556LL /* 349 */, 210 | 0xC8F4924DD80C8FD6LL /* 350 */, 0xCF99CA3D754A173ALL /* 351 */, 211 | 0xFE477BACAF91BF3CLL /* 352 */, 0xED5371F6D690C12DLL /* 353 */, 212 | 0x831A5C285E687094LL /* 354 */, 0xC5D3C90A3708A0A4LL /* 355 */, 213 | 0x0F7F903717D06580LL /* 356 */, 0x19F9BB13B8FDF27FLL /* 357 */, 214 | 0xB1BD6F1B4D502843LL /* 358 */, 0x1C761BA38FFF4012LL /* 359 */, 215 | 0x0D1530C4E2E21F3BLL /* 360 */, 0x8943CE69A7372C8ALL /* 361 */, 216 | 0xE5184E11FEB5CE66LL /* 362 */, 0x618BDB80BD736621LL /* 363 */, 217 | 0x7D29BAD68B574D0BLL /* 364 */, 0x81BB613E25E6FE5BLL /* 365 */, 218 | 0x071C9C10BC07913FLL /* 366 */, 0xC7BEEB7909AC2D97LL /* 367 */, 219 | 0xC3E58D353BC5D757LL /* 368 */, 0xEB017892F38F61E8LL /* 369 */, 220 | 0xD4EFFB9C9B1CC21ALL /* 370 */, 0x99727D26F494F7ABLL /* 371 */, 221 | 0xA3E063A2956B3E03LL /* 372 */, 0x9D4A8B9A4AA09C30LL /* 373 */, 222 | 0x3F6AB7D500090FB4LL /* 374 */, 0x9CC0F2A057268AC0LL /* 375 */, 223 | 0x3DEE9D2DEDBF42D1LL /* 376 */, 0x330F49C87960A972LL /* 377 */, 224 | 0xC6B2720287421B41LL /* 378 */, 0x0AC59EC07C00369CLL /* 379 */, 225 | 0xEF4EAC49CB353425LL /* 380 */, 0xF450244EEF0129D8LL /* 381 */, 226 | 0x8ACC46E5CAF4DEB6LL /* 382 */, 0x2FFEAB63989263F7LL /* 383 */, 227 | 0x8F7CB9FE5D7A4578LL /* 384 */, 0x5BD8F7644E634635LL /* 385 */, 228 | 0x427A7315BF2DC900LL /* 386 */, 0x17D0C4AA2125261CLL /* 387 */, 229 | 0x3992486C93518E50LL /* 388 */, 0xB4CBFEE0A2D7D4C3LL /* 389 */, 230 | 0x7C75D6202C5DDD8DLL /* 390 */, 0xDBC295D8E35B6C61LL /* 391 */, 231 | 0x60B369D302032B19LL /* 392 */, 0xCE42685FDCE44132LL /* 393 */, 232 | 0x06F3DDB9DDF65610LL /* 394 */, 0x8EA4D21DB5E148F0LL /* 395 */, 233 | 0x20B0FCE62FCD496FLL /* 396 */, 0x2C1B912358B0EE31LL /* 397 */, 234 | 0xB28317B818F5A308LL /* 398 */, 0xA89C1E189CA6D2CFLL /* 399 */, 235 | 0x0C6B18576AAADBC8LL /* 400 */, 0xB65DEAA91299FAE3LL /* 401 */, 236 | 0xFB2B794B7F1027E7LL /* 402 */, 0x04E4317F443B5BEBLL /* 403 */, 237 | 0x4B852D325939D0A6LL /* 404 */, 0xD5AE6BEEFB207FFCLL /* 405 */, 238 | 0x309682B281C7D374LL /* 406 */, 0xBAE309A194C3B475LL /* 407 */, 239 | 0x8CC3F97B13B49F05LL /* 408 */, 0x98A9422FF8293967LL /* 409 */, 240 | 0x244B16B01076FF7CLL /* 410 */, 0xF8BF571C663D67EELL /* 411 */, 241 | 0x1F0D6758EEE30DA1LL /* 412 */, 0xC9B611D97ADEB9B7LL /* 413 */, 242 | 0xB7AFD5887B6C57A2LL /* 414 */, 0x6290AE846B984FE1LL /* 415 */, 243 | 0x94DF4CDEACC1A5FDLL /* 416 */, 0x058A5BD1C5483AFFLL /* 417 */, 244 | 0x63166CC142BA3C37LL /* 418 */, 0x8DB8526EB2F76F40LL /* 419 */, 245 | 0xE10880036F0D6D4ELL /* 420 */, 0x9E0523C9971D311DLL /* 421 */, 246 | 0x45EC2824CC7CD691LL /* 422 */, 0x575B8359E62382C9LL /* 423 */, 247 | 0xFA9E400DC4889995LL /* 424 */, 0xD1823ECB45721568LL /* 425 */, 248 | 0xDAFD983B8206082FLL /* 426 */, 0xAA7D29082386A8CBLL /* 427 */, 249 | 0x269FCD4403B87588LL /* 428 */, 0x1B91F5F728BDD1E0LL /* 429 */, 250 | 0xE4669F39040201F6LL /* 430 */, 0x7A1D7C218CF04ADELL /* 431 */, 251 | 0x65623C29D79CE5CELL /* 432 */, 0x2368449096C00BB1LL /* 433 */, 252 | 0xAB9BF1879DA503BALL /* 434 */, 0xBC23ECB1A458058ELL /* 435 */, 253 | 0x9A58DF01BB401ECCLL /* 436 */, 0xA070E868A85F143DLL /* 437 */, 254 | 0x4FF188307DF2239ELL /* 438 */, 0x14D565B41A641183LL /* 439 */, 255 | 0xEE13337452701602LL /* 440 */, 0x950E3DCF3F285E09LL /* 441 */, 256 | 0x59930254B9C80953LL /* 442 */, 0x3BF299408930DA6DLL /* 443 */, 257 | 0xA955943F53691387LL /* 444 */, 0xA15EDECAA9CB8784LL /* 445 */, 258 | 0x29142127352BE9A0LL /* 446 */, 0x76F0371FFF4E7AFBLL /* 447 */, 259 | 0x0239F450274F2228LL /* 448 */, 0xBB073AF01D5E868BLL /* 449 */, 260 | 0xBFC80571C10E96C1LL /* 450 */, 0xD267088568222E23LL /* 451 */, 261 | 0x9671A3D48E80B5B0LL /* 452 */, 0x55B5D38AE193BB81LL /* 453 */, 262 | 0x693AE2D0A18B04B8LL /* 454 */, 0x5C48B4ECADD5335FLL /* 455 */, 263 | 0xFD743B194916A1CALL /* 456 */, 0x2577018134BE98C4LL /* 457 */, 264 | 0xE77987E83C54A4ADLL /* 458 */, 0x28E11014DA33E1B9LL /* 459 */, 265 | 0x270CC59E226AA213LL /* 460 */, 0x71495F756D1A5F60LL /* 461 */, 266 | 0x9BE853FB60AFEF77LL /* 462 */, 0xADC786A7F7443DBFLL /* 463 */, 267 | 0x0904456173B29A82LL /* 464 */, 0x58BC7A66C232BD5ELL /* 465 */, 268 | 0xF306558C673AC8B2LL /* 466 */, 0x41F639C6B6C9772ALL /* 467 */, 269 | 0x216DEFE99FDA35DALL /* 468 */, 0x11640CC71C7BE615LL /* 469 */, 270 | 0x93C43694565C5527LL /* 470 */, 0xEA038E6246777839LL /* 471 */, 271 | 0xF9ABF3CE5A3E2469LL /* 472 */, 0x741E768D0FD312D2LL /* 473 */, 272 | 0x0144B883CED652C6LL /* 474 */, 0xC20B5A5BA33F8552LL /* 475 */, 273 | 0x1AE69633C3435A9DLL /* 476 */, 0x97A28CA4088CFDECLL /* 477 */, 274 | 0x8824A43C1E96F420LL /* 478 */, 0x37612FA66EEEA746LL /* 479 */, 275 | 0x6B4CB165F9CF0E5ALL /* 480 */, 0x43AA1C06A0ABFB4ALL /* 481 */, 276 | 0x7F4DC26FF162796BLL /* 482 */, 0x6CBACC8E54ED9B0FLL /* 483 */, 277 | 0xA6B7FFEFD2BB253ELL /* 484 */, 0x2E25BC95B0A29D4FLL /* 485 */, 278 | 0x86D6A58BDEF1388CLL /* 486 */, 0xDED74AC576B6F054LL /* 487 */, 279 | 0x8030BDBC2B45805DLL /* 488 */, 0x3C81AF70E94D9289LL /* 489 */, 280 | 0x3EFF6DDA9E3100DBLL /* 490 */, 0xB38DC39FDFCC8847LL /* 491 */, 281 | 0x123885528D17B87ELL /* 492 */, 0xF2DA0ED240B1B642LL /* 493 */, 282 | 0x44CEFADCD54BF9A9LL /* 494 */, 0x1312200E433C7EE6LL /* 495 */, 283 | 0x9FFCC84F3A78C748LL /* 496 */, 0xF0CD1F72248576BBLL /* 497 */, 284 | 0xEC6974053638CFE4LL /* 498 */, 0x2BA7B67C0CEC4E4CLL /* 499 */, 285 | 0xAC2F4DF3E5CE32EDLL /* 500 */, 0xCB33D14326EA4C11LL /* 501 */, 286 | 0xA4E9044CC77E58BCLL /* 502 */, 0x5F513293D934FCEFLL /* 503 */, 287 | 0x5DC9645506E55444LL /* 504 */, 0x50DE418F317DE40ALL /* 505 */, 288 | 0x388CB31A69DDE259LL /* 506 */, 0x2DB4A83455820A86LL /* 507 */, 289 | 0x9010A91E84711AE9LL /* 508 */, 0x4DF7F0B7B1498371LL /* 509 */, 290 | 0xD62A2EABC0977179LL /* 510 */, 0x22FAC097AA8D5C0ELL /* 511 */, 291 | 0xF49FCC2FF1DAF39BLL /* 512 */, 0x487FD5C66FF29281LL /* 513 */, 292 | 0xE8A30667FCDCA83FLL /* 514 */, 0x2C9B4BE3D2FCCE63LL /* 515 */, 293 | 0xDA3FF74B93FBBBC2LL /* 516 */, 0x2FA165D2FE70BA66LL /* 517 */, 294 | 0xA103E279970E93D4LL /* 518 */, 0xBECDEC77B0E45E71LL /* 519 */, 295 | 0xCFB41E723985E497LL /* 520 */, 0xB70AAA025EF75017LL /* 521 */, 296 | 0xD42309F03840B8E0LL /* 522 */, 0x8EFC1AD035898579LL /* 523 */, 297 | 0x96C6920BE2B2ABC5LL /* 524 */, 0x66AF4163375A9172LL /* 525 */, 298 | 0x2174ABDCCA7127FBLL /* 526 */, 0xB33CCEA64A72FF41LL /* 527 */, 299 | 0xF04A4933083066A5LL /* 528 */, 0x8D970ACDD7289AF5LL /* 529 */, 300 | 0x8F96E8E031C8C25ELL /* 530 */, 0xF3FEC02276875D47LL /* 531 */, 301 | 0xEC7BF310056190DDLL /* 532 */, 0xF5ADB0AEBB0F1491LL /* 533 */, 302 | 0x9B50F8850FD58892LL /* 534 */, 0x4975488358B74DE8LL /* 535 */, 303 | 0xA3354FF691531C61LL /* 536 */, 0x0702BBE481D2C6EELL /* 537 */, 304 | 0x89FB24057DEDED98LL /* 538 */, 0xAC3075138596E902LL /* 539 */, 305 | 0x1D2D3580172772EDLL /* 540 */, 0xEB738FC28E6BC30DLL /* 541 */, 306 | 0x5854EF8F63044326LL /* 542 */, 0x9E5C52325ADD3BBELL /* 543 */, 307 | 0x90AA53CF325C4623LL /* 544 */, 0xC1D24D51349DD067LL /* 545 */, 308 | 0x2051CFEEA69EA624LL /* 546 */, 0x13220F0A862E7E4FLL /* 547 */, 309 | 0xCE39399404E04864LL /* 548 */, 0xD9C42CA47086FCB7LL /* 549 */, 310 | 0x685AD2238A03E7CCLL /* 550 */, 0x066484B2AB2FF1DBLL /* 551 */, 311 | 0xFE9D5D70EFBF79ECLL /* 552 */, 0x5B13B9DD9C481854LL /* 553 */, 312 | 0x15F0D475ED1509ADLL /* 554 */, 0x0BEBCD060EC79851LL /* 555 */, 313 | 0xD58C6791183AB7F8LL /* 556 */, 0xD1187C5052F3EEE4LL /* 557 */, 314 | 0xC95D1192E54E82FFLL /* 558 */, 0x86EEA14CB9AC6CA2LL /* 559 */, 315 | 0x3485BEB153677D5DLL /* 560 */, 0xDD191D781F8C492ALL /* 561 */, 316 | 0xF60866BAA784EBF9LL /* 562 */, 0x518F643BA2D08C74LL /* 563 */, 317 | 0x8852E956E1087C22LL /* 564 */, 0xA768CB8DC410AE8DLL /* 565 */, 318 | 0x38047726BFEC8E1ALL /* 566 */, 0xA67738B4CD3B45AALL /* 567 */, 319 | 0xAD16691CEC0DDE19LL /* 568 */, 0xC6D4319380462E07LL /* 569 */, 320 | 0xC5A5876D0BA61938LL /* 570 */, 0x16B9FA1FA58FD840LL /* 571 */, 321 | 0x188AB1173CA74F18LL /* 572 */, 0xABDA2F98C99C021FLL /* 573 */, 322 | 0x3E0580AB134AE816LL /* 574 */, 0x5F3B05B773645ABBLL /* 575 */, 323 | 0x2501A2BE5575F2F6LL /* 576 */, 0x1B2F74004E7E8BA9LL /* 577 */, 324 | 0x1CD7580371E8D953LL /* 578 */, 0x7F6ED89562764E30LL /* 579 */, 325 | 0xB15926FF596F003DLL /* 580 */, 0x9F65293DA8C5D6B9LL /* 581 */, 326 | 0x6ECEF04DD690F84CLL /* 582 */, 0x4782275FFF33AF88LL /* 583 */, 327 | 0xE41433083F820801LL /* 584 */, 0xFD0DFE409A1AF9B5LL /* 585 */, 328 | 0x4325A3342CDB396BLL /* 586 */, 0x8AE77E62B301B252LL /* 587 */, 329 | 0xC36F9E9F6655615ALL /* 588 */, 0x85455A2D92D32C09LL /* 589 */, 330 | 0xF2C7DEA949477485LL /* 590 */, 0x63CFB4C133A39EBALL /* 591 */, 331 | 0x83B040CC6EBC5462LL /* 592 */, 0x3B9454C8FDB326B0LL /* 593 */, 332 | 0x56F56A9E87FFD78CLL /* 594 */, 0x2DC2940D99F42BC6LL /* 595 */, 333 | 0x98F7DF096B096E2DLL /* 596 */, 0x19A6E01E3AD852BFLL /* 597 */, 334 | 0x42A99CCBDBD4B40BLL /* 598 */, 0xA59998AF45E9C559LL /* 599 */, 335 | 0x366295E807D93186LL /* 600 */, 0x6B48181BFAA1F773LL /* 601 */, 336 | 0x1FEC57E2157A0A1DLL /* 602 */, 0x4667446AF6201AD5LL /* 603 */, 337 | 0xE615EBCACFB0F075LL /* 604 */, 0xB8F31F4F68290778LL /* 605 */, 338 | 0x22713ED6CE22D11ELL /* 606 */, 0x3057C1A72EC3C93BLL /* 607 */, 339 | 0xCB46ACC37C3F1F2FLL /* 608 */, 0xDBB893FD02AAF50ELL /* 609 */, 340 | 0x331FD92E600B9FCFLL /* 610 */, 0xA498F96148EA3AD6LL /* 611 */, 341 | 0xA8D8426E8B6A83EALL /* 612 */, 0xA089B274B7735CDCLL /* 613 */, 342 | 0x87F6B3731E524A11LL /* 614 */, 0x118808E5CBC96749LL /* 615 */, 343 | 0x9906E4C7B19BD394LL /* 616 */, 0xAFED7F7E9B24A20CLL /* 617 */, 344 | 0x6509EADEEB3644A7LL /* 618 */, 0x6C1EF1D3E8EF0EDELL /* 619 */, 345 | 0xB9C97D43E9798FB4LL /* 620 */, 0xA2F2D784740C28A3LL /* 621 */, 346 | 0x7B8496476197566FLL /* 622 */, 0x7A5BE3E6B65F069DLL /* 623 */, 347 | 0xF96330ED78BE6F10LL /* 624 */, 0xEEE60DE77A076A15LL /* 625 */, 348 | 0x2B4BEE4AA08B9BD0LL /* 626 */, 0x6A56A63EC7B8894ELL /* 627 */, 349 | 0x02121359BA34FEF4LL /* 628 */, 0x4CBF99F8283703FCLL /* 629 */, 350 | 0x398071350CAF30C8LL /* 630 */, 0xD0A77A89F017687ALL /* 631 */, 351 | 0xF1C1A9EB9E423569LL /* 632 */, 0x8C7976282DEE8199LL /* 633 */, 352 | 0x5D1737A5DD1F7ABDLL /* 634 */, 0x4F53433C09A9FA80LL /* 635 */, 353 | 0xFA8B0C53DF7CA1D9LL /* 636 */, 0x3FD9DCBC886CCB77LL /* 637 */, 354 | 0xC040917CA91B4720LL /* 638 */, 0x7DD00142F9D1DCDFLL /* 639 */, 355 | 0x8476FC1D4F387B58LL /* 640 */, 0x23F8E7C5F3316503LL /* 641 */, 356 | 0x032A2244E7E37339LL /* 642 */, 0x5C87A5D750F5A74BLL /* 643 */, 357 | 0x082B4CC43698992ELL /* 644 */, 0xDF917BECB858F63CLL /* 645 */, 358 | 0x3270B8FC5BF86DDALL /* 646 */, 0x10AE72BB29B5DD76LL /* 647 */, 359 | 0x576AC94E7700362BLL /* 648 */, 0x1AD112DAC61EFB8FLL /* 649 */, 360 | 0x691BC30EC5FAA427LL /* 650 */, 0xFF246311CC327143LL /* 651 */, 361 | 0x3142368E30E53206LL /* 652 */, 0x71380E31E02CA396LL /* 653 */, 362 | 0x958D5C960AAD76F1LL /* 654 */, 0xF8D6F430C16DA536LL /* 655 */, 363 | 0xC8FFD13F1BE7E1D2LL /* 656 */, 0x7578AE66004DDBE1LL /* 657 */, 364 | 0x05833F01067BE646LL /* 658 */, 0xBB34B5AD3BFE586DLL /* 659 */, 365 | 0x095F34C9A12B97F0LL /* 660 */, 0x247AB64525D60CA8LL /* 661 */, 366 | 0xDCDBC6F3017477D1LL /* 662 */, 0x4A2E14D4DECAD24DLL /* 663 */, 367 | 0xBDB5E6D9BE0A1EEBLL /* 664 */, 0x2A7E70F7794301ABLL /* 665 */, 368 | 0xDEF42D8A270540FDLL /* 666 */, 0x01078EC0A34C22C1LL /* 667 */, 369 | 0xE5DE511AF4C16387LL /* 668 */, 0x7EBB3A52BD9A330ALL /* 669 */, 370 | 0x77697857AA7D6435LL /* 670 */, 0x004E831603AE4C32LL /* 671 */, 371 | 0xE7A21020AD78E312LL /* 672 */, 0x9D41A70C6AB420F2LL /* 673 */, 372 | 0x28E06C18EA1141E6LL /* 674 */, 0xD2B28CBD984F6B28LL /* 675 */, 373 | 0x26B75F6C446E9D83LL /* 676 */, 0xBA47568C4D418D7FLL /* 677 */, 374 | 0xD80BADBFE6183D8ELL /* 678 */, 0x0E206D7F5F166044LL /* 679 */, 375 | 0xE258A43911CBCA3ELL /* 680 */, 0x723A1746B21DC0BCLL /* 681 */, 376 | 0xC7CAA854F5D7CDD3LL /* 682 */, 0x7CAC32883D261D9CLL /* 683 */, 377 | 0x7690C26423BA942CLL /* 684 */, 0x17E55524478042B8LL /* 685 */, 378 | 0xE0BE477656A2389FLL /* 686 */, 0x4D289B5E67AB2DA0LL /* 687 */, 379 | 0x44862B9C8FBBFD31LL /* 688 */, 0xB47CC8049D141365LL /* 689 */, 380 | 0x822C1B362B91C793LL /* 690 */, 0x4EB14655FB13DFD8LL /* 691 */, 381 | 0x1ECBBA0714E2A97BLL /* 692 */, 0x6143459D5CDE5F14LL /* 693 */, 382 | 0x53A8FBF1D5F0AC89LL /* 694 */, 0x97EA04D81C5E5B00LL /* 695 */, 383 | 0x622181A8D4FDB3F3LL /* 696 */, 0xE9BCD341572A1208LL /* 697 */, 384 | 0x1411258643CCE58ALL /* 698 */, 0x9144C5FEA4C6E0A4LL /* 699 */, 385 | 0x0D33D06565CF620FLL /* 700 */, 0x54A48D489F219CA1LL /* 701 */, 386 | 0xC43E5EAC6D63C821LL /* 702 */, 0xA9728B3A72770DAFLL /* 703 */, 387 | 0xD7934E7B20DF87EFLL /* 704 */, 0xE35503B61A3E86E5LL /* 705 */, 388 | 0xCAE321FBC819D504LL /* 706 */, 0x129A50B3AC60BFA6LL /* 707 */, 389 | 0xCD5E68EA7E9FB6C3LL /* 708 */, 0xB01C90199483B1C7LL /* 709 */, 390 | 0x3DE93CD5C295376CLL /* 710 */, 0xAED52EDF2AB9AD13LL /* 711 */, 391 | 0x2E60F512C0A07884LL /* 712 */, 0xBC3D86A3E36210C9LL /* 713 */, 392 | 0x35269D9B163951CELL /* 714 */, 0x0C7D6E2AD0CDB5FALL /* 715 */, 393 | 0x59E86297D87F5733LL /* 716 */, 0x298EF221898DB0E7LL /* 717 */, 394 | 0x55000029D1A5AA7ELL /* 718 */, 0x8BC08AE1B5061B45LL /* 719 */, 395 | 0xC2C31C2B6C92703ALL /* 720 */, 0x94CC596BAF25EF42LL /* 721 */, 396 | 0x0A1D73DB22540456LL /* 722 */, 0x04B6A0F9D9C4179ALL /* 723 */, 397 | 0xEFFDAFA2AE3D3C60LL /* 724 */, 0xF7C8075BB49496C4LL /* 725 */, 398 | 0x9CC5C7141D1CD4E3LL /* 726 */, 0x78BD1638218E5534LL /* 727 */, 399 | 0xB2F11568F850246ALL /* 728 */, 0xEDFABCFA9502BC29LL /* 729 */, 400 | 0x796CE5F2DA23051BLL /* 730 */, 0xAAE128B0DC93537CLL /* 731 */, 401 | 0x3A493DA0EE4B29AELL /* 732 */, 0xB5DF6B2C416895D7LL /* 733 */, 402 | 0xFCABBD25122D7F37LL /* 734 */, 0x70810B58105DC4B1LL /* 735 */, 403 | 0xE10FDD37F7882A90LL /* 736 */, 0x524DCAB5518A3F5CLL /* 737 */, 404 | 0x3C9E85878451255BLL /* 738 */, 0x4029828119BD34E2LL /* 739 */, 405 | 0x74A05B6F5D3CECCBLL /* 740 */, 0xB610021542E13ECALL /* 741 */, 406 | 0x0FF979D12F59E2ACLL /* 742 */, 0x6037DA27E4F9CC50LL /* 743 */, 407 | 0x5E92975A0DF1847DLL /* 744 */, 0xD66DE190D3E623FELL /* 745 */, 408 | 0x5032D6B87B568048LL /* 746 */, 0x9A36B7CE8235216ELL /* 747 */, 409 | 0x80272A7A24F64B4ALL /* 748 */, 0x93EFED8B8C6916F7LL /* 749 */, 410 | 0x37DDBFF44CCE1555LL /* 750 */, 0x4B95DB5D4B99BD25LL /* 751 */, 411 | 0x92D3FDA169812FC0LL /* 752 */, 0xFB1A4A9A90660BB6LL /* 753 */, 412 | 0x730C196946A4B9B2LL /* 754 */, 0x81E289AA7F49DA68LL /* 755 */, 413 | 0x64669A0F83B1A05FLL /* 756 */, 0x27B3FF7D9644F48BLL /* 757 */, 414 | 0xCC6B615C8DB675B3LL /* 758 */, 0x674F20B9BCEBBE95LL /* 759 */, 415 | 0x6F31238275655982LL /* 760 */, 0x5AE488713E45CF05LL /* 761 */, 416 | 0xBF619F9954C21157LL /* 762 */, 0xEABAC46040A8EAE9LL /* 763 */, 417 | 0x454C6FE9F2C0C1CDLL /* 764 */, 0x419CF6496412691CLL /* 765 */, 418 | 0xD3DC3BEF265B0F70LL /* 766 */, 0x6D0E60F5C3578A9ELL /* 767 */, 419 | 0x5B0E608526323C55LL /* 768 */, 0x1A46C1A9FA1B59F5LL /* 769 */, 420 | 0xA9E245A17C4C8FFALL /* 770 */, 0x65CA5159DB2955D7LL /* 771 */, 421 | 0x05DB0A76CE35AFC2LL /* 772 */, 0x81EAC77EA9113D45LL /* 773 */, 422 | 0x528EF88AB6AC0A0DLL /* 774 */, 0xA09EA253597BE3FFLL /* 775 */, 423 | 0x430DDFB3AC48CD56LL /* 776 */, 0xC4B3A67AF45CE46FLL /* 777 */, 424 | 0x4ECECFD8FBE2D05ELL /* 778 */, 0x3EF56F10B39935F0LL /* 779 */, 425 | 0x0B22D6829CD619C6LL /* 780 */, 0x17FD460A74DF2069LL /* 781 */, 426 | 0x6CF8CC8E8510ED40LL /* 782 */, 0xD6C824BF3A6ECAA7LL /* 783 */, 427 | 0x61243D581A817049LL /* 784 */, 0x048BACB6BBC163A2LL /* 785 */, 428 | 0xD9A38AC27D44CC32LL /* 786 */, 0x7FDDFF5BAAF410ABLL /* 787 */, 429 | 0xAD6D495AA804824BLL /* 788 */, 0xE1A6A74F2D8C9F94LL /* 789 */, 430 | 0xD4F7851235DEE8E3LL /* 790 */, 0xFD4B7F886540D893LL /* 791 */, 431 | 0x247C20042AA4BFDALL /* 792 */, 0x096EA1C517D1327CLL /* 793 */, 432 | 0xD56966B4361A6685LL /* 794 */, 0x277DA5C31221057DLL /* 795 */, 433 | 0x94D59893A43ACFF7LL /* 796 */, 0x64F0C51CCDC02281LL /* 797 */, 434 | 0x3D33BCC4FF6189DBLL /* 798 */, 0xE005CB184CE66AF1LL /* 799 */, 435 | 0xFF5CCD1D1DB99BEALL /* 800 */, 0xB0B854A7FE42980FLL /* 801 */, 436 | 0x7BD46A6A718D4B9FLL /* 802 */, 0xD10FA8CC22A5FD8CLL /* 803 */, 437 | 0xD31484952BE4BD31LL /* 804 */, 0xC7FA975FCB243847LL /* 805 */, 438 | 0x4886ED1E5846C407LL /* 806 */, 0x28CDDB791EB70B04LL /* 807 */, 439 | 0xC2B00BE2F573417FLL /* 808 */, 0x5C9590452180F877LL /* 809 */, 440 | 0x7A6BDDFFF370EB00LL /* 810 */, 0xCE509E38D6D9D6A4LL /* 811 */, 441 | 0xEBEB0F00647FA702LL /* 812 */, 0x1DCC06CF76606F06LL /* 813 */, 442 | 0xE4D9F28BA286FF0ALL /* 814 */, 0xD85A305DC918C262LL /* 815 */, 443 | 0x475B1D8732225F54LL /* 816 */, 0x2D4FB51668CCB5FELL /* 817 */, 444 | 0xA679B9D9D72BBA20LL /* 818 */, 0x53841C0D912D43A5LL /* 819 */, 445 | 0x3B7EAA48BF12A4E8LL /* 820 */, 0x781E0E47F22F1DDFLL /* 821 */, 446 | 0xEFF20CE60AB50973LL /* 822 */, 0x20D261D19DFFB742LL /* 823 */, 447 | 0x16A12B03062A2E39LL /* 824 */, 0x1960EB2239650495LL /* 825 */, 448 | 0x251C16FED50EB8B8LL /* 826 */, 0x9AC0C330F826016ELL /* 827 */, 449 | 0xED152665953E7671LL /* 828 */, 0x02D63194A6369570LL /* 829 */, 450 | 0x5074F08394B1C987LL /* 830 */, 0x70BA598C90B25CE1LL /* 831 */, 451 | 0x794A15810B9742F6LL /* 832 */, 0x0D5925E9FCAF8C6CLL /* 833 */, 452 | 0x3067716CD868744ELL /* 834 */, 0x910AB077E8D7731BLL /* 835 */, 453 | 0x6A61BBDB5AC42F61LL /* 836 */, 0x93513EFBF0851567LL /* 837 */, 454 | 0xF494724B9E83E9D5LL /* 838 */, 0xE887E1985C09648DLL /* 839 */, 455 | 0x34B1D3C675370CFDLL /* 840 */, 0xDC35E433BC0D255DLL /* 841 */, 456 | 0xD0AAB84234131BE0LL /* 842 */, 0x08042A50B48B7EAFLL /* 843 */, 457 | 0x9997C4EE44A3AB35LL /* 844 */, 0x829A7B49201799D0LL /* 845 */, 458 | 0x263B8307B7C54441LL /* 846 */, 0x752F95F4FD6A6CA6LL /* 847 */, 459 | 0x927217402C08C6E5LL /* 848 */, 0x2A8AB754A795D9EELL /* 849 */, 460 | 0xA442F7552F72943DLL /* 850 */, 0x2C31334E19781208LL /* 851 */, 461 | 0x4FA98D7CEAEE6291LL /* 852 */, 0x55C3862F665DB309LL /* 853 */, 462 | 0xBD0610175D53B1F3LL /* 854 */, 0x46FE6CB840413F27LL /* 855 */, 463 | 0x3FE03792DF0CFA59LL /* 856 */, 0xCFE700372EB85E8FLL /* 857 */, 464 | 0xA7BE29E7ADBCE118LL /* 858 */, 0xE544EE5CDE8431DDLL /* 859 */, 465 | 0x8A781B1B41F1873ELL /* 860 */, 0xA5C94C78A0D2F0E7LL /* 861 */, 466 | 0x39412E2877B60728LL /* 862 */, 0xA1265EF3AFC9A62CLL /* 863 */, 467 | 0xBCC2770C6A2506C5LL /* 864 */, 0x3AB66DD5DCE1CE12LL /* 865 */, 468 | 0xE65499D04A675B37LL /* 866 */, 0x7D8F523481BFD216LL /* 867 */, 469 | 0x0F6F64FCEC15F389LL /* 868 */, 0x74EFBE618B5B13C8LL /* 869 */, 470 | 0xACDC82B714273E1DLL /* 870 */, 0xDD40BFE003199D17LL /* 871 */, 471 | 0x37E99257E7E061F8LL /* 872 */, 0xFA52626904775AAALL /* 873 */, 472 | 0x8BBBF63A463D56F9LL /* 874 */, 0xF0013F1543A26E64LL /* 875 */, 473 | 0xA8307E9F879EC898LL /* 876 */, 0xCC4C27A4150177CCLL /* 877 */, 474 | 0x1B432F2CCA1D3348LL /* 878 */, 0xDE1D1F8F9F6FA013LL /* 879 */, 475 | 0x606602A047A7DDD6LL /* 880 */, 0xD237AB64CC1CB2C7LL /* 881 */, 476 | 0x9B938E7225FCD1D3LL /* 882 */, 0xEC4E03708E0FF476LL /* 883 */, 477 | 0xFEB2FBDA3D03C12DLL /* 884 */, 0xAE0BCED2EE43889ALL /* 885 */, 478 | 0x22CB8923EBFB4F43LL /* 886 */, 0x69360D013CF7396DLL /* 887 */, 479 | 0x855E3602D2D4E022LL /* 888 */, 0x073805BAD01F784CLL /* 889 */, 480 | 0x33E17A133852F546LL /* 890 */, 0xDF4874058AC7B638LL /* 891 */, 481 | 0xBA92B29C678AA14ALL /* 892 */, 0x0CE89FC76CFAADCDLL /* 893 */, 482 | 0x5F9D4E0908339E34LL /* 894 */, 0xF1AFE9291F5923B9LL /* 895 */, 483 | 0x6E3480F60F4A265FLL /* 896 */, 0xEEBF3A2AB29B841CLL /* 897 */, 484 | 0xE21938A88F91B4ADLL /* 898 */, 0x57DFEFF845C6D3C3LL /* 899 */, 485 | 0x2F006B0BF62CAAF2LL /* 900 */, 0x62F479EF6F75EE78LL /* 901 */, 486 | 0x11A55AD41C8916A9LL /* 902 */, 0xF229D29084FED453LL /* 903 */, 487 | 0x42F1C27B16B000E6LL /* 904 */, 0x2B1F76749823C074LL /* 905 */, 488 | 0x4B76ECA3C2745360LL /* 906 */, 0x8C98F463B91691BDLL /* 907 */, 489 | 0x14BCC93CF1ADE66ALL /* 908 */, 0x8885213E6D458397LL /* 909 */, 490 | 0x8E177DF0274D4711LL /* 910 */, 0xB49B73B5503F2951LL /* 911 */, 491 | 0x10168168C3F96B6BLL /* 912 */, 0x0E3D963B63CAB0AELL /* 913 */, 492 | 0x8DFC4B5655A1DB14LL /* 914 */, 0xF789F1356E14DE5CLL /* 915 */, 493 | 0x683E68AF4E51DAC1LL /* 916 */, 0xC9A84F9D8D4B0FD9LL /* 917 */, 494 | 0x3691E03F52A0F9D1LL /* 918 */, 0x5ED86E46E1878E80LL /* 919 */, 495 | 0x3C711A0E99D07150LL /* 920 */, 0x5A0865B20C4E9310LL /* 921 */, 496 | 0x56FBFC1FE4F0682ELL /* 922 */, 0xEA8D5DE3105EDF9BLL /* 923 */, 497 | 0x71ABFDB12379187ALL /* 924 */, 0x2EB99DE1BEE77B9CLL /* 925 */, 498 | 0x21ECC0EA33CF4523LL /* 926 */, 0x59A4D7521805C7A1LL /* 927 */, 499 | 0x3896F5EB56AE7C72LL /* 928 */, 0xAA638F3DB18F75DCLL /* 929 */, 500 | 0x9F39358DABE9808ELL /* 930 */, 0xB7DEFA91C00B72ACLL /* 931 */, 501 | 0x6B5541FD62492D92LL /* 932 */, 0x6DC6DEE8F92E4D5BLL /* 933 */, 502 | 0x353F57ABC4BEEA7ELL /* 934 */, 0x735769D6DA5690CELL /* 935 */, 503 | 0x0A234AA642391484LL /* 936 */, 0xF6F9508028F80D9DLL /* 937 */, 504 | 0xB8E319A27AB3F215LL /* 938 */, 0x31AD9C1151341A4DLL /* 939 */, 505 | 0x773C22A57BEF5805LL /* 940 */, 0x45C7561A07968633LL /* 941 */, 506 | 0xF913DA9E249DBE36LL /* 942 */, 0xDA652D9B78A64C68LL /* 943 */, 507 | 0x4C27A97F3BC334EFLL /* 944 */, 0x76621220E66B17F4LL /* 945 */, 508 | 0x967743899ACD7D0BLL /* 946 */, 0xF3EE5BCAE0ED6782LL /* 947 */, 509 | 0x409F753600C879FCLL /* 948 */, 0x06D09A39B5926DB6LL /* 949 */, 510 | 0x6F83AEB0317AC588LL /* 950 */, 0x01E6CA4A86381F21LL /* 951 */, 511 | 0x66FF3462D19F3025LL /* 952 */, 0x72207C24DDFD3BFBLL /* 953 */, 512 | 0x4AF6B6D3E2ECE2EBLL /* 954 */, 0x9C994DBEC7EA08DELL /* 955 */, 513 | 0x49ACE597B09A8BC4LL /* 956 */, 0xB38C4766CF0797BALL /* 957 */, 514 | 0x131B9373C57C2A75LL /* 958 */, 0xB1822CCE61931E58LL /* 959 */, 515 | 0x9D7555B909BA1C0CLL /* 960 */, 0x127FAFDD937D11D2LL /* 961 */, 516 | 0x29DA3BADC66D92E4LL /* 962 */, 0xA2C1D57154C2ECBCLL /* 963 */, 517 | 0x58C5134D82F6FE24LL /* 964 */, 0x1C3AE3515B62274FLL /* 965 */, 518 | 0xE907C82E01CB8126LL /* 966 */, 0xF8ED091913E37FCBLL /* 967 */, 519 | 0x3249D8F9C80046C9LL /* 968 */, 0x80CF9BEDE388FB63LL /* 969 */, 520 | 0x1881539A116CF19ELL /* 970 */, 0x5103F3F76BD52457LL /* 971 */, 521 | 0x15B7E6F5AE47F7A8LL /* 972 */, 0xDBD7C6DED47E9CCFLL /* 973 */, 522 | 0x44E55C410228BB1ALL /* 974 */, 0xB647D4255EDB4E99LL /* 975 */, 523 | 0x5D11882BB8AAFC30LL /* 976 */, 0xF5098BBB29D3212ALL /* 977 */, 524 | 0x8FB5EA14E90296B3LL /* 978 */, 0x677B942157DD025ALL /* 979 */, 525 | 0xFB58E7C0A390ACB5LL /* 980 */, 0x89D3674C83BD4A01LL /* 981 */, 526 | 0x9E2DA4DF4BF3B93BLL /* 982 */, 0xFCC41E328CAB4829LL /* 983 */, 527 | 0x03F38C96BA582C52LL /* 984 */, 0xCAD1BDBD7FD85DB2LL /* 985 */, 528 | 0xBBB442C16082AE83LL /* 986 */, 0xB95FE86BA5DA9AB0LL /* 987 */, 529 | 0xB22E04673771A93FLL /* 988 */, 0x845358C9493152D8LL /* 989 */, 530 | 0xBE2A488697B4541ELL /* 990 */, 0x95A2DC2DD38E6966LL /* 991 */, 531 | 0xC02C11AC923C852BLL /* 992 */, 0x2388B1990DF2A87BLL /* 993 */, 532 | 0x7C8008FA1B4F37BELL /* 994 */, 0x1F70D0C84D54E503LL /* 995 */, 533 | 0x5490ADEC7ECE57D4LL /* 996 */, 0x002B3C27D9063A3ALL /* 997 */, 534 | 0x7EAEA3848030A2BFLL /* 998 */, 0xC602326DED2003C0LL /* 999 */, 535 | 0x83A7287D69A94086LL /* 1000 */, 0xC57A5FCB30F57A8ALL /* 1001 */, 536 | 0xB56844E479EBE779LL /* 1002 */, 0xA373B40F05DCBCE9LL /* 1003 */, 537 | 0xD71A786E88570EE2LL /* 1004 */, 0x879CBACDBDE8F6A0LL /* 1005 */, 538 | 0x976AD1BCC164A32FLL /* 1006 */, 0xAB21E25E9666D78BLL /* 1007 */, 539 | 0x901063AAE5E5C33CLL /* 1008 */, 0x9818B34448698D90LL /* 1009 */, 540 | 0xE36487AE3E1E8ABBLL /* 1010 */, 0xAFBDF931893BDCB4LL /* 1011 */, 541 | 0x6345A0DC5FBBD519LL /* 1012 */, 0x8628FE269B9465CALL /* 1013 */, 542 | 0x1E5D01603F9C51ECLL /* 1014 */, 0x4DE44006A15049B7LL /* 1015 */, 543 | 0xBF6C70E5F776CBB1LL /* 1016 */, 0x411218F2EF552BEDLL /* 1017 */, 544 | 0xCB0C0708705A36A3LL /* 1018 */, 0xE74D14754F986044LL /* 1019 */, 545 | 0xCD56D9430EA8280ELL /* 1020 */, 0xC12591D7535F5065LL /* 1021 */, 546 | 0xC83223F1720AEF96LL /* 1022 */, 0xC3A0396F7363A51FLL /* 1023 */ }; 547 | 548 | #define t1 (table) 549 | #define t2 (table+256) 550 | #define t3 (table+256*2) 551 | #define t4 (table+256*3) 552 | 553 | #define save_abc \ 554 | aa = a; \ 555 | bb = b; \ 556 | cc = c; 557 | 558 | #ifdef OPTIMIZE_FOR_ALPHA 559 | /* This is the official definition of round */ 560 | #define round(a,b,c,x,mul) \ 561 | c ^= x; \ 562 | a -= t1[((c)>>(0*8))&0xFF] ^ t2[((c)>>(2*8))&0xFF] ^ \ 563 | t3[((c)>>(4*8))&0xFF] ^ t4[((c)>>(6*8))&0xFF] ; \ 564 | b += t4[((c)>>(1*8))&0xFF] ^ t3[((c)>>(3*8))&0xFF] ^ \ 565 | t2[((c)>>(5*8))&0xFF] ^ t1[((c)>>(7*8))&0xFF] ; \ 566 | b *= mul; 567 | #else 568 | /* This code works faster when compiled on 32-bit machines */ 569 | /* (but works slower on Alpha) */ 570 | #define round(a,b,c,x,mul) \ 571 | c ^= x; \ 572 | a -= t1[(byte)(c)] ^ \ 573 | t2[(byte)(((word32)(c))>>(2*8))] ^ \ 574 | t3[(byte)((c)>>(4*8))] ^ \ 575 | t4[(byte)(((word32)((c)>>(4*8)))>>(2*8))] ; \ 576 | b += t4[(byte)(((word32)(c))>>(1*8))] ^ \ 577 | t3[(byte)(((word32)(c))>>(3*8))] ^ \ 578 | t2[(byte)(((word32)((c)>>(4*8)))>>(1*8))] ^ \ 579 | t1[(byte)(((word32)((c)>>(4*8)))>>(3*8))]; \ 580 | b *= mul; 581 | #endif 582 | 583 | #define pass(a,b,c,mul) \ 584 | round(a,b,c,x0,mul) \ 585 | round(b,c,a,x1,mul) \ 586 | round(c,a,b,x2,mul) \ 587 | round(a,b,c,x3,mul) \ 588 | round(b,c,a,x4,mul) \ 589 | round(c,a,b,x5,mul) \ 590 | round(a,b,c,x6,mul) \ 591 | round(b,c,a,x7,mul) 592 | 593 | #define key_schedule \ 594 | x0 -= x7 ^ 0xA5A5A5A5A5A5A5A5LL; \ 595 | x1 ^= x0; \ 596 | x2 += x1; \ 597 | x3 -= x2 ^ ((~x1)<<19); \ 598 | x4 ^= x3; \ 599 | x5 += x4; \ 600 | x6 -= x5 ^ ((~x4)>>23); \ 601 | x7 ^= x6; \ 602 | x0 += x7; \ 603 | x1 -= x0 ^ ((~x7)<<19); \ 604 | x2 ^= x1; \ 605 | x3 += x2; \ 606 | x4 -= x3 ^ ((~x2)>>23); \ 607 | x5 ^= x4; \ 608 | x6 += x5; \ 609 | x7 -= x6 ^ 0x0123456789ABCDEFLL; 610 | 611 | #define feedforward \ 612 | a ^= aa; \ 613 | b -= bb; \ 614 | c += cc; 615 | 616 | #ifdef OPTIMIZE_FOR_ALPHA 617 | /* The loop is unrolled: works better on Alpha */ 618 | #define compress \ 619 | save_abc \ 620 | pass(a,b,c,5) \ 621 | key_schedule \ 622 | pass(c,a,b,7) \ 623 | key_schedule \ 624 | pass(b,c,a,9) \ 625 | for(pass_no=3; pass_no= 64; i -= 64) 678 | { 679 | #ifdef BIG_ENDIAN 680 | for (j = 0; j < 64; j++) 681 | temp[j ^ 7] = ((byte*)str)[j]; 682 | tiger_compress(((word64*)temp), res); 683 | #else 684 | tiger_compress(str, res); 685 | #endif 686 | str += 8; 687 | } 688 | 689 | #ifdef BIG_ENDIAN 690 | for (j = 0; j < i; j++) 691 | temp[j ^ 7] = ((byte*)str)[j]; 692 | 693 | temp[j ^ 7] = 0x01; 694 | j++; 695 | for (; j & 7; j++) 696 | temp[j ^ 7] = 0; 697 | #else 698 | for (j = 0; j < i; j++) 699 | temp[j] = ((byte*)str)[j]; 700 | 701 | temp[j++] = 0x01; 702 | for (; j & 7; j++) 703 | temp[j] = 0; 704 | #endif 705 | if (j > 56) 706 | { 707 | for (; j < 64; j++) 708 | temp[j] = 0; 709 | tiger_compress(((word64*)temp), res); 710 | j = 0; 711 | } 712 | 713 | for (; j < 56; j++) 714 | temp[j] = 0; 715 | ((word64*)(&(temp[56])))[0] = ((word64)length) << 3; 716 | tiger_compress(((word64*)temp), res); 717 | } 718 | 719 | namespace libpsutil 720 | { 721 | namespace cryptography 722 | { 723 | void tiger64(char* str, size_t length, uint64_t* res) 724 | { 725 | uint64_t tiger_hash[3]; 726 | tiger(str, length, tiger_hash); 727 | *res = tiger_hash[0]; 728 | } 729 | 730 | void tiger128(char* str, size_t length, uint64_t res[2]) 731 | { 732 | uint64_t tiger_hash[3]; 733 | tiger(str, length, tiger_hash); 734 | 735 | res[0] = tiger_hash[0]; 736 | res[1] = tiger_hash[1]; 737 | } 738 | 739 | void tiger192(char* str, size_t length, uint64_t res[3]) 740 | { 741 | tiger(str, length, res); 742 | } 743 | } 744 | } --------------------------------------------------------------------------------