Comments (3)
@dzonerzy that could be really useful
from gramfuzz.
@dzonerzy I have things like this in pfp, like this https://pfp.readthedocs.io/en/latest/metadata.html#watch-metadata
However, pfp is best suited to parsing existing data, and then modifying/rebuilding it. I think there could be a straightforward way to do this. Bulding on your example:
# PNG is composed of a header, and multiple chunks. Each chunk has the format
#
# | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F |
# -----------------------------------------------------------------
# | LENGTH | TYPE | ... DATA ... | CRC |
#
# Where the LENGTH is the length of the DATA, and the CRC is the CRC of the
# TYPE and the DATA concatenated
BinULong = UInt(min=0, max=0x10000, pack=">L")
def chunk_crc(field):
return calc_crc(field.rel("cname") + field.rel("data"))
RDef("chunk",
BinULong(name="length"),
String(name="cname", min=4, max=4, charset=String.charset_alpha),
String(name="data", min=Rel("length"), max=Rel("length")),
BinULong(data=chunk_crc),
)
# --- OR having the length based on the data, which would have to be generated
# first
RDef("chunk",
BinULong(name="length", data=len(Rel("data"))),
String(name="cname", min=4, max=4, charset=String.charset_alpha),
String(name="data", min=0, max=0x10002),
BinULong(data=chunk_crc),
)
# --- OR Creating a custom Crc type that accepts as parameters the fields to
# calculate the CRC from
class CRC(UInt):
self.pack = ">L"
def __init__(self, *rel_field_names):
self.rel_field_names = rel_field_names
def build(self, pre=None, shortest=False, data=None):
res = And(*list(map(Rel, self.rel_field_names)))
crc = calc_crc_of_data(res)
return UInt.build(self, pre, shortest=False, data=crc)
RDef("chunk",
BinULong(name="length", data=len(Rel("data"))),
String(name="cname", min=4, max=4, charset=String.charset_alpha),
String(name="data", min=0, max=0x10002),
CRC("cname", "data"),
)
To make this work, I think we'd need to add/change/make sure that:
- gramfuzz can track the context that fields are built within
- all fields can accept an optional
name
parameter in their__init__
- this will make them referenceable - the context needs to be tied to the build context, not the field instance (field instances can be reused)
- the
Field
class should have arel()
function that can be used as a way to get a reference to a named field in the current context - the correct order to generate fields based on their dependencies (relations) would have to be determined, and the resulting built values cached in the current scope/context
- a
Rel
top-level field class should exist that can be used to define relationships to other named fields in the current context/scope
- all fields can accept an optional
- All
gramfuzz.fields.Field:build()
functions need to accept an optionaldata
argument, which may be:- a gramfuzz field that needs to be built (like
Rel
) - a python function that will return data to use, instead of randomly creating it
- a raw value
- a gramfuzz field that needs to be built (like
from gramfuzz.
I have a javascript-specific wrapper of gramfuzz that I use for browser fuzzing that I haven't released that has some of this functionality, specifically tracking scope/context that things are built within and being able to reference other fields by name. This would be a decent amount of work, but definitely doable, and I think worthwhile.
Also, PRs are welcome too :^) If you @dzonerzy or anyone else wanted to start work on it, I should be able to be more responsive and provide feedback/direction, as I've taken less stressful employment.
from gramfuzz.
Related Issues (20)
- random fixes
- add debug logging
- add stand-alone gramfuzz script HOT 1
- __file__ is not defined in loaded grammars
- Use better badges in the README
- Autodeploy from pushed tags with Travis-CI
- Add python3 support
- Python3 : NameError: name 'NEWLINE' is not defined HOT 2
- Error in example.py writing to stdout with example.py
- Loading grammars does not use globals() and locals() correctly
- Error
- Error with `Int` field: doesn't respect min/max HOT 3
- Examples don't work in python3
- Feature Request: Weighted Or (already have implementation to use) HOT 4
- Thanks for implementing the feature but there is a small bug HOT 8
- UnicodeDecodeError: 'ascii' codec can't decode byte 0xcb in position 2542: ordinal not in range(128) HOT 4
- Error raise errors.GramFuzzError("referenced definition ({!r}) not defined".format(refname)) HOT 8
- TypeError when using String-Field with value parameter HOT 1
- Can the documentation describe the syntax of multi-level relationships in more detail?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gramfuzz.