Delphi code to C++ conversation

Hi

I have a piece of code and I want to convert it to C++ code, is there autometed tool to do it?

I paste my function here, maybe some one can do that manually or with autometed tool, so please advice about it, I don't know too much about Delphi.

Thanks
var
  bytesIO, c: DWORD;
  sp1: KSERVICE_PTR;
begin
  result := false;
  ZwQuerySystemInformation(SystemModuleInformation, @kmodule, sizeof(kmodule), @bytesIO);
 
  DeviceIoControl(DriverHandle, IOPORT_GET_KERNEL_SDT_INFO, nil, 0, @sdt1, sizeof(SERVICE_DESCRIPTOR_ENTRY), bytesIO, nil);
  CurrentTable := VirtualAlloc(nil, sdt1.NumberOfServices * sizeof(PVOID), MEM_COMMIT, PAGE_READWRITE);
  OrigTable := VirtualAlloc(nil, sdt1.NumberOfServices * sizeof(PVOID), MEM_COMMIT, PAGE_READWRITE);
 
  DumpOrigSDT();
  DeviceIoControl(DriverHandle, IOPORT_READ_KERNEL_SDT, nil, 0, CurrentTable, sdt1.NumberOfServices * sizeof(PVOID), bytesIO, nil);
  DumpExports(ntdll);
 
  for c := 0 to sdt1.NumberOfServices - 1 do
    dec(CurrentTable^[c], DWORD(kmodule.moduleinfo.Base));
 
  if (uhall) then
  begin
    for c := 0 to sdt1.NumberOfServices - 1 do
      if (CurrentTable^[c] <> OrigTable^[c]) then
      begin
        sp1.dwServiceNumber := c;
        sp1.dwServiceEntryPoint := pointer(OrigTable^[c] + DWORD(kmodule.moduleinfo.Base));
        result := DeviceIoControl(DriverHandle, IOPORT_WRITE_KERNEL_SDT, @sp1, sizeof(KSERVICE_PTR), nil, 0, bytesIO, nil);
      end;
  end
  else
  begin
    for c := 0 to sdt1.NumberOfServices - 1 do
      if (CurrentTable^[c] <> OrigTable^[c]) and (c = ServiceNumber) then
      begin
        sp1.dwServiceNumber := c;
        sp1.dwServiceEntryPoint := pointer(OrigTable^[c] + DWORD(kmodule.moduleinfo.Base));
        result := DeviceIoControl(DriverHandle, IOPORT_WRITE_KERNEL_SDT, @sp1, sizeof(KSERVICE_PTR), nil, 0, bytesIO, nil);
      end;
  end;
  VirtualFree(CurrentTable, 0, MEM_RELEASE);
  VirtualFree(OrigTable, 0, MEM_RELEASE);

Open in new window

LVL 17
CSecurityAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Geert GOracle dbaCommented:
variable declarations are missing :

kmodule
DriverHandle
sdt1
CurrentTable
OrigTable
c
uhall
0
Dagan HooverDeveloperCommented:
kmodule:
SystemBasicInformation

The number of processors in the system in a SYSTEM_BASIC_INFORMATION structure. Use the GetSystemInfo function instead.

----------------------------------------------------------------

DriverHandle will be a DWORD

----------------------------------------------------------------

sdt1: Im guessings its a SERVICE_DESCRIPTOR_ENTRY structure

----------------------------------------------------------------

CurrentTable and OrigTable: pointer or pchar

----------------------------------------------------------------

c is defined already as a dword

----------------------------------------------------------------

uhall is a boolean
0
CSecurityAuthor Commented:
Exactly! ThievingSix is completely right
0
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

CSecurityAuthor Commented:
Entire code is attached
Test.txt
0
CSecurityAuthor Commented:
But I want only that part of code I sent, to be translated into C++ lang

Thanks once again
0
Dagan HooverDeveloperCommented:
Here's my fun little go at it. Please, don't burn you're eyes looking at my c++ code, I usually translate the other way around. Maybe it can help if no one else has a better translation.
typedef struct {
	DWORD dwServiceNumber;
	LPVOID dwServiceEntryPoint;
} _KSERVICE_PTR;
 
typedef _KSERVICE_PTR KSERVICE_PTR;
typedef _KSERVICE_PTR* PKSERVICE_PTR
 
typedef struct {
	unsigned long modulescount;
	SYSTEM_MODULE_INFORMATION moduleinfo;
} infobuffer;
 
typedef struct {
	PVOID* ServiceTableBase;
	PVOID* ServiceCounterTableBase;
	DWORD NumberOfServices;
	unsigned char * ParamTableBase;
} SERVICE_DESCRIPTOR_ENTRY
 
 
bool UnHook(DWORD ServiceNumber, BOOL uHall);
{
	BOOL Result = FALSE;
	DWORD BytesIO;
	DWORD C;
	KSERVICE_PTR sp1;
	DWORD DriverHandle;
	infobuffer kmodule;
	SERVICE_DESCRIPTOR_ENTRY sdt1;
	char* CurrentTable;
	char* OrigTable;
 
	ZwQuerySystemInformation(SystemModuleInformation,&kmodule,sizeof(kmodule),&bytesIO);
	DeviceIOControl(DriverHandle,IOPORT_GET_KERNEL_SDT_INFO,NULL,0,&sdt1,sizeof(SERVICE_DESCRIPTOR_ENTRY),bytesIO,NULL);
	CurrentTable = VirtualAlloc(NULL,sdt1.NumberOfServices * sizeof(PVOID),MEM_COMMIT,PAGE_READWRITE);
	OrigTable = VirtualAlloc(NULL,sdt1.NumberOfServices * sizeof(PVOID),MEM_COMMIT,PAGE_READWRITE);
	DumpOrigDT();
	DeviceIOControl(DriverHandle,IOPORT_READ_KERNEL_SDT,NULL,0,CurrentTable,sdt1.NumberOfServices * sizeof(PVOID),bytesIO,NULL);
	DumpExports(ntdll);
	for(c=0,c<sdt1.NumberOfServices,c++)
	{
		CurrentTable[c] -= DWORD(kmodule.modultinfo.base);
	}
	if(uhall) 
	{
		for(c=0,c<sdt1.NumberOfServices,c++)
		{
			if(CurrentTable[c] != OrigTable[c])
			{
				sp1.dwServiceNumber = c;
				sp1.dwServiceEntryPoint = LPVOID(OrigTable[c] + DWORD(kmodule.moduleinfo.Base));
				Result = DeviceIOControl(DriverHandle,IOPORT_WRITE_KERNEL_SDT,&sp1,sizeof(KSERVICE_PTR),NULL,0,bytesIO,NULL);
			}
		}
	}
	else
	{
		for(c=0,c<sdt1.NumberOfServices,c++)
		{
			if((CurrentTable[c] != OrigTable[c]) && (c == ServiceNumber))
			{
				sp1.dwServiceNumber = c;
				sp1.dwServiceEntryPoint = LPVOID(OrigTable[c] + DWORD(kmodule.moduleinfo.Base));
				Result = DeviceIOControl(DriverHandle,IOPORT_WRITE_KERNEL_SDT,&sp1,sizeof(KSERVICE_PTR),NULL,0,bytesIO,NULL);
			}
		}
	}
	VirtualFree(CurrentTable,0,MEM_RELEASE);
	VirtualFree(OrigTable,0,MEM_RELEASE);
 
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CSecurityAuthor Commented:
Thank you so much, is it possible for you to convert DumpOrigDT(), without that I wasn't able to test the code.

Thank you so much for your work
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.