fede.97 (Normal User)
Newbie
Messaggi: 7
Iscritto: 29/11/2012
|
Salve a tutti, sono nuovo al C e avrei un problemino con un codice trovato sulla rete per una applicazione nativa.
Io ho i due file
Native.c
Codice sorgente - presumibilmente Delphi |
//====================================================================== // // Native.c // // Mark Russinovich // http://www.ntinternals.com // // This is a demonstration of a Native NT program. These programs // run outside of the Win32 environment and must rely on the raw // services provided by NTDLL.DLL. AUTOCHK (the program that executes // a chkdsk activity during the system boot) is an example of a // native NT application. // // This example is a native 'hello world' program. When installed with // the regedit file associated with it, you will see it print // "hello world" on the initialization blue screen during the system // boot. This program cannot be run from inside the Win32 environment. // //====================================================================== #include "ntddk.h" // include this for its native functions and defn's #include "stdio.h" #include "native.h" // // Our heap // HANDLE Heap; //---------------------------------------------------------------------- // // NtProcessStartup // // Instead of a 'main' or 'winmain', NT applications are entered via // this entry point. // //---------------------------------------------------------------------- void NtProcessStartup( PSTARTUP_ARGUMENT Argument ) { PUNICODE_STRING commandLine; PWCHAR stringBuffer, argPtr; UNICODE_STRING helloWorld; RTL_HEAP_DEFINITION heapParams; // // Initialize some heap // memset( &heapParams, 0, sizeof( RTL_HEAP_DEFINITION )); heapParams.Length = sizeof( RTL_HEAP_DEFINITION ); Heap = RtlCreateHeap() 2, 0, 0x100000, 0x1000, 0, &heapParams ); // // Point at command line // commandLine = &Argument->Environment->CommandLine; // // Locate the argument // argPtr = commandLine->Buffer; while( *argPtr != L' ' ) argPtr++; argPtr++; // // Print out the argument // stringBuffer = RtlAllocateHeap( Heap, 0, 256 ); swprintf( stringBuffer, L"\n%s", argPtr ); helloWorld.Buffer = stringBuffer; helloWorld.Length = wcslen( stringBuffer ) * sizeof(WCHAR); helloWorld.MaximumLength = helloWorld.Length + sizeof(WCHAR); NtDisplayString( &helloWorld ); // // Free heap // RtlFreeHeap( Heap, 0, stringBuffer ); // // Terminate // // COMMENTO NtTerminateProcess( NtCurrentProcess(), 0 ); }
|
Native.h
Codice sorgente - presumibilmente Delphi |
//====================================================================== // // Native.h // // Mark Russinovich // http://www.ntinternals.com // // This file includes the definitions required by the Native.exe sample // NT native program to do what it does. // //====================================================================== // // Environment information, which includes command line and // image file name // typedef struct { ULONG Unknown[21]; UNICODE_STRING CommandLine; UNICODE_STRING ImageFile; } ENVIRONMENT_INFORMATION, *PENVIRONMENT_INFORMATION; // // This structure is passed as NtProcessStartup's parameter // typedef struct { ULONG Unknown[3]; PENVIRONMENT_INFORMATION Environment; } STARTUP_ARGUMENT, *PSTARTUP_ARGUMENT; // // Data structure for heap definition. This includes various // sizing parameters and callback routines, which, if left NULL, // result in default behavior // typedef struct { ULONG Length; ULONG Unknown[11]; } RTL_HEAP_DEFINITION, *PRTL_HEAP_DEFINITION; // // Native NT api function to write something to the boot-time // blue screen // NTSTATUS NTAPI NtDisplayString( PUNICODE_STRING String ); // // Native applications must kill themselves when done - the job // of this native API // NTSTATUS NTAPI NtTerminateProcess( HANDLE ProcessHandle, LONG ExitStatus ); // // Definition to represent current process // #define NtCurrentProcess() ( (HANDLE) -1 ) // // Heap creation routine // HANDLE NTAPI RtlCreateHeap( ULONG Flags, PVOID BaseAddress, ULONG SizeToReserve, ULONG SizeToCommit, PVOID Unknown, PRTL_HEAP_DEFINITION Definition ); // // Heap allocation function (ala "malloc") // PVOID NTAPI RtlAllocateHeap( HANDLE Heap, ULONG Flags, ULONG Size ); // // Heap free function (ala "free") // BOOLEAN NTAPI RtlFreeHeap( HANDLE Heap, ULONG Flags, PVOID Address );
|
Il problema si verifica quando vado a compilare, codeblocks mi restituisce:
Codice sorgente - presumibilmente C/C++ |
error: invalid conversion from `void*' to `WCHAR*'
|
Aiutino? |
|
Bonny (Member)
Expert
Messaggi: 437
Iscritto: 24/04/2009
|
Nel file Native.c alla riga 55 siamo sicuri che questa istruzione vada scritta cosi:
Codice sorgente - presumibilmente Plain Text |
while( *argPtr != L' ' ) argPtr++;
|
penso che vada scritta cosi:
Codice sorgente - presumibilmente Plain Text |
while( *argPtr != 'L' ) argPtr++;
|
Ultima modifica effettuata da Bonny il 30/11/2012 alle 11:17 |
|
fede.97 (Normal User)
Newbie
Messaggi: 7
Iscritto: 29/11/2012
|
Postato originariamente da Bonny:
Nel file Native.c alla riga 55 siamo sicuri che questa istruzione vada scritta cosi:
Codice sorgente - presumibilmente Plain Text |
while( *argPtr != L' ' ) argPtr++;
|
penso che vada scritta cosi:
Codice sorgente - presumibilmente Plain Text |
while( *argPtr != 'L' ) argPtr++;
|
|
Grazie, intanto ho corretto , purtroppo però l'errore non era quello. |
|
Bonny (Member)
Expert
Messaggi: 437
Iscritto: 24/04/2009
|
Scusa ma il compilatore non ti dice anche la riga in qui si trova l'errore?
postala grazie
|
|
Bonny (Member)
Expert
Messaggi: 437
Iscritto: 24/04/2009
|
Anche a riga 61 c'è un errore di sintassi
Codice sorgente - presumibilmente Plain Text |
swprintf( stringBuffer, L"\n%s", argPtr );
|
Ultima modifica effettuata da Bonny il 30/11/2012 alle 14:56 |
|
fede.97 (Normal User)
Newbie
Messaggi: 7
Iscritto: 29/11/2012
|
Certo che mi dice la riga! Che stupido a non postarla!
Riga 60
Per l'errore: Non lo vedo, dove mancherebbe la virgola?
|
|
Bonny (Member)
Expert
Messaggi: 437
Iscritto: 24/04/2009
|
Cioè il secondo parametro non mi sembra scritto bene
Codice sorgente - presumibilmente Plain Text |
swprintf( stringBuffer, L"\n%s", argPtr );
|
|
|
Bonny (Member)
Expert
Messaggi: 437
Iscritto: 24/04/2009
|
in riga 60 prova a sostituire con questo:
Codice sorgente - presumibilmente Plain Text |
stringBuffer = (WCHAR *) RtlAllocateHeap( Heap, 0, 256 );
|
|
|
fede.97 (Normal User)
Newbie
Messaggi: 7
Iscritto: 29/11/2012
|
Vuoi che ci arrivi da solo per il parametro, giusto?
Ho sostituito ed ora il debug restituisce
Codice sorgente - presumibilmente Delphi |
NATIVE.C||undefined reference to `_Z13RtlCreateHeapmPvmmS_P19RTL_HEAP_DEFINITION@24'| NATIVE.C||undefined reference to `_Z15RtlAllocateHeapPvmm@12'| NATIVE.C||undefined reference to `_Z15NtDisplayStringP15_UNICODE_STRING@4'| NATIVE.C||undefined reference to `_Z11RtlFreeHeapPvmS_@12'| NATIVE.C||undefined reference to `_Z18NtTerminateProcessPvl@8'| main.c||undefined reference to `WinMain@16'| ||=== Build finished: 6 errors, 0 warnings ===|
|
Ora devo studiare, dopo vedo di lavorarci per provare a risolvere da solo. Probabilmente sarò ancora qui a chiedere aiuto...
|
|