extract APK file contents using .NET tool - c#

I used apktool to extract an APK file contents. But for some reasons I need such a tool written in .NET so I do not need to install the JDK in the server.
Is there such a tool?

No. There is no such a tool. You need to start a Process in C# and run the batch file with the arguments using ProcessStartInfo class

I think in another approach, take the APK file and create a Java program that extracts the info I need such as package name, icon resource etc... and then expose it as COM object and use it in my .NET project.
After deep research we can not extract that info in standard functions in Java, since the only way to extract the info is to unzip the APK via the APKTool and read the manifest from the file system.
Another way but hard is to write your own extractor which involves in deep knowledge in the format of the APK.

Related

Accessing StreamingAssets resources from C++ DLL in Unity on Android

I have developed a C# application in Unity for Android. Additionally, I built a custom external C++ DLL which is properly loaded and accessible from the C# code. I have also added some .xml files into the StreamingAssets folder which works as expected as I can see those files loaded into the .apk.
Currently my problem is that I'm not able to access such xml files from my C++ library. On one hand I'm not sure how to do it correctly, on the other I tried multiple unsuccessful approaches including trying to understand in which cwd was my DLL loaded and then navigate to the files I needed (which didn't work as I constantly receive an access denied error).
EDIT:
Your replies actually put me on the right track and I solved the issue as follow:
During the OnStart() phase of my application, I use the UnityWebRequest class to extract from the JAR file the required files and then I save them in the Application.persistentDataPath
After that, I pass to my DLL the new path to each file which allows me to access them without any issue.
On Android the StreamingAssets are in a jar. That may well be the reason why you can't access them, but as you can see in the manual you can use the WWW class to retrieve files there.
On Android, the files are contained within a compressed .jar file
(which is essentially the same format as standard zip-compressed
files). This means that if you do not use Unity’s WWW class to
retrieve the file, you need to use additional software to see inside
the .jar archive and obtain the file.
(https://docs.unity3d.com/Manual/StreamingAssets.html)
On Android, the files are contained within a compressed .jar file
(which is essentially the same format as standard zip-compressed
files). This means that if you do not use Unity’s WWW class to
retrieve the file, you need to use additional software to see inside
the .jar archive and obtain the file.
A JAR is a package file format typically used to aggregate many Java class files and associated metadata and resources into one file for distribution. JAR files are archive files that include a Java-specific manifest file. They are built on the ZIP format and typically have a .jar file extension.
This means that you can work with jar files the same way as you do with zip files.
There is a fork for minizip with examples on how to use it.

How to merge a file to a precompiled exe application

I have designed and created two seperate windows application ( say winapp1 and winapp2). Winapp1 creates a file(say file.txt) in the disk containing some text. And I need to merge this file.txt with precompiled version of winapp2 ie winapp2.exe so that the winapp2 can display it.
Winapp1 creates a file with different contents each execution time. And for each file there will be a copy of winapp2 that needs to be merged.
Is there a way to this? If there is, help me.
And my English is not so good. Thanks for reading this.
The easiest solution, (assuming that releasing the source code for winapp2 to the system that runs winapp1 doesn't present problems) is to have the entire source for the winapp2 project accessible to winapp1. The source should include a blank copy of the file as an embedded resource. Winapp1 can then modify the source file and use MSBuild to build a fresh copy of Winapp2.
To modify the text file, you should be able to just use the normal file manipulation .NET methods and to call MSBuild, you may be able to do it via a .NET class, but you can certainly just call the msbuild executable from the relevant .NET framework folder in %windir%\Microsoft.NET\Framework\ and pass in the full path of the project file.

create self extract file from folder on server ASP.NET C#

i need it to be self extract file and after the user downloads the file to his computer and run the EXE file the installation of the software starts automatically. as can be done with WINZIP and WINRAR.
I tried to use:
http://sevenzipsharp.codeplex.com/
and could not succeed.
I know i can do it with "dotnetzip" but from what I understand it need .net 2.0 for the self extract EXE file and i do not want to be dependent on .NET framwork.
You can use a batch command to create the file and check the output for success or failure. Just use a compiled standard version of 7zip and then run the command:
"7z.exe" a -t7z -m0=LZMA -mmt=on -mx5 -sfx7z.sfx -wc:\ParetnDirectoryOfFolder D:\MyNewSelfExtracting.exe D:\Users\Martyn\FolderToBeZipped
Once you have confirmation, you can store the details in a database for retrieval later, or how ever you want the interface to go.
Sorry it's not a coded answer, but from the looks of it, you are very close to completing!

Embed exe file in a Class library

Is it possible to embed an exe file in a class library (dll file)?
I want to use this exe without the necessity of copying it manually to my workstation. In other words, if I want to use my C# class library in another app, I won't need to copy these exe files in a folder and pass the path of this folder in my app.
If there is a way how to do this, it would be great.
sorry but what I mean is just, I made a library for screenshots using Selenium Webdriver and when creating a new webdriver object, I need to pass the exe file of the webdriver.
what I need the most is that I don't want to copy the exe file if I will use this library to another workstation for example, I want everything to be packaged as one file
Thank you
Well, technically you can embed a binary file as a resource within a DLL (by adding the file as a binary resource through the project properties), but you'll still need to save the file to disk in order to execute it (which is assume what you're trying to do) and will possibly have security issues unless your application is fully trusted.
If the binary file is a resource you can extract the bytes from the static Properties class:
byte[] exe = Properties.Resources.MyExe;
and save it to disk like any other byte array.
If you own the code for the EXE then it would be a lot better for you to turn your EXE code into a library. Then you'll be able to refer to that library from anywhere and call any public functionnality it has. It's a far, far, FAR better approach.
Should you still need to run that code as a standalone process, nothing prevents you from making a new EXE front that will refer to that same library.
Now if you do not have the code, then depending on your deployment strategy you may prefer creating a reusable deployment component / module that can be attached to other application setups.

Difference between .jar and .dll file

I am learning Java these days and I've spent a lot of time with .NET so when I want to export or import libraries, they are usually in .dll format which is called assemblies in .NET environment and they are compiled to IL and they can have resources like images, XML, audio and so on, anyways.
I am wondering the same process in Java as well. I've read documents but they actually confused me a little bit and to clarify things out I need your help guys.
Questions:
.NET Assembly is the same thing as Java .jar?
.dll contains compiled IL code and .jar contains compiled .class/byte code files?
They say resources, what kind of resources we are talking about here? Images, .txt files, etc. or all of them possible?
I've examined AWS (Amazon Web Service API for java) and I saw three .jar file and they are
aws-java-sdk-1.1.1.jar
aws-java-sdk-1.1.1-javadoc.jar
aws-java-sdk-1.1.1-sources.jar
and they contain .class files - java documentation in html format and .java files which are still not compiled. So then I've realized .jar doesn't just include compiled byte codes (.class) and also other things.
When I want to import java libraries, will I always need to import .jar files?
When I want to export my own java libraries, should I need to export in .jar file.
Thanks for help in advance.
Is a .NET Assembly the same thing as a Java .jar?
They play the same role, yes.
.dll contains compiled IL code and .jar contains compiled .class/byte code files?
Yes. Although JARs are just zip files (you can open them in your favorite Zip tool), so they can really contain just about anything.
They say resources, what kind of resources we are talking about here? Images, .txt files, etc. or all of them are possible?
Any file type is allowed in a JAR. Your Java code can access the contents of files within the jar via, for example, getResourceAsStream or getResource. Obviously .class files in a JAR are treated specially (as bytecode).
I've examined AWS (Amazon Web Service API for Java) and I saw three .jar files and they are: aws-java-sdk-1.1.1.jar, aws-java-sdk-1.1.1-javadoc.jar, aws-java-sdk-1.1.1-sources.jar
The above packaging is fairly common. Sometimes people use .jar as an alternative file extension to .zip. I find this practice confusing, but it is not uncommon, and Amazon has done it in this case. I think this practice became more common with the launch of Maven, which stores reference source code in files named .jar.
aws-java-sdk-1.1.1.jar - This is the only file necessary for compilation and execution. It contains the classes (.class files) and resources necessary for the library to function.
aws-java-sdk-1.1.1-sources.jar - This is just a zip file that contains the source code (.java files) for the library. It is not necessary for compilation or execution. It is provided to help you troubleshoot problems you may encounter while using the library. You could unzip this file and read the source code from your hard drive. However, your IDE can probably utilize this file directly by creating a "source attachment" to the main library JAR. With this library->source association set up in your IDE, your IDE will be able to show you the source code of the library when you use your IDE's "Go to Definition" feature on a library class.
aws-java-sdk-1.1.1-javadoc.jar - This is just a zip file that contains the JavaDoc for the library. Again, it is not necessary for compilation or execution. JavaDoc is just HTML, so you could unzip this file and read the JavaDoc HTML directly from your hard drive. However, most IDEs can create a "Javadoc attachment" to the main library, which allows you to pull up context-sensitive JavaDoc for the library from within the IDE. Actually, most IDEs can generate the JavaDoc on the fly from the -sources.jar, so I rarely use Javadoc jars anymore.
When I want to import Java libraries, will I always need to import .jar files?
It's usually called "adding JARs to the classpath", but yes. You pretty much always need to help Java find all the JARs you're using by constructing a classpath whenever you build or execute. In general, using JARs and classpaths is a much more manual and explicit process than using DLLs in .NET. For example Java has no direct equivalent of .NET's "global assembly cache"; also vanilla Java will not automatically load .jars from the working directory.
There are a few other techniques for creating a more "automatic" feeling classpath, but they are kind of advanced: Manifest.MF classpaths are possible, for example -- but this approach is used infrequently as it is brittle. As of Java 6, Java has limited support for using wildcards in the classpath.
When I want to export my own Java libraries, should I need to export in .jar file
This is standard, yes.
I can answer part of that question :-)
As I understand it, a jar is just a "Java Archive" file. It can contain anything you want, but is most often used to distribute binary versions of libraries. It can also be used for distributing executables -- double-clicking a JAR file will launch the application, if that's how it's been packaged.
As such, it may be difficult to tell what a particular jar file is intended for. For example, what is aws-java-sdk-1.1.1-sources.jar?. Is it a self-installer? A compressed code archive? Without reading documentation, it's anybody's guess.
Edit: case in point, I just downloaded the JAI jar file assuming it was a binary build of the library. But in fact, it contains the installer application.
To answer this specific question.
aws-java-sdk-1.1.1.jar
aws-java-sdk-1.1.1-javadoc.jar
aws-java-sdk-1.1.1-sources.jar
The 1) is the compiler java archive file (jar), which in .NET is called a DLL. The 2) is the javadoc. An HTML documentation of java classes (found in 1)) along with method description. The 3) is the source code (java files) of 1).
When I want to import java libraries, will I always need to
import .jar files?
When I want to export my own java libraries, should I need to
export in .jar file.
For 1) If you need to use a class that is found in a jar file, then you'll need to import that jar into your project.
For 2) You don't need to. You can bundle your dependency jars into your library or package each into their own jars and import them into your project.
.NET Assembly is same thing as java .jar? Answer: Yes.
.dll contains compiled IL code and .jar contains complied .class/byte code files?
Answer: .jar files is an archived file of java resources, classes, images/icons/etc. that is necessary for an application, just like in .DLL. Class files contains compile java source codes (Called java bytecode).

Categories

Resources