~ubuntu-dev/sleuthkit/trunk

« back to all changes in this revision

Viewing changes to bindings/java/jni/dataModel_SleuthkitJNI.cpp

  • Committer: carriersvn
  • Date: 2011-10-05 02:47:12 UTC
  • Revision ID: svn-v4:1db85b72-fc57-0410-9196-8d408266ab40:trunk:399
udpated multi-image database code. Patch by Peter Martel

Show diffs side-by-side

added added

removed removed

Lines of Context:
152
152
 */
153
153
JNIEXPORT void JNICALL
154
154
    Java_org_sleuthkit_datamodel_SleuthkitJNI_closeCaseDbNat(JNIEnv * env,
155
 
    jclass obj, jstring caseHandle) {
 
155
    jclass obj, jlong caseHandle) {
156
156
 
157
157
    TskCaseDb *tskCase = ((TskCaseDb *) caseHandle);
158
158
    if (tskCase->m_tag != TSK_CASE_DB_TAG) {
159
159
        throwTskError(env,
160
 
            "closeCaseDbNate: Invalid TskCaseDb object passed in");
 
160
            "closeCaseDbNat: Invalid TskCaseDb object passed in");
161
161
        return;
162
162
    }
163
163
 
164
164
    delete tskCase;
 
165
    return;
165
166
}
166
167
 
167
168
 
202
203
 
203
204
 
204
205
/*
205
 
 * Create a database for the given image using a pre-created process which can be cancelled
 
206
 * Create a database for the given image using a pre-created process which can be cancelled.
 
207
 * MUST call commitAddImg or revertAddImg afterwards once runAddImg returns (unless there's an error).
206
208
 * @return the 0 for success 1 for failure
207
209
 * @param env pointer to java environment this was called from
208
210
 * @param obj the java object this was called from
226
228
    //change to true when autopsy needs the block table.
227
229
    tskAuto->createBlockMap(false);
228
230
 
 
231
    
 
232
 
229
233
    // move the strings into the C++ world
230
234
 
231
235
    // get pointers to each of the file names
239
243
            (char *) env->
240
244
            GetStringUTFChars((jstring) env->GetObjectArrayElement(paths,
241
245
                i), &isCopy);
 
246
        if (imagepaths8[i] == NULL) {
 
247
            throwTskError(env,
 
248
                "runAddImgNat: Can't convert path strings.");
 
249
            return;
 
250
        }
242
251
    }
243
252
 
244
253
    // flag to free tskAuto if the process is interuppted
260
269
    free(imagepaths8);
261
270
    tskAuto->closeImage();
262
271
 
263
 
    if (deleteProcess)
 
272
    if (deleteProcess) {
264
273
        delete tskAuto;
 
274
    }
265
275
    // if process completes successfully, must call revertAddImgNat or commitAddImgNat to free the TskAutoDb
266
276
}
267
277
 
318
328
    TskAutoDb *tskAuto = ((TskAutoDb *) process);
319
329
    if (tskAuto->m_tag != TSK_AUTO_TAG) {
320
330
        throwTskError(env,
321
 
            "commitAddImgNat: Invalid TskAutoDb object passed in");
 
331
             "commitAddImgNat: Invalid TskAutoDb object passed in");
322
332
        return -1;
323
333
    }
324
334
    int64_t imgId = tskAuto->commitProcess();
472
482
 * @param env JNI env
473
483
 * @param buf Buffer to copy from
474
484
 * @param len Length of bytes in buf
475
 
 * @returns Pointer to java byte array or exception if there is an error
 
485
 * @returns Pointer to java byte array or NULL if there is an error
476
486
 */
477
487
static jbyteArray
478
488
copyBufToByteArray(JNIEnv * env, const char *buf, ssize_t len)
479
489
{
480
490
    jbyteArray return_array = env->NewByteArray(len);
481
 
    // @@@ Error check
 
491
    if (return_array == NULL) {
 
492
        throwTskError(env, "NewByteArray returned error while getting an array to copy buffer into.");
 
493
        return NULL;
 
494
    }
482
495
 
483
 
    jbyte *jBytes = env->GetByteArrayElements(return_array, 0);
484
 
    // @@@ error check
 
496
    jbyte * jBytes= env->GetByteArrayElements(return_array, 0);
 
497
    if (jBytes == NULL) {
 
498
        throwTskError(env, "GetByteArrayElements returned error while getting elements to copy buffer into.");   
 
499
        return NULL;
 
500
    }
485
501
 
486
502
    for (int i = 0; i < len; i++) {
487
503
        jBytes[i] = buf[i];
561
577
 
562
578
/*
563
579
 * Read bytes from the given volume
564
 
 * @return array of bytes read from the volume
 
580
 * @return array of bytes read from the volume or NULL on error
565
581
 * @param env pointer to java environment this was called from
566
582
 * @param obj the java object this was called from
567
583
 * @param a_vol_info the pointer to the volume object
578
594
        throwTskError(env);
579
595
        return NULL;
580
596
    }
 
597
 
581
598
    TSK_VS_PART_INFO *vol_part_info = castVsPartInfo(env, a_vol_info);
582
599
 
583
600
    ssize_t retval =
585
602
        (size_t) len);
586
603
    if (retval == -1) {
587
604
        throwTskError(env, tsk_error_get());
 
605
        free(buf);
 
606
        return NULL;
588
607
    }
589
608
 
590
609
    // package it up for return
591
610
    jbyteArray return_array = copyBufToByteArray(env, buf, retval);
 
611
    // no point checking for error. copyBufToByteArray will call throwTskError and return NULL itself
 
612
 
592
613
    free(buf);
593
614
    return return_array;
594
615
}