2010-09-30 60 views
1

我只需要了解一条单一指令,因此我需要生成这些东西。如何为“mov”指令生成数据?

我需要在运行时使用以下汇编代码传递结构(用户定义的数据类型的对象)。

凡以下是用户定义的数据类型,即WESContext:

typedef struct CWESContext 
{ 

    BSTR UserName; 
    BSTR MachineIP; 
    BSTR Certificate; 
    BSTR BrowserClienthandle;//Its the handle of the BrowserClient or Java Application Level Object 
    BSTR SessionID; 
    BSTR TaskID;// name of the original task 

    long LocaleID;//The location of the ultimate Caller 
    long FeatureID;//The feature ID mapping to some feature available in WESFW 
    long SessionTypeID;//Itmay be; Browser CLient Session, OPC Client Session,    Authenticated OPC Clients session(as they have more rights), WESFWSystemClient. 

    SYSTEMTIME TimeStamp;//the time the original task was executed 
    DWORD Priority; //task priority of the original task 

    struct WESProductCategory 
    { 
     BSTR ProductCategoryName; 
     int serialNo; 

     struct WESDimensions 
     { 
      int weight;   
      struct WESVolume 
      { 
       int length; 
       int heigth; 
       int width; 
      } oVolume; 

      BSTR tempHeight; 
      BSTR otherUnknownDimensions; 
     } oDimensions;  
    } oWESProductCategory; 
} CWESContext; 

我创建了块足够大小WESContext和样本数据填充它。

 int sizeOfWESContext = sizeof(CWESContext); 

     void *pWESContext = malloc(sizeOfWESContext); 
     void *pGenericPtr = pWESContext; 
     memset(pWESContext,0,sizeOfWESContext); 

     BSTR *bstrUserName = (BSTR*)pGenericPtr; 
     *bstrUserName = SysAllocString(CT2OLE(CA2T(results.at(0).c_str()))); 
     bstrUserName++; 

     pGenericPtr = bstrUserName; 

     BSTR *bstrMachineIp = (BSTR*)pGenericPtr; 
     *bstrMachineIp = SysAllocString(CT2OLE(CA2T(results.at(1).c_str()))); 
     bstrMachineIp++; 

     pGenericPtr = bstrMachineIp; 

     BSTR *bstrCertificate = (BSTR*)pGenericPtr; 
    *bstrCertificate = SysAllocString(CT2OLE(CA2T(results.at(2).c_str()))); 
     bstrCertificate++; 

     pGenericPtr = bstrCertificate; 

      ..................... 
      so on so forth............... 

如果我通过使此作为对象调用它:

调用Normaly: MyCallableMethodUDT(((CWESContext)pWESContext));

现在下面的程序集中,我只是在调试时从Visual Studio的Dissasembly视图中拉出来的。

 mov   esi,dword ptr [pWESContext] 
     sub   esp,58h 
     mov   ecx,16h 
     mov   edi,esp 
     rep movs dword ptr es:[edi],dword ptr [esi] 

我只需要知道3号线..

AS提高我的用户定义的结构内部成员(即这里WESContext),它增加了,但我无法断定它是如何增加....?我需要生成这条指令,以便无论Object是什么以及它包含的任何大小和数据类型......它都应该通过调用上面写的汇编指令来调用它。

问候, 乌斯曼

+0

请格式化您的代码! – 2010-09-30 19:00:02

回答

1

ecx被用作计数双字由在线路5的rep movs指令被复制的数量它从起始地址将数据复制指向esi的位置开始edi

ecx中的值将是正在复制的数据的大小。

+0

实际上是双字的数量。如果ptrs是“BYTE PTR”,或者指令是“MOVSB”,那么它将是字节数。但是,目前的汇编将与“MOVSD”一样。 – cHao 2010-09-30 19:09:16

+0

嗯,是的,我没有注意到指令中存在DWORD PTR。固定。 – 2010-09-30 20:23:13