Programmatically installing unsigned driver with CreateService - windows

I am trying to install an unsigned driver that I got from an older embedded solution (winxp embedded), that I am currently reversing. I am installing and setting up the driver like the software does, however, with the driver being unsigned, I am unable to install it, at least programmatically.
Installation code:
std::cout << "Installing driver from " << this->driverPath << std::endl;
SC_HANDLE scManager = OpenSCManagerA(0, 0, 0xF003F);
if (!scManager) {
std::cout << "Failed to open SCManager" << std::endl;
return;
}
SC_HANDLE hService = CreateServiceA(scManager, this->serviceName, this->serviceName, 0xF01FF, 1, 3, 1, this->driverPath, 0, 0, 0, 0, 0);
if (!hService) {
hService = OpenServiceA(scManager, this->serviceName, 0xF01FF);
if (!hService) {
std::cout << "error: " << std::to_string(GetLastError()) << std::endl;
CloseServiceHandle(scManager);
return;
}
else {
std::cout << "OK!" << std::endl;
}
}
if (!StartServiceA(hService, 0, 0)) {
std::cout << "StartService failed: " << std::to_string(GetLastError()) << std::endl;
return;
}
The command line output based on this is as follows:
Installing driver from C:\driver.sys
OK!
StartService failed: 1275
The error code is that of ERROR_DRIVER_BLOCKED. I tried to force Windows to allow me to install this after all by going into advanced startup and disabling signature enforcement, but the only effect was that Windows no longer gave me a separate OS window telling me it blocked driver installation.
I have tried the three methods described here, without any luck: https://www.maketecheasier.com/install-unsigned-drivers-windows10/
(However, I assume these are made for users hand-installing the drivers).
How can I tell Windows to allow me to programmatically install this unsigned driver?

The driver was 32-bit, the system was 64-bit. Using a 32-bit system solves this.

Related

"No Devices connected" with PCL1.6 and Primesense Camera (Carmine 1.09)

I am using primesense camera for a project which has device driver indicating Carmine 1.09 (installed from OpenNI folder). When I am running OpenNI2's viewer, you can see the depth data coming through so the camera is definitely connected.
However, when I am running a project using PCL, it just kept throwing an error exception saying "no devices connected". I tried many different version of primesense (i.e. https://github.com/jspricke/openni-sensor-primesense), but still not helping.
Here is where the problem occurs. Wherever there is a pcl:: command, it will try to throw this exception.
try {
if (!pcl::OpenNIGrabber().getDevice())
{
std::cout << "No device is found!" << std::endl;
return;
}
else
{
std::cout << "Device is found!" << std::endl;
pcl::Grabber* grabber = new pcl::OpenNIGrabber();
}
}
catch (const pcl::PCLIOException& ex)
{
std::cout << ex.what() << std::endl;
return;
}
catch(const char* msg)
{
std::cout << msg << std::endl;
return;
}
FYI. I'm currently using Windows8.1 64 bit, but the projects are all running 32 bits, with PCL 1.6 and OpenNI 1.5.4 (I tried the patched version as well).
Does anybody know a solution to this?

Opencl function found deprecated by Visual Studio

I am getting started with opencl in VS using this tutorial:
https://opencl.codeplex.com/wikipage?title=OpenCL%20Tutorials%20-%201
I am having trouble with setting up the host program. This is the code so far:
const char* clewErrorString(cl_int error) {
//stuff
}
int main(int argc, char **argv) {
cl_int errcode_ret;
cl_uint num_entries;
// Platform
cl_platform_id platforms;
cl_uint num_platforms;
num_entries = 1;
cout << "Getting platform id..." << endl;
errcode_ret = clGetPlatformIDs(num_entries, &platforms, &num_platforms);
if (errcode_ret != CL_SUCCESS) {
cout << "Error getting platform id: " << clewErrorString(errcode_ret) << endl;
exit(errcode_ret);
}
cout << "Success!" << endl;
// Device
cl_device_type device_type = CL_DEVICE_TYPE_GPU;
num_entries = 1;
cl_device_id devices;
cl_uint num_devices;
cout << "Getting device id..." << endl;
errcode_ret = clGetDeviceIDs(platforms, device_type, num_entries, &devices, &num_devices);
if (errcode_ret != CL_SUCCESS) {
cout << "Error getting device id: " << clewErrorString(errcode_ret) << endl;
exit(errcode_ret);
}
cout << "Success!" << endl;
// Context
cl_context context;
cout << "Creating context..." << endl;
context = clCreateContext(0, num_devices, &devices, NULL, NULL, &errcode_ret);
if (errcode_ret < 0) {
cout << "Error creating context: " << clewErrorString(errcode_ret) << endl;
exit(errcode_ret);
}
cout << "Success!" << endl;
// Command-queue
cl_command_queue queue;
cout << "Creating command queue..." << endl;
queue = clCreateCommandQueue(context, devices, 0, &errcode_ret);
if (errcode_ret != CL_SUCCESS) {
cout << "Error creating command queue: " << clewErrorString(errcode_ret) << endl;
exit(errcode_ret);
}
cout << "Success!" << endl;
return 0;
}
This doesn't compile, though: I get an error C4996: 'clCreateCommandQueue': was declared deprecated when i try to compile. I don't understand the whole setup process as of yet, so I don't know if I have messed up something or not. According to chronos, the function doesn't seem to be deprecated though:
https://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/clCreateCommandQueue.html
If I remove the command queue part, the rest runs without problems. How can I make this work?
The clCreateCommandQueue function was deprecated as of OpenCL 2.0, and replaced with clCreateCommandQueueWithProperties. If you are only targeting devices that support OpenCL 2.0 (some recent Intel and AMD processors at the time of writing), you can safely use this new function.
If you need your code to run on devices that don't yet support OpenCL 2.0, you can continue using the deprecated clCreateCommandQueue function by using the preprocessor macros that the OpenCL headers provide, e.g:
#define CL_USE_DEPRECATED_OPENCL_1_2_APIS
#include <CL/cl.h>

Fast Loopback Socket Windows 8 machine

I currently searching for some performance problems in our distributed multiprocess application!
Thats the reason I would like to try fast loopback sockets
SIO_LOOPBACK_FAST_PATH descreption and msdn desc.
here is my code fragment for opening server socket:
TcpipSocket::TcpipSocket(FullIPAddress const& address)
: m_Port(address.m_Port)
, m_IPAddress(address.m_Address)
, m_Socket(INVALID_SOCKET)
{
if (0 == ms_NumberOfInstances)
{
initNetwork(NULL); // here i call the WSAStartup function
}
m_Socket = ::socket(TCPSocketFamily, TCPSocketType, TCPProtocol);
if (INVALID_SOCKET == m_Socket)
{
throwException(ConstrName);
}
else
{
// this is the code to enable the FAST Loopback Sockets see [1]
int OptionValue =1;
DWORD NumberOfBytesReturned =0;
int status=::WSAIoctl(m_Socket,
SIO_LOOPBACK_FAST_PATH,
&OptionValue,
sizeof(OptionValue),
NULL,
0,
&NumberOfBytesReturned,
0,
0);
if (SOCKET_ERROR == status)
{
DWORD LastError = ::WSAGetLastError();
if (WSAEOPNOTSUPP == LastError)
{
std::ostringstream out;
out << "This system is not Windows Windows Server 2012/Windows 8, \n";
out << "and the call is not supported.\n";
out << "ErrorNumber: "<< LastError;
throwException(out.str().c_str());
}
else
{
std::ostringstream out;
out << "TcpipSocket::Loopback Fastpath WSAIoctl failed: ";
out << "\nErrorNumber: "<< LastError;
throwException(out.str().c_str());
}
}
}
}
The problem: I always receive the error WSAEOPNOTSUPP
running the example on Windows 8 64 bit with all updates..
What did I miss? regarding the example, it should work straight forward?
The code is written on a win 7 x64 with VS2012
I using the Platform toolset "Visual Studio 2012 (v110)"

Get a process executable name from process ID

I am currently trying to get the names of a list of programs whose pid I have.
The program is run as administrator, but GetModuleFileNameEx fails with error code 5.
I open the program with OpenProcess(PROCESS_TERMINATE,PROCESS_QUERY_INFORMATION) and I have the SE_DEBUG_PRIVILEGE enabled.
The process handle passed to GetModuleFileNameEx() requires PROCESS_QUERY_INFORMATION and PROCESS_VM_READ access rights.
This worked for me:
HANDLE h = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
FALSE,
6088);
if (0 == h)
{
std::cerr << "OpenProcess() failed: " << GetLastError() << "\n";
}
else
{
char exe_path[2048] = {};
if (GetModuleFileNameEx(h, 0, exe_path, sizeof(exe_path) - 1))
{
std::cout << exe_path << "\n";
}
else
{
std::cerr << "GetModuleFileNameEx() failed: " <<
GetLastError() << "\n";
}
CloseHandle(h);
}
However, as others have pointed out (and is also stated in documentation for GetModuleFileNameEx()) there are safer ways to acquire this information:
GetProcessImageFileName()
QueryFullProcessImageName()
According to this thread that error is returned when there's not enough information to return the filename.

SetCommState failing on Windows 7

We have code that talks to our USB COMM class device, which works fine under Windows XP but is failing under Windows 7. Specifically the call to SetCommState is failing. Here's a simplified snippet. Note that in this case we don't even change any fields from GetCommState, but the result is that SetCommState fails with an error code of 87 (illegal parameter).
DCB dcb;
SecureZeroMemory(&dcb, sizeof(DCB));
dcb.DCBlength = sizeof(DCB);
if (!GetCommState(m_hIDComDev, &dcb)) {
DWORD dwError = GetLastError();
CloseHandle(m_hIDComDev);
dlDebug(5, "SerialPort::openPort") << "GetCommState failed for" << m_portName << dwError;
return 0;
}
dlDebug(5, "SerialPort::openPort") << m_portName << "rate" << dcb.BaudRate << "size" << dcb.ByteSize;
// dcb.BaudRate = baud;
// dcb.ByteSize = 8;
if (!SetCommState(m_hIDComDev, &dcb)) {
DWORD dwError = GetLastError();
CloseHandle(m_hIDComDev);
dlDebug(5, "SerialPort::openPort") << "SetCommState failed for" << m_portName << dwError;
return 0;
}
Any ideas what might be going wrong? One thought is that the USB device descriptor is incorrect and Win7 is more rigorous about double-checking (but I'm a little skeptical about that as the device works fine under MacOS X and Linux with no issues). I'm stumped!
If you are working on 64 bit, maybe you have to set dcb.DCBLength not to sizeof(DCB) but to the next highest multiple of 8.

Resources