[{"data":1,"prerenderedAt":396},["ShallowReactive",2],{"project-17289801":3},{"id":4,"name":5,"line":6,"line_source":7,"title":8,"url":9,"domain":10,"maker":11,"posted_at":12,"year":13,"points":14,"comments":15,"rank_in_year":16,"shown_in_year":17,"top":18,"tier":19,"category":20,"subcategory":21,"format":22,"keywords":23,"reception":28,"sentiment":29,"stance_mix":30,"scored_comments":35,"aspects":36,"strip":43,"post_text":44,"what":45,"said":81,"maker_in_thread":223,"shape":234,"grid":238,"attempts":359,"same_week":360,"maker_shows":33,"maker_hidden":389,"reader_version":390,"card":391},"17289801","T2b","A wicked-powerful text macro language for building binary files","title","Show HN: T2b – A wicked-powerful text macro language for building binary files","https:\u002F\u002Fgithub.com\u002Fthosakwe\u002Ft2b","github.com","thosakwe",1528763461,2018,117,52,376,2155,18,"notable","dev_tools","binary file generator","cli",[21,24,25,26,27],"macro language","binary data","hex dump","bootstrapping","curious",0,{"positive":31,"neutral":32,"mixed":33,"critical":34},5,17,1,6,29,{"design":37,"idea":39,"docs":41,"execution":42},{"positive":29,"critical":38},2,{"positive":31,"critical":40},3,{"positive":29,"critical":29},{"positive":29,"critical":33},[40,29,40,33,29,29,29,40,29,33,40,29,40,40,40,40,40,40,40,40,29,29,31,29,29,31,31,29,33,29,29,29,31,31,33,40,40,40,29,33],null,{"problem":44,"audience":44,"pricing":44,"motivation":46,"time_to_build":56,"stack":62,"openness":78,"stage":79,"team_size":80},{"value":47,"source":48,"evidence":49},"Built quickly for a small VM project and as a fun hack","maker",[50,53],{"id":51,"by":11,"text":52},"17292522","That's true, I'll get around to patching t2b today or tomorrow to get in the fixes that everyone's suggested. This tool was hacked together quickly, and you can tell by using it…",{"id":54,"by":11,"text":55},"17294064","Oh definitely, this was a fun one to write. I got so caught up in it that I completely forgot the original project I wanted to use it, which was a small VM.",{"value":57,"source":48,"evidence":58},"hacked together in about a day",[59],{"id":60,"by":11,"text":61},"17292517","Well, for starts, Kaitai looks like it's much more mature, and it probably is, considering that t2b is just something I hacked together yesterday. Also, it seems like Kaitai is…",[63,71],{"value":64,"source":65,"evidence":66},"C++","commenter",[67],{"id":68,"by":69,"text":70},"17295314","memeslayer","Neat! I could used this for generating mixed binary\u002FASCII payloads for network protocol testing. One issue, though -- it seems like trailing whitespace in the input isn't handled…",{"value":72,"source":65,"evidence":73},"CLion IDE",[74],{"id":75,"by":76,"text":77},"17292490","chris_overseas","It's shared project configuration. If you're using the same IDE as the author (CLion in this case) you get all the code style settings, run\u002Fdebug configurations and shared…","open_source","prototype","unknown",{"praise":82,"objections":105,"requests":140,"questions":183,"alternatives":195},[83,94],{"value":84,"source":65,"evidence":85},"Useful niche tool; fun hacking spirit",[86,90],{"id":87,"by":88,"text":89},"17294018","vinayms","Not sure if I will use it, but I like it. This is as close to raw bytes as it gets despite some HLL like features. This to me is real hacking, saying what the heck and writing a…",{"id":91,"by":92,"text":93},"17293596","emily-c","I use fasm for this very use case. It has a wonderful macro language that can be used to programmatically generate binary data on top of being able to emit instructions. It's…",{"value":95,"source":65,"evidence":96},"Good idea for generating binary data and intermediate formats",[97,101],{"id":98,"by":99,"text":100},"17289875","brad0","Looks good. I can see this being a great intermediate format for hacks etc. Alternatively you could use some kind of fluent API to write binary data. Depends on your use case of…",{"id":102,"by":103,"text":104},"17290481","rmgraham","I really wanted something like this when embedding serial numbers and keys in ROMs. At the time I was mostly working in C and PHP, so I was imagining something closer to a…",[106,125,136],{"value":107,"source":65,"evidence":108},"Global hex mode toggle is confusing; use explicit modifiers or commands",[109,113,117,121],{"id":110,"by":111,"text":112},"17291879","yoz-y","Interesting. I have several suggestions though: - the hex modifier does both turning mode on and off, which will be confusing in a longer file - it would be good if prefixes such…",{"id":114,"by":115,"text":116},"17290183","edudobay","Cool idea! Clear and nicely organized too :) Wouldn’t it be more readable and less error-prone to have separate commands for turning hex mode on and off? Such as `hex on` and…",{"id":118,"by":119,"text":120},"17290839","ygra","Was the first thing that stood out to me as well. Toggled modes like this are also quite annoying when shuffling around sections of the file. Copy one hex too many and suddenly…",{"id":122,"by":123,"text":124},"17290254","abtinf","I think it might be more intuitive as an explicit stream modifier: hex, decimal, etc. No reason to turn anything “off”, which is actually the activation of a diffferent mode.…",{"value":126,"source":65,"evidence":127},"Existing tools like pack, struct, and Kaitai already cover this",[128,132],{"id":129,"by":130,"text":131},"17290511","emmelaich","Trying not to be a downer, but I wouldn't think of writing such a tool. I'd use Perl's pack or Python's struct. Of course there might be some value in something less than a full…",{"id":133,"by":134,"text":135},"17292502","benatkin","How does it compare to https:\u002F\u002Fkaitai.io ?",{"value":137,"source":65,"evidence":138},"Trailing whitespace in input is mishandled",[139],{"id":68,"by":69,"text":70},[141,149,157,169,176],{"value":142,"source":65,"evidence":143},"Endianness control",[144,145],{"id":110,"by":111,"text":112},{"id":146,"by":147,"text":148},"17290549","skissane","Length-prefixed strings would be useful for some file formats. You'd need to be able to pick a size for the length-prefix, such as u8,u16,etc. Also some ability to length-prefix…",{"value":150,"source":65,"evidence":151},"Length-prefixed strings and TLV support",[152,153],{"id":146,"by":147,"text":148},{"id":154,"by":155,"text":156},"17292460","childintime","> Also some ability to length-prefix the output of a macro might be useful for tag-length-value-like formats. Exactly. TLV (tag-length-value) support is really what I expected to…",{"value":158,"source":65,"evidence":159},"Octal and binary modes, and 0x\u002F0b literal prefixes",[160,164,168],{"id":161,"by":162,"text":163},"17290472","stevekemp","It surprised me that an octal mode wasn't available, or a binary one. But that's a minor gripe. The only other thing I could see being useful is the ability to define \"structs\",…",{"id":165,"by":166,"text":167},"17290459","cryptonector","Why have hex mode toggles at all? Just use 0xa1b2, and so on. 0x... -> hex, 0... -> octal -- invent a syntax for binary.",{"id":110,"by":111,"text":112},{"value":170,"source":65,"evidence":171},"Bit-level field support",[172],{"id":173,"by":174,"text":175},"17293836","Adamantcheese","It would be great if I could specify the number of bits per field like in Elixir\u002FErlang\u002FC++ bit fields and then also specify what the extra bits should be set to if the total…",{"value":177,"source":65,"evidence":178},"Fluent API or library header",[179,180],{"id":98,"by":99,"text":100},{"id":181,"by":11,"text":182},"17289957","Thanks! Some sort of API would be pretty cool... I'll add that if this takes off. At the very least, the function to execute T2B scripts could be exposed in a simple header.",[184,191],{"value":185,"source":65,"evidence":186},"Does the GPL apply to prebuilt binaries?",[187],{"id":188,"by":189,"text":190},"17294122","iffycan","If you use the prebuilt binaries, does the GPL apply?",{"value":192,"source":65,"evidence":193},"How does it compare to Kaitai?",[194],{"id":133,"by":134,"text":135},[196,200,204,212],{"value":197,"source":65,"evidence":198},"Perl pack and Python struct",[199],{"id":129,"by":130,"text":131},{"value":201,"source":65,"evidence":202},"Kaitai Struct",[203],{"id":133,"by":134,"text":135},{"value":205,"source":65,"evidence":206},"fasm macros",[207,208],{"id":91,"by":92,"text":93},{"id":209,"by":210,"text":211},"17293257","labdsf","There is already https:\u002F\u002Fflatassembler.net\u002F which uses macros to emit ELF and PE headers.",{"value":213,"source":65,"evidence":214},"Construct and suitcase for Python",[215,219],{"id":216,"by":217,"text":218},"17292003","rcfox","For Python, suitcase (https:\u002F\u002Fpypi.org\u002Fproject\u002Fsuitcase\u002F) makes dealing with structured binary data easier.",{"id":220,"by":221,"text":222},"17292411","unscaled","Or Construct: https:\u002F\u002Fconstruct.readthedocs.io\u002Fen\u002Flatest\u002F",{"comments":224,"answered":225,"key":226},9,4,[227,228,231],{"id":51,"text":52},{"id":229,"text":230},"17290202","Believe it or not, I didn't even consider that. That's definitely a better way to do it.",{"id":232,"text":233},"17290274","Definitely, that's probably the best way, considering all the other commands are \"stream-y\" as-is.",{"commenters":235,"max_depth":34,"maker_replies":224,"first_comment_mins":236,"lifespan_hours":237},38,14,23,[239,241,243,247,249,252,254,255,259,262,263,265,267,270,271,272,273,275,279,281,283,286,288,289,290,293,297,300,303,305,307,310,315,317,318,319,320,323,327,330,333,335,339,341,342,344,349,350,352,353,354,355],[110,29,40,240,111,29],"project\u002Fneutral\u002Fdesign",[51,29,29,242,11,33],"maker\u002Fneutral\u002Fnone",[244,29,40,245,246,29],"17294221","project\u002Fneutral\u002Fidea","kitd",[129,33,33,248,130,29],"project\u002Fcritical\u002Fidea",[250,33,40,245,251,29],"17290783","elcritch",[216,33,29,253,217,29],"other\u002Fcritical\u002Fidea",[220,33,29,253,221,29],[256,33,29,257,258,29],"17291747","other\u002Fneutral\u002Fdocs","kamaal",[260,33,29,257,261,29],"17291868","b6z",[114,38,40,240,115,29],[229,38,29,264,11,33],"maker\u002Fneutral\u002Fdesign",[118,38,33,266,119,29],"project\u002Fcritical\u002Fdesign",[268,38,33,266,269,29],"17290941","akx",[122,38,40,240,123,29],[232,38,29,264,11,33],[165,38,40,240,166,29],[274,38,40,240,147,29],"17290523",[276,38,29,277,278,29],"17291984","other\u002Fneutral\u002Fnone","IshKebab",[280,38,40,240,166,29],"17294350",[161,38,40,282,162,29],"project\u002Fmixed\u002Fdesign",[284,40,40,245,285,29],"17294012","tptacek",[287,40,29,277,166,29],"17294392",[146,225,40,245,147,29],[154,225,40,245,155,29],[291,225,29,292,11,33],"17292540","maker\u002Fneutral\u002Fidea",[294,31,40,295,296,29],"17292248","project\u002Fneutral\u002Fdocs","cup-of-tea",[298,31,29,299,11,33],"17292574","maker\u002Fneutral\u002Fdocs",[301,31,29,302,296,29],"17292681","commenter\u002Fneutral\u002Fdocs",[91,34,31,304,92,29],"project\u002Fpositive\u002Fidea",[306,34,29,277,246,29],"17294214",[308,34,29,277,309,29],"17294437","tov_objorkin",[311,312,29,313,314,29],"17291252",7,"other\u002Fneutral\u002Fidea","abau_org",[87,316,31,304,88,29],8,[54,316,29,242,11,33],[98,224,31,304,99,29],[181,224,29,292,11,33],[68,321,33,322,69,29],10,"project\u002Fcritical\u002Fexecution",[324,325,29,277,326,29],"17290573",11,"nickpsecurity",[328,325,29,277,329,29],"17290895","steve19",[331,325,29,277,332,29],"17291010","emmanueloga_",[334,325,29,277,326,29],"17299062",[336,337,31,304,338,29],"17290861",12,"adiusmus",[102,340,31,304,103,29],13,[173,236,40,245,174,29],[209,343,33,248,210,29],15,[345,346,40,347,348,29],"17291744",16,"project\u002Fneutral\u002Fnone","M_Bakhtiari",[75,346,40,347,76,29],[351,346,29,242,11,33],"17293018",[133,32,40,245,134,29],[60,32,29,292,11,33],[188,18,40,347,189,29],[356,357,33,248,358,29],"17292350",19,"z29LiTp5qUC30n",[],[361,366,370,375,380,384],{"id":362,"name":363,"points":364,"category":365},"17286770","Ancient Earth",384,"learning_science",{"id":367,"name":368,"points":369,"category":365},"17272516","Scaler (grunfy)",277,{"id":371,"name":372,"points":373,"category":374},"17291269","Dilay",227,"creative",{"id":376,"name":377,"points":378,"category":379},"17294548","Fo",165,"languages",{"id":381,"name":382,"points":383,"category":379},"17255418","µFSM",154,{"id":385,"name":386,"points":387,"category":388},"17254212","tor-controller",113,"infrastructure",false,"v2",{"id":392,"name":5,"line":6,"ai":389,"cat":20,"year":13,"points":14,"comments":15,"rec":28,"s":29,"top":18,"kw":393,"maker":11,"domain":10,"tier":19,"attempts":29,"strip":394,"url":9,"mix":395,"praise":84,"objection":107,"sub":21},17289801,[21,24,25,26,27],"3031000301303333333300500550100055133301",[31,32,33,34],1794036566857]