-
Notifications
You must be signed in to change notification settings - Fork 23
/
dump_gdbindexes.py
85 lines (72 loc) · 2.77 KB
/
dump_gdbindexes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python
# -*- coding: utf-8 -*-
###############################################################################
# $Id$
#
# Project: GDAL/OGR
# Purpose: Dump FileGDB .gdbindexes content
# Author: Even Rouault <even dot rouault at mines dash paris dot org>
#
###############################################################################
# Copyright (c) 2013, Even Rouault <even dot rouault at mines dash paris dot org>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
###############################################################################
import struct
import sys
if len(sys.argv) != 2:
print('Usage: dump_gdbindexes.py some_file.gdbindexes')
sys.exit(1)
filename = sys.argv[1]
def read_uint8(f):
return ord(f.read(1))
def read_uint16(f):
v = f.read(2)
return struct.unpack('H', v)[0]
def read_int32(f):
v = f.read(4)
return struct.unpack('i', v)[0]
def read_utf16(f, nbcar):
# FIXME : only works with ASCII currently
val = ''
for j in range(nbcar):
val = val + '%c' % read_uint8(f)
f.read(1)
return val
f = open(filename, 'rb')
nindexes = read_int32(f)
print('nindexes = %d' % nindexes)
for i in range(nindexes):
idx_name_length_utf16_car = read_int32(f)
idx_name = read_utf16(f, idx_name_length_utf16_car)
print('idx_name = %s' % idx_name)
magic1 = read_uint16(f)
magic2 = read_int32(f)
magic3 = read_uint16(f)
magic4 = read_int32(f)
print('magic1 = %d' % magic1)
print('magic2 = %d' % magic2)
print('magic3 = %d' % magic3)
print('magic4 = %d' % magic4)
col_name_length_utf16_car = read_int32(f)
col_name = read_utf16(f, col_name_length_utf16_car)
print('col_name = %s' % col_name)
magic5 = read_uint16(f)
print('magic5 = %d' % magic5)
print('')