-
-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
problems matching Windows executables #5
Comments
I suspect that it cannot find your magic.gz file which should be at the top of the classpath? Can you put a breakpoint in ContentInfoUtil.readEntriesFromResource(...) to see if it is being found? It also may be that those file types are not in the magic file. If you attach the files in question I can take a look at them. If you need to specify the specific location of the magic file, I'd use the ContentInfoUtil(String, ErrorCallBack) constructor to specify the location of the magic file in the resource path. ErrorCallBack can be null. I've changed the code to throw an exception if it can't find the magic file. Right now it just sets it to be null. |
The magic.gz file is located in the res folder and I updated the INTERNAL_MAGIC_FILE to point to "/res/magic.gz". If I change the path to the magic.gz file it complains that it can not find the file. Stepping through the findMatch method I can that the probe is read from my input stream and the application tries to find a matching pattern in MagicEntries.java: public ContentInfo findMatch(byte[] bytes) As windows executable I tried the "putty.exe" file, but I'm still getting a null object. |
Hrm. It may be that my magic file does not have information about Windows executable. It's roots are in Unix-land. I just found this. http://www.delorie.com/djgpp/doc/exe/ |
I got it! :) I tried this on a unix machine with some files from the filesystem and it worked. After that I went back to my windows machine and tested some files I copied from unix. The program is still functional. After that I tried again with the files I used at first. It does not work. So I took a closer look at the files:
I used exactly these three files. I verified the function with another selection of files and your application works totally fine. Thank you for your quick help. |
Cool! Can you post the executable somewhere or tell me which path it is on a "standard" windows computer? I'll add it to my unit tests. |
You can find putty.exe here: http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe The explorer exe located in C:\WIndows is not recognized either. |
Excellent. Thanks much dude. |
Note that the unit test for .exe files is broken.
which is clearly a copy and paste error from a few lines above. I noticed this after fixing another error that was causing the test to fail on "/files/x.gz". After fixing that issue, the bogus test for x.exe started failing (as it should have been all along). The problem that caused the x.gz test to fail was in the method findWhitespaceWithoutEscape. It needed the following else clause added to the if statement:
|
This has been fixed in version 1.7. Turned out that I was not handling some specific magic file line patterns correctly. |
Hi,
I am writing a file analyser in java and plan to use your simplemagic application to determine the file type of an input stream. To use your application as comfortable as possible I compiled it into a jar file including your magic.gz file.
Unfortunately the findMatch Method always returns null for all types on inputstreams. I tried windows executables, bitmaps, plain text, ...
Is there any error in the current version of your code or do I just call it in a wrong way?
This is my test code:
You can see the folder structure of the simplemagic.jar file attached.
![simplemagic](https://cloud.githubusercontent.com/assets/5543041/3090319/c46cea98-e58a-11e3-8ccf-ba86a94aff27.JPG)
The com folder includes the class files of your code. The res folder includes the magic.gz dictionary file.
Thank you for your help.
The text was updated successfully, but these errors were encountered: