JNIEXPORT jdouble JNICALL Java_AutoSteg_spotf5(JNIEnv *env, jclass clazz, jstring name){ char *filename = (*env)->GetStringUTFChars(env, name, NULL); double beta; if (jpg_open(filename) == -1) { printf("Couldn't open %s\n", filename); return beta == -1; } beta = detect_f5(filename); char tmp[80]; int stars; char outbuf[1024]; sprintf(outbuf, "%s :", filename); if (beta < 0.25) { //no f5 detected } else { //f5 detected stars = 1; if (beta > 0.25) stars++; if (beta > 0.4) stars++; snprintf(tmp, sizeof(tmp), "\n\tCODE RED CODE RED: f5[%f] DETECTED", beta); //strlcat(outbuf, quality(tmp, stars), sizeof(outbuf)); //printf("%s\n", outbuf); } return beta; }
int main(int argc, char *argv[]) { if( argc <= 1 ) { printf("usage: %s image.jpeg\n", argv[0]); exit(1); } argc--; while(argc > 0) { argc--; argv++; char *name = argv[0]; printf("looking for f5 in: %s\n", name); if (jpg_open(name) == -1) { printf("Couldn't open %s\n", name); continue; } double beta = detect_f5(name); char tmp[80]; int stars; char outbuf[1024]; sprintf(outbuf, "%s :", name); if (beta < 0.25) { // no f5 } else { //f5 detected stars = 1; if (beta > 0.25) stars++; if (beta > 0.4) stars++; snprintf(tmp, sizeof(tmp), "\n\tCODE RED CODE RED: f5[%f] DETECTED", beta); strlcat(outbuf, quality(tmp, stars), sizeof(outbuf)); printf("%s\n", outbuf); } } }
void docompare(char *file1, char *file2) { int i; int bits1, bits2, count, last, sumlast; int hist1[257], hist2[257]; int shist[257], shist1[257], shist2[257]; float ratio; int one; short *dcts1, *dcts2; dcts1 = dcts2 = NULL; /* Open first file */ if (jpg_open(file1) == -1) goto out; if (scans & FLAG_DOJPHIDE) prepare_jphide(&dcts1, &bits1); else prepare_all(&dcts1, &bits1); jpg_finish(); jpg_destroy(); /* Open second file */ if (jpg_open(file2) == -1) goto out; if (scans & FLAG_DOJPHIDE) prepare_jphide(&dcts2, &bits2); else prepare_all(&dcts2, &bits2); jpg_finish(); jpg_destroy(); if (bits1 != bits2) { warnx("Size of images differs: %d != %d", bits1, bits2); goto out; } fprintf(stdout, "Size: %d\n", bits1); memset(hist, 0, sizeof(hist)); memset(hist1, 0, sizeof(hist1)); memset(hist2, 0, sizeof(hist2)); last = -1; sumlast = 0; count = 0; one = 0; ratio = 0.5; for (i = 0; i < bits1; i++) { if (dcts1[i] >= -127 && dcts1[i] <= 127) hist1[dcts1[i] + 128]++; if (dcts2[i] >= -127 && dcts2[i] <= 127) hist2[dcts2[i] + 128]++; if (abs(dcts2[i]) & 1) one++; if ((i % 500) == 0 && i) { ratio = 0.7*ratio + 0.3*((float)one/500); one = 0; } if (dcts1[i] != dcts2[i]) { unsigned short first, second; count++; /* jphide */ if (scans & FLAG_DOJPHIDE) { first = dcts1[i] > 0 ? dcts1[i] : -dcts1[i]; second = dcts2[i] > 0 ? dcts2[i] : -dcts2[i]; } else { /* outguess */ first = dcts1[i]; second = dcts2[i]; } sumlast += last >= 0 ? i - last : 0; if ((scans & FLAG_HIST) == 0) { fprintf(stdout, "% 9d: % 5d != % 5d: %0x | % 5d : %7.2f| %4.2f\n", i, dcts1[i], dcts2[i], first ^ second, last >= 0 ? i - last : 0, (float)sumlast/count, ratio); } last = i; if (dcts1[i] >= -127 && dcts1[i] <= 127) hist[dcts1[i] + 128]++; if (scans & FLAG_DOJPHIDE) { memcpy(shist, hist, sizeof(shist)); memcpy(shist1, hist1, sizeof(shist1)); memcpy(shist2, hist2, sizeof(shist2)); } } } if (scans & FLAG_DOJPHIDE) { memcpy(hist, shist, sizeof(hist)); memcpy(hist1, shist1, sizeof(hist1)); memcpy(hist2, shist2, sizeof(hist2)); } if (scans & FLAG_HIST) { for (i = 0; i <= 256; i++) fprintf(stdout, "% 4d % 5d % 5d\n", i - 128, hist1[i], hist2[i]); goto out; } fprintf(stdout, "Total changes: %d bits, %d bytes\n", count, count/8); for (i = 0; i <= 256; i++) list[i] = i; qsort(list, sizeof(list)/sizeof(int), sizeof(int), compare); fprintf(stdout, "Histogram of changes to coefficients:\n"); for (i = 0; i <= 256; i++) if (hist[list[i]]) fprintf(stdout, "% 4d: % 5d(%.3f) | %6.3f%% || % 7d | % 7d : %7.3f%%\n", list[i] - 128, hist[list[i]], (float)hist[list[i]]/hist1[list[i]], (float)hist[list[i]]/count * 100, hist1[list[i]], hist2[list[i]], (float)(hist2[list[i]] - hist1[list[i]])/ hist1[list[i]] * 100); fprintf(stdout, "Histogram of changes to coefficients (in order):\n"); for (i = 0; i <= 256; i++) if (hist[i]) fprintf(stdout, "% 4d: % 5d(%.3f) | %6.3f%% || % 7d | % 7d : %7.3f%%\n", i - 128, hist[i], (float)hist[i]/hist1[i], (float)hist[i]/count * 100, hist1[i], hist2[i], (float)(hist2[i] - hist1[i])/ hist1[i] * 100); out: if (dcts1) free(dcts1); if (dcts2) free(dcts2); }