Math functions in templates Log Out | Topics | Search
Moderators | Edit Profile

X-Ways Support Forum » Advanced Features » Math functions in templates « Previous Next »

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

Bscott (Bscott)
Posted on Wednesday, Sep 4, 2002 - 18:26:   

I'm attempting to build a template to process AFP files. Each AFP field has the structure of X'5A xx yy' where xx yy is the total field length.
Somehow I'd like to be able to use the variable length - 5. The move function works to cleanly go from field to field, but I end up displaying 5 bytes of the next field

My template look like this:

template "AFP fields"
// Sample template by Bill Scott
description "5A xx xx hex define each data field"
appliesto file
multiple
requires 0 "5A"
requires 3 "D3"
big-endian
begin
hex 1 "Start AFP field"
int16 "length"
hex 1 "D3 Structured field Int"
hex 2 "D3xxyy definition"
hex length "AFP detail fields"
move -5
end

A small piece of sample data

5A0008D3A8C60081225A001CD3A8CE008123C6F1F0F1F0F1F1F000000A21FE000000000000005A0008D3A8CD0081245A0010D3A8CC008125C4F0F1C6C5F0F1405A000ED3ACAF0081260000000000005A0015D3A68800812700003840384000000000000000...

Any suggestions?
Top of pagePrevious messageNext messageBottom of page Link to this message

Stefan Fleischmann (Admin)
Posted on Thursday, Sep 5, 2002 - 1:47:   

Sorry, so far, templates are unable to calculate, as stated in the docs. The ability to use formulas is on the wish list already.

For the moment I suggest you move 5 bytes back before displaying the long hex array. That way the template won't display any data of the next field. The first 5 bytes in "AFP detail fields" must be ignored, then, or you could label it "Entire AFP field".
Top of pagePrevious messageNext messageBottom of page Link to this message

Bscott (Bscott)
Posted on Thursday, Sep 5, 2002 - 13:52:   

Also for the wish list would be the super template or sub templates, so that a group of templates could be processed together. The first one that fit would be automatically selected.
Top of pagePrevious messageNext messageBottom of page Link to this message

Stefan Kortmann (Admin2)
Posted on Friday, Apr 2, 2004 - 15:13:   

The next version of WinHex will include the feature to use calculations both in scripts as in templates.

For a formula to be recognized as a calculation by WinHex, calculations must be enclosed in a pair of round brackets.

Valid operands for calculations will be integer constants and other variables to which integer values have been assigned before.

Following operations will be possible in any order (with their according operators):

+ : addition
- : subtraction
* : multiplication
/ : integer division (result rounded to nearest integer)
% : modular division
& : bitwise AND
| : bitwise OR
^ : bitwise XOR
Top of pagePrevious messageNext messageBottom of page Link to this message

rjohnson
Posted on Thursday, Jun 24, 2004 - 9:37:   

Here is a little script I created to test the new math functions,

I have noted:

> / : integer division (result rounded to nearest integer)

----------------------------------
// June 23, 2004
// test math in scripts to determine if division with intergers truncates, rounds or ??

ifequal ((400*100)/100) ((400*100)/100)
messagebox "EQUAL"
else messagebox "NOT equal"
endif

ifequal ((400/100)*100) ((400*100)/100)
messagebox "EQUAL"
else messagebox "NOT equal"
endif
------------------------------------------
when run the first one declares equal the second, not equal. Shouldn't these both be equal, even with rounding (since no rounding should occur in this formula)?
breakdwon of the second formula
ifequal ((400/100)*100) ((400*100)/100)
-----------((4)*100)-----((40000)/100)
--------------(400)----------(400)

Even this comes back "not equal"??
ifequal (4*100) (40000/100)
Top of pagePrevious messageNext messageBottom of page Link to this message

Stefan Fleischmann (Admin)
Posted on Thursday, Jun 24, 2004 - 14:07:   

Whereever numerical parameters are expected (integer numbers), the integrated formula parser allows you to use mathematical expressions. IfEqual does not yet support mathematical expression. This function compares two variables, ASCII strings, or hexadecimal values at the binary level. In your case it compares the ASCII strings you provided and according to your findings works correctly as documented. We will probably add support for mathematical expressions as IfEqual parameters some time.
Top of pagePrevious messageNext messageBottom of page Link to this message

rjohnson
Posted on Thursday, Jun 24, 2004 - 17:33:   

I think I understand your explanation:
IfEqual "Compares two variables, ASCII strings, or hexadecimal values at the binary level. ..." (from the Help file)

Also in the help file; IfGreater handles integer values and so does Assign. If correct that may be enough:

Assign test1 ((400/100)*100)
Assign test2 ((400*100)/100)
IfEqual test1 test2
messagebox "EQUAL"
else messagebox "NOT equal"
endif

This appears to solve my situation, no need to modify IfEqual (unless Assign slows process much?)

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

(Am I correct, Find in scripts does everything as in WinHex except 'Cond: offset mod"?)
Top of pagePrevious messageNext messageBottom of page Link to this message

Stefan Fleischmann (Admin)
Posted on Thursday, Jun 24, 2004 - 18:36:   

Yes, that is a good idea. Assign will not slow down the process noticeably, except perhaps if this is done a thousand times in a row. In that case, however, Turbo On should help.

> Find in scripts does everything as in WinHex except 'Cond: offset mod"?)

"Search in all open windows", "Archive/Count occurrence positions", and "Ignore read error" are three other options known from Find Text not available as parameters of the Find command in scripts.
Top of pagePrevious messageNext messageBottom of page Link to this message

Stefan Kortmann (Admin2)
Posted on Wednesday, Jul 7, 2004 - 9:18:   

The upcoming release of WinHex will include comparison of numerical values, integer variables and mathematical calculations in any combination, both in scripts and in templates.

The syntax is as follows (scripts and templates):

IfEqual 4 (MyVariable*5-43*(MyVariable2|32))
..
EndIf

or

IfEqual MyVariable (854+19045/4096*32&MyVariable2)
..
Else
..
EndIf

or to check if the first operand is greater than the second

IfGreater MyVariable 12345
..
EndIf


As before, you can also compare byte sequences given as ascii text or hex values

IfEqual "abc" 0x414243
..
EndIf

This will compare on byte level.

Comparing strings and/or hex values only results to equal if the operands have the same length.


IfGreater "test1" "test2"
..
EndIf
Top of pagePrevious messageNext messageBottom of page Link to this message

Enrico Sadi
Username: enricosadi

Registered: N/A
Posted on Tuesday, Oct 10, 2006 - 16:38:   

HI all,
I'm new here.
I need to make a disk copy skipping 128 sectors by 128, so that the final target contains sectors 1-128, 257-384, 513-640 and so on, consecutively queued so that the target will be half size of th original disk. I need this to recover a raid with double parity (Raid 6). Any suggestion? Can this be done with Winhex script language?
Thanks to all
Enrico Sadi
Prato Italy
Top of pagePrevious messageNext messageBottom of page Link to this message

Stefan Fleischmann
Username: admin

Registered: 1-2001
Posted on Tuesday, Oct 10, 2006 - 22:46:   

Yes, can be done.
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 - 5:03:   

Sorry if I have missed this (I have checked the latest Help file [Sep. 2008] and searched the forum)


Does EndIf also apply to IfGreater?

An example above (i.e. Steve Kortman, 7-7-2004) and some basic testing shows that it probably does, but I would appreciate a definitive answer in case I have not tested all variations.

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:30:   

Yes, it does.

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.