sp0987
Members-
Content Count
56 -
Joined
-
Last visited
Everything posted by sp0987
-
Access Violation and Invalid Pointer exception while accessing files from web pages
sp0987 posted a topic in Indy
I am writing an HTTP server (TIdHTTPServer) program that services GET requests for images. This 'OnCommandGet ' procedure of Httpserver, calls other procedures to do various tasks, and then finally gets back to the client via TIdHTTPResponseInfo. procedure TVRMEditor.HTTPServerCommandGet(AContext: TIdContext; req: TIdHTTPRequestInfo; res: TIdHTTPResponseInfo); var act, DocExt: string; begin try res.SERVER := 'VRM Editor'; res.ContentType := 'text/html;charset="UTF-8"'; res.ResponseNo := 200; act := UpperCase(copy(req.Document, 2, Length(req.Document) - 1)); DocExt := UpperCase(ExtractFileExt(act)); self.Log(fcomp_name + ': ' + copy(req.RawHTTPCommand, 1, Length(req.RawHTTPCommand) - 9), allowed); -- allowed is a flag to print all the req commands when set to true if DocExt = '.MAX' then begin self.ProcessResponse(req, res); end else self.SendFileToClient(req, res); -- access all the js/css/jpg/css files which are needed to open a web page except on E: Exception do begin self.Log(req.URI + ' : ' + req.Document + sLineBreak + E.ClassName + ' : ' + E.Message); end; end; end; When the Allowed flag is set to true, it prints al the request commands and opens the webpage without any error. If it sets to false, am getting AV / Invalid pointer and couldn't open the page. Am not sure whether you can get the log, but you can see the exceptions. Allowed = true.log Allowed=false.log -
Access Violation and Invalid Pointer exception while accessing files from web pages
sp0987 replied to sp0987's topic in Indy
Procedure GLog(Msg: String); var gLogger: TFileLogger = nil; begin if Assigned(gLogger) and Assigned(gLogger.Memo) then begin gLogger.fmLock.Enter; gLogger.Memo.Lines.BeginUpdate; while gLogger.Memo.Lines.Count > 600 do gLogger.Memo.Lines.Delete(0); gLogger.Memo.Lines.Add(Msg); gLogger.Memo.Lines.EndUpdate; gLogger.Memo.Perform(EM_SCROLLCARET, 0, 0); gLogger.fmLock.Leave; end; _Log(Msg); end; Upon my observation, when log prints all the requests from web page, there was no AV/ Invalid pointer Exception. Am not sure that log function was the culprit... -
Access Violation and Invalid Pointer exception while accessing files from web pages
sp0987 replied to sp0987's topic in Indy
procedure TVRMEditor.SendFileToClient(req: TIdHTTPRequestInfo; res: TIdHTTPResponseInfo); var doc, ext, Data, fname, err: String; b: boolean; rlst: TStringList; begin Data := ''; fname := req.Document; doc := ExpandFilename(self.RootDir + fname); if not FileExists(doc) then begin self.Log(fcomp_name + ': ' + fname + ' not in editor''s webroot!', LogServer); doc := ExpandFilename(fclirootdir + '\webroot\' + fname); if not FileExists(doc) then begin self.Log(fcomp_name + ': ' + fname + ' not found in any webroot!'); doc := ''; end; end; if doc <> '' then begin ext := UpperCase(ExtractFileExt(fname)); b := (ext = '.CSS') or (ext = '.HTM') or (ext = '.HTML') or (ext = '.JS'); if not b then begin res.ContentType := fMIMEMap.GetFileMIMEType(doc); res.ContentStream := TFileStream.Create(doc, fmOpenRead or fmShareCompat); end else begin try rlst := TStringList.Create; GetConstantGroup('Global_Skin', rlst); Data := LoadDataFromFile(doc); Data := ReplaceAllStringParams(Data, [rlst], '#S', '#', true); if not ReplaceForIncludFiles(Data, err, rlst, true) then self.Log(' #Include Replace Error: ' + err); res.ContentType := fMIMEMap.GetFileMIMEType(doc); res.ContentStream := TStringStream.Create(Data); finally rlst.Free; end; end; end; end; Code to sendfiletoclient -
Unicode NBSP(u00A0) No-Break Space character for 64-bit
sp0987 posted a topic in RTL and Delphi Object Pascal
Hi, I am trying to create a .JSON file in Delphi 11 64-bit. While writing sample data to .json file , the   character was weird in 64-bit. In 32-bit version , it was like "u00A0" and when coming to 64-bit version it was like "u=<68" and sometimes "u3<78". When I parse this resulted json file in .JS files , it throws an error like "invalid JSON". Attached are samples from 32-bit and 64-bit. Please suggest. 32-bit.json 64-bit.json -
Unicode NBSP(u00A0) No-Break Space character for 64-bit
sp0987 replied to sp0987's topic in RTL and Delphi Object Pascal
Am sorry i didn't get you -
Unicode NBSP(u00A0) No-Break Space character for 64-bit
sp0987 replied to sp0987's topic in RTL and Delphi Object Pascal
Attaching a sample project. The project will create a json file, which when we try to use in javascript reults in error "invalid Json". can be run in bot 32-bit and 64-bit with few changes. The changes were mentioned in the respected .pas files as comments. TestJson.7z -
Unicode NBSP(u00A0) No-Break Space character for 64-bit
sp0987 replied to sp0987's topic in RTL and Delphi Object Pascal
Am having issue with "u3<78" . Instead of "u1618", am getting "u3<78" in some areas. When we see the 32-bit , it was 'u00A0' all over. -
Unicode NBSP(u00A0) No-Break Space character for 64-bit
sp0987 replied to sp0987's topic in RTL and Delphi Object Pascal
It was just a part of json file, not the whole thing. -
Changes in System.sysutils.pas were not reflecting in other unit in Delphi 11
sp0987 posted a topic in General Help
We have introduced a new variable to the interface part and a function to the implementation portion of the Delphi 11 System.Sysutils.pas, in accordance with project requirements. The freshly generated variable is not accessible to me, and when I try to access it, I get the "Undefined Identifier" error. In Delphi 7, the same procedure was effective. -
Changes in System.sysutils.pas were not reflecting in other unit in Delphi 11
sp0987 replied to sp0987's topic in General Help
Much grateful for you response. It worked. The problem is with this LOC. Without stdcall it worked in D7. -
Changes in System.sysutils.pas were not reflecting in other unit in Delphi 11
sp0987 replied to sp0987's topic in General Help
AM sure, it's not working. When the call the Now() after "Interceptcreate", then as we hooked the "gettbttime" it will go to GetTBTtime proc and then decode the date which was given in the code. And then it goes to function Now() in sysutils.pas. In that function , the SystemTime var will be filled with either '0''s or weird numbers. The same code when in debugged using D7, the SystemTime var in Now() of sysutils.pas was filled with the date given in "gettbttime" -
Changes in System.sysutils.pas were not reflecting in other unit in Delphi 11
sp0987 replied to sp0987's topic in General Help
In the DecodeDateTime, we will not use that param. -
Changes in System.sysutils.pas were not reflecting in other unit in Delphi 11
sp0987 replied to sp0987's topic in General Help
Does DDetours offer support for Delphi 11? I'm having trouble using the library right now. DDetours was utilized in place of editing the sysutils.pas file, as advised. However, it functions properly with Delphi 7 but returns a "Inavalid Date to EncodeDate" issue with Delphi 11. This code sample, which functions well in D7 but not in D11, was supplied. implementation {$R *.dfm} var windows_GetLocalTime: procedure(var st: TSystemTime); stdcall; procedure getTbtTime(var st: TSystemTime); var dt: TDateTime; begin dt := strtodatetime('12/06/2024'); DecodeDateTime(dt, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds); end; procedure TForm1.FormCreate(Sender: TObject); begin windows_GetLocalTime := Windows.GetLocalTime; end; procedure TForm1.Button1Click(Sender: TObject); var dt, value: TDateTime; s: string; begin dt := Now; showmessage('before hook:- ' + datetimetostr(dt)); windows_GetLocalTime := InterceptCreate(@Windows.GetLocalTime, @getTbtTime); dt := Now; // Returns error "Invalid date to Encodedate" s := FormatDateTime('mm/dd/yyyy : hh:nn:ss.zzz - ', dt); // showmessage('after hook:- ' + datetimetostr(dt)); end; -
Changes in System.sysutils.pas were not reflecting in other unit in Delphi 11
sp0987 replied to sp0987's topic in General Help
I didn't fully go through their WiKi and examples before, but the "Hooking WinAPI function" example is exactly what I need. I've got the idea how it works now. Thank you ALL for helping out pointing me the right direction! -
Changes in System.sysutils.pas were not reflecting in other unit in Delphi 11
sp0987 replied to sp0987's topic in General Help
I was planning to use the suggested DDetours library and since I didn't have it nor D11 in front of me I called it createNewDetour(). This is the actual function: function InterceptCreate(const TargetProc, InterceptProc: Pointer; const Param: Pointer = nil; const Options: TInterceptOptions = DefaultInterceptOptions): Pointer; overload; Calling reference of the original function will not work then. Thank you for the explanation of the internal DDetours implementation. If there is no other way than I'll look into modifying the PE imports table. That is something I never had to do. Hopefully it is easy. -
Changes in System.sysutils.pas were not reflecting in other unit in Delphi 11
sp0987 replied to sp0987's topic in General Help
Great idea, thank you. I will save the original reference before the detour and use that from within. FYI, I'm going to rewrite the existing D7 implementation using the mentioned DDetour library and use same or built in D11 as well. -
Changes in System.sysutils.pas were not reflecting in other unit in Delphi 11
sp0987 replied to sp0987's topic in General Help
before I start, how do I ensure that calling the original Windows.GetLocalTime from within my detoured function does not get also detoured causing circular reference errors? Or that will no longer possible? Example: procedure myNewLocalTime(var st: TSystemTime); begin st := Windows.GetLocalTime(st); // now further modify st end; createNewDetour(@Window.GetLocalTime, @myNewLocalTime, ...); -
Changes in System.sysutils.pas were not reflecting in other unit in Delphi 11
sp0987 replied to sp0987's topic in General Help
Because our software needs to operate/tested through time from past to the future in cycles and we can't change the OS time as we did in past. -
Changes in System.sysutils.pas were not reflecting in other unit in Delphi 11
sp0987 replied to sp0987's topic in General Help
Thanks for this suggestion too. GetLocalTime is just reference into external Windows DLL in Windows unit I think. I'll need to create a wrapper with same name around it with additional logic somewhere within my project which can be reached by the original GetLocalTime in sysUtils? Correction: it doesn't need to have same name. I could do something like: // excuse wrong code as I do not have D11 in front of me createNewDetour(@Window.GetLocalTime, @myNewLocalTime, ...); yes? -
Changes in System.sysutils.pas were not reflecting in other unit in Delphi 11
sp0987 replied to sp0987's topic in General Help
If detours take care of this than that would be exactly what I need! I will attach detours in main's object constructor and test even 3rd party code goes through them. Thank you all for this suggestion! -
Changes in System.sysutils.pas were not reflecting in other unit in Delphi 11
sp0987 replied to sp0987's topic in General Help
Hi, I looked into the detours, its definitely a cool feature but I'm not sure it will solve our dilemma. With some (coding) effort detours may intercept the few system's DateTime functions within our project units, but what about 3rd party units, code and components? They will probably be still using the core sysUtils with original functionality. This may introduce bugs as the app will use 2 different times (ours, and OS). Is there a way (place in Delphi) we could easily (without recompiling RTL/VCL) override the few sysUtils's functions? Or this exactly can be accomplished with proper implementation of detours? -
Changes in System.sysutils.pas were not reflecting in other unit in Delphi 11
sp0987 replied to sp0987's topic in General Help
If it's really about the interface section, then i have tested the same without modifying interface section. I just created a new function in implementation section and tried to call the newly added function in our sample app. It also gives me the same error. -
Changes in System.sysutils.pas were not reflecting in other unit in Delphi 11
sp0987 replied to sp0987's topic in General Help
The utility was a good suggestion. Thanks for that. But, in our case we would like to handle it in our code as we sync the changes with DB and other's. -
Changes in System.sysutils.pas were not reflecting in other unit in Delphi 11
sp0987 replied to sp0987's topic in General Help
related to datetime or datetime conversions? -
Changes in System.sysutils.pas were not reflecting in other unit in Delphi 11
sp0987 replied to sp0987's topic in General Help
In Delphi 7 we easily intercepted/modified result of all DateTime core functions as Now, Date, Time etc. to use our DateTime (not the real OS DateTime) for testing purposes without the need to change the machine's OS time. D7 easily allowed us to do that introducing an optional event. Here is a small example how we successfully handled it in D7: type TGetTbtTime = procedure(var st: TSystemTime) of object; var gGetTbtTime: TGetTbtTime; procedure tbtLocalTime(var st: TSystemTime); begin if Assigned(gGetTbtTime) then gGetTbtTime(st) // HERE WE PROVIDE BACK OUR OWN DATETIME else Window.GetLocalTime(st); end; // NATIVE DELPHI FUNCTION function Date: TDateTime; var SystemTime: TSystemTime; begin tbtLocalTime(SystemTime); with SystemTime do Result := EncodeDate(wYear, wMonth, wDay); end; D11 is giving us a hard time to do the same.