Access Private Members in C++

Just a proof-of-concept, not really much practical use. Also this tells us: if you REALLY want to access something, just get a pointer and start casting, lol.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
 * Output:
 * 
 * $ g++ -w -O0 AccessPrivateField.cc 
 * $ ./a.out
 * a: 0
 * a: 9999
 * A::secretFunc called (this depends on your platform and compiler, probably won't work)
 * $
 */ 
 
#include <iostream>
#include <cstdio>
 
class A {
private:
	int a;
 
public:
	A() : a(0) {};
 
	void print();
 
private:
	void secretFunc();
};
 
void A::print() {
	std::cout << "a: " << a << std::endl;
}
 
void A::secretFunc() {
	std::cout << "A::secretFunc called" << std::endl;
}
 
int main(int argc, char **agrv) {
	A *myA = new A();
 
	myA->print();
 
	// Compilation error: cannot access private member variable
	// myA->a = 9999;
 
	// This is how you do it
	*((int *) myA) = 9999;
 
	myA->print();
 
	// try access private member function
 
	// dirty trick to convert pointer-to-member to a local address
	char buf[100];
	std::sprintf(buf, "%p", &A::print);
	unsigned long ptrAddress;
	std::sscanf(buf, "%lx", &ptrAddress);
 
	// the -0x30 offset is retreived AFTER compilation,
	// and it depends on the length of generated code for A::print
	// which renders this technique useless in practice
	void (*secretFuncPtr)(A*) = (void (*)(A*)) (ptrAddress - 0x30);
	secretFuncPtr(myA);
 
	return 0;
}

“Unlocalizing” Your FireFox Search Engines

To better learn Japanese, I recently changed all my software packages, including FireFox, to Japanese ones. (It’s quite easy on Mac OS X thanks to the excellent international support)

One thing annoying me is that the bundled Google and Wikipedia search became Japanese versions. And FireFox won’t allow you to add english Google back via the Mozzilla add-on center as it is “built-in”.

ピクチャ 12.png

So here’s the fix

1. Download a English (US) version of FireFox, open the English FireFox.app package (Control-Click -> “Show Package Contents”), navigate to “Contents/MacOS/searchplugins“.

2. Open your localized version of FireFox.app, navigate to the same directory.

3. Copy any search engines you want from the English version to the localized version.

ピクチャ 13.png

4. Now because you have two search engines named “Google” now, open the localized version of your search engine file (google-jp.xml, for example), and rename it.

ピクチャ 14.png

5. Now for the final touch, change the location bar search back to Google.com. type “about:config” in the location bar, in the following screen change the value in “keyword.URL” from google.co.jp to google.com.

ピクチャ 15.png

Now everything’s back to normal, and as a bonus, you now have some local search engines you’ve never heard of before, lol.

ピクチャ 16.png

ピクチャ 17.png

Introuducing TouchRemote

TouchRemote lets you use your iPhone/iPod Touch as an Apple Remote.

TouchRemote is designed to be operated completely eye-free, with only touch and gesture.

TouchRemote works completely like the real Apple Remote, ensuring maximum compatibility with iTunes, Front Row, VLC or ANYTHING that works with Apple Remote.

TouchRemote is expected to be released in AppStore soon, stay tuned.

Project Page: http://playground.softboysxp.org/TouchRemote/

iPhone OS 3.0 Tethering with 3 (Hutchison) HK

Following the instructions in this fantastic tutorial, I successfully enabled Internet Tethering on my new iPhone 3G (OS 3.0 beta 2), with 3 (Hutchison) Hong Kong as my service provider.

img_0046 img_0047

You can download this file if you have access to the beta OS image and follow steps in the above tutorial to enable tethering for your 3 devices.

Also I found something interesting: not only you can tether your 3G connection, you can also tether the Wi-Fi connection with your computer, making your iPhone a handy wireless adapter (for older computers without one).

Note:
- I only tested this with my own iPhone and I am a 3 HK subscriber.
- The file provided is for testing and developing purpose ONLY.
- Enable tethering may or may not violate your contract with 3.
- The tethering feature may slow down your iPhone system and cause syncing problems.
- DO IT AT YOUR OWN RISK.

Red Alert 3 (Mac) Activation Failed Solution

I just got a digital copy from gametreeonline.com. Dragged the app to /Applications, updated to newest version and fired it up. And Boo ! “Activation Failed, check your internet connection” blah blah.

SecuROM Warning

After messing around for an hour, I found the solution. Not only you need “administrative privileges” as described in ReadMe, you have to actually be root to run this thing ! So that’s it, login as root, or open a terminal and run

sudo /Applications/Command\ and\ Conquer\ -\ Red\ Alert\ 3.app/Contents/MacOS/CNCRA3-launcher

. The problem was caused by SecuROM which needs to do its dirty stuff with root privilege.

Skype for iPhone

So the app is live now at Japan iTunes store, for free.

The sound quality is better than fring, and excellent for skype-to-skype calls.

Works great on iPod Touch too, with an iPhone headset connected.

Resident Evil 5 Review

More than three years has passed since the release of Resident Evil 4. Now here comes the latest installment of the series, first time on next-gen consoles, also first time on a non-Japanese console.

I just beat the game through. I cannot find a suitable word to describe it, awesome just isn’t enough for the game.

Graphics

It’s amazing how Japanese developers keeps pushing consoles to their limits. There was Dead or Alive 4, Ace Combat 6, Ninja Gaiden 2, and now there is Resident Evil 5. The great graphics makes the game looks just like a movie, and an HD one, XD. Lighting was great, with only minor bugs on enemy shadows.

Audio

Again it’s amazing how much attention Japanese pay to soundtracks in their games. Like every other RE game, RE5 has just the right soundtracks that blended into the gameplay naturally. Sound effects are borrowed from RE4 I think. Again it makes you feel natural, when you hear the menu selection sound, you just know it’s Resident Evil.

Storyline

I don’t wanna be a spoiler so I’ll just say the story’s quite good. Enough background information of new characters or untold past stories were provided in cut scenes. And comparing to RE4, huge amount of documents regarding Umbrella, Biohazard incidents and each characters were added in the new “Library” feature. The RE series has been like a puzzle, and now with RE5, many mysteries are solved.

Gameplay

The basic combat system remains the same as RE4. More weapons are available in this installment. The popular purchase and upgrade system is preserved. Also trivias like figure collecting, hidden costumes and weapons are still there.

In RE5 you play with your partner throughout the game. It’s important and fun to balancing weapons, items and ammos between Chris and Sheva. Also for the first time in history you can enjoy the horror of Resident Evil with your friends by cooping on Xbox Live or Playstation Network. The multiplayer feature already gained popularity with the Xbox Live demo. Now with the full game, there’s more chapters and more fun.

Trivia

The game was released on Mar 5 for Japan and Asia (Hong Kong), prior to North American. Currently there’re four versions in the HK market: Resident Evil 5 and its limited edition (with posters and a 2GB chainsaw flash drive), Biohazard 5 (yup, that’s the Japanese version) and its limited edition (also posters and flash drive, and a making-of DVD). The HK/Asia version is bilingual, based on the language preference of your console, the game automatically switches between English and Japanese. Also the asia version features two box arts, both Resident Evil 5 and Biohazard 5.

Kana Pad Ready for Sale

Kana Pad is a handy sketchpad for practicing and remembering Kana characters.

Kana Pad runs on iPhone and iPod with iPhoneOS 2.2 or above.

Click Here to download it FREE from the App Store

12CC646E-D64D-4A7C-878A-1DC410CDCEF9.jpg

Google Chrome Consumes More Memory ?

Just a simple test out of boredom.

All browsers were launched with a blank page and then navigated to Google home page. At this point, Chrome consumes the least memory of the three.

browser_memory

 

However, when opened up more tabs (Google, Yahoo and MSN), Chrome actually takes up more memory.

browser_memory_2

 

Google Chrome uses multi-processes instead of multi-threads for its tabs in order to prevent events such as a tab crashes whole browser (which is also the behavior of IE 8), which would be the most likely explanation for the test result.

Resident Evil: Degeneration

A full-length CG movie by Capcom and Sony. Storyline follows the raccoon city incident. Leon.S.Kennedy and Claire Redfield return to the public sight, both appearing, should I say, much hotter.

I got a 720p scene release. Will purchase the Blu-ray version for sure when coming back to HK (it’d be called Biohazard: Degeneration then).

Some screenshots

Claire Redfield. I wouldn’t have recongized her if it weren’t for the red dress and hair. btw, where’s her family jacket ?

Angela Miller, a new character introduced in the movie

Our beloved hero, (Secret Agent) Leon.S.Kennedy, appearing in his RE4 jacket

We call it “G1″, 1st form of the G-Virus infected creature

Another G1

“G2″, the 2nd form

Resident Evil rocks !