[英]The 'get' equivalent of _set_se_translator?
我需要使用當前的翻譯器手動翻譯結構化異常。
我如何“獲取”某人通過_set_se_translator
設置的_set_se_translator
?
我最初沒有意識到這一點,但是SE轉換器是線程本地的 , 而不是進程范圍的。
因此,這實際上是最好的(也是最簡單的)解決方案:
_se_translator_function _get_se_translator(void) {
_se_translator_function translator = _set_se_translator(NULL); // temporary
_set_se_translator(translator); // Restore the old value
return translator;
}
沒有直接的方法可以執行此操作,但是如果您要冒一些不兼容的風險並深入研究Visual C運行時的內部結構,則可以采用以下解決方案:
_se_translator_function __cdecl _get_se_translator(void) {
unsigned char const *p = (unsigned char const *)(&__uncaught_exception);
struct _tiddata {
unsigned long _tid;
void *_thandle;
int _terrno; unsigned long _tdoserrno;
unsigned int _fpds;
unsigned long _holdrand;
char *_token; wchar_t *_wtoken;
unsigned char *_mtoken;
char *_errmsg; wchar_t *_werrmsg;
char *_namebuf0; wchar_t *_wnamebuf0;
char *_namebuf1; wchar_t *_wnamebuf1;
char *_asctimebuf; wchar_t *_wasctimebuf;
void *_gmtimebuf;
char *_cvtbuf;
unsigned char _con_ch_buf[5];
unsigned short _ch_buf_used;
void *_initaddr; void *_initarg;
void *_pxcptacttab;
void *_tpxcptinfoptrs;
int _tfpecode;
void *ptmbcinfo; void *ptlocinfo;
int _ownlocale;
unsigned long _NLG_dwCode;
void *_terminate; void *_unexpected;
_se_translator_function _translator;
};
if (p[0] == 0x48) /* sub RSP, 0x28 */ { p += 4; } // x64 only
if (p[0] == 0xE8) /* call _getpid */ { ++p; } // must be true
void const *_getptd = p + *(long *)p + sizeof(long);
return ((struct _tiddata *(__cdecl *)(void))_getptd)()->_translator;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.