aboutsummaryrefslogblamecommitdiffstats
path: root/bruiser/lua-scripts/wasmtest.lua
blob: 315c5f43b711aacd13b813ad161fda2143ab520f (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
 


                              






                                                                                         































































































































































                                                                                     


       
colors = require("ansicolors")

-- aka dump wasm
function demo4()
  local a = getwasmobj("/home/bloodstalker/devi/hell2/bruiser/autogen/wasm/ft/test.wasm")
  print(a)
  print(type(a))
  for k, v in pairs(a) do
    print(k, v, type(k), type(v))
  end

  print(colors("%{green}".."\ntype section:"))
  if a["type_section"] ~= nil then
    io.write(tostring("id:"..a["type_section"]:id()).."\n")
    io.write(tostring("payloadlength:"..a["type_section"]:payloadlength()).."\n")
    io.write(tostring("namelength:"..a["type_section"]:namelength()).."\n")
    io.write(tostring("name:"..a["type_section"]:name()).."\n")
    io.write(tostring("count:"..a["type_section"]:count()).."\n")
    io.write("entries"..tostring(a["type_section"]:entries()).."\n")
    for k, v in pairs(a["type_section"]:entries()) do
      io.write(v:form().."\t")
      io.write(v:param_count().."\t")
      io.write(v:param_types().."\t")
      io.write(v:return_count().."\t")
      io.write(v:return_types().."\n")
    end
  else
    print(colors("%{red}".."section doesnt exist."))
  end

  print(colors("%{green}".."\nimport section:"))
  if a["import_section"] ~= nil then
    io.write("id:"..tostring(a["import_section"]:id()).."\n")
    io.write("payloadlength:"..tostring(a["import_section"]:payloadlength()).."\n")
    io.write("namelength:"..tostring(a["import_section"]:namelength()).."\n")
    io.write("name:"..tostring(a["import_section"]:name()).."\n")
    io.write("count:"..tostring(a["import_section"]:count()).."\n")
    io.write("entries"..tostring(a["import_section"]:entries()).."\n")
    for k, v in pairs(a["import_section"]:entries()) do
      --print(k, v, type(v))
      io.write(v:module_length().."\t")
      io.write(v:module_str().."\t")
      io.write(v:field_len().."\t")
      io.write(v:field_str().."\t")
      io.write(v:kind().."\n")
    end
  else
    print(colors("%{red}".."section doesnt exist."))
  end

  print(colors("%{green}".."\nfunction section:"))
  if a["function_section"] ~= nil then
    io.write("id:"..tostring(a["function_section"]:id()).."\n")
    io.write("payloadlength:"..tostring(a["function_section"]:payloadlength()).."\n")
    io.write("namelength:"..tostring(a["function_section"]:namelength()).."\n")
    io.write("name:"..tostring(a["function_section"]:name()).."\n")
    io.write("count:"..tostring(a["function_section"]:count()).."\n")
    io.write("types:"..tostring(a["function_section"]:types()).."\n")
  else
    print(colors("%{red}".."section doesnt exist."))
  end

  print(colors("%{green}".."\ntable section:"))
  if a["table_section"] ~= nil then
    io.write("id:"..tostring(a["table_section"]:id()).."\n")
    io.write("payloadlength:"..tostring(a["table_section"]:payloadlength()).."\n")
    io.write("namelength:"..tostring(a["table_section"]:namelength()).."\n")
    io.write("name:"..tostring(a["table_section"]:name()).."\n")
    io.write("count:"..tostring(a["table_section"]:count()).."\n")
    io.write("entries:"..tostring(a["table_section"]:entries()).."\n")
  else
    print(colors("%{red}".."section doesnt exist."))
  end

  print(colors("%{green}".."\nmemory section:"))
  if a["memory_section"] ~= nil then
    io.write("id:"..tostring(a["memory_section"]:id()).."\n")
    io.write("payloadlength:"..tostring(a["memory_section"]:payloadlength()).."\n")
    io.write("namelength:"..tostring(a["memory_section"]:namelength()).."\n")
    io.write("name:"..tostring(a["memory_section"]:name()).."\n")
    --io.write("count:"..tostring(a["memory_section"]:count()).."\n")
    io.write("entries:"..tostring(a["memory_section"]:entries()).."\n")
  else
    print(colors("%{red}".."section doesnt exist."))
  end

  print(colors("%{green}".."\nglobal section:"))
  if (a["global_section"] ~= nil) then
    io.write("id:"..tostring(a["global_section"]:id()).."\n")
    io.write("payloadlength:"..tostring(a["global_section"]:payloadlength()).."\n")
    io.write("namelength:"..tostring(a["global_section"]:namelength()).."\n")
    io.write("name:"..tostring(a["global_section"]:name()).."\n")
    io.write("count:"..tostring(a["global_section"]:count()).."\n")
    io.write("globals:"..tostring(a["global_section"]:globals()).."\n")
  else
    print(colors("%{red}".."section doesnt exist."))
  end

  print(colors("%{green}".."\nexport section:"))
  if (a["export_section"] ~= nil) then
    io.write("id:"..tostring(a["export_section"]:id()).."\n")
    io.write("payloadlength:"..tostring(a["export_section"]:payloadlength()).."\n")
    io.write("namelength:"..tostring(a["export_section"]:namelength()).."\n")
    io.write("name:"..tostring(a["export_section"]:name()).."\n")
    io.write("count:"..tostring(a["export_section"]:count()).."\n")
    io.write("entries:"..tostring(a["export_section"]:entries()).."\n")
  else
    print(colors("%{red}".."section doesnt exist."))
  end

  print(colors("%{green}".."\nstart section:"))
  if (a["start_section"] ~= nil) then
    io.write("id:"..tostring(a["start_section"]:id()).."\n")
    io.write("payloadlength:"..tostring(a["start_section"]:payloadlength()).."\n")
    io.write("namelength:"..tostring(a["start_section"]:namelength()).."\n")
    io.write("name:"..tostring(a["start_section"]:name()).."\n")
    io.write("index:"..tostring(a["start_section"]:index()).."\n")
  else
    print(colors("%{red}".."section doesnt exist."))
  end

  print(colors("%{green}".."\nelement section:"))
  if (a["element_section"] ~= nil) then
    io.write("id:"..tostring(a["element_section"]:id()).."\n")
    io.write("payloadlength:"..tostring(a["element_section"]:payloadlength()).."\n")
    io.write("namelength:"..tostring(a["element_section"]:namelength()).."\n")
    io.write("name:"..tostring(a["element_section"]:name()).."\n")
    io.write("count:"..tostring(a["element_section"]:count()).."\n")
    io.write("entries:"..tostring(a["element_section"]:entries()).."\n")
  else
    print(colors("%{red}".."section doesnt exist."))
  end

  print(colors("%{green}".."\ncode section:"))
  if (a["code_section"] ~= nil) then
    io.write("id:"..tostring(a["code_section"]:id()).."\n")
    io.write("payloadlength:"..tostring(a["code_section"]:payloadlength()).."\n")
    io.write("namelength:"..tostring(a["code_section"]:namelength()).."\n")
    io.write("name:"..tostring(a["code_section"]:name()).."\n")
    io.write("count:"..tostring(a["code_section"]:count()).."\n")
    io.write("bodies:"..tostring(a["code_section"]:bodies()).."\n")
    for k,v in pairs(a["code_section"]:bodies()) do
      io.write(v:body_size())
      io.write(v:local_count())
      --io.write(v:locals())
    end
  else
    print(colors("%{red}".."section doesnt exist."))
  end

  print(colors("%{green}".."\ndata section:"))
  if (a["data_section"] ~= nil) then
    io.write("id:"..tostring(a["data_section"]:id()).."\n")
    io.write("payloadlength:"..tostring(a["data_section"]:payloadlength()).."\n")
    io.write("namelength:"..tostring(a["data_section"]:namelength()).."\n")
    io.write("name:"..tostring(a["data_section"]:name()).."\n")
    io.write("count:"..tostring(a["data_section"]:count()).."\n")
    io.write("entries:"..tostring(a["data_section"]:entries()).."\n")
    if type(a["data_section"]:entries()) == "table" then
      for k,v in pairs(a["data_section"]:entries()) do
        io.write(v:index().."\t")
        io.write(tostring(v:offset()).."\t")
        io.write(v:size().."\n")
        --io.write(v:data().."\n")
      end
    end
  else
    print(colors("%{red}".."section doesnt exist."))
  end

end

demo4()