Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/postgres/binary_writer.rb
Views: 11766
# -*- coding: binary -*-1require 'postgres_msf'2require 'postgres/byteorder'34# Namespace for Metasploit branch.5module Msf6module Db78module BinaryWriterMixin910# == 8 bit1112# no byteorder for 8 bit!1314def write_word8(val)15pw(val, 'C')16end1718def write_int8(val)19pw(val, 'c')20end2122alias write_byte write_word82324# == 16 bit2526# === Unsigned2728def write_word16_native(val)29pw(val, 'S')30end3132def write_word16_little(val)33str = [val].pack('S')34str.reverse! if ByteOrder.network? # swap bytes as native=network (and we want little)35write(str)36end3738def write_word16_network(val)39str = [val].pack('S')40str.reverse! if ByteOrder.little? # swap bytes as native=little (and we want network)41write(str)42end4344# === Signed4546def write_int16_native(val)47pw(val, 's')48end4950def write_int16_little(val)51pw(val, 'v')52end5354def write_int16_network(val)55pw(val, 'n')56end5758# == 32 bit5960# === Unsigned6162def write_word32_native(val)63pw(val, 'L')64end6566def write_word32_little(val)67str = [val].pack('L')68str.reverse! if ByteOrder.network? # swap bytes as native=network (and we want little)69write(str)70end7172def write_word32_network(val)73str = [val].pack('L')74str.reverse! if ByteOrder.little? # swap bytes as native=little (and we want network)75write(str)76end7778# === Signed7980def write_int32_native(val)81pw(val, 'l')82end8384def write_int32_little(val)85pw(val, 'V')86end8788def write_int32_network(val)89pw(val, 'N')90end9192# add some short-cut functions93%w(word16 int16 word32 int32).each do |typ|94alias_method "write_#{typ}_big", "write_#{typ}_network"95end9697# == Other methods9899private100101# shortcut for pack and write102def pw(val, template)103write([val].pack(template))104end105end106107end108end109110111