Home Hex Edit Home Page
Hex Edit Features Hex Edit Features
Button Testimonials
Button Screen Shots
Button Downloads
Button Forums Home
Button HexEdit FAQ
Button Known Bugs
about help privacy register
Forums
Search Members Help

» Welcome Guest
[ Log In :: Register ]

 

[ Track This Topic :: Email This Topic :: Print this topic ]

reply to topic new topic new poll
Topic: Variable Length Sections In Templates, Template Design Question< Next Oldest | Next Newest >
 Post Number: 1
ohall Search for posts by this member.

Avatar



Group: Members
Posts: 3
Joined: Jul. 2010

Member Rating: None
PostIcon Posted on: Jul. 30 2010,09:19  Skip to the next post in this topic. Ignore posts   QUOTE

Hi,

I'm trying to build a template to read an obscure file type.  Following a basic header, the file has a number of chunks that vary in length.  The first two bytes of the chunk specify the length of the whole chunk, but the chunk itself may then contain one or more variable length records.  This is all fine for a chunk with a single record, but I'm struggling when the chunk has multiple records as I'm not sure how to make use of the "chunk length" data to control the FOR section that reads the records - does that make sense?

Here's a pseudo example:

[Header]
[Chunk 0]
[Chunk Length] (e.g. 20 bytes)
  [Record 0] (length == 20 bytes Chunk Length)
[Chunk 1]
[Chunk Length] (e.g. 50 bytes)
 [Record 0] (length == 30 bytes != Chunk Length)
 [Record 1] (kaboom!)

How would I tackle this in the template design?
Many thanks,
Oliver
Offline
Top of Page Profile Contact Info 
 Post Number: 2
ohall Search for posts by this member.

Avatar



Group: Members
Posts: 3
Joined: Jul. 2010

Member Rating: None
PostIcon Posted on: Aug. 02 2010,15:06 Skip to the previous post in this topic. Skip to the next post in this topic. Ignore posts   QUOTE

This is starting to get frustrating - I just can't find the right way to do this...

I have a structure of the form
Start (1 byte)
Len (1 byte)
Chunk[1..n] (variable lengths)

Where the value of Len = 1+sum( length of each Chunk element).

My FOR "stop" expression for the array of Chunk is:
addressof( this ) >= ( addressof( Start ) + Len + 1 )

This always attempts to read one more Chunk than it should.  I assume that the "addressof( this )" isn't equating to the start of the next Chunk, but instead points to the start of the Chunk just iterated over...

Please help!
Ol
Offline
Top of Page Profile Contact Info 
 Post Number: 3
andrew Search for posts by this member.

Avatar



Group: Super Administrators
Posts: 635
Joined: Oct. 2003

Member Rating: 4
PostIcon Posted on: Aug. 11 2010,21:17 Skip to the previous post in this topic. Skip to the next post in this topic. Ignore posts   QUOTE

Sorry I didn't see this earlier.  (I should receive an email when someone posts here but I never saw it.)

To paraphrase what you are saying (1st post), I think your problem is that you need to add up the lengths of the records to know when you have reached the end of the chunk.

You can create a variable to keep track of the length of the records seen in the chunk so far.  Set this to zero at the start of a chunk and add the length of each record as you see it.  The chunk finishes when the length of the records seen so far equals the chunk length.

Similarly, (in your 2nd post) you can keep track of the lengths of all the chunks seen so far and stop looking for chunks when this reaches "Len".  I can post some template (XML) code if you send me some more details and perhaps an example file.  (Email to aphillips @ hexedit.com and include the word "HexEdit" in the subject.)

You are right that addressof(this) is the address of the current element you are processing.  In a FOR test this is probably the address of the start of the FOR.  You can get the address of the start of the next chunk at the start of the chunk by adding  the length of the chunk to addressof(this) and saving it in a variable for later use.  Something like:

  EVAL: NextEnd = 0
  EVAL: End = addressof(this) + Len + 1
  FOR : stop_if="NextEnd >= End"
     EVAL: NextEnd = NextEnd + ChunkLength

Also you might have a look at the simialr _IIF.XML sample XML file.  However, this format is a little more complicated as you can nest CHUNKs within CHUNKs to any depth.

Andrew.


--------------
Andrew Phillips
Moderator of Forums and creator of Hex Edit
Offline
Top of Page Profile Contact Info WEB 
 Post Number: 4
ohall Search for posts by this member.

Avatar



Group: Members
Posts: 3
Joined: Jul. 2010

Member Rating: None
PostIcon Posted on: Aug. 12 2010,13:36 Skip to the previous post in this topic. Skip to the next post in this topic. Ignore posts   QUOTE

Hi Andrew,

Many thanks for the reply - I've followed your instructions and got it working.

Many thanks for the help, and a great product.
Ol
Offline
Top of Page Profile Contact Info 
 Post Number: 5
Tcll Search for posts by this member.
The Awesome Programmer
Avatar



Group: Members
Posts: 111
Joined: Feb. 2011

Member Rating: 5
PostIcon Posted on: Mar. 29 2011,08:15 Skip to the previous post in this topic. Skip to the next post in this topic. Ignore posts   QUOTE

I didn't ;_;
I'm getting an error I can't seem to understand

here's my layout:
EVAL: pos = 0
EVAL: data_end = addressof(this) + Len + 1
FOR : stop_if="pos >= data_end"
-DEF: register
--IF: specific register command
---EVAL: pos = pos + 4

and here's the error:


I'm using a DEF for the register commands in seperate parts of the file:
"""
pos += 1 #register type

10 = XF Register
-pos += 1 #command
--pos += 2 #value

08 = CP Register
-pos += 1
--pos += 4

61 = BP Register
-pos += 1
--pos += 3
"""
multiple places in the file use these registers,
and there is only a total length of the block...

most of the block is padding btw


--------------
Offline
Top of Page Profile Contact Info WEB 
 Post Number: 6
andrew Search for posts by this member.

Avatar



Group: Super Administrators
Posts: 635
Joined: Oct. 2003

Member Rating: 4
PostIcon Posted on: Apr. 26 2011,18:57 Skip to the previous post in this topic. Skip to the next post in this topic. Ignore posts   QUOTE

Looking at this again (I couldn't see the error message in your post when I first time looked at it and I still can't but I can see a problem since I now know you are using 3.0)...

You can't have an EVAL within an IF in 3.0.  (I believe you are using the free 3.0 version.) The template editing dialogs won't even let you do that but if you try to do it by editing the XML directly you will get an error.  You can fix this by changing the DTD file if you know enough about XML or you can download the 4.0 beta (free) version as I suggested to you before.


--------------
Andrew Phillips
Moderator of Forums and creator of Hex Edit
Offline
Top of Page Profile Contact Info WEB 
 Post Number: 7
Tcll Search for posts by this member.
The Awesome Programmer
Avatar



Group: Members
Posts: 111
Joined: Feb. 2011

Member Rating: 5
PostIcon Posted on: Apr. 26 2011,20:13 Skip to the previous post in this topic. Skip to the next post in this topic. Ignore posts   QUOTE

I see...
well... crap...

looks like I'll have to UD the entire community to 4.0
prepair for loads of DL's... heh


--------------
Offline
Top of Page Profile Contact Info WEB 
 Post Number: 8
Tcll Search for posts by this member.
The Awesome Programmer
Avatar



Group: Members
Posts: 111
Joined: Feb. 2011

Member Rating: 5
PostIcon Posted on: Dec. 30 2011,17:39 Skip to the previous post in this topic. Skip to the next post in this topic. Ignore posts   QUOTE

ok, so I've gotten this implemented, and it appears to be working...

but it takes forever to load >_>
it was halfway loaded when I started this post...
it's now 2/3rds loaded

EDIT:
btw...
I wanted to fix my error img...
but I can't seem to edit my post w/o the invalid permission error >_>
think you can fix that :)


--------------
Offline
Top of Page Profile Contact Info WEB 
 Post Number: 9
Tcll Search for posts by this member.
The Awesome Programmer
Avatar



Group: Members
Posts: 111
Joined: Feb. 2011

Member Rating: 5
PostIcon Posted on: Dec. 30 2011,19:25 Skip to the previous post in this topic.  Ignore posts   QUOTE

JSYK
I've found a better way to pull off this method...

[eval] data_len = (block_size)
[for] stop{data_len == 0}
 [eval] data_len = data_len - (value_len)

or you could also do this:

[eval] max_count = (count)
[for] {max_count || max_count - 1} stop{max_count == 0}

both result in a great speedup, and are less prone to error. ;)


--------------
Offline
Top of Page Profile Contact Info WEB 
8 replies since Jul. 30 2010,09:19 < Next Oldest | Next Newest >

[ Track This Topic :: Email This Topic :: Print this topic ]


 
reply to topic new topic new poll

» Quick Reply Variable Length Sections In Templates
iB Code Buttons
You are posting as:

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code