Search code examples
iosjailbreakobjective-c++theoscydia

Python in iOS Tweak?


i tried using https://github.com/pybee/Python-Apple-support (the python 3.5.3 ios library)

EDIT: i tried adding HackScript_PRIVATE_FRAMEWORKS = Python.framework but it says Python/Python.h doesnt exist when i try to include.

Tweak.xm:

#include "Python\Python.framework\Versions\3.5\Resources\include\python3.5\Python.h"
%hook SpringBoard

- (void)applicationDidFinishLaunching:(id)application {
    %orig;

    PyObject *py_main, *py_dict;
    py_main = PyImport_AddModule("__main__");
  py_dict = PyModule_GetDict(py_main);

    PyObject *PyRes = PyRun_String("print(\"This is a test message from HackScript\")", Py_single_input, py_dict, py_dict);

    PyObject *PyResRep = PyObject_Str(PyRes);

    char *PyResCStr = PyBytes_AS_STRING(PyResRep);
    NSString *PyResStr = @(PyResCStr);

    UIAlertView *alert1 = [[objc_getClass("UIAlertView") alloc] initWithTitle:@"Welcome"
        message:PyResStr
        delegate:self
        cancelButtonTitle:@"k"
        otherButtonTitles:nil];

        [alert1 show];

        [alert1 release];
}

%end

Makefile:

export ARCHS = armv7 armv7s arm64
export TARGET = iphone:clang:8.1:8.1
export SDKVERSION=8.1

include $(THEOS)/makefiles/common.mk

TWEAK_NAME = HackScript
HackScript_FILES = Tweak.xm

include $(THEOS_MAKE_PATH)/tweak.mk

after-install::
    install.exec "killall -9 SpringBoard"

but when i include Python.h and try to access python objects it gives me this error when compilling:

Undefined symbols for architecture armv7:
  "_PyImport_AddModule", referenced from:
      __ZL67_logos_method$_ungrouped$SpringBoard$applicationDidFinishLaunching$P11SpringBoardP13objc_selectorP11objc_object in Tweak.xm.2544b2e5.o
  "_PyModule_GetDict", referenced from:
      __ZL67_logos_method$_ungrouped$SpringBoard$applicationDidFinishLaunching$P11SpringBoardP13objc_selectorP11objc_object in Tweak.xm.2544b2e5.o
  "_PyObject_Str", referenced from:
      __ZL67_logos_method$_ungrouped$SpringBoard$applicationDidFinishLaunching$P11SpringBoardP13objc_selectorP11objc_object in Tweak.xm.2544b2e5.o
  "_PyRun_StringFlags", referenced from:
      __ZL67_logos_method$_ungrouped$SpringBoard$applicationDidFinishLaunching$P11SpringBoardP13objc_selectorP11objc_object in Tweak.xm.2544b2e5.o
ld: symbol(s) not found for architecture armv7
arm64-apple-darwin14-clang-3.9: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [/opt/theos/makefiles/instance/library.mk:33: /home/jujha/projects/hackscript/.theos/obj/debug/armv7/HackScript.dylib] Error 1
make[2]: *** [/opt/theos/makefiles/instance/library.mk:32: /home/jujha/projects/hackscript/.theos/obj/debug/armv7/HackScript.dylib] Error 2
make[1]: *** [/opt/theos/makefiles/instance/library.mk:24: internal-library-all_] Error 2
make: *** [/opt/theos/makefiles/master/rules.mk:90: HackScript.all.tweak.variables] Error 2

if this wont work can anyone recommend a scripting language i can embed into my theos tweak?


Solution

  • Have you copied the Python.framework into your binary in the Copy phase?

    See the issues section on GitHub.