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, 2023
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, 2023
by
andreas
(
3,500
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, 2023
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.
commented
Jul 9
by
martin-winter
(
180
points)
I have a similarly hacky solution in my grammar: I use the description field to specify which structure a script element should map. I wish there were an official solution.
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
(21)
Hexinator
(8)
Synalyze It!
(21)
Scripting
(12)
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)
Trying to install on Ubuntu, but there is a dependency to python2.7
Length information comes after the usage of the actual length. Is it even possible to use it in Grammar?
Most popular tags
grammar
hexinator
scripts
python
structure
value
endianness
repeat
numberelement
offset-search
automation
floating-point-numbers
variable-length
bit-logic
padding
result
string
object-file
omf-51
font
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
elf
masks
magicnumber
derive
mapper
delimited
change
no
getcurrentresults
element
file
length
order
...