Javaflow Continuation: Trying to Save Static variable - continuations

I had been trying to create some check-pointing solutions using Javaflow . It works well with all the local variable. But it is unable to save the static variable instance. I am trying to do something like this:
foo( ){
//Doing Something
//Writing the static variable value, suppose
MyClass.StaticValue=10;
Continuation.suspend( ); //Checkpoint P created
//Do Something
//Update the static value, suppose
MyClass.StaticValue=11;
return;
}
Now when i try to restore back from checkPoint P, I expect to read the StaticValue as 10, but it is 11. I have two questions regarding it:
Is it a expected behavior from Javaflow or I am missing something while using Javaflow?
Is there a smart way to store these static variable other than using some versioning and storing all of them.

I think I found my answer:
1. Javaflow don't support static variables check-pointing.
2. Only versioning looks like a direction.

Related

How to detect if it's inside Backboardd in my tweak of iOS?

I want to inject some functions to Backboardd, because of some reasons, I can not use plist to restrict it, so I want to use "if" to determine whether it's inside Backboardd.I know in 'Logos' I can use like that:
%ctor{
if (%c(SpringBoard)) {
}
}
But without Logos, can I do it like below?It doesn't work.
MSInitialize {
if (objc_getClass("Backboardd")) {
CFMessagePortRef local = CFMessagePortCreateLocal(NULL, CFSTR(MACH_PORT_NAME), messageCallBack, NULL, NULL);
CFRunLoopSourceRef source = CFMessagePortCreateRunLoopSource(NULL, local, 0);
CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode);
}
}
In general, you need to find some obj-c class that is unique to what you are hooking. Ideally, it should be class defined inside that binary, not imported from a framework. For example, in SpringBoard there is SpringBoard class that can only be found inside SpringBoard's binary. If objc_getClass("SpringBoard") returns non NULL value then you're inside the SpringBoard.
Now, backboardd. What I'm doing in cases like that is copying binary on my PC and obtaining the list of all classes inside that binary using class-dump or IDA. In case of backboardd, good candidate would be BKApplication. So
if (objc_getClass("BKApplication")) {
...
}
would do the job. There is no Backboardd class in backboardd.
And just for the future, use more popular tags for the questions like that. You have a better chance of getting an answer if you use jailbreak or iphone-privateapi tags.

What does it mean to write `static void * ptr = &ptr` in Objective-C

I am reading Apple's recently (Dec 5, 2013) updated sample code for camera control using AV Foundation (here is the link). And I come across the following lines in the file AVCamViewController.m which I don't understand.
static void * CapturingStillImageContext = &CapturingStillImageContext;
static void * RecordingContext = &RecordingContext;
static void * SessionRunningAndDeviceAuthorizedContext = &SessionRunningAndDeviceAuthorizedContext;
What does it mean to assign the pointer of itself? Why do we need this?
Update (2015-10-02): Now the AVCam is updated and rename to AVCam-iOS, if you are still insterest in this code AVCamViewController.m.
Well, so idea for these constants is to have some unique value, that will not repeat anywhere in the program, but we don't really care about its content.
Now, instead of coming up with some random string/number etc, we just create a pointer, and put its address as content, this way it's unique and the code is simple is nice :)

Use UUID as action parameters in Play Framework

I'd like to use UUID as action parameters. However, unless I use .toString() on the UUID objects when generating the action URL's, Play seems to serialize the object differently; Something like this: referenceId.sequence=-1&referenceId.hashCode=1728064460&referenceId.version=-1&referenceId.variant=-1&referenceId.timestamp=-1&referenceId.node=-1
However, using toString "works", but when I redirect from one action to another by simply invoking the method directly, there's no way I can call toString, as the method expects a UUID. Therefore it gives me the representation shown above.
Is there any way I can intersect the serialization of a certain type?
aren't you able to just use string in your action parameter? you know that this string is an UUID, so you can always recreate UUID from it. Maybe this is not the solution for you but that's my first thought. As far as I know play serializes objects like that when passing them trough paremeters.
If this does not work for you try finding something here: http://www.playframework.org/documentation/1.2.4/controllers
I found a way to do this, but right now it means hacking a part of the frameworks code itself.
What you basically need is a TypeBinder for binding the value from the String to the UUID
and a small code change in
play/framework/src/play/data/binding/Unbinder.java
if (!isAsAnnotation) {
// We want to use that one so when redirecting it looks ok. We could as well use the DateBinder.ISO8601 but the url looks terrible
if (Calendar.class.isAssignableFrom(src.getClass())) {
result.put(name, new SimpleDateFormat(I18N.getDateFormat()).format(((Calendar) src).getTime()));
} else {
result.put(name, new SimpleDateFormat(I18N.getDateFormat()).format((Date) src));
}
}
}
//here's the changed code
else if (UUID.class.isAssignableFrom(src.getClass()))
{
result.put(name, src.toString());
}
else {
// this code is responsible for the behavior you're seeing right now
Field[] fields = src.getClass().getDeclaredFields();
for (Field field : fields) {
if ((field.getModifiers() & BeanWrapper.notwritableField) != 0) {
// skip fields that cannot be bound by BeanWrapper
continue;
}
I'm working with the framework authors on a fix for this. will come back later with results.
if you need this urgently, apply the change to the code yourself and rebuild the framework by issuing
ant
in the playframework/framework
directory.

Dynamic/Anonymous type, returning anonymous types!

this is not a question as i think its discussion, i know you cant return an anonymous type across methods, when i first used anonymous types i thought it would be really nice to be able to return it across methods and when .net 4 came out and with the edition of the dynamic types i thought there might be a hope in returning an anonymous type through dynamic type like this:
public static dynamic getCustomer()
{
.....
var x = from c in customers
select new {Fname = c.FirstName};
return x;
}
and then
static void Main(string[] args)
{
dynamic x = getCustomer();
Console.WriteLine(x.First().Fname);
Console.ReadKey();
}
but sadly that doesnt work although it compile good,
i guess the reason why is :
Anonymous types known in compile type and must be wrapped into classes that is KNOWN IN RUNTIME !, now anonymous type carry thier information in the compile time hoping some class will come and take this information to runtime , but dynamic type are unkown in compile time so passing anonymous type through dynamic type force the anonymous type to loss its informations/intellisence, i tried to debug and i could get the data i wanted but i guess it works only in debug mode , or maybe im missing something.
i was wondering if any one got it to work or thought about it ?
You can return an anonymous type, you just can't declare that you'll do so. You can get round it with a horrible hack.
The reason your code doesn't work is nothing to do with anonymous types - it's to do with extension methods not being found in dynamic typing.
Change to:
Console.WriteLine(Enumerable.First(x).Fname);
and I expect it will work.

How to check an object's type in C++/CLI?

Is there a simple way to check the type of an object? I need something along the following lines:
MyObject^ mo = gcnew MyObject();
Object^ o = mo;
if( o->GetType() == MyObject )
{
// Do somethine with the object
}
else
{
// Try something else
}
At the moment I'm using nested try-catch blocks looking for System::InvalidCastExceptions which feels ugly but works. I was going to try and profile something like the code above to see if it's any faster/slower/readable but can't work out the syntax to even try.
In case anyone's wondering, this comes from having a single queue entering a thread which supplied data to work on. Occasionally I want to change settings and passing them in via the data queue is a simple way of doing so.
You can use MyObject::typeid in C++/CLI the same way as typeof(MyObject) is used in C#. Code below shamelessly copied from your question and modified ...
MyObject^ mo = gcnew MyObject();
Object^ o = mo;
if( o->GetType() == MyObject::typeid )
{
// Do somethine with the object
}
else
{
// Try something else
}
You should check out How to: Implement is and as C# Keywords in C++:
This topic shows how to implement the functionality of the is and as C# keywords in Visual C++.
edit: I will leave this here. But this answer is for C++. Probably not even slightly related to doing this for the CLI.
You need to compile with RTTI(Run Time Type Information) on. Then look at the wikipedia article http://en.wikipedia.org/wiki/Run-time_type_information and search google for RTTI. Should work for you.
On the other hand you might want to have a virtual base class for all your data classes with a member variable that describes what type it is.