关于lua字节码在32位和64位系统上不兼容的问题

关于lua字节码在32位和64位系统上不兼容的问题,第1张

https://blog.csdn.net/you_lan_hai/article/details/77430116

具体在
build\lua-5.3.5\src\ldump.c
build\lua-5.3.5\src\lundump.c

build\lua-5.3.5\src\ldump.c中的修改:

static void DumpBlock (const void *b, size_t size, DumpState *D) {
  if (D->status == 0 && size > 0) {
    lua_unlock(D->L);
    D->status = (*D->writer)(D->L, b, size, D->data);
    lua_lock(D->L);
  }
}
改为:
static void DumpBlock (const void *b, int size, DumpState *D) {
  if (D->status == 0 && size > 0) {
    lua_unlock(D->L);
    D->status = (*D->writer)(D->L, b, size, D->data);
    lua_lock(D->L);
  }
}

static void DumpString (const TString *s, DumpState *D) {
  if (s == NULL)
    DumpByte(0, D);
  else {
    size_t size = tsslen(s) + 1;  /* include trailing 'const' */
    char * =str getstr ()s;if
    ( <size 0xFF )DumpByte
      (cast_int()size,) D;else
    DumpByte {
      (0xFF,) D;DumpVar
      (,size) D;}
    DumpVector
    (,str- size 1 ,) D;/* no need to save '}' */  }
  static
void

改为:
DumpString ( const *, TString *s) DumpState ifD( {
  == NULLs ) DumpByte(
    0,); Delseint
  = {
    tsslen size ( )+s1 ; /* include trailing 'const' */char  *
    = getstr (str ) ;ifs(<
    0xFF )size DumpByte (cast_int
      (),)size;else DDumpByte(
    0xFF {
      ,);DumpVar D(,
      );size} DDumpVector(
    ,
    -1str, size ) ;/* no need to save '}' */ D}static  void
  DumpHeader
(
* ) DumpLiteral (DumpState ,D) {
  ;DumpByteLUA_SIGNATURE( D,)
  ;DumpByteLUAC_VERSION( D,)
  ;DumpLiteralLUAC_FORMAT( D,)
  ;DumpByteLUAC_DATA( Dsizeof(
  int),);DumpByte( Dsizeof(
  ),);size_tDumpByte( Dsizeof(
  ),);InstructionDumpByte( Dsizeof(
  ),);lua_IntegerDumpByte( Dsizeof(
  ),);lua_NumberDumpInteger( D,)
  ;DumpNumberLUAC_INT( D,)
  ;}LUAC_NUMstatic DvoidDumpHeader
(


改为:
* ) DumpLiteral (DumpState ,D) {
  ;DumpByteLUA_SIGNATURE( D,)
  ;DumpByteLUAC_VERSION( D,)
  ;DumpLiteralLUAC_FORMAT( D,)
  ;DumpByteLUAC_DATA( Dsizeof(
  int),);DumpByte( Dsizeof(
  int),);DumpByte( Dsizeof(
  ),);InstructionDumpByte( Dsizeof(
  ),);lua_IntegerDumpByte( Dsizeof(
  ),);lua_NumberDumpInteger( D,)
  ;DumpNumberLUAC_INT( D,)
  ;}LUAC_NUMstatic DvoidLoadBlock
(

build\lua-5.3.5\src\lundump.c
中的修改:

* , void *LoadState ,S) if (bluaZ_read size_t size( {
  , ,)!=S->Z0 b) sizeerror ( ,"truncated"
    );S} staticvoidLoadBlock
(
改为:
* , void *LoadState ,Sint ) ifb( luaZ_read size( {
  , ,)!=S->Z0 b) sizeerror ( ,"truncated"
    );S} static*LoadString
(

* TString )= LoadByteLoadState (S) {
  size_t size ; if(S==0xFF
  ) LoadVarsize ( ,)
    ;ifS( size==0
  ) returnsize NULL ;else
    if (--
  <= ) /* short string? */charsize [ LUAI_MAXSHORTLEN] {  ;
    LoadVector buff(LUAI_MAXSHORTLEN,,
    );Sreturn buffluaS_newlstr size(,
    , );S->L} buffelse size/* long string */*
  =
  luaS_createlngstrobj {  (
    TString ,ts ) ;LoadVectorS->L( size,getstr
    ()S, );ts/* load directly in final place */return size;}  }
    static ts*
  LoadString
(


改为:

* TString )int =LoadState LoadByteS( {
  ) size ; if(S==0xFF
  ) LoadVarsize ( ,)
    ;ifS( size==0
  ) returnsize NULL ;else
    if (--
  <= ) /* short string? */charsize [ LUAI_MAXSHORTLEN] {  ;
    LoadVector buff(LUAI_MAXSHORTLEN,,
    );Sreturn buffluaS_newlstr size(,
    , );S->L} buffelse size/* long string */*
  =
  luaS_createlngstrobj {  (
    TString ,ts ) ;LoadVectorS->L( size,getstr
    ()S, );ts/* load directly in final place */return size;}  }
    static tsvoid
  checkliteral
(

* , const charLoadState *S, const char *s) char [ sizeofmsg( {
  ) buff+sizeof(LUA_SIGNATURE) ] ;/* larger than both */LUAC_DATA=strlen( )
  size_t len ; LoadVector(s,,
  );Sif buff( lenmemcmp(
  , ,)!=s0 buff) lenerror ( ,)
    ;}Sstatic msgvoidfchecksize
(


* , , constLoadState charS* size_t size) if ( LoadBytetname( {
  ) !=)errorS( , sizeluaO_pushfstring
    (,S"%s size mismatch in" ,)S->L) ;} tnamestaticvoidcheckliteral
(


改为:
* , const charLoadState *S, const char *s) char [ sizeofmsg( {
  ) buff+sizeof(LUA_SIGNATURE) ] ;/* larger than both */LUAC_DATAint=strlen (
  ) len ; LoadVector(s,,
  );Sif buff( lenmemcmp(
  , ,)!=s0 buff) lenerror ( ,)
    ;}Sstatic msgvoidfchecksize
(


* , int ,LoadState constSchar * size) if ( LoadBytetname( {
  ) !=)errorS( , sizeluaO_pushfstring
    (,S"%s size mismatch in" ,)S->L) ;} tnamestaticvoidcheckHeader
(
* ) checkliteral (LoadState ,S+ {
  1,S"not a" LUA_SIGNATURE ) ;/* 1st char already checked */ if(LoadByte  (
  ) !=)errorS( , LUAC_VERSION"version mismatch in"
    );Sif (LoadByte(
  ) !=)errorS( , LUAC_FORMAT"format mismatch in"
    );Scheckliteral (,,
  "corrupted")S; LUAC_DATAchecksize (,int
  );Schecksize (,)
  ;checksizeS( size_t,)
  ;checksizeS( Instruction,)
  ;checksizeS( lua_Integer,)
  ;ifS( lua_NumberLoadInteger(
  ) !=)errorS( , LUAC_INT"endianness mismatch in"
    );Sif (LoadNumber(
  ) !=)errorS( , LUAC_NUM"float format mismatch in"
    );S} staticvoidcheckHeader
(

改为:
* ) checkliteral (LoadState ,S+ {
  1,S"not a" LUA_SIGNATURE ) ;/* 1st char already checked */ if(LoadByte  (
  ) !=)errorS( , LUAC_VERSION"version mismatch in"
    );Sif (LoadByte(
  ) !=)errorS( , LUAC_FORMAT"format mismatch in"
    );Scheckliteral (,,
  "corrupted")S; LUAC_DATAchecksize (,int
  );Schecksize (,int
  );Schecksize (,)
  ;checksizeS( Instruction,)
  ;checksizeS( lua_Integer,)
  ;ifS( lua_NumberLoadInteger(
  ) !=)errorS( , LUAC_INT"endianness mismatch in"
    );Sif (LoadNumber(
  ) !=)errorS( , LUAC_NUM"float format mismatch in"
    );S} 


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/563116.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-04-02
下一篇2022-04-02

发表评论

登录后才能评论

评论列表(0条)

    保存