From b2d797c48028d86ada8e5bae1186b0f0a4c284ae Mon Sep 17 00:00:00 2001 From: Lenheart <947330670@qq.com> Date: Tue, 15 Feb 2022 20:31:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E9=87=8D=E5=86=99=20dofile?= =?UTF-8?q?=20=E6=96=87=E4=BB=B6=E6=B5=81=E6=88=90=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/framework.h | 7 +++++-- test/pch.h | 3 ++- test/函数块.cpp | 39 ++++++++++++++++++++++++++++----------- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/test/framework.h b/test/framework.h index d920597..10139e5 100644 --- a/test/framework.h +++ b/test/framework.h @@ -1,5 +1,5 @@ #pragma once - +#define _CRT_SECURE_NO_WARNINGS #define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容 // Windows 头文件 #include @@ -7,4 +7,7 @@ #include #include "squirrel.h" -#include "MinHook.h" \ No newline at end of file +#include "MinHook.h" + +#include +#include \ No newline at end of file diff --git a/test/pch.h b/test/pch.h index a08c429..bcac771 100644 --- a/test/pch.h +++ b/test/pch.h @@ -111,6 +111,7 @@ typedef void* (SQDOFILEFunc)(uint32_t v, const wchar_t* filename, bool retval, b static SQDOFILEFunc* SQDOFILE = (SQDOFILEFunc*)0x1356240; +typedef void*(*SQFILE)(); //SQ_io_file_lexfeed_编码 //typedef int(LSQLEXREADFUNC)(int n); typedef int(*LSQLEXREADFUNC)(int n); @@ -119,7 +120,7 @@ static LSQLEXREADFUNC SQ_io_file_lexfeed_UCS2_BE = (LSQLEXREADFUNC)0x1356050; static LSQLEXREADFUNC SQ_io_file_lexfeed_UCS2_LE = (LSQLEXREADFUNC)0x1356020; static LSQLEXREADFUNC SQ_io_file_lexfeed_UTF8 = (LSQLEXREADFUNC)0x1355F90; //SQfopen -typedef void* (SQfopenFunc)(const wchar_t* filename, const wchar_t* type); +typedef SQFILE* (SQfopenFunc)(const wchar_t* filename, const wchar_t* type); static SQfopenFunc* SQfopen = (SQfopenFunc*)0x1355DC0; //SQfread typedef int(SQfreadFunc)(void* buffer, int a, int b, void* file); diff --git a/test/函数块.cpp b/test/函数块.cpp index 17b369b..be10a9b 100644 --- a/test/函数块.cpp +++ b/test/函数块.cpp @@ -240,7 +240,9 @@ int GetEquAddr(int addr) // static int SQloadfile(uint32_t v, const wchar_t* filename, bool printerror) { - void* file = SQfopen(filename, L"rb"); + SQFILE* file = SQfopen(filename, L"rb+"); + //FILE* file; + //file = fopen(filename, "rb"); int ret; unsigned short us; unsigned char uc; @@ -283,18 +285,26 @@ static int SQloadfile(uint32_t v, const wchar_t* filename, bool printerror) default: SQfseek(file, 0, 2); break; // ascii } - const char *add = "newstr"; - int prevpos = SQftell(file); + char* nstr = (char*)"IIIAAAB <- 6648"; + //SQwrite(&add, 1, sizeof(add), file); + SQwrite(nstr, sizeof(nstr), strlen(nstr), file); + SQfseek(file, 0, 1); int length = SQftell(file); - SQfseek(file, prevpos, 2); - char temp[256]; - SQwrite(&add, 1, sizeof(add), file); - SQfread(&temp, length + 10, sizeof(temp), file); - std::cout << temp << std::endl; - - + SQfseek(file, 0, 2); + std::cout << "lenth:" << length << std::endl; + //char temp[256]; + char* temp = new char[length]; + //SQwrite(&add, 1, sizeof(add), file); + SQfread(temp, sizeof(temp), length, file); + temp[length] = '\0'; + printf(temp); + printf("\n"); + //std::cout << temp << std::endl; + + //char* temp = new char[16 * 4]; + SQfseek(file, 0, 2); if (SQ_Compile(v, func, file, filename, printerror) >= 0) { SQ__Fclose(file); @@ -361,7 +371,6 @@ void RegisterNutApi(const wchar_t* funcName, void* funcAddr, uint32_t v) static int sq_Test(uint32_t v) { //sq_pushinteger(v, n1); - SQdofile(v, L"1.cpp", false, false); return 0; } // װ @@ -618,6 +627,14 @@ static int LDofile(uint32_t v) { SQGetString(v, 2, &n1); SQPopTop(v); + /* + size_t len = wcslen(n1) + 1; + size_t converted = 0; + char* CStr; + CStr = (char*)malloc(len * sizeof(char)); + wcstombs_s(&converted, CStr, len, n1, _TRUNCATE); + */ + SQdofile(v, n1, false, false); SQPushBool(v, true); }