Porting pice. Added pe parsing in loader.

svn path=/trunk/; revision=2431
This commit is contained in:
Eugene Ingerman 2001-12-15 23:50:07 +00:00
parent a7d526433d
commit 3edb1beb95
5 changed files with 303 additions and 316 deletions

View file

@ -7,7 +7,7 @@ Module Name:
main.c main.c
Abstract: Abstract:
loader/translator for pIce LINUX loader/translator for pIce LINUX
Environment: Environment:
@ -22,7 +22,7 @@ Revision History:
04-Aug-1998: created 04-Aug-1998: created
15-Nov-2000: general cleanup of source files 15-Nov-2000: general cleanup of source files
Copyright notice: Copyright notice:
This file may be distributed under the terms of the GNU Public License. This file may be distributed under the terms of the GNU Public License.
@ -33,13 +33,8 @@ Copyright notice:
// includes // includes
#include "stdinc.h" #include "stdinc.h"
#include <linux/errno.h>
#include <asm/ioctl.h>
#include <sys/stat.h>
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
// constant defines // constant defines
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
@ -47,7 +42,7 @@ Copyright notice:
char SrcFileNames[2048][2048]; char SrcFileNames[2048][2048];
ULONG ulCurrentSrcFile = 0; ULONG ulCurrentSrcFile = 0;
int debugger_file; HANDLE debugger_file;
ULONG ulGlobalVerbose = 0; ULONG ulGlobalVerbose = 0;
@ -59,10 +54,10 @@ ULONG ulGlobalVerbose = 0;
void process_stabs( void process_stabs(
char* pExeName, // name of exe char* pExeName, // name of exe
int fileout, // symbol file handle int fileout, // symbol file handle
Elf32_Shdr* pSHdr, PIMAGE_SECTION_HEADER section, //Elf32_Shdr* pSHdr,
int nSHdrSize, int sectionHeadersSize, //int nSHdrSize,
void* p, // ptr to memory where whole exe was read void* p, // ptr to memory where whole exe was read
PSTAB_ENTRY pStab, // ptr to stabs PSTAB_ENTRY pStab, // ptr to stabs
int nStabLen, // size of stabs int nStabLen, // size of stabs
char* pStr, // ptr to stabs strings char* pStr, // ptr to stabs strings
int nStrLen, // sizeof stabs strings int nStrLen, // sizeof stabs strings
@ -71,7 +66,7 @@ void process_stabs(
char* pGlobalsStr, // ptr to global strings char* pGlobalsStr, // ptr to global strings
int nGlobalStrLen) // size of global strings int nGlobalStrLen) // size of global strings
{ {
int i,strLen; unsigned i,strLen;
int nOffset=0,nNextOffset=0; int nOffset=0,nNextOffset=0;
PSTAB_ENTRY pStabCopy = pStab; PSTAB_ENTRY pStabCopy = pStab;
char* pName,szCurrentPath[2048]; char* pName,szCurrentPath[2048];
@ -82,10 +77,11 @@ void process_stabs(
//printf("LOADER: enter process_stabs()\n"); //printf("LOADER: enter process_stabs()\n");
PICE_memset((void*)&SymbolFileHeader,0,sizeof(SymbolFileHeader)); //get the name of the executable file
memset((void*)&SymbolFileHeader,0,sizeof(SymbolFileHeader));
SymbolFileHeader.magic = PICE_MAGIC; SymbolFileHeader.magic = PICE_MAGIC;
PICE_strcpy(temp,pExeName); strcpy(temp,pExeName);
pSlash = strrchr(temp,'/'); pSlash = strrchr(temp,'\\');
pDot = strrchr(temp,'.'); pDot = strrchr(temp,'.');
if(pDot) if(pDot)
{ {
@ -95,7 +91,7 @@ void process_stabs(
{ {
pCopyExeName = pSlash+1; pCopyExeName = pSlash+1;
} }
PICE_strcpy(SymbolFileHeader.name,pCopyExeName); strcpy(SymbolFileHeader.name,pCopyExeName);
for(i=0;i<(nStabLen/sizeof(STAB_ENTRY));i++) for(i=0;i<(nStabLen/sizeof(STAB_ENTRY));i++)
{ {
@ -119,27 +115,27 @@ void process_stabs(
//printf("LOADER: changing string offset %x %x\n",nOffset,nNextOffset); //printf("LOADER: changing string offset %x %x\n",nOffset,nNextOffset);
break; break;
case N_SO: case N_SO:
if((strLen = PICE_strlen(pName))) if((strLen = strlen(pName)))
{ {
if(pName[strLen-1]!='/') if(pName[strLen-1]!='/')
{ {
if(strlen(szCurrentPath)) if(strlen(szCurrentPath))
{ {
//printf("LOADER: ###########################################################################\n"); //printf("LOADER: ###########################################################################\n");
PICE_strcat(szCurrentPath,pName); strcat(szCurrentPath,pName);
//printf("LOADER: changing source file %s\n",szCurrentPath); //printf("LOADER: changing source file %s\n",szCurrentPath);
PICE_strcpy(SrcFileNames[ulCurrentSrcFile++],szCurrentPath); strcpy(SrcFileNames[ulCurrentSrcFile++],szCurrentPath);
szCurrentPath[0]=0; szCurrentPath[0]=0;
} }
else else
{ {
//printf("LOADER: ###########################################################################\n"); //printf("LOADER: ###########################################################################\n");
//printf("LOADER: changing source file %s\n",pName); //printf("LOADER: changing source file %s\n",pName);
PICE_strcpy(SrcFileNames[ulCurrentSrcFile++],pName); strcpy(SrcFileNames[ulCurrentSrcFile++],pName);
} }
} }
else else
PICE_strcpy(szCurrentPath,pName); strcpy(szCurrentPath,pName);
} }
else else
{ {
@ -211,21 +207,20 @@ void process_stabs(
//printf("LOADER: SymbolFileHeader.ulSizeOfStabsStrings = %x (%x)\n",nStrLen,(LPSTR)pStr-(LPSTR)p); //printf("LOADER: SymbolFileHeader.ulSizeOfStabsStrings = %x (%x)\n",nStrLen,(LPSTR)pStr-(LPSTR)p);
SymbolFileHeader.ulOffsetToHeaders = sizeof(PICE_SYMBOLFILE_HEADER); SymbolFileHeader.ulOffsetToHeaders = sizeof(PICE_SYMBOLFILE_HEADER);
SymbolFileHeader.ulSizeOfHeader = nSHdrSize; SymbolFileHeader.ulSizeOfHeader = sectionHeadersSize;
SymbolFileHeader.ulOffsetToGlobals = sizeof(PICE_SYMBOLFILE_HEADER)+nSHdrSize; SymbolFileHeader.ulOffsetToGlobals = sizeof(PICE_SYMBOLFILE_HEADER)+sectionHeadersSize;
SymbolFileHeader.ulSizeOfGlobals = nGlobalLen; SymbolFileHeader.ulSizeOfGlobals = nGlobalLen;
SymbolFileHeader.ulOffsetToGlobalsStrings = sizeof(PICE_SYMBOLFILE_HEADER)+nSHdrSize+nGlobalLen; SymbolFileHeader.ulOffsetToGlobalsStrings = sizeof(PICE_SYMBOLFILE_HEADER)+sectionHeadersSize+nGlobalLen;
SymbolFileHeader.ulSizeOfGlobalsStrings = nGlobalStrLen; SymbolFileHeader.ulSizeOfGlobalsStrings = nGlobalStrLen;
SymbolFileHeader.ulOffsetToStabs = sizeof(PICE_SYMBOLFILE_HEADER)+nSHdrSize+nGlobalLen+nGlobalStrLen; SymbolFileHeader.ulOffsetToStabs = sizeof(PICE_SYMBOLFILE_HEADER)+sectionHeadersSize+nGlobalLen+nGlobalStrLen;
SymbolFileHeader.ulSizeOfStabs = nStabLen; SymbolFileHeader.ulSizeOfStabs = nStabLen;
SymbolFileHeader.ulOffsetToStabsStrings = sizeof(PICE_SYMBOLFILE_HEADER)+nSHdrSize+nGlobalLen+nGlobalStrLen+nStabLen; SymbolFileHeader.ulOffsetToStabsStrings = sizeof(PICE_SYMBOLFILE_HEADER)+sectionHeadersSize+nGlobalLen+nGlobalStrLen+nStabLen;
SymbolFileHeader.ulSizeOfStabsStrings = nStrLen; SymbolFileHeader.ulSizeOfStabsStrings = nStrLen;
SymbolFileHeader.ulOffsetToSrcFiles = sizeof(PICE_SYMBOLFILE_HEADER)+nSHdrSize+nGlobalLen+nGlobalStrLen+nStabLen+nStrLen; SymbolFileHeader.ulOffsetToSrcFiles = sizeof(PICE_SYMBOLFILE_HEADER)+sectionHeadersSize+nGlobalLen+nGlobalStrLen+nStabLen+nStrLen;
SymbolFileHeader.ulNumberOfSrcFiles = ulCurrentSrcFile; SymbolFileHeader.ulNumberOfSrcFiles = ulCurrentSrcFile;
write(fileout,&SymbolFileHeader,sizeof(SymbolFileHeader)); write(fileout,&SymbolFileHeader,sizeof(SymbolFileHeader));
write(fileout,section,sectionHeadersSize);
write(fileout,pSHdr,nSHdrSize);
write(fileout,pGlobals,nGlobalLen); write(fileout,pGlobals,nGlobalLen);
write(fileout,pGlobalsStr,nGlobalStrLen); write(fileout,pGlobalsStr,nGlobalStrLen);
write(fileout,pStab,nStabLen); write(fileout,pStab,nStabLen);
@ -237,18 +232,31 @@ void process_stabs(
int len; int len;
PVOID pFile; PVOID pFile;
PICE_SYMBOLFILE_SOURCE pss; PICE_SYMBOLFILE_SOURCE pss;
file = open(SrcFileNames[i],O_RDONLY); file = _open(SrcFileNames[i],O_RDONLY);
if( file <= 0 ){
//let's try win format drive:/file
char srctmp[2048];
strcpy(srctmp, SrcFileNames[i] );
if(strncmp(srctmp,"//",2)==0){
*(srctmp) = *(srctmp+2);
*(srctmp+1) = ':';
*(srctmp+2) = '/';
file = _open(srctmp,O_RDONLY);
if( file <= 0 )
printf("Can't open file: %s\n", srctmp );
}
}
if(file>0) if(file>0)
{ {
//printf("LOADER: [%u] opened %s as FD %x\n",i,SrcFileNames[i],file); //printf("LOADER: [%u] opened %s as FD %x\n",i,SrcFileNames[i],file);
len = lseek(file,0,SEEK_END); len = _lseek(file,0,SEEK_END);
//printf("LOADER: length = %x\n",(int)len); //printf("LOADER: length = %x\n",(int)len);
lseek(file,0,SEEK_SET);
PICE_strcpy(pss.filename,SrcFileNames[i]); _lseek(file,0,SEEK_SET);
strcpy(pss.filename,SrcFileNames[i]);
pss.ulOffsetToNext = len+sizeof(PICE_SYMBOLFILE_SOURCE); pss.ulOffsetToNext = len+sizeof(PICE_SYMBOLFILE_SOURCE);
pFile = malloc(len); pFile = malloc(len);
@ -256,15 +264,15 @@ void process_stabs(
if(pFile) if(pFile)
{ {
//printf("LOADER: reading file...\n"); //printf("LOADER: reading file...\n");
read(file,pFile,len); _read(file,pFile,len);
write(fileout,&pss,sizeof(PICE_SYMBOLFILE_SOURCE)); _write(fileout,&pss,sizeof(PICE_SYMBOLFILE_SOURCE));
//printf("LOADER: writing file...\n"); //printf("LOADER: writing file...\n");
write(fileout,pFile,len); _write(fileout,pFile,len);
free(pFile); free(pFile);
} }
close(file); _close(file);
} }
} }
@ -276,29 +284,28 @@ void process_stabs(
// find_stab_sections() // find_stab_sections()
// //
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
void find_stab_sections(void* p,Elf32_Shdr* pSHdr,PSTAB_ENTRY* ppStab,int* pLen,char** ppStr,int* pnStabStrLen,int num,int index) void find_stab_sections(void* p,PIMAGE_SECTION_HEADER section, unsigned cSections,
PSTAB_ENTRY* ppStab,int* pLen,char** ppStr,int* pnStabStrLen)
{ {
int i; unsigned i;
char* pStr = (char*)((int)p + pSHdr[index].sh_offset);
//printf("LOADER: enter find_stab_sections()\n"); //printf("LOADER: enter find_stab_sections()\n");
*ppStab = 0; *ppStab = 0;
*ppStr = 0; *ppStr = 0;
for(i=0;i<num;i++,pSHdr++)
for ( i=1; i <= cSections; i++, section++ )
{ {
int sh_name = pSHdr->sh_name;
//printf("LOADER: [%u] %32s %8x %8x %8x %8x %8x\n",i,&pStr[sh_name],pSHdr->sh_offset,pSHdr->sh_size,pSHdr->sh_addr,pSHdr->sh_type,pSHdr->sh_link); if(strcmp(section->Name,".stab") == 0)
if(PICE_strcmp(&pStr[sh_name],".stab") == 0)
{ {
*ppStab = (PSTAB_ENTRY)((int)p + pSHdr->sh_offset); *ppStab = (PSTAB_ENTRY)((int)p + section->PointerToRawData);
*pLen = pSHdr->sh_size; *pLen = section->SizeOfRawData;
//printf("LOADER: .stab @ %x (offset %x) len = %x\n",*ppStab,pSHdr->sh_offset,pSHdr->sh_size); printf("LOADER: .stab @ %x (offset %x) len = %x\n",*ppStab,section->PointerToRawData,section->SizeOfRawData);
} }
else if(PICE_strcmp(&pStr[sh_name],".stabstr") == 0) else if(strncmp(section->Name,".stabstr",strlen(".stabstr")) == 0)
{ {
*ppStr = (char*)((int)p + pSHdr->sh_offset); *ppStr = (char*)((int)p + section->PointerToRawData);
*pnStabStrLen = pSHdr->sh_size; *pnStabStrLen = section->SizeOfRawData;
//printf("LOADER: .stabstr @ %x (offset %x size=%u)\n",*ppStr,pSHdr->sh_offset,pSHdr->sh_size); printf("LOADER: .stabstr @ %x (offset %x) len = %x\n",*ppStab,section->PointerToRawData,section->SizeOfRawData);
} }
} }
@ -306,173 +313,114 @@ char* pStr = (char*)((int)p + pSHdr[index].sh_offset);
} }
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
// find_symtab() // process_pe()
// //
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
Elf32_Sym* find_symtab(void* p,Elf32_Shdr* pSHdrOrig,int num,int index,int* pLen,LPSTR* ppStr,int *pnSymStrLen) int process_pe(char* filename,int file,void* p,int len)
{ {
int i;
Elf32_Sym* pSym = NULL,*pSymOrig = NULL;
// char* pStr = (char*)((int)p + pSHdrOrig[index].sh_offset);
LPSTR pName;
ULONG ulSymTabEntries = 0,link=-1;
Elf32_Shdr* pSHdr;
//printf("LOADER: enter find_symtab()\n"); PIMAGE_DOS_HEADER pDosHeader;
PIMAGE_NT_HEADERS pNTHeaders;
// find global symbol table
pSHdr = pSHdrOrig;
for(i=0;i<num;i++,pSHdr++)
{
//int sh_name = pSHdr->sh_name;
//printf("LOADER: [%u] %32s %8x %8x %8x %8x %8x\n",i,pStr,pSHdr->sh_offset,pSHdr->sh_size,pSHdr->sh_addr,pSHdr->sh_type,pSHdr->sh_link);
if(pSHdr->sh_type == SHT_SYMTAB)
{
pSym = (Elf32_Sym*)((int)p+pSHdr->sh_offset);
//printf("LOADER: symbol table %u %x %u\n",i,pSHdr->sh_offset,pSHdr->sh_link);
ulSymTabEntries = pSHdr->sh_size;
link = pSHdr->sh_link;
}
}
if(link != (-1))
{
// find global string table
pSHdr = pSHdrOrig;
for(i=0;i<num;i++,pSHdr++)
{
//int sh_name = pSHdr->sh_name;
//printf("LOADER: [%u] %32s %8x %8x %8x %8x %8x\n",i,pStr,pSHdr->sh_offset,pSHdr->sh_size,pSHdr->sh_addr,pSHdr->sh_type,pSHdr->sh_link);
if(pSHdr->sh_type == SHT_STRTAB && i==link)
{
*ppStr = (LPSTR)((int)p+pSHdr->sh_offset);
*pnSymStrLen = pSHdr->sh_size;
}
}
if(*ppStr && pSym)
{
LPSTR pStr = *ppStr;
pSymOrig = pSym;
for(i=0;i<ulSymTabEntries/sizeof(Elf32_Sym);i++)
{
pName = &pStr[pSym->st_name];
//printf("LOADER: [%u] %32s %x %x %x %x\n",i,pName,pSym->st_name,pSym->st_value,pSym->st_info,pSym->st_other);
pSym++;
}
}
*pLen = ulSymTabEntries;
}
else
{
pSymOrig= NULL;
}
//printf("LOADER: leave find_symtab()\n");
return pSymOrig;
}
///////////////////////////////////////////////////////////////////////////////////
// process_elf()
//
///////////////////////////////////////////////////////////////////////////////////
int process_elf(char* filename,int file,void* p,int len)
{
Elf32_Ehdr* pEHdr =(Elf32_Ehdr*)p;
Elf32_Shdr* pSHdr;
char* pStr; char* pStr;
PSTAB_ENTRY pStab; PSTAB_ENTRY pStab;
int nStabLen,nSym; DWORD nStabLen,nSym;
LPSTR pStrTab; char* pStrTab;
Elf32_Sym* pSymTab; char* pSymTab;
char szSymName[2048]; char szSymName[2048];
int fileout; int fileout;
int nSymStrLen,nStabStrLen; int nSymStrLen,nStabStrLen;
int iRetVal = 0; int iRetVal = 0;
//printf("LOADER: enter process_elf()\n"); pDosHeader = (PIMAGE_DOS_HEADER)p;
if(strncmp(pEHdr->e_ident,"\177ELF",4) == 0) // is ELF binary magic pNTHeaders = (PIMAGE_NT_HEADERS)((DWORD)p + pDosHeader->e_lfanew);
if ((pDosHeader->e_magic == IMAGE_DOS_SIGNATURE)
&& (pDosHeader->e_lfanew != 0L)
&& (pNTHeaders->Signature == IMAGE_NT_SIGNATURE))
{ {
pSHdr = (Elf32_Shdr*)((int)p+pEHdr->e_shoff); if( pNTHeaders->FileHeader.PointerToSymbolTable ){
//printf("LOADER: Section header @ %x (offset %x)\n",pSHdr,pEHdr->e_shoff);
//printf("LOADER: %u entries\n",pEHdr->e_shnum); pSymTab = (char*)((DWORD)p + pNTHeaders->FileHeader.PointerToSymbolTable);
//printf("LOADER: string table index %u\n",pEHdr->e_shstrndx); nSym = pNTHeaders->FileHeader.NumberOfSymbols;
if((pSymTab = find_symtab(p,pSHdr,pEHdr->e_shnum,pEHdr->e_shstrndx,&nSym,&pStrTab,&nSymStrLen)) != NULL ) //string table follows immediately after symbol table. first 4 bytes give the length of the table
{ //references to string table include the first 4 bytes.
find_stab_sections(p,pSHdr,&pStab,&nStabLen,&pStr,&nStabStrLen,pEHdr->e_shnum,pEHdr->e_shstrndx); pStrTab = (PIMAGE_SYMBOL)pSymTab + nSym;
nSymStrLen = *((DWORD*)pStrTab);
find_stab_sections(p,IMAGE_FIRST_SECTION(pNTHeaders),pNTHeaders->FileHeader.NumberOfSections,
&pStab,&nStabLen,&pStr,&nStabStrLen);
if(pStab && nStabLen && pStr && nStabStrLen) if(pStab && nStabLen && pStr && nStabStrLen)
{ {
LPSTR pDot; LPSTR pDot;
PICE_strcpy(szSymName,filename); strcpy(szSymName,filename);
//printf("LOADER: file name = %s\n",szSymName); //printf("LOADER: file name = %s\n",szSymName);
if((pDot = strrchr(szSymName,'.'))) if((pDot = strrchr(szSymName,'.')))
{ {
*pDot = 0; *pDot = 0;
PICE_strcat(pDot,".sym"); strcat(pDot,".pice");
} }
else else
{ {
PICE_strcat(szSymName,".sym"); strcat(szSymName,".pice");
} }
//printf("LOADER: symbol file name = %s\n",szSymName); //printf("LOADER: symbol file name = %s\n",szSymName);
printf("LOADER: creating symbol file %s for %s\n",szSymName,filename); printf("LOADER: creating symbol file %s for %s\n",szSymName,filename);
fileout = creat(szSymName,S_IRUSR|S_IWUSR); // make r/w for owner fileout = _creat(szSymName, _S_IREAD | _S_IWRITE ); // make r/w
if(fileout != -1) if(fileout != -1)
{ {
process_stabs(szSymName, process_stabs(szSymName,
fileout, fileout,
pSHdr, IMAGE_FIRST_SECTION(pNTHeaders),
pEHdr->e_shnum*sizeof(Elf32_Shdr), pNTHeaders->FileHeader.NumberOfSections*sizeof(PIMAGE_SECTION_HEADER),
p, p,
pStab, pStab,
nStabLen, nStabLen,
pStr, pStr,
nStabStrLen, nStabStrLen,
(LPSTR)pSymTab, (char*)pSymTab,
nSym, nSym,
pStrTab, pStrTab,
nSymStrLen); nSymStrLen);
close(fileout); close(fileout);
} }
else else
{ {
printf("LOADER: creation of symbol file %s failed\n",szSymName); printf("LOADER: creation of symbol file %s failed\n",szSymName);
iRetVal = 2; iRetVal = 2;
} }
} }
else else
{ {
printf("LOADER: file %s has no data inside symbol tables\n",filename); printf("LOADER: file %s has no data inside symbol tables\n",filename);
if( ulGlobalVerbose ) if( ulGlobalVerbose )
{ {
if( !pStab || !nStabLen ) if( !pStab || !nStabLen )
printf("LOADER: - symbol table is empty or not present\n"); printf("LOADER: - symbol table is empty or not present\n");
if( !pStr || !nStabStrLen ) if( !pStr || !nStabStrLen )
printf("LOADER: - string table is empty or not present\n"); printf("LOADER: - string table is empty or not present\n");
} }
iRetVal = 2; iRetVal = 2;
} }
} }
else else{
{ printf("LOADER: file %s does not have a symbol table\n",filename);
printf("LOADER: file %s does not have a symbol table\n",filename);
iRetVal = 2; iRetVal = 2;
} }
} }
else else
{ {
printf("LOADER: file %s is not an ELF binary\n",filename); printf("LOADER: file %s is not an ELF binary\n",filename);
iRetVal = 1; iRetVal = 1;
} }
//printf("LOADER: leave process_elf()\n"); //printf("LOADER: leave process_pe()\n");
return iRetVal; return iRetVal;
} }
@ -488,30 +436,29 @@ int process_file(char* filename)
int iRetVal=0; int iRetVal=0;
//printf("LOADER: enter process_file()\n"); //printf("LOADER: enter process_file()\n");
file = open(filename,O_RDONLY); file = _open(filename,O_RDONLY|_O_BINARY);
if(file>0) if(file>0)
{ {
//printf("LOADER: opened %s as FD %x\n",filename,file); //printf("LOADER: opened %s as FD %x\n",filename,file);
len = lseek(file,0,SEEK_END); len = _lseek(file,0,SEEK_END);
printf("LOADER: file %s is %u bytes\n",filename,(int)len); printf("LOADER: file %s is %u bytes\n",filename,(int)len);
lseek(file,0,SEEK_SET); _lseek(file,0,SEEK_SET);
p = malloc(len+16); p = malloc(len+16);
if(p) if(p)
{ {
long count;
//printf("LOADER: malloc'd @ %x\n",p); //printf("LOADER: malloc'd @ %x\n",p);
PICE_memset(p,0,len+16); memset(p,0,len+16);
if(len == (count = _read(file,p,len)))
if(len == read(file,p,len))
{ {
//printf("LOADER: trying ELF format\n"); //printf("LOADER: trying ELF format\n");
iRetVal = process_elf(filename,file,p,len); iRetVal = process_pe(filename,file,p,len);
} }
} }
_close(file);
close(file);
} }
else else
{ {
@ -527,12 +474,12 @@ int process_file(char* filename)
// open_debugger() // open_debugger()
// //
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
int open_debugger(void) HANDLE open_debugger(void)
{ {
debugger_file = open("/dev/pice0",O_RDONLY); debugger_file = CreateFile("\\Device\\Pice",GENERIC_READ,0,NULL,OPEN_EXISTING,NULL,NULL);
if(debugger_file<0) if(debugger_file == INVALID_HANDLE_VALUE)
{ {
printf("LOADER: debugger is not loaded\n"); printf("LOADER: debugger is not loaded. Last Error: %ld\n", GetLastError());
} }
return debugger_file; return debugger_file;
@ -544,7 +491,24 @@ int open_debugger(void)
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
void close_debugger(void) void close_debugger(void)
{ {
close(debugger_file); if( !CloseHandle(debugger_file) ){
printf("Error closing debugger handle: %ld\n", GetLastError());
}
}
int ioctl( HANDLE device, DWORD ioctrlcode, PDEBUGGER_STATUS_BLOCK psb)
{
DEBUGGER_STATUS_BLOCK tsb;
DWORD bytesreturned;
if( !DeviceIoControl( device, ioctrlcode, psb, sizeof(DEBUGGER_STATUS_BLOCK),
&tsb, sizeof(DEBUGGER_STATUS_BLOCK),&bytesreturned, NULL) ){
printf("Error in DeviceIoControl: %ld\n", GetLastError());
return -EINVAL;
}
else{
memcpy( psb, &tsb, sizeof(DEBUGGER_STATUS_BLOCK) );
}
return 0;
} }
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
@ -576,28 +540,31 @@ void banner(void)
void change_symbols(int action,char* pfilename) void change_symbols(int action,char* pfilename)
{ {
int iRetVal = 0; int iRetVal = 0;
DEBUGGER_STATUS_BLOCK sb;
strcpy(sb.filename, pfilename);
switch(action) switch(action)
{ {
case ACTION_LOAD: case ACTION_LOAD:
printf("LOADER: loading symbols from %s\n",pfilename); printf("LOADER: loading symbols from %s\n",pfilename);
if(open_debugger()>=0) if(open_debugger() != INVALID_HANDLE_VALUE)
{ {
iRetVal = ioctl(debugger_file,PICE_IOCTL_LOAD,pfilename); iRetVal = ioctl(debugger_file,PICE_IOCTL_LOAD,&sb);
close_debugger(); close_debugger();
} }
break; break;
case ACTION_UNLOAD: case ACTION_UNLOAD:
printf("LOADER: unloading symbols from %s\n",pfilename); printf("LOADER: unloading symbols from %s\n",pfilename);
if(open_debugger()>=0) if(open_debugger() != INVALID_HANDLE_VALUE)
{ {
iRetVal = ioctl(debugger_file,PICE_IOCTL_UNLOAD,pfilename); iRetVal = ioctl(debugger_file,PICE_IOCTL_UNLOAD,&sb);
close_debugger(); close_debugger();
} }
break; break;
case ACTION_RELOAD: case ACTION_RELOAD:
printf("LOADER: reloading all symbols\n"); printf("LOADER: reloading all symbols\n");
if(open_debugger()>=0) if(open_debugger() != INVALID_HANDLE_VALUE)
{ {
ioctl(debugger_file,PICE_IOCTL_RELOAD,NULL); ioctl(debugger_file,PICE_IOCTL_RELOAD,NULL);
close_debugger(); close_debugger();
@ -607,7 +574,7 @@ void change_symbols(int action,char* pfilename)
default : default :
printf("LOADER: an internal error has occurred at change_symbols\n"); printf("LOADER: an internal error has occurred at change_symbols\n");
} }
switch( iRetVal ) switch( iRetVal )
{ {
case -EINVAL : case -EINVAL :
@ -621,6 +588,8 @@ void change_symbols(int action,char* pfilename)
} }
} }
// Dynamic install to be added later
#if 0
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
// tryinstall() // tryinstall()
// //
@ -630,11 +599,11 @@ int tryinstall(void)
char *argv[]={"/sbin/insmod","pice.o",NULL}; char *argv[]={"/sbin/insmod","pice.o",NULL};
int err = 0; int err = 0;
int pid,status; int pid,status;
banner(); banner();
printf("LOADER: trying to install debugger...\n"); printf("LOADER: trying to install debugger...\n");
if(!(open_debugger() < 0) ) if( open_debugger() != INVALID_HANDLE_VALUE )
{ {
printf("LOADER: debugger already installed...\n"); printf("LOADER: debugger already installed...\n");
close_debugger(); close_debugger();
@ -651,7 +620,7 @@ int tryinstall(void)
printf("LOADER: fork failed for execution of '%s' (errno = %u).\n",argv[0],err); printf("LOADER: fork failed for execution of '%s' (errno = %u).\n",argv[0],err);
break; break;
case 0: case 0:
// child process handler // child process handler
execve(argv[0],argv,NULL); execve(argv[0],argv,NULL);
// returns only on error, with return value -1, errno is set // returns only on error, with return value -1, errno is set
printf("LOADER: couldn't execute '%s' (errno = %u)\n",argv[0],errno); printf("LOADER: couldn't execute '%s' (errno = %u)\n",argv[0],errno);
@ -680,7 +649,7 @@ int tryinstall(void)
} }
break; break;
} }
return err; return err;
} }
@ -693,12 +662,12 @@ int tryuninstall(void)
char *argv[]={"/sbin/rmmod","pice",NULL}; char *argv[]={"/sbin/rmmod","pice",NULL};
int err = 0; int err = 0;
int pid,status; int pid,status;
banner(); banner();
printf("LOADER: trying to remove debugger...\n"); printf("LOADER: trying to remove debugger...\n");
// check for loaded debugger // check for loaded debugger
if(open_debugger() < 0) if(open_debugger() == INVALID_HANDLE_VALUE)
{ {
return -1; return -1;
} }
@ -715,7 +684,7 @@ int tryuninstall(void)
printf("LOADER: fork failed for execution of '%s' (errno=%u).\n",argv[0],err); printf("LOADER: fork failed for execution of '%s' (errno=%u).\n",argv[0],err);
break; break;
case 0: case 0:
// child process handler // child process handler
execve(argv[0],argv,NULL); execve(argv[0],argv,NULL);
// returns only on error, with return value -1, errno is set // returns only on error, with return value -1, errno is set
printf("LOADER: couldn't execute '%s' (errno = %u)\n",argv[0],errno); printf("LOADER: couldn't execute '%s' (errno = %u)\n",argv[0],errno);
@ -725,7 +694,7 @@ int tryuninstall(void)
// parent process handler // parent process handler
printf("LOADER: waiting for debugger to unload...\n"); printf("LOADER: waiting for debugger to unload...\n");
pid = waitpid(pid, &status, 0); // suspend until child is done pid = waitpid(pid, &status, 0); // suspend until child is done
if( (pid>0) && WIFEXITED(status) && (WEXITSTATUS(status) == 0) ) if( (pid>0) && WIFEXITED(status) && (WEXITSTATUS(status) == 0) )
printf("LOADER: debugger removed!\n"); printf("LOADER: debugger removed!\n");
else if( pid<=0 ) else if( pid<=0 )
@ -747,6 +716,7 @@ int tryuninstall(void)
} }
return err; return err;
} }
#endif
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
// showstatus() // showstatus()
@ -757,12 +727,11 @@ void showstatus(void)
DEBUGGER_STATUS_BLOCK sb; DEBUGGER_STATUS_BLOCK sb;
int iRetVal; int iRetVal;
if(open_debugger()>=0) if(open_debugger() != INVALID_HANDLE_VALUE)
{ {
sb.Test = 0;
iRetVal = ioctl(debugger_file,PICE_IOCTL_STATUS,&sb); iRetVal = ioctl(debugger_file,PICE_IOCTL_STATUS,&sb);
printf("LOADER: Test = %X\n",sb.Test); //printf("LOADER: Test = %X\n",sb.Test);
close_debugger(); close_debugger();
} }
} }
@ -775,10 +744,9 @@ void dobreak(void)
{ {
int iRetVal; int iRetVal;
if(open_debugger()>=0) if(open_debugger() != INVALID_HANDLE_VALUE)
{ {
iRetVal = ioctl(debugger_file,PICE_IOCTL_BREAK,NULL); iRetVal = ioctl(debugger_file,PICE_IOCTL_BREAK,NULL);
close_debugger(); close_debugger();
} }
} }
@ -787,6 +755,7 @@ void dobreak(void)
// doterminal() // doterminal()
// //
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
#if 0
void doterminal(void) void doterminal(void)
{ {
if(SetupSerial(2,B115200)) if(SetupSerial(2,B115200))
@ -795,6 +764,7 @@ void doterminal(void)
CloseSerial(); CloseSerial();
} }
} }
#endif
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
// process_switches() // process_switches()
@ -816,46 +786,46 @@ int process_switches(int argc,char* argv[])
if(*parg == '-') if(*parg == '-')
{ {
int new_action=ACTION_NONE; int new_action=ACTION_NONE;
parg++; parg++;
if(PICE_strcmp(parg,"load")==0 || PICE_strcmp(parg,"l")==0) if(strcmp(parg,"load")==0 || strcmp(parg,"l")==0)
{ {
new_action = ACTION_LOAD; new_action = ACTION_LOAD;
} }
else if(PICE_strcmp(parg,"unload")==0 || PICE_strcmp(parg,"u")==0) else if(strcmp(parg,"unload")==0 || strcmp(parg,"u")==0)
{ {
new_action = ACTION_UNLOAD; new_action = ACTION_UNLOAD;
} }
else if(PICE_strcmp(parg,"trans")==0 || PICE_strcmp(parg,"t")==0) else if(strcmp(parg,"trans")==0 || strcmp(parg,"t")==0)
{ {
new_action = ACTION_TRANS; new_action = ACTION_TRANS;
} }
else if(PICE_strcmp(parg,"reload")==0 || PICE_strcmp(parg,"r")==0) else if(strcmp(parg,"reload")==0 || strcmp(parg,"r")==0)
{ {
new_action = ACTION_RELOAD; new_action = ACTION_RELOAD;
} }
else if(PICE_strcmp(parg,"verbose")==0 || PICE_strcmp(parg,"v")==0) else if(strcmp(parg,"verbose")==0 || strcmp(parg,"v")==0)
{ {
if( ulGlobalVerbose+1 > ulGlobalVerbose ) if( ulGlobalVerbose+1 > ulGlobalVerbose )
ulGlobalVerbose++; ulGlobalVerbose++;
} }
else if(PICE_strcmp(parg,"install")==0 || PICE_strcmp(parg,"i")==0) else if(strcmp(parg,"install")==0 || strcmp(parg,"i")==0)
{ {
new_action = ACTION_INSTALL; new_action = ACTION_INSTALL;
} }
else if(PICE_strcmp(parg,"uninstall")==0 || PICE_strcmp(parg,"x")==0) else if(strcmp(parg,"uninstall")==0 || strcmp(parg,"x")==0)
{ {
new_action = ACTION_UNINSTALL; new_action = ACTION_UNINSTALL;
} }
else if(PICE_strcmp(parg,"status")==0 || PICE_strcmp(parg,"s")==0) else if(strcmp(parg,"status")==0 || strcmp(parg,"s")==0)
{ {
new_action = ACTION_STATUS; new_action = ACTION_STATUS;
} }
else if(PICE_strcmp(parg,"break")==0 || PICE_strcmp(parg,"b")==0) else if(strcmp(parg,"break")==0 || strcmp(parg,"b")==0)
{ {
new_action = ACTION_BREAK; new_action = ACTION_BREAK;
} }
else if(PICE_strcmp(parg,"serial")==0 || PICE_strcmp(parg,"ser")==0) else if(strcmp(parg,"serial")==0 || strcmp(parg,"ser")==0)
{ {
new_action = ACTION_TERMINAL; new_action = ACTION_TERMINAL;
} }
@ -865,28 +835,28 @@ int process_switches(int argc,char* argv[])
error = 1; error = 1;
} }
if( new_action != ACTION_NONE ) if( new_action != ACTION_NONE )
{ {
if( action == ACTION_NONE ) if( action == ACTION_NONE )
action = new_action; action = new_action;
else else
if( action == new_action ) if( action == new_action )
{ {
// identical, just ignore // identical, just ignore
} }
else else
{ {
printf("LOADER: error: conflicting switch %s", argv[i]); printf("LOADER: error: conflicting switch %s", argv[i]);
error = 1; error = 1;
} }
} }
} }
else else
{ {
if( pfilename ) if( pfilename )
{ {
printf("LOADER: error: additional filename %s", parg); printf("LOADER: error: additional filename %s", parg);
error = 1; error = 1;
} }
pfilename = parg; pfilename = parg;
} }
@ -894,45 +864,49 @@ int process_switches(int argc,char* argv[])
// check number of required parameters // check number of required parameters
switch( action ) switch( action )
{ {
case ACTION_TRANS : case ACTION_TRANS :
case ACTION_LOAD : case ACTION_LOAD :
case ACTION_UNLOAD : case ACTION_UNLOAD :
if( !pfilename ) if( !pfilename )
{ {
printf("LOADER: error: missing filename\n"); printf("LOADER: error: missing filename\n");
error = 1; error = 1;
} }
break;
case ACTION_RELOAD :
/* filename parameter is optional */
break; break;
case ACTION_RELOAD :
/* filename parameter is optional */
break;
#if 0
case ACTION_UNINSTALL: case ACTION_UNINSTALL:
close_debugger(); close_debugger();
tryuninstall(); tryuninstall();
break; break;
case ACTION_INSTALL: case ACTION_INSTALL:
tryinstall(); tryinstall();
break; break;
#endif
case ACTION_STATUS: case ACTION_STATUS:
showstatus(); showstatus();
break; break;
case ACTION_BREAK: case ACTION_BREAK:
dobreak(); dobreak();
break; break;
#if 0
case ACTION_TERMINAL: case ACTION_TERMINAL:
doterminal(); doterminal();
break; break;
case ACTION_NONE : #endif
printf("LOADER: no action specified specifed on commandline\n"); case ACTION_NONE :
error = 1; printf("LOADER: no action specified specifed on commandline\n");
error = 1;
break; break;
default : default :
printf("LOADER: an internal error has occurred at commandline parsing\n"); printf("LOADER: an internal error has occurred at commandline parsing\n");
error = 1; error = 1;
} }
if( !error ) // commandline was fine, now start processing if( !error ) // commandline was fine, now start processing
{ {
switch( action ) switch( action )
@ -941,16 +915,16 @@ int process_switches(int argc,char* argv[])
printf("LOADER: trying to translate file %s...\n",pfilename); printf("LOADER: trying to translate file %s...\n",pfilename);
if( process_file(pfilename)==0 ) if( process_file(pfilename)==0 )
printf("LOADER: file %s has been translated\n",pfilename); printf("LOADER: file %s has been translated\n",pfilename);
else else
printf("LOADER: error while translating file %s\n",pfilename); printf("LOADER: error while translating file %s\n",pfilename);
break; break;
case ACTION_LOAD : case ACTION_LOAD :
case ACTION_UNLOAD : case ACTION_UNLOAD :
case ACTION_RELOAD : case ACTION_RELOAD :
change_symbols(action,pfilename); change_symbols(action,pfilename);
break; break;
} }
} }
return error; return error;
} }
@ -993,26 +967,12 @@ void showpermission(void)
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
int main(int argc,char* argv[]) int main(int argc,char* argv[])
{ {
int uid;
// find out who's using us
// if it's not the superuser, bail!
if(argc==1 || argc>3) if(argc==1 || argc>3)
{ {
showhelp(); showhelp();
return 1; return 1;
} }
else
{
uid = getuid();
if(uid != 0)
{
showpermission();
return 0;
}
return process_switches(argc,argv); return process_switches(argc,argv);
}
} }

View file

@ -1,14 +1,15 @@
CC = gcc CC = gcc
CFLAGS := -Wall -fomit-frame-pointer -O2 -DLINUX CFLAGS := -Wall -fomit-frame-pointer -O2 -DLINUX
LDFLAGS := -dynamic -lncurses LDFLAGS := -dynamic
#-lncurses
OBJS = main.o terminal.o OBJS = main.o terminal.o
loader: $(OBJS) loader: $(OBJS)
$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^ $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^
clean: clean:
@echo deleting all intermediate files @echo deleting all intermediate files
@rm $(OBJS) loader -f @rm $(OBJS) loader -f
make make

View file

@ -1,18 +1,25 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <malloc.h> #include <malloc.h>
#include <io.h>
//#include <ddk/winnt.h>
#include <windows.h>
#include <winnt.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> //#include <sys/wait.h>
#include <sys/ioctl.h> //#include <sys/ioctl.h>
#include <sys/signal.h> //#include <sys/signal.h>
#include <SYS/STAT.H>
#include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> //#include <unistd.h>
#include <linux/unistd.h> //#include <linux/unistd.h>
#include <elf.h>
//#include "../../../include/pe.h"
#include "stab_gnu.h" #include "stab_gnu.h"
#include "retypes.h" //#include "retypes.h"
#include "terminal.h" //#include "terminal.h"
#include <termios.h> //#include <termios.h>
#include "../shared/shared.h" #include "../shared/shared.h"

View file

@ -7,7 +7,7 @@ Module Name:
termínal.c termínal.c
Abstract: Abstract:
serial terminal for pICE headless mode serial terminal for pICE headless mode
Environment: Environment:
@ -21,12 +21,13 @@ Author:
Revision History: Revision History:
23-Jan-2001: created 23-Jan-2001: created
Copyright notice: Copyright notice:
This file may be distributed under the terms of the GNU Public License. This file may be distributed under the terms of the GNU Public License.
--*/ --*/
#if 0 //ei not ready
#include "stdinc.h" #include "stdinc.h"
#include <curses.h> #include <curses.h>
@ -106,7 +107,7 @@ PSERIAL_PACKET ReadPacket(void)
for(i=0;i<sizeof(SERIAL_PACKET_HEADER);i++) for(i=0;i<sizeof(SERIAL_PACKET_HEADER);i++)
{ {
// //printf("reading()\n"); // //printf("reading()\n");
if(! ReadByte(pHeaderRaw)) if(! ReadByte(pHeaderRaw))
{ {
// //printf("no header byte read!\n"); // //printf("no header byte read!\n");
return NULL; return NULL;
@ -142,7 +143,7 @@ PSERIAL_PACKET ReadPacket(void)
pData = (PUCHAR)p + sizeof(header); pData = (PUCHAR)p + sizeof(header);
for(i=0;i<header.packet_size;i++) for(i=0;i<header.packet_size;i++)
{ {
if(! ReadByte(pData)) if(! ReadByte(pData))
{ {
//printf("no data byte read!\n"); //printf("no data byte read!\n");
return NULL; return NULL;
@ -189,8 +190,8 @@ BOOLEAN SetupSerial(ULONG port,ULONG baudrate)
{ {
struct termios newtio; struct termios newtio;
char* ports[]={"/dev/ttyS0","/dev/ttyS1","/dev/ttyS2","/dev/ttyS3"}; char* ports[]={"/dev/ttyS0","/dev/ttyS1","/dev/ttyS2","/dev/ttyS3"};
/* /*
Open modem device for reading and writing and not as controlling tty Open modem device for reading and writing and not as controlling tty
because we don't want to get killed if linenoise sends CTRL-C. because we don't want to get killed if linenoise sends CTRL-C.
*/ */
@ -198,40 +199,40 @@ BOOLEAN SetupSerial(ULONG port,ULONG baudrate)
fd_comm = open(ports[port-1], O_RDWR | O_NOCTTY); fd_comm = open(ports[port-1], O_RDWR | O_NOCTTY);
if (fd_comm <0) if (fd_comm <0)
{ {
perror(ports[port-1]); perror(ports[port-1]);
exit(-1); exit(-1);
} }
//printf("tcgetattr()\n"); //printf("tcgetattr()\n");
tcgetattr(fd_comm,&oldtio); /* save current modem settings */ tcgetattr(fd_comm,&oldtio); /* save current modem settings */
/* /*
Set bps rate and hardware flow control and 8n1 (8bit,no parity,1 stopbit). Set bps rate and hardware flow control and 8n1 (8bit,no parity,1 stopbit).
Also don't hangup automatically and ignore modem status. Also don't hangup automatically and ignore modem status.
Finally enable receiving characters. Finally enable receiving characters.
*/ */
newtio.c_cflag = baudrate | CS8 | CLOCAL | CREAD; newtio.c_cflag = baudrate | CS8 | CLOCAL | CREAD;
/* /*
Ignore bytes with parity errors and make terminal raw and dumb. Ignore bytes with parity errors and make terminal raw and dumb.
*/ */
newtio.c_iflag = IGNPAR; newtio.c_iflag = IGNPAR;
/* /*
Raw output. Raw output.
*/ */
newtio.c_oflag = 0; newtio.c_oflag = 0;
/* /*
Don't echo characters because if you connect to a host it or your Don't echo characters because if you connect to a host it or your
modem will echo characters for you. Don't generate signals. modem will echo characters for you. Don't generate signals.
*/ */
newtio.c_lflag = 0; newtio.c_lflag = 0;
/* blocking read until 1 char arrives */ /* blocking read until 1 char arrives */
newtio.c_cc[VMIN]=0; newtio.c_cc[VMIN]=0;
newtio.c_cc[VTIME]=0; newtio.c_cc[VTIME]=0;
/* now clean the modem line and activate the settings for modem */ /* now clean the modem line and activate the settings for modem */
//printf("tcflush()\n"); //printf("tcflush()\n");
tcflush(fd_comm, TCIFLUSH); tcflush(fd_comm, TCIFLUSH);
@ -315,7 +316,7 @@ void Print(LPSTR p,USHORT x,USHORT y)
{ {
SetCursorPosition(x,y); SetCursorPosition(x,y);
refresh(); refresh();
addstr(p); addstr(p);
refresh(); refresh();
SetCursorPosition(usCurX,usCurY); SetCursorPosition(usCurX,usCurY);
@ -361,14 +362,14 @@ void ProcessPacket(PSERIAL_PACKET p)
case PACKET_TYPE_INVERTLINE: case PACKET_TYPE_INVERTLINE:
{ {
PSERIAL_DATA_PACKET_INVERTLINE pDataInvertLine = (PSERIAL_DATA_PACKET_INVERTLINE)pData; PSERIAL_DATA_PACKET_INVERTLINE pDataInvertLine = (PSERIAL_DATA_PACKET_INVERTLINE)pData;
InvertLine(pDataInvertLine->line); InvertLine(pDataInvertLine->line);
} }
break; break;
case PACKET_TYPE_PRINT: case PACKET_TYPE_PRINT:
{ {
PSERIAL_DATA_PACKET_PRINT pDataPrint = (PSERIAL_DATA_PACKET_PRINT)pData; PSERIAL_DATA_PACKET_PRINT pDataPrint = (PSERIAL_DATA_PACKET_PRINT)pData;
Print(pDataPrint->string,pDataPrint->x,pDataPrint->y); Print(pDataPrint->string,pDataPrint->x,pDataPrint->y);
} }
break; break;
@ -426,3 +427,4 @@ void DebuggerShell(void)
} }
} }
} }
#endif

View file

@ -15,10 +15,10 @@ Environment:
LINUX 2.2.X LINUX 2.2.X
Kernel mode only Kernel mode only
Author: Author:
Klaus P. Gerlicher Klaus P. Gerlicher
reactos port by: reactos port by:
Eugene Ingerman Eugene Ingerman
@ -26,7 +26,7 @@ Revision History:
13-Nov-1999: created 13-Nov-1999: created
15-Nov-2000: general cleanup of source files 15-Nov-2000: general cleanup of source files
10/20/2001: porting to reactos begins 10/20/2001: porting to reactos begins
Copyright notice: Copyright notice:
@ -35,7 +35,24 @@ Copyright notice:
--*/ --*/
#include <ddk/ntddk.h> //#include <ddk/ntddk.h>
#include <winnt.h>
//temporary
#ifndef CTL_CODE
#define CTL_CODE(Dev, Func, Meth, Acc) ( ((Dev)<<16) | ((Acc)<<14) | ((Func)<<2) | (Meth))
// IOCTL Parameter buffering methods
#define METHOD_BUFFERED 0
#define METHOD_IN_DIRECT 1
#define METHOD_OUT_DIRECT 2
#define METHOD_NEITHER 3
// IOCTL File access type
#define FILE_ANY_ACCESS 0
#define FILE_READ_ACCESS 1
#define FILE_WRITE_ACCESS 2
#endif
// define custom device type // define custom device type
#define PICE_DEVICE_DEBUGGER 64787 #define PICE_DEVICE_DEBUGGER 64787
@ -49,7 +66,7 @@ Copyright notice:
typedef struct _DEBUGGER_STATUS_BLOCK typedef struct _DEBUGGER_STATUS_BLOCK
{ {
ULONG Test; char filename[256];
}DEBUGGER_STATUS_BLOCK,*PDEBUGGER_STATUS_BLOCK; }DEBUGGER_STATUS_BLOCK,*PDEBUGGER_STATUS_BLOCK;
#define MAGIC_ULONG( ch0, ch1, ch2, ch3 ) \ #define MAGIC_ULONG( ch0, ch1, ch2, ch3 ) \