FiringSquad: Home of the Hardcore Gamer - Games, Hardware, Reviews and NewsSubmit your own or view users' CPU overclocking results!

  
 Home   News   THE MATRIX   Deals   Hardware   Games   Features   Media   Products   Forums   FS China 
AddThis Social Bookmark Button

Home : Hardware : Video Cards : Benchmarking Ethics and the ATI Radeon
» Join the Greatest Gaming Community NOW! (It's free)

Already a member? Login
 



Random Gallery >> 
Click to view high-res Image!
TERA February 2012 Screenshots [5] (0)

Crank that SH#!t Up Contest Entry (10) by Boltshot
[FX] 3-Screen Effect - Guide (part-1) (0) by nGAGE
CRANG That S#!T Up! (15) by ElwinRansom
HOW I CRANK THAT S#!T UP!! (4) by nvidia4life
2nd Entry for Crank That S#!t Up! (2) by CamoDaGreat
[Entry] Crank That S#!t Up Video Contest (5) by Animehero
My Crank That Sh#!t Up! entry :D (3) by chipmunk995
[FX] 3-Screen Effect - Guide (part-3) (0) by nGAGE
Superlative Computer (6) by arvernis
Crank That PhysX UP! (10) by mohawkade

More Blogs >>




Benchmarking Ethics and the ATI Radeon
October 24, 2001   Brandon Sandman Bell > [View My Other Articles]
Kenn Hwang > [View My Other Articles]
Product Info | User Reviews | Article Images(15) | Image Gallery | Comments | Forum Thread
Naming Code

Quack Verification

When we first heard about the "quackifier" program over a week ago, our first impression was one of skepticism. All we knew was that this was a program that purported to change string values in an executable file. When run, it did create a new "quack3.exe" file, but what else did it do? It could have made more changes to the file than its claimed purpose, or even modify existing OpenGL drivers.

While we inquired into the quackifier source, we asked Andrew, our ace Gamers.com developer to create an application from scratch that does the same thing; namely, to search a single file for any string values containing "quake" or "Quake" and rename those to "quack". Within 5 minutes, we had a fully working version, shown below:



import java.io.*;
import java.util.*;

public class Test {

public static void main(String[] args) {

try {
//test string
String str = args[0];
String rep = args[1];
String inFile = args[2];
String outFile = args[3];

System.out.println( "Test String: " + str );
byte[] pattern = str.getBytes();
System.out.println( "Replace with: " + rep );
byte[] replace = rep.getBytes();

//read file into array
BufferedInputStream input = new BufferedInputStream
	(new FileInputStream(inFile));
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int b = input.read();
while (b != -1) {
	buffer.write(b);
	b = input.read();
}
byte [] file = buffer.toByteArray();
buffer.reset();
System.out.println(inFile + " size: " + file.length + " bytes.");

// search thru file & replace
byte [] test = new byte[pattern.length];
for (int i=0; i < file.length; i++) {
	if (file[i] == pattern[0] && (i + pattern.length) <= file.length ) {
		System.arraycopy( file, i, test, 0, pattern.length);
		if (Arrays.equals( pattern, test )) {
			System.out.println("Match at: " + i);
			buffer.write(replace, 0, replace.length);
			i += (pattern.length - 1);
			continue;
		}
	}
	buffer.write(file[i]);
}

byte [] newFile = buffer.toByteArray();
buffer.close();
// write out new file if changed
if (! Arrays.equals(file, newFile) && ! outFile.equals("null")) {
	BufferedOutputStream output = new BufferedOutputStream
		(new FileOutputStream(outFile));
	output.write(newFile, 0, newFile.length);
	output.close();
	System.out.println("Wrote new file: " + outFile);
} else {
	System.out.println("File not written");
}

} catch (Exception e) {
	e.printStackTrace();
}
}

public static void print(byte [] pattern) {
	for (int i=0; i < pattern.length; i++) {
		System.out.print( pattern[i] + " ");
	}
	System.out.println();
	System.out.println();
}
}
The code above was spaced to fit in our page template, but you can download the source and compiled class files here to experiment at home: Now that we have our quack, let's see what it does.

Back! Page 1     Running Quack3 Next!
Blog + Share: Digg Del.icio.us Reddit SU furl • More: AddThis Social Bookmark Button
Send This Article to a Friend!  
Table of Contents
  Print Entire Article  

MATRIX CONTENT » RANDOM MEDIA BLOG More Blogs >>
No ratings yet
» Please rate this
Read this Media-Blog entry!» My First Video (3)
by Stryker (3) Talk with this user on their Shout Box (My other blogs) Posted 18 months ago


 Hottest Topics
Blizzard appealing to block Valve trademarking DOTA (10)
Skyrim mod toolkit and Steam Workshop integration arrive with free official high-resolution texture pack (6)
Obsidian has 'Kickstarter fever', asks for suggestions (6)
Bethesda shows modders how it's done: see what Skyrim developers added during free-form 'Game Jam' week (5)
Diablo 3 dev diary explains nightmare mode difficulty (5)
Today's News >>
Today's Siteseeing >>


 Table of Contents


 Quick Fact
Download Java from http://java.sun.com


FiringSquad is powered by... Back to Top Site MapContact UsAdvertise With Us Privacy StatementAbout Us  
News RSSSiteseeing RSSArticle RSS   © 1998-2012 FS Media, Inc. All Rights Reserved