2010-09-30 56 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