module not fond when call Lua file in ios - ios

i am writing an ios game.i use lua to write the game logic.then i try to integrate lua files into ios program.i add the lua files to app resource.when i run the program, an error occur:
LUA_ERRRUN: a runtime error.
...4-489C-4A40-8582-F734FAAC428D/ChemLLK.app/llk_facade.lua:3: module 'lianliankan' not found:
no field package.preload['lianliankan']
no file '/usr/local/share/lua/5.2/lianliankan.lua'
no file '/usr/local/share/lua/5.2/lianliankan/init.lua'
no file '/usr/local/lib/lua/5.2/lianliankan.lua'
no file '/usr/local/lib/lua/5.2/lianliankan/init.lua'
no file './lianliankan.lua'
no file '/usr/local/lib/lua/5.2/lianliankan.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './lianliankan.so'
i wander whether "." in path is equal to the resource folder. and i don't know how to solve this problem.
who can help me?

When a script calls require, it searches a number of preset locations for the script. None of those preset locations are your application resources. Therefore, a script's require function will never find what it's looking for.
You need to register a handler for require that will look for the script in your resources.

Related

detect and remove all executable files in uploaded ZIP file

I am working on a web application using Rails which user can upload a zip file which contains its data/file/docs and etc. But I'm concerned with security right now, I want to scan the uploaded zip file and remove all kind of executable such exe, bash and etc how can I do this?
Edit: I am aware of clamav API for rails but it would only scan the file for malicious files not removing the executable, just imagine opening a wrong uploaded executable file in the server and the cost of this action server/business-wide!
First, it would be better and more robust to whitelist allowed file types, and not blacklist disallowed ones (eg. executables). So you should have a list of types you allow if that is possible in your application.
Then the question is how you determine the type of a file.
The trivial way is checking the file extension, but that's not very strong. It may still be good for a first check to avoid spending precious cpu time on further checks.
After that, you can use the filemagic database to quite reliably find the type of uploaded files. You have two options:
If your application runs on linux, you can call the file tool directly, something like filetype = `file -Ib #{filename}` to get the filetype. Note that filename in this example needs to be sanitized to avoid OS command injection!
If you want to support Windows too (or just want to avoid calling shell commands and have nicer code), you can use the ruby-filemagic gem:
require 'filemagic'
filename = 'yourfile.ext'
magic = FileMagic.new
filetype = magic.file(filename)
The problem with ruby-filemagic is that it's not maintained anymore, but it would probably still work fine to find executables.

Test an iOS module that writes to NSApplicationSupportDirectory?

I have this iOS module that creates and writes to some plist files in NSApplicationSupportDirectory, and I'd like to test that the module is performing these writes correctly. However, the writes don't seem to be going through - after calling the module method, the file seems to not exist. I've also tried writing to the desired file directly from the unit test module, and that doesn't seem to do anything either - using NSDictionary writeToFile returns NO, indicating that the write failed.
Is it impossible to write to this directory from a unit test environment, or is it more likely that I just screwed something up? And if it is indeed impossible to perform this write, what would the proper way to test this behavior be? If anyone needs more details, I'd be happy to provide them.
Thanks!
Discovered my own error: The NSApplicationSupportDirectory simply doesn't exist by default (this is why the write is failing). You need to create the directory before you can use it. See this post:
iOS: Can't save file to 'Application Support' folder, but can to 'Documents'

iOS AUSampler audiounit - file path issue with EXS audio files?

Following the Apple docs here I have been able to successfully load a GarageBand EXS sampler instrument into AUSampler in my iOS app by recreating, for example the following path within my app directory:
/Sampler Files/Funk Horn Section/nameofaudio.aif
iOS looks for the audio file in the following directory:
file:///Library/Application%20Support/GarageBand/Instrument%20Library/Sampler/Sampler%20Files/Funk%20Horn%20Section/'
However this doesn't work when I create my own EXS file. How does it know to remove the first part of the filepath if GarageBand?? I've even tried creating my EXS instrument and even created in the same GarageBand directory but it makes no difference:
Failed to locate sample '001%20VirusTI%20-%20SeaThr%2314A1B3.aif -- file:///macSSD/Library/Application%20Support/GarageBand/Instrument%20Library/Sampler/Sampler%20Files/VirusTI%20-%20SeaThreeHS%20v2/'
I've also tried manually editing the file path in the exs file with a text editor but nothing works.
The EXS instrument plays fine in logic. But my app can't find it.
Any help greatly appreciated.
The key here is that your source sampler file has to reference samples that come from any of these 'trigger' directory structures to work properly:
"/Sounds/"
"/Sampler Files/"
"/Apple Loops/"
"/EXS Factory Samples/"
"/SoundFont Samples/"
Your sample has to exist in a directory path with one of those triggers in it, and then the path has to match the exact same in your bundle. iOS looks for one of those triggers, then deletes everything before that, and uses that as the new search path in the bundle to find your sample.
It is tricky, but it will work this way if you make sure everything is in order.
I fought with this because my samples were stored in places without any of those keywords, and so it would never find them.

C FOpen() Open Documents Directory iOS

I need help getting access to the documents directory using only C on iOS.
I have my .c file looking for a specific file in the application bundle. I have no problem accessing this file. It looks like this: fopen("filename",
Unfortunately, if I want to move that file to the documents directory, appending "/Documents/filename" doesn't work.
I know how to access the file using an objective-c class, easily, using filesystemrepresentation. But I don't know how to do it only in C. Any help would be greatly appreciated!
Thanks!
Fopen defaults to the directory that the executable file is in, ".app/" - on iOS.
I was able to get to the documents directory by making a char of the Current Working Directory and then removing the last couple characters of the char to get out of the ".app/" bundle and then appending the Documents path to the end of it.

How do I find out the path of the file triggered by opening a file with a custom file extension?

How do i get the location of the file that i used to open my programs with?
Example: if i create a new extention ".xyz" say and i tell windows that i want to open the file type .xyz with myapplication, then it starts my aplication. Great, but how does my application get a handle on the file path of the file that was used to start it?
Also, is there a way to keep just one version of my app running and new files that are opened to just call a method in my application? For example if your using a torrent and you open 5 .torrent files they all just get passed to one application.
Side question: are all file extensions 3 letters long and is there a list of ones that are publicly used? If im creating a file extension I don't want to use one that is already used.
When you created your file association, you specified the command line that Explorer should run to activate your program. The shell puts the name of the document file on the command line, too, so in your program, check the command-line arguments. How you do that depends on your language and development environment. In Delphi, use the ParamCount and ParamStr functions.
When you create the file association, you can specify exactly where on the command line the document file name should go. Use %1 somewhere on the command line, and the shell will replace it with the file name. Since Windows file names frequently contains spaces, you should put quotation marks around the file name, so the command line in the file association would look like this:
ArthurApp.exe "%1"
With that association, double-clicking another document file will start another instance of your program. If you'd prefer to have the document opened in another window of the already-running instance, then you can write code to make your program look for already-running instances when it starts up. If it finds one, then it can communicate with that instance to tell it what file to open. You can effect that communication any number of ways, including mailslots, sockets, named pipes, memory-mapped files, and DDE.
The shell's file-association mechanism already has a way of communicating via DDE, so a second instance of your program wouldn't be started at all. Instead, the shell would start a DDE conversation with the already-running instance and tell it the new file name that way. However, DDE seems to be falling out of favor nowadays, so check out some of the other options first.
For your side question, no, extensions are not always three characters long. Look around, and that should be obvious: C code goes in .c files, Adobe Illustrator graphics go in .ai files, and new Microsoft Word documents go in .docx files.
But beware. If you ask for **.doc*, the results will include .docx files as well. That's because FindFirstFile matches both short and long file names, and long file names with long file extensions have three-character extensions in their short-file-name versions.
Rob covered the answer to your question(s) beautifully.
As to the last part, whether there is a public list of file extensions - not as such, but there is shell.windows.com, the web service Explorer uses to locate handlers for unknown file extensions. You can make up an extension then query shell.windows.com to see whether it's been registered. For example, to check whether the extension .blah has been registered by anyone on shell.windows.com, just open this URL in any browser:
http://shell.windows.com/fileassoc/0409/xml/redir.asp?ext=blah
Of course, replace the trailing blah with your extension.
You can find more details about this in KB929149 and in Raymond Chen's post Where does shell.windows.com get information about file extensions, and how do I get in on that action?.

Resources