Calling COM Methods using Microsoft Detours - hook

I am trying to hook compile method of the jscript.dll located in C:\Windows\System32 which is the core of Internet Explorer Javascript Engine.
The code work fine for API Calls for example RegOpenKeyExW which is reponsible to read registery values.
But when I try to use COleScript::Compile in jscript.dll it get me an error.
this is my Code:
FunctionHook* CompileFunExWHook = new FunctionHook();
CompileFunExWHook->Identifier = "COleScript::Compile";
CompileFunExWHook->Module = "jscript.dll";
CompileFunExWHook->Detour = (PBYTE)MyRegOpenKeyExW;
HookManager::Instance()->CreateHook(CompileFunExWHook);
pOriginalRegOpenKeyExW = (pRegOpenKeyExW)(HookManager::Instance()- >GetHook("COleScript::Compile")->DetourAddress);

Related

How to use pystemd to control systemd timedated ntp service?

I'm working on a python app that needs to get the NTPSynchronized parameter from system-timedated. I'd also like to be able to start and stop the NTP service by using the SetNTP method.
To communicate with timedated over d-bus I have been using this as reference: https://www.freedesktop.org/wiki/Software/systemd/timedated/
I previously got this working with dbus-python, but have since learned that this library has been deprecated. I tried the dbus_next package, but that does not have support for Python 3.5, which I need.
I came across the pystemd package, but I am unsure if this can be used to do what I want. The only documentation I have been able to find is this example (https://github.com/facebookincubator/pystemd), but I can not figure out how to use this to work with system-timedated.
Here is the code I have that works with dbus-python:
import dbus
BUS_NAME = 'org.freedesktop.timedate1`
IFACE = 'org.freedesktop.timedate1`
bus = dbus.SystemBus()
timedate_obj = bus.get_object(BUS_NAME, '/org/freedesktop/timedate1')
# Get synchronization value
is_sync = timedate_obj.Get(BUS_NAME, 'NTPSynchronized', dbus_interface=dbus.PROPERTIES_IFACE)
# Turn off NTP
timedate_obj.SetNTP(False,False, dbus_interface=IFACE)
Here's what I have so far with pystemd, but I don't think I'm accessing it in the right way:
from pystemd.systemd1 import Unit
unit = Unit(b'systemd-timesyncd.service')
unit.load()
# Try to access properties
prop = unit.Properties
prop.NTPSynchronized
Running that I get:
Attribute Error: 'SDInterface' object has no attribute 'NTPSynchronized'
I have a feeling that either the service I entered is wrong, or the way I'm accessing properties is wrong, or even both are wrong.
Any help or advice is appreciated.
Looking at the source code, it appears that using the pystemd.systemd1 Unit object has a default destination of "org.freedesktop.systemd1" + the service name (https://github.com/facebookincubator/pystemd/blob/master/pystemd/systemd1/unit.py)
This is not what I want because I am trying to access "org.freedesktop.timedate1"
So instead I instantiated it's base class SDObject from pystemd.base (https://github.com/facebookincubator/pystemd/blob/master/pystemd/base.py)
The following code allowed me to get the sync status of NTP
from pystemd.base import SDObject
obj = SDObject(
destination=b'org.freedesktop.timedate1',
path=b'/org/freedesktop/timedate1',
bus=None,
_autoload=False
)
obj.load()
is_sync = obj.Properties.Get('org.freedesktop.timedate1','NTPSynchronized')
print(is_sync)
Not sure if this is what the library author intended, but hey it works!

COMException^ on FilePicker PickSingleFileAsync() call

I'm trying to make a game (Universal DX11 application) and at some point I need access to image library to allow user to select avatar. But for some reason call of PickSingleFileAsync on picker rises an exception.
Windows::Storage::Pickers::FileOpenPicker^ openPicker = ref new Windows::Storage::Pickers::FileOpenPicker();
openPicker->SuggestedStartLocation = Windows::Storage::Pickers::PickerLocationId::PicturesLibrary;
openPicker->ViewMode = Windows::Storage::Pickers::PickerViewMode::Thumbnail;
// Filter to include a sample subset of file types.
auto filters = openPicker->FileTypeFilter;
filters->Clear();
filters->Append(".png");
openPicker->PickSingleFileAsync();// same exception with create_task(...);
Seems like the sample works only if I put it into UI thread. How can I use picker from my own thread?
UPD: HRESULT:0x80004005
Ok, I just decided to call dipatcher's RunAsync to execute this code. But I still have no idea why I cannot open picker inside non-UI thread.

JavaScript Library XPages

I currently have JavaScript dotted around my XPages - I would like to create a JavaScript library containing all this code and then just call the individual functions e.g. the press of a button. Here is an example of the code I would like in the JavaScript library:
// get the user document for that person
var myView:NotesView = database.getView("xpBenutzerInnen");
var query = new java.util.Vector();
query.addElement(sessionScope.notesName);
var myDoc:NotesDocument = myView.getDocumentByKey(query, true);
When I place this code in the library I get the error:
Syntax error on token ":", ; expected
I assume that the "var name:type" declaration is specific to XPages (this is what I found on creating JavaScript vars: http://www.w3schools.com/js/js_variables.asp) - I could just remove the type declaration and the code seems to run without any problems - I would like to better define the variable type though.
Is there any way that I can move the code out of the XPage but still keeping my typing?
Thanking you in advance
Ursus
You need to distinguish between client side JavaScript and Server side JavaScript. Your code is server side JS and should work in a Script library just as it does inside an XPage. Have you accidentally created a client side JS lib?
A few pointers: I try to make functions in a script library independent from global objects. Mostly the database object. This function works in a library just fine:
function getUserDocument(username:string, db:database) {
var myView:NotesView = db.getView("xpBenutzerInnen");
var query = new java.util.Vector();
query.addElement(username);
var myDoc:NotesDocument = myView.getDocumentByKey(query, true);
myView.recycle();
return myDoc;
}
Let me know how it goes

WASAPI - trouble with CoCreateInstance method

I am trying to capture audio from the mic using the windows core audio APIs
The relevant lines of code are
const CLSID CLSID_MMDeviceEnumerator = __uuidof(MMDeviceEnumerator);
const IID IID_IMMDeviceEnumerator = __uuidof(IMMDeviceEnumerator);
IMMDeviceEnumerator *pEnumerator = NULL;
hr = CoCreateInstance(CLSID_MMDeviceEnumerator,NULL,CLSCTX_ALL,IID_IMMDeviceEnumerator, (void**)&pEnumerator);
hr returns the following value-
0x800401f0 : CoInitialize has not been called.
I have adapted the sample program from the msdn page - Capturing an audio stream
What could be wrong? Also I don't understand what the error means - from the descriptions I got from Google search and all.
I am using Visual studio 2012 express on Win7 Home Pro x64.
Isn't the error message clear enough? You need to call CoInitialize before calling CoCreateInstance (or using COM in any other way).

Monotouch/iPhone - Call to HttpWebRequest.GetRequestStream() connects to server when HTTP Method is DELETE

My Scenario:
I am using Monotouch for iOS to create an iPhone app. I am calling ASP.NEt MVC 4 Web API based http services to login/log off. For Login, i use the POST webmethod and all's well. For Logoff, i am calling the Delete web method. I want to pass JSON data (serialized complex data) to the Delete call. If i pass simple data like a single string parameter as part of the URL itself, then all's well i.e. Delete does work! In order to pass the complex Json Data, here's my call (i have adjusted code to make it simple by showing just one parameter - UserName being sent via JSON):
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://localhost/module/api/session/");
req.ContentType = "application/json";
req.CookieContainer = jar;
req.Method = "Delete";
using (var streamWrite = new StreamWriter(req.GetRequestStream()))
{
string jSON = "{\"UserName\":\"" + "someone" + "\"}";
streamWrite.Write(jSON);
streamWrite.Close();
}
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
on the server, the Delete method looks has this definition:
public void Delete(Credentials user)
where Credentials is a complex type.
Now, here's the issue!
The above code, gets into the Delete method on the server as soon as it hits:
req.GetRequestStream()
And hence the parameter sent to the Delete method ends up being null
And here's the weird part:
If i use the exact same code using a test VS 2010 windows application, even the above code works...i.e it does not call Delete until req.GetResponse() is called! And in this scenario, the parameter to the Delete method is a valid object!
QUESTION
Any ideas or Is this a bug with Monotouch, if so, any workaround?
NOTE:
if i change the Delete definition to public void Delete(string userName)
and instead of json, if i pass the parameter as part of the url itself, all's well. But like i said this is just a simplified example to illustrate my issue. Any help is appreciated!!!
This seems to be ill-defined. See this question for more details: Is an entity body allowed for an HTTP DELETE request?
In general MonoTouch (based on Mono) will try to be feature/bug compatible with the Microsoft .NET framework to ease code portability between platforms.
IOW if MS.NET ignores the body of a DELETE method then so will MonoTouch. If the behaviour differs then a bug report should be filled at http://bugzilla.xamarin.com

Resources