Intrigued
11-19-2005, 11:57 AM
http://www.garykessler.net/library/file_sigs.html
Brett
11-21-2005, 08:21 AM
That could make a neat AMS60 project: "What's My Type?"
Just read that data block in with Lua's io functions and do numeric comparisons. This would be a neat way to identify unknown files or files that are trying to pretend they are something that they are not.
Brett
11-21-2005, 08:56 AM
In fact, here is some code that I was playing around with in case you are interested in this sort of thing. It is not complete, but has a few types started for you:
tblTypes = {};
tblTypes.EXE =
{
2, -- Data size
77, 90, -- Data
Name = "Windows Executable/DLL/OCX/Screen Saver" -- Name
};
tblTypes.HLP =
{
4, -- Data size
76, 78, 2, 0, -- Data
Name = "Windows Help File" -- Name
};
tblTypes.PDF =
{
4, -- Data size
37, 80, 68, 70, -- Data
Name = "PDF File" -- Name
};
function GuessTypeRawData(rawData)
local strType = "Unknown";
for strName, tblType in tblTypes do
-- Break out of loop if found...
if(strType ~= "Unknown") then break; end
local bMatch = true;
local nDataSize = tblType[1];
for i = 2, (nDataSize + 1) do
if(bMatch)then
bMatch = tblType[i] == string.byte(rawData,(i-1));
end
end
if(bMatch)then
strType = tblType.Name;
end
end
return strType;
end
function GetTypeOfFile(strFilename)
local strRet = "Unknown";
fileHandle = io.open(strFilename,"rb");
if(fileHandle)then
local Data = fileHandle:read(50);
strRet = GuessTypeRawData(Data);
else
strRet = "ERROR: Could not open file: "..strFilename;
end
if(fileHandle)then
fileHandle:close();
end
return strRet;
end
Just call GetTypeOfFile with the filename as an argument.
Corey
11-21-2005, 02:04 PM
I hate files who pretend to be something they're not. In fact I think I saw an ABC afterschool special once which dealt with that very issue. They should just be proud to be themselves and not worry about what the other files think. :yes
Intrigued
11-21-2005, 03:57 PM
Thanks Brett. I'm checking that out now.
Powered by vBulletin™ Version 4.0.6 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.