How to rename a file in Appium after copying it in to the device using pushFile()? - appium

I am using pushFile() to copy a file in to the folder "/sdcard", which gets copied to "/internal storage/" folder inside the device, but with a different name and extension like "Appium.tmp". For our threat detection app to work it has to be having a name like "<my_malicious_app.apk>" file.
How do I rename the file after being copied from "Appium.tmp"
to "<my_malicious_app.apk>" ??

Related

Using backslash (\) to indicate subfolder in ios

Please bear with me while I try to explain my problem
Suppose the folder structure of my download container's Document folder is represented /A/B/C/, which I have obtained through the proper API's in ViewController.m. I am porting a PC C++ project to ios, where, at one point the program decodes it's input to get the name and full path of a file, for example, as images\background.png. Since my program automatically locates the Document folder through API's, it is supposed to create the folder structure /A/B/C/images\background.png. The program I am porting to ios also contains a directory creator function, which detects the locations of / in the pathname string, checks whether a directory by that name is already present or not (for example, it would detect /A as being present, but /A/B/C/images would be detected as absent, as images has not been created yet). The function creates all the subfolders in this tree if they do not exist already. After the directory structure has been created (/A/B/C/images), the program does something like this to create the file (background.png in this example):
.
.
.
Create directory structure
fid = fopen(`/A/B/C/images\background.png`, "wb"); // note that full path `/A/B/C/images\background.png` is automatically determined by the program by the time it reaches this point
.
.
file writing code
fclose(fid)
.
.
My problem is that after creating the folder images, it creates the png file as images\background.png, instead of creating a background.png inside the images folder. I have already ported this program to android NDK and it creates the png file inside the images folder as expected, so I can only assume that android considers \ to indicate a subfolder while ios doesn't.
What can be done in order to get background.png created inside the images subfolder? Any idea will be appreciated.

Unable to Locate Realm File on Device

I am attempting to locate the realm DB file on my device (iPhone) and I followed the steps here and here. However, I do not see any realm files in the folder AppData/Documents.
I print out the URL path as I run the app on my device and my simulator, and this is what I see:
//On device
/private/var/mobile/Containers/Shared/AppGroup/C7332EE4-1567-4C96-8392-7FBD0DC9C863/DB/default.realm
//On simulator
/Users/MYNAME/Library/Developer/CoreSimulator/Devices/D205C50D-F432-4A1F-80CB-FB3D91E0A1EA/data/Containers/Shared/AppGroup/5E67A740-A338-4583-9B9D-461F5D1A734A/DB/default.realm
The URL written on the simulator appears to be any default URL where the Realm DB is written to. I can't seem to understand why can't I find the realm file at AppData/Documents on the actual device.
Realm files are only created on disk when you call Realm() for the first time. Once you've created an instance of Realm, you can find the exact file route of that Realm by printing out realm.configuration.fileURL. You can normally use Realm.Configuration to set a different location of the Realm file on disk as opposed to the Documents directory.
Both of those file paths you displayed show that the file is located in a folder named DB and it appears to be in an app group (eg, a shared folder between apps and extensions) instead of your app's default Documents directory.
So with that being said, it would appear that somewhere in your app, a custom Realm.Configuration object is being used to create the Realm file somewhere else, which would explain why you can't find it in Documents.

How do I put content into the iOS Documents folder at compile time, using Xamarin?

I have a data file that I need to include with my app when I distribute it. When loading any files in the app, I prefix the file name with:
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
This works great for anything I create within the app (and for reading back), like files I download in response to a user action. But I can't for the life of me figure out how to place files there when I build my app in Visual Studio.
I've tried making a "Documents" subdirectory in the special "Resources" folder, but that didn't work (I tried setting the "Build Action" to both BundleResource and Content). When I look at the folder for my app (from using the simulator) I can see that in the "Documents" folder there's all the files I downloaded, but I can't find my data file that I'm trying to bundle ahead of time. I even searched my entire hard drive on the Mac and still couldn't find said data file.
The data file isn't an image, if it matters. Just raw binary data. How do I set it up so that this file goes into the proper documents directory at compile time, so that I can read it using the SpecialFolder.MyDocuments prefix? Thanks.
You can't. You can include files in your app bundle, and then at startup copy them from the bundle into a user folder. But this won't happen automatically.

How do I get my pre-populated Default.realm file onto a device?

I have a realm file that is already populated with data that needs to be there when the app is loaded on a device.
What can I do to get the realm file onto my device for testing and what do I need to do to make sure it is already there when someone downloads the app from the app store?
I am using Swift.
Add your database file to the Xcode project, i.e. "preloaded.realm"
Make sure you select the add to targets, when first dropping in your file
Then (taking from the migration example) you can do something like this to copy that preloaded file to your default directory. This will create a read/write realm
// copy over old data files for migration
let defaultPath = RLMRealm.defaultRealmPath()
let defaultParentPath = defaultPath.stringByDeletingLastPathComponent
let v0Path = NSBundle.mainBundle().resourcePath!.stringByAppendingPathComponent("preloaded.realm")
NSFileManager.defaultManager().removeItemAtPath(defaultPath, error: nil)
NSFileManager.defaultManager().copyItemAtPath(v0Path, toPath: defaultPath, error: nil)
Here is a link to that general code https://github.com/realm/realm-cocoa/blob/master/examples/ios/swift-2.2/Migration/AppDelegate.swift
You'll first have to create the realm file you want to ship with your app. Once you have that, add it to your app's Xcode project and copy it into the bundle (which Xcode should do automatically).
At this point, the app should be able to access the bundled file (you can use NSBundle.mainBundle().pathForResource(_:ofType:) to get the path).
You can either create a read-only realm at this path (see RLMRealm(path:readOnly:error:)), or copy it to your Documents directory to create a read-write realm file.
You should refer to our migration example for more details on how to do this.

How to load json file from arbitrary folder inside project?

How to load json file from arbitrary folder inside project ?
I have data folder and inside file user_data.json, but system.DocumentsDirectory points to another ( I have copied from net, I am pretty new to lua and corona)
function custom_load( strFilename )
local path = system.pathForFile( strFilename, system.DocumentsDirectory )
local file = io.open( path, "r" )
if file then
local content = file:read( "*a" )
io.close( file )
return contents
else
return ''
end
end
Your file has to exist before you can read it. Perhaps a brief description of the Corona SDK folder structure will help you understand what's going on.
All apps, regardless of iOS, Android or Corona while running in the simulator are made of up an "Application Bundle". In iOS terms, this is the .app file that Corona SDK produces. In Android, it's the .apk file. The files in the folder with your main.lua and any folders you create there are part of this app bundle. For security purposes, this folder is "Read Only" to your app. Corona SDK allows you to reference files in this folder as system.ResourceDirectory.
Once the app is created and running on the device, Three other folders are created in your App's Sandbox. This is an area that only your app can access. These are:
system.DocumentsDirectory, a readable and writable folder to store things you want to keep around with your app. This is where you would save settings files, files that your users create with your app and so on.
system.TemporaryDirectory, a readable and writeable folder to store things you don't expect to be there. It's where you can download files to that you intend to throw away.
Apple's iOS has a 3rd folder that Corona calls system.CachesDirectory which like system.TemporaryDirectory has not guarantees on now long files that are stored there will last, but the intent from Apple is if you can download it from the net and it gets deleted, you can always download it again. On Android, system.CachesDirectory and system.TemporaryDirectory are the same folders.
Since the assumption is the app is the only thing that can write to it's sandbox, files in system.DocumentsDirectory have to be created by the app. You can't just put a file there (okay there are ways in particular on the simulator, it's just a folder on your Mac or PC if you know where to look, but that's not realistic of a user loading your app) so your app has to create the file in system.DocumentsDirectory.
If the file has not been created, then trying to use io.open() in "read" mode ( the "r" ) to open a file will return nil because the file does not exist.
Dont worry its very simply , just refer this code you will automatically code after reading this.
https://github.com/robmiracle/Simple-Table-Load-Save-Functions-for-Corona-SDK/blob/master/main.lua
In pathForFile use
local path = system.pathForFile( "data/user_data.json", system.ResourceDirectory)

Resources