Scripts for data comparisons.. Log Out | Topics | Search
Moderators | Edit Profile

X-Ways Support Forum » Advanced Features » Scripts for data comparisons.. « Previous Next »

Author Message
Top of pagePrevious messageNext messageBottom of page Link to this message

Mark Miliano (Mark)
Posted on Wednesday, Nov 14, 2001 - 1:09:   

I have a sectors worth of data that I want to write to-and back from a specific hard disk to compare for data integrity. I have been able to compare files and return wether or not the file sizes are the same.

NOW: I have been attempting to write this same sector of data to files in a loop many times so I can verify the integrity of these files throughout
the drive and not just in one place. Any suggestions would be greatly appreciated.. I don't see any sample code vaguely similar for this effort.
Top of pagePrevious messageNext messageBottom of page Link to this message

Stefan Fleischmann (Admin)
Posted on Wednesday, Nov 14, 2001 - 1:33:   

I am not sure I understand what you trying to do. If you wish to compare if data written to and data read from a hard disk is the same, you could proceed like this:

You could read 512 bytes from a file with the test data into a variable (Open + Read command).

In a loop you could then do the following, starting at sector 0:

{
Write that variable to the hard disk (Open + Write command) and read it back into a second variable (Move command backward + Read command). Then you compare both variables (IfEqual), and go on with the next sector or, say, 1000 sectors after (Move command).
}

--

This integrity check would overwrite existing data on the disk. You could introduce a third variable that buffers the original data of each sector and writes it back after the test to avoid this.
Top of pagePrevious messageNext messageBottom of page Link to this message

Mark Miliano (Mark)
Posted on Wednesday, Nov 14, 2001 - 20:55:   

Stefan, thanks for your help! I was wondering if it is possible to use a variable- say.. an integer
inside of a script file that I can increment and send with the compared sector data so that I know which sector it was that was written/compared and such. I know this can be done in the templates... but I want to be able to do this on the fly with many sectors automatically.
thoughts?
-Mark
Top of pagePrevious messageNext messageBottom of page Link to this message

Stefan Fleischmann (Admin)
Posted on Wednesday, Nov 14, 2001 - 21:04:   

Not currently possible, sorry. However, you could have the script abort execution if the comparison fails, and the current cursor position would reveal which sector has been access last.

Besides, I am thinking about making all the script commands available as exported functions in the winhex.exe module. Would it help you if you were able to use them from your own program? Could be written in C++, Delphi, or Visual Basic. You could then use variables etc. as you like.
Top of pagePrevious messageNext messageBottom of page Link to this message

Mark Miliano (Mark)
Posted on Wednesday, Nov 14, 2001 - 22:16:   

Stefan,
>current cursor position would reveal which >sector has been access last.
Is is possible to write CurrentPos to an error log? I tried this- and all I saw written in the errorlog was the word "CurrentPos"- how do I extract the actual position from it?

>Would it help you if you were able to use them >from your own program?
Yes! That would be great if I could port a C++ program into WinHex.

-Mark
Top of pagePrevious messageNext messageBottom of page Link to this message

Stefan Fleischmann (Admin)
Posted on Wednesday, Nov 14, 2001 - 23:58:   

The write command did not yet interpret the CurrentPos function as a parameter. I have changed that. Also, it is now possible to store the CurrentPos from the disk in a variable ("Assign MyVar CurrentPos"), so it can be written into a file, where CurrentPos has a different value. Note that the current position will be written as a binary integer.

The changes will take effect with the next service release. I will e-mail you about a preliminary version.

I will post here if and when the script commands will be available as exported .DLL functions.
Top of pagePrevious messageNext messageBottom of page Link to this message

Ross Johnson
Username: ross_winpro_net

Registered: N/A
Posted on Tuesday, Sep 9, 2008 - 8:35:   

[WH 15.1 SR-1] Script questions regarding data comparison ... using some of the techniques suggested in the second post of this topic.

I have three opened files (2 source and 1 destination)

The two source files are slightly different.

I have a variable called 'zeros' that contains 512 bytes of zeros.

I have opened the objects in such a way as to ensure that source 1 will be the focus when the loop starts, then NextObj will switch to source 2 and finally the destination.

The goal is too compare 512 bytes at a time from the two source files, if they are the same write the 512 bytes to the destination, if they are different write 512 zeroes to the destination.

Even though there are differences between source 1 and source 2, the segment below always writes the variable 'File2' to the destination resulting in the destination being identical to source 2.

Script segment:

{
NextObj //source 1
Read File1 512

NextObj //source 2
Read File2 512

NextObj //destination
Ifequal File1 File2 Write File2
else write Zeros
endif

}[10]


As per post # 2 above, I am using IfEqual to compare 512 bytes of data being read into two variables, However IfEqual acts as if the variables are always equal even when I know they should not be (e.g. the first 512 bytes of the two source files are not equal).

I would really appreciate anyone pointing out the errors in my very little script segment. I am sure it is quite simple but I have spent more time than I should on this ...

Thank you,

Ross@WinPro.net
Top of pagePrevious messageNext messageBottom of page Link to this message

Stefan Fleischmann
Username: admin

Registered: 1-2001
Posted on Tuesday, Sep 9, 2008 - 13:58:   

The IfEqual command was not prepared to compare variables longer than 255 bytes. Will be fixed with the next release.
Top of pagePrevious messageNext messageBottom of page Link to this message

Ross Johnson
Username: ross_winpro_net

Registered: N/A
Posted on Tuesday, Sep 9, 2008 - 20:53:   

Thank you,

I have changed the bytes read to 128 and then multiplied the number of loops by four; that solves it AOK.

Will comparing (i.e. using IfEqual) 128 bytes at a time (over four times as many loops) be faster than comparing 512 bytes, especially in a huge number of total loops? In otherwords will there be a major speed variation when choosing between using many loops to read/compare smaller variables vs. fewer loops to read/compare larger variable?

-----------

I can't find right now, but I think I remember reading yesterday that at one time (and maybe still?) that IfGreater only applies to integers? Whereas IfEqual can also deal with Hex?

Here is what I would like to do ...

Script segment:

{
NextObj //source 1
Read File1 128

NextObj //source 2
Read File2 128

NextObj //destination
Ifgreater File1 File2 Write File1
else write file2
endif

}[10]

This script is to be used only on files that are identical excepting where one or the other may have zeroed sectors; and is simply an attempt to merge the two into a single file that includes all possible sectors that contain non-zeroed data.

However, when I Use IfGreater, it sometimes (not always) calculates a 128 byte range of Hex zeroes (i.e. x00) as being greater than the other file's same range that contains bytes that are not Hex zeroes. This is evidenced by an occasional stripe of 128 bytes of zeroes in the destination file even though one of the source files had non-zeroed (Hex) data at that location.

I would like to confirm that I should not be using IfGreater in this way? (i.e. to presume that Hex zeroes are the lowest value when using IfGreater?)

If not, how can I otherwise (most efficiently) accomplish my task without the script becoming cumbersome and therefore slower on large iterations?

Thank you,

Ross@WinPro.net
Top of pagePrevious messageNext messageBottom of page Link to this message

Ross Johnson
Username: ross_winpro_net

Registered: N/A
Posted on Wednesday, Sep 10, 2008 - 5:47:   

re:
>how can I otherwise (most efficiently) accomplish my task

I have found a way, thanx,

I replaced the comparison routine with:

nextobj
IfEqual File1 filezeros write file2
else write File1
EndIf

This works perfectly (Filezeros is a 128 byte variable that has been set to all Hex zeroes).

I hope this helps anyone else trying to accomplish similar results.


However, I am still curious regarding other aspects of my last post.

-----------------------------------------------------------------------------------


new questions:

Additionally, I also would like to know how the SAVE command affects things.

As a precaution, I had used Save after the EndIf to save changes to the destination file on every loop but this slowed things down considerably. However, when removed, I am not sure of what is happening as the destination file grows? Is it in a tempfile on an HD? Is it in RAM until I save it? Are there size limits? So, far the results have been OK but I want to use this script on very large files (e.g. 350mb to start with).

I can see a file in the the temp folder growing that must be my destination file, but I am not sure how WinHex scripts works with temp files (e.g. what are the limits, when or how often are they saved). I have viewed the help file for the Undo options but only see a reference to templates.

Please point me to the correct resources regarding the answers (i.e. help file section or forum topic). Thank you,

Ross@WinPro.net
Top of pagePrevious messageNext messageBottom of page Link to this message

Stefan Fleischmann
Username: admin

Registered: 1-2001
Posted on Saturday, Sep 13, 2008 - 1:49:   

> I am not sure of what is happening as the destination
> file grows?

Same as if you add data to a file (e.g. typing or pasting) in a data window without a script.

> Is it in a tempfile on an HD? Is it in RAM until I save it?

Usually in a temporary file.

> Are there size limits?

Practically limited only by available drive space.

> Please point me to the correct resources regarding the
> answers (i.e. help file section or forum topic).

How this works internally is certainly not documented in the program help or user manual.

Add Your Message Here
Post:
Username: Posting Information:
Only registered users may post messages here, i.e. you need to have an account.
Password:
Options: Enable HTML code in message
Automatically activate URLs in message
Action:
Forum operated by X-Ways Software Technology AG.