vivisect / vstruct2 Goto Github PK
View Code? Open in Web Editor NEWVivisect Structure Definition/Parsing Library
License: Apache License 2.0
Vivisect Structure Definition/Parsing Library
License: Apache License 2.0
This issue can serve as a discussion point for the following behavior, which I was surprised by, and find inconsistent.
An uninitialized vbytes
instance emits 0 bytes, while an uninitialized number instance emits a non-zero number of bytes. For example:
import vstruct.types as v_types
# initialized vbytes should have `size` bytes emitted
a = v_types.vbytes(size=8)
a.vsParse(b"\x00" * 8)
assert(len(a.vsEmit()) == 8) # --> OK
# uninitialized vbytes should have `size` bytes emitted???
b = v_types.vbytes(size=8)
assert(len(b.vsEmit()) == 8) # --> AssertionError: the size is 0
# initialized uint64 should have 8 bytes emitted
c = v_types.uint64()
c.vsParse(b"\x00" * 8)
assert(len(c.vsEmit()) == 8) # --> OK
# uninitialized uint64 should have 8 bytes emitted
d = v_types.uint64()
assert(len(d.vsEmit()) == 8) # --> OK
This surprised me while writing parsers because if I created a new instance of a VStruct that contained both number and vbytes members, I only had to explicitly initialize some of them. (Actually, I started with vstructs that only contained numbers, and didn't have to initialize the struct to emit a buffer of correct length. This changed when I added a vbytes member.)
I think the API would be more consistent if vbytes emitted size
0x00 bytes if its not been initialized; however, I can also understand the argument that structs should be initialized or undefined behavior results.
What are your thoughts?
via: vivisect/dissect#1
i had used the following function to cast the bytes from one vstruct to another:
def cast_vstruct(src_instance, dst_instance):
'''
load the bytes that back `src_instance` into `dst_instance`.
note that subsequent changes made to `dst_instance` are not reflected in `src_instance`.
so this is useful in 'by-value' situations, but not for situations expecting writeback support.
modifies `dst_instance`. does not modify src_instance.
type src_instance: v_types.VStruct
type dst_instance: v_types.VStruct
'''
d = src_instance.vsEmit()
dst_instance.vsParse(d)
a vsCast
method on vstruct might enable the passing of the fd/bytes and offset to the destination object, and therefore:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.