Theos tweak MSHookFunction - tweak

I followed http://brandontreb.com/beginning-jailbroken-ios-development-building-and-deployment
to make a tweak.
but after i done successfully with the helloworld tweak.
I hook the fopen using MSHookFunction
and then i meet a linking error
Making all for tweak hw...
Preprocessing Tweak.xm...
Compiling Tweak.xm...
Linking tweak hw...
Undefined symbols for architecture armv7:
"_MSHookFunction", referenced from:
global constructors keyed to Tweak.xm.mmin Tweak.xm.51941273.o
ld: symbol(s) not found for architecture armv7
collect2: ld returned 1 exit status
make[2]: *** [.theos/obj/hw.dylib.ba964c90.unsigned] Error 1
make[1]: *** [internal-library-all_] Error 2
make: *** [hw.all.tweak.variables] Error 2
this is Tweak.xm
#import "substrate.h"
static FILE * (*s_orig_fopen) ( const char * filename, const char * mode );
static FILE * my_fopen ( const char * filename, const char * mode ){
return s_orig_fopen(filename, mode);
}
static void entry(void) __attribute__ ((constructor));
static void entry(void) {
MSHookFunction(fopen, my_fopen, &s_orig_fopen);
}
does anyone know how to fix it?

You can try this:
#import "substrate.h"
static FILE * (*s_orig_fopen) ( const char * filename, const char * mode );
static FILE * my_fopen ( const char * filename, const char * mode ){
return s_orig_fopen(filename, mode);
}
%ctor {
MSHookFunction(fopen, my_fopen, &s_orig_fopen);
}

Related

why code runner can't run cgo program in vscode?

It;s my test code.
package main
/*
#cgo LDFLAGS: -ldl
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
static void SayHello(const char* s) {
puts(s);
}
*/
// void SayHello2(const char* s);
import "C"
func main() {
C.SayHello(C.CString("Hello, World\n"))
C.SayHello2(C.CString("Hello, World123\n"))
}
#include <stdio.h>
void SayHello2(const char *s) {
puts(s);
}
when i try the right click, it's not work, and catch some err:
/usr/local/go/pkg/tool/darwin_arm64/link: running clang failed: exit status 1
Undefined symbols for architecture arm64:
"_SayHello2", referenced from:
__cgo_a234d07dd13f_Cfunc_SayHello2 in 000001.o
(maybe you meant: __cgo_a234d07dd13f_Cfunc_SayHello2)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
but when i use vscode run and debug, everything is ok,
Starting: /Users/pandy/go/bin/dlv dap --check-go-version=false --listen=127.0.0.1:64352 --log-dest=3 from /Users/pandy/GolandProjects/CGO/pkg03
DAP server listening at: 127.0.0.1:64352
Type 'dlv help' for list of commands.
Hello, World
Hello, World123
Process 4948 has exited with status 0
Detaching
dlv dap (4910) exited with code: 0
is there some tips when use code runner?
i want to know why..

C++ macOS M1 ld: symbol(s) not found for architecture arm64 clang: error

i have a project about sorting data from files. However when i tried to implement main.cpp, i got an error.
TERMINAL OUTPUT:
Executing task: /usr/bin/clang++ -std=c++17 -stdlib=libc++ -g /Users/utku/Desktop/workspaces/cppworkspace/homework-1/main.cpp -o /Users/utku/Desktop/workspaces/cppworkspace/homework-1/main
Undefined symbols for architecture arm64:
"TestBed::setAlgorithm(int, int)", referenced from:
_main in main-f84827.o
"TestBed::execute()", referenced from:
_main in main-f84827.o
"TestBed::TestBed()", referenced from:
_main in main-f84827.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The terminal process "/bin/zsh '-c', '/usr/bin/clang++ -std=c++17 -stdlib=libc++ -g /Users/utku/Desktop/workspaces/cppworkspace/homework-1/main.cpp -o /Users/utku/Desktop/workspaces/cppworkspace/homework-1/main'" terminated with exit code: 1.
Terminal will be reused by tasks, press any key to close it.
(Using VSCode and M1 MacBook) ,
¨
using namespace std;
int main(int argc, char *argv[]) {
string testfile;
if (argc < 2) {
cout << "Enter a test file name:" << endl;
cin >> testfile;
}
else {
testfile = argv[1];
}
ifstream file(testfile.c_str());
if (file.is_open()) {
cin.rdbuf(file.rdbuf());
}
else {
cout << "Error: cannot read the test file!" << endl;
return -1;
}
int algorithmType = 0;
int k = 0;
// Numbers are obtained from the file line by line with cin
cin >> algorithmType;
cin >> k;
// Create a TestBed object, initialize and execute the algorithm
TestBed *test = new TestBed() ;
test->setAlgorithm(algorithmType,k);
test->execute();
return 0;
}¨

Qt PostgreSQL linker error when trying to add database

I'm trying to set a connection to postgre database, but having linker errors.
.pro file:
QT -= gui
CONFIG += c++11 console
CONFIG -= app_bundle
CONFIG += sql
DEFINES += QT_DEPRECATED_WARNINGS
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
unix|win32: LIBS += -L$$PWD/../../PostgreSQL/12/lib/ -llibpq
INCLUDEPATH += $$PWD/../../PostgreSQL/12/include
DEPENDPATH += $$PWD/../../PostgreSQL/12/include
win32:!win32-g++: PRE_TARGETDEPS += $$PWD/../../PostgreSQL/12/lib/libpq.lib
else:unix|win32-g++: PRE_TARGETDEPS += $$PWD/../../PostgreSQL/12/lib/liblibpq.a
.cpp file:
#include <QCoreApplication>
#include <QtSql/QSqlDatabase>
#include <QtSql/QSql>
#include <QtSql/QSqlDriver>
#include <QTextStream>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QSqlDatabase mDB=QSqlDatabase::addDatabase("QPSQL");
return a.exec();
}
It's just that. I'm not even trying to connect yet.
Errors are:
main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QSqlDatabase::~QSqlDatabase(void)" (__imp_??1QSqlDatabase##QEAA#XZ) referenced in function main
main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: static class QSqlDatabase __cdecl QSqlDatabase::addDatabase(class QString const &,class QString const &)" (__imp_?addDatabase#QSqlDatabase##SA?AV1#AEBVQString##0#Z) referenced in function main
main.obj:-1: error: LNK2001: unresolved external symbol "__declspec(dllimport) public: static char const * const QSqlDatabase::defaultConnection" (__imp_?defaultConnection#QSqlDatabase##2PEBDEB)
Postge is 64bit for Windows, compiler chosen for this application is also 64 MSVC2019 64bit. Please help.
Problem was in .pro file. It should be:
QT += sql
and not:
CONFIG += sql

Error while compiling Ethos framework

I'm trying make Ethos framework on Mac OS Lion.
git://git.dronelabs.com/ethos
Here result of ./configure:
Ethos 0.2.3
Prefix...................: /usr/local
Debug level..............: minimum
Maintainer Compiler flags: no
Build API reference......: no
Enable test suite........: yes
Bindings
GObject Introspection....: no
Vala Bindings............: no
Python Bindings..........: no
Javascript Bindings......: no
Now type `make' to compile ethos
Then I do sudo make, and while compiling arise an error:
Making all in c-plugins
CC libsample.so
Undefined symbols for architecture x86_64:
"_ethos_plugin_get_type", referenced from:
_my_plugin_get_type in cc3gPLKS.o
_my_plugin_class_init in cc3gPLKS.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make[3]: *** [libsample.so] Error 1
make[2]: *** [all-recursive] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
How can I fix it?
I found that Ethos can be installed on Mac OS X 10.7 after the following modifications:
1)Edit file: ethos_dir/ethos/ethos_manager.c (:194):
FROM:
while (NULL != (filename = g_dir_read_name (dir))) {
if (g_str_has_suffix (filename, "." G_MODULE_SUFFIX)) {
abspath = g_build_filename (loaders_dir, filename, NULL);
loader = ethos_manager_create_plugin_loader (manager, abspath);
if (loader != NULL)
loaders = g_list_prepend (loaders, loader);
g_free (abspath);
}
}
TO:
while (NULL != (filename = g_dir_read_name (dir))) {
#ifdef __APPLE__
gchar* suffix = "dylib"; // to able find ethos-plugin-loader
#else
gchar* suffix = ("." G_MODULE_SUFFIX);
#endif
if (g_str_has_suffix (filename, suffix)) {
abspath = g_build_filename (loaders_dir, filename, NULL);
loader = ethos_manager_create_plugin_loader (manager, abspath);
if (loader != NULL)
loaders = g_list_prepend (loaders, loader);
g_free (abspath);
}
}
2)Disable making for: ethos-dir/tests,
Change in Makefile.am
FROM:
line#: contents
02: SUBDIRS = c-plugins manager-dep
30: manager_sources = manager.c
31: plugin_info_sources = plugin-info.c
TO:
02: #SUBDIRS = c-plugins manager-dep
30: #manager_sources = manager.c
31: #plugin_info_sources = plugin-info.c
This is necessary because, while making process it cannot find libethos.

g++ problem with -l option and PostgreSQL

I've written simple program.
Here a code:
#include <iostream>
#include <stdio.h>
#include <D:\Program Files\PostgreSQL\8.4\include\libpq-fe.h>
#include <string>
using namespace std;
int main()
{
PGconn *conn;
PGresult *res;
int rec_count;
int row;
int col;
cout << "ble ble: " << 8 << endl;
conn = PQconnectdb("dbname=db_pm host=localhost user=postgres password=postgres");
if (PQstatus(conn) == CONNECTION_BAD) {
puts("We were unable to connect to the database");
exit(0);
}
}
I'm trying to connect with PostgreSQL.
I compile this code with following command:
gcc -I/"d:\Program Files\PostgreSQL\" -L/"d:\Program Files\PostgreSQL\8.4\lib\" -lpq -o firstcpp.o firstcpp.cpp
This command is from following site:
http://www.mkyong.com/database/how-to-building-postgresql-libpq-programs/
And when I compile it I get following error:
/cygnus/cygwin-b20/H-i586-cygwin32/i586-cygwin32/bin/ld: cannot open -lpq: No such file or directory
collect2: ld returned 1 exit status
Does anyone help me?
Difek
You can try using forward slashes instead of backward slashes. And I have no idea about the first forward slash. Isn't it meant to be inside the quotes ? Eg -I"/d:/Program Files/PostgreSQL/"
Anyway, if you are using the gcc from cygwin, you could also try
-I"/cygdrive/d/Program Files/PostgreSQL"
And I'd do the same with that include (libpq-fe) - though apparently that is working, the error is in the linker.