Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
in my application i read a file, calculate its MD5 hash, cypher it with AES128 and write it inside file comments.
Thats because i need to ensure that file is not manipulated.
Sadly, when i write something inside file's "comments" properties its MD5 change and my work become useless.
So, i want to read my file excluding file's properties and only then calculate my HASH.
Now i read my file with this function:
function MD5File(const FileName: string): string;
var
IdMD5: TIdHashMessageDigest5;
FS: TFileStream;
begin
IdMD5 := TIdHashMessageDigest5.Create;
FS := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite);
try
Result := IdMD5.HashStreamAsHex(FS)
finally
FS.Free;
IdMD5.Free;
end;
end;
How can i get the "file properties" size? i suppose they are on the header OR the footer, so if i know the size i can exclude the first or the last part of the file
edit:
more information: i store the information manually editing the file properties (right click -> properties)
i too suppose that editing those information must not alterate my MD5.. but it does for some reason!
I read the file AND calculate its MD5 with the function in my post.
My problem is that when i write any value inside the comment the file's hash change and i'm writing a string based on file hash.
i think i will just wipe the "comment" properties before calculate hash.
Your premise is wrong. The "Comments" data you are entering is stored within the file in the EXIF part of the .JPG file. It does not have a fixed offset, so it's not easy to exclude it from your hash. You'll need to parse the .JPG file and manually skip over the portions of the file that you do not want to include in your hash. Read up on .JPG files and EXIF information stored therein.
Or rethink your premise. If you simply want a hash over the image portion, you can load the image as a TBitMap and iterate over all the pixels in the image (a very slow process) and include their colour code in your hash, thus excluding any data that isn't an actual part of the image itself.
Both these methods will mean that you can't do what you are attempting on anything other than files for which you know the file format (unless they are all image files that you can load into a TBitmap and thus only include the pixels in your hash). You cannot, for example, allow people to change comments or other things in f.ex. Word documents or PDF documents, unless - again - you read the file manually and only calculate a hash over the parts that you don't want to allow people to alter.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 months ago.
Improve this question
By using the Win32 API in C, I am trying to open a file explorer and make the user select an file, for which the absolute path will be put into some other function.
I have looked at Microsoft's resources [1-2], in order to try to utilize CoCreateInstance. However, they specify that five inputs should be given, while every other example, both in [1] and in [2], only gives four inputs. Compiling with only four inputs gives me an error in MinGW's GCC.
How can I create retrieve the absolute path from a file that the user specifies through the file explorer?
Moreover, is it possible to apply a filter to the file explorer such that only specified files can be seen? I can only see that this is possible in C#, and not C [3].
How can I create retrieve the absolute path from a file that the user specifies through the file explorer?
When calling CoCreateInstance(), you have to give it 5 parameters. The IID_PPV_ARGS seen in many examples is just a preprocessor macro provided for convenience to generate the last 2 parameters in a type-safe manner, but it is not a requirement. You can supply the last 2 parameters manually, as long as you are careful with them. For example:
IFileDialog *pfd = NULL;
CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pfd));
Is really just the same as this:
IFileDialog *pfd = NULL;
CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, __uuidof(IFileDialog), (void**)&pfd);
Aka:
IFileDialog *pfd = NULL;
CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_IFileDialog, (void**)&pfd);
Moreover, is it possible to apply a filter to the file explorer such that only specified files can be seen?
Yes. Use the IFileDialog::SetFileTypes() and IFileDialog::SetFileTypeIndex() methods.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
When I create a symbol layer the text field is wrapped if the text becomes too long. I'm not able to figure out why/when the text is to long. It seems to depend on different things e.g. font type, text size and text length.
I tested the text length by using this example code. I replace Cafeteria with the alphabet with space between each character. It then wraps to a second line between m and n and that's to few letters on one line for our use case. https://azuremapscodesamples.azurewebsites.net/Symbol%20Layer/Formatted%20text%20field.html
I have been working with mapbox. They have a setting "text-max-width" that solves this issue.
I have checked the javascript code that comes with the npm package azure-maps-control and it doesn't implement support for "text-max-width".
Do anyone know how to fix the wrapping issue or if the package azure-maps-control are going to implement support for the "text-max-width" setting?
There is no option for this today, but I've added it to the feature request list. As a work around, you could do the following:
var layer = new atlas.layer.SymbolLayer(datasource);
map.map.setPaintProperty(layer.getId(), 'text-max-width', 15);
I need help about tiff files. I need to resolve tags and return user image details (such as imageWidth, imageHeight, orientation etc.) without using any special library. With this and this I resolved header and found first IFD, but I couldn't understand finding tag and next inside a single IFD.
for example, documentation says,
Offset - 2+x*12
Datatype - Tag structure
Value - Tag data
but there is not any information about x. OR it says 2+(number of tags in IFD)*12 for next IFD offset, but the result is out of range.
In conclusion, I want to know how to find tags address and get their data, and find next IFD.
I want to display mat file's content to see all the results. I know that I can load it and then double click on it the content are display in the workspace, this case happen when the mat file content few information but when I have mat file content information for more than 13000 record I can't display it. could please any one help me to find any way to display mat file as table?
thanks
I do not know the format of your data (multi-dimensional, structs, cell-arrays), but there is a function called "openvar" which can be very useful for these things.
Let's define a large random 500x500x10 3d-matrix:
large = rand(500,500,10);
This variable contains 2.5 million double-values and takes up close to 20MB of memory. Opening this in the variable editor by double click in the Workspace window on "large" will usually (atleast on my system) give the following message:
"Cannot display summaries of variables with more than 524288 elements."
But you can use the "openvar"-function to open certain parts:
openvar('large(:,:,1)'); %# pass the argument as a string.
This will open the first "layer" of matrices in your Variable Editor (a 500x500 matrix in this case). This is useful if you need to look into certain parts of a large variable.
Of course you can always define new variables that contain subsets of your larger variable:
less_large = large(:,:,1);
... and then open "less_large" in the variable editor by double clicking on it in the workspace-window. But sometimes the "openvar"-method is a bit faster/easier.
You have a few options. Starting from a clear workspace, you could load the mat file into the workspace. Anything now in the workspace is in the mat file. You can use the variable viewer or parse with scripts.
If you have the Simulink toolbox, you can use Simulink.saveVars to save the contents of the workspace to a human readable m-script that would generate the same contents. It's a shame that you need Simulink to do this, as this function has nothing to do with Simulink.
How about after loading the data, and use whos to display the variables in current workspace? Note that you may want to clear all the other variables before displaying them.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have a huge .bib file generated automatically from Papers for Mac and all the capitalization in the .bib is already the way I want it, but it doesn't have {} brackets on word like RNA.
Is there a way to force BibTeX to keep the capitalization rather than change some words to lowercase?
I agree with Killian that the right thing is to put {}s to conserve capitalisation, but I don't recommend doing this always, since the behaviour is wrong in some contexts, and not automatisable, but instead the right thing with Bibtex is to do the following:
Put book and article titles into title case (i.e., capitalising all significant words [1], but not protecting them yet);
Protect the capitals of all proper names, e.g., From {B}rouwer to {H}ilbert;
Protect the capitals of all technical acronyms, e.g., The definition of {S}tandard {ML}; and
Protect the initial word of a subtitle, e.g. the {W}ittgenstein's Poker: {T}he story of a ten-minute argument.
Don't protect lowercase letters: this prevents Bibtex from converting the string to all-caps, which is required by some obscure bibliographical styles.
If you have been using a spell-checker, then the contents of its database will, with luck, contain nearly all of the material you need to know to capitalise properly: spell-checker's store information on which words are all-caps, and which are capitalised as proper names. If you can programmatically match words against this, then you can generate your Bibtex database automatically, with more than a little work, but it's maybe a two-hour project.
Tiresomely, Bibtex can't be used to get all bibliographies right, since different citation styles actually have different lists of non-significant words. However, in practice hardly anyone ever cares about the differences, so one can come up with a standard list of non-capitalised words.
[1] - Significant words:"a", all two-letter actual words, "the", "and", "some", all one-word prepositions, and all one-word pronouns would be an acceptable list of non-significant words , I think, to nearly all publishers.
If you prefer to edit the bibtex style (.bst) rather than the bibliography (.bib), you can search for occurences of change.case$ in it. This is the function that capitalizes or title-izes fields that are not people names.
Typically, for the title field, you should find something like title "t" change.case$. Since you want the title unmodified, replace that by just title.
In that case you should just add {} around each entire title, which has the same effect and should be easy to do automatically.
I was getting the same issue with a title such as:
title = {blah blah AB blah AB blah}
turning out as:
"blah blah ab blah ab blah"
Using Charles Stewart's suggestion, I changed my title to:
title = {blah blah {A}{B} blah {A}{B} blah}
Now my title turns out right:
blah blah AB blah AB blah
Hope this helps.
One alternative to using {curly brackets} is this:-
Check your root folder for .bbl file, where .bbl is your BiBteX database, after you run pdflatex for the first time and then run bibtex on your BiBteX database file.bbl.
Open this *.bbl file in an editor of your choice.
The file would look like this:
\begin{thebibliography}{10}
\expandafter\ifx\csname url\endcsname
\relax
\def\url#1{\texttt{#1}}
\fi
\expandafter\ifx\csname urlprefix\endcsname
\relax\def\urlprefix{URL }
\fi
\bibitem{label}.....
Edit this *.bbl file to meet your requirements and now run the pdflatex command on your .tex file. This should give you the desired result.
By this method you can edit the bibliography in any manner. You can even add names with accented characters.