Skip to content

Commit a6cb28d

Browse files
committed
fixed some conversion from primitive types to Java ones. fixes cSploit/android#118 .
1 parent 967bc1a commit a6cb28d

4 files changed

Lines changed: 47 additions & 34 deletions

File tree

cSploitClient/cache.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ int init_csploit_events_cache(JNIEnv *env) {
130130
{ "org/csploit/android/events/Account", "(Ljava/net/InetAddress;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V" },
131131
{ "org/csploit/android/events/Message", "(Ljava/lang/String;Ljava/lang/String;)V" },
132132
{ "org/csploit/android/events/Login", "(ILjava/net/InetAddress;Ljava/lang/String;Ljava/lang/String;)V" },
133-
{ "org/csploit/android/events/Attempts", "(JJJJJ)V" },
134-
{ "org/csploit/android/events/Packet", "(Ljava/net/InetAddress;Ljava/net/InetAddress;S)V" },
133+
{ "org/csploit/android/events/Attempts", "(JJJJ)V" },
134+
{ "org/csploit/android/events/Packet", "(Ljava/net/InetAddress;Ljava/net/InetAddress;I)V" },
135135
{ "org/csploit/android/events/FuseBind", "(Ljava/lang/String;Ljava/lang/String;)V" },
136136
{ "org/csploit/android/events/Host", "([BLjava/net/InetAddress;Ljava/lang/String;)V" },
137137
{ "org/csploit/android/events/HostLost", "(Ljava/net/InetAddress;)V" },
@@ -240,6 +240,15 @@ void _free_cache(JNIEnv *env) {
240240
&(cache.csploit.events.hop.class),
241241
&(cache.csploit.events.port.class),
242242
&(cache.csploit.events.os.class),
243+
&(cache.csploit.events.ready.class),
244+
&(cache.csploit.events.account.class),
245+
&(cache.csploit.events.message.class),
246+
&(cache.csploit.events.login.class),
247+
&(cache.csploit.events.attempts.class),
248+
&(cache.csploit.events.packet.class),
249+
&(cache.csploit.events.fusebind.class),
250+
&(cache.csploit.events.host.class),
251+
&(cache.csploit.events.hostlost.class),
243252
};
244253

245254
for(i=0;i<NUMELEM(global_refs); i++) {

cSploitClient/event.c

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ jobject create_child_end_event(JNIEnv *env, void *arg) {
120120
event = (*env)->NewObject(env,
121121
cache.csploit.events.child_end.class,
122122
cache.csploit.events.child_end.ctor,
123-
*((uint8_t *) arg));
123+
(jint) *((uint8_t *) arg));
124124

125125
if(event)
126126
return event;
@@ -203,7 +203,7 @@ jobject create_hop_event(JNIEnv *env, void *arg) {
203203
res = (*env)->NewObject(env,
204204
cache.csploit.events.hop.class,
205205
cache.csploit.events.hop.ctor,
206-
hop_info->hop, hop_info->usec, addr);
206+
hop_info->hop, (jlong)(hop_info->usec), addr);
207207

208208
(*env)->DeleteLocalRef(env, addr);
209209

@@ -272,7 +272,8 @@ jobject create_port_event(JNIEnv *env, void *arg) {
272272
res = (*env)->NewObject(env,
273273
cache.csploit.events.port.class,
274274
cache.csploit.events.port.ctor,
275-
jproto, service_info->port, jservice, jversion);
275+
jproto, (jint)(service_info->port),
276+
jservice, jversion);
276277

277278
cleanup:
278279

@@ -323,7 +324,7 @@ jobject create_os_event(JNIEnv *env, void *arg) {
323324
res = (*env)->NewObject(env,
324325
cache.csploit.events.os.class,
325326
cache.csploit.events.os.ctor,
326-
os_info->accuracy, jos, jtype);
327+
(jshort)(os_info->accuracy), jos, jtype);
327328

328329
cleanup:
329330

@@ -491,16 +492,28 @@ jobject create_message_event(JNIEnv *env, message *m) {
491492
*/
492493
jobject create_attempts_event(JNIEnv *env, message *m) {
493494
jobject res;
495+
jlong jsent, jleft, jelapsed, jeta;
494496
struct hydra_attempts_info *attempts_info;
495497

496498
attempts_info = (struct hydra_attempts_info *) m->data;
497499

500+
if(attempts_info->sent > INT64_MAX) {
501+
LOGW("%s: sent logins exceed maximum Java long value", __func__);
502+
}
503+
504+
if(attempts_info->left > INT64_MAX) {
505+
LOGW("%s: left logins exceed maximum Java long value", __func__);
506+
}
507+
508+
jsent = attempts_info->sent;
509+
jleft = attempts_info->left;
510+
jelapsed = attempts_info->elapsed;
511+
jeta = attempts_info->eta;
512+
498513
res = (*env)->NewObject(env,
499514
cache.csploit.events.attempts.class,
500515
cache.csploit.events.attempts.ctor,
501-
attempts_info->sent, attempts_info->left,
502-
attempts_info->rate, attempts_info->elapsed,
503-
attempts_info->eta);
516+
jsent, jleft, jelapsed, jeta);
504517

505518
if((*env)->ExceptionCheck(env)) {
506519
(*env)->ExceptionDescribe(env);
@@ -549,7 +562,8 @@ jobject create_login_event(JNIEnv *env, message *m) {
549562
res = (*env)->NewObject(env,
550563
cache.csploit.events.login.class,
551564
cache.csploit.events.login.ctor,
552-
login_info->port, addr, jlogin, jpswd);
565+
(jint)(login_info->port), addr,
566+
jlogin, jpswd);
553567

554568
cleanup:
555569

@@ -585,12 +599,15 @@ jobject create_packet_event(JNIEnv *env, message *m) {
585599
if(!src) return NULL;
586600

587601
dst = inaddr_to_inetaddress(env, packet_info->dst);
588-
if(!dst) return NULL;
602+
if(!dst) {
603+
(*env)->DeleteLocalRef(env, src);
604+
return NULL;
605+
}
589606

590607
res = (*env)->NewObject(env,
591608
cache.csploit.events.packet.class,
592609
cache.csploit.events.packet.ctor,
593-
src, dst, packet_info->len);
610+
src, dst, (jint)(packet_info->len));
594611

595612
(*env)->DeleteLocalRef(env, src);
596613
(*env)->DeleteLocalRef(env, dst);

cSploitHandlers/hydra.c

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ __attribute__((constructor))
5151
void hydra_init() {
5252
int ret;
5353

54-
if((ret = regcomp(&status_pattern, "^\\[STATUS\\] ([0-9,]+) tries/min, ([0-9]+) tries in ([0-9]{2}):([0-9]{2})h, ([0-9]+) todo in ([0-9]{2}):([0-9]{2})h", REG_EXTENDED))) {
54+
if((ret = regcomp(&status_pattern, "^\\[STATUS\\] [0-9,]+ tries/min, ([0-9]+) tries in ([0-9]{2}):([0-9]{2})h, ([0-9]+) todo in ([0-9]{2}):([0-9]{2})h", REG_EXTENDED))) {
5555
print( ERROR, "regcomp(status_pattern): %d", ret);
5656
}
5757
if((ret = regcomp(&alert_pattern, "^\\[(ERROR|WARNING)\\] ", REG_EXTENDED | REG_ICASE))) {
@@ -74,13 +74,11 @@ void hydra_fini() {
7474
* @returns a ::message on success, NULL on error.
7575
*/
7676
message *parse_hydra_status(char *line) {
77-
regmatch_t pmatch[8];
77+
regmatch_t pmatch[7];
7878
struct hydra_attempts_info *status_info;
7979
message *m;
80-
char *end;
81-
float f;
8280

83-
if(regexec(&status_pattern, line, 8, pmatch, 0))
81+
if(regexec(&status_pattern, line, 7, pmatch, 0))
8482
return NULL;
8583

8684
m = create_message(0, sizeof(struct hydra_attempts_info), 0);
@@ -96,27 +94,17 @@ message *parse_hydra_status(char *line) {
9694
*(line + pmatch[4].rm_eo) = '\0';
9795
*(line + pmatch[5].rm_eo) = '\0';
9896
*(line + pmatch[6].rm_eo) = '\0';
99-
*(line + pmatch[7].rm_eo) = '\0';
10097

10198

10299
status_info = (struct hydra_attempts_info *) m->data;
103100
status_info->hydra_action = HYDRA_ATTEMPTS;
104101

105-
f = strtof(line + pmatch[1].rm_so, &end);
106-
107-
if(end==(line + pmatch[1].rm_so) || *end != 0 || f == HUGE_VALF || !f) {
108-
print( WARNING, "cannot parse rate. input string='%s'. rate string='%s'",
109-
line, line + pmatch[1].rm_so);
110-
} else {
111-
status_info->rate = (unsigned int) (f * 60);
112-
}
113-
114-
status_info->sent = strtoul(line + pmatch[2].rm_so, NULL, 10);
115-
status_info->left = strtoul(line + pmatch[5].rm_so, NULL, 10);
116-
status_info->elapsed = (strtoul(line + pmatch[3].rm_so, NULL, 10) * 60) +
117-
strtoul(line + pmatch[4].rm_so, NULL, 10);
118-
status_info->eta = (strtoul(line + pmatch[6].rm_so, NULL, 10) * 60) +
119-
strtoul(line + pmatch[7].rm_so, NULL, 10);
102+
status_info->sent = strtoul(line + pmatch[1].rm_so, NULL, 10);
103+
status_info->left = strtoul(line + pmatch[4].rm_so, NULL, 10);
104+
status_info->elapsed = (strtoul(line + pmatch[2].rm_so, NULL, 10) * 60) +
105+
strtoul(line + pmatch[3].rm_so, NULL, 10);
106+
status_info->eta = (strtoul(line + pmatch[5].rm_so, NULL, 10) * 60) +
107+
strtoul(line + pmatch[6].rm_so, NULL, 10);
120108

121109
return m;
122110
}

cSploitHandlers/hydra.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ enum hydra_action {
3131
/// hydra attempts info
3232
struct hydra_attempts_info {
3333
char hydra_action; ///< must be set to ::HYDRA_ATTEMPTS
34-
unsigned int rate; ///< # of attempts per hour
3534
unsigned long int sent; ///< # of sent logins
3635
unsigned long int left; ///< # of logins left to try
3736
unsigned int elapsed; ///< elapsed time in minutes

0 commit comments

Comments
 (0)