Jumat, 03 April 2009

Anti-Piracy Snippet

Don't know who to credit for this, although it uses techniques discussed here, here is a snippet of code that shows one way to detect pirated copies of your application.

The problem with this snippet, though, is that by putting this logic in an Objective-C method with an obvious name, you actually make it pretty easy for hackers to bypass or change this check. Instead, take the same basic logic and make it a C function and make sure you compile with debug symbols off. Better yet, make it a static inline function and call it from several places. This will scatter the same exact logic several places throughout your code, making cracking your program much more of a hassle.

You can never make any program that's completely unhackable, but you can make it a bit of a pain for the hackers and perhaps delay it from getting out on to the hacker sites for a little while.

Adding CLANG to Your Build Process

Frasier Spiers has a nifty piece this morning on using Git pre-commit hooks to automatically run the CLANG Static Analyzer. I'm not a Git user myself, but I know a lot of people are, so this looks like good info for those of you who are

Kamis, 02 April 2009

Zip & Unzip Objective-C Code

A new Google Code Project gives you the ability to zip and unzip data from Objective-C. I haven't used this yet, but definitely plan to check it out.

Rabu, 01 April 2009

Apple's Xcode Team is Hiring

Via Michael Jurewitz, the Xcode team at Apple is hiring.
Join Apple and help lead the development for the next generation of iPhone OS development tools!

Here's the job posting at Apple Jobs.

Automated Commit and Build Number Incrementing

For some projects, I like to commit and increment my build number every time I compile. Not every project, but on some. In other cases, I only want to automatically commit and increment the build number when I do a Release configuration build.

Apple provides a tool called agvtool which stands for Apple Generic Versioning Tool. But, you generally don't want to use it while you have an Xcode project open, so incorporating it into a run script build phase is not advised.

I've found a few examples on the internet of scripts that incorporate the Subversion build number, but they didn't quite fit my needs. The ones I found were written in Perl and Python, and I'm not particularly comfortable in either of those languages, so I decided to write my own in Ruby, with which I have a much higher comfort level, rather than tweak those existing ones to meet my needs.

This script does not utilize the versioning system built-into Xcode, but rather directly sets the Bundle Version based on the Subversion version number. It also does a commit if there have been any changes since the last build before grabbing the version number from Subversion.

To use this script, right-click on your Target where you want to use this and select Add->New Build Phase->New Run Script Build Phase.

When the window opens up, set the Shell to
/usr/bin/ruby
and then paste the following script into the window if you want to commit and increment on every build:

def get_file_as_string(filename)
data = ''
f = File.open(filename, "r")
f.each_line do |line|
data += line
end
return data
end

# commit if any changes
%x[svn -m 'automated build commit' commit]

svn_version = %x[svnversion -n]
parts = svn_version.split(":")
new_version = parts[1]

# Figure out where the Info.plist file is
project_dir = ENV['PROJECT_DIR']
infoplist_file = ENV['INFOPLIST_FILE']
plist_filename = "#{project_dir}/#{infoplist_file}"
infoplist = get_file_as_string("/Users/jeff/dev/FlyPaper/Resources/Info.plist")
start_of_key = infoplist.index("CFBundleVersion")
start_of_value = infoplist.index("<string>", start_of_key)
end_of_value = infoplist.index("</string>", start_of_value) + "</string>".length
old_value = infoplist[start_of_value, end_of_value - start_of_value]

new_key = "<string>#{new_version}</string>"
new_info_plist = "#{infoplist[0, start_of_value]}#{new_key}\n#{infoplist[end_of_value+1, infoplist.length - (end_of_value+1)]}"

File.open(plist_filename, 'w') {|f| f.write(new_info_plist) }


or use this script if you only want to commit and increment the build number on builds using the Release configuration:

def get_file_as_string(filename)
data = ''
f = File.open(filename, "r")
f.each_line do |line|
data += line
end
return data
end

if ENV['BUILD_STYLE'] == "Release"
# commit if any changes
%x[svn -m 'automated build commit' commit]
end

svn_version = %x[svnversion -n]
parts = svn_version.split(":")
new_version = parts[1]

# Figure out where the Info.plist file is
project_dir = ENV['PROJECT_DIR']
infoplist_file = ENV['INFOPLIST_FILE']
plist_filename = "#{project_dir}/#{infoplist_file}"
infoplist = get_file_as_string("/Users/jeff/dev/FlyPaper/Resources/Info.plist")
start_of_key = infoplist.index("CFBundleVersion")
start_of_value = infoplist.index("<string>", start_of_key)
end_of_value = infoplist.index("</string>", start_of_value) + "</string>".length
old_value = infoplist[start_of_value, end_of_value - start_of_value]

new_key = "<string>#{new_version}</string>"
new_info_plist = "#{infoplist[0, start_of_value]}#{new_key}\n#{infoplist[end_of_value+1, infoplist.length - (end_of_value+1)]}"

File.open(plist_filename, 'w') {|f| f.write(new_info_plist) }


After you paste it in, close the window. You might want to rename the run script build phase to something more meaningful. You can do that by right-clicking on it and selecting Rename from the menu that pops up. Also, you need to drag the new build phase up so that it fires before the Copy Bundle Resources phase so that the commit happens before it builds the application. Otherwise, the application will always reflect the previous version number in the Get Info window.

That's all you have to do. Now, whenever you build or do a Release build, Xcode will commit your files to the Subversion repository if there have been changes, then set the bundle version to the value currently in Subversion. Now, this script has not been extensively tested. If you have problems, let me know about them, and I will try to fix any issues that arise.

Fundamental Misunderstandings

I really hate bad journalism. Unfortunately, that seems to be the norm these days. Today, Fortune ran an article with the headline How Microsoft Put Apple on the Defensive on its Apple 2.0 blog.

The point of this article is that the Apple faithful are "on the defensive" because of the Lauren commercial. Now, I think it's fair to say I'm one of the "Apple faithful", as are most of my professional and many of my personal acquaintances. I, personally, haven't seen a shred of defensiveness. Moderate amusement and head-shaking? Yeah. More laughs at Microsoft's expense? Sure. A reinforced opinion that Microsoft's marketing team just doesn't "get it"? Well, of couse.

But defensive? Nope. Nobody feels threatened by this at all. It's a silly ad. If you were to do this with any other product, the inherent silliness would be blatantly obvious. Heck, to me, it's blatantly obvious here, but apparently Microsoft and Fortune don't see it.

If you were to, say, offer to buy somebody a free car as long as they could find one under $10,000, and then sent them off to the Lexus dealer, people would laugh in your face. Lexus doesn't try to compete in the sub-$10,000 market, so sending somebody there to look for a sub-$10,000 car is just assinine, and actually going there to test drive a car with a budget of $10,000 is flat-out idiotic.

The first words that jump to my mind when I saw this commercial were "horribly contrived", followed by "passive aggressive" ("annoying redhead" entered my head also, I must admit). If you want to accuse Mac users of being elitists, at least have the balls to come out and say it outright. This pejorative "I'm not cool enough" crap is the kind of thing you'd expect to see out of an unpopular third-grader who didn't get picked first for dodgeball.

Let's be frank: in an economy like this, there is a strong idea at the heart of this ad: if you have a small budget, you can get a decent computer for fairly little money if you don't mind buying technology that is already obsolete and don't mind putting up with Windows and the various,spyware, crapware adware, and other baggage that comes pre-installed on these machines. Acting like a pouty adolescent is hardly the best way to capitalize on that message, however. There are people with whom the underlying message would resonate, but (call me crazy) I really doubt you're going to entice those people by telling them they're not cool and can't afford the stuff that is cool. I know that was meant as a backhanded swipe at Apple, but it's not going to read that way to the iPod generation, many of whom actually do think Apple's products are pretty cool. I mean, other than Steve Balmer's kids, do you know many young people who don't either have or want an iPod?

So, if anyone's being defensive here, it's Microsoft. If you can't focus on what makes your product better and need to resort to childish name-calling of your opponent, then you don't have much confidence that your product is any good. Understandable when your product is Vista, but still, let's be honest about who's on the defensive.

Happy Birthday, Apple, Inc.

As most of you probably know, today is the 33rd anniversary of the founding of Apple Computer, Inc., which later became Apple, Inc.

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Lady Gaga, Salman Khan