How to hook according WMI function in fastprox.dll? - hook

Below is a block of C# code , I want to hook (ms-detours) the enumerating part:
var wql=new WqlObjectQuery(queryString);
using(var searcher =new ManagementObjectSearcher(scope,wql))
{
using(var records=searcher.Get())
{
**foreach(var record in records)** //This is where I want to hook
{
//do something
}
}
}
I don't know which function in fastprox.dll is the one to hook.
I've tried ?Get#CWbemObject##UEAAJPEBGJPEAUtagVARIANT##PEAJ2#Z , it could be hooked ,while it is not the one to enumerate ojbect.
Could anyone help ?

Related

In Xamarin azure, UpdateAsync is not updating database, only changes info locally

So my app updates the information inside locally when i call UpdateSync on the table but it doesn't update the online database? Am I doing something wrong?
IMobileServiceSyncTable<Models.About_user> about_user_table;
Update_my_table(Object Item)
{
Models.About_user About_user = (Models.About_user)Item;
await about_user_table.UpdateAsync(About_user);
IMobileServiceSyncTable<Models.About_user> about_user_table;
}
So All I had to is put that on the bottom of my updatesync. Note: this didnt work unless I explicitly had a variable in my about_user model called version like [JsonProperty(PropertyName = "Version")]
public string Version { get; set; }
await about_user_table.UpdateAsync(About_user);
try
{
await Client.SyncContext.PushAsync();
/// await about_user_table.PullAsync("all About_user", about_user_table.CreateQuery());
}
catch (MobileServicePushFailedException ex)
{
if (ex.PushResult != null)
{
foreach (var error in ex.PushResult.Errors)
{
await ResolveConflictAsync(error,"about_user_table");
}
}
}
async Task ResolveConflictAsync(MobileServiceTableOperationError error, string table_name)
{
var serverItem = error.Result.ToObject<About_user>();
var localItem = error.Item.ToObject<About_user>();
// Note that you need to implement the public override Equals(TodoItem item)
// method in the Model for this to work
if (serverItem.Equals(localItem))
{
// Items are the same, so ignore the conflict
await error.CancelAndDiscardItemAsync();
return;
}
// Client Always Wins
localItem.Version = serverItem.Version;
await error.UpdateOperationAsync(JObject.FromObject(localItem));
}
According to your code, you are using the sync table (IMobileServiceSyncTable), for the UpdateAsync operation, it would update your local SQLite database. In order to update your online database, you need to execute the Push operation by using the following code:
await Client.SyncContext.PushAsync();
Note: when executing the push operation, you may need to handle Conflict Resolution. For more details, you could refer to adrian's book about Handling Conflict Resolution and An Offline Client.
Moreover, you could use client.GetTable<Model>() for constructing an online table and do CUD changes against your online table. For more details, you could refer to here. Additionally, you could follow here about offline synchronization.

Meteor: Creating a collections: Reference Error when debug in chrome console

I follow a tutorial with Meteor I try to create a collection, both for client and server. Here is my code:
var lists = new Meteor.Collection("Lists");
if (Meteor.isClient) {
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
}
As tutorial I have read, when run on server, if I open chrome console and type lists I will receive Meteor.Collection. But when I tried on my machine, I received error:
Reference error. lists is not define
Have I done something wrong? Please tell me.
Thanks :)
Also you can put all your collections inside the /lib/collection.js route (for better practices).
So with that we ensure that meteor loads first the collections, and they will be available on both client/server.
you should remove Autopublish/insecure package, to avoid meteor sends all the collections when load and to control who can or not insert/remove/update on the collections.
meteor remove autopublish
meteor remove insecure.
So a simple collection will look like this.
//lib/collection.js
Example = new Mongo.Collection("Example") //we create collection global
if(Meteor.isClient) {
Meteor.subscribe('Example') //we subscribe both after meteor loads client and server folders
}
now on /server/collections.js
Meteor.publish('Example', function(){
return Example.find(); //here you can control whatever you want to send to the client, you can change the return to just return Example.find({}, {fields: {stuff: 1}});
});
// Here we control the security of the collections.
Example.allow({
insert: function(userId, doc) {
if(Meteor.userId()){
return true; //if the user is connected he can insert
} else{
return false// not connected no insert
}
},
update: function(userId, doc, fields, modifier) { //other validation },
remove: function(userId, doc) { //other validation },
});
Just to try to explain a little more deep the Collection here on meteor, hope it help you GL
I think you have autopulish/autosubscribe turned off. Try
if (Meteor.isClient) {
Meteor.subscribe('lists');
}
if (Meteor.isServer){
Meteor.publish('lists',function(){
return Lists.find();
});
}
For your naming, I'd also recommend you reverse the way you're capitalizing your collections. So instead it would be
var Lists = new Meteor.Collection("lists");
And finally, look at https://github.com/matteodem/meteor-boilerplate for your directory structure so you don't have to do the if meteor.is stuff anymore.
Edit
Full code should look like:
var Lists = new Meteor.Collection("lists");
if (Meteor.isClient) {
Meteor.subscribe('lists');
}
if (Meteor.isServer){
Meteor.publish('lists',function(){
return Lists.find();
});
}
All of your script source files are wrapped in a function closure as part of the build process. In order for your collection to be visible outside of that file (or in your case - attached to the window object) you will need to declare it as a global variable:
Lists = new Meteor.Collection('lists');
Note the lack of var. As #thatgibbyguy pointed out, the accepted pattern is to capitalize collection variables, and camelcase collection names.

Passing an async object to dustjs template

I have a hard time understanding how to pass an object fetched from a database to a dust.js template.
Let's say I have a template:
{#person}
{name} - {title}
{/person}
I try to setup a context something like this:
var ctx = {
person: return chunk.map(function(chunk) {
database.person(12345, function(data) {
dust.nextTick(function() {
chunk.end(data); // What to really do here?
});
});
});
}
Where database.person fetches the object from a database and passes it to a callback.
And then I would run the render function:
res.render('person', ctx);
The correct form was:
var ctx = {
person: function(chunk, context, bodies) {
return chunk.map(function(chunk) {
database.person(1234, function(data) {
return chunk.render(bodies.block, context.push(data)).end();
});
});
}
}
Instead of write I had to call render as in Alan's answer.
The whole db call had to be enclosed in the return chunk.map call to work. I also had to chain an end command to send the results back to the stream.
Why these calls are needed is told in the dust.js guide (http://akdubya.github.io/dustjs/#guide):
chunk.map tells Dust to manufacture a new chunk, reserving a slot in
the output stream before continuing on to render the rest of the
template. You must (eventually) call chunk.end() on a mapped chunk to
weave its content back into the stream.
This is something that isn't addressed in the LinkedIn guide pages.
I'm assuming your db call will return something along the lines of a json object such as the "data" below.
The async code looks ok. chunk.write will just write out whatever you give it so you need to pass your data in on the context so it can be accessed in the template. Use chunk.render instead of write. A non-async example would be :
{
"person": function(chunk, context, bodies) {
var data = {name:"Smith", title:"Mr"};
return chunk.render(bodies.block, context.push(data));
}
}
Running that through linkedin dust tests seems to get the right answer.
Hope that helps,
Alan

RequireJS module for SignalR

Rather than copy and pasting my code onto here, I have uploaded it to github. The RequireJS module does have a dependency on jquery.signalr and in tern has a dependency on jquery but also have a dependency on the javascript held in /signalr/hubs. There is a bit of config to do with Require.Config.
Basically what is happening is on the first time you load the page the connection is made to the hubs within signalr and the "server side" code is executed and does the desired thing. When you refresh the page it does not. All client side code is called, so for example:
var myViewModel = new MyViewMode();
myViewModel.init();
and within your init method you have
var connection = $.connection.myHub;
this.init = function() {
connection.server.myMethod();
}
this would then go off to
public MyHub : Hub
{
public void MyMethod()
{
Client.Request.populateSomeInformation() // I think it's request but I'm doing this from memory!
}
}
and then call
connection.client.populateSomeInformation = function () { .. )
but doesn't call this :(
It looks like a connection has been made (using the good old console.log() to see what it outputs) and indeed debugging the project it executes the code within the hub but there is no response made back to the javascript.
So wonderful people of the internet, where am I going wrong? Do I need to check the state of $.connection.hub.start(); before attempting to start it again?
Time for beer :)
I believe it should be
connection.client.populateSomeInformation = function () { .. )
(not connection.server)
http://www.asp.net/signalr/overview/hubs-api/hubs-api-guide-javascript-client#callclient
(observations on the code you have on github right now)
var isLoaded = false;
// ... some code that doesn't change isLoaded ...
if (isLoaded == false) {
scrollIntervalId = window.setInterval(function () {
signalRLoaded();
}, 30);
}
I think isLoaded will always be false at this point. Not sure what you intended this to accomplish.
var connection = $.connection.hub.start();
I don't think you're supposed to open the connection before defining any client functions. I don't see any client functions being defined here, so maybe you're doing that somewhere else? I don't know if it really matters other than if the server attempts to call a client function that hasn't yet been defined...
function SignalRReady(callback) {
if (isLoaded) {
callback(connection);
} else {
readyCalls = callback;
}
return SignalRReady;
}
SignalRReady.version = "1.0.0";
SignalRReady.load = function(name, request, onLoad, config) {
if (config.isBuild) {
onLoad();
} else {
SignalRReady(onLoad);
}
};
return SignalRReady;
I'm confused by this bit of code, probably because I don't see how it's being used. Is this an attempt at a kind of singleton? I see that SignalRReady is the "class" being returned for the module. You're not really returning an object, you're returning a constructor which implies that you're instantiating it in other places, something like
define(['SignalRReady'], function(sigR)
{
var srr = new sigR();
});
But then you have that load function defined that calls the constructor and makes this look all weird. How are you using this?
Anyways, I'm thinking you might be hitting some kind of race condition where the client function may not always be available at the time the server is trying to call it.
(additional comments/code 2013-09-06)
Your connection object is actually a jQuery promise ( http://api.jquery.com/category/deferred-object/ ).
If you're unfamiliar with promises, think of them generically as a queue of callbacks to be executed later. In this case, when connected, all the callbacks will be executed (in the order they were added). If a callback is added after being connected, it will get executed immediately. This is how your code is working now. You add the callback to the .done queue after the connection is made and is executed immediately.
If you insist on creating the connection object yourself, then you do not need to use the stateChanged event. You just add the callback to the .done queue:
define(function()
{
function signalRReady(callback)
{
if (window.connection == undefined) {
window.connection = $.connection.hub.start();
}
window.connection.done(callback);
}
signalRReady.version = "1.0.0";
return signalRReady;
});
However, I believe it's not a good idea to initiate the connection yourself. Because your module isn't a complete wrapper around SignalR such that people would only use your module to do SignalR stuff, you are not guaranteed (and cannot expect) other code will not initiate the connection. Especially if someone is adding your module to an existing codebase.
Your module is simply adding a new event, so keep it simple. Take the callback and execute it yourself when appropriate:
define(function()
{
function signalRReady(callback)
{
$.connection.hub.stateChanged(function (state)
{
if(state.newState === $.signalR.connectionState.connected)
{
callback();
}
});
}
signalRReady.version = "1.0.0";
return signalRReady;
});
Nowadays, promises are pretty popular. You might want to implement a promise-based module like:
define(function()
{
var deferred = $.Deferred();
$.connection.hub.stateChanged(function (state)
{
if(state.newState === $.signalR.connectionState.connected)
{
// executes all callbacks attached by the "ready" function below
deferred.resolve();
}
});
return {
ready: function(callback)
{
deferred.done(callback);
},
version: "1.0.0"
};
});
If callbacks are attached after the connection has been made, they are executed immediately.
Also, notice this example module's init function returns an object instead of a function. Since RequireJS will pass the same instance around to any module that requires it, state is maintained - we can use local variables instead of global.

How can I use threading in MonoDroid such that it will be cross platform compatible with MonoTocuh

Specifically when doing MonoDroid uses of threads all the documentation I can find recommends calling RunOnUiThread() to call the callback. There is a similar function that can be used on MonoTouch however both of them require a GUI (Activity or whatever its counter part is on IOS). What I would like is to be able to start a thread, pass in a callback and call that callback on the thread that started the thread. For example
ThreadPool.QueueUserWorkItem(state =>
{
//Do Stuff
execute_callback_magically_on_main_thread(() => callback(response));
});
Any ideas? To be clear I would prefer this to not need a handle to the Activity etc.
What if you do something like this? (assuming they have the same signature) I haven't messed with RunOnUiThread, so I don't know it's signature.
public delegate void InvokeOnUIMethod(Action action);
public void CallingMethod()
{
//iOS
MyMethod(InvokeOnMainThread, () => { /* Your callback functionality */ });
//Android
MyMethod(RunOnUiThread, () => { /* Your callback functionality */ });
}
public void MyMethod(InvokeOnUIMethod execute_callback_magically_on_main_thread, Action callback)
{
System.Threading.ThreadPool.QueueUserWorkItem(state =>
{
//Do Stuff
execute_callback_magically_on_main_thread(() => callback(response));
});
}
I hope this helps.
Using the Alpha builds (Hopefully soon to be available as stable) you can use the new Async await idiom.
here is an overview on MSDN:
http://msdn.microsoft.com/en-gb/library/vstudio/hh191443.aspx
and here is a great video series on Channel9:
http://channel9.msdn.com/Series/Three-Essential-Tips-for-Async/Tip-1-Async-void-is-for-top-level-event-handlers-only
I found a solution that works and does not appear to be dependent on either platform.
Task<string> t = new Task<string>(() =>
{
//Do Stuff
return "my results";
});
t.ContinueWith(task =>{
if(callback != null)
callback(task.Result);
}, TaskScheduler.FromCurrentSynchronizationContext());
t.Start();
The important part is the TaskScheduler.FromCurrentSynchronizationContext() which tells the "ContinueWith" to execute on the original thread.

Resources