How to find running application size programatically in blackberry? - blackberry

i want to find the size of running application of blackberry by code.I checked the how to find application size in blackberry by code? link but i am not getting answer. Please suggest me solution. Thanks in advance.

If you mean of size of running application that size of total cod files
then we can calculate.
when we instal application using JAD we can see the application size.
For example: my application name is PictureBackground
After successful sign in application we can take cod fils and jad file for devise installation. when we click on PictureBackground.jad then we can find following type of information
Name: PictureBackground
Version: 1.0.0
Vender: Blackberry Developer
Size: 513.4kb
If you want to pragmatically retrieve that size, then we can do it as following
we can find all information about application in PictureBackground.jad file
For example PictureBackground.jad file as follow:
RIM-COD-SHA1-4: ff 3c 2f ec 7b 6a 3d 1a e3 86 ec d2 87 0a c3 e1 6c f3 14 0e
RIM-COD-SHA1-3: 07 4d f7 db 9a f3 df 1d 00 90 b6 4f 54 f0 3a f0 c8 de ca b1
RIM-COD-SHA1-2: 95 14 4a 6a 7d 3a 1b db 2e 0f 05 b8 e1 ff 66 8a e0 ce f1 64
RIM-COD-SHA1-1: 68 a7 09 4e dc cf 2f c1 9b 43 d1 0b 35 b8 4b bc 35 72 ba 92
RIM-MIDlet-Flags-1: 0
MIDlet-Jar-Size: 591513
MIDlet-Name: PictureBackground
MIDlet-Jar-URL: PictureBackground.jar
MicroEdition-Configuration: CLDC-1.1
RIM-COD-URL-9: PictureBackground-9.cod
RIM-COD-URL-8: PictureBackground-8.cod
RIM-COD-URL-7: PictureBackground-7.cod
RIM-COD-Module-Dependencies: net_rim_cldc
RIM-COD-URL-6: PictureBackground-6.cod
RIM-COD-URL-5: PictureBackground-5.cod
RIM-COD-URL-4: PictureBackground-4.cod
RIM-COD-URL-3: PictureBackground-3.cod
RIM-COD-URL-2: PictureBackground-2.cod
RIM-COD-URL-1: PictureBackground-1.cod
RIM-COD-Size-9: 51288
RIM-COD-Size-8: 55284
RIM-COD-Size-7: 58560
RIM-COD-Size-6: 51340
RIM-COD-Size-5: 55748
RIM-COD-Size-4: 53000
RIM-COD-Size-3: 55084
RIM-COD-Module-Name: PictureBackground
RIM-COD-Size-2: 51284
RIM-COD-Size-1: 60448
RIM-COD-SHA1: 55 82 db c2 8c 44 73 c8 44 b6 ce 7f 20 bb 70 47 d2 df fe ab
RIM-COD-Size: 33688
MicroEdition-Profile: MIDP-2.0
MIDlet-Vendor: BlackBerry Developer
MIDlet-1: PictureBackground,,
RIM-COD-URL: PictureBackground.cod
Manifest-Version: 1.0
MIDlet-Version: 1.0.0
RIM-COD-SHA1-9: 76 04 75 59 21 27 c6 18 97 ed 49 fb ce 03 f3 21 fd 63 c1 96
RIM-COD-SHA1-8: 79 a9 b7 85 59 aa 06 e6 4b 76 89 de 12 cd 10 0d 54 93 48 dd
RIM-COD-SHA1-7: 3d d1 d1 47 e3 8d b5 9d 57 89 51 e3 a9 b3 77 5e c4 57 17 a8
RIM-COD-Creation-Time: 1327931490
RIM-COD-SHA1-6: f7 78 f7 b3 46 f5 69 91 9d 87 33 d0 a9 9d 9b 92 b6 de 90 74
RIM-COD-SHA1-5: 98 b3 45 64 8b 5f 36 0a aa c1 0e 2e 66 ea 7a f7 50 37 05 7a
Through this we can find the running application size
Sample code :
package samplecode;
import java.util.Enumeration;
import net.rim.device.api.system.ApplicationDescriptor;
import net.rim.device.api.system.CodeModuleGroup;
import net.rim.device.api.system.CodeModuleGroupManager;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;
public class StartUp extends UiApplication{
public static void main(String[] args) {
StartUp up=new StartUp();
up.enterEventDispatcher();
}
public StartUp()
{
MainScreen screen=new MainScreen();
CodeModuleGroup cmg = null;
CodeModuleGroup[] allGroups = CodeModuleGroupManager.loadAll();
String moduleName = ApplicationDescriptor.currentApplicationDescriptor().getModuleName();
for (int i = 0; i < allGroups.length; i++) {
if (allGroups[i].containsModule(moduleName)) {
cmg = allGroups[i];
break;
}
}
if (cmg == null) {
screen.add(new LabelField("not able to fetch properties"));
} else {
double size=0;
for (Enumeration e = cmg.getPropertyNames(); e
.hasMoreElements();) {
String name = (String) e.nextElement();
String value = cmg.getProperty(name);
if(name.indexOf("RIM-COD-Size")!=-1)
{
size=size+Double.parseDouble(value);
}
//add(new LabelField("Name: " + name));
}
screen.add(new LabelField("Size: " +(size/1024)+"kb"));
}
UiApplication.getUiApplication().pushScreen(screen);
}
}
NOTE: IT WONT WORK ON SIMULATOR, IT WORKS ON DEVISE(IT SHOULD BE INSTALL FROM JAD FILE) AND WE CAN FIND OUTPUT AS FOLLOWING
size:513.40234375KB

Related

Lazarus/FreePascal, Synapse send file to TCPBlockSocket

I tried to make an analogue nc (netcat) tool.
Open file and send it in to TCP socket.
client (sender) side
procedure TForm1.SpeedButton3Click(Sender: TObject);
var Client:TTCPBlockSocket;
FS: TFileStream;
begin
Client:=TTCPBlockSocket.Create;
Client.RaiseExcept:=True;
Client.Connect('192.168.1.95','9999');
FS:=TFileStream.Create('/tmp/test_print.pdf',fmOpenRead);
FS.Position:=0;
Client.SendStream(FS);
FS.Free;
Client.CloseSocket;
Client.Free;
end;
server (reciever) side
nc -l 192.168.1.95 9999 > test.pdf
After run i get test.pdf but md5sum not valid
fe2e5d86acd267ca39a9c15c456e1be0 /tmp/test_print.pdf
34d755aa81d72f525a5e691e98bed283 test.pdf
size is differ too
-rw-rw---- 1 user1 DomainUsers 46444 Июн 8 17:11 /tmp/test_print.pdf
-rw-r--r-- 1 user1 DomainUsers 46448 Июн 11 15:40 test.pdf
What i do wrong? Where is my mistake?
p.s. Excess 4 bytes at the beginning of test.pdf (6c,b5,00,00)
[user1#pandora6 /tmp]$ hexdump -C test.pdf | head -5
00000000 6c b5 00 00 25 50 44 46 2d 31 2e 34 0a 25 c7 ec |l...%PDF-1.4.%..|
00000010 8f a2 0a 34 20 30 20 6f 62 6a 0a 3c 3c 2f 4c 69 |...4 0 obj.<</Li|
00000020 6e 65 61 72 69 7a 65 64 20 31 2f 4c 20 34 36 34 |nearized 1/L 464|
00000030 34 34 2f 48 5b 20 34 33 39 36 38 20 31 34 32 5d |44/H[ 43968 142]|
00000040 2f 4f 20 36 2f 45 20 34 33 39 36 38 2f 4e 20 31 |/O 6/E 43968/N 1|
[user1#pandora6 /tmp]$ hexdump -C /tmp/test_print.pdf | head -5
00000000 25 50 44 46 2d 31 2e 34 0a 25 c7 ec 8f a2 0a 34 |%PDF-1.4.%.....4|
00000010 20 30 20 6f 62 6a 0a 3c 3c 2f 4c 69 6e 65 61 72 | 0 obj.<</Linear|
00000020 69 7a 65 64 20 31 2f 4c 20 34 36 34 34 34 2f 48 |ized 1/L 46444/H|
00000030 5b 20 34 33 39 36 38 20 31 34 32 5d 2f 4f 20 36 |[ 43968 142]/O 6|
00000040 2f 45 20 34 33 39 36 38 2f 4e 20 31 2f 54 20 34 |/E 43968/N 1/T 4|
Well... Hex 00 00 B5 6C (your extra bytes in reverse) is equal to 46444. So my guess is that TFileStream or SendStream sends the number of bytes it wants to send before the actual data.
Looking at the code of Synapse there is the function:
procedure TBlockSocket.InternalSendStream(const Stream: TStream; WithSize, Indy: boolean);
And SendStream calls it like this:
InternalSendStream(Stream, true, false);
So the WithSize is true and the size of the stream is send before the actual data.
If you use SendStreamRaw all is send without the size in front of it.
procedure TForm1.SpeedButton3Click(Sender: TObject);
var Client:TTCPBlockSocket;
FS: TFileStream;
begin
Client:=TTCPBlockSocket.Create;
Client.RaiseExcept:=True;
Client.Connect('192.168.1.95','9999');
FS:=TFileStream.Create('/tmp/test_print.pdf',fmOpenRead);
FS.Position:=0;
Client.SendStreamRAW(FS);
FS.Free;
Client.CloseSocket;
Client.Free;
end;

Converting a string to a list of integers in Erlang

I am trying to convert a string to a list of integers.
String = "08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08".
But
lists:map(fun(X) -> string:to_integer(X) end, string:tokens(String, " ")).
just gives me...
[{8,[]}, {2,[]}, {22,[]}, {97,[]}, ... , {91,[]}, {8,[]}]
Can someone perhaps tell me what a good/nice way would be to get?
[8,2,22,97...91,8]
(Or do I need a helper function?)
This works:
String = "08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08".
lists:map(fun(X) -> {Int, _} = string:to_integer(X),
Int end,
string:tokens(String, " ")).
> [8,2,22,97,38,15,0,40,0,75,4,5,7,78,52,12,50,77,91,8]
See, string:to_integer returns not a single integer, but a tuple:
to_integer(String) -> {Int,Rest} | {error,Reason}
... so you have to extract the first element from this tuple to get the actual number.
Also, you might use list generator syntax:
[begin {Int,_}=string:to_integer(Token), Int end|| Token<-string:tokens(String," ")].
From shell:
1> String = "08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08".
"08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08"
2>
2> [begin {Int,_}=string:to_integer(Token), Int end|| Token<-string:tokens(String," ")].
[8,2,22,97,38,15,0,40,0,75,4,5,7,78,52,12,50,77,91,8]
[list_to_integer(X)|| X<-string:tokens(String," ")].

Parsing AMF3 objects

I'm trying to decode an AMF0 message with AMF3 included .. All is well
except making sense of the U29 format and the way string are encoded
in AMF4
channel=3 size=134 pkttype=0x11 time=1973
00000: 00 02 00 14 73 65 6E 64 55 6E 69 76 65 72 73 61 6C 4D 65 73 ....sendUniversalMes
00020: 73 61 67 65 00 00 00 00 00 00 00 00 00 05 02 00 11 6D 62 5F sage.............mb_
00040: 31 32 32 31 30 5F 37 35 39 32 33 33 38 30 05 00 40 58 C0 00 12210_75923380..#X..
00060: 00 00 00 00 11 0A 0B 01 09 68 62 69 64 04 81 CF 5E 09 73 72 .........hbid...^.sr
00080: 63 65 06 49 63 37 62 39 32 33 65 65 2D 30 61 30 38 2D 34 62 ce.Ic7b923ee-0a08-4b
00100: 61 32 2D 38 65 37 63 2D 63 38 32 61 39 33 64 37 37 31 34 32 a2-8e7c-c82a93d77142
00120: 09 68 62 64 6C 04 00 09 74 65 78 74 01 01 .hbdl...text..
first byte I skip
02 = string
00 14 = length of string ( 20 characters , sendUniversalMessage )
00 00 00 00 00 00 00 00 00 = number = 0
05 = null
02 = string
00 11 = length of string ( 17 characters , mb_12210_75923380 )
05 = null
00 40 58 C0 00 00 00 00 00 = number = 99
11 = AMV+
here is where I have problems
0A = AMF3 object
now I need to do a readU29 which starts with
0B = what does this mean
01 = what does this mean
09 = what does this mean
where is the length of the string 'hbid' ?
in U29, if the first byte is worth less than 128, it fits on the first byte. So you have to read this as 3 different u29s, worth 0B, 01, 09.
0B: details about the type of object. It seems you're not too interested in that byte and it's complicated, so pass.
01: The LSB is the bit that says that this isn't a string reference. Then 01 >> 1 = 0 is the length of the class name. This means empty string, which means this is an anonymous (untyped) object.
09: = 00001001. The LSB is also the bit that says this isn't a string reference. Then 1001 >> 1 = 0100 = 4 is the string length.
hope that helps

Problem with TRandomStream - Delphi TurboPower LockBox 3

I am using TurboPower LockBox 3 (http://sourceforge.net/projects/tplockbox/ and http://lockbox.seanbdurkin.id.au/tiki-index.php)
I have a problem with the TRandomStream. I'm trying to generate a chunk of 32 byte random data, but the output does not seem to be random.
The code is:
function StringToHex(S: String): String;
var I: Integer;
begin
Result:= '';
for I := 1 to length (S) do
Result:= Result+IntToHex(ord(S[i]),2)+' ';
end;
procedure TForm1.btn1Click(Sender: TObject);
const
Len = 32;
var
j,k: Integer;
P: Pointer;
Str: AnsiString;
begin
GetMem(P,Len);
TRandomStream.Instance.Randomize;
SetLength(Str,Len);
for j := 1 to 20 do
begin
TRandomStream.Instance.Read(P^,Len);
for k := 0 to Len-1 do
begin
Str[k+1]:=PAnsiChar(P)[k];
end;
mmoOutput.Lines.Add('> '+StringToHex(Str));
end;
FreeMem(P,Len);
end;
The output is:
> 91 79 00 77 FD F7 1C 51 22 64 BA 07 9F 87 8F B2 85 94 92 84 6B F7 5B 55 1A 0D DE E5 44 4A 56 DA
> A5 A6 C3 3D DB 01 69 61 5A 66 D8 ED 3F 3B 4D 00 A5 D7 CB 84 BB 40 CE 3E 5A 90 54 DD BF 63 0E 2C
> A5 5F 75 70 76 1F 08 25 5A E0 8D F0 9C 0B 15 F7 A5 9F C1 A7 F9 7C FF BA 5A 60 58 60 B5 97 F4 25
> A5 9F 23 E2 09 D2 74 52 5A 60 AC 5E 6E D8 B6 81 A5 9F 33 B5 2B B8 B5 15 5A 60 4C 51 96 DB 68 66
> A5 9F B3 4D 3A 51 4C 0D 5A 60 4C E6 D5 4C F8 83 A5 9F B3 11 AF 19 DB 2D 5A 60 4C 8E D2 D6 49 70
> A5 9F B3 31 55 5D D1 28 5A 60 4C CE B7 26 56 C8 A5 9F B3 31 86 7A 83 A0 5A 60 4C CE E1 A5 B8 E8
> A5 9F B3 31 0E 64 14 5E 5A 60 4C CE 31 9F CC EB A5 9F B3 31 4E B0 9B 4A 5A 60 4C CE B1 69 6C 04
> A5 9F B3 31 4E 12 D6 AE 5A 60 4C CE B1 BD 6A C9 A5 9F B3 31 4E 22 A9 D0 5A 60 4C CE B1 5D 5D F1
> A5 9F B3 31 4E A2 41 DF 5A 60 4C CE B1 5D F2 30 A5 9F B3 31 4E A2 05 54 5A 60 4C CE B1 5D 9A 2D
> A5 9F B3 31 4E A2 25 FA 5A 60 4C CE B1 5D DA 12 A5 9F B3 31 4E A2 25 2B 5A 60 4C CE B1 5D DA 3C
> A5 9F B3 31 4E A2 25 B3 5A 60 4C CE B1 5D DA 8C A5 9F B3 31 4E A2 25 F3 5A 60 4C CE B1 5D DA 0C
> A5 9F B3 31 4E A2 25 F3 5A 60 4C CE B1 5D DA 0C A5 9F B3 31 4E A2 25 F3 5A 60 4C CE B1 5D DA 0C
> A5 9F B3 31 4E A2 25 F3 5A 60 4C CE B1 5D DA 0C A5 9F B3 31 4E A2 25 F3 5A 60 4C CE B1 5D DA 0C
> A5 9F B3 31 4E A2 25 F3 5A 60 4C CE B1 5D DA 0C A5 9F B3 31 4E A2 25 F3 5A 60 4C CE B1 5D DA 0C
> A5 9F B3 31 4E A2 25 F3 5A 60 4C CE B1 5D DA 0C A5 9F B3 31 4E A2 25 F3 5A 60 4C CE B1 5D DA 0C
> A5 9F B3 31 4E A2 25 F3 5A 60 4C CE B1 5D DA 0C A5 9F B3 31 4E A2 25 F3 5A 60 4C CE B1 5D DA 0C
> A5 9F B3 31 4E A2 25 F3 5A 60 4C CE B1 5D DA 0C A5 9F B3 31 4E A2 25 F3 5A 60 4C CE B1 5D DA 0C
> A5 9F B3 31 4E A2 25 F3 5A 60 4C CE B1 5D DA 0C A5 9F B3 31 4E A2 25 F3 5A 60 4C CE B1 5D DA 0C
> A5 9F B3 31 4E A2 25 F3 5A 60 4C CE B1 5D DA 0C A5 9F B3 31 4E A2 25 F3 5A 60 4C CE B1 5D DA 0C
> A5 9F B3 31 4E A2 25 F3 5A 60 4C CE B1 5D DA 0C A5 9F B3 31 4E A2 25 F3 5A 60 4C CE B1 5D DA 0C
Which does not seem to be random.
What am I doing wrong?
Thanks and regards.
OK. I've found the problem and a fix. Procedure TRandomStream.Crunch uses Compiler Version switching:
For Compiler Version > 17
FValue := FValue * Factor + 1 ;
Whilst for Compiler Version <= 17 (which is my case), the use of the function SquarePlus1Int64_NoOverflowChecks equates to:
FValue := FValue * FValue + 1;
To fix change:
function SquarePlus1Int64_NoOverflowChecks(Factor: int64): int64;
begin
result := Factor * Factor + 1
end;
to
function MultiplyPlus1Int64_NoOverflowChecks(Value,Factor: int64): int64;
begin
result := Value * Factor + 1
end;
and in TRandomStream.Crunch change:
FValue := SquarePlus1Int64_NoOverflowChecks(FValue);
to
FValue := MultiplyPlus1Int64_NoOverflowChecks(FValue, Factor);

Chromium closes WebSocket with no explanation

I have Chromium 12.0.742.112 (90304) and I'm trying to set up a simple WebSocket server with it. I receive a handshake request like:
Upgrade: WebSocket
Connection: Upgrade
Host: akira:22222
Origin: http://akira:22222
Sec-WebSocket-Key1: ;39LP*eC48 n /r0P6 v6548
Sec-WebSocket-Key2: 1 0 r 362547 4 4 G
followed by 8 key bytes, in this case 88 09 F9 EE 21 13 F4 0D. I've verified that these are the same keys Chromium shows in the Network console tab. I calculate the first two keys as:
Key1: 3948066548 / 4 = 987016637
Key2: 1036254744 / 12 = 86354562
and send my response:
000001 48 54 54 50 2F 31 2E 31 20 31 30 31 20 57 65 62 HTTP/1.1 101 Web
000011 20 53 6F 63 6B 65 74 20 50 72 6F 74 6F 63 6F 6C Socket Protocol
000021 20 48 61 6E 64 73 68 61 6B 65 0D 0A 55 70 67 72 Handshake..Upgr
000031 61 64 65 3A 20 57 65 62 53 6F 63 6B 65 74 0D 0A ade: WebSocket..
000041 43 6F 6E 6E 65 63 74 69 6F 6E 3A 20 55 70 67 72 Connection: Upgr
000051 61 64 65 0D 0A 53 65 63 2D 57 65 62 53 6F 63 6B ade..Sec-WebSock
000061 65 74 2D 4F 72 69 67 69 6E 3A 20 68 74 74 70 3A et-Origin: http:
000071 2F 2F 61 6B 69 72 61 3A 32 32 32 32 32 0D 0A 53 //akira:22222..S
000081 65 63 2D 57 65 62 53 6F 63 6B 65 74 2D 4C 6F 63 ec-WebSocket-Loc
000091 61 74 69 6F 6E 3A 20 77 73 3A 2F 2F 61 6B 69 72 ation: ws://akir
0000A1 61 3A 32 32 32 32 32 2F 73 6F 63 6B 65 74 0D 0A a:22222/socket..
0000B1 0D 0A FF F4 2E 12 9D DC 12 C2 56 40 B8 09 F3 84 ..........V#....
0000C1 CA EF .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..##############
Chromium just closes the socket without even printing a message in the JS console. I can't tell what I'm doing wrong?
The server-side code is in Lua (thus why the above hex dump is indexed starting from 1):
require('crypto')
local handshake = {
"HTTP/1.1 101 Web Socket Protocol Handshake",
"Upgrade: WebSocket",
"Connection: Upgrade",
"Sec-WebSocket-Origin: " .. request.header.origin,
"Sec-WebSocket-Location: " ..
request.header.origin:gsub('http:', 'ws:') .. "/socket",
'\r\n'}
log.debug("Request header:\n%s\n", table.concat(request.rawheader, '\n'))
local client = response.socket
client:settimeout(10)
local keys =
{request.header.sec_websocket_key1, request.header.sec_websocket_key2}
local sum = {}
for i, k in ipairs(keys) do
local nspc = 0
sum[i] = ''
k:gsub('%d', function(n) sum[i] = sum[i] ..n end)
k:gsub(' ', function() nspc = nspc + 1 end)
log.debug("Key%d: %s / %d = ", i, sum[i], nspc)
sum[i] = tostring(tonumber(sum[i]) / nspc)
log.debug("%s\n", sum[i])
end
local key = assert(client:receive(8))
local bytes = {key:byte(1, #key)}
local keydump = {}
for i = 1, #bytes do keydump[i] = ('%02X'):format(bytes[i]) end
log.debug("Key3: %s\n", table.concat(keydump, ' '))
local resp = crypto.evp.digest('md5', table.concat(sum) .. key, true)
handshake = table.concat(handshake, '\r\n') .. resp
client:settimeout(0.1)
log.debug("Send handshake:\n%s\n", rena.debug.hexdump(handshake))
client:send(handshake)
repeat
local res, err = client:receive('*l')
if res then log.debug("R: %s\n", res) end
local res, err = client:send("Test " .. tostring(os.time()) .. '\n')
if res then socket.sleep(1)
elseif err == 'timeout' then log.debug("WS: Timed out\n")
elseif err == 'closed' then log.debug("WS: Closed\n")
else log.error("WS: Error: %s\n", tostring(err))
end
until not res
(This script is loaded by the server script which presets some variables such as request and response, and uses LuaCrypto for MD5). Everything looks right (though I notice all the examples show nice ASCII characters for the binary keys whereas mine are mostly unprintable), but it just closes the socket.
Unfortunately Chromium is the only browser I have that supports WebSocket at all (unless there's some way to enable it in Firefox 6?), so I can't check in anything else.
Well I found the issue. The first two keys are meant to be concatenated as 32-bit integers (into a single 64-bit integer), not as ASCII strings:
- sum[i] = tostring(tonumber(sum[i]) / nspc)
+ sum[i] = ('%08X'):format(tonumber(sum[i]) / nspc)
- local resp = crypto.evp.digest('md5', table.concat(sum) .. key, true)
- handshake = table.concat(handshake, '\r\n') .. resp
+ local challenge = ''
+ (sum[1] .. sum[2]):gsub('..', function(byte)
+ challenge = challenge .. string.char(tonumber(byte, 16))
+ end)
+
+ challenge = challenge .. key
+ log.debug("Ch: %s\n", challenge:tohex())
+
+ local resp = crypto.evp.digest('md5', challenge, true)
+ handshake = table.concat(handshake, '\r\n') .. resp
With that Chromium accepts the connection. I've filed a bug to complain about the lack of error message with an incorrect hash.

Resources