Hi I need to view code of an .exe file which has to be loaded dynamically. So, is there any method of obtaining source code of an exe file in Java or do I need another language to do that?
Standard Java will presumably not be able to do this because what you want to do is platform specific.
I don't know any library that is able to do this.
What you could do is take the exe, extract its code segments and compare their content to a list of opcodes. You could then for example simply iterrate over the bytes and create a list how often hex 0x90 is found, which is an indication for a nop.
Perhaps it is a better solution to simply disassemble the file (into "sourcecode") and count the occurences based on their text representation.
Related
I have >400 JPG files and a JSON file for each which contains the image tags, description and title. I've found this command
exiftool -json=picture.json picture.jpg
But I don't want to run this for each and every file.
How can I run this command for the folder containing the JPGs and JSONs or is there another way I can batch process these?
Each JSON file has the same name as it's JPG counterpart so it's easy to identify which files match up to each other.
Assuming your JPGs and JSONs have the same filename, but different extesion(e.g. picture001.jpg has an associated picture001.json,etc.), a batch for loop might work.
Assuming you've already cd-ed into the folder and the files aren't nested in folders, something like this should work
( for jpg in *.jpg; do exiftool -json=${jpg/\.jpg/.json} $jpg; done )
Note that this isn't tested. I recommend making a copy of your folder and testing there beforehand to make sure you don't irreversibly damage them.
I've also noticed you're using the java tag. I had to work with EXIF data in Java a while back (on Android then) and I used the JHeader library. If you want to roll your own little java command line tool, you should be able to use Java's IO classes to traverse your directory and files and the JHeader library to modify the EXIF data.
I'm making two Java applications one to collect data, another to use it. The one collecting will be importing a file from the other which will include data and images and will be decrypted.
I'm unsure what filetype to use. So far all of the data is in XML and works great but I need the images and was hoping not to have to rely on giving all the images in a folder with a path reference.
Ideas?
well, I think that the best way is to create your own format (.myformat or .data). This file will be in fact a Zip file that contains your XML file and images.
There is no perfect example writen in java as far as I know. However, here are some examples :
Not in java
The best example is, as #Bolo said, the odt format. Indeed, OpenOffice writes the doc in an xml file, and the images too. All that is wrapped in an odt file.
The .exe file is an other example. The C files and the resources are put in a single file. try to open it with 7-zip, you'll see.
The Skyrim plugins are .esp file that contain the dds, the scripts, the niffs (textures)...
In java
The minecraft texture packs are a zip file that contains a .mcmeta file (the infos) and the textures (.png)
Jar files are like exe.
If both programs are in java you could also go with serialization, which is basically saving an object as a file (suffix will be .ser I think) and then being able to retrieve it. You should google it, even if it won't help right now it is quite good to know about it.
I'd suggest using JSON. Gson is a decent library.
You can embed images as byte arrays.
Save the serialized string in a file with a preferred extension, read it from the second application, de-serialize, and reconstruct images.
You can convert binary image data to text with Base64 encoding and this way you can embed your images in XML. [1]: http://en.wikipedia.org/wiki/Base64
Basically, I want to be able execute a byte stream as a file, without writing said bytes to a file.
I want to do this in a windows environment.
You could say I want a to create a file, copy the stream to the file, and open the file as an executable, but I want the file to have no physical manifestation on the disk.
Thanks
This is not possible to do using the standard Java API. You will have to rely on some OS specific native implementations, either that do the whole thing for you, or that allow you to create some sort of RAM-disk on which you can place your temporary data and execute it.
Possibly related:
write file in memory with java.nio?
Supposing you bytestream is the one of a standard exe, and you don't want to call a whole virtualisation environnement, the short answer is no because internal adresses in the code wouldn't map.
Here's a more detailled answer :
process.start() embedded exe without extracting to file first c#
Someone know one method to get the mime type from byte array? Attention, i want to do that without external library, only native java.
There is a way to do that using Java 7, but it is kind of clumsy (um tanto "desajeitado"):
write the bytes to a (temporary) file,
use Files.probeContentType(Path) to check the contents of that file
if the bytes came from a file you could use probeContentType directly on it.
EDIT:
not very useful, at least on Windows: probeContentType seams to primarily use the file extension to determine the file type [:-|
A task I'm working on has grown. I need to open up some rtf documents using Office 2010, edit them, and then save them. Is there a way to automate this programatically using Java 6? I'm not aware of any java open source offerings that can run Office 2010 for something like this or what options there are for this type of task?
You can use the java.lang.Runtime and java.lang.Process to execute external programs through a sort of command line approach. Check the exec method in Runtime which uses a String[], it's the one that gives you program and argument options.
Process:
http://download.oracle.com/javase/6/docs/api/java/lang/Process.html
Runtime:
http://download.oracle.com/javase/6/docs/api/java/lang/Runtime.html
Here is a general idea of how it's used
http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/
Also here is a little bit about opening Word through a command line approach
http://support.microsoft.com/kb/210565
I've used this approach myself to open files in notepad and such
However, if you want to open these files and apply some automated edit to them, there may be a much different way of doing that, that may not require Word.
Have you tried this, which allows you to read write and manipulate RTF files
RTF is just text. The simplest solution that I can think of to to create the template document in Word and save as RTF. Then you can perform string replacement in the text file. A quick test of $HelloWorld$ work just fine so let's assume that single fields are no problem.