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!
Playstation 3 Impressions Gallery [16] (4)


My Biostar OC Contest Entry (0) by OneShotMemtok
Far Cry (PC) Review by exe3 (4) by exe3
Guitar Hero 3 - The thing that should not be (UPDATED) (5) by Beefysworld
World in Conflict (PC) Review (6) by Kessandra
C&C:Renegade Review, wrist-slittingly good! (8) by McStu
Beyond Good and Evil (prelim 2) (5) by exe3
Writing a Game Review (9) by Kessandra
The Bland Addiction: World of Warcraft (17) by Discobiscuits
Micutzu @ crazypc.ro benching for Biostar contest (0) by Micutzu
Guild Wars Gets a Bad Review (9) by Joluha

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
I am an AMD AgentRead this Media-Blog entry!» Finalists and Final Rules (6)
by FS-Lyle (167) Talk with this user on their Shout Box (My other blogs) Posted 10 months ago

Sponsored Links
:
[GO]


 Latest Headlines
Update - Biostar $2,500 Overclocking Contest (7)
Core i7 coming Nov 17th? (4)
Bungie: Halo 3 Recon is last Halo trilogy game (4)
Fallout 3 system reqs released; 360 already cracked (9)
Microsoft announces Xbox 360 holiday bundles (2)
Today's News >>
Today's Siteseeing >>


 Table of Contents


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


Loans  Personal Car Finance  Cheap Loans  Credit Card Consolidation  Credit Counseling
FiringSquad is powered by... Back to Top Site MapContact UsAdvertise With Us Privacy StatementAbout Us  
News RSSSiteseeing RSSArticle RSS   © 1998-2008 FS Media, Inc. All Rights Reserved