flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > [fasmg] make DB, obfuscate (why?) |
Author |
|
bitRAKE 15 May 2022, 22:54
The nice thing about fixed VHD files is that it's just composed of a footer structure. So, the disk image can usually still be loaded into other tools. Here is a macro to build that footer structure ...
I could have opted to get rid of all the magic numbers, but this is only mildly more readable: Code: virtual at $ - 512 footer VHD.Footer end virtual load sig:sizeof VHD.Footer.Signature from footer.Signature load ver:sizeof VHD.Footer.Version from footer.Version load met:sizeof VHD.Footer.NextMeta from footer.NextMeta load typ:sizeof VHD.Footer.DiskType from footer.DiskType if sig = VHD.Cookie \ & ver = 0x0000_0100 \ & met = VHD.FixedMeta \ & typ = ((VHD.DiskType.Fixed) bswap 4) FILE.BYTES = $ - 512 else ; assume RAW disk image FILE.BYTES = $ end if For example, in Linux DD can copy a disk and then add a footer to load it into VM.
_________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||||||||||
15 May 2022, 22:54 |
|
bitRAKE 20 Jun 2022, 23:00
Today I had a need to format some JSON, which was output in a minimized form (from a source I don't have control of). It was over 200MB and ballooned to 360MB, but at least my editor can view it now.
Code: ; strip whitespace from JSON file and re-format with tab if definite FILE virtual DAT:: file FILE DAT_END := $ - $$ end virtual define _db calminstruction json_prettier i:0,instring:0,depth:0 local awk,char more: arrange awk, =load =_db:1 =from =DAT:i assemble awk compute i, i + 1 compute char, 0+_db check instring jyes string_contents check _db = '"' jyes string_inout check _db = ',' jyes output_indent check _db = '{' jyes increase_depth check _db = '}' jyes decrease_depth check _db = '[' jyes increase_depth check _db = ']' jyes decrease_depth ; consume existing whitespace check _db = ' ' jyes skip_ws check _db = 10 jyes skip_ws check _db = 13 jyes skip_ws check _db = 9 jyes skip_ws output_char: arrange awk, =db char assemble awk skip_ws: check i < DAT_END jyes more exit decrease_depth: compute depth, depth - 1 indent_output: arrange awk, =db 10,depth =dup 9,char assemble awk jump skip_ws increase_depth: compute depth, depth + 1 output_indent: arrange awk, =db char,10,depth =dup 9 assemble awk jump skip_ws string_contents: check instring = 3 jyes string_esc check _db = '"' jyes string_inout check _db = '\' jno output_char string_esc: compute instring, instring xor 2 jump output_char string_inout: compute instring, instring xor 1 jump output_char end calminstruction json_prettier else display 'usage: fasmg -i "define FILE ''<filename>''" ',__FILE__,' <outfile>' end if _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
20 Jun 2022, 23:00 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.