Revision 9a3428e4
Added by Neels Hofmeyr over 4 years ago
sim-applet/src/org/osmocom/IMSIPseudo/IMSIPseudo.java | ||
---|---|---|
102 | 102 |
return resp; |
103 | 103 |
} |
104 | 104 |
|
105 |
/* |
|
106 |
This was used to find out that the first byte of a text field seems to be 4. |
|
107 |
private byte[] getResponseDBG() |
|
108 |
{ |
|
109 |
ProactiveResponseHandler rspHdlr; |
|
110 |
byte resp[]; |
|
111 |
byte strlen = -1; |
|
112 |
rspHdlr = ProactiveResponseHandler.getTheHandler(); |
|
113 |
|
|
114 |
for (byte occurence = 1; occurence <= 3; occurence++) { |
|
115 |
short len; |
|
116 |
try { |
|
117 |
if (rspHdlr.findTLV(TAG_TEXT_STRING, (byte)occurence) != TLV_NOT_FOUND) { |
|
118 |
if ((len = rspHdlr.getValueLength()) > 1) { |
|
119 |
len = 3; |
|
120 |
resp = new byte[len]; |
|
121 |
rspHdlr.copyValue((short)0, resp, (short)0, (short)(len)); |
|
122 |
showMsg(resp); |
|
123 |
showMsgAndWaitKey(Bytes.hexdump(resp)); |
|
124 |
return resp; |
|
125 |
} |
|
126 |
} |
|
127 |
} catch (Exception e) { |
|
128 |
showError((short)(30 + occurence)); |
|
129 |
return null; |
|
130 |
} |
|
131 |
} |
|
132 |
showError((short)(39)); |
|
133 |
return null; |
|
134 |
} |
|
135 |
*/ |
|
136 |
|
|
105 | 137 |
private byte[] showMsgAndWaitKey(byte[] msg) { |
106 | 138 |
ProactiveHandler proHdlr = ProactiveHandler.getTheHandler(); |
107 | 139 |
proHdlr.initGetInkey((byte)0, DCS_8_BIT_DATA, msg, (short)0, (short)(msg.length)); |
... | ... | |
110 | 142 |
return getResponse(); |
111 | 143 |
} |
112 | 144 |
|
113 |
private byte[] prompt(byte[] msg, short minLen, short maxLen) { |
|
145 |
private byte[] prompt(byte[] msg, byte[] prefillVal, short minLen, short maxLen) {
|
|
114 | 146 |
/* if maxLen < 1, the applet crashes */ |
115 | 147 |
if (maxLen < 1) |
116 | 148 |
maxLen = 1; |
117 | 149 |
|
118 | 150 |
ProactiveHandler proHdlr = ProactiveHandler.getTheHandler(); |
119 | 151 |
proHdlr.initGetInput((byte)0, DCS_8_BIT_DATA, msg, (short)0, (short)(msg.length), minLen, maxLen); |
152 |
if (prefillVal != null && prefillVal.length > 0) { |
|
153 |
/* appendTLV() expects the first byte to be some header before the actual text. |
|
154 |
* At first I thought it was the value's length, but turned out to only work for lengths under 8... |
|
155 |
* In the end I reversed the value 4 from the first byte read by rspHdlr.copyValue() for |
|
156 |
* TAG_TEXT_STRING fields. As long as we write 4 into the first byte, things just work out, |
|
157 |
* apparently. |
|
158 |
* Fucking well could have said so in the API docs, too; oh the brain damage, oh the hours wasted. |
|
159 |
* This is the appendTLV() variant that writes one byte ahead of writing an array: */ |
|
160 |
proHdlr.appendTLV((byte)(TAG_DEFAULT_TEXT), (byte)4, prefillVal, (short)0, |
|
161 |
(short)(prefillVal.length)); |
|
162 |
} |
|
120 | 163 |
proHdlr.send(); |
121 | 164 |
|
122 | 165 |
return getResponse(); |
Also available in: Unified diff
prompt(): add prefillVal arg