I coded an iOKit fuzzer for iOS. Here is the code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mach/mach.h>
#include <mach/vm_map.h>
#include <IOKit/IOKitLib.h>
int main()
{
io_service_t service = IOServiceGetMatching(kIOMasterPortDefault, IOserviceMatching("IOUSBHIDDriver")); // change service each time
if(!service)
{
return -1;
}
io_connect_t connect;
kern_return_t kr = IOServiceOpen(service, mach_task_self(), 0, &connect);
if(kr != kIOReturnSuccess)
{
return -1;
}
uint32_t selector =3;
uint64_t input[0];
input[0] = 0x44444444444;
IOConnectCallMethod(connect, selector, input, 1, 0, 0, NULL, NULL, NULL, NULL);
printf("Did it crash? No? Do it again! -Toxic\n");
}
I've been trying to compile this with GCC for a while now, but I get all kinds of errors. I'd like to know if anyone know exactly how to compile a command line tool for iOS. Thanks.
As far as I'm aware, there's no such thing as a command line tool for (non-jailbroken) iOS, although you can output to the log using NSLog from an App. Also, Apple's toolchain for iOS uses clang (llvm) although the 'gcc' command is typically aliased to clang. The easiest way to get a script is to create a test project in Xcode, build it and look at the build log. This shows you all the commands that were run with what arguments.
Idk have you found the solution or not but anyways.
If you want to conpile with clang on device type:
clang -framework IOKit your_app.c -isysroot /var/theos/sdks/iPhoneos_whatever_sdk_you_have -o output
And this should compile.
On the mac same just without isysroot & /var...
And if you try in xcode make sure that the driver can run inside the sandbox and include iokit headers
:D
Related
I trying use OpenCV with visual studio 2017 and running this example code is giving me build time errors
I have provided the right directories to the libraries. I have gone through many tutorials and questions/answers on stack overflow so many times but haven't succeeded in fixing the problem.
#include "opencv2\opencv.hpp"
#include "opencv2\core.hpp"
#include "pch.h"
#include "opencv2\core\core.hpp"
using namespace cv;
int main(int argv, char** argc)
{
Mat test = imread("lena.jpg", IMREAD_UNCHANGED);
imshow("tst", test);
waitKey();
}
I get the following errors
C2065 'IMREAD_UNCHANGED':undeclared identifier
C3861 'imread': identifier not found
C3861 'imshow': identifier not found
C3861 'waitkey': identifier not found
Intellisense gives me all the library suggestions when I type the code but it throws errors after build.
We have some functions made available to us in iOS static library. There is a header (.h) and the compiled (.a) file. Is there any way that the functions in the static library can be called from a command line ( either OS X, Windows or Linux )? I have researched this for couple of days now and I am starting to doubt if this is even possible? We don't deal with Apple/iOS/xcode environment and the vendor only has this static library. Any hints? If it is possible in anyway I am open to reading any and very documentation but at this time I am in doubt if this is even possible? thanks
While checking out what is possible, I ran this
lipo -info libExaNumberCalc.a
I ran the above and it says
Architectures in the fat file: libExaNumberCalc.a are : i386 armv7 x86_64 arm64
Wonder if the above adds any hope?
The first thing that springs to mind is that you could write thin wrapper around your library function and build/run it. Something like
// main.c
#include "your_library_header.h"
int main(int argc, char *argv[])
{
// parse & pass parameters if necessary from command line
your_lib_function();
return 0;
}
Build with something like
clang main.c -o output.file -lyourlibrary
I had installed CUDA 9.1 previously and tested my OpenCV with the code below, all worked fine but later on I had to remove it and install 8.0. Now the below code gives errors since the previous dlls are searched.
Here is my test code:
#include <iostream>
#include "opencv2/opencv.hpp"
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/cudaarithm.hpp"
using namespace cv;
int main(int argc, char* argv[])
{
try
{
cv::Mat src_host = cv::imread("hdd.png", cv::IMREAD_GRAYSCALE);
cv::cuda::GpuMat dst, src;
src.upload(src_host);
cv::cuda::threshold(src, dst, 128.0, 255.0, cv::THRESH_BINARY);
cv::Mat result_host(dst);
cv::namedWindow("Result", cv::WINDOW_NORMAL);
cv::imshow("Result", result_host);
cv::waitKey();
}
catch (const cv::Exception& ex)
{
std::cout << "Error: " << ex.what() << std::endl;
}
return 0;
}
Here is the error:
The code execution cannot proceed because cudart64_91.dll was not found. Reinstalling the program may fix this problem.
It asks for 2-3 more dlls when I click on OK button, but I am not gonna write them here as I suspect the problem arises from the same source.
The problem is rather obvious. The dlls which are tried to be loaded, belong to the uninstalled version of CUDA (9.1), whereas I have now 8.0. I do not know why my Visual Studio 2013 tries to load the previous ones still.
Before anyone asks, yes I do have my newer installation (8.0) in my PATH. I am using Windows 10 x64, if it matters.
The real problem behind your error:
OpenCV was built with CUDA 9.1, this will not change even if you change the CUDA installation, thus it will the DLLs from CUDA 9.1 will always be required for every program that is compiled with OpenCV. Maybe a module does not have this linked and you can use it... but I am almost sure the main ones do and you won't be able to use them.
Possible solutions:
Build OpenCV with CUDA 8.0 then it will require is CUDA 8.0 DLLs and not the 9.1 ones.
Install CUDA 9.1. Both CUDA can be installed in the same computer, that is why they have this _80 or _91, this way you can have both paths and the computer decide which one is needed... I think it is not possible to have BOTH in the same program though, so be careful with this option. If it is only used by OpenCV then it will be ok.
I would recommend the first option, it is safer to stick to one library version...
The closest thing I can find is T popcount(T x) in the Metal Standard Library.
Is there a simpler version, like:
#include <x86intrin.h>
__builtin_popcount();
which compiles well for the Simulator but not for the iPhone device ...
Don't #include <x86intrin.h>:
// #include <x86intrin.h>
__builtin_popcount();
I have downloaded the new iOS 8 into both my phone and the latest Xcode onto my Mac. It all works fine but after loading up and trying the new iPhone 6 plus simulator when I try the iPhone 4s or 5 simulators (it works with 5s) I get the following error:
Undefined symbols for architecture i386:
"_fwrite$UNIX2003", referenced from:
leveldb::(anonymous namespace)::PosixEnv::~PosixEnv() in Firebase(env_posix.o)
leveldb::(anonymous namespace)::PosixEnv::~PosixEnv() in Firebase(env_posix.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
It seems very odd to me that I have been using the iPhone 4 simulator all morning but it is only after I try the iPhone 6 plus simulator that it breaks and I can't get its usage back
Answer provided in this link worked fine for me.
As per above link ,
In order to remove all of these error you have to create a *.c file (doesn't need a specific name) and copy paste the bellow code:
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
FILE *fopen$UNIX2003( const char *filename, const char *mode )
{
return fopen(filename, mode);
}
int fputs$UNIX2003(const char *res1, FILE *res2){
return fputs(res1,res2);
}
int nanosleep$UNIX2003(int val){
return usleep(val);
}
char* strerror$UNIX2003(int errornum){
return strerror(errornum);
}
double strtod$UNIX2003(const char *nptr, char **endptr){
return strtod(nptr, endptr);
}
size_t fwrite$UNIX2003( const void *a, size_t b, size_t c, FILE *d )
{
return fwrite(a, b, c, d);
}
normally everything should be ok.
fwrite$UNIX2003 is a symbol that is provided by OS X and is not part of the iOS Simulator runtime. iOS is always conformant and thus does not have legacy (non $UNIX2003) variants of functions (which are provided for binary compatibility with code built against older versions of the OS X SDK).
The common cause of the issue you are seeing is that you have an object file or archive (env_posix.o or a libsomething.a that contains env_posix.o) that was built against the OS X SDK and are trying to link it into your iOS Simulator executable. That is not supported as the two platforms are not binary compatible at that layer.
You need to rebuild env_posix.o against the iOS Simulator SDK.