1
mirror of https://github.com/rapid7/metasploit-framework synced 2024-11-12 11:52:01 +01:00
metasploit-framework/lib/postgres/binary_writer.rb
Tod Beardsley a65af9c8b3 See #730. Forking and adding Postgres-PR, with the following changes:
Namespaced everything under Msf::Db::PostgreSQL, renamed top-level include to postgres_msf to disambiguate.
Included recursive requires for all files.
Noted the IO monkeypatch -- should revisit.
Added a testcase for database connections.

The reason for the namespacing is to avoid stomping on any existing Postgres-PR installations, or any other requires named "postgres" or "postgresql" or even "pg," since these may or may not support the method's we're using here. The seperate namespace also allows for easier integration of custom commands later on.




git-svn-id: file:///home/svn/framework3/trunk@8342 4d416f70-5f16-0410-b530-b9f4589650da
2010-02-01 19:49:36 +00:00

109 lines
1.8 KiB
Ruby

require 'postgres_msf'
require 'postgres/byteorder'
# Namespace for Metasploit branch.
module Msf
module Db
module BinaryWriterMixin
# == 8 bit
# no byteorder for 8 bit!
def write_word8(val)
pw(val, 'C')
end
def write_int8(val)
pw(val, 'c')
end
alias write_byte write_word8
# == 16 bit
# === Unsigned
def write_word16_native(val)
pw(val, 'S')
end
def write_word16_little(val)
str = [val].pack('S')
str.reverse! if ByteOrder.network? # swap bytes as native=network (and we want little)
write(str)
end
def write_word16_network(val)
str = [val].pack('S')
str.reverse! if ByteOrder.little? # swap bytes as native=little (and we want network)
write(str)
end
# === Signed
def write_int16_native(val)
pw(val, 's')
end
def write_int16_little(val)
pw(val, 'v')
end
def write_int16_network(val)
pw(val, 'n')
end
# == 32 bit
# === Unsigned
def write_word32_native(val)
pw(val, 'L')
end
def write_word32_little(val)
str = [val].pack('L')
str.reverse! if ByteOrder.network? # swap bytes as native=network (and we want little)
write(str)
end
def write_word32_network(val)
str = [val].pack('L')
str.reverse! if ByteOrder.little? # swap bytes as native=little (and we want network)
write(str)
end
# === Signed
def write_int32_native(val)
pw(val, 'l')
end
def write_int32_little(val)
pw(val, 'V')
end
def write_int32_network(val)
pw(val, 'N')
end
# add some short-cut functions
%w(word16 int16 word32 int32).each do |typ|
alias_method "write_#{typ}_big", "write_#{typ}_network"
end
# == Other methods
private
# shortcut for pack and write
def pw(val, template)
write([val].pack(template))
end
end
end
end