コード例 #1
0
ファイル: omf2asm.cpp プロジェクト: StarHack/osx-dev
void COMF2ASM::MakeCommunalSymbolsTable() {
   // Make symbol table entries for communal symbols
   char * string;                                // Symbol name

   // Search for communal records
   for (uint32 i = 0; i < NumRecords; i++) {
      // Count communal records
      if (Records[i].Type2 == OMF_CEXTDEF) {
         Records[i].Index = 3;
         // Loop through strings in record
         while (Records[i].Index < Records[i].End) {			 
            uint32 LIndex = Records[i].GetIndex();
            Records[i].GetIndex(); // Group. Ignore
            string = GetLocalName(LIndex);

            // find section with same name
            int32 section = 0;
            for (uint32 j = 0; j < Segments.GetNumEntries(); j++) {
               if (Segments[j].NameIndex == LIndex) {
                  section = (int32)j; break;
               }
            }

            // Define symbol
            Disasm.AddSymbol(section, 0, 0, 0, 0x10, 0, string);
         }
      }
   }
}
コード例 #2
0
///////////////////////////////////////////////////////////////////////////////
// GetIPAddress
///////////////////////////////////////////////////////////////////////////////
// DESCRIPTION:
//      Returns an IP address.
//          - It tries to convert the string directly
//          - If that fails, it tries to resolve it as a hostname
// PARAMETERS:
//  LPCTSTR strHostName: host name to get IP address
///////////////////////////////////////////////////////////////////////////////
ULONG CSocketComm::GetIPAddress( LPCTSTR strHostName )
{
    LPHOSTENT   lphostent;
    ULONG       uAddr = INADDR_NONE;
    TCHAR       strLocal[HOSTNAME_SIZE] = { 0 };

    // if no name specified, get local
    if ( NULL == strHostName )
    {
        GetLocalName(strLocal, sizeof(strLocal));
        strHostName = strLocal;
    }

#ifdef _UNICODE
    char strHost[HOSTNAME_SIZE] = { 0 };
    WideCharToMultiByte(CP_ACP, 0, strHostName, -1, strHost, sizeof(strHost), NULL, NULL );
#else
    LPCTSTR strHost = strHostName;
#endif

    // Check for an Internet Protocol dotted address string
    uAddr = inet_addr( strHost );

    if ( (INADDR_NONE == uAddr) && (strcmp( strHost, "255.255.255.255" )) )
    {
        // It's not an address, then try to resolve it as a hostname
        if ( lphostent = gethostbyname( strHost ) )
            uAddr = *((ULONG *) lphostent->h_addr_list[0]);
    }
    
    return ntohl( uAddr );
}
コード例 #3
0
ファイル: omf2asm.cpp プロジェクト: StarHack/osx-dev
void COMF2ASM::MakeGroupDefinitions() {
   // Make segment group definitions
   uint32 i;                                     // Record index

   // Search for group records
   for (i = 0; i < NumRecords; i++) {
      if (Records[i].Type2 == OMF_GRPDEF) {
         // GRPDEF record
         Records[i].Index = 3;
         // Get group name
         uint32 ClassIndex = Records[i].GetIndex();
         char * GroupName = GetLocalName(ClassIndex);

         // Define group
         Disasm.AddSectionGroup(GroupName, 0);

         // Loop through remaining entries in record
         while (Records[i].Index < Records[i].End) {
            // Entry type should be 0xFF
            uint8 Type = Records[i].GetByte();
            // Get member name
            int32 NameIndex = Records[i].GetIndex();
            // Check if type valid
            if (Type == 0xFF && NameIndex > 0) {
               // A group member is found. Add member to group
               Disasm.AddSectionGroup(GroupName, NameIndex);
            }
         }
         if (Records[i].Index != Records[i].End) err.submit(1203);   // Check for consistency
      }
   }
}
コード例 #4
0
ファイル: symref.c プロジェクト: mingpen/OpenNT
/*  SRSendSymLocate - send a locate-symbol message to the server
 *
 *  Send request to server, display all responses until
 *  !EOM is seen.
 *
 *  psz 	symbol to find
 *  fFilesOnly	TRUE => just list filenames
 *  pszScope	scope of search
 */
void SRSendSymLocate (PSZ psz, BOOL fFilesOnly, PSZ pszScope)
{
    char sz[CBMSG];
    char *p;
    char szFile[MAX_PATH];
    HANDLE hServer;

    sprintf (sz, "%s %s %s %s", CMD_LOCATE, psz, fFilesOnly ? "-f" : "-a", pszScope);

    hServer = OpenDatabase (FALSE);

    SendSz (hServer, sz);

    while (ReceiveSz (hServer, sz)) {
	if (!strcmp (sz, RSP_EOD))
	    break;
	p = strbscan (sz, " ");
	*p++ = 0;

	GetLocalName (sz, szFile);

	if (fFilesOnly)
	    printf ("%s\n", szFile);
	else
	    printf ("%s %s\n", szFile, p);
	}

    CloseDatabase (hServer);
}
コード例 #5
0
ファイル: omf.cpp プロジェクト: DinrusGroup/DRC
void COMF::DumpSymbols() {
   // Dump public, external and communal names records
   uint32 i;          // Record index
   uint32 xn = 0;     // External name index
   char * string;
   uint32 TypeIndex;
   uint32 Group;
   uint32 Segment;
   uint32 BaseFrame;
   uint32 Offset;

   for (i = 0; i < NumRecords; i++) {
      if (Records[i].Type2 == OMF_EXTDEF) {
         // EXTDEF record.
         Records[i].Index = 3;
         printf("\n\nExternal names:");

         // Loop through strings in record
         while (Records[i].Index < Records[i].End) {
            string = Records[i].GetString();
            TypeIndex = Records[i].GetIndex();
            printf("\n  %2i  %s, Type %i", ++xn, string, TypeIndex);
         }
         if (Records[i].Index != Records[i].End) err.submit(1203);   // Check for consistency
      }

      if (Records[i].Type2 == OMF_PUBDEF) {
         // PUBDEF record.
         printf("\n\nPublic names:");
         Records[i].Index = 3;
         Group = Records[i].GetIndex();
         Segment = Records[i].GetIndex();
         BaseFrame = 0;
         if (Segment == 0) BaseFrame = Records[i].GetWord();
         // Loop through strings in record
         while (Records[i].Index < Records[i].End) {
            string = Records[i].GetString();
            Offset = Records[i].GetNumeric();
            TypeIndex = Records[i].GetIndex();
            printf("\n  %s, Segment %s, Group %s, Offset 0x%X, Type %i", 
               string, GetSegmentName(Segment), GetGroupName(Group), Offset, TypeIndex);
            if (BaseFrame) printf(", Frame %i", BaseFrame);
         }
         if (Records[i].Index != Records[i].End) err.submit(1203);   // Check for consistency
      }

      if (Records[i].Type2 == OMF_CEXTDEF) {
         // CEXTDEF record.
         printf("\n\nCommunal names:");
         Records[i].Index = 3;
         while (Records[i].Index < Records[i].End) {
            uint32 LIndex = Records[i].GetIndex();    // Index into preceding LNAMES
            uint32 Type = Records[i].GetIndex();      // Type index. Ignored
            printf("\n  %2i  %s, Type %i", ++xn, GetLocalName(LIndex), Type);
         }
         if (Records[i].Index != Records[i].End) err.submit(1203);   // Check for consistency
      }
   }
}
コード例 #6
0
// Wraps GetLocalName() to provide a Python method interface.
// Takes no arguments.
//
// Returns the local device name as a unicode python string.
static PyObject* LightBlue_GetLocalName(PyObject* self, PyObject* args) 
{
    TBTDeviceName deviceName;
    
    if (!PyArg_ParseTuple(args, ""))
        return NULL;
    
    TInt err = GetLocalName(deviceName);
    if (err) 
        return SPyErr_SetFromSymbianOSErr(err);
        
    return Py_BuildValue("u#", deviceName.Ptr(), deviceName.Length());
}
コード例 #7
0
ファイル: program_data.cpp プロジェクト: epowers/arc
void ProgramData::Link() {
  Mutex::Autolock mutex(&lock_);
  if (current_program_->IsLinked()) {
    return;
  }

  current_program_->Link();
  has_warned_about_sampler_use_ = false;
  has_link_failure_ = !current_program_->IsLinked();
  if (!has_link_failure_) {
    SetLinkedProgramLocked(current_program_);
    return;
  }

  ALOGE("Unable to link program %d(%d)\n%s", GetLocalName(),
        current_program_->GetOrCreateGlobalName(),
        current_program_->GetInfoLog().c_str());

  if (use_count_ == 0) {
    SetLinkedProgramLocked(ProgramVariantPtr(NULL));
  }
}
コード例 #8
0
ファイル: omf2asm.cpp プロジェクト: StarHack/osx-dev
void COMF2ASM::CountSegments() {
   // Make temporary Segments table
   uint32 i;                                     // Record number
   uint32 NameIndex;                             // Name index
   uint32 ClassIndex;                            // Class name index
   SOMFSegment SegRecord;                        // Segment record

   // Define structure of attributes
   OMF_SAttrib Attributes;

   // Initialize temporary list of segments. Entry 0 is blank
   Segments.PushZero();
   
   // Search for SEGDEF records
   for (i = 0; i < NumRecords; i++) {
      if (Records[i].Type2 == OMF_SEGDEF) {
         // SEGDEF record
         Records[i].Index = 3;
         // Loop through entries in record. There should be only 1
         while (Records[i].Index < Records[i].End) {
            // Read segment attributes
            Attributes.b = Records[i].GetByte();
            if (Attributes.u.A == 0) {
               // Frame and Offset only included if A = 0
               Records[i].GetWord();             // Frame ignored
               SegRecord.Offset = Records[i].GetByte();
            }
            else SegRecord.Offset = 0;

            SegRecord.Size = Records[i].GetNumeric();
            NameIndex  = Records[i].GetIndex();
            ClassIndex = Records[i].GetIndex();  // Class index
            Records[i].GetIndex();               // Overlay index ignored
            SegRecord.NameO = GetLocalNameO(NameIndex);     // Segment name

            if (Attributes.u.B) {
               // Segment is big
               if (Attributes.u.P) {
                  // 32 bit segment. Big means 2^32 bytes!
                  err.submit(2306);
               }
               else {
                  // 16 bit segment. Big means 2^16 bytes
                  SegRecord.Size = 0x10000;
               }
            }

            // Get word size
            SegRecord.WordSize = Attributes.u.P ? 32 : 16;

            // Get alignment
            switch (Attributes.u.A) {
            case 0:  // Absolute segment
            case 1:  // Byte alignment
               SegRecord.Align = 0;
               break;

            case 2:  // Word alignment
               SegRecord.Align = 1;
               break;

            case 3:  // Paragraph alignment
               SegRecord.Align = 4;
               break;

            case 4:  // Page alignment
               SegRecord.Align = 16;
               break;

            case 5:  // DWord alignment
               SegRecord.Align = 2;
               break;

            default: // Unknown
               SegRecord.Align = 3; // Arbitrary value
               break;
            }

            // Get further attributes from class name
            char * ClassName = GetLocalName(ClassIndex);

            // Convert class name to upper case
            uint32 n = (uint32)strlen(ClassName);
            for (uint32 j = 0; j < n; j++) ClassName[j] &= ~0x20;

            // Search for known class names.
            // Standard names are CODE, DATA, BSS, CONST, STACK
            if (strstr(ClassName, "CODE") || strstr(ClassName, "TEXT")) {
               // Code segment
               SegRecord.Type = 1;
            }
            else if (strstr(ClassName, "DATA")) {
               // Data segment
               SegRecord.Type = 2;
            }
            else if (strstr(ClassName, "BSS")) {
               // Unitialized data segment
               SegRecord.Type = 3;
            }
            else if (strstr(ClassName, "CONST")) {
               // Constant data segment
               SegRecord.Type = 4;
            }
            else if (strstr(ClassName, "STACK")) {
               // Stack segment.
               SegRecord.Type = 0;
            }
            else {
               // Unknown/user defined class. Assume data segment
               SegRecord.Type = 2;
            }

            // Store temporary segment record
            Segments.Push(SegRecord);
         }
         if (Records[i].Index != Records[i].End) err.submit(1203);   // Check for consistency
      }
   }

   FirstComDatSection = Segments.GetNumEntries();
   // Communal sections (as used by Digital Mars):
   // This part by Don Clugston
   for (i = 0; i < NumRecords; i++) {
      if (Records[i].Type2 == OMF_COMDAT) {
         Records[i].Index = 3;

         uint8 flags = Records[i].GetByte();
         if ((flags & 2)!= 0) {
            // don't support iterated data yet
            err.submit(2318);           // Error message: not supported
            continue;
         }
         uint8 attribs = Records[i].GetByte();
         uint8 align = Records[i].GetByte();
         uint32 ofs  = Records[i].GetNumeric();
         Records[i].GetIndex(); // type (ignore)
         uint16 publicBase = 0;
         uint16 publicSegment = 0;
         // From the OMF Spec 1.1: "If alloc type is EXPLICIT, public base is present and is
         // identical to public base fields BaseGroup, Base Segment & BaseFrame in the PUBDEF."
         // BUT: In the diagram in the spec it is described as 1-2 bytes (ie, an Index field).
         // but in PUBDEF, those fields are Index, Index, or Index, zero, Index. (2-5 bytes)
         // The diagram appears to be erroneous.
         if ((attribs & 0xF) == 0){
            publicBase = Records[i].GetIndex();
            publicSegment = Records[i].GetIndex();
            if (publicSegment == 0) Records[i].GetIndex(); // skip frame in this case
         }
         uint16 publicName = Records[i].GetIndex();
         uint32 RecSize = Records[i].End - Records[i].Index; // Calculate size of data
         if (attribs & 0xF) {
            SegRecord.Type = 0x1000  | (attribs & 0xFF);
            SegRecord.WordSize = (attribs & 0x2) ? 32 : 16;
         }
         else {			 
            // use value from segdef
            SegRecord.Type = 0x1000 | Segments[publicSegment].Type;
            SegRecord.WordSize = Segments[publicSegment].WordSize;
         }
         if (align != 0) {
            // alignment: (none), byte, word, paragraph, page, dword, arbitrary, arbitrary.
            static const int alignvalues[] = {0, 0, 1, 4, 16, 2, 3, 3};
            SegRecord.Align = alignvalues[align & 0x7];
         }
         else { // use value from segdef
            SegRecord.Align = Segments[publicSegment].Align;
         }
         SegRecord.Size = RecSize;

         // Get function name
         const char * name = GetLocalName(publicName);

         // Make a section name by putting _text$ before function name
         uint32 ComdatSectionNameIndex = NameBuffer.Push("_text$", 6);
         NameBuffer.PushString(name); // append function name
         SegRecord.NameO = ComdatSectionNameIndex;
         SegRecord.NameIndex = publicName;

         if (flags & 1) {
            // continuation.
            // Add to the length to the previous entry.
            Segments[Segments.GetNumEntries()-1].Size += RecSize;
         } 
         else {
            SegRecord.Offset = ofs;
            Segments.Push(SegRecord);
         }
      }
   }

   // Communal sections (as used by Borland):
   for (i = 0; i < NumRecords; i++) {
      if (Records[i].Type2 == OMF_COMDEF) {
         uint32 DType, DSize, DNum;
         uint16 Segment = 0;
         const char * FuncName;

         // Loop through possibly multiple entries in record
         while (Records[i].Index < Records[i].End) {
            // Get function name
            FuncName = Records[i].GetString();
            Records[i].GetByte(); // Type index, should be 0, ignored
            DType = Records[i].GetByte(); // Data type
            switch (DType) {
            case 0x61:
               DNum  = Records[i].GetLength();
               DSize = Records[i].GetLength() * DNum;
               break;
            case 0x62:
               DSize = Records[i].GetLength();
               break;
            default:
               DSize = Records[i].GetLength();
               if (DType < 0x60) { // Borland segment index
                  Segment = DType;
                  break;
               }
               err.submit(2016); // unknown type
               break;
            }
         }
         if (Segment >= Segments.GetNumEntries()) {err.submit(2016); return;}

         // Copy segment record
         SegRecord = Segments[Segment];

         // Make a section name as SEGMENTNAME$FUNCTIONNAME
         const char * SegmentName = NameBuffer.Buf() + SegRecord.NameO;
         uint32 ComdatSectionNameIndex = NameBuffer.Push(SegmentName, strlen(SegmentName));
         NameBuffer.Push("$", 1);
         NameBuffer.PushString(FuncName); // append function name
         SegRecord.NameO = ComdatSectionNameIndex;
         SegRecord.Size = DSize;
         SegRecord.Type |= 0x1000;
         //SegRecord.BufOffset = ??

         // Store segment
         Segments.Push(SegRecord);

         if (Records[i].Index != Records[i].End) err.submit(1203);   // Check for consistency
      }
   }
   // Number of segments, not including blank zero entry
   NumSegments = Segments.GetNumEntries() - 1;
}
コード例 #9
0
	bool XMLReader::IsStartElement(const char * localName, const char * namespaceURI) {
	    return (MoveToContent() == kElement)
	        && Equals(GetLocalName(), localName)
	        && Equals(GetNamespaceURI(), namespaceURI);
	}
コード例 #10
0
ファイル: ncpfit.cpp プロジェクト: EISALab/AMGAgroundwater
bool DoPdeFit( int nId, CClientSession* pSession, void* pParam )
{
	SERVERINFO sysinfo;

	char buf[MAXPATH], path[MAXPATH];

	if( !pSession->Logon( "smyan_new", "" ) )return false;
	strcpy( path, "uma_sga" );
	strcat( path, "_" );
	strcat( path, GetLocalName().substr(0,8).c_str() );

	pSession->MkDir( path );
	pSession->ChDir( path );
	pSession->ServerInfo( sysinfo );

	sprintf( path, "slave%d", nId );

	char* cmd = NULL;
	if( sysinfo.nOpSystem==SI_WIN32 ){
		cmd = "surrga.exe";
	}else if( sysinfo.nOpSystem==SI_LINUX ){
		cmd = "surrga.ln";
	}else if( sysinfo.nOpSystem==SI_UNIX ){
		cmd = "surrga.un";
	}

	//send all the static files in the static folder to the remote host
	pSession->FileMode( O_TEXT );
	bool bOk = true;
//	bool bOk = SendDir( pSession, "static", false );

	pSession->FileMode( O_BINARY );
//	pSession->CopyTo( cmd, cmd, COPY_OLD_OVERWRITE );
	pSession->ChMod( cmd, 0x700 );

	//for shared disk, make sub compuation folder and enter it.
	if( sysinfo.bShareDisk ){
		pSession->MkDir( path );
		pSession->ChDir( path );
	}

	//delete the surrbak.data file now
	pSession->Remove( "surrbak.dat" );

//	cdump<<lock<<nId<<"--check point 1"<<endl<<unlock;
	//send the files in the slave folder.
	pSession->FileMode( O_TEXT );
	SendDir( pSession, path, true );

	//for shared disk, make soft link in the computation folder
	if( sysinfo.bShareDisk ){
		LinkDir( pSession, "static" );
		char buf[100];
//		pSession->Remove( cmd );
		sprintf( buf, "../%s", cmd );
		pSession->SoftLink( buf, cmd );
	}


	//run the pdefit
	DWORD dwExit = 0;
	bOk = pSession->RunCommand( cmd, true, dwExit );
//	bOk = pSession->CopyTo( "surrbak.dat", "surrbak.dat", COPY_NO_OVERWRITE );
	if( bOk && dwExit==0 ){
		//retrieve surrback.dat
		strcpy( buf, path );
		strcat( buf, "/surrbak.dat" );
		bOk = pSession->CopyFrom( "surrbak.dat", buf );
	}else{
		bOk = false;
	}

	if( sysinfo.bShareDisk ){
		pSession->ChDir( ".." );
		pSession->RemoveDir( path, true );
//		pSession->EmptyDir( "." );
		//remove the intemediate files to save disk space.
//		pSession->Remove( "optdemo_fine.ftl" );
//		pSession->Remove( "fort.30" );
//		pSession->Remove( "fort.35" );
	}

//	pSession->ChDir( "~" );

	return bOk;
}
コード例 #11
0
ファイル: omf.cpp プロジェクト: DinrusGroup/DRC
void COMF::PublicNames(CMemoryBuffer * Strings, CSList<SStringEntry> * Index, int m) {
   // Make list of public names
   // Strings will receive ASCIIZ strings
   // Index will receive records of type SStringEntry with Member = m
   SOMFRecordPointer rec;                        // Current OMF record
   char * string;                                // Symbol name
   SStringEntry se;                              // String entry record to save

   // Initialize record pointer
   rec.Start(Buf(), 0, GetDataSize());

   // Loop through records and search for PUBDEF records
   do {
      // Read record
      if (rec.Type2 == OMF_PUBDEF) {

         // Public symbols definition found
         rec.GetIndex(); // Read group
         uint32 Segment = rec.GetIndex(); // Read segment
         if (Segment == 0) rec.GetWord(); // Read base frame
         // Loop through strings in record
         while (rec.Index < rec.End) {
            string = rec.GetString();  // Read name
            rec.GetNumeric(); // Read offset
            rec.GetIndex(); // Read type
            // Make SStringEntry record
            se.Member = m;
            // Store name
            se.String = Strings->PushString(string);
            // Store name index
            Index->Push(se);
         }
         if (rec.Index != rec.End) err.submit(1203);   // Check for consistency
      }
      if (rec.Type2 == OMF_CEXTDEF) {
         // CEXTDEF record. Store communal symbol names
         // Loop through entries in record
         while (rec.Index < rec.End) {
            uint32 LIndex = rec.GetIndex() - 1;  // Index into preceding LNAMES
            rec.GetIndex();                      // Type index. Ignore
            // Check if index valid
            if (LIndex < LocalNameOffset.GetNumEntries()) {
               // Make SStringEntry record
               se.Member = m;
               // Get name
               char * name = GetLocalName(LIndex);
               if (strlen(name) > 0) {
                  // Store name
                  se.String = Strings->PushString(name);
                  // Store name index
                  Index->Push(se);
               }
            }
         }
         if (rec.Index != rec.End) err.submit(1203);  // Check for consistency
      }
      if (rec.Type2 == OMF_LNAMES) {
         // LNAMES record. Check if file has been parsed
         if (Records.GetNumEntries() == 0) {
            // ParseFile has not been called. We need to store LNAMES table because
            // these names may be needed by subsequent EXTDEF records.
            // Loop through strings in record
            while (rec.Index < rec.End) {
               char * LocalName = rec.GetString();
               uint32 LocalNameIndex = NameBuffer.PushString(LocalName); // Store local name
               LocalNameOffset.Push(LocalNameIndex);// Store local name index
            }
            if (rec.Index != rec.End) err.submit(1203);  // Check for consistency
         }
      }
   } // Get next record
   while (rec.GetNext());                        // End of loop through records
}
コード例 #12
0
ファイル: omf.cpp プロジェクト: DinrusGroup/DRC
void COMF::DumpRelocations() {
   // Dump all LEDATA, LIDATA, COMDAT and FIXUPP records
   uint32 LastDataRecord = 0;          // Index to the data record that relocations refer to
   uint32 LastDataRecordSize = 0;      // Size of the data record that relocations refer to
   int8 * LastDataRecordPointer = 0;   // Pointer to data in the data record that relocations refer to
   uint32 i;                           // Loop counter
   uint32 Segment, Offset, Size;       // Contents of LEDATA or LIDATA record
   uint32 LastOffset = 0;              // Offset of last LEDATA or LIDATA record
   uint32 Frame, Target, TargetDisplacement; // Contents of FIXUPP record
   uint8 byte1, byte2;                 // First two bytes of subrecord

   // Bitfields in subrecords
   OMF_SLocat Locat;         // Structure of first two bytes of FIXUP subrecord swapped = Locat field
   OMF_SFixData FixData;     // Structure of FixData field in FIXUP subrecord of FIXUPP record
   OMF_STrdDat TrdDat;       // Structure of Thread Data field in THREAD subrecord of FIXUPP record

   printf("\n\nLEDATA, LIDATA, COMDAT and FIXUPP records:");
   for (i = 0; i < NumRecords; i++) {
      if (Records[i].Type2 == OMF_LEDATA) {
         // LEDATA record
         Segment = Records[i].GetIndex();             // Read segment and offset
         Offset  = Records[i].GetNumeric();
         Size    = Records[i].End - Records[i].Index; // Calculate size of data
         LastDataRecord = i;                          // Save for later FIXUPP that refers to this record
         LastDataRecordSize = Size;
         LastDataRecordPointer = Records[i].buffer + Records[i].FileOffset + Records[i].Index;
         if (Segment < 0x4000) {
            printf("\n  LEDATA: segment %s, Offset 0x%X, Size 0x%X", // Dump segment, offset, size
               GetSegmentName(Segment), Offset, Size);
            LastOffset = Offset;
         }
         else { // Undocumented Borland communal section
            printf("\n  LEDATA communal section %i, Offset 0x%X, Size 0x%X", // Dump segment, offset, size
               (Segment & ~0x4000), Offset, Size);
            LastOffset = Offset;
         }
      }

      if (Records[i].Type2 == OMF_LIDATA) {
         // LIDATA record
         Segment = Records[i].GetIndex();
         Offset  = Records[i].GetNumeric();
         LastDataRecord = i;
         LastDataRecordSize = Records[i].End - Records[i].Index; // Size before expansion of repeat blocks
         LastDataRecordPointer = Records[i].buffer + Records[i].FileOffset + Records[i].Index;
         printf("\n  LIDATA: segment %s, Offset 0x%X, Size ",
            GetSegmentName(Segment), Offset);
         // Call recursive function to interpret repeat data block
         Size = Records[i].InterpretLIDATABlock();
         printf(" = 0x%X", Size);
         LastOffset = Offset;
      }

      if (Records[i].Type2 == OMF_COMDAT) {
         // COMDAT record
         uint32 Flags = Records[i].GetByte(); // 1 = continuation, 2 = iterated, 4 = local, 8 = data in code segment
         uint32 Attributes = Records[i].GetByte(); 
         uint32 Base = 0;
         // 0 = explicit, 1 = far code, 2 = far data, 3 = code32, 4 = data32
         // 0x00 = no match, 0x10 = pick any, 0x20 = same size, 0x30 = exact match
         uint32 Align = Records[i].GetByte(); // Alignment
         Offset  = Records[i].GetNumeric();    // Offset
         uint32 TypeIndex = Records[i].GetIndex(); // Type index
         if ((Attributes & 0x0F) == 0) {
            Base = Records[i].GetIndex(); // Public base
         }
         uint32 NameIndex = Records[i].GetIndex(); // LNAMES index
         Size    = Records[i].End - Records[i].Index; // Calculate size of data

         printf("\n  COMDAT: name %s, Offset 0x%X, Size 0x%X, Attrib 0x%02X, Align %i, Type %i, Base %i",
            GetLocalName(NameIndex), Offset, Size, Attributes, Align, TypeIndex, Base);
         LastOffset = Offset;
      }

      if (Records[i].Type2 == OMF_FIXUPP) {
         // FIXUPP record
         printf("\n  FIXUPP:");
         Records[i].Index = 3;

         // Loop through entries in record
         while (Records[i].Index < Records[i].End) {

            // Read first byte
            byte1 = Records[i].GetByte();
            if (byte1 & 0x80) {
               // This is a FIXUP subrecord
               Frame = 0; Target = 0; TargetDisplacement = 0;

               // read second byte
               byte2 = Records[i].GetByte();
               // swap bytes and put into byte12 bitfield
               Locat.bytes[1] = byte1;
               Locat.bytes[0] = byte2;
               // Read FixData
               FixData.b = Records[i].GetByte();

               // print mode and location
               printf("\n   %s %s, Offset 0x%X", 
                  Lookup(OMFRelocationModeNames, Locat.s.M),
                  Lookup(OMFFixupLocationNames, Locat.s.Location),
                  Locat.s.Offset + LastOffset);

               // Read conditional fields
               if (FixData.s.F == 0) {
                  if (FixData.s.Frame < 4) {
                     Frame = Records[i].GetIndex();
                  }
                  else Frame = 0;

                  switch (FixData.s.Frame) { // Frame method
                  case 0:  // F0: segment
                     printf(", segment %s", GetSegmentName(Frame));  break;

                  case 1:  // F1: group
                     printf(", group %s", GetGroupName(Frame));  break;

                  case 2:  // F2: external symbol
                     printf(", external frame %s", GetSymbolName(Frame));  break;

                  case 4:  // F4: frame = source, 
                           // or Borland floating point emulation record (undocumented?)
                     printf(", frame = source; or Borland f.p. emulation record");
                     break;

                  case 5:  // F5: frame = target
                     printf(", frame = target");  break;

                  default:
                     printf(", target frame %i method F%i", Frame, FixData.s.Frame);
                  }
               }
               else {
                  printf(", frame uses thread %i", FixData.s.Frame);
               }
               
               if (FixData.s.T == 0) {
                  // Target specified
                  Target = Records[i].GetIndex();
                  uint32 TargetMethod = FixData.s.Target + FixData.s.P * 4;

                  switch (FixData.s.Target) { // = Target method modulo 4
                  case 0: // T0 and T4: Target = segment
                  case 1: // T1 and T5: Target = segment group
                     printf(". Segment %s (T%i)",
                        GetSegmentName(Target), TargetMethod);
                     break;
                  case 2: // T2 and T6: Target = external symbol
                     printf(". Symbol %s (T%i)",
                        GetSymbolName(Target), TargetMethod);
                     break;
                  default: // Unknown method
                     printf(", target %i unknown method T%i", Target, TargetMethod);
                  }
               }
               else {
                  // Target specified in previous thread
                  printf(", target uses thread %i", FixData.s.Target);
               }

               if (FixData.s.P == 0) {
                  TargetDisplacement = Records[i].GetNumeric();
                  printf("\n    target displacement %i", TargetDisplacement);
               }
               // Get inline addend
               if (LastDataRecordPointer && Locat.s.Offset < LastDataRecordSize) {
                  int8 * inlinep = LastDataRecordPointer + Locat.s.Offset;
                  switch (Locat.s.Location) {
                  case 0: case 4:  // 8 bit
                     printf(", inline 0x%X", *inlinep);  break;

                  case 1: case 2: case 5: // 16 bit
                     printf(", inline 0x%X", *(int16*)inlinep);  break;

                  case 3: // 16+16 bit
                     printf(", inline 0x%X:0x%X", *(int16*)(inlinep+2), *(int16*)inlinep);  break;

                  case 9: case 13: // 32 bit
                     printf(", inline 0x%X", *(int32*)inlinep);  break;

                  case 6: case 11: // 16+32 bit
                     printf(", inline 0x%X:0x%X", *(int16*)(inlinep+4), *(int32*)inlinep);  break;
                  }
               }
            }
            else {
               // This is a THREAD subrecord
               TrdDat.b = byte1;                 // Put byte into bitfield

               uint32 Index  = 0;
               if (TrdDat.s.Method < 4) {
                  Index  = Records[i].GetIndex(); // has index field if method < 4 ?
               }
               printf("\n   %s Thread %i. Method %s%i, index %i",
                  (TrdDat.s.D ? "Frame" : "Target"), TrdDat.s.Thread,
                  (TrdDat.s.D ? "F" : "T"), TrdDat.s.Method, Index);
            }
         } // Finished loop through subrecords
         if (Records[i].Index != Records[i].End) err.submit(1203);   // Check for consistency
      }
   } // Finished loop through records
}
コード例 #13
0
ファイル: omf.cpp プロジェクト: DinrusGroup/DRC
void COMF::DumpSegments() {
   // Dump all segment records

   // Define structure of attributes
   OMF_SAttrib Attributes;

   // Record values
   uint32 Frame, Offset, SegLength, NameIndex, ClassIndex, OverlayIndex;

   uint32 i;                                     // Record number
   uint32 SegNum = 0;                            // Segment number
   
   printf("\n\nSegment records:");
   for (i = 0; i < NumRecords; i++) {
      if (Records[i].Type2 == OMF_SEGDEF) {
         // SEGDEF record
         Records[i].Index = 3;
         // Loop through entries in record. There should be only 1
         while (Records[i].Index < Records[i].End) {
            Attributes.b = Records[i].GetByte();     // Read attributes
            if (Attributes.u.A == 0) {
               // Frame and Offset only included if A = 0
               Frame = Records[i].GetWord();  Offset = Records[i].GetByte();
            }
            else Frame = Offset = 0;
            SegLength    = Records[i].GetNumeric();
            NameIndex    = Records[i].GetIndex();
            ClassIndex   = Records[i].GetIndex();
            OverlayIndex = Records[i].GetIndex();

            printf("\n  Segment %2i, Name %s, Class %s, Align %i, %s, %i bit",
               ++SegNum, GetLocalName(NameIndex), GetLocalName(ClassIndex), 
               OMFAlignTranslate[Attributes.u.A], 
               Lookup(OMFSegmentCombinationNames, Attributes.u.C),
               Attributes.u.P ? 32 : 16);
            if (Attributes.u.B) printf(", big");
            if (Attributes.u.A == 0) printf(", Frame %i, Offset 0x%X", Frame, Offset);
            printf(", Length %i", SegLength);
            if (OverlayIndex) printf("\n   Overlay %i", OverlayIndex);
         }
         if (Records[i].Index != Records[i].End) err.submit(1203);   // Check for consistency
      }
   }
   printf("\n\nGroup records:");
   for (i = 0; i < NumRecords; i++) {
      if (Records[i].Type2 == OMF_GRPDEF) {
         // GRPDEF record
         Records[i].Index = 3;
         ClassIndex = Records[i].GetIndex();
         printf("\n  Group: %s\n   Segments:", GetLocalName(ClassIndex));

         // Loop through remaining entries in record
         while (Records[i].Index < Records[i].End) {
            uint8 Type = Records[i].GetByte();
            if (Type != 0xFF) printf(" Type=%X:", Type);
            NameIndex =  Records[i].GetIndex();
            printf(" %s", GetSegmentName(NameIndex));
         }
         if (Records[i].Index != Records[i].End) err.submit(1203);   // Check for consistency
      }
   }
}
コード例 #14
0
void
CProxySessionManager::ProcessNewConnection( SOCKET Server )
{
    CProxySession* pSession = NULL;
    SOCKET Client;
    
    // SOCKADDR_STORAGE from;
    // на Vista изменили размер SOCKADDR_STORAGE. теперь 128 байт.
    // на вс¤кий случай делаю 256 ( вдруг еще раз измен¤т !? )
    // P.S. pigs !!!
    union _MY_SOCKADDR_STORAGE {
        SOCKADDR_STORAGE ss;
        char reserved[256];
    } from;

    int fromlen = sizeof ( from );

    char    DrvBuffer[512];
    int     RetVal;

    Client = accept(Server, (struct sockaddr *)&from, &fromlen);

    if ( Client == INVALID_SOCKET )
    {
        KLSTD_TRACE1( KLMC_TRACELEVEL, "ProcessNewConnection: accept error = %d", WSAGetLastError() );        
        return;    
    }
    
    KLSTD_TRACE0( KLMC_TRACELEVEL, "ProcessNewConnection: connection accepted. create Session" );

    SetBlocking( Client, true );

    RetVal = recv ( Client, DrvBuffer, 500, 0 );

	char Prefix[16];
	memset( Prefix, '.', sizeof(Prefix) );
    memcpy( Prefix, DrvBuffer, 10 );
    Prefix[15] = 0;

    KLSTD_TRACE3 (KLMC_TRACELEVEL, "CProxySessionManager::Run => recv %d bytes from server [%s]. err = %d", 
        RetVal, GetBinBufferTraceStringShort((const BYTE *)Prefix, sizeof(Prefix)).c_str(), WSAGetLastError() );

	if (RetVal == 0 || RetVal == INVALID_SOCKET)
	{
		// CLOSESOCKET(Client);
        closesocket( Client );
		return;
	}
    
    // обычный редирект через KAVSEND. ќставлено на вс¤ких случай, если не смогли переключитьс¤ на новую схему.
    if ( 0 == memcmp( DrvBuffer, KAVSEND_COMMAND, strlen( KAVSEND_COMMAND ) ) ) 
    {   
        KLSTD_TRACE0 (KLMC_TRACELEVEL, "CProxySessionManager::Run => KAVSEND" );

        pSession = new CProxySession(m_hParent, this, m_hStopEvent );

        if ( pSession )
        {
            KLSTD_TRACE1 (KLMC_TRACELEVEL, "CProxySessionManager::Run => KAVSEND create session(%p)", pSession );
            // тут клиентский сокет
            pSession->m_Flags |= FPS_GOT_KAVSEND;
            pSession->m_AcceptedSock = Client;
            pSession->ParseKavsendBuffer( DrvBuffer, RetVal );

            pSession->StartProtocollers();

            m_SessionList.push_back(pSession);  //ƒобавим в список запущенную сессию            
            if ( !pSession->StartClient() )
            {
                KLSTD_TRACE0 (KLMC_TRACELEVEL, "CProxySessionManager::Run => Unable to start thread after KAVSEND");
                AddClient( pSession );
            }
        }
        return;
    }

    // редирект по новой схеме KAVSVC
    if ( 0 == memcmp( DrvBuffer, KAVSVC_COMMAND, strlen( KAVSVC_COMMAND ) ))
    {
        // сервисное соединение. “ут должны указыватьс¤ параметры сервера,
        // куда выполн¤ем соединение. ѕрокси должна соединитьс¤ туда и 
        // создать ID сессии.
        pSession = new CProxySession(m_hParent, this, m_hStopEvent );

        KLSTD_TRACE1 (KLMC_TRACELEVEL, "CProxySessionManager::Run => KAVSVC. session = %p", pSession );

        if ( pSession )
        {
            pSession->m_AcceptedSock = Client; 
            pSession->m_Flags |= FPS_GOT_KAVSVC;
            pSession->ParseKavsvcBuffer( DrvBuffer, RetVal );
            
            m_SessionList.push_back(pSession); //ƒобавим в список запущенную сессию            
            if ( !pSession->StartClient() )
            {
                KLSTD_TRACE0 (KLMC_TRACELEVEL, "CProxySessionManager::Run => Unable to start thread after KAVSVC");
                AddClient( pSession );
            }
        }

        return;
    }

    // продолжение редиректа по новой схеме. ћы законнектились на сервер.
    // “еперь нужно найти сессию с установленным серверным соединением по указанному ID
    // !! TODO : можно избежать лишнего запуска потока. дл¤ этого нужно засинхронизировать
    //           уже работающий поток с серверным соединением с текущим потоком.
    if ( 0 == memcmp( DrvBuffer, KAVCONN_ID, strlen( KAVCONN_ID ) ) )
    {
        __int64 ID = *(__int64*) ( (PCHAR)DrvBuffer + 10 );

        KLSTD_TRACE1 (KLMC_TRACELEVEL, "CProxySessionManager::Run => KAVCONN_ID 0x%I64x", ID );

        if ( pSession  = FindSessionByID( ID ) )
        {
            KLSTD_TRACE1 (KLMC_TRACELEVEL, "CProxySessionManager::Run => Session %p found by KAVCONN_ID", pSession );
            // тут клиентский сокет
            
            pSession->m_client.AssignSocket( Client );
            pSession->m_client.PrepareSocket();

            GetLocalName( pSession->m_client.Socket(), pSession->m_Localhost, sizeof ( pSession->m_Localhost ) );

            pSession->m_Flags |= FPS_GOT_KAVCONN_ID | FPS_ESTABLISHED | FPS_CLIENT_CONNECTED;
            
            pSession->StartProtocollers();

            // запускаем поток сессии
            if ( !pSession->StartClient() )
            {
                KLSTD_TRACE0 (KLMC_TRACELEVEL, "CProxySessionManager::Run => Unable to start thread after KAVCONN_ID");
                AddClient( pSession );
            }
        }
        else
        {
            KLSTD_TRACE0 (KLMC_TRACELEVEL, "CProxySessionManager::Run => Session NOT found by KAVCONN_ID" );
        }

        return;
    }
}
コード例 #15
0
ファイル: Get.c プロジェクト: aosm/ncftp
int DoGet(GetOptionsPtr gopt)
{
	int fd;
	int result;
	string local;
	long fileSize;
	time_t modifTime;
	int doReports;
	struct stat st;
	size_t restartPt;
	const char *mode = "w";
	time_t now;
	XferSpecPtr xp;

	if (gTransferType == 'A') {
		/* Have to set the type here, because GetDateAndSize() may
		 * use the SIZE command, and the result of that depends
		 * on the current transfer type setting.
		 */
		SETASCII;
	} else {
		SetType(gTransferType);
	}
	
	/* See if we can get some info about the file first. */
	fileSize = GetDateAndSize(gopt->rName, &modifTime);
	restartPt = SZ(0);
	doReports = 0;

	if (gopt->outputMode == kDumpToStdout) {
		fd = gStdout;
		STRNCPY(local, kLocalFileIsStdout);
		/* Don't have progress reports going if we're piping or
		 * dumping to the screen.
		 */
	} else {
		GetLocalName(gopt, local);
		if (stat(local, &st) == 0) {
			/* File exists on the local host.  We must decide whether
			 * we really want to fetch this file, since we might have
			 * it here already.  But when in doubt, we will go ahead
			 * and fetch the file.
			 */
			if (gopt->forceReget) {
				/* If the local file is smaller, then we
				 * should attempt to restart the transfer
				 * from where we left off.
				 */
				if ((st.st_size < fileSize) || (fileSize == kSizeUnknown)) {
					restartPt = SZ(st.st_size);
					mode = "a";
					DebugMsg("Manually continuing local file %s.", local);
				} else {
					PrintF("Already have %s with size %lu.\n", gopt->rName, fileSize);
					return (0);
				}
			} else if (!gopt->overwrite) {
				if (modifTime != kModTimeUnknown) {
					/* We know the date of the remote file. */
					DebugMsg("Local file %s has size %lu and is dated %s",
						local,
						(unsigned long) st.st_size,
						ctime(&st.st_mtime)
					);
					if (modifTime < st.st_mtime) {
						/* Remote file is older than existing local file. */
						PrintF("Already have %s.\n", gopt->rName);
						return (0);
					} else if (modifTime == st.st_mtime) {
						/* Remote file is same age. */
						if (fileSize != kSizeUnknown) {
							/* If the local file is smaller, then we
							 * should attempt to restart the transfer
							 * from where we left off, since we the remote
							 * file has the same date.
							 */
							if (st.st_size < fileSize) {
								restartPt = SZ(st.st_size);
								mode = "a";
							} else if (st.st_size == fileSize) {
								PrintF("Already have %s.\n", gopt->rName);
								return (0);
							} else {
								DebugMsg("Overwriting %s; local file has same date,\n",
									gopt->lName);
								DebugMsg("but local file is larger, so fetching remote version anyway.\n");
							}
						} else {
							DebugMsg("Overwriting %s; local file has same date,\n",
									gopt->lName);
							DebugMsg("but can't determine remote size, so fetching remote version anyway.\n");
						}
					} else {
						/* Remote file is more recent.  Fetch the
						 * whole file.
						 */
						DebugMsg("Overwriting %s; remote was newer.\n",
							gopt->lName);
					}
				} else {
					/* We don't know the date of the file.
					 * We won't be able to safely assume anything about
					 * the remote file.  It is legal to have a more
					 * recent remote file (which we don't know), with a
					 * smaller (or greater, or equal even) size.  We
					 * will just have to fetch it no matter what.
					 */
					DebugMsg("Overwriting %s; couldn't determine remote file date.\n",
						gopt->lName);
				}
			} else {
				DebugMsg("Explicitly overwriting %s.\n", gopt->lName);
			}
		} else {
			/* We don't have a local file with the same name as the remote,
			 * but we may also want to avoid doing the transfer of this
			 * file.  For example, this is where we check the remote
			 * file's date if we were told to only get files which are
			 * less than X days old.
			 */
			if (gopt->newer > 0) {
				time(&now);
				if (((unsigned long) now - (unsigned long) (gopt->newer * 86400)) > (unsigned long) modifTime) {
					DebugMsg("Skipping %s, older than %d days.\n",
						gopt->rName, gopt->newer);
					return (0);
				}
			}
		}
		if (*mode == 'w')
			fd = open(local, O_WRONLY | O_TRUNC | O_CREAT,
				S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
		else
			fd = open(local, O_WRONLY | O_APPEND | O_CREAT,
				S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
		if (fd < 0) {
			Error(kDoPerror, "Can't open local file %s.\n", local);
			return (-1);
		}
		doReports = gopt->doReports;
	}

	xp = InitXferSpec();
	xp->netMode = kNetReading;
	xp->outStream = fd;
	
	/* This group is needed for the progress reporting and logging stuff.
	 * Otherwise, it isn't that important.
	 */
	xp->doReports = doReports;
	xp->localFileName = local;
	xp->remoteFileName = gopt->rName;
	xp->expectedSize = fileSize;
	xp->startPoint = restartPt;
	xp->doUTime = gopt->doUTime;
	xp->remoteModTime = modifTime;
	
	if (gTransferType == 'A') {
		result = AsciiGet(xp);
	} else {		
		result = BinaryGet(xp);
	}

	if (fd != gStdout) {
		(void) close(fd);
		if ((result < 0) && (xp->bytesTransferred < 1L) && (*mode != 'a')) {
			/* An error occurred, and we didn't transfer anything,
			 * so remove empty file we just made.
			 */
			(void) UNLINK(local);
		} else {
			/* Restore the modifcation date of the new file to
			 * what it was on the remote host, if possible.
			 */
			SetLocalFileTimes(gopt->doUTime, modifTime, local);
		}
	}

	DoneWithXferSpec(xp);
	return (result);
}	/* DoGet */