Personally I’ve always appreciated the emphasis on Populi versus Dei especially considering tumultuous, fractious and socialist history of Europe. But what it expresses best is the materialistic notion that perfection, i.e. God, is possible from the voice of the people and that truth resides in each and everyone of us. So this is my food for thoughts blog article about software technology. If you found article on this blog useful, click on any ad so that I can have a drink on you.
Monkey: The Monkey is a program that runs on your emulator or device and generates pseudo-random streams of user events such as clicks, touches, or gestures, as well as a number of system-level events. You can use the Monkey to stress-test applications that you are developing, in a random yet repeatable manner.
Monkey script is unfortunately poorly documented but it is pretty easy to write monkey script after looking at the Monkey Script Java source code itself. The Java Source code is the code in charge of parsing the monkey script and dispatching all monkey script event in a timely manner.
/* * Copyright (C) 2008 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */
/** * monkey event queue. It takes a script to produce events * * sample script format: * type= raw events * count= 10 * speed= 1.0 * start data >> * captureDispatchPointer(5109520,5109520,0,230.75429,458.1814,0.20784314, * 0.06666667,0,0.0,0.0,65539,0) * captureDispatchKey(5113146,5113146,0,20,0,0,0,0) * captureDispatchFlip(true) * ... */ public class MonkeySourceScript implements MonkeyEventSource { private int mEventCountInScript = 0; //total number of events in the file private int mVerbose = 0; private double mSpeed = 1.0; private String mScriptFileName; private MonkeyEventQueue mQ;
private static final String HEADER_TYPE = "type="; private static final String HEADER_COUNT = "count="; private static final String HEADER_SPEED = "speed=";
private long mLastRecordedDownTimeKey = 0; private long mLastRecordedDownTimeMotion = 0; private long mLastExportDownTimeKey = 0; private long mLastExportDownTimeMotion = 0; private long mLastExportEventTime = -1; private long mLastRecordedEventTime = -1;
private static final boolean THIS_DEBUG = false; // a parameter that compensates the difference of real elapsed time and // time in theory private static final long SLEEP_COMPENSATE_DIFF = 16;
// maximum number of events that we read at one time private static final int MAX_ONE_TIME_READS = 100;
// number of additional events added to the script // add HOME_KEY down and up events to make start UI consistent in each round private static final int POLICY_ADDITIONAL_EVENT_COUNT = 2;
// event key word in the capture log private static final String EVENT_KEYWORD_POINTER = "DispatchPointer"; private static final String EVENT_KEYWORD_TRACKBALL = "DispatchTrackball"; private static final String EVENT_KEYWORD_KEY = "DispatchKey"; private static final String EVENT_KEYWORD_FLIP = "DispatchFlip";
// a line at the end of the header private static final String STARTING_DATA_LINE = "start data >>"; private boolean mFileOpened = false;
public MonkeySourceScript(String filename, long throttle) { mScriptFileName = filename; mQ = new MonkeyEventQueue(throttle); }
/** * * @return the number of total events that will be generated in a round */ public int getOneRoundEventCount() { //plus one home key down and up event return mEventCountInScript + POLICY_ADDITIONAL_EVENT_COUNT; }
mFStream = new FileInputStream(mScriptFileName); mInputStream = new DataInputStream(mFStream); mBufferReader = new BufferedReader( new InputStreamReader(mInputStream)); String sLine; while ((sLine = mBufferReader.readLine()) != null) { sLine = sLine.trim(); if (sLine.indexOf(HEADER_TYPE) >= 0) { // at this point, we only have one type of script } else if (sLine.indexOf(HEADER_COUNT) >= 0) { try { mEventCountInScript = Integer.parseInt(sLine.substring( HEADER_COUNT.length() + 1).trim()); } catch (NumberFormatException e) { System.err.println(e); } } else if (sLine.indexOf(HEADER_SPEED) >= 0) { try { mSpeed = Double.parseDouble(sLine.substring( HEADER_SPEED.length() + 1).trim());
} catch (NumberFormatException e) { System.err.println(e); } } else if (sLine.indexOf(STARTING_DATA_LINE) >= 0) { // header ends until we read the start data mark mFileOpened = true; if (THIS_DEBUG) { System.out.println("read script header success"); } return true; } } } catch (FileNotFoundException e) { System.err.println(e); } catch (IOException e) { System.err.println(e); }
if (THIS_DEBUG) { System.out.println("Error in reading script header"); } return false; }
private void processLine(String s) { int index1 = s.indexOf('('); int index2 = s.indexOf(')');
if (index1 < 0 || index2 < 0) { return; }
StringTokenizer st = new StringTokenizer( s.substring(index1 + 1, index2), ",");
if (s.indexOf(EVENT_KEYWORD_KEY) >= 0) { // key events try { long downTime = Long.parseLong(st.nextToken()); long eventTime = Long.parseLong(st.nextToken()); int action = Integer.parseInt(st.nextToken()); int code = Integer.parseInt(st.nextToken()); int repeat = Integer.parseInt(st.nextToken()); int metaState = Integer.parseInt(st.nextToken()); int device = Integer.parseInt(st.nextToken()); int scancode = Integer.parseInt(st.nextToken());
MonkeyKeyEvent e = new MonkeyKeyEvent(downTime, eventTime, action, code, repeat, metaState, device, scancode); mQ.addLast(e);
} catch (NumberFormatException e) { // something wrong with this line in the script } } else if (s.indexOf(EVENT_KEYWORD_POINTER) >= 0 || s.indexOf(EVENT_KEYWORD_TRACKBALL) >= 0) { // trackball/pointer event try { long downTime = Long.parseLong(st.nextToken()); long eventTime = Long.parseLong(st.nextToken()); int action = Integer.parseInt(st.nextToken()); float x = Float.parseFloat(st.nextToken()); float y = Float.parseFloat(st.nextToken()); float pressure = Float.parseFloat(st.nextToken()); float size = Float.parseFloat(st.nextToken()); int metaState = Integer.parseInt(st.nextToken()); float xPrecision = Float.parseFloat(st.nextToken()); float yPrecision = Float.parseFloat(st.nextToken()); int device = Integer.parseInt(st.nextToken()); int edgeFlags = Integer.parseInt(st.nextToken());
int type = MonkeyEvent.EVENT_TYPE_TRACKBALL; if (s.indexOf("Pointer") > 0) { type = MonkeyEvent.EVENT_TYPE_POINTER; } MonkeyMotionEvent e = new MonkeyMotionEvent(type, downTime, eventTime, action, x, y, pressure, size, metaState, xPrecision, yPrecision, device, edgeFlags); mQ.addLast(e); } catch (NumberFormatException e) { // we ignore this event } } else if (s.indexOf(EVENT_KEYWORD_FLIP) >= 0) { boolean keyboardOpen = Boolean.parseBoolean(st.nextToken()); MonkeyFlipEvent e = new MonkeyFlipEvent(keyboardOpen); mQ.addLast(e); } }
/** * add home key press/release event to the queue */ private void addHomeKeyEvent() { MonkeyKeyEvent e = new MonkeyKeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HOME); mQ.addLast(e); e = new MonkeyKeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HOME); mQ.addLast(e); }
/** * read next batch of events from the provided script file * @return true if success */ private boolean readNextBatch() { String sLine = null; int readCount = 0;
if (THIS_DEBUG) { System.out.println("readNextBatch(): reading next batch of events"); }
if (!mFileOpened) { if (!readScriptHeader()) { closeFile(); return false; } resetValue();
/* * In order to allow the Monkey to replay captured events multiple times * we need to define a default start UI, which is the home screen * Otherwise, it won't be accurate since the captured events * could end anywhere */ addHomeKeyEvent(); }
if (sLine == null) { // to the end of the file if (THIS_DEBUG) { System.out.println("readNextBatch(): to the end of file"); } closeFile(); } return true; }
/** * sleep for a period of given time, introducing latency among events * @param time to sleep in millisecond */ private void needSleep(long time) { if (time < 1) { return; } try { Thread.sleep(time); } catch (InterruptedException e) { } }
/** * check whether we can successfully read the header of the script file */ public boolean validate() { boolean b = readNextBatch(); if (mVerbose > 0) { System.out.println("Replaying " + mEventCountInScript + " events with speed " + mSpeed); } return b; }
public void setVerbose(int verbose) { mVerbose = verbose; }
/** * adjust key downtime and eventtime according to both * recorded values and current system time * @param e KeyEvent */ private void adjustKeyEventTime(MonkeyKeyEvent e) { if (e.getEventTime() < 0) { return; } long thisDownTime = 0; long thisEventTime = 0; long expectedDelay = 0;
/** * adjust motion downtime and eventtime according to both * recorded values and current system time * @param e KeyEvent */ private void adjustMotionEventTime(MonkeyMotionEvent e) { if (e.getEventTime() < 0) { return; } long thisDownTime = 0; long thisEventTime = 0; long expectedDelay = 0;
if (mLastRecordedEventTime <= 0) { // first time event thisDownTime = SystemClock.uptimeMillis(); thisEventTime = thisDownTime; } else { if (e.getDownTime() != mLastRecordedDownTimeMotion) { thisDownTime = e.getDownTime(); } else { thisDownTime = mLastExportDownTimeMotion; } expectedDelay = (long) ((e.getEventTime() - mLastRecordedEventTime) * mSpeed); thisEventTime = mLastExportEventTime + expectedDelay; // add sleep to simulate everything in recording needSleep(expectedDelay - SLEEP_COMPENSATE_DIFF); }
/** * if the queue is empty, we generate events first * @return the first event in the queue, if null, indicating the system crashes */ public MonkeyEvent getNextEvent() { long recordedEventTime = -1;
if (mQ.isEmpty()) { readNextBatch(); } MonkeyEvent e = mQ.getFirst(); mQ.removeFirst();
To write monkey script the first thing you have to do is write a small JAVA application. You can use hello world sample application. You can build it using Eclipse Java IDE and Android Windows SDK. Inside your sample application open the main activity JAVA file and add some code to enumerate the activity of an APK of your choice assuming this application is not presently running. If the application you'd like to automate is running, then use getPackageInfo(), instead of getPackageArchiveInfo().
See code bellow. Run the "rever engineering" application in the debugger with the device attached to your PC/Laptop with USB cable so that you can step into the code.
public class ReverseEngineering extends Activity { static final String TAG = "ReverseEngineering:Log";
/** onStart() is called when the application is on the foreground. * We shouldn't use onCreate() which is called only once in the phone's process life cycle. * This function will override what is available in the parent Activity class. */ @Override public void onStart() { // Keep on starting. super.onStart(); setContentView(R.layout.main);
Once you know the name of the activity you can invoke, write a small script. The following script named monkey_script.txt will execute a package and its activity.
captureDispatchPointer is a tap down action followed by a tap up action at the coordinate x and y EG X 146 and Y 165 as if you were using the touch screen with your finger. To find out the coordinate for a particular screen on the device you need to capture the screen using ddms (android tool) and open the screen with your favorites image editor. Mine is PhotoShop CS5 or Gimp if you don't have that much $ to spend. Development on Android is free after all.
# KEYEVENT http://developer.android.com/reference/android/view/KeyEvent.html# Start of Script type= user count= 49 speed= 1.0 start data >> LaunchActivity(com.company.application.Activity, com.company.application.Activity) UserWait(2000) # first screen captureDispatchPointer(5109520,5109520,0,146,165,0,0,0,0,0,0,0); captureDispatchPointer(5109521,5109521,1,146,165,0,0,0,0,0,0,0); UserWait(5000) # second screen captureDispatchPointer(5109520,5109520,0,117,268,0,0,0,0,0,0,0); captureDispatchPointer(5109521,5109521,1,117,268,0,0,0,0,0,0,0); # second screen selection dialog autoclose on selection UserWait(2000) # now access an other screen captureDispatchPointer(5109520,5109520,0,117,358,0,0,0,0,0,0,0); captureDispatchPointer(5109521,5109521,1,117,358,0,0,0,0,0,0,0); UserWait(2000) # access a selection dialog with only a cancel button. Dialog will autoclose on tap down captureDispatchPointer(5109520,5109520,0,117,177,0,0,0,0,0,0,0); captureDispatchPointer(5109521,5109521,1,117,177,0,0,0,0,0,0,0); UserWait(2000)
This document describes the syntax of Android.mk build file written to describe your C and C++ source files to the Android NDK. To understand what follows, it is assumed that you have read the docs/OVERVIEW.TXT file that explains their role and usage.
Overview: ---------
An Android.mk file is written to describe your sources to the build system. More specifically:
- The file is really a tiny GNU Makefile fragment that will be parsed one or more times by the build system. As such, you should try to minimize the variables you declare there and do not assume that anything is not defined during parsing.
- The file syntax is designed to allow you to group your sources into 'modules'. A module is one of the following:
- a static library - a shared library
Only shared libraries will be installed/copied to your application package. Static libraries can be used to generate shared libraries though.
You can define one or more modules in each Android.mk file, and you can use the same source file in several modules.
- The build system handles many details for you. For example, you don't need to list header files or explicit dependencies between generated files in your Android.mk. The NDK build system will compute these automatically for you.
This also means that, when updating to newer releases of the NDK, you should be able to benefit from new toolchain/platform support without having to touch your Android.mk files.
Note that the syntax is *very* close to the one used in Android.mk files distributed with the full open-source Android platform sources. While the build system implementation that uses them is different, this is an intentional design decision made to allow reuse of 'external' libraries' source code easier for application developers.
Simple example: ---------------
Before describing the syntax in details, let's consider the simple "hello JNI" example, i.e. the files under:
apps/hello-jni/project
Here, we can see:
- The 'src' directory containing the Java sources for the sample Android project.
- The 'jni' directory containing the native source for the sample, i.e. 'jni/hello-jni.c'
This source file implements a simple shared library that implements a native method that returns a string to the VM application.
- The 'jni/Android.mk' file that describes the shared library to the NDK build system. Its content is:
---------- cut here ------------------ LOCAL_PATH := $(call my-dir)
include $(BUILD_SHARED_LIBRARY) ---------- cut here ------------------
Now, let's explain these lines:
LOCAL_PATH := $(call my-dir)
An Android.mk file must begin with the definition of the LOCAL_PATH variable. It is used to locate source files in the development tree. In this example, the macro function 'my-dir', provided by the build system, is used to return the path of the current directory (i.e. the directory containing the Android.mk file itself).
include $(CLEAR_VARS)
The CLEAR_VARS variable is provided by the build system and points to a special GNU Makefile that will clear many LOCAL_XXX variables for you (e.g. LOCAL_MODULE, LOCAL_SRC_FILES, LOCAL_STATIC_LIBRARIES, etc...), with the exception of LOCAL_PATH. This is needed because all build control files are parsed in a single GNU Make execution context where all variables are global.
LOCAL_MODULE := hello-jni
The LOCAL_MODULE variable must be defined to identify each module you describe in your Android.mk. The name must be *unique* and not contain any spaces. Note that the build system will automatically add proper prefix and suffix to the corresponding generated file. In other words, a shared library module named 'foo' will generate 'libfoo.so'.
IMPORTANT NOTE: If you name your module 'libfoo', the build system will not add another 'lib' prefix and will generate libfoo.so as well. This is to support Android.mk files that originate from the Android platform sources, would you need to use these.
LOCAL_SRC_FILES := hello-jni.c
The LOCAL_SRC_FILES variables must contain a list of C and/or C++ source files that will be built and assembled into a module. Note that you should not list header and included files here, because the build system will compute dependencies automatically for you; just list the source files that will be passed directly to a compiler, and you should be good.
Note that the default extension for C++ source files is '.cpp'. It is however possible to specify a different one by defining the variable LOCAL_DEFAULT_CPP_EXTENSION. Don't forget the initial dot (i.e. '.cxx' will work, but not 'cxx').
include $(BUILD_SHARED_LIBRARY)
The BUILD_SHARED_LIBRARY is a variable provided by the build system that points to a GNU Makefile script that is in charge of collecting all the information you defined in LOCAL_XXX variables since the latest 'include $(CLEAR_VARS)' and determine what to build, and how to do it exactly. There is also BUILD_STATIC_LIBRARY to generate a static library.
There are more complex examples under apps/, with commented Android.mk files that you can look at.
Reference: ----------
This is the list of variables you should either rely on or define in an Android.mk. You can define other variables for your own usage, but the NDK build system reserves the following variable names:
- names that begin with LOCAL_ (e.g. LOCAL_MODULE) - names that begin with PRIVATE_, NDK_ or APP_ (used internally) - lower-case names (used internally, e.g. 'my-dir')
If you need to define your own convenience variables in an Android.mk file, we recommend using the MY_ prefix, for a trivial example:
LOCAL_SRC_FILES += $(MY_SOURCES) ---------- cut here ------------------
So, here we go:
NDK-provided variables: - - - - - - - - - - - -
These GNU Make variables are defined by the build system before your Android.mk file is parsed. Note that under certain circumstances the NDK might parse your Android.mk several times, each with different definition for some of these variables.
CLEAR_VARS Points to a build script that undefines nearly all LOCAL_XXX variables listed in the "Module-description" section below. You must include the script before starting a new module, e.g.:
include $(CLEAR_VARS)
BUILD_SHARED_LIBRARY Points to a build script that collects all the information about the module you provided in LOCAL_XXX variables and determines how to build a target shared library from the sources you listed. Note that you must have LOCAL_MODULE and LOCAL_SRC_FILES defined, at a minimum before including this file. Example usage:
include $(BUILD_SHARED_LIBRARY)
note that this will generate a file named lib$(LOCAL_MODULE).so
BUILD_STATIC_LIBRARY A variant of BUILD_SHARED_LIBRARY that is used to build a target static library instead. Static libraries are not copied into your project/packages but can be used to build shared libraries (see LOCAL_STATIC_LIBRARIES and LOCAL_STATIC_WHOLE_LIBRARIES described below). Example usage:
include $(BUILD_STATIC_LIBRARY)
Note that this will generate a file named lib$(LOCAL_MODULE).a
TARGET_ARCH Name of the target CPU architecture as it is specified by the full Android open-source build. This is 'arm' for any ARM-compatible build, independent of the CPU architecture revision.
TARGET_PLATFORM Name of the target Android platform when this Android.mk is parsed. For now, only 'android-3' is supported, which corresponds to the Android 1.5 platform.
TARGET_ARCH_ABI Name of the target CPU+ABI when this Android.mk is parsed. For now, only 'arm' is supported, which really means the following:
ARMv5TE or higher CPU, with 'softfloat' floating point support
Other target ABIs will be introduced in future releases of the NDK and will have a different name. Note that all ARM-based ABIs will have 'TARGET_ARCH' defined to 'arm', but may have different 'TARGET_ARCH_ABI'
TARGET_ABI The concatenation of target platform and abi, it really is defined as $(TARGET_PLATFORM)-$(TARGET_ARCH_ABI) and is useful when you want to test against a specific target system image for a real device.
The following are GNU Make 'function' macros, and must be evaluated by using '$(call )'. They return textual information.
my-dir Returns the path of the current Android.mk's directory, relative to the top of the NDK build system. This is useful to define LOCAL_PATH at the start of your Android.mk as with:
LOCAL_PATH := $(call my-dir)
all-subdir-makefiles Returns a list of Android.mk located in all sub-directories of the current 'my-dir' path. For example, consider the following hierarchy:
If sources/foo/Android.mk contains the single line:
include $(call all-subdir-makefiles)
Then it will include automatically sources/foo/lib1/Android.mk and sources/foo/lib2/Android.mk
This function can be used to provide deep-nested source directory hierarchies to the build system. Note that by default, the NDK will only look for files in sources/*/Android.mk
this-makefile Returns the path of the current Makefile (i.e. where the function is called).
parent-makefile Returns the path of the parent Makefile in the inclusion tree, i.e. the path of the Makefile that included the current one.
The following variables are used to describe your module to the build system. You should define some of them between an 'include $(CLEAR_VARS)' and an 'include $(BUILD_XXXXX)'. As written previously, $(CLEAR_VARS) is a script that will undefine/clear all of these variables, unless explicitely noted in their description.
LOCAL_PATH This variable is used to give the path of the current file. You MUST define it at the start of your Android.mk, which can be done with:
LOCAL_PATH := $(call my-dir)
This variable is *not* cleared by $(CLEAR_VARS) so only one definition per Android.mk is needed (in case you define several modules in a single file).
LOCAL_MODULE This is the name of your module. It must be unique among all module names, and shall not contain any space. You MUST define it before including any $(BUILD_XXXX) script.
The module name determines the name of generated files, e.g. lib.so for a shared library module named . However you should only refer to other modules with their 'normal' name (e.g. ) in your NDK build files (either Android.mk or Application.mk)
LOCAL_SRC_FILES This is a list of source files that will be built for your module. Only list the files that will be passed to a compiler, since the build system automatically computes dependencies for you.
Note that source files names are all relative to LOCAL_PATH and you can use path components, e.g.:
LOCAL_SRC_FILES := foo.c \ toto/bar.c
NOTE: Always use Unix-style forward slashes (/) in build files. Windows-style back-slashes will not be handled properly.
LOCAL_CPP_EXTENSION This is an optional variable that can be defined to indicate the file extension of C++ source files. The default is '.cpp' but you can change it. For example:
LOCAL_CPP_EXTENSION := .cxx
LOCAL_C_INCLUDES An optional list of paths, relative to the NDK *root* directory, which will be appended to the include search path when compiling all sources (C, C++ and Assembly). For example:
LOCAL_C_INCLUDES := sources/foo
Or even:
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../foo
These are placed before any corresponding inclusion flag in LOCAL_CFLAGS / LOCAL_CPPFLAGS
LOCAL_CFLAGS An optional set of compiler flags that will be passed when building C *and* C++ source files.
This can be useful to specify additionnal macro definitions or compile options.
IMPORTANT: Try not to change the optimization/debugging level in your Android.mk, this can be handled automatically for you by specifying the appropriate information in your Application.mk, and will let the NDK generate useful data files used during debugging.
NOTE: In android-ndk-1.5_r1, the corresponding flags only applied to C source files, not C++ ones. This has been corrected to match the full Android build system behaviour. (You can use LOCAL_CPPFLAGS to specify flags for C++ sources only now).
LOCAL_CXXFLAGS An alias for LOCAL_CPPFLAGS. Note that use of this flag is obsolete as it may disappear in future releases of the NDK.
LOCAL_CPPFLAGS An optional set of compiler flags that will be passed when building C++ source files *only*. They will appear after the LOCAL_CFLAGS on the compiler's command-line.
NOTE: In android-ndk-1.5_r1, the corresponding flags applied to both C and C++ sources. This has been corrected to match the full Android build system. (You can use LOCAL_CFLAGS to specify flags for both C and C++ sources now).
LOCAL_STATIC_LIBRARIES The list of static libraries modules (built with BUILD_STATIC_LIBRARY) that should be linked to this module. This only makes sense in shared library modules.
LOCAL_SHARED_LIBRARIES The list of shared libraries *modules* this module depends on at runtime. This is necessary at link time and to embed the corresponding information in the generated file.
Note that this does not append the listed modules to the build graph, i.e. you should still add them to your application's required modules in your Application.mk
LOCAL_LDLIBS The list of additional linker flags to be used when building your module. This is useful to pass the name of specific system libraries with the "-l" prefix. For example, the following will tell the linker to generate a module that links to /system/lib/libz.so at load time:
LOCAL_LDLIBS := -lz
See docs/STABLE-APIS.TXT for the list of exposed system libraries you can linked against with this NDK release.
LOCAL_ALLOW_UNDEFINED_SYMBOLS By default, any undefined reference encountered when trying to build a shared library will result in an "undefined symbol" error. This is a great help to catch bugs in your source code.
However, if for some reason you need to disable this check, set this variable to 'true'. Note that the corresponding shared library may fail to load at runtime.
LOCAL_ARM_MODE By default, ARM target binaries will be generated in 'thumb' mode, where each instruction are 16-bit wide. You can define this variable to 'arm' if you want to force the generation of the module's object files in 'arm' (32-bit instructions) mode. E.g.:
LOCAL_ARM_MODE := arm
Note that you can also instruct the build system to only build specific sources in arm mode by appending an '.arm' suffix to its source file name. For example, with:
LOCAL_SRC_FILES := foo.c bar.c.arm
Tells the build system to always compile 'bar.c' in arm mode, and to build foo.c according to the value of LOCAL_ARM_MODE.
NOTE: Setting APP_OPTIM to 'debug' in your Application.mk will also force the generation of ARM binaries as well. This is due to bugs in the toolchain debugger that don't deal too well with thumb code.
I personally love Electric Commander from Electric cloud when it comes to run automated build. Electric Commander comes with a very good Procedure and Steps engine which can integrate on Multiple agent node and be able to execute perl script. At the end of the build it is always recommanded to generate a nice report sometimes after running complex automation test.
PDF Packages
I like PDF::Reuse, but there are several other options for PDF creation and manipulation on the CPAN.
PDF::API2, by Alfred Reibenschuh, is actively maintained. It is the package of choice if creating new PDF documents from scratch. PDF::API2::Simple, by Red Tree Systems, is a wrapper over the PDF::API2 module for users who find the PDF::API2 module to difficult to use. Text::PDF, by Martin Hosken, can work on more than PDF file at the same time and has Truetype font support. CAM::PDF, by Clotho Advanced Media, is like PDF::Reuse more focused on reading and manipulating existing PDF documents. However, it can work on multiple files at the same time. Use it if you need more features than PDF::Reuse actually provides. Conclusions PDF::Reuse is a well-written and well-documented package, which makes it easy to create, combine, and change existing PDF documents. The two sample applications show some of its capabilities. Two limitations should be mentioned however, PDF::Reuse can't reuse existing bookmarks, and after combining different PDF documents some of the inner document hyperlinks might stop working properly.
When encoding a URL, a character may not be available on the keyboard. Other times, the character of a URL might not be usable in contexts where it may conflict with a reserved character. In either case, the character can be encoded with a % followed by its ASCII hexadecimal equivalent code.
It is tricky to write batch file aimed to execute a java application on windows if you want to process command line arguments coming from the Windows OS. Windows will report path with \ and add some " automatically when draging a file or a path on the batch file itself. While when reunning from the command line you can past a windows path using the clipboard.
On the other end we all know that java is much more happy with / inside file path.
So assuming %1 is the argument you will receive from the OS, you need to replace to / and then make sure you remove the quote since you are adding the " in the batch file.
REM Replace - Replace a substring using string substitution echo %1 set str=%1 echo.%str% set str=%str:\=/% echo.%str% REM Trim Quotes - Remove surrounding quotes via FOR command for /f "useback tokens=*" %%a in ('%str%') do set str=%%~a
This book is a gift from the Windows Phone 7 team at Microsoft to the programming community, and Charles Petzold has been a part of it. Within the pages that follow, Charles Petzold shows you the basics of writing applications for Windows Phone 7 using the C# programming language with the Silverlight and XNA 2D frameworks.
This book is divided into three parts. The first part discusses basic concepts of Windows Phone 7 programming using example programs that target both Silverlight and the XNA framework. It is likely that many Windows Phone 7 developers will choose either one platform or the other, but Charles Petzold think it’s important for all developers who have at least a little knowledge of the alternative to their chosen path.
The second part of this book focuses entirely on Silverlight, and the third part on XNA 2D. For your convenience, the chapters in each part build upon previous knowledge in a progressive tutorial narrative, and hence are intended to be read sequentially.
When logging into a website you usually start by submitting your username and password. The server then checks to see if an account matching this information exists and if so, replies back to you with a "cookie" which is used by your browser for all subsequent requests. It's extremely common for websites to protect your password by encrypting the initial login, but surprisingly uncommon for websites to encrypt everything else. This leaves the cookie (and the user) vulnerable. HTTP session hijacking (sometimes called "sidejacking") is when an attacker gets a hold of a user's cookie, allowing them to do anything the user can do on a particular website. On an open wireless network, cookies are basically shouted through the air, making these attacks extremely easy.
This is a widely known problem that has been talked about to death, yet very popular websites continue to fail at protecting their users. The only effective fix for this problem is full end-to-end encryption, known on the web as HTTPS or SSL. Facebook is constantly rolling out new "privacy" features in an endless attempt to quell the screams of unhappy users, but what's the point when someone can just take over an account entirely? Twitter forced all third party developers to use OAuth then immediately released (and promoted) a new version of their insecure website. When it comes to user privacy, SSL is the elephant in the room.
wxWidgets not only works for C++, but also has bindings for python, perl, java, lua, eiffel, C# (.NET), basic, ruby and even javascript (see General Information for bindings). It is one of the most complete GUI toolkits. There are many utility classes. There is a lot of documentation (though a bit fragmented in places). Free for personal and commercial use. Whenever possible, wxWidgets uses the native platform SDK. This means that a program compiled on Windows will have the look and feel of a Windows program, and when compiled on a Linux machine, it will get the look and feel of a Linux program. A positive side effect is that wxWidgets is thus more likely to look, behave and feel native - sometimes including native features for free (e.g. possibility to have spellchecking built-in in all text areas on OS X). A negative side effect of this is that it is more likely that the behaviour is different between platforms; toolkits where widgets are lightweight lose some of the native aspect but also minimize platform-specific code (hence minimizing the risk of different behaviour from platform to platform and also minimizing the risk of platform-specific bugs). Concentrating on native looks also mean wx may not be best suited for applications that want a customized look instead of the system's theme.
Windows Build extract everything under
C:\wxWidgets-2.8.11
Go to C:\wxWidgets-2.8.11\build\msw
open wx.dsw with Visual Studio 2008. Visual Studio will then ask you if you want to convert the Visual Studio 6 project to visual studio vcproj. Select yes to all. By default wxWidgets will target win32 platform but you can add x64 platform.
All lib will be generated under
C:\wxWidgets-2.8.11\lib\vc_lib
wxWidget works well with GTK+ because GTK is one of the choice to build wxWidget on Linux.
GTK+
http://www.gtk.org GTK+, originally the Gimp toolkit, is a LGPL C-language GUI library for Unix systems. It has been ported to Windows, VMS, and other systems (MacOS X currently possible through Apple's X11.app, native version in development) using the same API. However, primary development and focus is for Unix, with multi-platform development mostly as an afterthought. GTK+ is the primary library used to construct user interfaces in GNOME. Unlike wxWidgets, GTK+ supports C (and there is a C++ wrapper called GTKMM, http://www.gtkmm.org ) The API is quite well developed, and includes safe casting and other things; but C++ has these built in. It's built on top of glib, a general-purpose library (similar in some ways to the C++ STL -- it provides a few data structures, functions to help memory management, etc). It looks the same on all platforms, except Windows XP, where it tries (with some success) to get Windows' native look and feel with the Wimp theme, which uses UxTheme. However, it's still very much a Unix library.
Building GTK+ on Windows requires MinGW and MSys which might mot be an easy task some
Stable release for GTK+ is available on:
GNU/Linux and Unix Windows (32-bit) and 64-bit OSX
For windows http://www.gtk.org/download-windows.html there are all-in-one bundles of the GTK+ stack including 3rd-party dependencies, both of GTK+ 2.16 and 2.20. The bundles contain both binaries and a lot of developer files, many of which are relatively irrelevant. If you intend to redistribute the GTK+ run-time, you need to figure out which files you can leave out yourself.
CMake is a great way to generate Visual Studio 2008 solution for wxWidgets/GTK UI. CMake GUI will help you browse for all library include path and library. Cmake will update the build folder and cache all missing entry inside CMakeCache.txt
# This is the CMakeCache file. # For build in directory: c:/Dev/Project/Source/build # It was generated by CMake: C:/Program Files (x86)/CMake 2.8/bin/cmake.exe # You can edit this file to change values found and used by cmake. # If you do not want to change any of the values, simply exit the editor. # If you do want to change a value, simply edit, save, and exit the editor. # The syntax for the file is as follows: # KEY:TYPE=VALUE # KEY is the name of a variable in the cache. # TYPE is a hint to GUI's for the type of VALUE, DO NOT EDIT TYPE!. # VALUE is the current value for the KEY.
When clicking on generate a solution for your compiler EG Visual Studio 2008 will be generated. From there you can open the solution and step into wxWidget/GTK UI. GTK offer the advantage to be stable in term of API which means that if you build a UI using GTK today it should work 5 years from now.
On the other hand Trolltek team made quite some changes between QT 3 and QT 4 which require some work to translate old code to new code. See Moving from Qt 3 to Qt 4 http://doc.trolltech.com/4.3/porting4-overview.html When starting a project from scratch QT 4 would be a good solution.
QT
Both Qt (http://www.qtsoftware.com/) and wxWidgets have many non-GUI-related classes, such as date/time, containers, networking and OpenGL functionality. Qt4.5 is available on MS Windows, Mac, and GNU/Linux under the LGPL and under a commercial license. All ports of wxWidgets are distributed under a permissive modified (but explicitly OSI-approved) LGPL, which allows development and distribution of proprietary applications without license costs. Qt doesn't have true native ports like wxWidgets does. What we mean by this is that even though Qt draws them quite realistically, Qt draws its own widgets on each platform. It's worth mentioning though that Qt comes with special styles for Mac OS X and MS Windows XP and Vista that use native APIs (Appeareance Manager on Mac OS X, UxTheme on Windows XP) for drawing standard widget primitives (e.g. scrollbars or buttons) exactly like any native application. Event handling, the resulting visual feedback and widget layout are always implemented by Qt. An approach similar to Qt's is achieved with wxUniversal. It should be noted that on KDE and Qt for Embedded Linux platforms, Qt is the native GUI library. Qt is used by several large projects like KDE (on the other hand, wxWidgets is used by projects like the AOL Communicator) Qt makes extremely liberal use of virtual functions (QWidget, the base class of all widgets in Qt had 51 at last count), giving it a more OO design than wxWidgets (which uses a more MFC-like approach using macros). What this means is fewer lines of code in general when using Qt, but faster execution speed when using wxWidgets (although the degree to which this occurs depends on whom you ask). Qt is used by IBM and Borland Kylix (discontinued): this should yield more reliability. However, it is rumoured that wxWidgets will be used in the next version of C++BuilderX. Qt has a full-featured embeddable GUI (Qt for Embedded Linux) based on GNU/Linux with framebuffer. This means that once you have Linux with /dev/fb you are ready to run examples with no additional pains. Qt for Embedded Linux has a small footprint compared with X11. There are numerous IDEs for Qt, QtDesigner, QtCreator, QDevelop, Edyuk as well as integrations with popular IDEs such as Visual Studio, Eclipse and XCode (though there are also several IDEs for wxWidgets). Qt offers reliable commercial support (but so does wx, see http://www.wxwidgets.org/support/support.htm) There is nothing to stop somebody writing a Qt-based implementation of wxWidgets, though wxWidgets applications can already be made to appear Qt-ish using wxGTK and GTK-Qt (this doesn’t work too good, though).
First of all running automation of Internet Explorer with Flash Content on a 64 bit OS is not easy because by default the OS will launch 64 bit version of Internet Explorer instead of the 32 bit version.
Products affected You might be on this page because you can't view content with the Flash Player. This is likely because your computer is running a 64-bit Web browser on a 64-bit operating system and you are trying to install Flash Player. Flash Player does not run in most 64-bit browsers. If you attempt to download the Flash Player in a 64-bit browser that does not support Flash Player, you will see a message from Adobe and a link back to this page. To install Flash Player, use a 32-bit Web browser on your 64-bit operating system. All major browsers are available in 32-bit versions and the Internet Explorer 32-bit browser is the default browser on Windows 64-bit systems.
There are two InternetExplorer.Application objects on x64-bit systems, one for x32 bit, the other for x64. By default, the x64 bit version is launched when you call the object, because by default the x64 bit wscript.exe is used. But you can also launch the x32 bit version of the object by using the x32 bit version of wscript.exe and passing the vbs url to it as an argument:
The same works for all other x32 bit ActiveX objects in case you have to use them.
If you are using CoCreateInstance() of CLSID_InternetExplorer (to obtain an out-of-proc instance of iexplore.exe), you can pass one of these new flags in the dwClsCtx field to control which kind of server (32-bit or 64-bit) you get:
CLSCTX_ACTIVATE_32_BIT_SERVER = 0x40000, // Pick 32 bit server over 64 bit server CLSCTX_ACTIVATE_64_BIT_SERVER = 0x80000 // Pick 64 bit server over 32 bit server
Activideo is a software created by a small company Actimus which can help you generate all what you need to produce the raw data needed for an interactive video experience. For more information about Activideo visit http://shop.actimus.com/ and to see how it work visit http://shop.actimus.com/demo/howitworks/. Some video tutorials are now available to explain you how to use Activideo http://shop.actimus.com/demo/tutorials/ and user who purchase the software have access to online documentation.
Activideo is a fast and easy way to turn your videos into interactive presentations thanks to the export of well known Adobe XMP Metadata container. Activideo adds interactive hot spots (also called overlay sequences) to your videos. It is a simple but powerful concept: user-created hyperlinks within the video at various intervals and for specific areas in the video the same way hypertext is used on the Internet. These hyperlinks and interactive hotspots are exported into Adobe XMP RDF XML file format. Activideo could also produce Adobe Flash Action script 3 file along with a FLA and HTML template to be able to build your custom SWF with Adobe Flash CS4 or Adobe Flash CS5 thanks to a Plugin SDK. Actimus is about to release a live component for Flash CS5 which will provide the ability to validate/test each invisible hotspot by playing the video inside the Activideo Player.
Input Formats:
Activideo supports many input video file formats mostly any file format supported by the Direct Show software stack. Today, it currently supports MPEG1, MPEG2*, MPEG2-TS* transport streams including HD (720, 1080), DivX*, Microsoft AVI, Microsoft WMV* and WMV-HD *, Blueray * m2ts file, MKV, FLV and should work with WEBM (VP8). Activideo never modifies the original source video neither encode a Video. This tasks is left to Adobe Media Encoder and Adobe Bridge CS4 bundled with Adobe Flash CS4 Pro
Overlays:
The outlining of the overlay sequences is very precise because Activideo supports polygons with up to 100 vertices within a sequence. It performs linear interpolation of each vertex to transition smoothly from one shape to another. While the video is playing into Activideo, the user can move the current polygon location with the mouse visually to match any portion of the video associated and covered by polygon (and polygon are not visible on top of the final encoded Video. This is a human intervention process but it can be automated if the user doesn't plan to move the object on screen thanks to a very functional Wizard well suited to create a unique sequence and for example turn a logo encoded in the video into an hyperlink. To ease the overlay authoring process, a static logo sequence can be generate using the Creation Wizard.
Demo version: Yes : Export of XMP No : Project saving. Yes : Wizard to create an interactive sequence available. 21 days of evaluation.
Full version: Yes : Export XMP Yes : Access to self registered COM Export Plug-ins available through Export As Menu NO activation required.
DOWNLOAD QT SOURCE CODE As the option to download only the Qt source code is a bit obfuscated on the current Nokia website, please follow these directions:
Go to http://qt.nokia.com/downloads and click the Go LGPL button. Since you want only source code, look at the Qt: Framework Only column on the right. Click e.g. Download Qt libraries 4.6.3 for Windows (VS 2008, 194 MB) — choose the VS2008 one.
This starts the download for pre-built Qt. But we don’t want that as we will be building Qt ourselves. A page will appear with . Cancel the Save As dialog in your browser to cancel the binaries download you had clicked on, then click on this link, e.g. http://get.qt.nokia.com/qt/source/qt-everywhere-opensource-src-4.6.3.zip Unzip the file into e.g. c:\qt\4.6.3-vc. Please use a path with no embedded spaces, as the Qt build tools have issues with them. SET ENVIRONMENT VARIABLES Open Computer Properties | Advanced system settings | Environment Variables:
Edit environment variable to add: QTDIR = c:\qt\4.6.3-vc Edit the PATH environment variable to add: %QTDIR%\bin Either close all command prompts and Visual Studio instances, or reboot... the computer so the new command-line takes effect. BUILD VC++ VERSION OF QT Open a Microsoft Visual Studio 2008 Command Prompt, which is a command console with environment variables set for the specified VS. This is easily accomplished using Start | All Programs | Microsoft Visual Studio 2005 (or 2008) | Visual Studio Tools | Visual Studio 2005 (or 2008) Command Prompt. Cleanup any previous build: c:\> cd c:\qt\4.6.3-vc c:\qt\4.6.3-vc> nmake distclean
c:\qt\4.6.3-vc> rm -rf tmp* // <– recursively remove all tmp\ folders and files I use GNU Tools or even better Cygwin. Cygwin is very useful because you can also build other open source unix source code library including complicated ffmpeg that you may want to link to your QT project. You can download the gnuwin32 package maintenance utility on the sourceforge.net project portal. Cygwin can be downloaded here
Run Configure with no parameters to see a help screen. Configure generates nmake compatible makefiles to build all the Qt DLL’s, tools, and demos.
4. Run nmake to build.
c:\qt\4.6.3-vc> nmake
It will take awhile, but this grinds through building the specified Qt DLL’s, tools, and demos with Visual Studio.
INSTALL VISUAL STUDIO ADD-IN The Qt Visual Studio Add-in is indispensible for developing Qt apps in Visual Studio. The Add-in has replaced the previous Qt Visual Studio Integration, which was only available to Commercial customers. Now the Add-in is used by both LPGL and Commercial licensees, and the Integration has been deprecated. While the Add-in does not allow integrated .ui editing (it instead launches Qt Designer to edit .ui files), it is fully supported and maintained by Nokia, whereas the Integration hadn’t been modified since the 4.3/4.4 timeframe.
Because Visual Studio Express does not allow add-ins, using these free versions of Visual Studio is not recommended for Qt development. You need at least Visual Studio Standard (Pro, Team System, etc. of course will also work).
1. Download and install the Qt Visual Studio Add-in to install the Qt plug-in into Visual Studio (both 2005 and 2008 are supported by the add-in).
2. Start Visual Studio.
3. Select menu Qt | Configure Qt Versions. Add c:\qt\4.6.3-vc.
4. Now Qt is fully functional, and you can use VS2008 to build Qt apps.
QT IN VISUAL STUDIO 1. See Qt menu item. Launch Qt Designer (the Resource editor) and Qt Linguist (the localization tool).
2. Create new Qt projects. File | New project, select Qt4 project.
3. Read Qt Help. Available from Help menu (Qt help is merged in with Visual Studio Help and viewed in Document Explorer.) Or, manually launch
1. On the command line with "qmake -tp vcapp -r yourProfile.pro"
Ensure that the QMAKESPEC environment variable is set to the appropriate value. If you use Visual Studio 2008, then win32-msvc2008 is the correct value.
To set your environment variables in Windows, please see http://en.wikipedia.org/wiki/Environment_variable Note that you may have to re-open a command window before your settings are changed. To check that your PATH is set correctly: C:\> qmake -v QMake version: 2.01a Using Qt version 4.6.3 in C:\Qt\4.6.3\lib To see if QMAKESPEC is set correctly: C:\> echo %QMAKESPEC% %QMAKESPEC% // not set win32-msvc2008 // set
2. With the Qt Visual Studio integration via the menu "Qt->Open From .pro File" and save your project to also save the visual studio solution .sln file
==================== MFC AND QT
This walkthrough covers the migration of an MFC based program, generated by Microsoft Visual Studio's MFC Application Wizard, to the Qt toolkit using the Windows Migration Framework.
The task of protecting your software from hackers is not easy. Put simply, complete and total protection - is not possible. If the hacker has access to your complete program, they can eventually break any and all protections you put in their way. This is not opinion - it is a fact. This is simply because they control the hardware at the most "intimate" level on which your program is running. As you know, a program is simply a set of instructions. Since the hacker controls the hardware on which those instructions are executed, eventually they will find the instructions in your program where your protections lie and simply change them.
A simple analogy illustrates this point: You have a lock on the front-door to your home don't you? When you leave the house, do you lock it? Of course you do. Why? You lock it because you don't want people to steal your stuff. If the door was unlocked, they would walk in and rob you. But, ask yourself, if they really wanted to get in, could they? If they had a crowbar and a chain-saw of course they could, sometimes they could simply kick in the door. If you had a great deal of valuables, you might get an alarm-system or a stronger door, but again, if they really wanted to rob you - they could. Software that resists hackers is just like a home with a locked door. You must make a reasonable attempt to keep your software safe since that will "keep the honest people honest", but at the same time, do not delude yourself into a false sense of security.
Of course - all is not lost. We recommend that, in light of this knowledge and accepting the facts as they are, instead of playing "the game" of protection with the intent to "win" (to completely stop the hackers) - we play for an impasse. Since we know that a "win" is impossible, we play the "game" for the next best thing - a tie. What we mean by a "tie" is that you should engineer your protections in such a way that:
It is as difficult, tedious and time consuming as possible for a cracker to crack. Is difficult to crack successfully or without breaking some key part of the program. If cracked, can be quickly and easily changed so the crack no longer works with the current version of the software.
What can you, as a developer, do to make your implementation of you software licensing solution as secure as possible? What can you, as a developer, do on an ongoing basis, in order to make your software as secure as possible? Anti-hacker standard practices are just that - standard. They should not be limited solely to your implementation of the licensing System and the code around it. So, in fact, the two concerns above are one and the same. Below are several simple "tricks" you should consider, that when used together, will force crackers trying to defeat your system to invest incrementally more time in doing so. When used in conjunction with the licensing System, their job will be unpleasant to say the least. Please be sure you understand that the purpose of playing the "game" is an impasse.
Here are several standard things you should do in any software you wish to protect to slow down crackers:
1 - Never give any registration or protection testing function a self describing name. Never use a function name like "IsActivated". Crackers will quickly locate these names (in most high level languages) and simply remove or rewrite them. 2 - Avoid unnecessary error messages. If your program gives an error message after an unsuccessful activation attempt, the crackers will be able to quickly locate the error message and know that at some point in the call stack immediately before it - a protection or activation-test function call failed. 3 - Wait using a timer in a separate thread to provide error messages. When an error message is unavoidable, you may wish to set a timer in a separate thread that will fire several seconds or minutes later to warn the user and take action. This makes tracing back to the protection call that caused the timer to start up more difficult and will slow the cracker down. 4 - Encrypt any and all protection strings. When an error message in unavoidable, be sure to dynamically generate the message string itself. The best way to do this is to store it in encrypted form in the binary and decrypt only immediately before you need it. This makes searching for the string very difficult. Better yet - encrypt all your programs strings. 5 - Use random tests for activation. Test that the program is correctly activated at random time intervals; hours, days or even weeks after it was first installed and run. Possibly test only after certain key functions (unrelated to activation) are used. This will often be missed by crackers and again will slow them down or make their crack worthless. 6 - Don't start the activation test for several seconds (or even minutes) after the activation. you may wish to store any Activation Codes input by the user temporarily in memory and after a brief pause try to activate them. You may even wish to require the user to restart the program before you input the value. This makes it difficult to trace and will slow the cracker down. 7 - Use CRC checksums in your application and dlls. Have your EXEs check themselves, check other DLLs, or even have them check each other. Consider computing a checksum on just a small section of the file itself instead of the whole thing - this makes the crackers job more difficult. 8 - Use Anti-Debugging tricks. Be sure you have read the Anti-Debugging section for more information on how to slow down crackers by having your software resist debuggers. 9 - Use Anti-Disassembling tricks. Be sure you have read the Anti-Disassembling section for more information on how to slow down crackers by having your software resist disassembling. 10 - Use more activation checking routines than the minimum necessary. You should test in several places, and in places where the crackers might not expect it. Check at random time intervals too (see above). One routine requires a time investment from the cracker to remove, then more routines will require even more time to break. 11 - Use Honey Pots. A "Honey Pot" is a fake or decoy routine (or set of routines) you code into your program that seem to check activation, but in fact - does nothing. Have it write and read registry keys, manipulate files, jump all over in memory computing useless values and doing meaningless comparisons. Use your imagination here. Name honey pots to draw the crackers attention (like "CheckReg"). The point is to waste their time with a ruse. 12 - Wrap Activation testing routines in ridiculously long code. Consider using several long procedures which do a huge amount of unnecessary (but seemingly meaningful) processing. At some point during this useless processing, legitimately check the activation. Consider even checking it two or three times in different ways. This make the crackers job of tracing through this giant jumble of assembly looking for the "real" code a more frustrating experience. This will slow them down. Your testing routines can safely take 5 to 20 seconds to execute on a reasonably fast machine. 13 - If you use a demo version of your software with limited features, make sure you don't have "grayed out" buttons or menu options. A cracker can simply change the enabled property of these controls which will effectively make your features visible again. It is always preferable to dynamically create these controls only when they are available. If you use a demo version of your software with limited features, consider not distributing the actual binary code to execute those functions. The simplest way to do this is to include the "paid version only code" inside a DLL which is called from your program when it is legitimately purchased. Then when a customer purchases your software, give them an Activation Code to release your software protections as well as the required DLL containing the code for the missing features. 14 - If your program has been cracked, release a new version. This is probably the most important principle which makes all the above tricks worth while. Once you have wasted the crackers time as much as possible, slowing them down with all these tricks (and others you may think up yourself), you must immediately make all their hard work go to waste - release a new version fast. Change a few things around, re-organize the code, update the version number, test - and re-release. The cracker will have to start all over again. Reaction time is important too. Expect to move quickly if a crack is released. Try and release a new version as rapidly as possible to maximize the frustration effect.
cyclic redundancy check
A CRC (cyclic redundancy check) is a numeric value computed from some source (file, string, digest, etc). Unlike encryption, a CRC value is always the same size regardless of the source size. A CRC is also commonly referred to as a hash or a checksum.
There are numerous sources on the internet for information on what a CRC is, so the algorithms wont be discussed in depth here. Regardless - it may be preferable from a security standpoint for you to develop your own CRC algorithm variation based on a well-known cryptographically secure one.
A CRC can be used to help slow down hackers by computing a CRC checksum of some file (on Windows your EXE or a DLL) and comparing the computed value with a stored value from a known and trusted source. If any of the instructions have been changed, the CRC checksum will not match.
This can be used by your software team in a couple ways to slow down the crackers:
Trojan Server Attack
A cracker may try to replace the DLL (in case of COM with a Trojan COM server with the exact same interface but whose functions always returns true values). You can use a CRC value to attempt to defeat this attack: The basic premise is:
On Windows Operating Systems, read from the registry the location of the DLL based on the known GUID of the COM server you want to check. If that file exists, calculate a CRC checksum on it. (Any CRC or hashing algorithm can be used - it doesn't matter). Compare the checksum calculated against your known checksum which you have previously computed on a trusted copy of the COM server. Take action depending on the match. Perform a CRC check on the dll every time your program starts but before you actually use the system. Check the return value of the CRC check on the dll against a value you store inside your program. If they are not the same - the dll has been swapped, damaged or altered. To make this even more secure have the value inside the program you check against be stored in three different places, and assemble it just before you use it. A C++ example follows where, at development time, you have already run your CRC function on a trusted copy of the dll file and you know it should return a value of 3070908778 :
char buffer1[25] = {'\0'}; char buffer2[25] = {'\0'}; const char * val1 = "778"; // declared in a different module somewhere const int val2 = 3070; // declared in a different module somewhere static int val3 = 908; // maybe read from the registry where your installer wrote it.
You can even implement or use you own version of itoa, atol and strcat
CRCChecks can be quite simple to implement. We suggest that you use your own CRC to ensure that it is original.
Binary Instruction Replacement Attack A cracker may simply replace the protection calls in your program to do nothing - ignoring the COM server altogether. In fact - this is a very common attack used by most crackers. You can use a CRC value to attempt to defeat this attack:
All 32-bit executables have a CRC checksum field in their programs PE header. You can force your compiler to generate this checksum. Then, using the Win32 API MapFileAndCheckSumA() you can get both the computed checksum and the stored one. Then simply compare them. This of course only works if the cracker doesn't change the stored one, but can sometimes be effective. There are many more sophisticated approaches to using CRCs in your program to detect the integrity of both itself and external modules (dlls) but they are beyond the scope of this help file.
You may even wish to consider computing the checksum on just a small section of the file itself instead of the whole thing - this makes the crackers job more difficult. Don't just have EXEs and DLLs check themselves, have them check each other.
Anti-Debugging
Debuggers are tools just like your IDE that allow crackers to trace a programs execution as they are running - instruction by instruction.
There are numerous anti-debugging tricks that are documented in books and on-line, but all approach the problem from two specific angles:
They attempt to detect any debugger that is currently attached to the process or running in the background.
They attempt to detect specific debuggers (like SoftICE and others).
Protected software should use some sophisticated techniques to protect you from debuggers in both these ways, However, this is only effective when the Binary/DLL methods are actually called to perform some action. To be even more resistant you should consider implementing anti-debugging tricks of your own.
There are simply too many well-documented ways to detect specific debuggers (like SoftICE) available to discuss them here. Many of them are very complex to implement or are ineffective. Instead, we suggest you make at least a simple attempt to detect debuggers. The simplest way to do this is with the Win32 API function call "IsDebuggerPresent". Although this is relatively simple to replace by most crackers, and only works on Windows NT, 2000 and XP, placing it in various unexpected locations in your program can sometimes be quite effective at slowing them down.
Anti-Disassembling
Disassemblers are tools crackers use to translate application code back into assembler or even a higher level language. There are several disassemblers on the market of various quality. Some even write comments on the translated code, which makes it easier for the cracker to understand.
Since the purpose of disassembling is to understand the programs code, a good way to counter disassemblers is to make it more incomprehensible internally. The simplest way to defend against disassemblers is to insert numerous small bits of code in between the legitimate program code instructions that do nothing meaningful, but appear to, and are complex to understand.
A simple way to do this is to define a number of anti-disassembling macros and inline functions. Use your imagination to write these macros and functions. Do lots of pointer arithmetic and mathematical transformations. Conditionally and unconditionally jump all around in memory. Make sure your anti-disassembling routines are macros or inline functions so the anti-disassembling code gets pre-processed and duplicated everywhere it is placed (instead of a simple function call which can be found and replaced in a single location by a cracker).
Then, sprinkle these macros and functions liberally around areas of your programs you wish to protect from disassembling. Increase the density of the routines around sensitive areas. Naturally this will increase the footprint of your binary and can potentially impact performance so use this trick very wisely. You may wish to reserve its use for areas only around your protections and licensing code.
The more you can make the crackers job tedious, the more time he will have to invest in cracking your software - which is the ultimate goal - to slow them down as much as possible.
The Qualcomm Snapdragon platform continues to generate robust industry attention to accompany its steadily expanding customer base. At the recent COMPUTEX 2010 show, Qualcomm unveiled the sampling of the third generation of its Snapdragon platform – namely its first dual-CPU Snapdragon chipsets consisting of the MSM8260, MSM8660 and QSD8672 products that feature enhanced dual cores that can run at up to 1.2GHz and 1.5GHz respectively, and are targeted at the high-end smartphone market area (the third generation Snapdragon platform is expected to support commercial products by the end of 2010). The new third-generation Snapdragon products complement its first-generation QSD8x50 1GHz core product and the second-generation MSM8x55 and QSD8x50A products with 1GHz enhanced core, including multimedia optimizations and 1.3GHz enhanced core respectively.
The Snapdragon platform can be viewed as competing within the mobile application processor market segment (also referred to as the mobile multimedia processor market segment). Today the application processor segment includes IC platforms that typically integrate the application processor core along with additional functions such as baseband modem andwireless connectivity functions onto a single system-on-a-chip (SoC); this includes the Qualcomm Snapdragon. The application processor market also consists of IC platforms that exclude integration of baseband modems (e.g., TI’s OMAP 4). The application processor platform segment addresses a wide range of mobile devices including smartphones, mobile Internet devices (MIDs), netbooks and portable media devices. By its nature, the mobile application processor market segment attracts a wide swath of competition from the top-tier mobile silicon players, including Samsung, Apple, Intel and TI. Due to Qualcomm’s historically solid competitive foundation, based heavily on its CDMA chipset royalties, and the burgeoning traction of the Snapdragon platform (in over 140 device designs), it presents a mounting competitive challenge and thus generates the key issue of how the competition can position against the overall Snapdragon platform. Perspective Current Perspective The Snapdragon platform has been commercially available since Q4 2008 through the QSD8650 and QSD8250 first generation product offerings. From its inception, Qualcomm positioned the Snapdragon platform as an innovative breakthrough offering since it uses the in-house custom developed Scorpion CPU as the core application processor based on the ARMv7-based Cortex-A8 core. This approach has enabled Qualcomm to engineer improvements over standard off-the-shelf ARMv7-based Cortex-A8 processors in areas such as power consumption (e.g., the first Scorpion processor required 150 mW less power consumption at 600 MHz than the non-customized ARM equivalent and so on) as well as optimizing the processor design for the low-power (LP) process. As a result, the Snapdragon platform has proven a stalwart in the smartphone application processor market, as evidenced by the Snapdragon platform’s incorporation in over 140 device designs that include mobile devices that range from HTC’s Droid Incredible and Nexus One smartphones to Huawei’s S7 tablet, to name a few.
For the first generation Snapdragon QSD82x0 products and the second generation Snapdragon MSM8x55 and QSD8x50A products, Qualcomm shares platform and product metrics in areas such as core processor clock speed/performance, flexible wireless connectivity functions, HD video/3D/display/camera support and O/S versatility. This gives rivals a wide range of product areas to seek selective differentiation against the Qualcomm Snapdragon platform, although Qualcomm is hardly unique in that regard.
The topic of core processor clock speed and performance, for example, represents a straightforward and intuitive product area for rivals to assert competitive differentiation. The Snapdragon platform’s first-generation QSD8x50 supports a 1GHz core processor while the second-generation MSM8x55 and QSD8x50A products support a 1GHz enhanced core, including multimedia optimizations and a 1.3GHz enhanced core respectively. In contrast, Intel asserts that its x86 processor-based Moorestown platform via the Atom Z6xx processor series can support up to 1.5GHz clock speed for smartphone devices and up to 1.9 GHz clock speed for tablet devices. Such metrics will still match the third generation Snapdragon QSD8672 product that is designed to run dual cores that operate at 1.5GHz (this product should appear in mobile devices at retail by the end of 2010). This complements Intel’s overall efforts to position its Moorestown platform as prime time ready for smartphone technology due to the improvements realized in areas such as power consumption advances in battery life spans (based on 1500 mAh batteries) in support of 1080p/720p video (e..g, up to four hours for 1080p video) and browsing applications as well as multi-fold improvements gained in Java script, Web page, graphics and video performance. This includes up to fourfold Java script performance improvement and at least a doubling of Web page download performance and graphic performance in relation to the Qualcomm Snapdragon platform as well as wielding the industry’s only across-the-board support of 1080 HP/MP/BP 30 fps and 720 HP/MP/BP 30 fps video capabilities. Intel’s overall R&D investment and marketing blitz on behalf of the Moorestown platform is certainly targeted at Snapdragon, as well as advancing Intel’s longstanding ambition to promote the x86 processor architecture as a viable alternative to the ARM processor architecture that dominates the mobile device silicon market today. Intel hopes to play a more prominent role within the overall mobile device silicon market beyond netbook silicon. There is a bit of irony here as Intel is looking to use the Intel Moorestown platform to attack the ARM-centric Snapdragon platform in Qualcomm’s backyard of smartphone and tablet silicon, while Qualcomm is developing the Snapdragon platform to help more directly challenge Intel’s prominence within the netbook silicon segment.
Apple, Samsung and TI are Qualcomm rivals that also use the customization of the ARMv7-based Cortex-A8 processor to achieve select advancements over the standard ARM offering. Samsung and Apple currently have a strange bedfellow arrangement that can influence how they position their respective platforms against the Snapdragon platform. Samsung collaborated with Intrinsity in developing and introducing its 45nm-based Hummingbird platform during 2009. In April 2010, it was revealed that Apple acquired Intrinsity in stealth mode to lock up the FastCore intellectual property (IP) that was instrumental in realizing the iPad A4 processor’s enhancements to standard issue ARM Cortex-8 core processor technology (e.g., achieving 1 Ghz clock speed on a 45nm process). Through the acquisition, Apple can promote that its A4 processor development efforts are dedicated exclusively to the support of Apple products such as the iPad and iPhone, and the company can avoid the dissipation of processor engineering resources that its rivals, such as Qualcomm, are obliged to perform through the open-ended support of multiple OEM products. Samsung should look to further elucidate its plans to license the Hummingbird technology to other mobile device vendors and what if any impact this has on its Apple relationship. The Apple acquisition of Intrinsity does not change the fact that Apple’s A4 technology remains based on Samsung’s 45nm SoC technology and Samsung continues to have access and wield the Hummingbird IP gained from its joint collaboration with Intrinsity prior to the Apple acquisition of Intrinsity.
Samsung continues to register significant product development and marketing advances with its Hummingbird SC5PC110 processor. The Hummingbird S5PC110 runs the Samsung Galaxy S smartphone, which Samsung asserts will launch in an astonishing 110 countries. One area the Samsung can assert clear product differentiation against Qualcomm is in the area of 3D graphics. The S5PC110 processor can scale up to support 90 million triangles per second. In contrast, the Qualcomm QSD8650 delivers only 22 million triangles per second while the pending QSD8672 will do up to 80 million triangles per second. Additionally, in the related area of 2D graphics rendering, Samsung’s S5PC110 product can support up to one billion pixels per second while Qualcomm’s QSD8650 supports only 133 million pixels per second and the upcoming QSD8672 product still comes up short against Samsung with an improved 500 million pixels per second.
TI’s OMAP 4 platform using the OMAP4440 processor is slated to support mobile device products that will hit retail in late 2010/early 2011. The OMAP processor series is already found in well-known mobile handset products such as the Nokia N-series, the Motorola DROID, and the Palm Pre. However, OMAP 4 dual core clock speeds are limited to just 1 GHz, and that’s for a product that is not yet in generally available mobile products. In this regard, OMAP 4 only ties the Qualcomm Snapdragon’s first generation 1 GHz product and trails both the second and third generation 1.2Ghz-1.5Ghz products. However, TI has already staked out a competitive position against Qualcomm in this area showing how apples-to-apples comparisons can prove dicey at times in the mobile silicon space. TI asserts that the OMAP 4 can deliver improved resolution display and still image metrics in relation to the Snapdragon platform, despite the core processor clock speed differentials. For example, the OMAP 4 can deliver 20-megapixel camera support while the QSD8x50 product can only handle 12-megapixel cameras. Moreover, TI advocates the OMAP 4 platform will prove more flexible in hardware support of future video codecs in relation to the Snapdragon platform. TI will also invoke that its OMAP4440 processor will use the ARM Cortex-9 architecture, which can yield performance improvements over ARM Cortex-A8 products (up to 30 percent according to ARM) and more flexible dual core power management arrangements.
Overall the most serious long-term competitive threats to the Qualcomm Snapdragon platform within the smartphone and tablet application processor market will prove to be the major mobile silicon players such as Samsung, Apple and TI, as well as Intel, who already possess competitive application processor platforms targeted specifically at smartphone, MID and tablet products. Mobile silicon rivals such as Marvell, Freescale, NVIDIA and ST-Ericsson all sport viable mobile application processor platforms but need to prove they can move the market needle more within the mobile application processor market segment to mount a serious challenge to Qualcomm in the evolving smartphone/tablet silicon market segment. Marvell and Freescale have achieved market distinction within the ereader niche, for example, but are not able to match the Snapdragon’s presence in over 140 device design wins. Samsung, Apple, Intel and TI all possess the product differentiators in areas such as core processor clock speed/performance, power consumption metrics, and HD video/3D/display/camera video performance and the global channels to challenge the Snapdragon’s early market prominence in this area into the foreseeable future. Recommended Actions Vendor Actions • Mobile application processor vendors that target emerging 4G/LTE silicon devices should consider getting out ahead of the market in explaining how their platforms optimally complement the region-sensitive E-UTRA LTE bands (TDD/FDD modes). In general, mobile application processor vendors should posit the 4G/LTE market represents a new level playing field in the market as Qualcomm’s dominance in the CDMA/3G silicon market will not directly translate into the same type of dominance within the 4G/LTE space.
• Mobile application processor vendors should note that they generally rely on third-party partners to supply fundamental mobile silicon components such as baseband modems and RF transceivers to complement their application processor platforms while Qualcomm uses integrated in-house baseband modem and RF transceiver components as part of the Snapdragon offering. This provides some latitude in asserting that they can select best-of-breed components in these areas and have more supply chain flexibility in relation to Qualcomm’s single vendor approach.
• Intel should continue to pointing out that the smartphone/tablet market is still in its developing stages, which gives Intel ample opportunity to capitalize on new market opportunities in this fast growing segment. This includes pointing out that the Atom Z6xx series is already in the advanced demo stage in smartphones with 3.8”+ displays and ~15mm thin tablets and the x86 platform supports rising mobile O/Ss such as Android and MeeGo. User Actions • Smartphone and tablet OEMs need to test and contrast the Intel Atom Processor Z6xx series (prior codename Lincroft SoC) against competing ARM-based mobile device SoCs, such as Qualcomm’s Snapdragon platform, due to factors such as its compact package (i.e., 13.8x13.8x1.1mm with 0.5mm pitch), support of 19 power islands with on-die clock and power gating, new ultra low-power states (i.e., SOi1, SOi3), and the leveraging of Intel’s Hi-K 45nm LP SoC process.
• Smartphone and tablet OEMs should investigate the new OS power management (OSPM) capability that accompanies the overall Moorestown platform. This includes support of integrated PMUs, software-based OS power management options, and fine-grain power management functions that create power islands for sub-systems (i.e., power is only allocated to the application running and not dispersed to idle applications, etc.) and factor in such capabilities in seeking apples-to-apples validation of Intel’s power conservation claims on behalf of the Atom Moorestown platform in relation to the Snapdragon platform