Login
Login
Register
Questions
Unanswered
Tags
Users
Ask a Question
Ask a Question
Is there a way to pass parameters to custom types?
0
votes
asked
Apr 24
by
lambdaknight
(
160
points)
I would like to make a custom type that represents a fixed-point number with a variable binary scaling. Ideally, I'd like to make a custom type that I can input a parameter in to for that scaling factor. Is such a thing possible?
scripts
grammar
hexinator
Please
log in
or
register
to answer this question.
1 Answer
0
votes
answered
Apr 24
by
andreas
(
3,300
points)
So you want to provide for each usage in the Grammar a parameter to the script of the custom type?
And the parameter doesn't depend on any other element parsed previously?
commented
Apr 27
by
lambdaknight
(
160
points)
That's correct! The specific use-case I have is that a protocol stores several values as fixed-point numbers with various lengths of the fractional part. The code to parse them all is identical except for scaling the value by a variable part. I would like to avoid copy and pasting the same code a ridiculous number of times while changing 1 value. My current hacky solution is to parse the field as a raw number and then follow it with a Script element that just takes the raw value from the previous result and does the parsing and replaces that result.
Please
log in
or
register
to add a comment.
Welcome to Synalysis Q&A, where you can ask questions and receive answers from other members of the community.
All categories
Grammars
(20)
Hexinator
(6)
Synalyze It!
(20)
Scripting
(10)
Related questions
Is there a way to get nibble arrays to obey endianness?
What is the best way to add a binary coded decimal (BCD) number to a grammar?
Any way to automate a set of hex edits? (from a batch file or similar)
Length information comes after the usage of the actual length. Is it even possible to use it in Grammar?
Displaying masked data as a different type
Most popular tags
grammar
scripts
python
hexinator
structure
value
endianness
repeat
numberelement
offset-search
automation
floating-point-numbers
bit-logic
padding
result
string
consists-of
meter-bus
m-bus
cpap
conditional
date
dates
dump
nokia
decode
bug
bin
decrypt
openssl
wav-files
corrupted
audio
csv
lengthunit
structuremapper
headers
signature
pattern
aob
diff
export
hex-editing
installer
variable-length
elf
masks
magicnumber
derive
mapper
delimited
change
no
getcurrentresults
element
file
length
order
...