Comments (10)
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.
from simplemagic.
The magic.gz file is located in the res folder and I updated the INTERNAL_MAGIC_FILE to point to "/res/magic.gz".
I put a breakpoint on the ContentInfoUtil constructor and and stepped through it's initialisation. It seems to be fine, the magic.gz file is found and read into your data structures.
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.
from simplemagic.
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/
from simplemagic.
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:
- Exe files (in windows) are not recognized
- BMP files generated in Windows explorer have a size of 0 bytes until you open it the first time. So this could not be recognized anyway.
- Plain text files are not recognized.
I used exactly these three files. I verified the function with another selection of files and your application works totally fine.
Maybe I can fix the recognition of exe files later.
Thank you for your quick help.
from simplemagic.
On the left you see the relevant section to recognize exe files.
On the right side you see the first bytes of an exe file.
The null bytes after the "MZ" string seem to be responsible for the missmatch...
from simplemagic.
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.
from simplemagic.
You can find putty.exe here: http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe
I just tried this version. The executable is not recognized.
The explorer exe located in C:\WIndows is not recognized either.
I think this can be reproduced with any *.exe files.
from simplemagic.
Excellent. Thanks much dude.
from simplemagic.
Note that the unit test for .exe files is broken.
ContentInfoUtilTest.java has:
new FileType("/files/x.exe", ContentType.OTHER, "MythTV", null,
"MythTV NuppelVideo v (640x480),progressive,aspect:1.00,fps:29.97"),
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:
else {
lastEscape = false; // don't leave escape active after non-whitespace escaped character
}
from simplemagic.
This has been fixed in version 1.7. Turned out that I was not handling some specific magic file line patterns correctly.
from simplemagic.
Related Issues (20)
- Problem with detecting Illustrator file HOT 4
- CMYK Jpeg files being incorrectly read with mime-type octet-stream
- RegexType reads a line for every byte in mutableOffset.offset HOT 1
- svg is not recognized HOT 1
- Doesn't recognize bitmap files exported from GIMP HOT 5
- Bash script not recognized correctly HOT 1
- findMatch() reads too much bytes HOT 4
- Possible bug inside of MagicEntryParser HOT 4
- Slim version without internal config files HOT 2
- Support for audio/amr HOT 6
- Questions about compatibility with Android HOT 3
- bug: Weird identification of heic image file HOT 1
- Upgrade built-in magic file and use external on Linux HOT 1
- How to use external magic db? HOT 1
- AWS cloudfront image return as content type html HOT 2
- ContentInfoUtil.findMatch([77, 90]) generates NPE HOT 1
- pcapng filetype support
- .xls file shows null in return of getMimeType
- Can't read the correct content type for .xlsx files (application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
- Request: add nullable annotations, to know what can return null HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simplemagic.