Open an unknown file that was saved in Java - java

I am doing data recovery for a company. They need one type of file specifically, created in a java software package from the government. Filenames are lost, but the files themselves contain the project name. You can only find these when you actually open them in that software though, the files themselves do not contain any plain text. There are many thousands of files, so we can't expect someone to manually open them and update the filenames.
An added difficulty is that there are several different formats of these files: the most recent version of the software can't just open files from the previous version, it needs to "convert" them. This gives me the impression that the files are simply Objects that have been saved, and with each software version they change their Class so much that old files can't be cast into their new Class anymore. Or something. It's been a while since I programmed in java. :)
In any case, I "simply" want to read a single property of that object. But I don't have its Class to parse it with (which can be one of many, depending on the software version the file was saved with). I have the jar files from that software, but am hoping I don't need to start analysing that whole software package to see what it does exactly.
So I finally get to my question: can I open such a file (assuming it's indeed a "saved Object"), and somehow parse its contents as plain text? I'm sure that once that is done, I can retrieve where the project name is saved - hopefully in the same place across software versions.

If they are serialized objects, the file will start with a magic value of 0xACED and then a protocol version number, currently 0x0005.
If so, you can't really parse it other than by deserializing it with Java code, with all the relevant classes available on the CLASSPATH in the relevant versions. The reason is that any serializable class can provide its own code to write to the stream, which therefore only that class will understand correctly.

Related

Better way to extract files from apk

I've used this method for extracting the Java and XML files from the apk file but my Java files have a lot of modifications which for sure wasn't there in the original code.
For example, in one class appears for several times access$902, access$902 ,string of digits like 2130903064. They appear in the place of other methods or variables and the project doesn't build because of them.
Can be there extracted the original files or is a solution for this problem? Thanks
No.
Because build process generate .class files, and reverse engineering nevers get to the original code (AFAIK).
If the .apk file was generated using the proguard, this will be less readable and more difficult to understand.
The best alternative is use the AndroChef java decompiler, that runs in windows. This tool can allow you to change the method / variable / class names to be more readable, including the generated files.
The original code only the developer / company owns. I hope you are not using this for something illegal.

What are filesystem dot attributes or filesystem.attributes files?

I got a Java project from another developer and I found several files with these two names strewn around the source folder:
vssver.scc
filesystem.attributes
I know the first one is from Visual SourceSafe but what about the second? Are these files from Visual SourceSafe too?
It's difficult to search this as Google simply ignores the dot character in between, even if I put the whole thing in quotes.
Edit: File contents are binary but mostly have references to classes from Java and libraries:
After some digging, it looks to be a (presumably obsolete) Netbeans thing. The only real reference I could find is this Netbeans mailing list post from August 2000, which says it was used to store various IDE metadata about each file.
It is created automatically when you modify some attributes of a file
using the IDE itself. [...] Every file (including directories) stores its
attributes in a filesystem.attributes located alongside it (in the
same containing directory). FileUtil.extractJar specially recognizes
filesystem.attributes in a JAR, so if you jar up your directory then
when it is extracted the jarred attributes will be applied to the
extraction folder.
The post mentions a "future reimplementation" using an XML-based filesystem, which I think has happened by now. This later post mentions using the name .nbattrs to replace the old filesystem.attributes. I'm not a NetBeans user, but this seems to be what happened; for instance, I found an example in this gist.

How to load and save files in Android?

I need to load "configuration" type files for my program in Android, they are both .bin files containing dictionary data for the NLP library. I'm a bit new to Android still, and I'm having trouble finding a folder to place the files in so I can access them when the activity starts.
I also need to create/save/load a filetype specific to my program, and I don't know where to put it either. All I've been able to find on here is people using the getAssetManager() function to fetch input streams, but I explicitly need File objects for me to be able to load them into my pre-existing desktop software code I'd like to reuse (plus the libraries require them anyway)
I've also seen people using a "res/raw" folder, however the ADT did not generate this "raw" file when I made the project - so I'm not sure what to do there either.
Here is how I usually start the software in the desktop version, but I need to fetch these files in an Android environment:
brain.start(new File("memboric.core"), new File("en_pos_maxent.bin"), new File("en_sent.bin"));
core = brain.getInterpreter().getCore();
The memboric.core file can be generated, but I need to know WHERE and HOW to do so.
Thank you very much for your time, feel free to direct me to other resources if you feel this question is inadequate.
TLDR; how do I load "static" files for the software to function (needs to be included with software), and how to create/load/save "personal" files into an appropriate area of the device?
Use Context.getFilesDir(). Your application can read and write files in that folder and they'll automatically get deleted if your application gets uninstalled.
From that point forward, you can create, delete and read from files like any other Java application.
the "raw"-folder you can create it on your own. So check this out, which shows how to handle files in Android: http://developer.android.com/training/basics/data-storage/files.html

Get current state of Java interface from Jar file

This may be a weird request, but I'm going to ask it.
I have a open-source software, written in Java.I modified it for a project.
The software lets me place some elements on its interface and link the elements together.I modified the code to add some extra elements.
After compilation the software is generated in a executable .jar file.
The software only provides the option to sync with a certain server but I do not have access to that server.
Also,the software does not provide any save option to save the current state of the interface.
My question is : Is there a way to find and/or save the current state of the interface? Like an option to save current state in a temporary folder?
I tried to implement my own save option method but the software is huge, with many classes.all the classes are dedicated for the server sync.Hence, it is a difficult problem to solve.
Thank you!

Java - How to find that the user has changed the configuration file?

I am developing a Java Desktop Application. This app needs a configuration to be started. For this, I want to supply a defaultConfig.properties or defaultConfig.xml file with the application so that If user doesn't select any configuration, then the application will start with the help of defaultConfig file.
But I am afraid of my application crash if the user accidentally edit the defaultConfig file. So Is there any mechanism through which I can check before the start of the application that whether the config file has changed or not.
How other applications (out in the market) deal with this type of situation in which their application depends on a configuration file?
If the user edited the config file accidentally or intentionally, then the application won't run in future unless he re-installs the application.
I agree with David in that using a MD5 hash is a good and simple way to accomplish what you want.
Basically you would use the MD5 hashing code provided by the JDK (or somewhere else) to generate a hash-code based on the default data in Config.xml, and save that hash-code to a file (or hardcode it into the function that does the checking). Then each time your application starts load the hash-code that you saved to the file, and then load the Config.xml file and again generate a hash-code from it, compare the saved hash-code to the one generated from the loaded config file, if they are the same then the data has not changed, if they are different, then the data has been modified.
However as others are suggesting if the file should not be editable by the user then you should consider storing the configuration in a manner that the user can not easily edit. The easiest thing I can think of would be to wrap the Output Stream that you are using to write the Config.xml file in a GZIP Output Stream. Not only will this make it difficult for the user to edit the configuration file, but it will also cause the Config.xml file to take up less space.
I am not at all sure that this is a good approach but if you want to go ahead with this you can compute a hash of the configuration file (say md5) and recompute and compare every time the app starts.
Come to think of it, if the user is forbidden to edit a file why expose it? Stick it in a jar file for example, far away from the user's eyes.
If the default configuration is not supposed to be edited, perhaps you don't really want to store it in a file in the first place? Could you not store the default values of the configuration in the code directly?
Remove write permissions for the file. This way the user gets a warning before trying to change the file.
Add a hash or checksum and verify this before loading file
For added security, you can replace the simple hash with a cryptographic signature.
From I have found online so far there seems to be different approaches code wise. none appear to be a 100 hundred percent fix, ex:
The DirectoryWatcher implements
AbstractResourceWatcher to monitor a
specified directory.
Code found here twit88.com develop-a-java-file-watcher
one problem encountered was If I copy
a large file from a remote network
source to the local directory being
monitored, that file will still show
up in the directory listing, but
before the network copy has completed.
If I try to do almost anything non
trivial to the file at that moment
like move it to another directory or
open it for writing, an exception will
be thrown because really the file is
not yet completely there and the OS
still has a write lock on it.
found on the same site, further below.
How the program works It accepts a ResourceListener class, which is FileListener. If a change is detected in the program a onAdd, onChange, or onDelete event will be thrown and passing the file to.
will keep searching for more solutions.

Categories

Resources