July 14, 2014 Re: SImple C++ code to D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alexandre | And some other strange thing is, the generate struct in PE file is wrong.. look at imagens... As it should be...: http://i.imgur.com/4z1T3jF.png And how is being generated...: http://i.imgur.com/Oysokuh.png My actual source is that: http://dpaste.com/2TZKWF5 On Monday, 14 July 2014 at 11:55:18 UTC, Alexandre wrote: > Look at line 114 of my code: http://dpaste.com/3B5WYGV > > Have a more better way to make this conversion ? > *(DWORD*)"PE\0\0" ? |
July 14, 2014 Re: SImple C++ code to D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alexandre | Alexandre: >> Look at line 114 of my code: http://dpaste.com/3B5WYGV The indentations are messed up. > peh.Signature = ('\0' << 8) + ('\0' << 8) + ('E' << 8) + 'P'; You need shifts 8, 16, 24... > alias PIMAGE_DOS_HEADER = IMAGE_DOS_HEADER*; I don't see much need for such aliases. > auto peh = cast(PIMAGE_NT_HEADERS32)&image[0x80]; I suggest to avoid magic constants like that 0x80, like I have avoided it here: memcpy(&image[IMAGE_DOS_HEADER.sizeof], Bye, bearophile |
July 14, 2014 Re: SImple C++ code to D | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | Is there any counter-indication with this:
immutable ubyte[5] stub = x"b8 01 4c cd 21".representation;
?
Is it a compile time value?
On Monday, 14 July 2014 at 12:18:20 UTC, bearophile wrote:
> Alexandre:
>
>>> Look at line 114 of my code: http://dpaste.com/3B5WYGV
>
> The indentations are messed up.
>
>
>> peh.Signature = ('\0' << 8) + ('\0' << 8) + ('E' << 8) + 'P';
>
> You need shifts 8, 16, 24...
>
>
>> alias PIMAGE_DOS_HEADER = IMAGE_DOS_HEADER*;
>
> I don't see much need for such aliases.
>
>
>> auto peh = cast(PIMAGE_NT_HEADERS32)&image[0x80];
>
> I suggest to avoid magic constants like that 0x80, like I have avoided it here:
> memcpy(&image[IMAGE_DOS_HEADER.sizeof],
>
> Bye,
> bearophile
|
July 14, 2014 Re: SImple C++ code to D | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | > I don't see much need for such aliases. Ok, how I can reduce the number of aliaSs ? > I suggest to avoid magic constants like that 0x80, like I have avoided it here: > memcpy(&image[IMAGE_DOS_HEADER.sizeof], Btw, I need to start that part of code in x80 Look, that is my C++ code base: http://dpaste.com/1MMZK4R I get a lot of problens, to convert 'strings' to UCHAR... :/ |
July 14, 2014 Re: SImple C++ code to D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrea Fontana | > immutable ubyte[5] stub = x"b8 01 4c cd 21".representation; that is a Real-Mode Stub Program On Monday, 14 July 2014 at 12:32:38 UTC, Andrea Fontana wrote: > Is there any counter-indication with this: > > immutable ubyte[5] stub = x"b8 01 4c cd 21".representation; > > ? > > Is it a compile time value? > > > On Monday, 14 July 2014 at 12:18:20 UTC, bearophile wrote: >> Alexandre: >> >>>> Look at line 114 of my code: http://dpaste.com/3B5WYGV >> >> The indentations are messed up. >> >> >>> peh.Signature = ('\0' << 8) + ('\0' << 8) + ('E' << 8) + 'P'; >> >> You need shifts 8, 16, 24... >> >> >>> alias PIMAGE_DOS_HEADER = IMAGE_DOS_HEADER*; >> >> I don't see much need for such aliases. >> >> >>> auto peh = cast(PIMAGE_NT_HEADERS32)&image[0x80]; >> >> I suggest to avoid magic constants like that 0x80, like I have avoided it here: >> memcpy(&image[IMAGE_DOS_HEADER.sizeof], >> >> Bye, >> bearophile |
July 14, 2014 Re: SImple C++ code to D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrea Fontana | Andrea Fontana: > Is there any counter-indication with this: > > immutable ubyte[5] stub = x"b8 01 4c cd 21".representation; > > ? See: https://issues.dlang.org/show_bug.cgi?id=10454 https://issues.dlang.org/show_bug.cgi?id=5909 > Is it a compile time value? Generally you need module-level values or enums to be sure a value is compile-time. In this case it is probably not. Bye, bearophile |
July 14, 2014 Re: SImple C++ code to D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alexandre | Alexandre:
> I get a lot of problens, to convert 'strings' to UCHAR... :/
I suggest you to take a look at the D docs and understand what D fixed-sized arrays are, dynamic arrays, and strings (that are dynamic arrays).
Bye,
bearophile
|
July 14, 2014 Re: SImple C++ code to D | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | bearophile, Thanks for all help! As I said, I'm coming from C # and C + +, I need to learn "tricks" of D language... 'm reading this book: http://ddili.org/ders/d.en/ I have a struct with union... struct IMAGE_SECTION_HEADER { BYTE[8] Name; union Misc { DWORD PhysicalAddress, VirtualSize; } DWORD VirtualAddress, SizeOfRawData, PointerToRawData, PointerToRelocations, PointerToLinenumbers; WORD NumberOfRelocations, NumberOfLinenumbers; DWORD Characteristics; } ( the identation is wrong here... ) Btw, my problem is, how to acess the union elements ? I try this: //... scth[0].Misc.VirtualSize = 15; //... But, the compiler return that error: main.d(151): Error: need 'this' for 'VirtualSize' of type 'uint' On Monday, 14 July 2014 at 13:00:21 UTC, bearophile wrote: > Alexandre: > >> I get a lot of problens, to convert 'strings' to UCHAR... :/ > > I suggest you to take a look at the D docs and understand what D fixed-sized arrays are, dynamic arrays, and strings (that are dynamic arrays). > > Bye, > bearophile |
July 14, 2014 Re: SImple C++ code to D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alexandre | Alexandre: > BYTE[8] Name; Generally in D field names start with a lowercase (unless you need them with uppercase). > Btw, my problem is, how to acess the union elements ? > > I try this: > //... > scth[0].Misc.VirtualSize = 15; > //... > > But, the compiler return that error: > main.d(151): Error: need 'this' for 'VirtualSize' of type 'uint' The error message is not the best. It is saying you are not accessing data, just its definition. So you need to instantiate the union: struct Foo { ubyte[8] name; union Bar { ushort physicalAddress, virtualSize; } Bar b; } void main() { Foo f; f.b.physicalAddress = 10; } Or use an anonymous one: struct Foo { ubyte[8] name; union { ushort physicalAddress, virtualSize; } } void main() { Foo f; f.physicalAddress = 10; } Bye, bearophile |
July 14, 2014 Re: SImple C++ code to D | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | > Generally in D field names start with a lowercase (unless you need them with uppercase).
And user defined type names start with an upper case. This is useful, because if you write:
scth[0].Misc.virtualSize = 15;
You see immediately that Misc is not a value but a type. So it can't work.
Bye,
bearophile
|
Copyright © 1999-2021 by the D Language Foundation