armando-basile/monosim

crash when reading the SIM

Closed this issue · 11 comments

What steps will reproduce the problem?
1. Use an empty SIM
2. Load a phonebook from a file into the SIM
3. Load the SIM phonebook

What is the expected output? What do you see instead?
monosim worked fine with the empty SIM. The PIN was asked and no records where 
displayed.
After I loaded 2 entries using monosim then monosim now crashes before asking 
for the PIN.

applicationPath = 
/home/lroussea/Téléchargements/monosim-1.5.2/monosim/bin/Release/languages
theKey = 1
readerToUse = Gemalto GemPC Twin 00 00
theReaderName = Gemalto GemPC Twin 00 00
nActiveProtocol = 1
retRName = Gemalto GemPC Twin 00 00
3F00 Response = 0000FFFF3F00010000000000098102090800838A838A9000
theReaderName = Gemalto GemPC Twin 00 00
nActiveProtocol = 1
retRName = Gemalto GemPC Twin 00 00
alphaID 1 = 4C75646F76696320526F75737365
Marshaling clicked signal
Exception in Gtk# callback delegate
  Note: Applications can use GLib.ExceptionManager.UnhandledException to handle the exception.
System.Reflection.TargetInvocationException: Exception has been thrown by the 
target of an invocation. ---> System.ArgumentOutOfRangeException: Cannot exceed 
length of string.
Parameter name: startIndex
  at System.String.Substring (Int32 startIndex, Int32 length) [0x00000] in <filename unknown>:0 
  at GladeApp.SwapTel (System.String numTel, System.String lenTel) [0x00000] in <filename unknown>:0 
  at GladeApp.decodeRecord (System.String dataIN, System.String& out1, System.String& out2) [0x00000] in <filename unknown>:0 
  at GladeApp.readSimContacts () [0x00000] in <filename unknown>:0 
  at GladeApp.On_ConnectSim_Press (System.Object sender, Gtk.ButtonReleaseEventArgs a) [0x00000] in <filename unknown>:0 
  at GladeApp.On_tbConnectSim_Clicked (System.Object sender, System.EventArgs a) [0x00000] in <filename unknown>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <filename unknown>:0 
  at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x00000] in <filename unknown>:0 
  at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00000] in <filename unknown>:0 
  at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in <filename unknown>:0 
  at GLib.Signal.ClosureInvokedCB (System.Object o, GLib.ClosureInvokedArgs args) [0x00000] in <filename unknown>:0 
  at GLib.SignalClosure.Invoke (GLib.ClosureInvokedArgs args) [0x00000] in <filename unknown>:0 
  at GLib.SignalClosure.MarshalCallback (IntPtr raw_closure, IntPtr return_val, UInt32 n_param_vals, IntPtr param_values, IntPtr invocation_hint, IntPtr marshal_data) [0x00000] in <filename unknown>:0 
   at GLib.ExceptionManager.RaiseUnhandledException(System.Exception e, Boolean is_terminal)
   at GLib.SignalClosure.MarshalCallback(IntPtr raw_closure, IntPtr return_val, UInt32 n_param_vals, IntPtr param_values, IntPtr invocation_hint, IntPtr marshal_data)
   at Gtk.Application.gtk_main()
   at Gtk.Application.Run()
   at GladeApp..ctor(System.String[] args)
   at GladeApp.Main(System.String[] args)

What version of the product are you using? On what operating system?

monosim version 1.5.2
Debian testing (mainly Squeeze plus some newer packages)

Please provide any additional information below.
The phonebook I tried to load is:

Ludovic Rousseau
+33123456789
Web site
+1987654321

Original issue reported on code.google.com by ludovic....@gmail.com on 26 Apr 2011 at 8:13

I got the issue when trying to write an article about monosim for my blog 
http://ludovicrousseau.blogspot.com/

Is monosim still maintained?

Original comment by ludovic....@gmail.com on 26 Apr 2011 at 8:20

Hi Ludovic,
i will try to reproduce problem. I see that problem could stay in SwapTel 
function. 

Many thanks for your article on your blog :)

> Is monosim still maintained?
yes, but releases are slow because i trying to add some fix/feature each 
release, and also because i working on some other open source projects.


Original comment by hmandevt...@gmail.com on 26 Apr 2011 at 9:36

  • Changed state: Accepted
Hi Ludovic,
to help me in debug of this and other smartcard applications i developed 
comex-project
http://comex-project.googlecode.com

So i prepare a .comex command file that you could use to obtain info that i 
need.


Original comment by hmandevt...@gmail.com on 31 Aug 2011 at 3:38

Comex is a more or less a mono equivalent of my gscriptor 
http://ludovic.rousseau.free.fr/softwares/pcsc-tools/index.html

Original comment by ludovic....@gmail.com on 31 Aug 2011 at 6:54

Hi Ludovic,
i release monosim-2.0.0.0-Alpha1 binaries in [Downloads] section. It need of 
log4net also installed.
It's an alpha so some features aren't still implemented but you can scan sim 
and read contacts. Please could you launch it with:
$ mono --debug monosim-gtk.exe --log-console --log-file

it generate console debug informations and also a log file (~/comex.log) so you 
could send me log file.

Original comment by hmandevt...@gmail.com on 9 Oct 2011 at 3:53

  • Changed state: Started
I get a "Cannot exceed length of string. Parameter name: startIndex" error just 
by reading my SIM card.



$ mono --debug monosim-gtk.exe --log-console --log-file
INFO  16:18:16 Application Started
INFO  16:18:16 Enabled also log in file: /home/rousseau/comex-base.log
INFO  16:18:16 System      Language Tag: fr-FR
INFO  16:18:17 Application Language Tag: en-US
DEBUG 16:18:17 PcscReader::CreateContext: SCardEstablishContext 00
DEBUG 16:18:17 GlobalObjUI::SetLanguage: 
LanguagePath=/home/rousseau/Téléchargements/monosim-2.0.0.0-Alpha1/Languages/m
onosim-en-US.xml
INFO  16:18:20 Changing reader to Gemalto GemPC Twin 01 00
DEBUG 16:18:22 PcscReader::ReleaseContext: SCardReleaseContext 00
DEBUG 16:18:22 PcscReader::CreateContext: SCardEstablishContext 00
DEBUG 16:18:22 MainWindowClass::GetSimPinStatus: SELECT MF 9F16
DEBUG 16:18:22 MainWindowClass::GetSimPinStatus: GET RESPONSE 
0000FFFF3F00010000000000098102090800838A838A9000
DEBUG 16:18:22 MainWindowClass::ReadIccId: SELECT ICCID 9F0F
DEBUG 16:18:23 MainWindowClass::ReadIccId: READ ICCID 000000000000000000009000
DEBUG 16:18:23 MainWindowClass::ReadADN: SELECT DF TELECOM 9F16
DEBUG 16:18:23 MainWindowClass::ReadADN: SELECT ADN 9F0F
DEBUG 16:18:23 MainWindowClass::ReadADN: GET RESPONSE 
000003486F3A04001100220102011C9000
DEBUG 16:18:23 GlobalObjUI.Sim::ReadSimContactsList: READ ADN REC 001 
4C75646F76696320526F75737365617507103321436587F9FFFFFFFF9000
DEBUG 16:18:23 GlobalObjUI.Sim::ReadSimContactsList: READ ADN REC 002 
5765622073697465FFFFFFFFFFFF06109178563412FFFFFFFFFFFFFF9000
DEBUG 16:18:23 GlobalObjUI.Sim::ReadSimContactsList: READ ADN REC 003 
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9000
DEBUG 16:18:23 GlobalObjUI.Sim::ReadSimContactsList: READ ADN REC 004 
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9000
DEBUG 16:18:23 GlobalObjUI.Sim::ReadSimContactsList: READ ADN REC 005 
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9000
DEBUG 16:18:23 GlobalObjUI.Sim::ReadSimContactsList: READ ADN REC 006 
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9000
DEBUG 16:18:23 GlobalObjUI.Sim::ReadSimContactsList: READ ADN REC 007 
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9000
DEBUG 16:18:24 GlobalObjUI.Sim::ReadSimContactsList: READ ADN REC 008 
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9000
DEBUG 16:18:24 GlobalObjUI.Sim::ReadSimContactsList: READ ADN REC 009 
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9000
DEBUG 16:18:24 GlobalObjUI.Sim::ReadSimContactsList: READ ADN REC 010 
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9000
DEBUG 16:18:24 GlobalObjUI.Sim::ReadSimContactsList: READ ADN REC 011 
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9000
DEBUG 16:18:24 GlobalObjUI.Sim::ReadSimContactsList: READ ADN REC 012 
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9000
DEBUG 16:18:24 GlobalObjUI.Sim::ReadSimContactsList: READ ADN REC 013 
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9000
DEBUG 16:18:24 GlobalObjUI.Sim::ReadSimContactsList: READ ADN REC 014 
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9000
DEBUG 16:18:24 GlobalObjUI.Sim::ReadSimContactsList: READ ADN REC 015 
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9000
DEBUG 16:18:24 GlobalObjUI.Sim::ReadSimContactsList: READ ADN REC 016 
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9000
DEBUG 16:18:24 GlobalObjUI.Sim::ReadSimContactsList: READ ADN REC 017 
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9000
DEBUG 16:18:24 GlobalObjUI.Sim::ReadSimContactsList: READ ADN REC 018 
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9000
DEBUG 16:18:24 GlobalObjUI.Sim::ReadSimContactsList: READ ADN REC 019 
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9000
DEBUG 16:18:25 GlobalObjUI.Sim::ReadSimContactsList: READ ADN REC 020 
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9000
DEBUG 16:18:25 GlobalObjUI.Sim::ReadSimContactsList: READ ADN REC 021 
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9000
DEBUG 16:18:25 GlobalObjUI.Sim::ReadSimContactsList: READ ADN REC 022 
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9000
DEBUG 16:18:25 GlobalObjUI.Sim::ReadSimContactsList: READ ADN REC 023 
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9000
DEBUG 16:18:25 GlobalObjUI.Sim::ReadSimContactsList: READ ADN REC 024 
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9000
DEBUG 16:18:25 GlobalObjUI.Sim::ReadSimContactsList: READ ADN REC 025 
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9000
DEBUG 16:18:25 GlobalObjUI.Sim::ReadSimContactsList: READ ADN REC 026 
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9000
DEBUG 16:18:25 GlobalObjUI.Sim::ReadSimContactsList: READ ADN REC 027 
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9000
DEBUG 16:18:25 GlobalObjUI.Sim::ReadSimContactsList: READ ADN REC 028 
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9000
DEBUG 16:18:25 GlobalObjUI.Sim::ReadSimContactsList: READ ADN REC 029 
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9000
DEBUG 16:18:25 GlobalObjUI.Sim::ReadSimContactsList: READ ADN REC 030 
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9000
ERROR 16:18:25 GlobalObjUI::DecodeSimADNRecord: Cannot exceed length of string.
Parameter name: startIndex
  at System.String.Substring (Int32 startIndex, Int32 length) [0x00000] in <filename unknown>:0 
  at monosimbase.GlobalObjUI.SwapNumber (System.String inNumber, Int32 numDigits) [0x0000d] in /media/ARMANDO_02G/csharp/monosim-solution/base-components/GlobalObjUI.cs:265 
  at monosimbase.GlobalObjUI.DecodeSimADNRecord (System.String recordValue) [0x000a2] in /media/ARMANDO_02G/csharp/monosim-solution/base-components/GlobalObjUI.cs:203 
DEBUG 16:18:40 PcScReader.IReader::CloseConnection: SCardDisconnect 0

Original comment by ludovic....@gmail.com on 13 Oct 2011 at 2:20

if you see pages 75, 76, 77 of 
http://www.ttfn.net/techno/smartcards/GSM11-11v6-2.pdf (GSM 11.11 
specifications) you see ADN record file structure. You can see that phonebook 
record have a MANDATORY tags sequence:
Alpha Identifier,
Length of BCD number/SSC contents,
TON and NPI,
Dialling Number/SSC String,
Capability/Configuration Identifier,
Extension1 Record Identifier

so Alpha tag len is calc using: record len - 14 bytes. In your case rec len is 
28 and your Aplha tag should be 14, instead you use 16 bytes in rec1:
4C75646F76696320526F757373656175 = Ludovic Rousseau

and 14 in rec 2
5765622073697465FFFFFFFFFFFF = Web site


Another thing, after 'Len of BCD number/SSC contents' is mandatory byte TonNpi 
than in all 2 records is missing.

As sample, in one of tested sim i have this contact
Music&Fun - 4444
record is
4D757369632646756EFFFFFFFFFF03814444FFFFFFFFFFFFFFFFFFFF
Alpha len 14 (28 bytes -14)
4D757369632646756EFFFFFFFFFF = Music&Fun

after there is 03 = 'Len of BCD number/SSC contents'
after there is 81 = TonNpi
after there is 4444 = phone number.

An example of your rec1 correct could be:
4C75646F76696320526F75737365 = Ludovic Rousse (14 bytes)
08 = 'Len of BCD number/SSC contents'
81 = TonNpi
103321436587F9FFFFFF = Phone number of 10 bytes
FF = Capability/Configuration Identifier
FF = Extension1 Record Identifier




Original comment by hmandevt...@gmail.com on 14 Oct 2011 at 10:06

sorry, in your records tonnpi is present so problem is present i think only in 
your first record because Alpha tag is more that 14 bytes. Could you try to 
write this 2 records using as Alpha tag of first 'Ludovic Rousse' ?
It might be sufficient to read sim with monosim

Original comment by hmandevt...@gmail.com on 14 Oct 2011 at 10:24

I used monosim itself to enter this first record in the SIM card :-)
The SIM was empty at the beginning.

Can you fix monosim so that it does not crash and I have a chance to update the 
record?

Original comment by ludovic....@gmail.com on 15 Oct 2011 at 7:12

of course, i also will send you a command file to use with comex to modify 
record

Original comment by hmandevt...@gmail.com on 15 Oct 2011 at 8:14

fixed in r70
i added specific method to parse each contact before write on sim
http://code.google.com/p/monosim/source/browse/trunk/base-components/GlobalObjUI
.cs#167


Original comment by hmandevt...@gmail.com on 15 Oct 2011 at 10:34

  • Changed state: Fixed