gnuk/tool/usb_strings.py

47 lines
1.4 KiB
Python
Raw Normal View History

2012-06-25 01:53:06 +00:00
#! /usr/bin/python
"""
usb_strings.py - a tool to dump USB string
Copyright (C) 2012, 2015, 2017 Free Software Initiative of Japan
2012-06-25 01:53:06 +00:00
Author: NIIBE Yutaka <gniibe@fsij.org>
This file is a part of Gnuk, a GnuPG USB Token implementation.
Gnuk is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gnuk is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from gnuk_token import *
2012-06-25 01:53:06 +00:00
import usb, sys
2015-07-15 07:37:19 +00:00
field = ['', 'Vendor', 'Product', 'Serial', 'Revision', 'Config', 'Sys', 'Board']
2012-06-25 01:53:06 +00:00
def main(n):
2015-08-04 02:57:46 +00:00
for dev in gnuk_devices_by_vidpid():
2012-06-25 01:53:06 +00:00
handle = dev.open()
try:
for i in range(1,n):
2015-08-03 07:44:38 +00:00
s = handle.getString(i, 512)
print("%10s: %s" % (field[i], s.decode('UTF-8')))
2012-06-25 01:53:06 +00:00
except:
pass
del dev
if __name__ == '__main__':
if len(sys.argv) > 1:
n = int(sys.argv[1])
else:
2015-07-15 07:37:19 +00:00
n = 8 # Gnuk has eight strings
2012-06-25 01:53:06 +00:00
main(n)