From fd8543cdb1e32314ed9562d76b5acd304c5979ef Mon Sep 17 00:00:00 2001 From: Naville <403799106@qq.com> Date: Sat, 23 Jul 2016 14:48:18 +0800 Subject: [PATCH] Integrate Liberation as Dynamic Instruction Patcher --- .gitmodules | 6 +- BuildConfig.py | 7 +- DOCS/CODEOWNERS.md | 15 +- Hooks/Liberation.h | 197 ++++++++++++++++++++++++ Hooks/SharedDefine.pch | 1 - Hooks/keystone/arm.h | 23 --- Hooks/keystone/arm64.h | 23 --- Hooks/keystone/hexagon.h | 24 --- Hooks/keystone/keystone.h | 314 -------------------------------------- Hooks/keystone/mips.h | 23 --- Hooks/keystone/ppc.h | 24 --- Hooks/keystone/sparc.h | 24 --- Hooks/keystone/systemz.h | 24 --- Hooks/keystone/x86.h | 23 --- Liberation | 1 + Makefile | 18 +-- Setup.sh | 17 ++- VERSION | 2 +- build.py | 22 ++- keystone | 1 - 20 files changed, 251 insertions(+), 538 deletions(-) create mode 100644 Hooks/Liberation.h delete mode 100644 Hooks/keystone/arm.h delete mode 100644 Hooks/keystone/arm64.h delete mode 100644 Hooks/keystone/hexagon.h delete mode 100644 Hooks/keystone/keystone.h delete mode 100644 Hooks/keystone/mips.h delete mode 100644 Hooks/keystone/ppc.h delete mode 100644 Hooks/keystone/sparc.h delete mode 100644 Hooks/keystone/systemz.h delete mode 100644 Hooks/keystone/x86.h create mode 160000 Liberation delete mode 160000 keystone diff --git a/.gitmodules b/.gitmodules index 7c7eb4b..063bbd5 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "capstone"] path = capstone url = https://github.com/aquynh/capstone.git -[submodule "keystone"] - path = keystone - url = https://github.com/keystone-engine/keystone.git +[submodule "Liberation"] + path = Liberation + url = git@github.com:iOSCheaters/Liberation.git diff --git a/BuildConfig.py b/BuildConfig.py index 31e0144..9ef8cd3 100644 --- a/BuildConfig.py +++ b/BuildConfig.py @@ -2,6 +2,7 @@ ManualList=["GlobalInit","getBoolFromPreferences","RandomString"] ExtraFramework=["UIKit","CoreGraphics","CoreFoundation","QuartzCore","CFNetwork"] ExtraLibrary=[] -LDFLAGS=["-lz","-L.","-v","-force_load","./ExtraFWs/libcapstone.a","-force_load","./ExtraFWs/libkeystone.a","-F./ExtraFWs/"] -ExtraCFlags=[] -ExtraOBJFiles=["./ExtraFWs/Reveal.framework/Reveal","./ExtraFWs/Cycript.framework/Cycript"] +LDFLAGS=["-lz","-L.","-v","-force_load ./ExtraFWs/libcapstone.a","-force_load ./ExtraFWs/libLiberation.a","-force_load ./ExtraFWs/Reveal.framework/Reveal","-force_load ./ExtraFWs/Cycript.framework/Cycript","-F./ExtraFWs/","-Wno-unused-function"] +ExtraCFlags=["-I./Hooks/"] +ExtraOBJFiles=[] +ExtraCCFlags=["-std=c++11"] diff --git a/DOCS/CODEOWNERS.md b/DOCS/CODEOWNERS.md index 72fd7bc..a0aa2ec 100644 --- a/DOCS/CODEOWNERS.md +++ b/DOCS/CODEOWNERS.md @@ -32,12 +32,15 @@ Everything Left. Unless Otherwise Specified - NSKeyedArchiver.xm - NSKeyedUnarchiver.xm -#DavidGoldman -##ThirdPartyTools/InspectiveC +##DavidGoldman +#ThirdPartyTools/InspectiveC -#Elias Limneos -##ThirdPartyTools/classdumpdyld +##Elias Limneos +#ThirdPartyTools/classdumpdyld -#Carina -##ThirdPartyTools/dumpdecrypted +##Carina +#ThirdPartyTools/dumpdecrypted + +##Submodules +#All Submodules Belong To Their Respective Owner diff --git a/Hooks/Liberation.h b/Hooks/Liberation.h new file mode 100644 index 0000000..4bc0512 --- /dev/null +++ b/Hooks/Liberation.h @@ -0,0 +1,197 @@ +//--------------------------------// +//-----------Liberation-----------// +//-------Created-by-Razzile-------// +//--------------------------------// +//------Don't mess with this------// +//------Unless you are smart------// +//--------------------------------// +//------------Licenses------------// +//--------------------------------// +// Copyright (c) 2016, Razzile + +// Permission to use, copy, modify, and/or distribute this software for any +// purpose +// with or without fee is hereby granted, provided that the above copyright +// notice +// and this permission notice appear in all copies. + +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND +// FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS +// OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +// OTHER +// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE +// OF +// THIS SOFTWARE. + +#if __cplusplus <= 199711L +#error Please enable C++11 for use with Liberation +#endif + +#include +#include +#include +#include +#include +#include + +#define hidden __attribute__((visibility("hidden"))) + +/* Container namespace for classes */ +inline namespace liberation { + +using bytes = std::vector; + +enum class ARMv7Mode { ARM, Thumb }; + +class Patch { +public: + static Patch *CreatePatch(vm_address_t address, uint32_t data); + static Patch *CreatePatch(vm_address_t address, std::string data); + static Patch *CreateRawPatch(vm_address_t addr, char *data, size_t len); + static Patch *CreateInstrPatch(vm_address_t address, std::string instr, + ARMv7Mode mode = ARMv7Mode::Thumb); + + virtual bool Apply(); + virtual bool Reset(); + +private: + Patch() = default; + Patch(vm_address_t addr, char *data, size_t len); + ~Patch(); + +protected: + vm_address_t _address; + bytes _patchBytes; + bytes _origBytes; + size_t _patchSize; +}; + +class Hook { +public: + ~Hook(); + Hook(std::string symbol, void *hookPtr, void **origPtr); + Hook(std::string symbol, void *hookPtr); + Hook(void *hookFuncAddr, void *hookPtr, void **origPtr); + Hook(void *hookFuncAddr, void *hookPtr); + Hook(vm_address_t hookFuncAddr, void *hookPtr, void **origPtr); + Hook(vm_address_t hookFuncAddr, void *hookPtr); + + template + hidden Hook(void *hookFuncAddress, T *hookPtr, T **origPtr) + : Hook(hookFuncAddress, (void *)hookPtr, (void **)origPtr) {} + + template + hidden Hook(void *hookFuncAddress, T *hookPtr) + : Hook(hookFuncAddress, (void *)hookPtr) {} + + template + hidden Hook(vm_address_t hookFuncAddr, T *hookPtr, T **origPtr) + : Hook((void *)(hookFuncAddr), (void *)hookPtr, (void **)origPtr) {} + + template + hidden Hook(vm_address_t hookFuncAddr, T *hookPtr) + : Hook((void *)(hookFuncAddr), (void *)hookPtr) {} + + bool Apply(); + bool Reset(); + +private: + std::string _symbol; + void *_hookPtr; + void **_origPtr; + void *_hookFuncAddr; +}; + +class Settings { +public: + Settings(const char *path); + ~Settings(); + + int GetPrefInt(const char *key); + float GetPrefFloat(const char *key); + bool GetPrefBool(const char *key); + + __attribute__((noinline)) bool reloadSettings(); + + class settings_proxy { + public: + char *key; + + union Value { + int asInt; + bool asBool; + float asFloat; + } value; + + enum ValueType { Int, Bool, Float } valueType; + + Settings *container; + + hidden settings_proxy(const char *_key) { + key = (char *)malloc(strlen(_key)); + strcpy(key, _key); + } + + hidden settings_proxy(int val) { + value.asInt = val; + valueType = Int; + } + + hidden settings_proxy(float val) { + value.asFloat = val; + valueType = Float; + } + + hidden settings_proxy(bool val) { + value.asBool = val; + valueType = Bool; + } + + hidden operator int() { return container->GetPrefInt(key); } + + hidden operator float() { return container->GetPrefFloat(key); } + + hidden operator bool() { return container->GetPrefBool(key); } + + hidden settings_proxy &operator=(const settings_proxy &source) { + switch (source.valueType) { + case Int: { + set(source.value.asInt); + break; + } + case Bool: { + set(source.value.asBool); + break; + } + case Float: { + set(source.value.asFloat); + break; + } + } + return *this; + } + void set(bool value); + void set(int value); + void set(float value); + + hidden ~settings_proxy() { + if (key != NULL) + free(key); + } + }; + + hidden settings_proxy operator[](const char *key) { + settings_proxy proxy(key); + proxy.container = this; + return proxy; + } + +private: + const char *path; + CFDictionaryRef dict; +}; +} // utils diff --git a/Hooks/SharedDefine.pch b/Hooks/SharedDefine.pch index 5393d61..66b64f8 100644 --- a/Hooks/SharedDefine.pch +++ b/Hooks/SharedDefine.pch @@ -18,7 +18,6 @@ #import "./Obfuscation.h" #import "./capstone/capstone.h" #import "Cycript.h" -#import "keystone/keystone.h" #define objectTypeNotSupported @"objectTypeNotSupported" #define traceStorage [SQLiteStorage sharedManager] diff --git a/Hooks/keystone/arm.h b/Hooks/keystone/arm.h deleted file mode 100644 index f4d2489..0000000 --- a/Hooks/keystone/arm.h +++ /dev/null @@ -1,23 +0,0 @@ -/* Keystone Assembler Engine */ -/* By Nguyen Anh Quynh, 2016 */ - -#ifndef KEYSTONE_ARM_H -#define KEYSTONE_ARM_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "keystone.h" - -typedef enum ks_err_asm_arm { - KS_ERR_ASM_ARM_INVALIDOPERAND = KS_ERR_ASM_ARCH, - KS_ERR_ASM_ARM_MISSINGFEATURE, - KS_ERR_ASM_ARM_MNEMONICFAIL, -} ks_err_asm_arm; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/Hooks/keystone/arm64.h b/Hooks/keystone/arm64.h deleted file mode 100644 index 7a7af41..0000000 --- a/Hooks/keystone/arm64.h +++ /dev/null @@ -1,23 +0,0 @@ -/* Keystone Assembler Engine */ -/* By Nguyen Anh Quynh, 2016 */ - -#ifndef KEYSTONE_ARM64_H -#define KEYSTONE_ARM64_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "keystone.h" - -typedef enum ks_err_asm_arm64 { - KS_ERR_ASM_ARM64_INVALIDOPERAND = KS_ERR_ASM_ARCH, - KS_ERR_ASM_ARM64_MISSINGFEATURE, - KS_ERR_ASM_ARM64_MNEMONICFAIL, -} ks_err_asm_arm64; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/Hooks/keystone/hexagon.h b/Hooks/keystone/hexagon.h deleted file mode 100644 index e615812..0000000 --- a/Hooks/keystone/hexagon.h +++ /dev/null @@ -1,24 +0,0 @@ -/* Keystone Assembler Engine */ -/* By Nguyen Anh Quynh, 2016 */ - -#ifndef KEYSTONE_HEXAGON_H -#define KEYSTONE_HEXAGON_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "keystone.h" - -typedef enum ks_err_asm_hexagon { - KS_ERR_ASM_HEXAGON_INVALIDOPERAND = KS_ERR_ASM_ARCH, - KS_ERR_ASM_HEXAGON_MISSINGFEATURE, - KS_ERR_ASM_HEXAGON_MNEMONICFAIL, -} ks_err_asm_hexagon; - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/Hooks/keystone/keystone.h b/Hooks/keystone/keystone.h deleted file mode 100644 index 2a885d0..0000000 --- a/Hooks/keystone/keystone.h +++ /dev/null @@ -1,314 +0,0 @@ -/* Keystone Assembler Engine (www.keystone-engine.org) */ -/* By Nguyen Anh Quynh , 2016 */ - -#ifndef KEYSTONE_ENGINE_H -#define KEYSTONE_ENGINE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include -#include - -#ifdef _MSC_VER // MSVC compiler -#pragma warning(disable:4201) -#pragma warning(disable:4100) -#define KEYSTONE_EXPORT __declspec(dllexport) -#else -#ifdef __GNUC__ -#define KEYSTONE_EXPORT __attribute__((visibility("default"))) -#else -#define KEYSTONE_EXPORT -#endif -#endif - - -struct ks_struct; -typedef struct ks_struct ks_engine; - -// Keystone API version -#define KS_API_MAJOR 0 -#define KS_API_MINOR 9 - -/* - Macro to create combined version which can be compared to - result of ks_version() API. -*/ -#define KS_MAKE_VERSION(major, minor) ((major << 8) + minor) - -// Architecture type -typedef enum ks_arch { - KS_ARCH_ARM = 1, // ARM architecture (including Thumb, Thumb-2) - KS_ARCH_ARM64, // ARM-64, also called AArch64 - KS_ARCH_MIPS, // Mips architecture - KS_ARCH_X86, // X86 architecture (including x86 & x86-64) - KS_ARCH_PPC, // PowerPC architecture (currently unsupported) - KS_ARCH_SPARC, // Sparc architecture - KS_ARCH_SYSTEMZ, // SystemZ architecture (S390X) - KS_ARCH_HEXAGON, // Hexagon architecture - KS_ARCH_MAX, -} ks_arch; - -// Mode type -typedef enum ks_mode { - KS_MODE_LITTLE_ENDIAN = 0, // little-endian mode (default mode) - KS_MODE_BIG_ENDIAN = 1 << 30, // big-endian mode - // arm / arm64 - KS_MODE_ARM = 1 << 0, // ARM mode - KS_MODE_THUMB = 1 << 4, // THUMB mode (including Thumb-2) - KS_MODE_V8 = 1 << 6, // ARMv8 A32 encodings for ARM - // mips - KS_MODE_MICRO = 1 << 4, // MicroMips mode - KS_MODE_MIPS3 = 1 << 5, // Mips III ISA - KS_MODE_MIPS32R6 = 1 << 6, // Mips32r6 ISA - KS_MODE_MIPS32 = 1 << 2, // Mips32 ISA - KS_MODE_MIPS64 = 1 << 3, // Mips64 ISA - // x86 / x64 - KS_MODE_16 = 1 << 1, // 16-bit mode - KS_MODE_32 = 1 << 2, // 32-bit mode - KS_MODE_64 = 1 << 3, // 64-bit mode - // ppc - KS_MODE_PPC32 = 1 << 2, // 32-bit mode - KS_MODE_PPC64 = 1 << 3, // 64-bit mode - KS_MODE_QPX = 1 << 4, // Quad Processing eXtensions mode - // sparc - KS_MODE_SPARC32 = 1 << 2, // 32-bit mode - KS_MODE_SPARC64 = 1 << 3, // 64-bit mode - KS_MODE_V9 = 1 << 4, // SparcV9 mode -} ks_mode; - -// All generic errors related to input assembly >= KS_ERR_ASM -#define KS_ERR_ASM 128 - -// All architecture-specific errors related to input assembly >= KS_ERR_ASM_ARCH -#define KS_ERR_ASM_ARCH 512 - -// All type of errors encountered by Keystone API. -typedef enum ks_err { - KS_ERR_OK = 0, // No error: everything was fine - KS_ERR_NOMEM, // Out-Of-Memory error: ks_open(), ks_emulate() - KS_ERR_ARCH, // Unsupported architecture: ks_open() - KS_ERR_HANDLE, // Invalid handle - KS_ERR_MODE, // Invalid/unsupported mode: ks_open() - KS_ERR_VERSION, // Unsupported version (bindings) - KS_ERR_OPT_INVALID, // Unsupported option - - // generic input assembly errors - parser specific - KS_ERR_ASM_EXPR_TOKEN = KS_ERR_ASM, // unknown token in expression - KS_ERR_ASM_DIRECTIVE_VALUE_RANGE, // literal value out of range for directive - KS_ERR_ASM_DIRECTIVE_ID, // expected identifier in directive - KS_ERR_ASM_DIRECTIVE_TOKEN, // unexpected token in directive - KS_ERR_ASM_DIRECTIVE_STR, // expected string in directive - KS_ERR_ASM_DIRECTIVE_COMMA, // expected comma in directive - KS_ERR_ASM_DIRECTIVE_RELOC_NAME, // expected relocation name in directive - KS_ERR_ASM_DIRECTIVE_RELOC_TOKEN, // unexpected token in .reloc directive - KS_ERR_ASM_DIRECTIVE_FPOINT, // invalid floating point in directive - KS_ERR_ASM_DIRECTIVE_UNKNOWN, // unknown directive - KS_ERR_ASM_DIRECTIVE_EQU, // invalid equal directive - KS_ERR_ASM_DIRECTIVE_INVALID, // (generic) invalid directive - KS_ERR_ASM_VARIANT_INVALID, // invalid variant - KS_ERR_ASM_EXPR_BRACKET, // brackets expression not supported on this target - KS_ERR_ASM_SYMBOL_MODIFIER, // unexpected symbol modifier following '@' - KS_ERR_ASM_SYMBOL_REDEFINED, // invalid symbol redefinition - KS_ERR_ASM_SYMBOL_MISSING, // cannot find a symbol - KS_ERR_ASM_RPAREN, // expected ')' in parentheses expression - KS_ERR_ASM_STAT_TOKEN, // unexpected token at start of statement - KS_ERR_ASM_UNSUPPORTED, // unsupported token yet - KS_ERR_ASM_MACRO_TOKEN, // unexpected token in macro instantiation - KS_ERR_ASM_MACRO_PAREN, // unbalanced parentheses in macro argument - KS_ERR_ASM_MACRO_EQU, // expected '=' after formal parameter identifier - KS_ERR_ASM_MACRO_ARGS, // too many positional arguments - KS_ERR_ASM_MACRO_LEVELS_EXCEED, // macros cannot be nested more than 20 levels deep - KS_ERR_ASM_MACRO_STR, // invalid macro string - KS_ERR_ASM_MACRO_INVALID, // invalid macro (generic error) - KS_ERR_ASM_ESC_BACKSLASH, // unexpected backslash at end of escaped string - KS_ERR_ASM_ESC_OCTAL, // invalid octal escape sequence (out of range) - KS_ERR_ASM_ESC_SEQUENCE, // invalid escape sequence (unrecognized character) - KS_ERR_ASM_ESC_STR, // broken escape string - KS_ERR_ASM_TOKEN_INVALID, // invalid token - KS_ERR_ASM_INSN_UNSUPPORTED, // this instruction is unsupported in this mode - KS_ERR_ASM_FIXUP_INVALID, // invalid fixup - KS_ERR_ASM_LABEL_INVALID, // invalid label - KS_ERR_ASM_FRAGMENT_INVALID, // invalid fragment - - // generic input assembly errors - architecture specific - KS_ERR_ASM_INVALIDOPERAND = KS_ERR_ASM_ARCH, - KS_ERR_ASM_MISSINGFEATURE, - KS_ERR_ASM_MNEMONICFAIL, -} ks_err; - - -// Runtime option for the Keystone engine -typedef enum ks_opt_type { - KS_OPT_SYNTAX = 1, // Choose syntax for input assembly -} ks_opt_type; - - -// Runtime option value (associated with ks_opt_type above) -typedef enum ks_opt_value { - KS_OPT_SYNTAX_INTEL = 1 << 0, // X86 Intel syntax - default on X86 (KS_OPT_SYNTAX). - KS_OPT_SYNTAX_ATT = 1 << 1, // X86 ATT asm syntax (KS_OPT_SYNTAX). - KS_OPT_SYNTAX_NASM = 1 << 2, // X86 Nasm syntax (KS_OPT_SYNTAX). - KS_OPT_SYNTAX_MASM = 1 << 3, // X86 Masm syntax (KS_OPT_SYNTAX) - unsupported yet. - KS_OPT_SYNTAX_GAS = 1 << 4, // X86 GNU GAS syntax (KS_OPT_SYNTAX). -} ks_opt_value; - - -#include "arm64.h" -#include "arm.h" -#include "hexagon.h" -#include "mips.h" -#include "ppc.h" -#include "sparc.h" -#include "systemz.h" -#include "x86.h" - -/* - Return combined API version & major and minor version numbers. - - @major: major number of API version - @minor: minor number of API version - - @return hexical number as (major << 8 | minor), which encodes both - major & minor versions. - NOTE: This returned value can be compared with version number made - with macro KS_MAKE_VERSION - - For example, second API version would return 1 in @major, and 1 in @minor - The return value would be 0x0101 - - NOTE: if you only care about returned value, but not major and minor values, - set both @major & @minor arguments to NULL. -*/ -KEYSTONE_EXPORT -unsigned int ks_version(unsigned int *major, unsigned int *minor); - - -/* - Determine if the given architecture is supported by this library. - - @arch: architecture type (KS_ARCH_*) - - @return True if this library supports the given arch. -*/ -KEYSTONE_EXPORT -bool ks_arch_supported(ks_arch arch); - - -/* - Create new instance of Keystone engine. - - @arch: architecture type (KS_ARCH_*) - @mode: hardware mode. This is combined of KS_MODE_* - @ks: pointer to ks_engine, which will be updated at return time - - @return KS_ERR_OK on success, or other value on failure (refer to ks_err enum - for detailed error). -*/ -KEYSTONE_EXPORT -ks_err ks_open(ks_arch arch, int mode, ks_engine **ks); - - -/* - Close KS instance: MUST do to release the handle when it is not used anymore. - NOTE: this must be called only when there is no longer usage of Keystone. - The reason is the this API releases some cached memory, thus access to any - Keystone API after ks_close() might crash your application. - After this, @ks is invalid, and nolonger usable. - - @ks: pointer to a handle returned by ks_open() - - @return KS_ERR_OK on success, or other value on failure (refer to ks_err enum - for detailed error). -*/ -KEYSTONE_EXPORT -ks_err ks_close(ks_engine *ks); - - -/* - Report the last error number when some API function fail. - Like glibc's errno, ks_errno might not retain its old error once accessed. - - @ks: handle returned by ks_open() - - @return: error code of ks_err enum type (KS_ERR_*, see above) -*/ -KEYSTONE_EXPORT -ks_err ks_errno(ks_engine *ks); - - -/* - Return a string describing given error code. - - @code: error code (see KS_ERR_* above) - - @return: returns a pointer to a string that describes the error code - passed in the argument @code - */ -KEYSTONE_EXPORT -const char *ks_strerror(ks_err code); - - -/* - Set option for Keystone engine at runtime - - @ks: handle returned by ks_open() - @type: type of option to be set - @value: option value corresponding with @type - - @return: KS_ERR_OK on success, or other value on failure. - Refer to ks_err enum for detailed error. -*/ -KEYSTONE_EXPORT -ks_err ks_option(ks_engine *ks, ks_opt_type type, size_t value); - - -/* - Assemble a string given its the buffer, size, start address and number - of instructions to be decoded. - This API dynamically allocate memory to contain assembled instruction. - Resulted array of bytes containing the machine code is put into @*encoding - - NOTE 1: this API will automatically determine memory needed to contain - output bytes in *encoding. - - NOTE 2: caller must free the allocated memory itself to avoid memory leaking. - - @ks: handle returned by ks_open() - @str: NULL-terminated assembly string. Use ; or \n to separate statements. - @address: address of the first assembly instruction, or 0 to ignore. - @encoding: array of bytes containing encoding of input assembly string. - NOTE: *encoding will be allocated by this function, and should be freed - with ks_free() function. - @encoding_size: size of *encoding - @stat_count: number of statements successfully processed - - @return: 0 on success, or -1 on failure. - - On failure, call ks_errno() for error code. -*/ -KEYSTONE_EXPORT -int ks_asm(ks_engine *ks, - const char *string, - uint64_t address, - unsigned char **encoding, size_t *encoding_size, - size_t *stat_count); - - -/* - Free memory allocated by ks_asm() - - @p: memory allocated in @encoding argument of ks_asm() -*/ -KEYSTONE_EXPORT -void ks_free(unsigned char *p); - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/Hooks/keystone/mips.h b/Hooks/keystone/mips.h deleted file mode 100644 index e71c553..0000000 --- a/Hooks/keystone/mips.h +++ /dev/null @@ -1,23 +0,0 @@ -/* Keystone Assembler Engine */ -/* By Nguyen Anh Quynh, 2016 */ - -#ifndef KEYSTONE_MIPS_H -#define KEYSTONE_MIPS_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "keystone.h" - -typedef enum ks_err_asm_mips { - KS_ERR_ASM_MIPS_INVALIDOPERAND = KS_ERR_ASM_ARCH, - KS_ERR_ASM_MIPS_MISSINGFEATURE, - KS_ERR_ASM_MIPS_MNEMONICFAIL, -} ks_err_asm_mips; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/Hooks/keystone/ppc.h b/Hooks/keystone/ppc.h deleted file mode 100644 index 39a602c..0000000 --- a/Hooks/keystone/ppc.h +++ /dev/null @@ -1,24 +0,0 @@ -/* Keystone Assembler Engine */ -/* By Nguyen Anh Quynh, 2016 */ - -#ifndef KEYSTONE_PPC_H -#define KEYSTONE_PPC_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "keystone.h" - -typedef enum ks_err_asm_ppc { - KS_ERR_ASM_PPC_INVALIDOPERAND = KS_ERR_ASM_ARCH, - KS_ERR_ASM_PPC_MISSINGFEATURE, - KS_ERR_ASM_PPC_MNEMONICFAIL, -} ks_err_asm_ppc; - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/Hooks/keystone/sparc.h b/Hooks/keystone/sparc.h deleted file mode 100644 index e49c426..0000000 --- a/Hooks/keystone/sparc.h +++ /dev/null @@ -1,24 +0,0 @@ -/* Keystone Assembler Engine */ -/* By Nguyen Anh Quynh, 2016 */ - -#ifndef KEYSTONE_SPARC_H -#define KEYSTONE_SPARC_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "keystone.h" - -typedef enum ks_err_asm_sparc { - KS_ERR_ASM_SPARC_INVALIDOPERAND = KS_ERR_ASM_ARCH, - KS_ERR_ASM_SPARC_MISSINGFEATURE, - KS_ERR_ASM_SPARC_MNEMONICFAIL, -} ks_err_asm_sparc; - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/Hooks/keystone/systemz.h b/Hooks/keystone/systemz.h deleted file mode 100644 index ec2b07a..0000000 --- a/Hooks/keystone/systemz.h +++ /dev/null @@ -1,24 +0,0 @@ -/* Keystone Assembler Engine */ -/* By Nguyen Anh Quynh, 2016 */ - -#ifndef KEYSTONE_SYSTEMZ_H -#define KEYSTONE_SYSTEMZ_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "keystone.h" - -typedef enum ks_err_asm_systemz { - KS_ERR_ASM_SYSTEMZ_INVALIDOPERAND = KS_ERR_ASM_ARCH, - KS_ERR_ASM_SYSTEMZ_MISSINGFEATURE, - KS_ERR_ASM_SYSTEMZ_MNEMONICFAIL, -} ks_err_asm_systemz; - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/Hooks/keystone/x86.h b/Hooks/keystone/x86.h deleted file mode 100644 index 1fac684..0000000 --- a/Hooks/keystone/x86.h +++ /dev/null @@ -1,23 +0,0 @@ -/* Keystone Assembler Engine */ -/* By Nguyen Anh Quynh, 2016 */ - -#ifndef KEYSTONE_X86_H -#define KEYSTONE_X86_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "keystone.h" - -typedef enum ks_err_asm_x86 { - KS_ERR_ASM_X86_INVALIDOPERAND = KS_ERR_ASM_ARCH, - KS_ERR_ASM_X86_MISSINGFEATURE, - KS_ERR_ASM_X86_MNEMONICFAIL, -} ks_err_asm_x86; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/Liberation b/Liberation new file mode 160000 index 0000000..ee4780c --- /dev/null +++ b/Liberation @@ -0,0 +1 @@ +Subproject commit ee4780c28bf735550edde45c753047f5bf4918e8 diff --git a/Makefile b/Makefile index 594efdd..2f95c7f 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,14 @@ -export CFLAGS=-Wp,"-DWTFJHTWEAKNAME=@\"TTW8ZU92QISYBX1\","-DWTFJHHostName=@\"Naville-Zhang-Retina-MacBook-Pro-2\" +export CFLAGS=-Wp,"-DWTFJHTWEAKNAME=@\"SV860J8AXBR6ET7\","-DWTFJHHostName=@\"Naville-Zhang-Retina-MacBook-Pro-2\" include $(THEOS)/makefiles/common.mk -TWEAK_NAME = TTW8ZU92QISYBX1 +TWEAK_NAME = SV860J8AXBR6ET7 SUBSTRATE ?= yes -TTW8ZU92QISYBX1_FILES = Tweak.xm CompileDefines.xm Hooks/API/AppleAccount.xm Hooks/API/CommonCryptor.xm Hooks/API/CommonDigest.xm Hooks/API/CommonHMAC.xm Hooks/API/CommonKeyDerivation.xm Hooks/API/CoreTelephony.xm Hooks/API/dlfcn.xm Hooks/API/Keychain.xm Hooks/API/libC.xm Hooks/API/libMobileGestalt.xm Hooks/API/LSApplication.xm Hooks/API/MachO.xm Hooks/API/Notification.xm Hooks/API/NSData.xm Hooks/API/NSFileHandle.xm Hooks/API/NSFileManager.xm Hooks/API/NSHTTPCookie.xm Hooks/API/NSInputStream.xm Hooks/API/NSKeyedArchiver.xm Hooks/API/NSKeyedUnarchiver.xm Hooks/API/NSOutputStream.xm Hooks/API/NSProcessInfo.xm Hooks/API/NSURLConnection.xm Hooks/API/NSURLCredential.xm Hooks/API/NSURLSession.xm Hooks/API/NSUserDefaults.xm Hooks/API/NSXMLParser.xm Hooks/API/ObjCRuntime.xm Hooks/API/Security.xm Hooks/API/Socket.xm Hooks/API/SSLKillSwitch.xm Hooks/API/sysctl.xm Hooks/API/UIPasteboard.xm Hooks/SDK/FclBlowfish.xm Hooks/SDK/JSPatch.xm Hooks/SDK/OpenSSLAES.xm Hooks/SDK/OpenSSLBlowFish.xm Hooks/SDK/OpenSSLMD5.xm Hooks/SDK/OpenSSLSHA1.xm Hooks/SDK/OpenSSLSHA512.xm Hooks/SDK/Reveal.xm Hooks/SDK/Wax.xm Hooks/Utils/CallStackInspector.m Hooks/Utils/CallTracer.m Hooks/Utils/DelegateProxies.m Hooks/Utils/NSURLConnectionDelegateProx.m Hooks/Utils/NSURLSessionDelegateProxy.m Hooks/Utils/PlistObjectConverter.m Hooks/Utils/RemoteLogSender.m Hooks/Utils/RuntimeUtils.m Hooks/Utils/SQLiteStorage.m Hooks/Utils/Utils.m Hooks/ThirdPartyTools/classdumpdyld.xm Hooks/ThirdPartyTools/dumpdecrypted.xm Hooks/ThirdPartyTools/InspectiveC.xm Hooks/Misc/Cycript.xm Hooks/Misc/fishhook.c Hooks/Misc/RemoveASLR.xm Hooks/Misc/SplitMachO.mm Hooks/Misc/WTSubstrate.mm -ADDITIONAL_CCFLAGS = -Qunused-arguments -ADDITIONAL_LDFLAGS = -Wl,-segalign,4000,-sectcreate,WTFJH,SIGDB,./SignatureDatabase.plist,-sectcreate,WTFJH,classdumpdyld,./classdumpdyld.dylib,-sectcreate,WTFJH,dumpdecrypted,./dumpdecrypted.dylib,-sectcreate,WTFJH,InspectiveC,./InspectiveC.dylib -lz -L. -v -force_load ./ExtraFWs/libcapstone.a -force_load ./ExtraFWs/libkeystone.a -F./ExtraFWs/ - -TTW8ZU92QISYBX1_LIBRARIES = sqlite3 substrate stdc++ c++ -TTW8ZU92QISYBX1_FRAMEWORKS = Foundation UIKit Security JavaScriptCore UIKit CoreGraphics CoreFoundation QuartzCore CFNetwork -TTW8ZU92QISYBX1_OBJ_FILES =./ExtraFWs/Reveal.framework/Reveal ./ExtraFWs/Cycript.framework/Cycript +SV860J8AXBR6ET7_FILES = Tweak.xm CompileDefines.xm Hooks/API/AppleAccount.xm Hooks/API/CommonCryptor.xm Hooks/API/CommonDigest.xm Hooks/API/CommonHMAC.xm Hooks/API/CommonKeyDerivation.xm Hooks/API/CoreTelephony.xm Hooks/API/dlfcn.xm Hooks/API/Keychain.xm Hooks/API/libC.xm Hooks/API/libMobileGestalt.xm Hooks/API/LSApplication.xm Hooks/API/MachO.xm Hooks/API/Notification.xm Hooks/API/NSData.xm Hooks/API/NSFileHandle.xm Hooks/API/NSFileManager.xm Hooks/API/NSHTTPCookie.xm Hooks/API/NSInputStream.xm Hooks/API/NSKeyedArchiver.xm Hooks/API/NSKeyedUnarchiver.xm Hooks/API/NSOutputStream.xm Hooks/API/NSProcessInfo.xm Hooks/API/NSURLConnection.xm Hooks/API/NSURLCredential.xm Hooks/API/NSURLSession.xm Hooks/API/NSUserDefaults.xm Hooks/API/NSXMLParser.xm Hooks/API/ObjCRuntime.xm Hooks/API/Security.xm Hooks/API/Socket.xm Hooks/API/SSLKillSwitch.xm Hooks/API/sysctl.xm Hooks/API/UIPasteboard.xm Hooks/SDK/FclBlowfish.xm Hooks/SDK/JSPatch.xm Hooks/SDK/OpenSSLAES.xm Hooks/SDK/OpenSSLBlowFish.xm Hooks/SDK/OpenSSLMD5.xm Hooks/SDK/OpenSSLSHA1.xm Hooks/SDK/OpenSSLSHA512.xm Hooks/SDK/Reveal.xm Hooks/SDK/Wax.xm Hooks/Utils/CallStackInspector.m Hooks/Utils/CallTracer.m Hooks/Utils/DelegateProxies.m Hooks/Utils/NSURLConnectionDelegateProx.m Hooks/Utils/NSURLSessionDelegateProxy.m Hooks/Utils/PlistObjectConverter.m Hooks/Utils/RemoteLogSender.m Hooks/Utils/RuntimeUtils.m Hooks/Utils/SQLiteStorage.m Hooks/Utils/Utils.m Hooks/ThirdPartyTools/classdumpdyld.xm Hooks/ThirdPartyTools/dumpdecrypted.xm Hooks/ThirdPartyTools/InspectiveC.xm Hooks/Misc/Cycript.xm Hooks/Misc/fishhook.c Hooks/Misc/RemoveASLR.xm Hooks/Misc/SplitMachO.mm Hooks/Misc/WTSubstrate.mm +export ADDITIONAL_CCFLAGS = -Qunused-arguments -std=c++11 +export ADDITIONAL_LDFLAGS = -Wl,-segalign,4000,-sectcreate,WTFJH,SIGDB,./SignatureDatabase.plist,-sectcreate,WTFJH,classdumpdyld,./classdumpdyld.dylib,-sectcreate,WTFJH,dumpdecrypted,./dumpdecrypted.dylib,-sectcreate,WTFJH,InspectiveC,./InspectiveC.dylib -lz -L. -v -force_load ./ExtraFWs/libcapstone.a -force_load ./ExtraFWs/libLiberation.a -force_load ./ExtraFWs/Reveal.framework/Reveal -force_load ./ExtraFWs/Cycript.framework/Cycript -F./ExtraFWs/ -Wno-unused-function +export ADDITIONAL_CFLAGS = -I./Hooks/ +SV860J8AXBR6ET7_LIBRARIES = sqlite3 substrate stdc++ c++ +SV860J8AXBR6ET7_FRAMEWORKS = Foundation UIKit Security JavaScriptCore UIKit CoreGraphics CoreFoundation QuartzCore CFNetwork + include $(THEOS_MAKE_PATH)/tweak.mk after-install:: install.exec "killall -9 SpringBoard" \ No newline at end of file diff --git a/Setup.sh b/Setup.sh index afa04ad..5ecba47 100755 --- a/Setup.sh +++ b/Setup.sh @@ -2,7 +2,6 @@ OrigDIR="$(pwd)" echo "DIR Set to:""${OrigDIR}" - echo "Installing Latest Dependencies" brew install dpkg brew install ldid @@ -18,6 +17,8 @@ rm ./ExtraFWs/Reveal.framework >> /dev/null 2>&1 rm ./Reveal.app.zip >> /dev/null 2>&1 rm -rf ./RevealTMP >> /dev/null 2>&1 rm -rf ./CYTMP >> /dev/null 2>&1 +rm ./ExtraFWs/libLiberation.a +rm ./Hooks/Liberation.h mkdir ExtraFWs >> /dev/null 2>&1 mkdir Packages >> /dev/null 2>&1 echo "Pulling Latest Trunk" @@ -30,12 +31,16 @@ cd "${OrigDIR}" echo "Moving capstone" mv ./capstone/libcapstone.a ./ExtraFWs/ >>/dev/null cp -r ./capstone/include ./Hooks/capstone >>/dev/null -echo "Building keystone" -cd keystone && git pull origin master&&rm -rf build &&mkdir build &&cd build &&../make-lib.sh cd "${OrigDIR}" -echo "Moving keystone" -mv ./keystone/build/llvm/lib/libkeystone.a ./ExtraFWs/ >> /dev/null 2>&1 -cp -r ./keystone/include/keystone ./Hooks/keystone >> /dev/null 2>&1 +echo "Building Liberation" +cd ./Liberation +cd keystone&&git pull origin master &&cd ../ +./liberation setup +./liberation build +cd "${OrigDIR}" +echo "Moving Liberation" +mv ./Liberation/lib/libLiberation.a ./ExtraFWs/ +mv ./Liberation/include/Liberation.h ./Hooks/ cd "${OrigDIR}" echo "Downloading Cycript" wget https://cydia.saurik.com/api/latest/3 -O Cycript.zip diff --git a/VERSION b/VERSION index 903dc0f..116f2e3 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -390 \ No newline at end of file +391 \ No newline at end of file diff --git a/build.py b/build.py index a179ede..b325925 100755 --- a/build.py +++ b/build.py @@ -56,6 +56,14 @@ def Exec(Command): buildCommand="make " global HostName HostName=subprocess.check_output("hostname -s", shell=True).replace("\n","") +global AllowedSourceExtension +AllowedSourceExtension=[".cpp",".xm",".xmi",".mm",".c",".m",".x",".xi"] + +def isSource(FileName): + for End in AllowedSourceExtension: + if FileName.upper().endswith(End.upper()): + return True + return False #Setup SIGINT Handler def signal_handler(signal, frame): @@ -134,16 +142,18 @@ def BuildMakeFile(): if(JAILED==True): makeFileString += randomTweakName+"_USE_SUBSTRATE = $(SUBSTRATE)\n" makeFileString += randomTweakName + MakeFileListString + "\n" - makeFileString += "ADDITIONAL_CCFLAGS = -Qunused-arguments\n" + makeFileString += "export ADDITIONAL_CCFLAGS = -Qunused-arguments" + for CCFlag in BuildConfig.ExtraCCFlags: + makeFileString +=" "+CCFlag + makeFileString+="\n" global LinkerString - makeFileString += "ADDITIONAL_LDFLAGS = -Wl,-segalign,4000,-sectcreate,WTFJH,SIGDB,./SignatureDatabase.plist"+LinkerString+" " + makeFileString += "export ADDITIONAL_LDFLAGS = -Wl,-segalign,4000,-sectcreate,WTFJH,SIGDB,./SignatureDatabase.plist"+LinkerString+" " for LDF in BuildConfig.LDFLAGS: makeFileString +=" "+LDF makeFileString +=" \n" - if(JAILED): - makeFileString +=randomTweakName+"_CFLAGS+=-Wno-unused-function" + makeFileString +="export ADDITIONAL_CFLAGS = " for CFlag in BuildConfig.ExtraCFlags: - makeFileString +=","+CFlag + makeFileString +=" "+CFlag makeFileString+="\n" makeFileString += randomTweakName + "_LIBRARIES = sqlite3 substrate stdc++ c++ " for LBName in BuildConfig.ExtraLibrary: @@ -255,7 +265,7 @@ def toggleModule(): def MakeFileIter(Path):#Iterate All Code Files FileList = buildlistdir(Path) for x in FileList: - if (x.endswith(".mm") == False and x.endswith(".m") == False and x.endswith(".xm") == False and x.endswith(".c") == False): + if (isSource(x)==False): if DEBUG==True: print (Fore.RED +x + " has been ignored.") else: diff --git a/keystone b/keystone deleted file mode 160000 index cac140b..0000000 --- a/keystone +++ /dev/null @@ -1 +0,0 @@ -Subproject commit cac140ba395160f0baca50e3c8c5549904647b12