Jump to content

Kas Ob.

Members
  • Content Count

    461
  • Joined

  • Last visited

  • Days Won

    8

Everything posted by Kas Ob.

  1. Kas Ob.

    Nobel prize for figuring out

    1) Right click on the folder and select properties. 2) in security tab click on advanced 3) Click on change owner 4) click advanced 5) click find now 6) in the list of users and groups select your user then OK 7) Now check that replace 8 ) ok
  2. Kas Ob.

    Nobel prize for figuring out

    Have you tried to take ownership of the directory ?
  3. Kas Ob.

    Nobel prize for figuring out

    Or try to take owner ship of a parent directory and apply the settings to sub folders.
  4. Kas Ob.

    Nobel prize for figuring out

    Here a theory: Once you ran the IDE with different user permission than yours now and the directory now have limited privileges, that interfere with the IDE ,the EXE, the DCU ...etc Also may be you used RDP once upon a time and renamed or created the needed directories, also with change the owner. Anyway, to test this, either check the permission, or an easier solution just rename a parent folder, or the project only, then create new with the same name, and try again.
  5. Kas Ob.

    Hext to Byte to Text = x509 cert

    Well, where to start ?!! See the first two hex values 3082 , from the first look i know this is an ASN.1 structure represent a what is most likely a X.509 certificate in raw content, so no texts or strings out of the box. Your question is not understandable, so i will guess here and assume that you want to get the text strings inside the certificate fields and extensions , right ? so here adjusted code function LoadHexSpaceSeparatedFileIntoAnsiString(aFileName: string): AnsiString; var i, c: Integer; st: string; LStingList: TStringList; begin LStingList := TStringList.Create; try LStingList.LineBreak := ' '; LStingList.LoadFromFile(aFileName); SetLength(Result, LStingList.Count); c := 1; for i := 0 to LStingList.Count - 1 do begin st := Trim(LStingList.Strings[i]); if (st <> '') and (Length(st) = 2) then begin HexToBin(PChar(@st[1]), PAnsiChar(@Result[c]), 1); Inc(c); end; end; SetLength(Result, c); finally LStingList.Free; end; end; procedure TForm10.Button1Click(Sender: TObject); var Cer:string; Stream:TMemoryStream; begin Cer := LoadHexSpaceSeparatedFileIntoAnsiString('HexFile.txt'); //Memo1.Lines.Add(Cer); Stream := TMemoryStream.Create; try Stream.Write(Ansistring(Cer)[1],Length(Cer)); Stream.Position := 0; Stream.SaveToFile('HexFile.der'); finally Stream.Free; end; end; This will give you fully restored certificate in BER format (also DER in this case) also if you grabbed that hex in full and pasted it in this site https://lapo.it/asn1js/ after decode you will have fully decoded ASN.1 structure, so when you ask for strings, i will assume you want the "issued to" field content, in that case then use the ICS examples and demoes to parse the X509 certificate and get you !! strings !! Away from that, please reform the question, so we can help. Also FPiette had asked, i don't get how did you get that hex in first place ??!!, my answer above is , WHAAT, ok, not my problem he asks for strings so lets make it a string, but it will not be a string, it is a complex structure with few readable string fields. Hope that clear things and helps. ps : The key usage (OID 1.3.6.1.4.1.49952.5.8.3.3) of this certificate is not recorded in any online OID databases, meaning this is proprietary and undocumented usage, also being issued by a governmental body, you really should be extra careful when it comes to such certificates and where its private key, such certificates usually locked to a hardware or locked to specific usage with specific software.
  6. Kas Ob.

    Hext to Byte to Text = x509 cert

    Well, may be not exactly what you need, but use it as you see fit. function LoadHexSpaceSeparatedFileIntoTBytes(aFileName: string): string; var i, c: Integer; st: string; LStingList: TStringList; begin LStingList := TStringList.Create; try LStingList.LineBreak := ' '; LStingList.LoadFromFile(aFileName); SetLength(Result, LStingList.Count); c := 1; for i := 0 to LStingList.Count - 1 do begin st := Trim(LStingList.Strings[i]); if (st <> '') and (Length(st) = 2) then begin HexToBin(PChar(@st[1]), PChar(@Result[c]), 1); Inc(c); end; end; SetLength(Result, c); finally LStingList.Free; end; end; Quick use of StringList to separate the values, of course you can parse it on your own and even skip the usage of HexToBin altogether by using your own.
  7. That is very slow. That is the reason of this slowness. Drop all of these, make sure you are using one, yes one loop ! PadZero is not needed at all as you will use IntToHex with like 2 digits, if while..do as one loop is too complicated for first write, then you use one while with increase over 16 and inner for/while with 16, the best approach is one while..do though. You can consider this as learning adventure, you build the content on two strings at the same time, the hex and the printed char then combine them at the end of each line, adding them to the result, read a byte once and get its hex value and its printable character. ByteToIntChar is not neede just use char(x) or char(pX^),, or simple Char(oneC). PadSpaceRt honestly ,i never heard of it but can imagine its job, simple concatenation with + is more than enough, in fact is faster than any function you think of in Delphi.
  8. You did a nice job there, also there is no standard hex dump, for the most used cases, have a look here https://www.asciitable.com/ The range is [32..126] , and for the extended it will be [32..126,128..254], and that it. One thing though about this, the first column should be the offset (or what you called the position), meaning the first raw should be 0000 and the next 0016. Another thing is refactor that piece of code, into completely agnostic input, meaning let the new refactored code take as input a pointer and size, TMemoryStream as example has Stream.Position returns a pointer to memory where the data reside, you can use it with a string when the content are corrupted to check what exactly went wrong, it could be a function return a string, and you can use it as your own code in separated unit (your own library), you will reuse that function in the future with different projects. In my own code i have the same, but sometimes i replace the offset with the address, or show both, but you rarely need the address itself.
  9. Kas Ob.

    Main menu

    @luciano_f I tried my own code today and the IDE generated a warning, it didn't show me yesterday so the code without warning is unit uRemoveUniDacMenu; interface uses Classes, SysUtils, ToolsAPI, Windows, VCL.Menus; implementation procedure FindMenuByCaptionAndHide(aMenu: TMenu; aCaption: string); var i: Integer; begin i := aMenu.Items.Count; while i > 0 do begin Dec(i); if aMenu.Items.Items[i].Caption = aCaption then begin aMenu.Items.Items[i].Visible := false; Break; end; end; end; procedure RemoveUniDacMenu; var NTAServices: INTAServices; IDEMainMenu: TMenu; begin if Supports(BorlandIDEServices, INTAServices, NTAServices) then begin IDEMainMenu := NTAServices.MainMenu; FindMenuByCaptionAndHide(IDEMainMenu, '&UniDAC'); FindMenuByCaptionAndHide(IDEMainMenu, 'V&irtualDAC'); end; end; initialization RemoveUniDacMenu; end. Another problem is after first IDE restart the menu was deleted but after two restart the menu was there and the code failed to delete the menu, the reason was something changed the order of package loading also this IDE is a cloned one meaning is really missed up, so can't be sure of the reason. Any way to make sure it will work always you need to add to required any of the UniDac packages like "dcldac220" and this ensure this package will follow the needed package, in this case all the UniDac RTL packages are loaded together so it will work with any of them.
  10. Kas Ob.

    Main menu

    Sorry couldn't resist. Here try this 1) New package. 2) Add to required 3) add this huge unit to search and hide menu unit uRemoveUniDacMenu; interface uses Classes, SysUtils, ToolsAPI, VCL.Menus; implementation procedure FindMenuByCaptionAndHide(aMenu: TMenu; aCaption: string); var i: Integer; begin i := aMenu.Items.Count; while i > 0 do begin Dec(i); if aMenu.Items.Items[i].Caption = aCaption then begin aMenu.Items.Items[i].Visible := false; Break; end; end; end; procedure RemoveUniDacMenu; var NTAServices: INTAServices; IDEMainMenu: TMenu; begin if Supports(BorlandIDEServices, INTAServices, NTAServices) then IDEMainMenu := NTAServices.MainMenu; if Assigned(IDEMainMenu) then begin FindMenuByCaptionAndHide(IDEMainMenu, '&UniDAC'); FindMenuByCaptionAndHide(IDEMainMenu, 'V&irtualDAC'); end; end; initialization RemoveUniDacMenu; end. Enjoy !
  11. Kas Ob.

    Main menu

    Using BPL maybe ?!!
  12. Kas Ob.

    GDI Objects limitation

    This means they are caching the button animation (drawing stage) as BITMAP's, i think solving this will be easy enough for them to some extend, there is few approaches like they can fix and even make it faster by using one bitmap and change its content from raw bytes, or put all the drawing stage in one bitmap and draw parts (rectangles) as needed.
  13. Kas Ob.

    String literals more then 255 chars

    Are you low on caffeine ? This is not the point of talk, i want what on the text to be converted at build/compile time to different codepage or encoding, like i want my constant multi line string to be an ansistring or/with specific code page no matter what the source file encoding was. I want to ditch using resource file with resource editor to add my long multiline scripts in an exe instead without losing the visibility and readability of them due the ',+ and #13#10 on every line and without adding spaces, i want to see them in the IDE as they are. Same goes for HTML code.
  14. Kas Ob.

    String literals more then 255 chars

    I think you missed mu codepage point, yes we can't use multi encoding in one text file, but we can control the compiler to handle the encoding as literal in the generated binary, if i want a ansistring Chinese with multiline without CRLF or with CRLF or simple one long string, followied by long Uniocde text, then the compiler will have no problem and it will be doable, instead of using resource files, also remembered the resource file rc, https://learn.microsoft.com/en-us/windows/win32/menurc/stringtable-resource Is that a multi encoding in one text file ?
  15. I don't know if you are familiar with https://castle-engine.io/ It does support 3DS format so importing from Autodesk 3DS Max hence the ability to even convert AutoCad model is possible, and it is cross platform. https://castle-engine.io/view3dscene.php
  16. Kas Ob.

    GDI Objects limitation

    Nope, no danger at all it will cause them few mega bytes in memory to can't be used, but i doubt if this is the best approach. You have to remove the need for such very high number. With such number (i only can guess ) you application is utilizing the CPU at very high level even without user interaction, let alone moving a windows with the mouse will cause the whole PC to hug, let alone if you are using double buffering everywhere. My suggestion is before contacting TMS to figure out why Ribbon is using such very high number, the last time i used TMS Ribbon was few years back with my license expired 12 years ago, i never noticed such thing. Try to start from scratch with the Ribbon in an empty and simple form to find the culprit or at least to understand the context that increase the GDI handles, also keep an eye on how many ImageList you are using and where, as they can be very expensive, your ImageList will behave better if you combine them, you can do this on separated module after initializing, i did such by keep many of them while developing a project but in production version the lists will be combined in one them freed. ps : the more GDI handle you have the slower the system behave, as these are look up tables and the most affecting thing is: the last to be created is the last in that list so the last frame or form created and showed will be the slowest to handle and will looks sluggish.
  17. Kas Ob.

    String literals more then 255 chars

    Few days ago i was ..well digging in the Delphi XE8 compiler refreshing my memories from Delphi 2010, i was was looking for how to find a way to enforce the compiler to resolve intrinsic function, why Addr(SetString) is resolved handled fine by the parser to @LStrFromPChar but refuse to compile it, but if you tried to use System.@LStrFromPChar in assembly block it will compile fine, meaning the compiler differ to specific parsing code to keep Pascal code intact introducing assembler parser BASM. Anyway, Delphi compiler is a big loop parser forward, but it will switch to different loop inside asm..end block, where semicolon is not needed or not obligatory and can handle instructions in different way, this simplify the code greatly and keep the speed of compilation intact for Pascal code, so if such multiline string format introduced everywhere then it might not be hindering the speed per se, but it will be the last !, no more string evolution forever, as any adjusting in the future will be the most ugly format and inconsistent has been existed. As Rollo62 pointed for the codepage and the very needed line breaks, it would be great if you can paste python code or Java or whatever strings and keep it with minimum modification as you found it, a bash script for Linux that doesn't need /r/n or just paste it as you found it, i really want to use both very long string like a whole X.509 base64 Encoded certificate with outline break but over multiline, also want to have to put Pascal script in whole in its readable format over multiline reserving line breaker CRLF. For that the above i suggested to move and restrict such implementation to defined block, as example we can have CppString (block just like resourcestring) that behave like C++11 with all its features, specially that the CBuilder already have the needed parser and it is working fine. By limiting such new string extension to well defined block(s), any number of strings format can be added in the future if not now, we can have multiline strings where new line can be new line is in source code as it or by /n, you can copy the lets paths from MSDN where the slash is double \\ without the need to adjust it to comply with Pascal, well in specific place of course.
  18. Kas Ob.

    String literals more then 255 chars

    Delphi/Pascal survived decades without multiline strings, also introducing them now will break things, but by restricting their usage in one dedicated place, will make adding compatibility backward easier with IFDEF directives and revert to the old style when needed without messing with the code itself.
  19. Kas Ob.

    String literals more then 255 chars

    Not only, but what if the multiline string was Pascal script code that have triple quote encapsulating a literal belongs to the script, and after that what about a semicolon following a triple quote in .... uhh... my head start to multifunction with the variants that can go wrong. That parser must have hundreds of test cases to pass, or as Thomas suggested, i like the idea to simplify the whole multiline strings by restricting it to resource string declaration or something new but similar, instead of a new intrinsic function.
  20. Don't use TStream ! TStream is base class, not implementing anything practical functionality except being a base to standardize all other streams for RTL, you can see it as an abstract. https://docwiki.embarcadero.com/Libraries/Sydney/en/System.Classes.TStream
  21. This is not an answer, sorry. But i think you need some pointers to begin with, say this code procedure TForm1.btnStrmToStringClick(Sender: TObject); // load/read into a tedit control begin strm.Read(s, strmSize); // read back the 15 chars eb2.Text := s; // show in tedit control end; here reside few problems, first how TStream works, stream's position need to be adjusted, in such case like above you need to use strm.Position := 0 before Read, also you need to make sure that s (the string) will have the right length to receive the data, so SetLength(s,strmSize) also needed, in your case it did work because s is not local variable. As i said this is not an answer, but i think you need to be aware of TPersistent and their usage, also what is serialization and what options you have in Delphi/Pascal to serialize data, i recommend to search the net, not because we are lazy here but your question is very wide and a full answer will require a book to cover, Please start here with this Remy great answer https://stackoverflow.com/questions/14763635/can-i-serialize-a-delphi-tpersistent-as-a-field-of-tcomponent-using-the-default Again please read about the subject more, and then refine your questions and we are here to help !
  22. Testing testing 1 2 3 Done...exiting Your encrypted text, if case you didn't solved this yet, here is the fixed code const cPassphrase = 's0m3s3cr3t!'; procedure CryptoError; var LError: TBytes; LMessage: string; begin SetLength(LError, 120); ERR_load_crypto_strings; ERR_error_string_n(ERR_get_error, @LError[0], Length(LError)); LMessage := TEncoding.UTF8.GetString(LError); // Display the message Writeln(LMessage); end; function DecryptAES256(const AValue: string): string; var LContext: PEVP_CIPHER_CTX; LOutputLen, LFinalLen: Integer; LBytes, LSalt, LIV, LEncryptedText, LKey, LOutput: TBytes; LCipher: Pointer; begin Result := ''; LBytes := TNetEncoding.Base64.DecodeStringToBytes(AValue); LCipher := EVP_aes_256_cbc; // prepare Key and IV length SetLength(LKey, EVP_CIPHER_key_length(LCipher)); SetLength(LIV, EVP_CIPHER_iv_length(LCipher)); // crypto-js returns an OpenSSL result, i.e. "salted__" + salt + encrypted text LEncryptedText := Copy(LBytes, 16, MaxInt); // Calc key and IV from passphrase and salt , crypto-js by default uses KDF with (MD5/8 bytes Salt/1 iteration) // https://github.com/brix/crypto-js/blob/develop/src/evpkdf.js LSalt := Copy(LBytes, 8, 8); if EVP_BytesToKey(LCipher, EVP_md5, @LSalt[0], @AnsiString(cPassphrase)[1], Length(cPassphrase), 1, @LKey[0], @LIV[0]) > 0 then begin LContext := EVP_CIPHER_CTX_new(); // Set padding EVP_CIPHER_CTX_set_padding(LContext, EVP_PADDING_PKCS7); if LContext <> nil then try // Initialize the decryption operation with 256 bit AES if EVP_DecryptInit_ex(LContext, LCipher, nil, @LKey[0], @LIV[0]) = 1 then begin SetLength(LOutput, Length(LEncryptedText) + EVP_CIPHER_block_size(LCipher)); // Provide the message to be decrypted, and obtain the plaintext output if EVP_DecryptUpdate(LContext, @LOutput[0], @LOutputLen, @LEncryptedText[0], Length(LEncryptedText)) = 1 then begin if EVP_DecryptFinal_ex(LContext, @LOutput[LOutputLen], @LFinalLen) = 1 then begin Inc(LOutputLen, LFinalLen); SetLength(LOutput, LOutputLen); Result := TEncoding.UTF8.GetString(LOutput); // might raise an unanticipated exception, should be inside try-except //Result := StringOf(LOutput); // IMO, this is safer than risking raising an exception end else CryptoError; end else CryptoError; end else CryptoError; finally EVP_CIPHER_CTX_free(LContext); end; end else CryptoError; end; begin // Decrypt value output by crypto-js // This is just an example value. Generate a new one from the Javascript code Writeln(DecryptAES256('U2FsdGVkX1812TdTm8MD2w4u2AaxUB2PdurCNOmu4bmutkR1Ul7Z1+bGXDsdlNK5')); Writeln('Done...exiting'); Readln; end. I recommend double check string Unicode on java part and how the above code will behave.
  23. Still there is a problem somewhere i think, see, the encryption code in java will make no sense if there is no padding as it will be prone for data lose or corruption, so i have assume either that it is using a padding scheme or the the encrypted data is well known length and constant and equal to a n*block_size (n*16), so if your plain text used with the encoding java code is less than 32 bytes then it is definitely using a padding scheme and you should use the same in decryption.
  24. OK, found the problem It seems OpenSSL has padding enabled by default, https://www.oreilly.com/library/view/secure-programming-cookbook/0596003943/ch05s19.html So this EVP_CIPHER_CTX_set_padding(LContext, 0); After EVP_DecryptInit_ex should solve the failure of EVP_DecryptFinal_ex, the rest is up to you to find and fix, specially that HMAC !!!!!, where it comes from ? , well ,i guess you already researched how that java script implemented.
  25. Small clarification : the size will be assumed not enough by EVP_DecryptFinal_ex if the a padding scheme is expected and will fail the same way as it didn't receive enough data (the data wasn't a multiplication of block_size)
×